2015-02-19 16:49:11 +00:00
|
|
|
// 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.
|
|
|
|
|
2015-09-30 19:49:46 +00:00
|
|
|
// Flags: --strong-mode
|
2015-02-19 16:49:11 +00:00
|
|
|
|
|
|
|
'use strong';
|
|
|
|
|
|
|
|
class C {}
|
|
|
|
|
2015-04-13 17:25:18 +00:00
|
|
|
let indirect_eval = eval;
|
|
|
|
|
2015-03-13 16:26:38 +00:00
|
|
|
function assertTypeError(script) { assertThrows(script, TypeError) }
|
|
|
|
function assertSyntaxError(script) { assertThrows(script, SyntaxError) }
|
|
|
|
function assertReferenceError(script) { assertThrows(script, ReferenceError) }
|
|
|
|
|
2015-02-19 16:49:11 +00:00
|
|
|
(function ImmutableClassBindings() {
|
|
|
|
class D {}
|
2015-04-13 17:25:18 +00:00
|
|
|
assertTypeError(function(){ indirect_eval("C = 0") });
|
2015-02-19 16:49:11 +00:00
|
|
|
assertEquals('function', typeof C);
|
|
|
|
assertEquals('function', typeof D);
|
2015-04-13 17:25:18 +00:00
|
|
|
assertTypeError("'use strong'; (function f() {class E {}; E = 0})()");
|
2015-02-19 16:49:11 +00:00
|
|
|
})();
|
2015-03-13 16:26:38 +00:00
|
|
|
|
|
|
|
function constructor(body) {
|
|
|
|
return "'use strong'; " +
|
|
|
|
"(class extends Object { constructor() { " + body + " } })";
|
|
|
|
}
|
|
|
|
|
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; } }"));
|
|
|
|
})();
|
|
|
|
|
2015-03-13 16:26:38 +00:00
|
|
|
(function NoMissingSuper() {
|
|
|
|
assertReferenceError(constructor(""));
|
|
|
|
assertReferenceError(constructor("1"));
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function NoNestedSuper() {
|
2015-04-22 11:04:25 +00:00
|
|
|
assertSyntaxError(constructor("super(), 0;"));
|
2015-03-19 19:39:53 +00:00
|
|
|
assertSyntaxError(constructor("(super());"));
|
2015-04-22 11:04:25 +00:00
|
|
|
assertSyntaxError(constructor("super().a;"));
|
2015-03-19 19:39:53 +00:00
|
|
|
assertSyntaxError(constructor("(() => super())();"));
|
|
|
|
assertSyntaxError(constructor("{ super(); }"));
|
2015-03-13 16:26:38 +00:00
|
|
|
assertSyntaxError(constructor("if (1) super();"));
|
2015-04-22 11:04:25 +00:00
|
|
|
assertSyntaxError(constructor("label: super();"));
|
2015-03-13 16:26:38 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function NoDuplicateSuper() {
|
|
|
|
assertSyntaxError(constructor("super(), super();"));
|
|
|
|
assertSyntaxError(constructor("super(); super();"));
|
|
|
|
assertSyntaxError(constructor("super(); (super());"));
|
|
|
|
assertSyntaxError(constructor("super(); { super() }"));
|
2015-03-19 19:39:53 +00:00
|
|
|
assertSyntaxError(constructor("super(); (() => super())();"));
|
|
|
|
})();
|
|
|
|
|
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);"));
|
|
|
|
})();
|
|
|
|
|
2015-03-19 19:39:53 +00:00
|
|
|
(function NoReturnValue() {
|
|
|
|
assertSyntaxError(constructor("return {};"));
|
|
|
|
assertSyntaxError(constructor("return undefined;"));
|
2015-04-22 11:04:25 +00:00
|
|
|
assertSyntaxError(constructor("return this;"));
|
|
|
|
assertSyntaxError(constructor("return this.a = 0;"));
|
2015-03-19 19:39:53 +00:00
|
|
|
assertSyntaxError(constructor("{ return {}; }"));
|
|
|
|
assertSyntaxError(constructor("if (1) return {};"));
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function NoReturnBeforeSuper() {
|
|
|
|
assertSyntaxError(constructor("return; super();"));
|
|
|
|
assertSyntaxError(constructor("if (0) return; super();"));
|
|
|
|
assertSyntaxError(constructor("{ return; } super();"));
|
2015-03-13 16:26:38 +00:00
|
|
|
})();
|
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;"));
|
|
|
|
})();
|