Debian Codegraph @

js/src/tests/test262/language/statements/async-function/unscopables-with.js

raw
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-decl.template
5 /*---
6 description: Symbol.unscopables behavior across scope boundaries (async function declaration)
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 AsyncFunctionDeclaration :
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 async function ref(x) {
51 count++;
52 with (globalThis) {
53 count++;
54 assert.sameValue(v, undefined, 'The value of `v` is expected to equal `undefined`');
55 }
56 count++;
57 var v = x;
58 with (globalThis) {
59 count++;
60 assert.sameValue(v, 10, 'The value of `v` is 10');
61 v = 20;
62 }
63 assert.sameValue(v, 20, 'The value of `v` is 20');
64 assert.sameValue(globalThis.v, 1, 'The value of globalThis.v is 1');
65 callCount = callCount + 1;
66 }
67
68 ref(10).then(() => {
69 assert.sameValue(callCount, 1, 'function invoked exactly once');
70 }).then($DONE, $DONE);
71
72 count++;
73 }
74 assert.sameValue(count, 6, 'The value of `count` is 6');