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