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 |
1784 void Builtins::Generate_Construct(MacroAssembler* masm) { | 1799 void Builtins::Generate_Construct(MacroAssembler* masm) { |
1785 // ----------- S t a t e ------------- | 1800 // ----------- S t a t e ------------- |
1786 // -- rax : the number of arguments (not including the receiver) | 1801 // -- rax : the number of arguments (not including the receiver) |
1787 // -- rdx : the original constructor (either the same as the constructor or | 1802 // -- rdx : the original constructor (either the same as the constructor or |
1788 // the JSFunction on which new was invoked initially) | 1803 // the JSFunction on which new was invoked initially) |
1789 // -- rdi : the constructor to call (can be any Object) | 1804 // -- rdi : the constructor to call (can be any Object) |
1790 // ----------------------------------- | 1805 // ----------------------------------- |
1791 StackArgumentsAccessor args(rsp, rax); | 1806 StackArgumentsAccessor args(rsp, rax); |
1792 | 1807 |
1793 Label non_callable, non_function; | 1808 // Check if target has a [[Construct]] internal method. |
1794 __ JumpIfSmi(rdi, &non_callable); | 1809 Label non_constructor; |
1795 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); | 1810 __ JumpIfSmi(rdi, &non_constructor, Label::kNear); |
| 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); |
1796 __ j(equal, masm->isolate()->builtins()->ConstructFunction(), | 1818 __ j(equal, masm->isolate()->builtins()->ConstructFunction(), |
1797 RelocInfo::CODE_TARGET); | 1819 RelocInfo::CODE_TARGET); |
1798 __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); | 1820 __ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE); |
1799 __ j(not_equal, &non_function, Label::kNear); | 1821 __ j(equal, masm->isolate()->builtins()->ConstructProxy(), |
| 1822 RelocInfo::CODE_TARGET); |
1800 | 1823 |
1801 // 1. Construct of function proxy. | 1824 // Called Construct on an exotic Object with a [[Construct]] internal method. |
1802 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies. | 1825 { |
1803 __ movp(rdi, FieldOperand(rdi, JSFunctionProxy::kConstructTrapOffset)); | 1826 // Overwrite the original receiver with the (original) target. |
1804 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); | 1827 __ movp(args.GetReceiverOperand(), rdi); |
| 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 } |
1805 | 1833 |
1806 // 2. Construct of something else, which might have a [[Construct]] internal | 1834 // Called Construct on an Object that doesn't have a [[Construct]] internal |
1807 // method (if not we raise an exception). | 1835 // method. |
1808 __ bind(&non_function); | 1836 __ bind(&non_constructor); |
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); | |
1822 { | 1837 { |
1823 FrameScope scope(masm, StackFrame::INTERNAL); | 1838 FrameScope scope(masm, StackFrame::INTERNAL); |
1824 __ Push(rdi); | 1839 __ Push(rdi); |
1825 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1); | 1840 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1); |
1826 } | 1841 } |
1827 } | 1842 } |
1828 | 1843 |
1829 | 1844 |
1830 // static | 1845 // static |
1831 void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) { | 1846 void Builtins::Generate_PushArgsAndCall(MacroAssembler* masm) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1914 __ ret(0); | 1929 __ ret(0); |
1915 } | 1930 } |
1916 | 1931 |
1917 | 1932 |
1918 #undef __ | 1933 #undef __ |
1919 | 1934 |
1920 } // namespace internal | 1935 } // namespace internal |
1921 } // namespace v8 | 1936 } // namespace v8 |
1922 | 1937 |
1923 #endif // V8_TARGET_ARCH_X64 | 1938 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |