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

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

Issue 1059273004: [strong] Implement static restrictions on direct eval (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cr feedback 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
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 assertThrows( 48 assertThrows(
49 "(function outer() {\n" + 49 "(function outer() {\n" +
50 " function f() { 'use strong'; if (false) { x; } } var x; f(); \n" + 50 " function f() { 'use strong'; if (false) { x; } } var x; f(); \n" +
51 "})()", 51 "})()",
52 ReferenceError); 52 ReferenceError);
53 assertDoesNotThrow( 53 assertDoesNotThrow(
54 "(function outer() {\n" + 54 "(function outer() {\n" +
55 " function f() { if (false) { x; } } var x; f(); \n" + 55 " function f() { if (false) { x; } } var x; f(); \n" +
56 "})()"); 56 "})()");
57 57
58 // Errors are also detected when the declaration and the use are in the same
59 // eval scope.
60 assertThrows("'use strong'; eval('if (false) { x; let x = 0;}')",
61 ReferenceError);
62 assertDoesNotThrow("'use strict'; eval('if (false) { x; let x = 0; }')");
63
64 // Use occurring in the initializer of the declaration: 58 // Use occurring in the initializer of the declaration:
65 assertThrowsHelper("let x = x + 1;"); 59 assertThrowsHelper("let x = x + 1;");
66 assertThrowsHelper("let x = x;"); 60 assertThrowsHelper("let x = x;");
67 assertThrowsHelper("let x = y, y = 4;"); 61 assertThrowsHelper("let x = y, y = 4;");
68 assertThrowsHelper("let x = function() { x; }"); 62 assertThrowsHelper("let x = function() { x; }");
69 assertThrowsHelper("let x = a => { x; }"); 63 assertThrowsHelper("let x = a => { x; }");
70 assertThrowsHelper("function f(x) { return x; }; let x = f(x);"); 64 assertThrowsHelper("function f(x) { return x; }; let x = f(x);");
71 assertThrowsHelper("const x = x;"); 65 assertThrowsHelper("const x = x;");
72 assertThrowsHelper("const x = function() { x; }"); 66 assertThrowsHelper("const x = function() { x; }");
73 assertThrowsHelper("const x = a => { x; }"); 67 assertThrowsHelper("const x = a => { x; }");
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 let func5 = (p1, p2) => { p1; p2; }; 202 let func5 = (p1, p2) => { p1; p2; };
209 func5(); 203 func5();
210 204
211 let func5b = p1 => p1; 205 let func5b = p1 => p1;
212 func5b(); 206 func5b();
213 207
214 function func6() { 208 function func6() {
215 var1, var2a, var2b, var2c; 209 var1, var2a, var2b, var2c;
216 } 210 }
217 211
218 (function eval1() {
219 let var7 = 0; // Declaration position will be something large.
220 // But use position will be something small, however, this is not an error,
221 // since the use is inside an eval scope.
222 eval("var7;");
223 })();
224
225
226 class C1 { constructor() { C1; } }; new C1(); 212 class C1 { constructor() { C1; } }; new C1();
227 let C2 = class C3 { constructor() { C3; } }; new C2(); 213 let C2 = class C3 { constructor() { C3; } }; new C2();
228 214
229 class C4 { method() { C4; } *generator_method() { C4; } }; new C4(); 215 class C4 { method() { C4; } *generator_method() { C4; } }; new C4();
230 let C5 = class C6 { method() { C6; } *generator_method() { C6; } }; new C5(); 216 let C5 = class C6 { method() { C6; } *generator_method() { C6; } }; new C5();
231 217
232 class C7 { static method() { C7; } }; new C7(); 218 class C7 { static method() { C7; } }; new C7();
233 let C8 = class C9 { static method() { C9; } }; new C8(); 219 let C8 = class C9 { static method() { C9; } }; new C8();
234 220
235 class C10 { get x() { C10; } }; new C10(); 221 class C10 { get x() { C10; } }; new C10();
(...skipping 13 matching lines...) Expand all
249 } 235 }
250 return new CInner(); 236 return new CInner();
251 } 237 }
252 } 238 }
253 (new COuter()).m().n(); 239 (new COuter()).m().n();
254 240
255 // Making sure the check which is supposed to prevent "object literal inside 241 // Making sure the check which is supposed to prevent "object literal inside
256 // computed property name references the class name" is not too generic: 242 // computed property name references the class name" is not too generic:
257 class C14 { m() { let obj = { n() { C14 } }; obj.n(); } }; (new C14()).m(); 243 class C14 { m() { let obj = { n() { C14 } }; obj.n(); } }; (new C14()).m();
258 })(); 244 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698