| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --strong-mode | 5 // Flags: --strong-mode |
| 6 // Flags: --harmony-classes --harmony-arrow-functions | 6 // Flags: --harmony-classes --harmony-arrow-functions |
| 7 | 7 |
| 8 'use strong'; | 8 'use strong'; |
| 9 | 9 |
| 10 class C {} | 10 class C {} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 assertEquals('function', typeof C); | 21 assertEquals('function', typeof C); |
| 22 assertEquals('function', typeof D); | 22 assertEquals('function', typeof D); |
| 23 assertTypeError("'use strong'; (function f() {class E {}; E = 0})()"); | 23 assertTypeError("'use strong'; (function f() {class E {}; E = 0})()"); |
| 24 })(); | 24 })(); |
| 25 | 25 |
| 26 function constructor(body) { | 26 function constructor(body) { |
| 27 return "'use strong'; " + | 27 return "'use strong'; " + |
| 28 "(class extends Object { constructor() { " + body + " } })"; | 28 "(class extends Object { constructor() { " + body + " } })"; |
| 29 } | 29 } |
| 30 | 30 |
| 31 (function NoSuperExceptCall() { | |
| 32 assertSyntaxError(constructor("super.a;")); | |
| 33 assertSyntaxError(constructor("super['a'];")); | |
| 34 assertSyntaxError(constructor("super.f();")); | |
| 35 assertSyntaxError(constructor("super.a;")); | |
| 36 assertSyntaxError(constructor("{ super.a }")); | |
| 37 assertSyntaxError(constructor("if (0) super.a;")); | |
| 38 // TODO(rossberg): arrow functions do not handle 'super' yet. | |
| 39 // assertSyntaxError(constructor("() => super.a;")); | |
| 40 // assertSyntaxError(constructor("() => () => super.a;")); | |
| 41 // assertSyntaxError(constructor("() => { () => if (0) { super.a; } }")); | |
| 42 })(); | |
| 43 | |
| 44 (function NoMissingSuper() { | 31 (function NoMissingSuper() { |
| 45 assertReferenceError(constructor("")); | 32 assertReferenceError(constructor("")); |
| 46 assertReferenceError(constructor("1")); | 33 assertReferenceError(constructor("1")); |
| 47 })(); | 34 })(); |
| 48 | 35 |
| 49 (function NoNestedSuper() { | 36 (function NoNestedSuper() { |
| 50 assertSyntaxError(constructor("super(), 0;")); | |
| 51 assertSyntaxError(constructor("(super());")); | 37 assertSyntaxError(constructor("(super());")); |
| 52 assertSyntaxError(constructor("super().a;")); | |
| 53 assertSyntaxError(constructor("(() => super())();")); | 38 assertSyntaxError(constructor("(() => super())();")); |
| 54 assertSyntaxError(constructor("{ super(); }")); | 39 assertSyntaxError(constructor("{ super(); }")); |
| 55 assertSyntaxError(constructor("if (1) super();")); | 40 assertSyntaxError(constructor("if (1) super();")); |
| 56 assertSyntaxError(constructor("label: super();")); | |
| 57 })(); | 41 })(); |
| 58 | 42 |
| 59 (function NoDuplicateSuper() { | 43 (function NoDuplicateSuper() { |
| 60 assertSyntaxError(constructor("super(), super();")); | 44 assertSyntaxError(constructor("super(), super();")); |
| 61 assertSyntaxError(constructor("super(); super();")); | 45 assertSyntaxError(constructor("super(); super();")); |
| 62 assertSyntaxError(constructor("super(); (super());")); | 46 assertSyntaxError(constructor("super(); (super());")); |
| 63 assertSyntaxError(constructor("super(); { super() }")); | 47 assertSyntaxError(constructor("super(); { super() }")); |
| 64 assertSyntaxError(constructor("super(); (() => super())();")); | 48 assertSyntaxError(constructor("super(); (() => super())();")); |
| 65 })(); | 49 })(); |
| 66 | 50 |
| 67 (function NoSuperAfterThis() { | |
| 68 assertSyntaxError(constructor("this.a = 0, super();")); | |
| 69 assertSyntaxError(constructor("this.a = 0; super();")); | |
| 70 assertSyntaxError(constructor("this.a = 0; super(); this.b = 0;")); | |
| 71 assertSyntaxError(constructor("this.a = 0; (super());")); | |
| 72 assertSyntaxError(constructor("super(this.a = 0);")); | |
| 73 })(); | |
| 74 | |
| 75 (function NoReturnValue() { | 51 (function NoReturnValue() { |
| 76 assertSyntaxError(constructor("return {};")); | 52 assertSyntaxError(constructor("return {};")); |
| 77 assertSyntaxError(constructor("return undefined;")); | 53 assertSyntaxError(constructor("return undefined;")); |
| 78 assertSyntaxError(constructor("return this;")); | |
| 79 assertSyntaxError(constructor("return this.a = 0;")); | |
| 80 assertSyntaxError(constructor("{ return {}; }")); | 54 assertSyntaxError(constructor("{ return {}; }")); |
| 81 assertSyntaxError(constructor("if (1) return {};")); | 55 assertSyntaxError(constructor("if (1) return {};")); |
| 82 })(); | 56 })(); |
| 83 | 57 |
| 84 (function NoReturnBeforeSuper() { | 58 (function NoReturnBeforeSuper() { |
| 85 assertSyntaxError(constructor("return; super();")); | 59 assertSyntaxError(constructor("return; super();")); |
| 86 assertSyntaxError(constructor("if (0) return; super();")); | 60 assertSyntaxError(constructor("if (0) return; super();")); |
| 87 assertSyntaxError(constructor("{ return; } super();")); | 61 assertSyntaxError(constructor("{ return; } super();")); |
| 88 })(); | 62 })(); |
| 89 | |
| 90 (function NoReturnBeforeThis() { | |
| 91 assertSyntaxError(constructor("return; this.a = 0;")); | |
| 92 assertSyntaxError(constructor("if (0) return; this.a = 0;")); | |
| 93 assertSyntaxError(constructor("{ return; } this.a = 0;")); | |
| 94 })(); | |
| 95 | |
| 96 (function NoThisExceptInitialization() { | |
| 97 assertSyntaxError(constructor("this;")); | |
| 98 assertSyntaxError(constructor("this.a;")); | |
| 99 assertSyntaxError(constructor("this['a'];")); | |
| 100 assertSyntaxError(constructor("this();")); | |
| 101 assertSyntaxError(constructor("this.a();")); | |
| 102 assertSyntaxError(constructor("this.a.b = 0;")); | |
| 103 assertSyntaxError(constructor("{ this }")); | |
| 104 assertSyntaxError(constructor("if (0) this;")); | |
| 105 // TODO(rossberg): this does not handle arrow functions yet. | |
| 106 // assertSyntaxError(constructor("() => this;")); | |
| 107 // assertSyntaxError(constructor("() => () => this;")); | |
| 108 // assertSyntaxError(constructor("() => { () => if (0) { this; } }")); | |
| 109 })(); | |
| 110 | |
| 111 (function NoNestedThis() { | |
| 112 assertSyntaxError(constructor("(this.a = 0);")); | |
| 113 assertSyntaxError(constructor("{ this.a = 0; }")); | |
| 114 assertSyntaxError(constructor("if (0) this.a = 0;")); | |
| 115 // TODO(rossberg): this does not handle arrow functions yet. | |
| 116 // assertSyntaxError(constructor("() => this.a = 0;")); | |
| 117 // assertSyntaxError(constructor("() => { this.a = 0; }")); | |
| 118 assertSyntaxError(constructor("label: this.a = 0;")); | |
| 119 })(); | |
| OLD | NEW |