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