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

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

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

Powered by Google App Engine
This is Rietveld 408576698