Chromium Code Reviews| Index: test/mjsunit/strong/declaration-after-use.js |
| diff --git a/test/mjsunit/strong/declaration-after-use.js b/test/mjsunit/strong/declaration-after-use.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ac5ee5c94b9ec9dd587d23b6bfe8513165598663 |
| --- /dev/null |
| +++ b/test/mjsunit/strong/declaration-after-use.js |
| @@ -0,0 +1,65 @@ |
| +// 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. |
| + |
| +// Flags: --strong-mode --harmony_rest_parameters --harmony_arrow_functions |
| + |
| +(function DeclarationAfterUse() { |
|
rossberg
2015/02/23 13:45:26
More tests would be great, both positive and negat
marja
2015/02/24 13:29:35
Added some tests here, probably not everything you
|
| + assertThrows("'use strong'; x; let x = 0;", ReferenceError); |
| + assertThrows("function f() { 'use strong'; x; let x = 0; } f();", |
| + ReferenceError); |
| + assertThrows("'use strong'; function f() { x; } let x = 0; f();", |
| + ReferenceError); |
| + assertThrows("function f() { 'use strong'; x; } var x = 0; f();", |
| + ReferenceError); |
| + // Errors are also detected when the declaration and the use are in the same |
| + // eval scope. |
| + assertThrows("'use strong'; eval('x; let x = 0;')", ReferenceError); |
| +})(); |
| + |
| + |
| +(function UsesWhichAreFine() { |
| + "use strong"; |
| + |
| + let var1 = 0; |
| + var1; |
| + |
| + for (let var2 = 0; var2 < 1; var2++) { |
| + var2; |
| + } |
| + |
| + let var3 = 5; |
| + for (; var3 < 10; ++var3) { } |
| + |
| + let arr = [1, 2]; |
| + for (let i of arr) { |
| + i; |
| + } |
| + |
| + try { |
| + throw "error"; |
| + } catch (e) { |
| + e; |
| + } |
| + |
| + function func1() { func1; this; } |
| + func1(); |
| + func1; |
| + |
| + function * func2() { func2; this; } |
| + func2(); |
| + func2; |
| + |
| + function func4(p, ...rest) { p; rest; this; func2; } |
| + func4(); |
| + |
| + let func5 = (p1, p2) => { p1; p2 }; |
| + func5(); |
| + |
| + (function eval1() { |
| + let var4 = 0; // Declaration position will be something large. |
| + // But use position will be something small, however, this is not an error, |
| + // since the use is inside an eval scope. |
| + eval("var4;"); |
| + })(); |
| +})(); |