throws-if-initializer-not-object.js (2314B)
1 // |reftest| shell-option(--enable-explicit-resource-management) skip-if(!(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('explicit-resource-management'))||!xulRuntime.shell) async -- explicit-resource-management is not enabled unconditionally, requires shell-options 2 // Copyright (C) 2023 Ron Buckton. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-let-and-const-declarations-runtime-semantics-evaluation 7 description: Throws if initialized value is not an Object 8 info: | 9 RS: Evaluation 10 AwaitUsingDeclaration : CoverAwaitExpressionAndAwaitUsingDeclarationHead BindingList ; 11 12 1. Perform ? BindingEvaluation of BindingList with argument async-dispose. 13 2. Return empty. 14 15 RS: BindingEvaluation 16 LexicalBinding : BindingIdentifier Initializer 17 18 ... 19 5. Return ? InitializeReferencedBinding(lhs, value, hint). 20 21 InitializeReferencedBinding ( V, W ) 22 23 ... 24 4. Return ? base.InitializeBinding(V.[[ReferencedName]], W). 25 26 InitializeBinding ( N, V, hint ) 27 28 ... 29 2. If hint is not normal, perform ? AddDisposableResource(envRec.[[DisposeCapability]], V, hint). 30 ... 31 32 AddDisposableResource ( disposeCapability, V, hint [, method ] ) 33 34 1. If method is not present then, 35 a. If V is either null or undefined and hint is sync-dispose, then 36 i. Return unused. 37 b. Let resource be ? CreateDisposableResource(V, hint). 38 ... 39 40 CreateDisposableResource ( V, hint [ , method ] ) 41 42 1. If method is not present, then 43 a. If V is either null or undefined, then 44 ... 45 b. Else, 46 i. If V is not an Object, throw a TypeError exception. 47 ... 48 ... 49 50 flags: [async] 51 includes: [asyncHelpers.js] 52 features: [explicit-resource-management] 53 ---*/ 54 55 asyncTest(async function () { 56 await assert.throwsAsync(TypeError, async function() { 57 await using x = true; 58 }, 'true'); 59 60 await assert.throwsAsync(TypeError, async function() { 61 await using x = false; 62 }, 'false'); 63 64 await assert.throwsAsync(TypeError, async function() { 65 await using x = 1; 66 }, 'number'); 67 68 await assert.throwsAsync(TypeError, async function() { 69 await using x = 'object'; 70 }, 'string'); 71 72 var s = Symbol(); 73 await assert.throwsAsync(TypeError, async function() { 74 await using x = s; 75 }, 'symbol'); 76 });