| 1 |
// This file was procedurally generated from the following sources: |
| 2 |
// - src/annex-b-fns/eval-func-init.case |
| 3 |
// - src/annex-b-fns/eval-func/direct-if-decl-else-stmt.template |
| 4 |
/*--- |
| 5 |
description: Variable binding is initialized to `undefined` in outer scope (IfStatement with a declaration in the first statement position in eval code) |
| 6 |
esid: sec-functiondeclarations-in-ifstatement-statement-clauses |
| 7 |
es6id: B.3.4 |
| 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 |
B.3.3.3 Changes to EvalDeclarationInstantiation |
| 20 |
|
| 21 |
[...] |
| 22 |
a. If declaredFunctionOrVarNames does not contain F, then |
| 23 |
i. If varEnvRec is a global Environment Record, then |
| 24 |
[...] |
| 25 |
ii. Else, |
| 26 |
i. Let bindingExists be varEnvRec.HasBinding(F). |
| 27 |
ii. If bindingExists is false, then |
| 28 |
i. Perform ! varEnvRec.CreateMutableBinding(F, true). |
| 29 |
ii. Perform ! varEnvRec.InitializeBinding(F, undefined). |
| 30 |
[...] |
| 31 |
---*/ |
| 32 |
var init, changed; |
| 33 |
|
| 34 |
(function() { |
| 35 |
eval( |
| 36 |
'init = f;\ |
| 37 |
f = 123;\ |
| 38 |
changed = f;if (true) function f() { } else ;' |
| 39 |
); |
| 40 |
}()); |
| 41 |
|
| 42 |
assert.sameValue(init, undefined, 'binding is initialized to `undefined`'); |
| 43 |
assert.sameValue(changed, 123, 'binding is mutable'); |
| 44 |
assert.throws(ReferenceError, function() { |
| 45 |
f; |
| 46 |
}, 'global binding is not created'); |