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

Unified Diff: src/compiler/ast-graph-builder.cc

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/compiler/ast-graph-builder.h ('k') | src/full-codegen.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/ast-graph-builder.cc
diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc
index e2d8aabc2b95c6f4d5205a110e37c6c5535ef06c..afe331df377b1829f9d0e3c7308c2b573241c710 100644
--- a/src/compiler/ast-graph-builder.cc
+++ b/src/compiler/ast-graph-builder.cc
@@ -2020,7 +2020,12 @@ Node* AstGraphBuilder::BuildVariableAssignment(
value = BuildHoleCheckSilent(current, value, current);
}
} else if (mode == CONST_LEGACY && op != Token::INIT_CONST_LEGACY) {
- // Non-initializing assignments to legacy const is ignored.
+ // Non-initializing assignments to legacy const is
+ // - exception in strict mode.
+ // - ignored in sloppy mode.
+ if (strict_mode() == STRICT) {
+ return BuildThrowConstAssignError(bailout_id);
+ }
return value;
} else if (mode == LET && op != Token::INIT_LET) {
// Perform an initialization check for let declared variables.
@@ -2034,8 +2039,8 @@ Node* AstGraphBuilder::BuildVariableAssignment(
value = BuildHoleCheckThrow(current, variable, value, bailout_id);
}
} else if (mode == CONST && op != Token::INIT_CONST) {
- // All assignments to const variables are early errors.
- UNREACHABLE();
+ // Non-initializing assignments to const is exception in all modes.
+ return BuildThrowConstAssignError(bailout_id);
}
environment()->Bind(variable, value);
return value;
@@ -2049,7 +2054,12 @@ Node* AstGraphBuilder::BuildVariableAssignment(
Node* current = NewNode(op, current_context());
value = BuildHoleCheckSilent(current, value, current);
} else if (mode == CONST_LEGACY && op != Token::INIT_CONST_LEGACY) {
- // Non-initializing assignments to legacy const is ignored.
+ // Non-initializing assignments to legacy const is
+ // - exception in strict mode.
+ // - ignored in sloppy mode.
+ if (strict_mode() == STRICT) {
+ return BuildThrowConstAssignError(bailout_id);
+ }
return value;
} else if (mode == LET && op != Token::INIT_LET) {
// Perform an initialization check for let declared variables.
@@ -2058,8 +2068,8 @@ Node* AstGraphBuilder::BuildVariableAssignment(
Node* current = NewNode(op, current_context());
value = BuildHoleCheckThrow(current, variable, value, bailout_id);
} else if (mode == CONST && op != Token::INIT_CONST) {
- // All assignments to const variables are early errors.
- UNREACHABLE();
+ // Non-initializing assignments to const is exception in all modes.
+ return BuildThrowConstAssignError(bailout_id);
}
const Operator* op = javascript()->StoreContext(depth, variable->index());
return NewNode(op, current_context(), value);
@@ -2153,6 +2163,16 @@ Node* AstGraphBuilder::BuildThrowReferenceError(Variable* variable,
}
+Node* AstGraphBuilder::BuildThrowConstAssignError(BailoutId bailout_id) {
+ // TODO(mstarzinger): Should be unified with the VisitThrow implementation.
+ const Operator* op =
+ javascript()->CallRuntime(Runtime::kThrowConstAssignError, 0);
+ Node* call = NewNode(op);
+ PrepareFrameState(call, bailout_id);
+ return call;
+}
+
+
Node* AstGraphBuilder::BuildBinaryOp(Node* left, Node* right, Token::Value op) {
const Operator* js_op;
switch (op) {
« no previous file with comments | « src/compiler/ast-graph-builder.h ('k') | src/full-codegen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698