non-definable-function-with-variable.js (1732B)
1 // Copyright (C) 2016 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-evaldeclarationinstantiation 5 es6id: 18.2.1.2 6 description: > 7 Global variables are not created if conflicting function declarations were 8 detected. 9 info: | 10 Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict) 11 12 ... 13 8. For each d in varDeclarations, in reverse list order do 14 a. If d is neither a VariableDeclaration or a ForBinding, then 15 i. Assert: d is either a FunctionDeclaration or a GeneratorDeclaration. 16 ii. NOTE If there are multiple FunctionDeclarations for the same name, the last declaration is used. 17 iii. Let fn be the sole element of the BoundNames of d. 18 iv. If fn is not an element of declaredFunctionNames, then 19 1. If varEnvRec is a global Environment Record, then 20 a. Let fnDefinable be varEnvRec.CanDeclareGlobalFunction(fn). 21 b. ReturnIfAbrupt(fnDefinable). 22 c. If fnDefinable is false, throw TypeError exception. 23 ... 24 15. For each String vn in declaredVarNames, in list order do 25 a. If varEnvRec is a global Environment Record, then 26 i. Let status be varEnvRec.CreateGlobalVarBinding(vn, true). 27 ii. ReturnIfAbrupt(status). 28 ... 29 ---*/ 30 31 try { 32 (0,eval)("var shouldNotBeDefined1; function NaN() {} var shouldNotBeDefined2;"); 33 } catch (e) { 34 // Ignore TypeError exception. 35 } 36 37 assert.sameValue( 38 Object.getOwnPropertyDescriptor(this, "shouldNotBeDefined1"), 39 undefined, 40 "declaration preceding" 41 ); 42 assert.sameValue( 43 Object.getOwnPropertyDescriptor(this, "shouldNotBeDefined2"), 44 undefined, 45 "declaration following" 46 ); 47 48 reportCompare(0, 0);