v8/test/mjsunit/es6/block-scope-class.js
littledan 23235b5fdb Reland of Ship ES2015 sloppy-mode function hoisting, let, class (patchset #1 id:1 of https://codereview.chromium.org/1565263002/ )
Reason for revert:
Crash fixed by https://codereview.chromium.org/1564923007

Original issue's description:
> Revert of Ship ES2015 sloppy-mode function hoisting, let, class (patchset #7 id:120001 of https://codereview.chromium.org/1551443002/ )
>
> Reason for revert:
> Causes frequent crashes in Canary: chromium:537816
>
> Original issue's description:
> > Ship ES2015 sloppy-mode function hoisting, let, class
> >
> > This patch doesn't ship all features of ES2015 variable/scoping
> > changes, notably omitting the removal of legacy const. I think
> > function hoisting, let and class in sloppy mode can stand to
> > themselves as a package, and the legacy const change is much
> > riskier and more likely to be reverted, so my intention is to
> > pursue those as a separate, follow-on patch.
> >
> > R=adamk@chromium.org
> > BUG=v8:4285,v8:3305
> > LOG=Y
> > CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_chromium_rel_ng;tryserver.blink:linux_blink_rel
> >
> > Committed: https://crrev.com/fcff8588a5a01587643d6c2507c7b882c78a2957
> > Cr-Commit-Position: refs/heads/master@{#33133}
>
> TBR=adamk@chromium.org
> # Not skipping CQ checks because original CL landed more than 1 days ago.
> BUG=v8:4285,v8:3305,chromium:537816
> LOG=Y
>
> Committed: https://crrev.com/adac5956c6216056a211cfaa460a00ac1500d8f8
> Cr-Commit-Position: refs/heads/master@{#33162}

TBR=adamk@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:4285,v8:3305,chromium:537816

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

Cr-Commit-Position: refs/heads/master@{#33189}
2016-01-08 17:34:59 +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;")
})();