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

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

Issue 1202963005: Fix receiver when calling eval() bound by with scope (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Full-codegen impls for all arches Created 5 years, 6 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/full-codegen.h ('k') | src/mips/full-codegen-mips.cc » ('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_IA32 7 #if V8_TARGET_ARCH_IA32
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 3018 matching lines...) Expand 10 before | Expand all | Expand 10 after
3029 Label uninitialized_this; 3029 Label uninitialized_this;
3030 __ j(equal, &uninitialized_this); 3030 __ j(equal, &uninitialized_this);
3031 __ push(Immediate(this_var->name())); 3031 __ push(Immediate(this_var->name()));
3032 __ CallRuntime(Runtime::kThrowReferenceError, 1); 3032 __ CallRuntime(Runtime::kThrowReferenceError, 1);
3033 __ bind(&uninitialized_this); 3033 __ bind(&uninitialized_this);
3034 3034
3035 EmitVariableAssignment(this_var, Token::INIT_CONST, slot); 3035 EmitVariableAssignment(this_var, Token::INIT_CONST, slot);
3036 } 3036 }
3037 3037
3038 3038
3039 // See http://www.ecma-international.org/ecma-262/6.0/#sec-function-calls.
3040 void FullCodeGenerator::PushCalleeAndWithBaseObject(Call* expr) {
3041 VariableProxy* callee = expr->expression()->AsVariableProxy();
3042 if (callee->var()->IsLookupSlot()) {
3043 Label slow, done;
3044 {
3045 PreservePositionScope scope(masm()->positions_recorder());
3046 // Generate code for loading from variables potentially shadowed by
3047 // eval-introduced variables.
3048 EmitDynamicLookupFastCase(callee, NOT_INSIDE_TYPEOF, &slow, &done);
3049 }
3050 __ bind(&slow);
3051 // Call the runtime to find the function to call (returned in eax) and
3052 // the object holding it (returned in edx).
3053 __ push(context_register());
3054 __ push(Immediate(callee->name()));
3055 __ CallRuntime(Runtime::kLoadLookupSlot, 2);
3056 __ push(eax); // Function.
3057 __ push(edx); // Receiver.
3058 PrepareForBailoutForId(expr->LookupId(), NO_REGISTERS);
3059
3060 // If fast case code has been generated, emit code to push the function
3061 // and receiver and have the slow path jump around this code.
3062 if (done.is_linked()) {
3063 Label call;
3064 __ jmp(&call, Label::kNear);
3065 __ bind(&done);
3066 // Push function.
3067 __ push(eax);
3068 // The receiver is implicitly the global receiver. Indicate this by
3069 // passing the hole to the call function stub.
3070 __ push(Immediate(isolate()->factory()->undefined_value()));
3071 __ bind(&call);
3072 }
3073 } else {
3074 VisitForStackValue(callee);
3075 // refEnv.WithBaseObject()
3076 __ push(Immediate(isolate()->factory()->undefined_value()));
3077 }
3078 }
3079
3080
3039 void FullCodeGenerator::VisitCall(Call* expr) { 3081 void FullCodeGenerator::VisitCall(Call* expr) {
3040 #ifdef DEBUG 3082 #ifdef DEBUG
3041 // We want to verify that RecordJSReturnSite gets called on all paths 3083 // We want to verify that RecordJSReturnSite gets called on all paths
3042 // through this function. Avoid early returns. 3084 // through this function. Avoid early returns.
3043 expr->return_is_recorded_ = false; 3085 expr->return_is_recorded_ = false;
3044 #endif 3086 #endif
3045 3087
3046 Comment cmnt(masm_, "[ Call"); 3088 Comment cmnt(masm_, "[ Call");
3047 Expression* callee = expr->expression(); 3089 Expression* callee = expr->expression();
3048 Call::CallType call_type = expr->GetCallType(isolate()); 3090 Call::CallType call_type = expr->GetCallType(isolate());
3049 3091
3050 if (call_type == Call::POSSIBLY_EVAL_CALL) { 3092 if (call_type == Call::POSSIBLY_EVAL_CALL) {
3051 // In a call to eval, we first call RuntimeHidden_ResolvePossiblyDirectEval 3093 // In a call to eval, we first call RuntimeHidden_ResolvePossiblyDirectEval
3052 // to resolve the function we need to call. Then we call the resolved 3094 // to resolve the function we need to call. Then we call the resolved
3053 // function using the given arguments. 3095 // function using the given arguments.
3054 ZoneList<Expression*>* args = expr->arguments(); 3096 ZoneList<Expression*>* args = expr->arguments();
3055 int arg_count = args->length(); 3097 int arg_count = args->length();
3056 { PreservePositionScope pos_scope(masm()->positions_recorder()); 3098 { PreservePositionScope pos_scope(masm()->positions_recorder());
3057 VisitForStackValue(callee); 3099 PushCalleeAndWithBaseObject(expr);
3058 // Reserved receiver slot. 3100
3059 __ push(Immediate(isolate()->factory()->undefined_value()));
3060 // Push the arguments. 3101 // Push the arguments.
3061 for (int i = 0; i < arg_count; i++) { 3102 for (int i = 0; i < arg_count; i++) {
3062 VisitForStackValue(args->at(i)); 3103 VisitForStackValue(args->at(i));
3063 } 3104 }
3064 3105
3065 // Push a copy of the function (found below the arguments) and 3106 // Push a copy of the function (found below the arguments) and
3066 // resolve eval. 3107 // resolve eval.
3067 __ push(Operand(esp, (arg_count + 1) * kPointerSize)); 3108 __ push(Operand(esp, (arg_count + 1) * kPointerSize));
3068 EmitResolvePossiblyDirectEval(arg_count); 3109 EmitResolvePossiblyDirectEval(arg_count);
3069 3110
3070 // Touch up the stack with the resolved function. 3111 // Touch up the stack with the resolved function.
3071 __ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax); 3112 __ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax);
3072 3113
3073 PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS); 3114 PrepareForBailoutForId(expr->EvalId(), NO_REGISTERS);
3074 } 3115 }
3075 // Record source position for debugger. 3116 // Record source position for debugger.
3076 SetSourcePosition(expr->position()); 3117 SetSourcePosition(expr->position());
3077 CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS); 3118 CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS);
3078 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); 3119 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize));
3079 __ CallStub(&stub); 3120 __ CallStub(&stub);
3080 RecordJSReturnSite(expr); 3121 RecordJSReturnSite(expr);
3081 // Restore context register. 3122 // Restore context register.
3082 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); 3123 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
3083 context()->DropAndPlug(1, eax); 3124 context()->DropAndPlug(1, eax);
3084 3125
3085 } else if (call_type == Call::GLOBAL_CALL) { 3126 } else if (call_type == Call::GLOBAL_CALL) {
3086 EmitCallWithLoadIC(expr); 3127 EmitCallWithLoadIC(expr);
3087 } else if (call_type == Call::LOOKUP_SLOT_CALL) { 3128 } else if (call_type == Call::LOOKUP_SLOT_CALL) {
3088 // Call to a lookup slot (dynamically introduced variable). 3129 // Call to a lookup slot (dynamically introduced variable).
3089 VariableProxy* proxy = callee->AsVariableProxy(); 3130 PushCalleeAndWithBaseObject(expr);
3090 Label slow, done;
3091 { PreservePositionScope scope(masm()->positions_recorder());
3092 // Generate code for loading from variables potentially shadowed by
3093 // eval-introduced variables.
3094 EmitDynamicLookupFastCase(proxy, NOT_INSIDE_TYPEOF, &slow, &done);
3095 }
3096 __ bind(&slow);
3097 // Call the runtime to find the function to call (returned in eax) and
3098 // the object holding it (returned in edx).
3099 __ push(context_register());
3100 __ push(Immediate(proxy->name()));
3101 __ CallRuntime(Runtime::kLoadLookupSlot, 2);
3102 __ push(eax); // Function.
3103 __ push(edx); // Receiver.
3104 PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS);
3105
3106 // If fast case code has been generated, emit code to push the function
3107 // and receiver and have the slow path jump around this code.
3108 if (done.is_linked()) {
3109 Label call;
3110 __ jmp(&call, Label::kNear);
3111 __ bind(&done);
3112 // Push function.
3113 __ push(eax);
3114 // The receiver is implicitly the global receiver. Indicate this by
3115 // passing the hole to the call function stub.
3116 __ push(Immediate(isolate()->factory()->undefined_value()));
3117 __ bind(&call);
3118 }
3119
3120 // The receiver is either the global receiver or an object found by
3121 // LoadContextSlot.
3122 EmitCall(expr); 3131 EmitCall(expr);
3123
3124 } else if (call_type == Call::PROPERTY_CALL) { 3132 } else if (call_type == Call::PROPERTY_CALL) {
3125 Property* property = callee->AsProperty(); 3133 Property* property = callee->AsProperty();
3126 bool is_named_call = property->key()->IsPropertyName(); 3134 bool is_named_call = property->key()->IsPropertyName();
3127 if (property->IsSuperAccess()) { 3135 if (property->IsSuperAccess()) {
3128 if (is_named_call) { 3136 if (is_named_call) {
3129 EmitSuperCallWithLoadIC(expr); 3137 EmitSuperCallWithLoadIC(expr);
3130 } else { 3138 } else {
3131 EmitKeyedSuperCallWithLoadIC(expr); 3139 EmitKeyedSuperCallWithLoadIC(expr);
3132 } 3140 }
3133 } else { 3141 } else {
(...skipping 2349 matching lines...) Expand 10 before | Expand all | Expand 10 after
5483 Assembler::target_address_at(call_target_address, 5491 Assembler::target_address_at(call_target_address,
5484 unoptimized_code)); 5492 unoptimized_code));
5485 return OSR_AFTER_STACK_CHECK; 5493 return OSR_AFTER_STACK_CHECK;
5486 } 5494 }
5487 5495
5488 5496
5489 } // namespace internal 5497 } // namespace internal
5490 } // namespace v8 5498 } // namespace v8
5491 5499
5492 #endif // V8_TARGET_ARCH_IA32 5500 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/full-codegen.h ('k') | src/mips/full-codegen-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698