Debian Codegraph @

js/src/tests/test262/language/expressions/arrow-function/unscopables-with.js

raw
1 // This file was procedurally generated from the following sources:
2 // - src/function-forms/unscopables-with.case
3 // - src/function-forms/default/arrow-function.template
4 /*---
5 description: Symbol.unscopables behavior across scope boundaries (arrow function expression)
6 esid: sec-arrow-function-definitions-runtime-semantics-evaluation
7 features: [globalThis, Symbol.unscopables]
8 flags: [generated, noStrict]
9 info: |
10 ArrowFunction : ArrowParameters => ConciseBody
11
12 [...]
13 4. Let closure be FunctionCreate(Arrow, parameters, ConciseBody, scope, strict).
14 [...]
15
16 9.2.1 [[Call]] ( thisArgument, argumentsList)
17
18 [...]
19 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
20 [...]
21
22 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList )
23
24 1. Let status be FunctionDeclarationInstantiation(F, argumentsList).
25 [...]
26
27 9.2.12 FunctionDeclarationInstantiation(func, argumentsList)
28
29 [...]
30 23. Let iteratorRecord be Record {[[iterator]]:
31 CreateListIterator(argumentsList), [[done]]: false}.
32 24. If hasDuplicates is true, then
33 [...]
34 25. Else,
35 b. Let formalStatus be IteratorBindingInitialization for formals with
36 iteratorRecord and env as arguments.
37 [...]
38
39 ...
40 Let envRec be lex's EnvironmentRecord.
41 Let exists be ? envRec.HasBinding(name).
42
43 HasBinding
44
45 ...
46 If the withEnvironment flag of envRec is false, return true.
47 Let unscopables be ? Get(bindings, @@unscopables).
48 If Type(unscopables) is Object, then
49 Let blocked be ToBoolean(? Get(unscopables, N)).
50 If blocked is true, return false.
51
52 (The `with` Statement) Runtime Semantics: Evaluation
53
54 ...
55 Set the withEnvironment flag of newEnv’s EnvironmentRecord to true.
56 ...
57
58 ---*/
59 let count = 0;
60 var v = 1;
61 globalThis[Symbol.unscopables] = {
62 v: true,
63 };
64
65 {
66 count++;
67
68 var callCount = 0;
69 // Stores a reference `ref` for case evaluation
70 var ref;
71 ref = (x) => {
72 count++;
73 with (globalThis) {
74 count++;
75 assert.sameValue(v, undefined, 'The value of `v` is expected to equal `undefined`');
76 }
77 count++;
78 var v = x;
79 with (globalThis) {
80 count++;
81 assert.sameValue(v, 10, 'The value of `v` is 10');
82 v = 20;
83 }
84 assert.sameValue(v, 20, 'The value of `v` is 20');
85 assert.sameValue(globalThis.v, 1, 'The value of globalThis.v is 1');
86 callCount = callCount + 1;
87 };
88
89 ref(10);
90 assert.sameValue(callCount, 1, 'arrow function invoked exactly once');
91
92 count++;
93 }
94 assert.sameValue(count, 6, 'The value of `count` is 6');
95
96 reportCompare(0, 0);