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 1789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1800 __ movp(rcx, FieldOperand(rcx, SharedFunctionInfo::kConstructStubOffset)); | 1800 __ movp(rcx, FieldOperand(rcx, SharedFunctionInfo::kConstructStubOffset)); |
1801 __ leap(rcx, FieldOperand(rcx, Code::kHeaderSize)); | 1801 __ leap(rcx, FieldOperand(rcx, Code::kHeaderSize)); |
1802 __ jmp(rcx); | 1802 __ jmp(rcx); |
1803 } | 1803 } |
1804 | 1804 |
1805 | 1805 |
1806 // static | 1806 // static |
1807 void Builtins::Generate_ConstructProxy(MacroAssembler* masm) { | 1807 void Builtins::Generate_ConstructProxy(MacroAssembler* masm) { |
1808 // ----------- S t a t e ------------- | 1808 // ----------- S t a t e ------------- |
1809 // -- rax : the number of arguments (not including the receiver) | 1809 // -- rax : the number of arguments (not including the receiver) |
| 1810 // -- rdi : the constructor to call (checked to be a JSProxy) |
1810 // -- rdx : the new target (either the same as the constructor or | 1811 // -- rdx : the new target (either the same as the constructor or |
1811 // the JSFunction on which new was invoked initially) | 1812 // the JSFunction on which new was invoked initially) |
1812 // -- rdi : the constructor to call (checked to be a JSProxy) | |
1813 // ----------------------------------- | 1813 // ----------------------------------- |
1814 | 1814 |
1815 // TODO(neis): This doesn't match the ES6 spec for [[Construct]] on proxies. | 1815 // Call into the Runtime for Proxy [[Construct]]. |
1816 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); | 1816 __ PopReturnAddressTo(kScratchRegister); |
| 1817 __ Push(rdi); |
| 1818 __ Push(rdx); |
| 1819 __ PushReturnAddressFrom(kScratchRegister); |
| 1820 // Include the pushed new_target, constructor and the receiver. |
| 1821 __ addp(rax, Immediate(3)); |
| 1822 __ JumpToExternalReference( |
| 1823 ExternalReference(Runtime::kJSProxyConstruct, masm->isolate()), 1); |
1817 } | 1824 } |
1818 | 1825 |
1819 | 1826 |
1820 // static | 1827 // static |
1821 void Builtins::Generate_Construct(MacroAssembler* masm) { | 1828 void Builtins::Generate_Construct(MacroAssembler* masm) { |
1822 // ----------- S t a t e ------------- | 1829 // ----------- S t a t e ------------- |
1823 // -- rax : the number of arguments (not including the receiver) | 1830 // -- rax : the number of arguments (not including the receiver) |
1824 // -- rdx : the new target (either the same as the constructor or | 1831 // -- rdx : the new target (either the same as the constructor or |
1825 // the JSFunction on which new was invoked initially) | 1832 // the JSFunction on which new was invoked initially) |
1826 // -- rdi : the constructor to call (can be any Object) | 1833 // -- rdi : the constructor to call (can be any Object) |
1827 // ----------------------------------- | 1834 // ----------------------------------- |
1828 StackArgumentsAccessor args(rsp, rax); | 1835 StackArgumentsAccessor args(rsp, rax); |
1829 | 1836 |
1830 // Check if target is a Smi. | 1837 // Check if target is a Smi. |
1831 Label non_constructor; | 1838 Label non_constructor; |
1832 __ JumpIfSmi(rdi, &non_constructor, Label::kNear); | 1839 __ JumpIfSmi(rdi, &non_constructor, Label::kNear); |
1833 | 1840 |
1834 // Dispatch based on instance type. | 1841 // Dispatch based on instance type. |
1835 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); | 1842 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx); |
1836 __ j(equal, masm->isolate()->builtins()->ConstructFunction(), | 1843 __ j(equal, masm->isolate()->builtins()->ConstructFunction(), |
1837 RelocInfo::CODE_TARGET); | 1844 RelocInfo::CODE_TARGET); |
1838 __ CmpInstanceType(rcx, JS_PROXY_TYPE); | |
1839 __ j(equal, masm->isolate()->builtins()->ConstructProxy(), | |
1840 RelocInfo::CODE_TARGET); | |
1841 | 1845 |
1842 // Check if target has a [[Construct]] internal method. | 1846 // Check if target has a [[Construct]] internal method. |
1843 __ testb(FieldOperand(rcx, Map::kBitFieldOffset), | 1847 __ testb(FieldOperand(rcx, Map::kBitFieldOffset), |
1844 Immediate(1 << Map::kIsConstructor)); | 1848 Immediate(1 << Map::kIsConstructor)); |
1845 __ j(zero, &non_constructor, Label::kNear); | 1849 __ j(zero, &non_constructor, Label::kNear); |
1846 | 1850 |
| 1851 // Only dispatch to proxies after checking whether they are constructors. |
| 1852 __ CmpInstanceType(rcx, JS_PROXY_TYPE); |
| 1853 __ j(equal, masm->isolate()->builtins()->ConstructProxy(), |
| 1854 RelocInfo::CODE_TARGET); |
| 1855 |
1847 // Called Construct on an exotic Object with a [[Construct]] internal method. | 1856 // Called Construct on an exotic Object with a [[Construct]] internal method. |
1848 { | 1857 { |
1849 // Overwrite the original receiver with the (original) target. | 1858 // Overwrite the original receiver with the (original) target. |
1850 __ movp(args.GetReceiverOperand(), rdi); | 1859 __ movp(args.GetReceiverOperand(), rdi); |
1851 // Let the "call_as_constructor_delegate" take care of the rest. | 1860 // Let the "call_as_constructor_delegate" take care of the rest. |
1852 __ LoadNativeContextSlot(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, rdi); | 1861 __ LoadNativeContextSlot(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, rdi); |
1853 __ Jump(masm->isolate()->builtins()->CallFunction(), | 1862 __ Jump(masm->isolate()->builtins()->CallFunction(), |
1854 RelocInfo::CODE_TARGET); | 1863 RelocInfo::CODE_TARGET); |
1855 } | 1864 } |
1856 | 1865 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2042 __ ret(0); | 2051 __ ret(0); |
2043 } | 2052 } |
2044 | 2053 |
2045 | 2054 |
2046 #undef __ | 2055 #undef __ |
2047 | 2056 |
2048 } // namespace internal | 2057 } // namespace internal |
2049 } // namespace v8 | 2058 } // namespace v8 |
2050 | 2059 |
2051 #endif // V8_TARGET_ARCH_X64 | 2060 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |