| OLD | NEW |
| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 106 |
| 107 #ifdef DEBUG | 107 #ifdef DEBUG |
| 108 if (strlen(FLAG_stop_at) > 0 && | 108 if (strlen(FLAG_stop_at) > 0 && |
| 109 info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { | 109 info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
| 110 __ int3(); | 110 __ int3(); |
| 111 } | 111 } |
| 112 #endif | 112 #endif |
| 113 | 113 |
| 114 // Sloppy mode functions and builtins need to replace the receiver with the | 114 // Sloppy mode functions and builtins need to replace the receiver with the |
| 115 // global proxy when called as functions (without an explicit receiver | 115 // global proxy when called as functions (without an explicit receiver |
| 116 // object). | 116 // object). Arrow functions need to replace the receiver with the "this" |
| 117 if (info->strict_mode() == SLOPPY && !info->is_native()) { | 117 // binding from the context, so this does not need to be done for those. |
| 118 if (info->strict_mode() == SLOPPY && !info->is_native() && |
| 119 !info->function()->is_arrow()) { |
| 118 Label ok; | 120 Label ok; |
| 119 // +1 for return address. | 121 // +1 for return address. |
| 120 StackArgumentsAccessor args(rsp, info->scope()->num_parameters()); | 122 StackArgumentsAccessor args(rsp, info->scope()->num_parameters()); |
| 121 __ movp(rcx, args.GetReceiverOperand()); | 123 __ movp(rcx, args.GetReceiverOperand()); |
| 122 | 124 |
| 123 __ CompareRoot(rcx, Heap::kUndefinedValueRootIndex); | 125 __ CompareRoot(rcx, Heap::kUndefinedValueRootIndex); |
| 124 __ j(not_equal, &ok, Label::kNear); | 126 __ j(not_equal, &ok, Label::kNear); |
| 125 | 127 |
| 126 __ movp(rcx, GlobalObjectOperand()); | 128 __ movp(rcx, GlobalObjectOperand()); |
| 127 __ movp(rcx, FieldOperand(rcx, GlobalObject::kGlobalProxyOffset)); | 129 __ movp(rcx, FieldOperand(rcx, GlobalObject::kGlobalProxyOffset)); |
| 128 | 130 |
| 129 __ movp(args.GetReceiverOperand(), rcx); | 131 __ movp(args.GetReceiverOperand(), rcx); |
| 130 | 132 |
| 131 __ bind(&ok); | 133 __ bind(&ok); |
| 132 } | 134 } |
| 133 | 135 |
| 134 // Open a frame scope to indicate that there is a frame on the stack. The | 136 // Open a frame scope to indicate that there is a frame on the stack. The |
| 135 // MANUAL indicates that the scope shouldn't actually generate code to set up | 137 // MANUAL indicates that the scope shouldn't actually generate code to set up |
| 136 // the frame (that is done below). | 138 // the frame (that is done below). |
| 137 FrameScope frame_scope(masm_, StackFrame::MANUAL); | 139 FrameScope frame_scope(masm_, StackFrame::MANUAL); |
| 138 | 140 |
| 139 info->set_prologue_offset(masm_->pc_offset()); | 141 info->set_prologue_offset(masm_->pc_offset()); |
| 140 __ Prologue(info->IsCodePreAgingActive()); | 142 __ Prologue(info->IsCodePreAgingActive()); |
| 141 info->AddNoFrameRange(0, masm_->pc_offset()); | 143 info->AddNoFrameRange(0, masm_->pc_offset()); |
| 142 | 144 |
| 145 // For arrow functions the value of the receiver is stored in the context, |
| 146 // so in the case of a function that actually uses "this", the receiver is |
| 147 // replaced by the one resulting from looking it up in the context. |
| 148 if (info->function()->is_arrow() && info->scope()->uses_this()) { |
| 149 DCHECK(info->scope()->scope_type() == ARROW_SCOPE); |
| 150 Comment cmnt(masm_, "[ Patch receiver for arrow function"); |
| 151 StackArgumentsAccessor args(rbp, info->scope()->num_parameters()); |
| 152 __ Push(rsi); // Context |
| 153 __ Push(isolate()->factory()->this_string()); |
| 154 __ CallRuntime(Runtime::kLoadLookupSlot, 2); |
| 155 __ movp(args.GetReceiverOperand(), rax); |
| 156 } |
| 157 |
| 143 { Comment cmnt(masm_, "[ Allocate locals"); | 158 { Comment cmnt(masm_, "[ Allocate locals"); |
| 144 int locals_count = info->scope()->num_stack_slots(); | 159 int locals_count = info->scope()->num_stack_slots(); |
| 145 // Generators allocate locals, if any, in context slots. | 160 // Generators allocate locals, if any, in context slots. |
| 146 DCHECK(!info->function()->is_generator() || locals_count == 0); | 161 DCHECK(!info->function()->is_generator() || locals_count == 0); |
| 147 if (locals_count == 1) { | 162 if (locals_count == 1) { |
| 148 __ PushRoot(Heap::kUndefinedValueRootIndex); | 163 __ PushRoot(Heap::kUndefinedValueRootIndex); |
| 149 } else if (locals_count > 1) { | 164 } else if (locals_count > 1) { |
| 150 if (locals_count >= 128) { | 165 if (locals_count >= 128) { |
| 151 Label ok; | 166 Label ok; |
| 152 __ movp(rcx, rsp); | 167 __ movp(rcx, rsp); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 __ Push(rdi); | 215 __ Push(rdi); |
| 201 __ CallRuntime(Runtime::kNewFunctionContext, 1); | 216 __ CallRuntime(Runtime::kNewFunctionContext, 1); |
| 202 } | 217 } |
| 203 function_in_register = false; | 218 function_in_register = false; |
| 204 // Context is returned in rax. It replaces the context passed to us. | 219 // Context is returned in rax. It replaces the context passed to us. |
| 205 // It's saved in the stack and kept live in rsi. | 220 // It's saved in the stack and kept live in rsi. |
| 206 __ movp(rsi, rax); | 221 __ movp(rsi, rax); |
| 207 __ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rax); | 222 __ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rax); |
| 208 | 223 |
| 209 // Copy any necessary parameters into the context. | 224 // Copy any necessary parameters into the context. |
| 225 DCHECK(info->scope()->receiver()->IsContextSlot() == |
| 226 info->scope()->inner_uses_this()); |
| 227 |
| 210 int num_parameters = info->scope()->num_parameters(); | 228 int num_parameters = info->scope()->num_parameters(); |
| 211 for (int i = 0; i < num_parameters; i++) { | 229 for (int i = -1; i < num_parameters; i++) { |
| 212 Variable* var = scope()->parameter(i); | 230 Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i); |
| 213 if (var->IsContextSlot()) { | 231 if (var->IsContextSlot()) { |
| 214 int parameter_offset = StandardFrameConstants::kCallerSPOffset + | 232 int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 215 (num_parameters - 1 - i) * kPointerSize; | 233 (num_parameters - 1 - i) * kPointerSize; |
| 216 // Load parameter from stack. | 234 // Load parameter from stack. |
| 217 __ movp(rax, Operand(rbp, parameter_offset)); | 235 __ movp(rax, Operand(rbp, parameter_offset)); |
| 218 // Store it in the context. | 236 // Store it in the context. |
| 219 int context_offset = Context::SlotOffset(var->index()); | 237 int context_offset = Context::SlotOffset(var->index()); |
| 220 __ movp(Operand(rsi, context_offset), rax); | 238 __ movp(Operand(rsi, context_offset), rax); |
| 221 // Update the write barrier. This clobbers rax and rbx. | 239 // Update the write barrier. This clobbers rax and rbx. |
| 222 if (need_write_barrier) { | 240 if (need_write_barrier) { |
| (...skipping 4970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5193 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5211 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 5194 Assembler::target_address_at(call_target_address, | 5212 Assembler::target_address_at(call_target_address, |
| 5195 unoptimized_code)); | 5213 unoptimized_code)); |
| 5196 return OSR_AFTER_STACK_CHECK; | 5214 return OSR_AFTER_STACK_CHECK; |
| 5197 } | 5215 } |
| 5198 | 5216 |
| 5199 | 5217 |
| 5200 } } // namespace v8::internal | 5218 } } // namespace v8::internal |
| 5201 | 5219 |
| 5202 #endif // V8_TARGET_ARCH_X64 | 5220 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |