Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/ast-graph-builder.h" | 5 #include "src/compiler/ast-graph-builder.h" |
| 6 | 6 |
| 7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
| 8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
| 9 #include "src/compiler/ast-loop-assignment-analyzer.h" | 9 #include "src/compiler/ast-loop-assignment-analyzer.h" |
| 10 #include "src/compiler/control-builders.h" | 10 #include "src/compiler/control-builders.h" |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 | 528 |
| 529 // Initialize the incoming context. | 529 // Initialize the incoming context. |
| 530 ContextScope incoming(this, scope, GetFunctionContext()); | 530 ContextScope incoming(this, scope, GetFunctionContext()); |
| 531 | 531 |
| 532 // Initialize control scope. | 532 // Initialize control scope. |
| 533 ControlScope control(this); | 533 ControlScope control(this); |
| 534 | 534 |
| 535 // TODO(mstarzinger): For now we cannot assume that the {this} parameter is | 535 // TODO(mstarzinger): For now we cannot assume that the {this} parameter is |
| 536 // not {the_hole}, because for derived classes {this} has a TDZ and the | 536 // not {the_hole}, because for derived classes {this} has a TDZ and the |
| 537 // JSConstructStubForDerived magically passes {the_hole} as a receiver. | 537 // JSConstructStubForDerived magically passes {the_hole} as a receiver. |
| 538 if (scope->has_this_declaration() && scope->receiver()->is_const_mode()) { | 538 if (scope->has_this_declaration() && scope->receiver()->mode() == CONST) { |
| 539 env.RawParameterBind(0, jsgraph()->TheHoleConstant()); | 539 env.RawParameterBind(0, jsgraph()->TheHoleConstant()); |
| 540 } | 540 } |
| 541 | 541 |
| 542 // Build local context only if there are context allocated variables. | 542 // Build local context only if there are context allocated variables. |
| 543 if (scope->num_heap_slots() > 0) { | 543 if (scope->num_heap_slots() > 0) { |
| 544 // Push a new inner context scope for the current activation. | 544 // Push a new inner context scope for the current activation. |
| 545 Node* inner_context = BuildLocalActivationContext(GetFunctionContext()); | 545 Node* inner_context = BuildLocalActivationContext(GetFunctionContext()); |
| 546 ContextScope top_context(this, scope, inner_context); | 546 ContextScope top_context(this, scope, inner_context); |
| 547 CreateGraphBody(stack_check); | 547 CreateGraphBody(stack_check); |
| 548 } else { | 548 } else { |
| (...skipping 2883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3432 case VariableLocation::UNALLOCATED: { | 3432 case VariableLocation::UNALLOCATED: { |
| 3433 // Global var, const, or let variable. | 3433 // Global var, const, or let variable. |
| 3434 Handle<Name> name = variable->name(); | 3434 Handle<Name> name = variable->name(); |
| 3435 Node* store = BuildGlobalStore(name, value, feedback); | 3435 Node* store = BuildGlobalStore(name, value, feedback); |
| 3436 PrepareFrameState(store, bailout_id, combine); | 3436 PrepareFrameState(store, bailout_id, combine); |
| 3437 return store; | 3437 return store; |
| 3438 } | 3438 } |
| 3439 case VariableLocation::PARAMETER: | 3439 case VariableLocation::PARAMETER: |
| 3440 case VariableLocation::LOCAL: | 3440 case VariableLocation::LOCAL: |
| 3441 // Local var, const, or let variable. | 3441 // Local var, const, or let variable. |
| 3442 if (mode == CONST_LEGACY && op != Token::INIT) { | 3442 if (mode == LET && op == Token::INIT) { |
| 3443 // Non-initializing assignment to legacy const is | |
| 3444 // - exception in strict mode. | |
| 3445 // - ignored in sloppy mode. | |
| 3446 if (is_strict(language_mode())) { | |
| 3447 return BuildThrowConstAssignError(bailout_id); | |
| 3448 } | |
| 3449 return value; | |
| 3450 } else if (mode == LET && op == Token::INIT) { | |
| 3451 // No initialization check needed because scoping guarantees it. Note | 3443 // No initialization check needed because scoping guarantees it. Note |
| 3452 // that we still perform a lookup to keep the variable live, because | 3444 // that we still perform a lookup to keep the variable live, because |
| 3453 // baseline code might contain debug code that inspects the variable. | 3445 // baseline code might contain debug code that inspects the variable. |
| 3454 Node* current = environment()->Lookup(variable); | 3446 Node* current = environment()->Lookup(variable); |
| 3455 CHECK_NOT_NULL(current); | 3447 CHECK_NOT_NULL(current); |
| 3456 } else if (mode == CONST && op == Token::INIT) { | 3448 } else if (mode == CONST && op == Token::INIT) { |
| 3457 // Perform an initialization check for const {this} variables. | 3449 // Perform an initialization check for const {this} variables. |
| 3458 // Note that the {this} variable is the only const variable being able | 3450 // Note that the {this} variable is the only const variable being able |
| 3459 // to trigger bind operations outside the TDZ, via {super} calls. | 3451 // to trigger bind operations outside the TDZ, via {super} calls. |
| 3460 Node* current = environment()->Lookup(variable); | 3452 Node* current = environment()->Lookup(variable); |
| 3461 if (current->op() != the_hole->op() && variable->is_this()) { | 3453 if (current->op() != the_hole->op() && variable->is_this()) { |
| 3462 value = BuildHoleCheckElseThrow(current, variable, value, bailout_id); | 3454 value = BuildHoleCheckElseThrow(current, variable, value, bailout_id); |
| 3463 } | 3455 } |
| 3464 } else if (IsLexicalVariableMode(mode) && op != Token::INIT) { | 3456 } else if (IsLexicalVariableMode(mode) && op != Token::INIT) { |
|
Toon Verwaest
2016/08/18 07:05:26
If I understood correctly, there was some unhappin
adamk
2016/08/18 18:40:18
Yeah, I've reverted that change on master, and upd
| |
| 3465 // Perform an initialization check for lexically declared variables. | 3457 // Perform an initialization check for lexically declared variables. |
| 3466 Node* current = environment()->Lookup(variable); | 3458 Node* current = environment()->Lookup(variable); |
| 3467 if (variable->binding_needs_init()) { | 3459 if (variable->binding_needs_init()) { |
| 3468 if (current->op() == the_hole->op()) { | 3460 if (current->op() == the_hole->op()) { |
| 3469 return BuildThrowReferenceError(variable, bailout_id); | 3461 return BuildThrowReferenceError(variable, bailout_id); |
| 3470 } else if (current->opcode() == IrOpcode::kPhi) { | 3462 } else if (current->opcode() == IrOpcode::kPhi) { |
| 3471 BuildHoleCheckThenThrow(current, variable, value, bailout_id); | 3463 BuildHoleCheckThenThrow(current, variable, value, bailout_id); |
| 3472 } | 3464 } |
| 3473 } | 3465 } |
| 3474 if (mode == CONST) { | 3466 if (mode == CONST) { |
| 3475 return BuildThrowConstAssignError(bailout_id); | 3467 if (variable->throw_on_const_assignment(language_mode())) { |
|
Toon Verwaest
2016/08/18 07:05:26
What about returning a ShouldThrow flag from throw
adamk
2016/08/18 18:40:18
I'm worried that still runs afoul of making each c
| |
| 3468 return BuildThrowConstAssignError(bailout_id); | |
| 3469 } | |
| 3470 return value; | |
| 3476 } | 3471 } |
| 3477 } | 3472 } |
| 3478 environment()->Bind(variable, value); | 3473 environment()->Bind(variable, value); |
| 3479 return value; | 3474 return value; |
| 3480 case VariableLocation::CONTEXT: { | 3475 case VariableLocation::CONTEXT: { |
| 3481 // Context variable (potentially up the context chain). | 3476 // Context variable (potentially up the context chain). |
| 3482 int depth = current_scope()->ContextChainLength(variable->scope()); | 3477 int depth = current_scope()->ContextChainLength(variable->scope()); |
| 3483 if (mode == CONST_LEGACY && op != Token::INIT) { | 3478 if (mode == CONST && op == Token::INIT) { |
| 3484 // Non-initializing assignment to legacy const is | |
| 3485 // - exception in strict mode. | |
| 3486 // - ignored in sloppy mode. | |
| 3487 if (is_strict(language_mode())) { | |
| 3488 return BuildThrowConstAssignError(bailout_id); | |
| 3489 } | |
| 3490 return value; | |
| 3491 } else if (mode == CONST && op == Token::INIT) { | |
| 3492 // Perform an initialization check for const {this} variables. | 3479 // Perform an initialization check for const {this} variables. |
| 3493 // Note that the {this} variable is the only const variable being able | 3480 // Note that the {this} variable is the only const variable being able |
| 3494 // to trigger bind operations outside the TDZ, via {super} calls. | 3481 // to trigger bind operations outside the TDZ, via {super} calls. |
| 3495 if (variable->is_this()) { | 3482 if (variable->is_this()) { |
| 3496 const Operator* op = | 3483 const Operator* op = |
| 3497 javascript()->LoadContext(depth, variable->index(), false); | 3484 javascript()->LoadContext(depth, variable->index(), false); |
| 3498 Node* current = NewNode(op, current_context()); | 3485 Node* current = NewNode(op, current_context()); |
| 3499 value = BuildHoleCheckElseThrow(current, variable, value, bailout_id); | 3486 value = BuildHoleCheckElseThrow(current, variable, value, bailout_id); |
| 3500 } | 3487 } |
| 3501 } else if (IsLexicalVariableMode(mode) && op != Token::INIT) { | 3488 } else if (IsLexicalVariableMode(mode) && op != Token::INIT) { |
|
Toon Verwaest
2016/08/18 07:05:26
the same here
| |
| 3502 // Perform an initialization check for lexically declared variables. | 3489 // Perform an initialization check for lexically declared variables. |
| 3503 if (variable->binding_needs_init()) { | 3490 if (variable->binding_needs_init()) { |
| 3504 const Operator* op = | 3491 const Operator* op = |
| 3505 javascript()->LoadContext(depth, variable->index(), false); | 3492 javascript()->LoadContext(depth, variable->index(), false); |
| 3506 Node* current = NewNode(op, current_context()); | 3493 Node* current = NewNode(op, current_context()); |
| 3507 value = BuildHoleCheckThenThrow(current, variable, value, bailout_id); | 3494 value = BuildHoleCheckThenThrow(current, variable, value, bailout_id); |
| 3508 } | 3495 } |
| 3509 if (mode == CONST) { | 3496 if (mode == CONST) { |
| 3510 // Assignment to const is exception in all modes. | 3497 if (variable->throw_on_const_assignment(language_mode())) { |
| 3511 return BuildThrowConstAssignError(bailout_id); | 3498 return BuildThrowConstAssignError(bailout_id); |
| 3499 } else { | |
| 3500 return value; | |
| 3501 } | |
| 3512 } | 3502 } |
| 3513 } | 3503 } |
| 3514 const Operator* op = javascript()->StoreContext(depth, variable->index()); | 3504 const Operator* op = javascript()->StoreContext(depth, variable->index()); |
| 3515 return NewNode(op, current_context(), value); | 3505 return NewNode(op, current_context(), value); |
| 3516 } | 3506 } |
| 3517 case VariableLocation::LOOKUP: { | 3507 case VariableLocation::LOOKUP: { |
| 3518 // Dynamic lookup of context variable (anywhere in the chain). | 3508 // Dynamic lookup of context variable (anywhere in the chain). |
| 3519 Handle<Name> name = variable->name(); | 3509 Handle<Name> name = variable->name(); |
| 3520 Node* store = BuildDynamicStore(name, value); | 3510 Node* store = BuildDynamicStore(name, value); |
| 3521 PrepareFrameState(store, bailout_id, combine); | 3511 PrepareFrameState(store, bailout_id, combine); |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4320 // Phi does not exist yet, introduce one. | 4310 // Phi does not exist yet, introduce one. |
| 4321 value = NewPhi(inputs, value, control); | 4311 value = NewPhi(inputs, value, control); |
| 4322 value->ReplaceInput(inputs - 1, other); | 4312 value->ReplaceInput(inputs - 1, other); |
| 4323 } | 4313 } |
| 4324 return value; | 4314 return value; |
| 4325 } | 4315 } |
| 4326 | 4316 |
| 4327 } // namespace compiler | 4317 } // namespace compiler |
| 4328 } // namespace internal | 4318 } // namespace internal |
| 4329 } // namespace v8 | 4319 } // namespace v8 |
| OLD | NEW |