Debian Codegraph @

js/src/tests/test262/language/global-code/script-decl-var-collision.js

raw
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-globaldeclarationinstantiation
5 es6id: 15.1.8
6 description: Var binding collision with existing lexical declaration
7 info: |
8 [...]
9 6. For each name in varNames, do
10 a. If envRec.HasLexicalDeclaration(name) is true, throw a SyntaxError
11 exception.
12 ---*/
13
14 var test262Var;
15 let test262Let;
16 const test262Const = null;
17 class test262Class {}
18
19 $262.evalScript('var test262Var;');
20 $262.evalScript('function test262Var() {}');
21
22 assert.throws(SyntaxError, function() {
23 $262.evalScript('var x; var test262Let;');
24 }, '`var` on `let` binding');
25 assert.throws(ReferenceError, function() {
26 x;
27 }, 'no bindings created (script declaring a `var` on a `let` binding)');
28
29 assert.throws(SyntaxError, function() {
30 $262.evalScript('var x; var test262Const;');
31 }, '`var` on `const` binding');
32 assert.throws(ReferenceError, function() {
33 x;
34 }, 'no bindings created (script declaring a `var` on a `const` binding)');
35
36 assert.throws(SyntaxError, function() {
37 $262.evalScript('var x; var test262Class;');
38 }, '`var` on `class` binding');
39 assert.throws(ReferenceError, function() {
40 x;
41 }, 'no bindings created (script declaring a `var` on a `class` binding)');
42
43 assert.throws(SyntaxError, function() {
44 $262.evalScript('var x; function test262Let() {}');
45 }, 'function on `let` binding');
46 assert.throws(ReferenceError, function() {
47 x;
48 }, 'no bindings created (script declaring a function on a `let` binding)');
49
50 assert.throws(SyntaxError, function() {
51 $262.evalScript('var x; function test262Const() {}');
52 }, 'function on `const` binding');
53 assert.throws(ReferenceError, function() {
54 x;
55 }, 'no bindings created (script declaring a function on a `const` binding)');
56
57 assert.throws(SyntaxError, function() {
58 $262.evalScript('var x; function test262Class() {}');
59 } , 'function on `class` binding');
60 assert.throws(ReferenceError, function() {
61 x;
62 }, 'no bindings created (script declaring a function on a class binding)');
63
64 reportCompare(0, 0);