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

Side by Side Diff: src/builtins.cc

Issue 864273002: Call directly to c callbacks in Invoke instead of transitioning to js and back out. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 months 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
« no previous file with comments | « src/builtins.h ('k') | src/execution.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/arguments.h" 8 #include "src/arguments.h"
9 #include "src/base/once.h" 9 #include "src/base/once.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 Object* holder = recv; 1055 Object* holder = recv;
1056 if (!recv_type->IsUndefined()) { 1056 if (!recv_type->IsUndefined()) {
1057 holder = FindHidden(heap, holder, FunctionTemplateInfo::cast(recv_type)); 1057 holder = FindHidden(heap, holder, FunctionTemplateInfo::cast(recv_type));
1058 if (holder == heap->null_value()) return heap->null_value(); 1058 if (holder == heap->null_value()) return heap->null_value();
1059 } 1059 }
1060 return holder; 1060 return holder;
1061 } 1061 }
1062 1062
1063 1063
1064 template <bool is_construct> 1064 template <bool is_construct>
1065 MUST_USE_RESULT static Object* HandleApiCallHelper( 1065 MUST_USE_RESULT static MaybeHandle<Object> HandleApiCallHelper(
1066 BuiltinArguments<NEEDS_CALLED_FUNCTION> args, Isolate* isolate) { 1066 Isolate* isolate, BuiltinArguments<NEEDS_CALLED_FUNCTION> args) {
1067 DCHECK(is_construct == CalledAsConstructor(isolate));
1068 Heap* heap = isolate->heap();
1069
1070 HandleScope scope(isolate); 1067 HandleScope scope(isolate);
1071 Handle<JSFunction> function = args.called_function(); 1068 Handle<JSFunction> function = args.called_function();
1072 // TODO(ishell): turn this back to a DCHECK. 1069 // TODO(ishell): turn this back to a DCHECK.
1073 CHECK(function->shared()->IsApiFunction()); 1070 CHECK(function->shared()->IsApiFunction());
1074 1071
1075 Handle<FunctionTemplateInfo> fun_data( 1072 Handle<FunctionTemplateInfo> fun_data(
1076 function->shared()->get_api_func_data(), isolate); 1073 function->shared()->get_api_func_data(), isolate);
1077 if (is_construct) { 1074 if (is_construct) {
1078 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1075 ASSIGN_RETURN_ON_EXCEPTION(
1079 isolate, fun_data, 1076 isolate, fun_data,
1080 isolate->factory()->ConfigureInstance( 1077 isolate->factory()->ConfigureInstance(
1081 fun_data, Handle<JSObject>::cast(args.receiver()))); 1078 fun_data, Handle<JSObject>::cast(args.receiver())),
1079 Object);
1082 } 1080 }
1083 1081
1084 DCHECK(!args[0]->IsNull()); 1082 DCHECK(!args[0]->IsNull());
1085 if (args[0]->IsUndefined()) args[0] = function->global_proxy(); 1083 if (args[0]->IsUndefined()) args[0] = function->global_proxy();
1086 1084
1087 Object* raw_holder = TypeCheck(heap, args[0], *fun_data); 1085 Object* raw_holder = TypeCheck(isolate->heap(), args[0], *fun_data);
1088 1086
1089 if (raw_holder->IsNull()) { 1087 if (raw_holder->IsNull()) {
1090 // This function cannot be called with the given receiver. Abort! 1088 // This function cannot be called with the given receiver. Abort!
1091 THROW_NEW_ERROR_RETURN_FAILURE( 1089 THROW_NEW_ERROR(
1092 isolate, 1090 isolate, NewTypeError("illegal_invocation", HandleVector(&function, 1)),
1093 NewTypeError("illegal_invocation", HandleVector(&function, 1))); 1091 Object);
1094 } 1092 }
1095 1093
1096 Object* raw_call_data = fun_data->call_code(); 1094 Object* raw_call_data = fun_data->call_code();
1097 if (!raw_call_data->IsUndefined()) { 1095 if (!raw_call_data->IsUndefined()) {
1098 // TODO(ishell): remove this debugging code. 1096 // TODO(ishell): remove this debugging code.
1099 CHECK(raw_call_data->IsCallHandlerInfo()); 1097 CHECK(raw_call_data->IsCallHandlerInfo());
1100 CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data); 1098 CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data);
1101 Object* callback_obj = call_data->callback(); 1099 Object* callback_obj = call_data->callback();
1102 v8::FunctionCallback callback = 1100 v8::FunctionCallback callback =
1103 v8::ToCData<v8::FunctionCallback>(callback_obj); 1101 v8::ToCData<v8::FunctionCallback>(callback_obj);
1104 Object* data_obj = call_data->data(); 1102 Object* data_obj = call_data->data();
1105 Object* result;
1106 1103
1107 LOG(isolate, ApiObjectAccess("call", JSObject::cast(*args.receiver()))); 1104 LOG(isolate, ApiObjectAccess("call", JSObject::cast(*args.receiver())));
1108 DCHECK(raw_holder->IsJSObject()); 1105 DCHECK(raw_holder->IsJSObject());
1109 1106
1110 FunctionCallbackArguments custom(isolate, 1107 FunctionCallbackArguments custom(isolate,
1111 data_obj, 1108 data_obj,
1112 *function, 1109 *function,
1113 raw_holder, 1110 raw_holder,
1114 &args[0] - 1, 1111 &args[0] - 1,
1115 args.length() - 1, 1112 args.length() - 1,
1116 is_construct); 1113 is_construct);
1117 1114
1118 v8::Handle<v8::Value> value = custom.Call(callback); 1115 v8::Handle<v8::Value> value = custom.Call(callback);
1116 Handle<Object> result;
1119 if (value.IsEmpty()) { 1117 if (value.IsEmpty()) {
1120 result = heap->undefined_value(); 1118 result = isolate->factory()->undefined_value();
1121 } else { 1119 } else {
1122 result = *reinterpret_cast<Object**>(*value); 1120 result = v8::Utils::OpenHandle(*value);
1123 result->VerifyApiCallResultType(); 1121 result->VerifyApiCallResultType();
1124 } 1122 }
1125 1123
1126 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); 1124 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
1127 if (!is_construct || result->IsJSObject()) return result; 1125 if (!is_construct || result->IsJSObject()) {
1126 return scope.CloseAndEscape(result);
1127 }
1128 } 1128 }
1129 1129
1130 return *args.receiver(); 1130 return scope.CloseAndEscape(args.receiver());
1131 } 1131 }
1132 1132
1133 1133
1134 BUILTIN(HandleApiCall) { 1134 BUILTIN(HandleApiCall) {
1135 return HandleApiCallHelper<false>(args, isolate); 1135 HandleScope scope(isolate);
1136 DCHECK(!CalledAsConstructor(isolate));
1137 Handle<Object> result;
1138 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
1139 HandleApiCallHelper<false>(isolate, args));
1140 return *result;
1136 } 1141 }
1137 1142
1138 1143
1139 BUILTIN(HandleApiCallConstruct) { 1144 BUILTIN(HandleApiCallConstruct) {
1140 return HandleApiCallHelper<true>(args, isolate); 1145 HandleScope scope(isolate);
1146 DCHECK(CalledAsConstructor(isolate));
1147 Handle<Object> result;
1148 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
1149 HandleApiCallHelper<true>(isolate, args));
1150 return *result;
1141 } 1151 }
1142 1152
1143 1153
1154 MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<JSFunction> function,
1155 Handle<Object> receiver,
1156 int argc,
1157 Handle<Object> args[]) {
1158 // Construct BuiltinArguments object: function, arguments reversed, receiver.
1159 const int kBufferSize = 32;
1160 Object* small_argv[kBufferSize];
1161 Object** argv;
1162 if (argc + 2 <= kBufferSize) {
1163 argv = small_argv;
1164 } else {
1165 argv = new Object* [argc + 2];
1166 }
1167 argv[argc + 1] = *receiver;
1168 for (int i = 0; i < argc; ++i) {
1169 argv[argc - i] = *args[i];
1170 }
1171 argv[0] = *function;
1172 MaybeHandle<Object> result;
1173 {
1174 auto isolate = function->GetIsolate();
1175 BuiltinArguments<NEEDS_CALLED_FUNCTION> arguments(argc + 2,
1176 &argv[argc + 1]);
1177 result = HandleApiCallHelper<false>(isolate, arguments);
1178 }
1179 if (argv != small_argv) {
1180 delete[] argv;
1181 }
1182 return result;
1183 }
1184
1185
1144 // Helper function to handle calls to non-function objects created through the 1186 // Helper function to handle calls to non-function objects created through the
1145 // API. The object can be called as either a constructor (using new) or just as 1187 // API. The object can be called as either a constructor (using new) or just as
1146 // a function (without new). 1188 // a function (without new).
1147 MUST_USE_RESULT static Object* HandleApiCallAsFunctionOrConstructor( 1189 MUST_USE_RESULT static Object* HandleApiCallAsFunctionOrConstructor(
1148 Isolate* isolate, 1190 Isolate* isolate,
1149 bool is_construct_call, 1191 bool is_construct_call,
1150 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { 1192 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) {
1151 // Non-functions are never called as constructors. Even if this is an object 1193 // Non-functions are never called as constructors. Even if this is an object
1152 // called as a constructor the delegate call is not a construct call. 1194 // called as a constructor the delegate call is not a construct call.
1153 DCHECK(!CalledAsConstructor(isolate)); 1195 DCHECK(!CalledAsConstructor(isolate));
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 } 1658 }
1617 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 1659 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
1618 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 1660 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
1619 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 1661 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
1620 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 1662 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
1621 #undef DEFINE_BUILTIN_ACCESSOR_C 1663 #undef DEFINE_BUILTIN_ACCESSOR_C
1622 #undef DEFINE_BUILTIN_ACCESSOR_A 1664 #undef DEFINE_BUILTIN_ACCESSOR_A
1623 1665
1624 1666
1625 } } // namespace v8::internal 1667 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/builtins.h ('k') | src/execution.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698