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 1763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1774 // Tail call to the function-specific construct stub (still in the caller | 1774 // Tail call to the function-specific construct stub (still in the caller |
1775 // context at this point). | 1775 // context at this point). |
1776 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 1776 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
1777 __ movp(rcx, FieldOperand(rcx, SharedFunctionInfo::kConstructStubOffset)); | 1777 __ movp(rcx, FieldOperand(rcx, SharedFunctionInfo::kConstructStubOffset)); |
1778 __ leap(rcx, FieldOperand(rcx, Code::kHeaderSize)); | 1778 __ leap(rcx, FieldOperand(rcx, Code::kHeaderSize)); |
1779 __ jmp(rcx); | 1779 __ jmp(rcx); |
1780 } | 1780 } |
1781 | 1781 |
1782 | 1782 |
1783 // static | 1783 // static |
1784 void Builtins::Generate_ConstructProxy(MacroAssembler* masm) { | |
1785 // ----------- S t a t e ------------- | |
1786 // -- rax : the number of arguments (not including the receiver) | |
1787 // -- rdx : the original constructor (either the same as the constructor or | |
1788 // the JSFunction on which new was invoked initially) | |
1789 // -- rdi : the constructor to call (checked to be a JSFunctionProxy) | |
1790 // ----------------------------------- | |
1791 | |
1792 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies. | |
1793 __ movp(rdi, FieldOperand(rdi, JSFunctionProxy::kConstructTrapOffset)); | |
1794 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); | |
1795 } | |
1796 | |
1797 | |
1798 // static | |
1799 void Builtins::Generate_Construct(MacroAssembler* masm) { | 1784 void Builtins::Generate_Construct(MacroAssembler* masm) { |
1800 // ----------- S t a t e ------------- | 1785 // ----------- S t a t e ------------- |
1801 // -- rax : the number of arguments (not including the receiver) | 1786 // -- rax : the number of arguments (not including the receiver) |
1802 // -- rdx : the original constructor (either the same as the constructor or | 1787 // -- rdx : the original constructor (either the same as the constructor or |
1803 // the JSFunction on which new was invoked initially) | 1788 // the JSFunction on which new was invoked initially) |
1804 // -- rdi : the constructor to call (can be any Object) | 1789 // -- rdi : the constructor to call (can be any Object) |
1805 // ----------------------------------- | 1790 // ----------------------------------- |
1806 StackArgumentsAccessor args(rsp, rax); | 1791 StackArgumentsAccessor args(rsp, rax); |
1807 | 1792 |
1808 // Check if target has a [[Construct]] internal method. | 1793 Label non_callable, non_function; |
1809 Label non_constructor; | 1794 __ JumpIfSmi(rdi, &non_callable); |
1810 __ JumpIfSmi(rdi, &non_constructor, Label::kNear); | 1795 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); |
1811 __ movp(rcx, FieldOperand(rdi, HeapObject::kMapOffset)); | |
1812 __ testb(FieldOperand(rcx, Map::kBitFieldOffset), | |
1813 Immediate(1 << Map::kIsConstructor)); | |
1814 __ j(zero, &non_constructor, Label::kNear); | |
1815 | |
1816 // Dispatch based on instance type. | |
1817 __ CmpInstanceType(rcx, JS_FUNCTION_TYPE); | |
1818 __ j(equal, masm->isolate()->builtins()->ConstructFunction(), | 1796 __ j(equal, masm->isolate()->builtins()->ConstructFunction(), |
1819 RelocInfo::CODE_TARGET); | 1797 RelocInfo::CODE_TARGET); |
1820 __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); | 1798 __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); |
1821 __ j(equal, masm->isolate()->builtins()->ConstructProxy(), | 1799 __ j(not_equal, &non_function, Label::kNear); |
1822 RelocInfo::CODE_TARGET); | |
1823 | 1800 |
1824 // Called Construct on an exotic Object with a [[Construct]] internal method. | 1801 // 1. Construct of function proxy. |
1825 { | 1802 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies. |
1826 // Overwrite the original receiver with the (original) target. | 1803 __ movp(rdi, FieldOperand(rdi, JSFunctionProxy::kConstructTrapOffset)); |
1827 __ movp(args.GetReceiverOperand(), rdi); | 1804 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); |
1828 // Let the "call_as_constructor_delegate" take care of the rest. | |
1829 __ LoadGlobalFunction(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, rdi); | |
1830 __ Jump(masm->isolate()->builtins()->CallFunction(), | |
1831 RelocInfo::CODE_TARGET); | |
1832 } | |
1833 | 1805 |
1834 // Called Construct on an Object that doesn't have a [[Construct]] internal | 1806 // 2. Construct of something else, which might have a [[Construct]] internal |
1835 // method. | 1807 // method (if not we raise an exception). |
1836 __ bind(&non_constructor); | 1808 __ bind(&non_function); |
| 1809 // Check if target has a [[Call]] internal method. |
| 1810 // TODO(bmeurer): This shoud use IsConstructor once available. |
| 1811 __ testb(FieldOperand(rcx, Map::kBitFieldOffset), |
| 1812 Immediate(1 << Map::kIsCallable)); |
| 1813 __ j(zero, &non_callable, Label::kNear); |
| 1814 // Overwrite the original receiver with the (original) target. |
| 1815 __ movp(args.GetReceiverOperand(), rdi); |
| 1816 // Let the "call_as_constructor_delegate" take care of the rest. |
| 1817 __ LoadGlobalFunction(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, rdi); |
| 1818 __ Jump(masm->isolate()->builtins()->CallFunction(), RelocInfo::CODE_TARGET); |
| 1819 |
| 1820 // 3. Construct of something that is not callable. |
| 1821 __ bind(&non_callable); |
1837 { | 1822 { |
1838 FrameScope scope(masm, StackFrame::INTERNAL); | 1823 FrameScope scope(masm, StackFrame::INTERNAL); |
1839 __ Push(rdi); | 1824 __ Push(rdi); |
1840 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1); | 1825 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1); |
1841 } | 1826 } |
1842 } | 1827 } |
1843 | 1828 |
1844 | 1829 |
1845 // static | 1830 // static |
1846 void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) { | 1831 void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1929 __ ret(0); | 1914 __ ret(0); |
1930 } | 1915 } |
1931 | 1916 |
1932 | 1917 |
1933 #undef __ | 1918 #undef __ |
1934 | 1919 |
1935 } // namespace internal | 1920 } // namespace internal |
1936 } // namespace v8 | 1921 } // namespace v8 |
1937 | 1922 |
1938 #endif // V8_TARGET_ARCH_X64 | 1923 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |