Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: test/mjsunit/strong/classes.js

Issue 1024063002: [strong] checking of this & super in constructors (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« test/cctest/test-parsing.cc ('K') | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {}
11 11
12 function assertTypeError(script) { assertThrows(script, TypeError) } 12 function assertTypeError(script) { assertThrows(script, TypeError) }
13 function assertSyntaxError(script) { assertThrows(script, SyntaxError) } 13 function assertSyntaxError(script) { assertThrows(script, SyntaxError) }
14 function assertReferenceError(script) { assertThrows(script, ReferenceError) } 14 function assertReferenceError(script) { assertThrows(script, ReferenceError) }
15 15
16 (function ImmutableClassBindings() { 16 (function ImmutableClassBindings() {
17 class D {} 17 class D {}
18 assertTypeError(function(){ eval("C = 0") }); 18 assertTypeError(function(){ eval("C = 0") });
19 assertTypeError(function(){ eval("D = 0") }); 19 assertTypeError(function(){ eval("D = 0") });
20 assertEquals('function', typeof C); 20 assertEquals('function', typeof C);
21 assertEquals('function', typeof D); 21 assertEquals('function', typeof D);
22 })(); 22 })();
23 23
24 function constructor(body) { 24 function constructor(body) {
25 return "'use strong'; " + 25 return "'use strong'; " +
26 "(class extends Object { constructor() { " + body + " } })"; 26 "(class extends Object { constructor() { " + body + " } })";
27 } 27 }
28 28
29 (function NoSuperExceptCall() {
30 assertSyntaxError(constructor("super.a;"));
31 assertSyntaxError(constructor("super['a'];"));
32 assertSyntaxError(constructor("super.f();"));
33 assertSyntaxError(constructor("super.a;"));
34 assertSyntaxError(constructor("{ super.a }"));
35 assertSyntaxError(constructor("if (0) super.a;"));
36 // TODO(rossberg): arrow functions do not handle 'super' yet.
37 // assertSyntaxError(constructor("() => super.a;"));
38 // assertSyntaxError(constructor("() => () => super.a;"));
39 // assertSyntaxError(constructor("() => { () => if (0) { super.a; } }"));
40 })();
41
29 (function NoMissingSuper() { 42 (function NoMissingSuper() {
30 assertReferenceError(constructor("")); 43 assertReferenceError(constructor(""));
31 assertReferenceError(constructor("1")); 44 assertReferenceError(constructor("1"));
32 })(); 45 })();
33 46
34 (function NoNestedSuper() { 47 (function NoNestedSuper() {
48 assertSyntaxError(constructor("super(), 0;"));
35 assertSyntaxError(constructor("(super());")); 49 assertSyntaxError(constructor("(super());"));
36 assertSyntaxError(constructor("(() => super())();")); 50 assertSyntaxError(constructor("(() => super())();"));
37 assertSyntaxError(constructor("{ super(); }")); 51 assertSyntaxError(constructor("{ super(); }"));
38 assertSyntaxError(constructor("if (1) super();")); 52 assertSyntaxError(constructor("if (1) super();"));
53 assertSyntaxError(constructor("label: super();"));
39 })(); 54 })();
40 55
41 (function NoDuplicateSuper() { 56 (function NoDuplicateSuper() {
42 assertSyntaxError(constructor("super(), super();")); 57 assertSyntaxError(constructor("super(), super();"));
43 assertSyntaxError(constructor("super(); super();")); 58 assertSyntaxError(constructor("super(); super();"));
44 assertSyntaxError(constructor("super(); (super());")); 59 assertSyntaxError(constructor("super(); (super());"));
45 assertSyntaxError(constructor("super(); { super() }")); 60 assertSyntaxError(constructor("super(); { super() }"));
46 assertSyntaxError(constructor("super(); (() => super())();")); 61 assertSyntaxError(constructor("super(); (() => super())();"));
47 })(); 62 })();
48 63
64 (function NoSuperAfterThis() {
65 assertSyntaxError(constructor("this.a = 0, super();"));
66 assertSyntaxError(constructor("this.a = 0; super();"));
67 assertSyntaxError(constructor("this.a = 0; super(); this.b = 0;"));
68 assertSyntaxError(constructor("this.a = 0; (super());"));
69 assertSyntaxError(constructor("super(this.a = 0);"));
70 })();
71
49 (function NoReturnValue() { 72 (function NoReturnValue() {
50 assertSyntaxError(constructor("return {};")); 73 assertSyntaxError(constructor("return {};"));
51 assertSyntaxError(constructor("return undefined;")); 74 assertSyntaxError(constructor("return undefined;"));
75 assertSyntaxError(constructor("return this;"));
76 assertSyntaxError(constructor("return this.a = 0;"));
52 assertSyntaxError(constructor("{ return {}; }")); 77 assertSyntaxError(constructor("{ return {}; }"));
53 assertSyntaxError(constructor("if (1) return {};")); 78 assertSyntaxError(constructor("if (1) return {};"));
54 })(); 79 })();
55 80
56 (function NoReturnBeforeSuper() { 81 (function NoReturnBeforeSuper() {
57 assertSyntaxError(constructor("return; super();")); 82 assertSyntaxError(constructor("return; super();"));
58 assertSyntaxError(constructor("if (0) return; super();")); 83 assertSyntaxError(constructor("if (0) return; super();"));
59 assertSyntaxError(constructor("{ return; } super();")); 84 assertSyntaxError(constructor("{ return; } super();"));
60 })(); 85 })();
86
87 (function NoReturnBeforeThis() {
88 assertSyntaxError(constructor("return; this.a = 0;"));
89 assertSyntaxError(constructor("if (0) return; this.a = 0;"));
90 assertSyntaxError(constructor("{ return; } this.a = 0;"));
91 })();
92
93 (function NoThisExceptInitialization() {
94 assertSyntaxError(constructor("this;"));
95 assertSyntaxError(constructor("this.a;"));
96 assertSyntaxError(constructor("this['a'];"));
97 assertSyntaxError(constructor("this();"));
98 assertSyntaxError(constructor("this.a.b = 0;"));
99 assertSyntaxError(constructor("{ this }"));
100 assertSyntaxError(constructor("if (0) this;"));
101 // TODO(rossberg): this does not handle arrow functions yet.
102 // assertSyntaxError(constructor("() => this;"));
103 // assertSyntaxError(constructor("() => () => this;"));
104 // assertSyntaxError(constructor("() => { () => if (0) { this; } }"));
105 })();
106
107 (function NoNestedThis() {
108 assertSyntaxError(constructor("(this.a = 0);"));
109 assertSyntaxError(constructor("{ this.a = 0; }"));
110 assertSyntaxError(constructor("if (0) this.a = 0;"));
111 // TODO(rossberg): this does not handle arrow functions yet.
112 // assertSyntaxError(constructor("() => this.a = 0;"));
113 // assertSyntaxError(constructor("() => { this.a = 0; }"));
114 assertSyntaxError(constructor("label: this.a = 0;"));
115 })();
OLDNEW
« test/cctest/test-parsing.cc ('K') | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698