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

Side by Side Diff: src/x64/full-codegen-x64.cc

Issue 976053002: Fix exception for assignment to uninitialised const (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comments Created 5 years, 9 months 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 unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-scopes.cc ('k') | test/mjsunit/harmony/block-const-assign.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/v8.h" 5 #include "src/v8.h"
6 6
7 #if V8_TARGET_ARCH_X64 7 #if V8_TARGET_ARCH_X64
8 8
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 2617 matching lines...) Expand 10 before | Expand all | Expand 10 after
2628 2628
2629 2629
2630 void FullCodeGenerator::EmitVariableAssignment(Variable* var, 2630 void FullCodeGenerator::EmitVariableAssignment(Variable* var,
2631 Token::Value op) { 2631 Token::Value op) {
2632 if (var->IsUnallocated()) { 2632 if (var->IsUnallocated()) {
2633 // Global var, const, or let. 2633 // Global var, const, or let.
2634 __ Move(StoreDescriptor::NameRegister(), var->name()); 2634 __ Move(StoreDescriptor::NameRegister(), var->name());
2635 __ movp(StoreDescriptor::ReceiverRegister(), GlobalObjectOperand()); 2635 __ movp(StoreDescriptor::ReceiverRegister(), GlobalObjectOperand());
2636 CallStoreIC(); 2636 CallStoreIC();
2637 2637
2638 } else if (op == Token::INIT_CONST_LEGACY) {
2639 // Const initializers need a write barrier.
2640 DCHECK(!var->IsParameter()); // No const parameters.
2641 if (var->IsLookupSlot()) {
2642 __ Push(rax);
2643 __ Push(rsi);
2644 __ Push(var->name());
2645 __ CallRuntime(Runtime::kInitializeLegacyConstLookupSlot, 3);
2646 } else {
2647 DCHECK(var->IsStackLocal() || var->IsContextSlot());
2648 Label skip;
2649 MemOperand location = VarOperand(var, rcx);
2650 __ movp(rdx, location);
2651 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex);
2652 __ j(not_equal, &skip);
2653 EmitStoreToStackLocalOrContextSlot(var, location);
2654 __ bind(&skip);
2655 }
2656
2657 } else if (var->mode() == LET && op != Token::INIT_LET) { 2638 } else if (var->mode() == LET && op != Token::INIT_LET) {
2658 // Non-initializing assignment to let variable needs a write barrier. 2639 // Non-initializing assignment to let variable needs a write barrier.
2659 DCHECK(!var->IsLookupSlot()); 2640 DCHECK(!var->IsLookupSlot());
2660 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); 2641 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2661 Label assign; 2642 Label assign;
2662 MemOperand location = VarOperand(var, rcx); 2643 MemOperand location = VarOperand(var, rcx);
2663 __ movp(rdx, location); 2644 __ movp(rdx, location);
2664 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); 2645 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex);
2665 __ j(not_equal, &assign, Label::kNear); 2646 __ j(not_equal, &assign, Label::kNear);
2666 __ Push(var->name()); 2647 __ Push(var->name());
2667 __ CallRuntime(Runtime::kThrowReferenceError, 1); 2648 __ CallRuntime(Runtime::kThrowReferenceError, 1);
2668 __ bind(&assign); 2649 __ bind(&assign);
2669 EmitStoreToStackLocalOrContextSlot(var, location); 2650 EmitStoreToStackLocalOrContextSlot(var, location);
2670 2651
2652 } else if (var->mode() == CONST && op != Token::INIT_CONST) {
2653 // Assignment to const variable needs a write barrier.
2654 DCHECK(!var->IsLookupSlot());
2655 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2656 Label const_error;
2657 MemOperand location = VarOperand(var, rcx);
2658 __ movp(rdx, location);
2659 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex);
2660 __ j(not_equal, &const_error, Label::kNear);
2661 __ Push(var->name());
2662 __ CallRuntime(Runtime::kThrowReferenceError, 1);
2663 __ bind(&const_error);
2664 __ CallRuntime(Runtime::kThrowConstAssignError, 0);
2665
2671 } else if (!var->is_const_mode() || op == Token::INIT_CONST) { 2666 } else if (!var->is_const_mode() || op == Token::INIT_CONST) {
2672 if (var->IsLookupSlot()) { 2667 if (var->IsLookupSlot()) {
2673 // Assignment to var. 2668 // Assignment to var.
2674 __ Push(rax); // Value. 2669 __ Push(rax); // Value.
2675 __ Push(rsi); // Context. 2670 __ Push(rsi); // Context.
2676 __ Push(var->name()); 2671 __ Push(var->name());
2677 __ Push(Smi::FromInt(language_mode())); 2672 __ Push(Smi::FromInt(language_mode()));
2678 __ CallRuntime(Runtime::kStoreLookupSlot, 4); 2673 __ CallRuntime(Runtime::kStoreLookupSlot, 4);
2679 } else { 2674 } else {
2680 // Assignment to var or initializing assignment to let/const in harmony 2675 // Assignment to var or initializing assignment to let/const in harmony
2681 // mode. 2676 // mode.
2682 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); 2677 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2683 MemOperand location = VarOperand(var, rcx); 2678 MemOperand location = VarOperand(var, rcx);
2684 if (generate_debug_code_ && op == Token::INIT_LET) { 2679 if (generate_debug_code_ && op == Token::INIT_LET) {
2685 // Check for an uninitialized let binding. 2680 // Check for an uninitialized let binding.
2686 __ movp(rdx, location); 2681 __ movp(rdx, location);
2687 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); 2682 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex);
2688 __ Check(equal, kLetBindingReInitialization); 2683 __ Check(equal, kLetBindingReInitialization);
2689 } 2684 }
2690 EmitStoreToStackLocalOrContextSlot(var, location); 2685 EmitStoreToStackLocalOrContextSlot(var, location);
2691 } 2686 }
2692 } else if (IsSignallingAssignmentToConst(var, op, language_mode())) { 2687
2693 __ CallRuntime(Runtime::kThrowConstAssignError, 0); 2688 } else if (op == Token::INIT_CONST_LEGACY) {
2689 // Const initializers need a write barrier.
2690 DCHECK(var->mode() == CONST_LEGACY);
2691 DCHECK(!var->IsParameter()); // No const parameters.
2692 if (var->IsLookupSlot()) {
2693 __ Push(rax);
2694 __ Push(rsi);
2695 __ Push(var->name());
2696 __ CallRuntime(Runtime::kInitializeLegacyConstLookupSlot, 3);
2697 } else {
2698 DCHECK(var->IsStackLocal() || var->IsContextSlot());
2699 Label skip;
2700 MemOperand location = VarOperand(var, rcx);
2701 __ movp(rdx, location);
2702 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex);
2703 __ j(not_equal, &skip);
2704 EmitStoreToStackLocalOrContextSlot(var, location);
2705 __ bind(&skip);
2706 }
2707
2708 } else {
2709 DCHECK(var->mode() == CONST_LEGACY && op != Token::INIT_CONST_LEGACY);
2710 if (is_strict(language_mode())) {
2711 __ CallRuntime(Runtime::kThrowConstAssignError, 0);
2712 }
2713 // Silently ignore store in sloppy mode.
2694 } 2714 }
2695 } 2715 }
2696 2716
2697 2717
2698 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { 2718 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) {
2699 // Assignment to a property, using a named store IC. 2719 // Assignment to a property, using a named store IC.
2700 Property* prop = expr->target()->AsProperty(); 2720 Property* prop = expr->target()->AsProperty();
2701 DCHECK(prop != NULL); 2721 DCHECK(prop != NULL);
2702 DCHECK(prop->key()->IsLiteral()); 2722 DCHECK(prop->key()->IsLiteral());
2703 2723
(...skipping 2682 matching lines...) Expand 10 before | Expand all | Expand 10 after
5386 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), 5406 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(),
5387 Assembler::target_address_at(call_target_address, 5407 Assembler::target_address_at(call_target_address,
5388 unoptimized_code)); 5408 unoptimized_code));
5389 return OSR_AFTER_STACK_CHECK; 5409 return OSR_AFTER_STACK_CHECK;
5390 } 5410 }
5391 5411
5392 5412
5393 } } // namespace v8::internal 5413 } } // namespace v8::internal
5394 5414
5395 #endif // V8_TARGET_ARCH_X64 5415 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/runtime/runtime-scopes.cc ('k') | test/mjsunit/harmony/block-const-assign.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698