Index: test/mjsunit/harmony/block-const-assign.js |
diff --git a/test/mjsunit/harmony/block-const-assign.js b/test/mjsunit/harmony/block-const-assign.js |
index 397695f86aecd1e2a5b8637e6c74147269e10d89..6f34e6af73d5dd9ab9bf66413f6e4e85b548d39f 100644 |
--- a/test/mjsunit/harmony/block-const-assign.js |
+++ b/test/mjsunit/harmony/block-const-assign.js |
@@ -33,124 +33,75 @@ |
"use strict"; |
-// Function local const. |
-function constDecl0(use) { |
- return "(function() { const constvar = 1; " + use + "; })();"; |
-} |
- |
- |
-function constDecl1(use) { |
- return "(function() { " + use + "; const constvar = 1; })();"; |
-} |
- |
- |
-// Function local const, assign from eval. |
-function constDecl2(use) { |
- use = "eval('(function() { " + use + " })')()"; |
- return "(function() { const constvar = 1; " + use + "; })();"; |
-} |
- |
- |
-function constDecl3(use) { |
- use = "eval('(function() { " + use + " })')()"; |
- return "(function() { " + use + "; const constvar = 1; })();"; |
-} |
- |
- |
-// Block local const. |
-function constDecl4(use) { |
- return "(function() { { const constvar = 1; " + use + "; } })();"; |
-} |
- |
- |
-function constDecl5(use) { |
- return "(function() { { " + use + "; const constvar = 1; } })();"; |
-} |
- |
- |
-// Block local const, assign from eval. |
-function constDecl6(use) { |
- use = "eval('(function() {" + use + "})')()"; |
- return "(function() { { const constvar = 1; " + use + "; } })();"; |
-} |
- |
- |
-function constDecl7(use) { |
- use = "eval('(function() {" + use + "})')()"; |
- return "(function() { { " + use + "; const constvar = 1; } })();"; |
-} |
- |
- |
-// Function expression name. |
-function constDecl8(use) { |
- return "(function constvar() { " + use + "; })();"; |
-} |
- |
- |
-// Function expression name, assign from eval. |
-function constDecl9(use) { |
- use = "eval('(function(){" + use + "})')()"; |
- return "(function constvar() { " + use + "; })();"; |
-} |
- |
-// For loop variable. |
-function constDecl10(use) { |
- return "(function() { for (const constvar = 0; ;) { " + use + "; } })();"; |
-} |
- |
-// For-in loop variable. |
-function constDecl11(use) { |
- return "(function() { for (const constvar in {a: 1}) { " + use + "; } })();"; |
-} |
- |
-// For-of loop variable. |
-function constDecl12(use) { |
- return "(function() { for (const constvar of [1]) { " + use + "; } })();"; |
-} |
- |
- |
-let decls = [ constDecl0, |
- constDecl1, |
- constDecl2, |
- constDecl3, |
- constDecl4, |
- constDecl5, |
- constDecl6, |
- constDecl7, |
- constDecl8, |
- constDecl9, |
- constDecl10, |
- constDecl11, |
- constDecl12 |
- ]; |
-let declsForTDZ = new Set([constDecl1, constDecl3, constDecl5, constDecl7]); |
-let uses = [ 'constvar = 1;', |
- 'constvar += 1;', |
- '++constvar;', |
- 'constvar++;' |
- ]; |
- |
-function Test(d,u) { |
- 'use strict'; |
+const decls = [ |
+ // Const declaration. |
+ function(use) { return "const c = 1; " + use + ";" }, TypeError, |
+ function(use) { return "const x = 0, c = 1; " + use + ";" }, TypeError, |
+ function(use) { return "const c = 1, x = (" + use + ");" }, TypeError, |
+ function(use) { return use + "; const c = 1;" }, ReferenceError, |
+ function(use) { return use + "; const x = 0, c = 1;" }, ReferenceError, |
+ function(use) { return "const x = (" + use + "), c = 1;" }, ReferenceError, |
+ |
+ // Function expression. |
+ function(use) { return "(function c() { " + use + "; })();"; }, TypeError, |
+ |
+ // For loop. |
+ function(use) { |
+ return "for (const c = 0; ;) { " + use + "; }" |
+ }, TypeError, |
+ function(use) { |
+ return "for (const x = 0, c = 0; ;) { " + use + "; }" |
+ }, TypeError, |
+ function(use) { |
+ return "for (const c in {a: 1}) { " + use + "; }" |
+ }, TypeError, |
+ function(use) { |
+ return "for (const c of [1]) { " + use + "; }" |
+ }, TypeError, |
+] |
+ |
+let uses = [ |
+ 'c = 1', |
+ 'c += 1', |
+ '++c', |
+ 'c--', |
+]; |
+ |
+let declcontexts = [ |
+ function(decl) { return decl; }, |
+ function(decl) { return "eval(\'" + decl + "\')"; }, |
+ function(decl) { return "{ " + decl + " }"; }, |
+ function(decl) { return "(function() { " + decl + " })()"; }, |
+]; |
+ |
+let usecontexts = [ |
+ function(use) { return use; }, |
+ function(use) { return "eval(\"" + use + "\")"; }, |
+ function(use) { return "(function() { " + use + " })()"; }, |
+ function(use) { return "(function() { eval(\"" + use + "\"); })()"; }, |
+]; |
+ |
+function Test(program, error) { |
+ program = "'use strict'; " + program; |
try { |
- print(d(u)); |
- eval(d(u)); |
+ print(program, "(* throw " + error.name + " *)"); |
+ eval(program); |
} catch (e) { |
- if (declsForTDZ.has(d) && u !== uses[0]) { |
- // In these cases, read of a const variable occurs |
- // before a write to it, so TDZ kicks in before const check. |
- assertInstanceof(e, ReferenceError); |
- return; |
+ assertInstanceof(e, error); |
+ if (e === TypeError) { |
+ assertTrue(e.toString().indexOf("Assignment to constant variable") >= 0); |
} |
- assertInstanceof(e, TypeError); |
- assertTrue(e.toString().indexOf("Assignment to constant variable") >= 0); |
return; |
} |
assertUnreachable(); |
} |
-for (var d = 0; d < decls.length; ++d) { |
+for (var d = 0; d < decls.length; d += 2) { |
for (var u = 0; u < uses.length; ++u) { |
- Test(decls[d], uses[u]); |
+ for (var o = 0; o < declcontexts.length; ++o) { |
+ for (var i = 0; i < usecontexts.length; ++i) { |
+ Test(declcontexts[o](decls[d](usecontexts[i](uses[u]))), decls[d + 1]); |
+ } |
+ } |
} |
} |