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

Unified Diff: test/mjsunit/harmony/block-const-assign.js

Issue 749633002: harmony-scoping: make assignment to 'const' a late error. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comment update Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/x64/full-codegen-x64.cc ('k') | test/mjsunit/harmony/classes.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 b71729e8a20ebe2f142d533a076bd424c4ea4591..c21a0a34803a686e677a5ce6a8b10cdeecf1d8ac 100644
--- a/test/mjsunit/harmony/block-const-assign.js
+++ b/test/mjsunit/harmony/block-const-assign.js
@@ -35,61 +35,61 @@
// Function local const.
function constDecl0(use) {
- return "(function() { const constvar = 1; " + use + "; });";
+ return "(function() { const constvar = 1; " + use + "; })();";
}
function constDecl1(use) {
- return "(function() { " + use + "; const constvar = 1; });";
+ return "(function() { " + use + "; const constvar = 1; })();";
}
// Function local const, assign from eval.
function constDecl2(use) {
- use = "eval('(function() { " + use + " })')";
+ use = "eval('(function() { " + use + " })')()";
return "(function() { const constvar = 1; " + use + "; })();";
}
function constDecl3(use) {
- use = "eval('(function() { " + use + " })')";
+ use = "eval('(function() { " + use + " })')()";
return "(function() { " + use + "; const constvar = 1; })();";
}
// Block local const.
function constDecl4(use) {
- return "(function() { { const constvar = 1; " + use + "; } });";
+ return "(function() { { const constvar = 1; " + use + "; } })();";
}
function constDecl5(use) {
- return "(function() { { " + use + "; const constvar = 1; } });";
+ return "(function() { { " + use + "; const constvar = 1; } })();";
}
// Block local const, assign from eval.
function constDecl6(use) {
- use = "eval('(function() {" + use + "})')";
+ use = "eval('(function() {" + use + "})')()";
return "(function() { { const constvar = 1; " + use + "; } })();";
}
function constDecl7(use) {
- use = "eval('(function() {" + use + "})')";
+ use = "eval('(function() {" + use + "})')()";
return "(function() { { " + use + "; const constvar = 1; } })();";
}
// Function expression name.
function constDecl8(use) {
- return "(function constvar() { " + use + "; });";
+ return "(function constvar() { " + use + "; })();";
}
// Function expression name, assign from eval.
function constDecl9(use) {
- use = "eval('(function(){" + use + "})')";
+ use = "eval('(function(){" + use + "})')()";
return "(function constvar() { " + use + "; })();";
}
@@ -104,6 +104,7 @@ let decls = [ constDecl0,
constDecl8,
constDecl9
];
+let declsForTDZ = new Set([constDecl1, constDecl3, constDecl5, constDecl7]);
let uses = [ 'constvar = 1;',
'constvar += 1;',
'++constvar;',
@@ -116,7 +117,13 @@ function Test(d,u) {
print(d(u));
eval(d(u));
} catch (e) {
- assertInstanceof(e, SyntaxError);
+ 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, TypeError);
assertTrue(e.toString().indexOf("Assignment to constant variable") >= 0);
return;
}
« no previous file with comments | « src/x64/full-codegen-x64.cc ('k') | test/mjsunit/harmony/classes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698