OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 3932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3943 | 3943 |
3944 | 3944 |
3945 void StackCheckStub::Generate(MacroAssembler* masm) { | 3945 void StackCheckStub::Generate(MacroAssembler* masm) { |
3946 __ TailCallRuntime(Runtime::kStackGuard, 0, 1); | 3946 __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
3947 } | 3947 } |
3948 | 3948 |
3949 | 3949 |
3950 void CallFunctionStub::Generate(MacroAssembler* masm) { | 3950 void CallFunctionStub::Generate(MacroAssembler* masm) { |
3951 Label slow; | 3951 Label slow; |
3952 | 3952 |
3953 // If the receiver might be a value (string, number or boolean) check for this | 3953 // The receiver might implicitly be the global object. This is |
3954 // and box it if it is. | 3954 // indicated by passing the hole as the receiver to the call |
3955 if (ReceiverMightBeValue()) { | 3955 // function stub. |
| 3956 if (ReceiverMightBeImplicit()) { |
| 3957 Label call; |
3956 // Get the receiver from the stack. | 3958 // Get the receiver from the stack. |
3957 // +1 ~ return address | 3959 // +1 ~ return address |
3958 Label receiver_is_value, receiver_is_js_object; | |
3959 __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); | 3960 __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
3960 | 3961 // Call as function is indicated with the hole. |
3961 // Check if receiver is a smi (which is a number value). | 3962 __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
3962 __ test(eax, Immediate(kSmiTagMask)); | 3963 __ j(not_equal, &call, Label::kNear); |
3963 __ j(zero, &receiver_is_value); | 3964 // Patch the receiver on the stack with the global receiver object. |
3964 | 3965 __ mov(ebx, GlobalObjectOperand()); |
3965 // Check if the receiver is a valid JS object. | 3966 __ mov(ebx, FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset)); |
3966 __ CmpObjectType(eax, FIRST_JS_OBJECT_TYPE, edi); | 3967 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ebx); |
3967 __ j(above_equal, &receiver_is_js_object); | 3968 __ bind(&call); |
3968 | |
3969 // Call the runtime to box the value. | |
3970 __ bind(&receiver_is_value); | |
3971 __ EnterInternalFrame(); | |
3972 __ push(eax); | |
3973 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); | |
3974 __ LeaveInternalFrame(); | |
3975 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), eax); | |
3976 | |
3977 __ bind(&receiver_is_js_object); | |
3978 } | 3969 } |
3979 | 3970 |
3980 // Get the function to call from the stack. | 3971 // Get the function to call from the stack. |
3981 // +2 ~ receiver, return address | 3972 // +2 ~ receiver, return address |
3982 __ mov(edi, Operand(esp, (argc_ + 2) * kPointerSize)); | 3973 __ mov(edi, Operand(esp, (argc_ + 2) * kPointerSize)); |
3983 | 3974 |
3984 // Check that the function really is a JavaScript function. | 3975 // Check that the function really is a JavaScript function. |
3985 __ test(edi, Immediate(kSmiTagMask)); | 3976 __ test(edi, Immediate(kSmiTagMask)); |
3986 __ j(zero, &slow); | 3977 __ j(zero, &slow); |
3987 // Goto slow case if we do not have a function. | 3978 // Goto slow case if we do not have a function. |
3988 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); | 3979 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
3989 __ j(not_equal, &slow); | 3980 __ j(not_equal, &slow); |
3990 | 3981 |
3991 // Fast-case: Just invoke the function. | 3982 // Fast-case: Just invoke the function. |
3992 ParameterCount actual(argc_); | 3983 ParameterCount actual(argc_); |
3993 __ InvokeFunction(edi, actual, JUMP_FUNCTION); | 3984 |
| 3985 if (ReceiverMightBeImplicit()) { |
| 3986 Label call_as_function; |
| 3987 __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
| 3988 __ j(equal, &call_as_function); |
| 3989 __ InvokeFunction(edi, actual, JUMP_FUNCTION); |
| 3990 __ bind(&call_as_function); |
| 3991 } |
| 3992 __ InvokeFunction(edi, |
| 3993 actual, |
| 3994 JUMP_FUNCTION, |
| 3995 NullCallWrapper(), |
| 3996 CALL_AS_FUNCTION); |
3994 | 3997 |
3995 // Slow-case: Non-function called. | 3998 // Slow-case: Non-function called. |
3996 __ bind(&slow); | 3999 __ bind(&slow); |
3997 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead | 4000 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
3998 // of the original receiver from the call site). | 4001 // of the original receiver from the call site). |
3999 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); | 4002 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
4000 __ Set(eax, Immediate(argc_)); | 4003 __ Set(eax, Immediate(argc_)); |
4001 __ Set(ebx, Immediate(0)); | 4004 __ Set(ebx, Immediate(0)); |
4002 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); | 4005 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
4003 Handle<Code> adaptor = | 4006 Handle<Code> adaptor = |
(...skipping 2187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6191 __ Drop(1); | 6194 __ Drop(1); |
6192 __ ret(2 * kPointerSize); | 6195 __ ret(2 * kPointerSize); |
6193 } | 6196 } |
6194 | 6197 |
6195 | 6198 |
6196 #undef __ | 6199 #undef __ |
6197 | 6200 |
6198 } } // namespace v8::internal | 6201 } } // namespace v8::internal |
6199 | 6202 |
6200 #endif // V8_TARGET_ARCH_IA32 | 6203 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |