Chromium Code Reviews| 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..e9f95b1424782cec15828170bb1d6db0352f416d 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 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,13 @@ Node* AstGraphBuilder::BuildVariableAssignment( |
| value = BuildHoleCheckThrow(current, variable, value, bailout_id); |
| } |
| } else if (mode == CONST && op != Token::INIT_CONST) { |
|
rossberg
2014/11/26 08:31:46
Why not merge this case with the above?
Dmitry Lomov (no reviews)
2014/11/26 08:52:32
And extract the condition into IsNonInitializingAs
Dmitry Lomov (no reviews)
2014/11/26 10:30:56
Actually, I realized that we also decided that non
|
| - // All assignments to const variables are early errors. |
| - UNREACHABLE(); |
| + // Non-initializing assignments to const is |
| + // - exception in strict mode. |
| + // - ignored in sloppy mode. |
| + if (strict_mode() == STRICT) { |
| + return BuildThrowConstAssignError(bailout_id); |
| + } |
| + return value; |
| } |
| environment()->Bind(variable, value); |
| return value; |
| @@ -2049,7 +2059,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 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 +2073,13 @@ Node* AstGraphBuilder::BuildVariableAssignment( |
| Node* current = NewNode(op, current_context()); |
| value = BuildHoleCheckThrow(current, variable, value, bailout_id); |
| } else if (mode == CONST && op != Token::INIT_CONST) { |
|
rossberg
2014/11/26 08:31:46
Same here.
|
| - // All assignments to const variables are early errors. |
| - UNREACHABLE(); |
| + // Non-initializing assignments to const is |
| + // - exception in strict mode. |
| + // - ignored in sloppy mode. |
| + if (strict_mode() == STRICT) { |
| + return BuildThrowConstAssignError(bailout_id); |
| + } |
| + return value; |
| } |
| const Operator* op = javascript()->StoreContext(depth, variable->index()); |
| return NewNode(op, current_context(), value); |
| @@ -2153,6 +2173,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) { |