Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1225)

Side by Side Diff: src/x64/builtins-x64.cc

Issue 1407313004: Adds the possibility of setting a Code object as the callback of a FunctionTemplate. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Update. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1949 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 // method. 1960 // method.
1961 __ bind(&non_constructor); 1961 __ bind(&non_constructor);
1962 { 1962 {
1963 FrameScope scope(masm, StackFrame::INTERNAL); 1963 FrameScope scope(masm, StackFrame::INTERNAL);
1964 __ Push(rdi); 1964 __ Push(rdi);
1965 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1); 1965 __ CallRuntime(Runtime::kThrowCalledNonCallable, 1);
1966 } 1966 }
1967 } 1967 }
1968 1968
1969 1969
1970 static void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver,
1971 Register function_template_info,
1972 Register scratch0, Register scratch1,
1973 Register scratch2,
1974 Label* receiver_check_failed) {
1975 Register signature = scratch0;
1976 Register map = scratch1;
1977 Register constructor = scratch2;
1978
1979 // If receiver is not an object, jump to receiver_check_failed.
1980 __ CmpObjectType(receiver, FIRST_JS_OBJECT_TYPE, kScratchRegister);
1981 __ j(below, receiver_check_failed);
1982
1983 // If there is no signature, return the holder.
1984 __ movp(signature, FieldOperand(function_template_info,
1985 FunctionTemplateInfo::kSignatureOffset));
1986 __ CompareRoot(signature, Heap::kUndefinedValueRootIndex);
1987 Label receiver_check_passed;
1988 __ j(equal, &receiver_check_passed, Label::kNear);
1989
1990 // Walk the prototype chain.
1991 Label prototype_loop_start;
1992 __ bind(&prototype_loop_start);
1993
1994 // End if receiver is null or if it's a hidden prototype.
1995 __ CompareRoot(receiver, Heap::kNullValueRootIndex);
1996 __ j(equal, receiver_check_failed, Label::kNear);
1997 __ movp(map, FieldOperand(receiver, HeapObject::kMapOffset));
1998 __ testq(FieldOperand(map, Map::kBitField3Offset),
1999 Immediate(Map::IsHiddenPrototype::kMask));
2000 __ j(not_zero, receiver_check_failed, Label::kNear);
2001
2002 // Get the constructor, if any.
2003 __ GetMapConstructor(constructor, map, kScratchRegister);
2004 __ CmpInstanceType(kScratchRegister, JS_FUNCTION_TYPE);
2005 Label next_prototype;
2006 __ j(not_equal, &next_prototype, Label::kNear);
2007
2008 // Get the constructor's signature.
2009 Register type = constructor;
2010 __ movp(type,
2011 FieldOperand(constructor, JSFunction::kSharedFunctionInfoOffset));
2012 __ movp(type, FieldOperand(type, SharedFunctionInfo::kFunctionDataOffset));
2013
2014 // Loop through the chain of inheriting function templates.
2015 Label function_template_loop;
2016 __ bind(&function_template_loop);
2017
2018 // If the signatures match, we have a compatible receiver.
2019 __ cmpp(signature, type);
2020 __ j(equal, &receiver_check_passed, Label::kNear);
2021
2022 // If the current type is not a FunctionTemplateInfo, load the next prototype
2023 // in the chain.
2024 __ JumpIfSmi(type, &next_prototype, Label::kNear);
2025 __ CmpObjectType(type, FUNCTION_TEMPLATE_INFO_TYPE, kScratchRegister);
2026 __ j(not_equal, &next_prototype, Label::kNear);
2027
2028 // Otherwise load the parent function template and iterate.
2029 __ movp(type,
2030 FieldOperand(type, FunctionTemplateInfo::kParentTemplateOffset));
2031 __ jmp(&function_template_loop, Label::kNear);
2032
2033 // Load the next prototype and iterate.
2034 __ bind(&next_prototype);
2035 __ movp(receiver, FieldOperand(map, Map::kPrototypeOffset));
2036 __ jmp(&prototype_loop_start, Label::kNear);
2037
2038 __ bind(&receiver_check_passed);
2039 }
2040
2041
2042 void Builtins::Generate_HandleFastApiCall(MacroAssembler* masm) {
2043 // ----------- S t a t e -------------
2044 // -- rax : number of arguments (not including the receiver)
2045 // -- rdi : callee
2046 // -- rsi : context
2047 // -- rsp[0] : return address
2048 // -- rsp[8] : last argument
2049 // -- ...
2050 // -- rsp[rax * 8] : first argument
2051 // -- rsp[(rax + 1) * 8] : receiver
2052 // -----------------------------------
2053
2054 StackArgumentsAccessor args(rsp, rax);
2055 __ movp(rcx, args.GetReceiverOperand());
2056
2057 // Update the receiver if this is a contextual call.
2058 Label set_global_proxy, valid_receiver;
2059 __ CompareRoot(rcx, Heap::kUndefinedValueRootIndex);
2060 __ j(equal, &set_global_proxy);
2061 __ bind(&valid_receiver);
2062
2063 // Load the FunctionTemplateInfo.
2064 __ movp(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
2065 __ movp(rbx, FieldOperand(rbx, SharedFunctionInfo::kFunctionDataOffset));
2066
2067 // Do the compatible receiver check.
2068 Label receiver_check_failed;
2069 CompatibleReceiverCheck(masm, rcx, rbx, rdx, r8, r9, &receiver_check_failed);
2070
2071 // Get the callback offset from the FunctionTemplateInfo, and jump to the
2072 // beginning of the code.
2073 __ movp(rdx, FieldOperand(rbx, FunctionTemplateInfo::kCallCodeOffset));
2074 __ movp(rdx, FieldOperand(rdx, CallHandlerInfo::kCallbackOffset));
2075 __ addp(rdx, Immediate(Code::kHeaderSize - kHeapObjectTag));
2076 __ jmp(rdx);
2077
2078 __ bind(&set_global_proxy);
2079 __ movp(rcx, GlobalObjectOperand());
2080 __ movp(rcx, FieldOperand(rcx, JSGlobalObject::kGlobalProxyOffset));
2081 __ movp(args.GetReceiverOperand(), rcx);
2082 __ jmp(&valid_receiver, Label::kNear);
2083
2084 // Compatible receiver check failed: pop return address, arguments and
2085 // receiver and throw an Illegal Invocation exception.
2086 __ bind(&receiver_check_failed);
2087 __ PopReturnAddressTo(rbx);
2088 __ leap(rax, Operand(rax, times_pointer_size, 1 * kPointerSize));
2089 __ addp(rsp, rax);
2090 __ PushReturnAddressFrom(rbx);
2091 {
2092 FrameScope scope(masm, StackFrame::INTERNAL);
2093 __ TailCallRuntime(Runtime::kThrowIllegalInvocation, 0, 1);
2094 }
2095 }
2096
2097
1970 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { 2098 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) {
1971 // Lookup the function in the JavaScript frame. 2099 // Lookup the function in the JavaScript frame.
1972 __ movp(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); 2100 __ movp(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
1973 { 2101 {
1974 FrameScope scope(masm, StackFrame::INTERNAL); 2102 FrameScope scope(masm, StackFrame::INTERNAL);
1975 // Pass function as argument. 2103 // Pass function as argument.
1976 __ Push(rax); 2104 __ Push(rax);
1977 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1); 2105 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1);
1978 } 2106 }
1979 2107
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2019 __ ret(0); 2147 __ ret(0);
2020 } 2148 }
2021 2149
2022 2150
2023 #undef __ 2151 #undef __
2024 2152
2025 } // namespace internal 2153 } // namespace internal
2026 } // namespace v8 2154 } // namespace v8
2027 2155
2028 #endif // V8_TARGET_ARCH_X64 2156 #endif // V8_TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698