Debian Codegraph @

js/src/tests/test262/language/eval-code/direct/non-definable-global-var.js

raw
1 // Copyright (C) 2015 André Bargull. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
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 flags: [noStrict]
21 ---*/
22
23 var nonExtensible;
24 try {
25 Object.preventExtensions(this);
26 nonExtensible = !Object.isExtensible(this);
27 } catch (e) {
28 nonExtensible = false;
29 }
30
31 // Run test if global object is non-extensible.
32 if (nonExtensible) {
33 var error;
34 try {
35 eval("var unlikelyVariableName");
36 } catch (e) {
37 error = e;
38 }
39
40 assert(error instanceof TypeError);
41 }
42
43 reportCompare(0, 0);