named-unscopables-with.js (1936B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/function-forms/unscopables-with.case 4 // - src/function-forms/default/async-func-expr-named.template 5 /*--- 6 description: Symbol.unscopables behavior across scope boundaries (async function named expression) 7 esid: sec-async-function-definitions 8 features: [globalThis, Symbol.unscopables, async-functions] 9 flags: [generated, noStrict, async] 10 info: | 11 14.6 Async Function Definitions 12 13 AsyncFunctionExpression : 14 async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } 15 16 17 ... 18 Let envRec be lex's EnvironmentRecord. 19 Let exists be ? envRec.HasBinding(name). 20 21 HasBinding 22 23 ... 24 If the withEnvironment flag of envRec is false, return true. 25 Let unscopables be ? Get(bindings, @@unscopables). 26 If Type(unscopables) is Object, then 27 Let blocked be ToBoolean(? Get(unscopables, N)). 28 If blocked is true, return false. 29 30 (The `with` Statement) Runtime Semantics: Evaluation 31 32 ... 33 Set the withEnvironment flag of newEnv’s EnvironmentRecord to true. 34 ... 35 36 ---*/ 37 let count = 0; 38 var v = 1; 39 globalThis[Symbol.unscopables] = { 40 v: true, 41 }; 42 43 { 44 count++; 45 46 47 var callCount = 0; 48 49 // Stores a reference `ref` for case evaluation 50 var ref; 51 ref = async function ref(x) { 52 count++; 53 with (globalThis) { 54 count++; 55 assert.sameValue(v, undefined, 'The value of `v` is expected to equal `undefined`'); 56 } 57 count++; 58 var v = x; 59 with (globalThis) { 60 count++; 61 assert.sameValue(v, 10, 'The value of `v` is 10'); 62 v = 20; 63 } 64 assert.sameValue(v, 20, 'The value of `v` is 20'); 65 assert.sameValue(globalThis.v, 1, 'The value of globalThis.v is 1'); 66 callCount = callCount + 1; 67 }; 68 69 ref(10).then(() => { 70 assert.sameValue(callCount, 1, 'function invoked exactly once'); 71 }).then($DONE, $DONE); 72 73 count++; 74 } 75 assert.sameValue(count, 6, 'The value of `count` is 6');