func-if-decl-else-stmt-eval-func-existing-fn-update.js (1871B)
1 // This file was procedurally generated from the following sources: 2 // - src/annex-b-fns/eval-func-existing-fn-update.case 3 // - src/annex-b-fns/eval-func/direct-if-decl-else-stmt.template 4 /*--- 5 description: Variable-scoped binding is updated following evaluation (IfStatement with a declaration in the first statement position in eval code) 6 esid: sec-functiondeclarations-in-ifstatement-statement-clauses 7 flags: [generated, noStrict] 8 info: | 9 The following rules for IfStatement augment those in 13.6: 10 11 IfStatement[Yield, Return]: 12 if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else Statement[?Yield, ?Return] 13 if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else FunctionDeclaration[?Yield] 14 if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] else FunctionDeclaration[?Yield] 15 if ( Expression[In, ?Yield] ) FunctionDeclaration[?Yield] 16 17 18 B.3.3.3 Changes to EvalDeclarationInstantiation 19 20 [...] 21 b. When the FunctionDeclaration f is evaluated, perform the following steps 22 in place of the FunctionDeclaration Evaluation algorithm provided in 23 14.1.21: 24 i. Let genv be the running execution context's VariableEnvironment. 25 ii. Let genvRec be genv's EnvironmentRecord. 26 iii. Let benv be the running execution context's LexicalEnvironment. 27 iv. Let benvRec be benv's EnvironmentRecord. 28 v. Let fobj be ! benvRec.GetBindingValue(F, false). 29 vi. Perform ? genvRec.SetMutableBinding(F, fobj, false). 30 vii. Return NormalCompletion(empty). 31 ---*/ 32 var after; 33 34 (function() { 35 eval( 36 'if (true) function f() { return "inner declaration"; } else ;after = f;\ 37 \ 38 function f() {\ 39 return "outer declaration";\ 40 }' 41 ); 42 }()); 43 44 assert.sameValue(typeof after, 'function'); 45 assert.sameValue(after(), 'inner declaration'); 46 47 reportCompare(0, 0);