test262/test/language/global-code/script-decl-var-collision.js
jugglinmike b9e21138cc Add tests for script interactions (#689)
ECMA262 allows for an arbitrary number of "ScriptJob"s to run in a given realm.
Although there is no standard mechanism for enqueuing these jobs, many
implementations offer this functionality through custom APIs. In those hosts,
the semantics describing script interactions are directly observable.
In order to guarantee conformance to the specification in advance of a
standardized API, Test262 now requires that hosts provide a $.evalScript
function whose behavior is defined in the project's "INTERPRETING.md" file.
Use this host-provided API to ensure that implementations correctly observe the
specification text that dictates script interactions.
(In writing these tests, I noticed some gaps in coverage that are observable
from a single script execution. This patch includes a dedicated commit for
these tests that do not require $.evalScript.)

* Improve coverage of GlobalDeclarationInstantiation

* Add tests for script interactions

Use the host-provied `$.evalScript` method to assert conformance to the
specification text that defines script interactions.

* fixup! Improve coverage of GlobalDeclarationInstantiation
2016-07-19 18:02:05 -07:00

63 lines
2.0 KiB
JavaScript

// 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 {}
$.evalScript('var test262Var;');
$.evalScript('function test262Var() {}');
assert.throws(SyntaxError, function() {
$.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() {
$.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() {
$.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() {
$.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() {
$.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() {
$.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)');