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 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/codegen.h" | 8 #include "src/codegen.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
(...skipping 2388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2399 // -- rdi : the target to call (can be any Object) | 2399 // -- rdi : the target to call (can be any Object) |
2400 // ----------------------------------- | 2400 // ----------------------------------- |
2401 StackArgumentsAccessor args(rsp, rax); | 2401 StackArgumentsAccessor args(rsp, rax); |
2402 | 2402 |
2403 Label non_callable, non_function, non_smi; | 2403 Label non_callable, non_function, non_smi; |
2404 __ JumpIfSmi(rdi, &non_callable); | 2404 __ JumpIfSmi(rdi, &non_callable); |
2405 __ bind(&non_smi); | 2405 __ bind(&non_smi); |
2406 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); | 2406 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); |
2407 __ j(equal, masm->isolate()->builtins()->CallFunction(mode, tail_call_mode), | 2407 __ j(equal, masm->isolate()->builtins()->CallFunction(mode, tail_call_mode), |
2408 RelocInfo::CODE_TARGET); | 2408 RelocInfo::CODE_TARGET); |
| 2409 |
| 2410 // Check if target has a [[Call]] internal method. |
| 2411 __ testb(FieldOperand(rcx, Map::kBitFieldOffset), |
| 2412 Immediate(1 << Map::kIsCallable)); |
| 2413 __ j(zero, &non_callable); |
| 2414 |
2409 __ CmpInstanceType(rcx, JS_BOUND_FUNCTION_TYPE); | 2415 __ CmpInstanceType(rcx, JS_BOUND_FUNCTION_TYPE); |
2410 __ j(equal, masm->isolate()->builtins()->CallBoundFunction(tail_call_mode), | 2416 __ j(equal, masm->isolate()->builtins()->CallBoundFunction(tail_call_mode), |
2411 RelocInfo::CODE_TARGET); | 2417 RelocInfo::CODE_TARGET); |
2412 __ CmpInstanceType(rcx, JS_PROXY_TYPE); | 2418 __ CmpInstanceType(rcx, JS_PROXY_TYPE); |
2413 __ j(not_equal, &non_function); | 2419 __ j(not_equal, &non_function); |
2414 | 2420 |
2415 // 0. Prepare for tail call if necessary. | 2421 // 0. Prepare for tail call if necessary. |
2416 if (tail_call_mode == TailCallMode::kAllow) { | 2422 if (tail_call_mode == TailCallMode::kAllow) { |
2417 PrepareForTailCall(masm, rax, rbx, rcx, r8); | 2423 PrepareForTailCall(masm, rax, rbx, rcx, r8); |
2418 } | 2424 } |
2419 | 2425 |
2420 // 1. Runtime fallback for Proxy [[Call]]. | 2426 // 1. Runtime fallback for Proxy [[Call]]. |
2421 __ PopReturnAddressTo(kScratchRegister); | 2427 __ PopReturnAddressTo(kScratchRegister); |
2422 __ Push(rdi); | 2428 __ Push(rdi); |
2423 __ PushReturnAddressFrom(kScratchRegister); | 2429 __ PushReturnAddressFrom(kScratchRegister); |
2424 // Increase the arguments size to include the pushed function and the | 2430 // Increase the arguments size to include the pushed function and the |
2425 // existing receiver on the stack. | 2431 // existing receiver on the stack. |
2426 __ addp(rax, Immediate(2)); | 2432 __ addp(rax, Immediate(2)); |
2427 // Tail-call to the runtime. | 2433 // Tail-call to the runtime. |
2428 __ JumpToExternalReference( | 2434 __ JumpToExternalReference( |
2429 ExternalReference(Runtime::kJSProxyCall, masm->isolate())); | 2435 ExternalReference(Runtime::kJSProxyCall, masm->isolate())); |
2430 | 2436 |
2431 // 2. Call to something else, which might have a [[Call]] internal method (if | 2437 // 2. Call to something else, which might have a [[Call]] internal method (if |
2432 // not we raise an exception). | 2438 // not we raise an exception). |
2433 __ bind(&non_function); | 2439 __ bind(&non_function); |
2434 // Check if target has a [[Call]] internal method. | |
2435 __ testb(FieldOperand(rcx, Map::kBitFieldOffset), | |
2436 Immediate(1 << Map::kIsCallable)); | |
2437 __ j(zero, &non_callable, Label::kNear); | |
2438 // Overwrite the original receiver with the (original) target. | 2440 // Overwrite the original receiver with the (original) target. |
2439 __ movp(args.GetReceiverOperand(), rdi); | 2441 __ movp(args.GetReceiverOperand(), rdi); |
2440 // Let the "call_as_function_delegate" take care of the rest. | 2442 // Let the "call_as_function_delegate" take care of the rest. |
2441 __ LoadNativeContextSlot(Context::CALL_AS_FUNCTION_DELEGATE_INDEX, rdi); | 2443 __ LoadNativeContextSlot(Context::CALL_AS_FUNCTION_DELEGATE_INDEX, rdi); |
2442 __ Jump(masm->isolate()->builtins()->CallFunction( | 2444 __ Jump(masm->isolate()->builtins()->CallFunction( |
2443 ConvertReceiverMode::kNotNullOrUndefined, tail_call_mode), | 2445 ConvertReceiverMode::kNotNullOrUndefined, tail_call_mode), |
2444 RelocInfo::CODE_TARGET); | 2446 RelocInfo::CODE_TARGET); |
2445 | 2447 |
2446 // 3. Call to something that is not callable. | 2448 // 3. Call to something that is not callable. |
2447 __ bind(&non_callable); | 2449 __ bind(&non_callable); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2741 __ ret(0); | 2743 __ ret(0); |
2742 } | 2744 } |
2743 | 2745 |
2744 | 2746 |
2745 #undef __ | 2747 #undef __ |
2746 | 2748 |
2747 } // namespace internal | 2749 } // namespace internal |
2748 } // namespace v8 | 2750 } // namespace v8 |
2749 | 2751 |
2750 #endif // V8_TARGET_ARCH_X64 | 2752 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |