summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/global-code/script-decl-var-collision.js
blob: dcc247e536aab79cb5a154636d5759596754f8c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-globaldeclarationinstantiation
es6id: 15.1.8
description: Var binding collision with existing lexical declaration
info: |
  [...]
  6. For each name in varNames, do
     a. If envRec.HasLexicalDeclaration(name) is true, throw a SyntaxError
        exception.
---*/

var test262Var;
let test262Let;
const test262Const = null;
class test262Class {}

$262.evalScript('var test262Var;');
$262.evalScript('function test262Var() {}');

assert.throws(SyntaxError, function() {
  $262.evalScript('var x; var test262Let;');
}, '`var` on `let` binding');
assert.throws(ReferenceError, function() {
  x;
}, 'no bindings created (script declaring a `var` on a `let` binding)');

assert.throws(SyntaxError, function() {
  $262.evalScript('var x; var test262Const;');
}, '`var` on `const` binding');
assert.throws(ReferenceError, function() {
  x;
}, 'no bindings created (script declaring a `var` on a `const` binding)');

assert.throws(SyntaxError, function() {
  $262.evalScript('var x; var test262Class;');
}, '`var` on `class` binding');
assert.throws(ReferenceError, function() {
  x;
}, 'no bindings created (script declaring a `var` on a `class` binding)');

assert.throws(SyntaxError, function() {
  $262.evalScript('var x; function test262Let() {}');
}, 'function on `let` binding');
assert.throws(ReferenceError, function() {
  x;
}, 'no bindings created (script declaring a function on a `let` binding)');

assert.throws(SyntaxError, function() {
  $262.evalScript('var x; function test262Const() {}');
}, 'function on `const` binding');
assert.throws(ReferenceError, function() {
  x;
}, 'no bindings created (script declaring a function on a `const` binding)');

assert.throws(SyntaxError, function() {
  $262.evalScript('var x; function test262Class() {}');
} , 'function on `class` binding');
assert.throws(ReferenceError, function() {
  x;
}, 'no bindings created (script declaring a function on a class binding)');

reportCompare(0, 0);