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

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