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

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

Issue 1097283003: Resolve references to "this" the same way as normal variables (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Add tests for "this" scoping in arrow functions Created 5 years, 8 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
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 #ifdef DEBUG 108 #ifdef DEBUG
109 if (strlen(FLAG_stop_at) > 0 && 109 if (strlen(FLAG_stop_at) > 0 &&
110 info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { 110 info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) {
111 __ int3(); 111 __ int3();
112 } 112 }
113 #endif 113 #endif
114 114
115 // Sloppy mode functions and builtins need to replace the receiver with the 115 // Sloppy mode functions and builtins need to replace the receiver with the
116 // global proxy when called as functions (without an explicit receiver 116 // global proxy when called as functions (without an explicit receiver
117 // object). 117 // object).
118 if (is_sloppy(info->language_mode()) && !info->is_native()) { 118 if (is_sloppy(info->language_mode()) && !info->is_native() &&
119 info->scope()->has_this_declaration()) {
119 Label ok; 120 Label ok;
120 // +1 for return address. 121 // +1 for return address.
121 StackArgumentsAccessor args(rsp, info->scope()->num_parameters()); 122 StackArgumentsAccessor args(rsp, info->scope()->num_parameters());
122 __ movp(rcx, args.GetReceiverOperand()); 123 __ movp(rcx, args.GetReceiverOperand());
123 124
124 __ CompareRoot(rcx, Heap::kUndefinedValueRootIndex); 125 __ CompareRoot(rcx, Heap::kUndefinedValueRootIndex);
125 __ j(not_equal, &ok, Label::kNear); 126 __ j(not_equal, &ok, Label::kNear);
126 127
127 __ movp(rcx, GlobalObjectOperand()); 128 __ movp(rcx, GlobalObjectOperand());
128 __ movp(rcx, FieldOperand(rcx, GlobalObject::kGlobalProxyOffset)); 129 __ movp(rcx, FieldOperand(rcx, GlobalObject::kGlobalProxyOffset));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 __ CallRuntime(Runtime::kNewFunctionContext, 1); 203 __ CallRuntime(Runtime::kNewFunctionContext, 1);
203 } 204 }
204 function_in_register = false; 205 function_in_register = false;
205 // Context is returned in rax. It replaces the context passed to us. 206 // Context is returned in rax. It replaces the context passed to us.
206 // It's saved in the stack and kept live in rsi. 207 // It's saved in the stack and kept live in rsi.
207 __ movp(rsi, rax); 208 __ movp(rsi, rax);
208 __ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rax); 209 __ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rax);
209 210
210 // Copy any necessary parameters into the context. 211 // Copy any necessary parameters into the context.
211 int num_parameters = info->scope()->num_parameters(); 212 int num_parameters = info->scope()->num_parameters();
212 for (int i = 0; i < num_parameters; i++) { 213 int first_parameter = info->scope()->has_this_declaration() ? -1 : 0;
213 Variable* var = scope()->parameter(i); 214 for (int i = first_parameter; i < num_parameters; i++) {
215 Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i);
216 CHECK_NOT_NULL(var);
adamk 2015/04/22 15:50:54 Seems unnecessary since receiver() already has thi
wingo 2015/04/23 14:16:02 Good catch; was vestigial. Removed.
214 if (var->IsContextSlot()) { 217 if (var->IsContextSlot()) {
215 int parameter_offset = StandardFrameConstants::kCallerSPOffset + 218 int parameter_offset = StandardFrameConstants::kCallerSPOffset +
216 (num_parameters - 1 - i) * kPointerSize; 219 (num_parameters - 1 - i) * kPointerSize;
217 // Load parameter from stack. 220 // Load parameter from stack.
218 __ movp(rax, Operand(rbp, parameter_offset)); 221 __ movp(rax, Operand(rbp, parameter_offset));
219 // Store it in the context. 222 // Store it in the context.
220 int context_offset = Context::SlotOffset(var->index()); 223 int context_offset = Context::SlotOffset(var->index());
221 __ movp(Operand(rsi, context_offset), rax); 224 __ movp(Operand(rsi, context_offset), rax);
222 // Update the write barrier. This clobbers rax and rbx. 225 // Update the write barrier. This clobbers rax and rbx.
223 if (need_write_barrier) { 226 if (need_write_barrier) {
(...skipping 2758 matching lines...) Expand 10 before | Expand all | Expand 10 after
2982 if (arg_count > 0) { 2985 if (arg_count > 0) {
2983 __ Push(Operand(rsp, arg_count * kPointerSize)); 2986 __ Push(Operand(rsp, arg_count * kPointerSize));
2984 } else { 2987 } else {
2985 __ PushRoot(Heap::kUndefinedValueRootIndex); 2988 __ PushRoot(Heap::kUndefinedValueRootIndex);
2986 } 2989 }
2987 2990
2988 // Push the enclosing function. 2991 // Push the enclosing function.
2989 __ Push(Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); 2992 __ Push(Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
2990 2993
2991 // Push the receiver of the enclosing function and do runtime call. 2994 // Push the receiver of the enclosing function and do runtime call.
2992 StackArgumentsAccessor args(rbp, info_->scope()->num_parameters()); 2995 Variable* this_var = scope()->LookupThis();
2993 __ Push(args.GetReceiverOperand()); 2996 CHECK_NOT_NULL(this_var);
adamk 2015/04/22 15:50:54 DCHECK
wingo 2015/04/23 14:16:02 Done.
2997 __ Push(VarOperand(this_var, kScratchRegister));
2994 2998
2995 // Push the language mode. 2999 // Push the language mode.
2996 __ Push(Smi::FromInt(language_mode())); 3000 __ Push(Smi::FromInt(language_mode()));
2997 3001
2998 // Push the start position of the scope the calls resides in. 3002 // Push the start position of the scope the calls resides in.
2999 __ Push(Smi::FromInt(scope()->start_position())); 3003 __ Push(Smi::FromInt(scope()->start_position()));
3000 3004
3001 // Do the runtime call. 3005 // Do the runtime call.
3002 __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 6); 3006 __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 6);
3003 } 3007 }
(...skipping 2414 matching lines...) Expand 10 before | Expand all | Expand 10 after
5418 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), 5422 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(),
5419 Assembler::target_address_at(call_target_address, 5423 Assembler::target_address_at(call_target_address,
5420 unoptimized_code)); 5424 unoptimized_code));
5421 return OSR_AFTER_STACK_CHECK; 5425 return OSR_AFTER_STACK_CHECK;
5422 } 5426 }
5423 5427
5424 5428
5425 } } // namespace v8::internal 5429 } } // namespace v8::internal
5426 5430
5427 #endif // V8_TARGET_ARCH_X64 5431 #endif // V8_TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698