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