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 3927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3938 | 3938 |
3939 | 3939 |
3940 void StackCheckStub::Generate(MacroAssembler* masm) { | 3940 void StackCheckStub::Generate(MacroAssembler* masm) { |
3941 __ TailCallRuntime(Runtime::kStackGuard, 0, 1); | 3941 __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
3942 } | 3942 } |
3943 | 3943 |
3944 | 3944 |
3945 void CallFunctionStub::Generate(MacroAssembler* masm) { | 3945 void CallFunctionStub::Generate(MacroAssembler* masm) { |
3946 Label slow; | 3946 Label slow; |
3947 | 3947 |
3948 // If the receiver might be a value (string, number or boolean) check for this | 3948 // The receiver might implicitly be the global object. This is |
3949 // and box it if it is. | 3949 // indicated by passing the hole as the receiver to the call |
3950 if (ReceiverMightBeValue()) { | 3950 // function stub. |
| 3951 if (ReceiverMightBeImplicit()) { |
| 3952 Label call; |
3951 // Get the receiver from the stack. | 3953 // Get the receiver from the stack. |
3952 // +1 ~ return address | 3954 // +1 ~ return address |
3953 Label receiver_is_value, receiver_is_js_object; | |
3954 __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); | 3955 __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
3955 | 3956 // Call as function is indicated with the hole. |
3956 // Check if receiver is a smi (which is a number value). | 3957 __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
3957 __ test(eax, Immediate(kSmiTagMask)); | 3958 __ j(not_equal, &call, Label::kNear); |
3958 __ j(zero, &receiver_is_value); | 3959 // Patch the receiver on the stack with the global receiver object. |
3959 | 3960 __ mov(ebx, GlobalObjectOperand()); |
3960 // Check if the receiver is a valid JS object. | 3961 __ mov(ebx, FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset)); |
3961 __ CmpObjectType(eax, FIRST_JS_OBJECT_TYPE, edi); | 3962 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ebx); |
3962 __ j(above_equal, &receiver_is_js_object); | 3963 __ bind(&call); |
3963 | |
3964 // Call the runtime to box the value. | |
3965 __ bind(&receiver_is_value); | |
3966 __ EnterInternalFrame(); | |
3967 __ push(eax); | |
3968 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); | |
3969 __ LeaveInternalFrame(); | |
3970 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), eax); | |
3971 | |
3972 __ bind(&receiver_is_js_object); | |
3973 } | 3964 } |
3974 | 3965 |
3975 // Get the function to call from the stack. | 3966 // Get the function to call from the stack. |
3976 // +2 ~ receiver, return address | 3967 // +2 ~ receiver, return address |
3977 __ mov(edi, Operand(esp, (argc_ + 2) * kPointerSize)); | 3968 __ mov(edi, Operand(esp, (argc_ + 2) * kPointerSize)); |
3978 | 3969 |
3979 // Check that the function really is a JavaScript function. | 3970 // Check that the function really is a JavaScript function. |
3980 __ test(edi, Immediate(kSmiTagMask)); | 3971 __ test(edi, Immediate(kSmiTagMask)); |
3981 __ j(zero, &slow); | 3972 __ j(zero, &slow); |
3982 // Goto slow case if we do not have a function. | 3973 // Goto slow case if we do not have a function. |
3983 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); | 3974 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
3984 __ j(not_equal, &slow); | 3975 __ j(not_equal, &slow); |
3985 | 3976 |
3986 // Fast-case: Just invoke the function. | 3977 // Fast-case: Just invoke the function. |
3987 ParameterCount actual(argc_); | 3978 ParameterCount actual(argc_); |
3988 __ InvokeFunction(edi, actual, JUMP_FUNCTION); | 3979 |
| 3980 if (ReceiverMightBeImplicit()) { |
| 3981 Label call_as_function; |
| 3982 __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
| 3983 __ j(equal, &call_as_function); |
| 3984 __ InvokeFunction(edi, actual, JUMP_FUNCTION); |
| 3985 __ bind(&call_as_function); |
| 3986 } |
| 3987 __ InvokeFunction(edi, |
| 3988 actual, |
| 3989 JUMP_FUNCTION, |
| 3990 NullCallWrapper(), |
| 3991 CALL_AS_FUNCTION); |
3989 | 3992 |
3990 // Slow-case: Non-function called. | 3993 // Slow-case: Non-function called. |
3991 __ bind(&slow); | 3994 __ bind(&slow); |
3992 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead | 3995 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
3993 // of the original receiver from the call site). | 3996 // of the original receiver from the call site). |
3994 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); | 3997 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
3995 __ Set(eax, Immediate(argc_)); | 3998 __ Set(eax, Immediate(argc_)); |
3996 __ Set(ebx, Immediate(0)); | 3999 __ Set(ebx, Immediate(0)); |
3997 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); | 4000 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
3998 Handle<Code> adaptor = | 4001 Handle<Code> adaptor = |
(...skipping 2187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6186 __ Drop(1); | 6189 __ Drop(1); |
6187 __ ret(2 * kPointerSize); | 6190 __ ret(2 * kPointerSize); |
6188 } | 6191 } |
6189 | 6192 |
6190 | 6193 |
6191 #undef __ | 6194 #undef __ |
6192 | 6195 |
6193 } } // namespace v8::internal | 6196 } } // namespace v8::internal |
6194 | 6197 |
6195 #endif // V8_TARGET_ARCH_IA32 | 6198 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |