v8/test/mjsunit/harmony/block-scope-class.js
littledan 1ebf0d7c5d Split function block scoping into a separate flag
In an initial attempt to implement sloppy mode lexical bindings,
functions were made lexically scoped in sloppy mode. However, the
ES2015 spec says that they need an additional hoisted var binding,
and further, it's not clear when we'll implement that behavior
or whether it's web-compatible.

This patch splits off function block scoping into a new, separate
flag called --harmony_sloppy_function. This change will enable the
possibility of testing and shipping this feature separately from
other block scoping-related features which don't have the same risks.

BUG=v8:4285
R=adamk
LOG=N

Review URL: https://codereview.chromium.org/1282093002

Cr-Commit-Position: refs/heads/master@{#30122}
2015-08-12 00:00:01 +00:00

60 lines
2.5 KiB
JavaScript

// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test for conflicting variable bindings.
// Flags: --harmony-sloppy --harmony-sloppy-function
function AssertEqualsStrictAndSloppy(value, code) {
assertEquals(value, eval("(function() {" + code + "})()"));
assertEquals(value, eval("(function() { 'use strict'; " + code + "})()"));
assertEquals(value, eval("(function() { var x = 0; {" + code + "} })()"));
assertEquals(value, eval("(function() { 'use strict'; var x = 0; {"
+ code + "} })()"));
}
function AssertThrowsStrictAndSloppy(code, error) {
assertThrows("(function() {" + code + "})()", error);
assertThrows("(function() { 'use strict'; " + code + "})()", error);
assertThrows("(function() { var x = 0; { " + code + "} })()", error);
assertThrows("(function() { 'use strict'; var x = 0; {" + code + "} })()",
error);
}
(function TestClassTDZ() {
AssertEqualsStrictAndSloppy(
"x", "function f() { return x; }; class x { }; return f().name;");
AssertEqualsStrictAndSloppy
("x", "class x { }; function f() { return x; }; return f().name;");
AssertEqualsStrictAndSloppy(
"x", "class x { }; var result = f().name; " +
"function f() { return x; }; return result;");
AssertThrowsStrictAndSloppy(
"function f() { return x; }; f(); class x { };", ReferenceError);
AssertThrowsStrictAndSloppy(
"f(); function f() { return x; }; class x { };", ReferenceError);
AssertThrowsStrictAndSloppy(
"f(); class x { }; function f() { return x; };", ReferenceError);
AssertThrowsStrictAndSloppy(
"var x = 1; { f(); class x { }; function f() { return x; }; }",
ReferenceError);
AssertThrowsStrictAndSloppy("x = 3; class x { };", ReferenceError)
})();
(function TestClassNameConflict() {
AssertThrowsStrictAndSloppy("class x { }; var x;", SyntaxError);
AssertThrowsStrictAndSloppy("var x; class x { };", SyntaxError);
AssertThrowsStrictAndSloppy("class x { }; function x() { };", SyntaxError);
AssertThrowsStrictAndSloppy("function x() { }; class x { };", SyntaxError);
AssertThrowsStrictAndSloppy("class x { }; for (var x = 0; false;) { };",
SyntaxError);
AssertThrowsStrictAndSloppy("for (var x = 0; false;) { }; class x { };",
SyntaxError);
})();
(function TestClassMutableBinding() {
AssertEqualsStrictAndSloppy(
"x3", "class x { }; var y = x.name; x = 3; return y + x;")
})();