Debian Codegraph @

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

raw
1 // This file was procedurally generated from the following sources:
2 // - src/function-forms/unscopables-with-in-nested-fn.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 (function() {
73 count++;
74 with (globalThis) {
75 count++;
76 assert.sameValue(v, 1, 'The value of `v` is 1');
77 }
78 })();
79 (function() {
80 count++;
81 var v = x;
82 with (globalThis) {
83 count++;
84 assert.sameValue(v, 10, 'The value of `v` is 10');
85 v = 20;
86 }
87 assert.sameValue(v, 20, 'The value of `v` is 20');
88 assert.sameValue(globalThis.v, 1, 'The value of globalThis.v is 1');
89 })();
90 assert.sameValue(v, 1, 'The value of `v` is 1');
91 assert.sameValue(globalThis.v, 1, 'The value of globalThis.v is 1');
92 callCount = callCount + 1;
93 };
94
95 ref(10);
96 assert.sameValue(callCount, 1, 'arrow function invoked exactly once');
97
98 count++;
99 }
100 assert.sameValue(count, 6, 'The value of `count` is 6');
101
102 reportCompare(0, 0);