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

Side by Side Diff: test/mjsunit/strong/declaration-after-use.js

Issue 968263002: [strong] Fix scoping related errors for methods. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: code review (arv, rossberg) Created 5 years, 9 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
« no previous file with comments | « src/scopes.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 --harmony_rest_parameters --harmony_arrow_functions --ha rmony_classes --harmony-computed-property-names 5 // Flags: --strong-mode --harmony_rest_parameters --harmony_arrow_functions --ha rmony_classes --harmony-computed-property-names
6 6
7 // Note that it's essential for these tests that the reference is inside dead 7 // Note that it's essential for these tests that the reference is inside dead
8 // code (because we already produce ReferenceErrors for run-time unresolved 8 // code (because we already produce ReferenceErrors for run-time unresolved
9 // variables and don't want to confuse those with strong mode errors). But the 9 // variables and don't want to confuse those with strong mode errors). But the
10 // errors should *not* be inside lazy, unexecuted functions, since lazy parsing 10 // errors should *not* be inside lazy, unexecuted functions, since lazy parsing
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 assertThrowsHelper( 104 assertThrowsHelper(
105 "'use strong'; if (false) { let C = class C2 { method() { C; } } }", 105 "'use strong'; if (false) { let C = class C2 { method() { C; } } }",
106 ReferenceError); 106 ReferenceError);
107 107
108 assertThrowsHelper( 108 assertThrowsHelper(
109 "'use strong'; if (false) { let C = class C2 { " + 109 "'use strong'; if (false) { let C = class C2 { " +
110 "static a() { return 'A'; } [C.a()]() { return 'B'; } }; }", 110 "static a() { return 'A'; } [C.a()]() { return 'B'; } }; }",
111 ReferenceError); 111 ReferenceError);
112 112
113 // TODO(marja, rossberg): More tests related to computed property names in 113 assertThrowsHelper(
114 // classes + recognize more errors. This one is not recognized as an error 114 "'use strong'; if (false) { let C = class C2 { " +
115 // yet: 115 "static a() { return 'A'; } [C2.a()]() { return 'B'; } }; }",
116 // let C = class C2 { 116 ReferenceError);
117 // static a() { return 'A'; } 117
118 // [C2.a()]() { return 'B'; } << C2 should not be allowed here 118 assertThrowsHelper(
119 // }; 119 "'use strong'; if (false) { let C = class C2 { " +
120 "[(function() { C; return 'A';})()]() { return 'B'; } }; }",
121 ReferenceError);
122
123 // The reference to C or C2 is inside a function, but not a method.
124 assertThrowsHelper(
125 "'use strong'; if (false) { let C = class C2 { " +
126 "[(function() { C2; return 'A';})()]() { return 'B'; } }; }",
127 ReferenceError);
128
129 assertThrowsHelper(
130 "'use strong'; if (false) { let C = class C2 { " +
131 "[(function() { C; return 'A';})()]() { return 'B'; } }; }",
132 ReferenceError);
133
134 // The reference to C or C2 is inside a method, but it's not a method of the
135 // relevant class (C2).
136 assertThrowsHelper(
137 "'use strong'; if (false) { let C = class C2 { " +
138 "[(new (class D { m() { C2; return 'A'; } })).m()]() " +
139 "{ return 'B'; } } }",
140 ReferenceError);
141
142 assertThrowsHelper(
143 "'use strong'; if (false) { let C = class C2 { " +
144 "[(new (class D { m() { C; return 'A'; } })).m()]() " +
145 "{ return 'B'; } } }",
146 ReferenceError);
147
148 // Methods inside object literals are not sufficiently distinguished from
149 // methods inside classes.
150 // https://code.google.com/p/v8/issues/detail?id=3948
151 // assertThrowsHelper(
152 // "'use strong'; if (false) { let C = class C2 { " +
153 // "[({m() { C2; return 'A'; }}).m()]() " +
154 // "{ return 'B'; } } }",
155 // ReferenceError);
156
157 assertThrowsHelper(
158 "'use strong'; if (false) { let C = class C2 { " +
159 "[({m() { C; return 'A'; }}).m()]() " +
160 "{ return 'B'; } } }",
161 ReferenceError);
162
163 // assertThrowsHelper(
164 // "'use strong';\n" +
165 // "if (false) {\n" +
166 // " class COuter {\n" +
167 // " m() {\n" +
168 // " class CInner {\n" +
169 // " [({ m() { CInner; return 'A'; } }).m()]() {\n" +
170 // " return 'B';\n" +
171 // " }\n" +
172 // " }\n" +
173 // " }\n" +
174 // " }\n" +
175 // "}",
176 // ReferenceError);
120 })(); 177 })();
121 178
122 179
123 (function UsesWhichAreFine() { 180 (function UsesWhichAreFine() {
124 "use strong"; 181 "use strong";
125 182
126 let var1 = 0; 183 let var1 = 0;
127 var1; 184 var1;
128 185
129 let var2a = 0, var2b = var2a + 1, var2c = 2 + var2b; 186 let var2a = 0, var2b = var2a + 1, var2c = 2 + var2b;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 var1, var2a, var2b, var2c; 230 var1, var2a, var2b, var2c;
174 } 231 }
175 232
176 (function eval1() { 233 (function eval1() {
177 let var7 = 0; // Declaration position will be something large. 234 let var7 = 0; // Declaration position will be something large.
178 // But use position will be something small, however, this is not an error, 235 // But use position will be something small, however, this is not an error,
179 // since the use is inside an eval scope. 236 // since the use is inside an eval scope.
180 eval("var7;"); 237 eval("var7;");
181 })(); 238 })();
182 239
183 // https://code.google.com/p/v8/issues/detail?id=3927
184 // class C1 { constructor() { C1; } }; new C1();
185 // let C2 = class C3 { constructor() { C3; } }; new C2();
186 240
187 // class C4 { method() { C4; method; } }; new C4(); 241 class C1 { constructor() { C1; } }; new C1();
188 // let C5 = class C6 { method() { C6; method; } }; new C5(); 242 let C2 = class C3 { constructor() { C3; } }; new C2();
243
244 class C4 { method() { C4; } }; new C4();
245 let C5 = class C6 { method() { C6; } }; new C5();
246
247 class C7 { static method() { C7; } }; new C7();
248 let C8 = class C9 { static method() { C9; } }; new C8();
249
250 class C10 { get x() { C10; } }; new C10();
251 let C11 = class C12 { get x() { C12; } }; new C11();
252
253 // Regression test for unnamed classes.
254 let C12 = class { m() { var1; } };
255
256 class COuter {
257 m() {
258 class CInner {
259 // Here we can refer to COuter but not to CInner (see corresponding
260 // assertion test):
261 [({ m() { COuter; return 'A'; } }).m()]() { return 'B'; }
262 // And here we can refer to both:
263 n() { COuter; CInner; }
264 }
265 return new CInner();
266 }
267 }
268 (new COuter()).m().n();
189 })(); 269 })();
OLDNEW
« no previous file with comments | « src/scopes.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698