| 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 if (scope->NeedsContext()) { | 542 if (scope->NeedsContext()) { |
| 543 // Push a new inner context scope for the current activation. | 543 // Push a new inner context scope for the current activation. |
| 544 Node* inner_context = BuildLocalActivationContext(GetFunctionContext()); | 544 Node* inner_context = BuildLocalActivationContext(GetFunctionContext()); |
| 545 ContextScope top_context(this, scope, inner_context); | 545 ContextScope top_context(this, scope, inner_context); |
| 546 CreateGraphBody(stack_check); | 546 CreateGraphBody(stack_check); |
| 547 } else { | 547 } else { |
| 548 // Simply use the outer function context in building the graph. | 548 // Simply use the outer function context in building the graph. |
| (...skipping 2885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3434 case VariableLocation::UNALLOCATED: { | 3434 case VariableLocation::UNALLOCATED: { |
| 3435 // Global var, const, or let variable. | 3435 // Global var, const, or let variable. |
| 3436 Handle<Name> name = variable->name(); | 3436 Handle<Name> name = variable->name(); |
| 3437 Node* store = BuildGlobalStore(name, value, feedback); | 3437 Node* store = BuildGlobalStore(name, value, feedback); |
| 3438 PrepareFrameState(store, bailout_id, combine); | 3438 PrepareFrameState(store, bailout_id, combine); |
| 3439 return store; | 3439 return store; |
| 3440 } | 3440 } |
| 3441 case VariableLocation::PARAMETER: | 3441 case VariableLocation::PARAMETER: |
| 3442 case VariableLocation::LOCAL: | 3442 case VariableLocation::LOCAL: |
| 3443 // Local var, const, or let variable. | 3443 // Local var, const, or let variable. |
| 3444 if (mode == CONST_LEGACY && op != Token::INIT) { | 3444 if (mode == LET && op == Token::INIT) { |
| 3445 // Non-initializing assignment to legacy const is | |
| 3446 // - exception in strict mode. | |
| 3447 // - ignored in sloppy mode. | |
| 3448 if (is_strict(language_mode())) { | |
| 3449 return BuildThrowConstAssignError(bailout_id); | |
| 3450 } | |
| 3451 return value; | |
| 3452 } else if (mode == LET && op == Token::INIT) { | |
| 3453 // No initialization check needed because scoping guarantees it. Note | 3445 // No initialization check needed because scoping guarantees it. Note |
| 3454 // that we still perform a lookup to keep the variable live, because | 3446 // that we still perform a lookup to keep the variable live, because |
| 3455 // baseline code might contain debug code that inspects the variable. | 3447 // baseline code might contain debug code that inspects the variable. |
| 3456 Node* current = environment()->Lookup(variable); | 3448 Node* current = environment()->Lookup(variable); |
| 3457 CHECK_NOT_NULL(current); | 3449 CHECK_NOT_NULL(current); |
| 3458 } else if (mode == LET && op != Token::INIT && | 3450 } else if (mode == LET && op != Token::INIT && |
| 3459 variable->binding_needs_init()) { | 3451 variable->binding_needs_init()) { |
| 3460 // Perform an initialization check for let declared variables. | 3452 // Perform an initialization check for let declared variables. |
| 3461 Node* current = environment()->Lookup(variable); | 3453 Node* current = environment()->Lookup(variable); |
| 3462 if (current->op() == the_hole->op()) { | 3454 if (current->op() == the_hole->op()) { |
| 3463 return BuildThrowReferenceError(variable, bailout_id); | 3455 return BuildThrowReferenceError(variable, bailout_id); |
| 3464 } else if (current->opcode() == IrOpcode::kPhi) { | 3456 } else if (current->opcode() == IrOpcode::kPhi) { |
| 3465 BuildHoleCheckThenThrow(current, variable, value, bailout_id); | 3457 BuildHoleCheckThenThrow(current, variable, value, bailout_id); |
| 3466 } | 3458 } |
| 3467 } else if (mode == CONST && op == Token::INIT) { | 3459 } else if (mode == CONST && op == Token::INIT) { |
| 3468 // Perform an initialization check for const {this} variables. | 3460 // Perform an initialization check for const {this} variables. |
| 3469 // Note that the {this} variable is the only const variable being able | 3461 // Note that the {this} variable is the only const variable being able |
| 3470 // to trigger bind operations outside the TDZ, via {super} calls. | 3462 // to trigger bind operations outside the TDZ, via {super} calls. |
| 3471 Node* current = environment()->Lookup(variable); | 3463 Node* current = environment()->Lookup(variable); |
| 3472 if (current->op() != the_hole->op() && variable->is_this()) { | 3464 if (current->op() != the_hole->op() && variable->is_this()) { |
| 3473 value = BuildHoleCheckElseThrow(current, variable, value, bailout_id); | 3465 value = BuildHoleCheckElseThrow(current, variable, value, bailout_id); |
| 3474 } | 3466 } |
| 3467 } else if (mode == CONST && op != Token::INIT && |
| 3468 variable->is_sloppy_function_name()) { |
| 3469 // Non-initializing assignment to sloppy function names is |
| 3470 // - exception in strict mode. |
| 3471 // - ignored in sloppy mode. |
| 3472 DCHECK(!variable->binding_needs_init()); |
| 3473 if (variable->throw_on_const_assignment(language_mode())) { |
| 3474 return BuildThrowConstAssignError(bailout_id); |
| 3475 } |
| 3476 return value; |
| 3475 } else if (mode == CONST && op != Token::INIT) { | 3477 } else if (mode == CONST && op != Token::INIT) { |
| 3476 if (variable->binding_needs_init()) { | 3478 if (variable->binding_needs_init()) { |
| 3477 Node* current = environment()->Lookup(variable); | 3479 Node* current = environment()->Lookup(variable); |
| 3478 if (current->op() == the_hole->op()) { | 3480 if (current->op() == the_hole->op()) { |
| 3479 return BuildThrowReferenceError(variable, bailout_id); | 3481 return BuildThrowReferenceError(variable, bailout_id); |
| 3480 } else if (current->opcode() == IrOpcode::kPhi) { | 3482 } else if (current->opcode() == IrOpcode::kPhi) { |
| 3481 BuildHoleCheckThenThrow(current, variable, value, bailout_id); | 3483 BuildHoleCheckThenThrow(current, variable, value, bailout_id); |
| 3482 } | 3484 } |
| 3483 } | 3485 } |
| 3484 // Assignment to const is exception in all modes. | 3486 // Assignment to const is exception in all modes. |
| 3485 return BuildThrowConstAssignError(bailout_id); | 3487 return BuildThrowConstAssignError(bailout_id); |
| 3486 } | 3488 } |
| 3487 environment()->Bind(variable, value); | 3489 environment()->Bind(variable, value); |
| 3488 return value; | 3490 return value; |
| 3489 case VariableLocation::CONTEXT: { | 3491 case VariableLocation::CONTEXT: { |
| 3490 // Context variable (potentially up the context chain). | 3492 // Context variable (potentially up the context chain). |
| 3491 int depth = current_scope()->ContextChainLength(variable->scope()); | 3493 int depth = current_scope()->ContextChainLength(variable->scope()); |
| 3492 if (mode == CONST_LEGACY && op != Token::INIT) { | 3494 if (mode == LET && op != Token::INIT && variable->binding_needs_init()) { |
| 3493 // Non-initializing assignment to legacy const is | |
| 3494 // - exception in strict mode. | |
| 3495 // - ignored in sloppy mode. | |
| 3496 if (is_strict(language_mode())) { | |
| 3497 return BuildThrowConstAssignError(bailout_id); | |
| 3498 } | |
| 3499 return value; | |
| 3500 } else if (mode == LET && op != Token::INIT && | |
| 3501 variable->binding_needs_init()) { | |
| 3502 // Perform an initialization check for let declared variables. | 3495 // Perform an initialization check for let declared variables. |
| 3503 const Operator* op = | 3496 const Operator* op = |
| 3504 javascript()->LoadContext(depth, variable->index(), false); | 3497 javascript()->LoadContext(depth, variable->index(), false); |
| 3505 Node* current = NewNode(op, current_context()); | 3498 Node* current = NewNode(op, current_context()); |
| 3506 value = BuildHoleCheckThenThrow(current, variable, value, bailout_id); | 3499 value = BuildHoleCheckThenThrow(current, variable, value, bailout_id); |
| 3507 } else if (mode == CONST && op == Token::INIT) { | 3500 } else if (mode == CONST && op == Token::INIT) { |
| 3508 // Perform an initialization check for const {this} variables. | 3501 // Perform an initialization check for const {this} variables. |
| 3509 // Note that the {this} variable is the only const variable being able | 3502 // Note that the {this} variable is the only const variable being able |
| 3510 // to trigger bind operations outside the TDZ, via {super} calls. | 3503 // to trigger bind operations outside the TDZ, via {super} calls. |
| 3511 if (variable->is_this()) { | 3504 if (variable->is_this()) { |
| 3512 const Operator* op = | 3505 const Operator* op = |
| 3513 javascript()->LoadContext(depth, variable->index(), false); | 3506 javascript()->LoadContext(depth, variable->index(), false); |
| 3514 Node* current = NewNode(op, current_context()); | 3507 Node* current = NewNode(op, current_context()); |
| 3515 value = BuildHoleCheckElseThrow(current, variable, value, bailout_id); | 3508 value = BuildHoleCheckElseThrow(current, variable, value, bailout_id); |
| 3516 } | 3509 } |
| 3510 } else if (mode == CONST && op != Token::INIT && |
| 3511 variable->is_sloppy_function_name()) { |
| 3512 // Non-initializing assignment to sloppy function names is |
| 3513 // - exception in strict mode. |
| 3514 // - ignored in sloppy mode. |
| 3515 DCHECK(!variable->binding_needs_init()); |
| 3516 if (variable->throw_on_const_assignment(language_mode())) { |
| 3517 return BuildThrowConstAssignError(bailout_id); |
| 3518 } |
| 3519 return value; |
| 3517 } else if (mode == CONST && op != Token::INIT) { | 3520 } else if (mode == CONST && op != Token::INIT) { |
| 3518 if (variable->binding_needs_init()) { | 3521 if (variable->binding_needs_init()) { |
| 3519 const Operator* op = | 3522 const Operator* op = |
| 3520 javascript()->LoadContext(depth, variable->index(), false); | 3523 javascript()->LoadContext(depth, variable->index(), false); |
| 3521 Node* current = NewNode(op, current_context()); | 3524 Node* current = NewNode(op, current_context()); |
| 3522 BuildHoleCheckThenThrow(current, variable, value, bailout_id); | 3525 BuildHoleCheckThenThrow(current, variable, value, bailout_id); |
| 3523 } | 3526 } |
| 3524 // Assignment to const is exception in all modes. | 3527 // Assignment to const is exception in all modes. |
| 3525 return BuildThrowConstAssignError(bailout_id); | 3528 return BuildThrowConstAssignError(bailout_id); |
| 3526 } | 3529 } |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4333 // Phi does not exist yet, introduce one. | 4336 // Phi does not exist yet, introduce one. |
| 4334 value = NewPhi(inputs, value, control); | 4337 value = NewPhi(inputs, value, control); |
| 4335 value->ReplaceInput(inputs - 1, other); | 4338 value->ReplaceInput(inputs - 1, other); |
| 4336 } | 4339 } |
| 4337 return value; | 4340 return value; |
| 4338 } | 4341 } |
| 4339 | 4342 |
| 4340 } // namespace compiler | 4343 } // namespace compiler |
| 4341 } // namespace internal | 4344 } // namespace internal |
| 4342 } // namespace v8 | 4345 } // namespace v8 |
| OLD | NEW |