v8/test/mjsunit/strong/classes.js

119 lines
4.4 KiB
JavaScript
Raw Normal View History

// 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.
// Flags: --strong-mode
'use strong';
class C {}
let indirect_eval = eval;
function assertTypeError(script) { assertThrows(script, TypeError) }
function assertSyntaxError(script) { assertThrows(script, SyntaxError) }
function assertReferenceError(script) { assertThrows(script, ReferenceError) }
(function ImmutableClassBindings() {
class D {}
assertTypeError(function(){ indirect_eval("C = 0") });
assertEquals('function', typeof C);
assertEquals('function', typeof D);
assertTypeError("'use strong'; (function f() {class E {}; E = 0})()");
})();
function constructor(body) {
return "'use strong'; " +
"(class extends Object { constructor() { " + body + " } })";
}
Revert of Revert of [strong] checking of this & super in constructors (patchset #1 id:1 of https://codereview.chromium.org/1105453002/) Reason for revert: Was an infrastructure problem. Original issue's description: > Revert of [strong] checking of this & super in constructors (patchset #7 id:110001 of https://codereview.chromium.org/1024063002/) > > Reason for revert: > [Sheriff] Breaks mac gc stress: > http://build.chromium.org/p/client.v8/builders/V8%20Mac%20GC%20Stress/builds/1024 > > Original issue's description: > > [strong] checking of this & super in constructors > > > > R=dslomov@chromium.org, marja@chromium.org > > BUG=v8:3956 > > LOG=N > > > > Enforces for constructors that > > - the only use of 'super' is the super constructor call > > - the only use of 'this' is a property assignment > > - both of these must happen at the top-level of the body > > - 'this' may only be assigned after the 'super' call > > - 'return' may only be used after the last assignment to 'this' > > > > Not yet working for arrow functions (there might be deeper bugs with those). > > > > Committed: https://crrev.com/580d66bcda66220d2f3062ac58daf925436df74c > > Cr-Commit-Position: refs/heads/master@{#27977} > > TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=v8:3956 TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=v8:3956 Review URL: https://codereview.chromium.org/1073103004 Cr-Commit-Position: refs/heads/master@{#28001}
2015-04-22 11:04:25 +00:00
(function NoSuperExceptCall() {
assertSyntaxError(constructor("super.a;"));
assertSyntaxError(constructor("super['a'];"));
assertSyntaxError(constructor("super.f();"));
assertSyntaxError(constructor("super.a;"));
assertSyntaxError(constructor("{ super.a }"));
assertSyntaxError(constructor("if (0) super.a;"));
// TODO(rossberg): arrow functions do not handle 'super' yet.
// assertSyntaxError(constructor("() => super.a;"));
// assertSyntaxError(constructor("() => () => super.a;"));
// assertSyntaxError(constructor("() => { () => if (0) { super.a; } }"));
})();
(function NoMissingSuper() {
assertReferenceError(constructor(""));
assertReferenceError(constructor("1"));
})();
(function NoNestedSuper() {
Revert of Revert of [strong] checking of this & super in constructors (patchset #1 id:1 of https://codereview.chromium.org/1105453002/) Reason for revert: Was an infrastructure problem. Original issue's description: > Revert of [strong] checking of this & super in constructors (patchset #7 id:110001 of https://codereview.chromium.org/1024063002/) > > Reason for revert: > [Sheriff] Breaks mac gc stress: > http://build.chromium.org/p/client.v8/builders/V8%20Mac%20GC%20Stress/builds/1024 > > Original issue's description: > > [strong] checking of this & super in constructors > > > > R=dslomov@chromium.org, marja@chromium.org > > BUG=v8:3956 > > LOG=N > > > > Enforces for constructors that > > - the only use of 'super' is the super constructor call > > - the only use of 'this' is a property assignment > > - both of these must happen at the top-level of the body > > - 'this' may only be assigned after the 'super' call > > - 'return' may only be used after the last assignment to 'this' > > > > Not yet working for arrow functions (there might be deeper bugs with those). > > > > Committed: https://crrev.com/580d66bcda66220d2f3062ac58daf925436df74c > > Cr-Commit-Position: refs/heads/master@{#27977} > > TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=v8:3956 TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=v8:3956 Review URL: https://codereview.chromium.org/1073103004 Cr-Commit-Position: refs/heads/master@{#28001}
2015-04-22 11:04:25 +00:00
assertSyntaxError(constructor("super(), 0;"));
assertSyntaxError(constructor("(super());"));
Revert of Revert of [strong] checking of this & super in constructors (patchset #1 id:1 of https://codereview.chromium.org/1105453002/) Reason for revert: Was an infrastructure problem. Original issue's description: > Revert of [strong] checking of this & super in constructors (patchset #7 id:110001 of https://codereview.chromium.org/1024063002/) > > Reason for revert: > [Sheriff] Breaks mac gc stress: > http://build.chromium.org/p/client.v8/builders/V8%20Mac%20GC%20Stress/builds/1024 > > Original issue's description: > > [strong] checking of this & super in constructors > > > > R=dslomov@chromium.org, marja@chromium.org > > BUG=v8:3956 > > LOG=N > > > > Enforces for constructors that > > - the only use of 'super' is the super constructor call > > - the only use of 'this' is a property assignment > > - both of these must happen at the top-level of the body > > - 'this' may only be assigned after the 'super' call > > - 'return' may only be used after the last assignment to 'this' > > > > Not yet working for arrow functions (there might be deeper bugs with those). > > > > Committed: https://crrev.com/580d66bcda66220d2f3062ac58daf925436df74c > > Cr-Commit-Position: refs/heads/master@{#27977} > > TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=v8:3956 TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=v8:3956 Review URL: https://codereview.chromium.org/1073103004 Cr-Commit-Position: refs/heads/master@{#28001}
2015-04-22 11:04:25 +00:00
assertSyntaxError(constructor("super().a;"));
assertSyntaxError(constructor("(() => super())();"));
assertSyntaxError(constructor("{ super(); }"));
assertSyntaxError(constructor("if (1) super();"));
Revert of Revert of [strong] checking of this & super in constructors (patchset #1 id:1 of https://codereview.chromium.org/1105453002/) Reason for revert: Was an infrastructure problem. Original issue's description: > Revert of [strong] checking of this & super in constructors (patchset #7 id:110001 of https://codereview.chromium.org/1024063002/) > > Reason for revert: > [Sheriff] Breaks mac gc stress: > http://build.chromium.org/p/client.v8/builders/V8%20Mac%20GC%20Stress/builds/1024 > > Original issue's description: > > [strong] checking of this & super in constructors > > > > R=dslomov@chromium.org, marja@chromium.org > > BUG=v8:3956 > > LOG=N > > > > Enforces for constructors that > > - the only use of 'super' is the super constructor call > > - the only use of 'this' is a property assignment > > - both of these must happen at the top-level of the body > > - 'this' may only be assigned after the 'super' call > > - 'return' may only be used after the last assignment to 'this' > > > > Not yet working for arrow functions (there might be deeper bugs with those). > > > > Committed: https://crrev.com/580d66bcda66220d2f3062ac58daf925436df74c > > Cr-Commit-Position: refs/heads/master@{#27977} > > TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=v8:3956 TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=v8:3956 Review URL: https://codereview.chromium.org/1073103004 Cr-Commit-Position: refs/heads/master@{#28001}
2015-04-22 11:04:25 +00:00
assertSyntaxError(constructor("label: super();"));
})();
(function NoDuplicateSuper() {
assertSyntaxError(constructor("super(), super();"));
assertSyntaxError(constructor("super(); super();"));
assertSyntaxError(constructor("super(); (super());"));
assertSyntaxError(constructor("super(); { super() }"));
assertSyntaxError(constructor("super(); (() => super())();"));
})();
Revert of Revert of [strong] checking of this & super in constructors (patchset #1 id:1 of https://codereview.chromium.org/1105453002/) Reason for revert: Was an infrastructure problem. Original issue's description: > Revert of [strong] checking of this & super in constructors (patchset #7 id:110001 of https://codereview.chromium.org/1024063002/) > > Reason for revert: > [Sheriff] Breaks mac gc stress: > http://build.chromium.org/p/client.v8/builders/V8%20Mac%20GC%20Stress/builds/1024 > > Original issue's description: > > [strong] checking of this & super in constructors > > > > R=dslomov@chromium.org, marja@chromium.org > > BUG=v8:3956 > > LOG=N > > > > Enforces for constructors that > > - the only use of 'super' is the super constructor call > > - the only use of 'this' is a property assignment > > - both of these must happen at the top-level of the body > > - 'this' may only be assigned after the 'super' call > > - 'return' may only be used after the last assignment to 'this' > > > > Not yet working for arrow functions (there might be deeper bugs with those). > > > > Committed: https://crrev.com/580d66bcda66220d2f3062ac58daf925436df74c > > Cr-Commit-Position: refs/heads/master@{#27977} > > TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=v8:3956 TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=v8:3956 Review URL: https://codereview.chromium.org/1073103004 Cr-Commit-Position: refs/heads/master@{#28001}
2015-04-22 11:04:25 +00:00
(function NoSuperAfterThis() {
assertSyntaxError(constructor("this.a = 0, super();"));
assertSyntaxError(constructor("this.a = 0; super();"));
assertSyntaxError(constructor("this.a = 0; super(); this.b = 0;"));
assertSyntaxError(constructor("this.a = 0; (super());"));
assertSyntaxError(constructor("super(this.a = 0);"));
})();
(function NoReturnValue() {
assertSyntaxError(constructor("return {};"));
assertSyntaxError(constructor("return undefined;"));
Revert of Revert of [strong] checking of this & super in constructors (patchset #1 id:1 of https://codereview.chromium.org/1105453002/) Reason for revert: Was an infrastructure problem. Original issue's description: > Revert of [strong] checking of this & super in constructors (patchset #7 id:110001 of https://codereview.chromium.org/1024063002/) > > Reason for revert: > [Sheriff] Breaks mac gc stress: > http://build.chromium.org/p/client.v8/builders/V8%20Mac%20GC%20Stress/builds/1024 > > Original issue's description: > > [strong] checking of this & super in constructors > > > > R=dslomov@chromium.org, marja@chromium.org > > BUG=v8:3956 > > LOG=N > > > > Enforces for constructors that > > - the only use of 'super' is the super constructor call > > - the only use of 'this' is a property assignment > > - both of these must happen at the top-level of the body > > - 'this' may only be assigned after the 'super' call > > - 'return' may only be used after the last assignment to 'this' > > > > Not yet working for arrow functions (there might be deeper bugs with those). > > > > Committed: https://crrev.com/580d66bcda66220d2f3062ac58daf925436df74c > > Cr-Commit-Position: refs/heads/master@{#27977} > > TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=v8:3956 TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=v8:3956 Review URL: https://codereview.chromium.org/1073103004 Cr-Commit-Position: refs/heads/master@{#28001}
2015-04-22 11:04:25 +00:00
assertSyntaxError(constructor("return this;"));
assertSyntaxError(constructor("return this.a = 0;"));
assertSyntaxError(constructor("{ return {}; }"));
assertSyntaxError(constructor("if (1) return {};"));
})();
(function NoReturnBeforeSuper() {
assertSyntaxError(constructor("return; super();"));
assertSyntaxError(constructor("if (0) return; super();"));
assertSyntaxError(constructor("{ return; } super();"));
})();
Revert of Revert of [strong] checking of this & super in constructors (patchset #1 id:1 of https://codereview.chromium.org/1105453002/) Reason for revert: Was an infrastructure problem. Original issue's description: > Revert of [strong] checking of this & super in constructors (patchset #7 id:110001 of https://codereview.chromium.org/1024063002/) > > Reason for revert: > [Sheriff] Breaks mac gc stress: > http://build.chromium.org/p/client.v8/builders/V8%20Mac%20GC%20Stress/builds/1024 > > Original issue's description: > > [strong] checking of this & super in constructors > > > > R=dslomov@chromium.org, marja@chromium.org > > BUG=v8:3956 > > LOG=N > > > > Enforces for constructors that > > - the only use of 'super' is the super constructor call > > - the only use of 'this' is a property assignment > > - both of these must happen at the top-level of the body > > - 'this' may only be assigned after the 'super' call > > - 'return' may only be used after the last assignment to 'this' > > > > Not yet working for arrow functions (there might be deeper bugs with those). > > > > Committed: https://crrev.com/580d66bcda66220d2f3062ac58daf925436df74c > > Cr-Commit-Position: refs/heads/master@{#27977} > > TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=v8:3956 TBR=dslomov@chromium.org,marja@chromium.org,conradw@chromium.org,rossberg@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=v8:3956 Review URL: https://codereview.chromium.org/1073103004 Cr-Commit-Position: refs/heads/master@{#28001}
2015-04-22 11:04:25 +00:00
(function NoReturnBeforeThis() {
assertSyntaxError(constructor("return; this.a = 0;"));
assertSyntaxError(constructor("if (0) return; this.a = 0;"));
assertSyntaxError(constructor("{ return; } this.a = 0;"));
})();
(function NoThisExceptInitialization() {
assertSyntaxError(constructor("this;"));
assertSyntaxError(constructor("this.a;"));
assertSyntaxError(constructor("this['a'];"));
assertSyntaxError(constructor("this();"));
assertSyntaxError(constructor("this.a();"));
assertSyntaxError(constructor("this.a.b = 0;"));
assertSyntaxError(constructor("{ this }"));
assertSyntaxError(constructor("if (0) this;"));
// TODO(rossberg): this does not handle arrow functions yet.
// assertSyntaxError(constructor("() => this;"));
// assertSyntaxError(constructor("() => () => this;"));
// assertSyntaxError(constructor("() => { () => if (0) { this; } }"));
})();
(function NoNestedThis() {
assertSyntaxError(constructor("(this.a = 0);"));
assertSyntaxError(constructor("{ this.a = 0; }"));
assertSyntaxError(constructor("if (0) this.a = 0;"));
// TODO(rossberg): this does not handle arrow functions yet.
// assertSyntaxError(constructor("() => this.a = 0;"));
// assertSyntaxError(constructor("() => { this.a = 0; }"));
assertSyntaxError(constructor("label: this.a = 0;"));
})();