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