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