non-definable-global-var.js (1183B)
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: Throws a TypeError if a global variable cannot be defined. 7 info: | 8 Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict) 9 10 ... 11 10. For each d in varDeclarations, do 12 a. If d is a VariableDeclaration or a ForBinding, then 13 i. For each String vn in the BoundNames of d, do 14 1. If vn is not an element of declaredFunctionNames, then 15 a. If varEnvRec is a global Environment Record, then 16 i. Let vnDefinable be varEnvRec.CanDeclareGlobalVar(vn). 17 ii. ReturnIfAbrupt(vnDefinable). 18 iii. If vnDefinable is false, throw TypeError exception. 19 ... 20 ---*/ 21 22 var nonExtensible; 23 try { 24 Object.preventExtensions(this); 25 nonExtensible = !Object.isExtensible(this); 26 } catch (e) { 27 nonExtensible = false; 28 } 29 30 // Run test if global object is non-extensible. 31 if (nonExtensible) { 32 assert.throws(TypeError, function() { 33 (0,eval)("var unlikelyVariableName;"); 34 }); 35 } 36 37 reportCompare(0, 0);