Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/annexB/language/eval-code/indirect/global-if-decl-else-decl-a-eval-global-block-scoping.js

raw
1 // This file was procedurally generated from the following sources:
2 // - src/annex-b-fns/eval-global-block-scoping.case
3 // - src/annex-b-fns/eval-global/indirect-if-decl-else-decl-a.template
4 /*---
5 description: A block-scoped binding is created (IfStatement with a declaration in both statement positions in eval code)
6 esid: sec-functiondeclarations-in-ifstatement-statement-clauses
7 es6id: B.3.3
8 flags: [generated, noStrict]
9 info: |
10 The following rules for IfStatement augment those in 13.6:
11
12 IfStatement[Yield, Return]:
13 if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return]
14 if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield]
15 if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield]
16 if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield]
17
18
19 13.2.14 Runtime Semantics: BlockDeclarationInstantiation
20
21 [...]
22 4. For each element d in declarations do
23 a. For each element dn of the BoundNames of d do
24 i. If IsConstantDeclaration of d is true, then
25 [...]
26 ii. Else,
27 2. Perform ! envRec.CreateMutableBinding(dn, false).
28
29 b. If d is a GeneratorDeclaration production or a FunctionDeclaration
30 production, then
31 i. Let fn be the sole element of the BoundNames of d.
32 ii. Let fo be the result of performing InstantiateFunctionObject for
33 d with argument env.
34 iii. Perform envRec.InitializeBinding(fn, fo).
35 ---*/
36 var initialBV, currentBV;
37
38 (0,eval)(
39 'if (true) function f() { initialBV = f; f = 123; currentBV = f; return "decl"; } else function _f() {}'
40 );
41
42 f();
43
44 assert.sameValue(
45 initialBV(),
46 'decl',
47 'Block-scoped binding value is function object at execution time'
48 );
49 assert.sameValue(currentBV, 123, 'Block-scoped binding is mutable');
50 assert.sameValue(
51 f(),
52 'decl',
53 'Block-scoped binding is independent of outer var-scoped binding'
54 );