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_IA32 | 5 #if V8_TARGET_ARCH_IA32 |
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 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 // Tail call to the function-specific construct stub (still in the caller | 1570 // Tail call to the function-specific construct stub (still in the caller |
1571 // context at this point). | 1571 // context at this point). |
1572 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); | 1572 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
1573 __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset)); | 1573 __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset)); |
1574 __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize)); | 1574 __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize)); |
1575 __ jmp(ecx); | 1575 __ jmp(ecx); |
1576 } | 1576 } |
1577 | 1577 |
1578 | 1578 |
1579 // static | 1579 // static |
1580 void Builtins::Generate_ConstructProxy(MacroAssembler* masm) { | |
1581 // ----------- S t a t e ------------- | |
1582 // -- eax : the number of arguments (not including the receiver) | |
1583 // -- edx : the original constructor (either the same as the constructor or | |
1584 // the JSFunction on which new was invoked initially) | |
1585 // -- edi : the constructor to call (checked to be a JSFunctionProxy) | |
1586 // ----------------------------------- | |
1587 | |
1588 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies. | |
1589 __ mov(edi, FieldOperand(edi, JSFunctionProxy::kConstructTrapOffset)); | |
1590 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); | |
1591 } | |
1592 | |
1593 | |
1594 // static | |
1595 void Builtins::Generate_Construct(MacroAssembler* masm) { | 1580 void Builtins::Generate_Construct(MacroAssembler* masm) { |
1596 // ----------- S t a t e ------------- | 1581 // ----------- S t a t e ------------- |
1597 // -- eax : the number of arguments (not including the receiver) | 1582 // -- eax : the number of arguments (not including the receiver) |
1598 // -- edx : the original constructor (either the same as the constructor or | 1583 // -- edx : the original constructor (either the same as the constructor or |
1599 // the JSFunction on which new was invoked initially) | 1584 // the JSFunction on which new was invoked initially) |
1600 // -- edi : the constructor to call (can be any Object) | 1585 // -- edi : the constructor to call (can be any Object) |
1601 // ----------------------------------- | 1586 // ----------------------------------- |
1602 | 1587 |
1603 // Check if target has a [[Construct]] internal method. | 1588 Label non_callable, non_function; |
1604 Label non_constructor; | 1589 __ JumpIfSmi(edi, &non_callable); |
1605 __ JumpIfSmi(edi, &non_constructor, Label::kNear); | 1590 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
1606 __ mov(ecx, FieldOperand(edi, HeapObject::kMapOffset)); | |
1607 __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), 1 << Map::kIsConstructor); | |
1608 __ j(zero, &non_constructor, Label::kNear); | |
1609 | |
1610 // Dispatch based on instance type. | |
1611 __ CmpInstanceType(ecx, JS_FUNCTION_TYPE); | |
1612 __ j(equal, masm->isolate()->builtins()->ConstructFunction(), | 1591 __ j(equal, masm->isolate()->builtins()->ConstructFunction(), |
1613 RelocInfo::CODE_TARGET); | 1592 RelocInfo::CODE_TARGET); |
1614 __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); | 1593 __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
1615 __ j(equal, masm->isolate()->builtins()->ConstructProxy(), | 1594 __ j(not_equal, &non_function, Label::kNear); |
1616 RelocInfo::CODE_TARGET); | |
1617 | 1595 |
1618 // Called Construct on an exotic Object with a [[Construct]] internal method. | 1596 // 1. Construct of function proxy. |
1619 { | 1597 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies. |
1620 // Overwrite the original receiver with the (original) target. | 1598 __ mov(edi, FieldOperand(edi, JSFunctionProxy::kConstructTrapOffset)); |
1621 __ mov(Operand(esp, eax, times_pointer_size, kPointerSize), edi); | 1599 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); |
1622 // Let the "call_as_constructor_delegate" take care of the rest. | |
1623 __ LoadGlobalFunction(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, edi); | |
1624 __ Jump(masm->isolate()->builtins()->CallFunction(), | |
1625 RelocInfo::CODE_TARGET); | |
1626 } | |
1627 | 1600 |
1628 // Called Construct on an Object that doesn't have a [[Construct]] internal | 1601 // 2. Construct of something else, which might have a [[Construct]] internal |
1629 // method. | 1602 // method (if not we raise an exception). |
1630 __ bind(&non_constructor); | 1603 __ bind(&non_function); |
| 1604 // Check if target has a [[Call]] internal method. |
| 1605 // TODO(bmeurer): This shoud use IsConstructor once available. |
| 1606 __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), 1 << Map::kIsCallable); |
| 1607 __ j(zero, &non_callable, Label::kNear); |
| 1608 // Overwrite the original receiver with the (original) target. |
| 1609 __ mov(Operand(esp, eax, times_pointer_size, kPointerSize), edi); |
| 1610 // Let the "call_as_constructor_delegate" take care of the rest. |
| 1611 __ LoadGlobalFunction(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, edi); |
| 1612 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET); |
| 1613 |
| 1614 // 3. Construct of something that is not callable. |
| 1615 __ bind(&non_callable); |
1631 { | 1616 { |
1632 FrameScope scope(masm, StackFrame::INTERNAL); | 1617 FrameScope scope(masm, StackFrame::INTERNAL); |
1633 __ Push(edi); | 1618 __ Push(edi); |
1634 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1); | 1619 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1); |
1635 } | 1620 } |
1636 } | 1621 } |
1637 | 1622 |
1638 | 1623 |
1639 // static | 1624 // static |
1640 void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) { | 1625 void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1852 | 1837 |
1853 __ bind(&ok); | 1838 __ bind(&ok); |
1854 __ ret(0); | 1839 __ ret(0); |
1855 } | 1840 } |
1856 | 1841 |
1857 #undef __ | 1842 #undef __ |
1858 } // namespace internal | 1843 } // namespace internal |
1859 } // namespace v8 | 1844 } // namespace v8 |
1860 | 1845 |
1861 #endif // V8_TARGET_ARCH_IA32 | 1846 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |