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