Debian Codegraph @

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