OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 v8::InvocationCallback callback = | 1091 v8::InvocationCallback callback = |
1092 v8::ToCData<v8::InvocationCallback>(callback_obj); | 1092 v8::ToCData<v8::InvocationCallback>(callback_obj); |
1093 Object* data_obj = call_data->data(); | 1093 Object* data_obj = call_data->data(); |
1094 Object* result; | 1094 Object* result; |
1095 | 1095 |
1096 LOG(isolate, ApiObjectAccess("call", JSObject::cast(*args.receiver()))); | 1096 LOG(isolate, ApiObjectAccess("call", JSObject::cast(*args.receiver()))); |
1097 ASSERT(raw_holder->IsJSObject()); | 1097 ASSERT(raw_holder->IsJSObject()); |
1098 | 1098 |
1099 CustomArguments custom(isolate); | 1099 CustomArguments custom(isolate); |
1100 v8::ImplementationUtilities::PrepareArgumentsData(custom.end(), | 1100 v8::ImplementationUtilities::PrepareArgumentsData(custom.end(), |
1101 data_obj, *function, raw_holder); | 1101 isolate, data_obj, *function, raw_holder); |
1102 | 1102 |
1103 v8::Arguments new_args = v8::ImplementationUtilities::NewArguments( | 1103 v8::Arguments new_args = v8::ImplementationUtilities::NewArguments( |
1104 custom.end(), | 1104 custom.end(), |
1105 &args[0] - 1, | 1105 &args[0] - 1, |
1106 args.length() - 1, | 1106 args.length() - 1, |
1107 is_construct); | 1107 is_construct); |
1108 | 1108 |
1109 v8::Handle<v8::Value> value; | 1109 v8::Handle<v8::Value> value; |
1110 { | 1110 { |
1111 // Leaving JavaScript. | 1111 // Leaving JavaScript. |
(...skipping 19 matching lines...) Expand all Loading... |
1131 BUILTIN(HandleApiCall) { | 1131 BUILTIN(HandleApiCall) { |
1132 return HandleApiCallHelper<false>(args, isolate); | 1132 return HandleApiCallHelper<false>(args, isolate); |
1133 } | 1133 } |
1134 | 1134 |
1135 | 1135 |
1136 BUILTIN(HandleApiCallConstruct) { | 1136 BUILTIN(HandleApiCallConstruct) { |
1137 return HandleApiCallHelper<true>(args, isolate); | 1137 return HandleApiCallHelper<true>(args, isolate); |
1138 } | 1138 } |
1139 | 1139 |
1140 | 1140 |
1141 #ifdef DEBUG | |
1142 | |
1143 static void VerifyTypeCheck(Handle<JSObject> object, | |
1144 Handle<JSFunction> function) { | |
1145 ASSERT(function->shared()->IsApiFunction()); | |
1146 FunctionTemplateInfo* info = function->shared()->get_api_func_data(); | |
1147 if (info->signature()->IsUndefined()) return; | |
1148 SignatureInfo* signature = SignatureInfo::cast(info->signature()); | |
1149 Object* receiver_type = signature->receiver(); | |
1150 if (receiver_type->IsUndefined()) return; | |
1151 FunctionTemplateInfo* type = FunctionTemplateInfo::cast(receiver_type); | |
1152 ASSERT(object->IsInstanceOf(type)); | |
1153 } | |
1154 | |
1155 #endif | |
1156 | |
1157 | |
1158 BUILTIN(FastHandleApiCall) { | |
1159 ASSERT(!CalledAsConstructor(isolate)); | |
1160 Heap* heap = isolate->heap(); | |
1161 const bool is_construct = false; | |
1162 | |
1163 // We expect four more arguments: callback, function, call data, and holder. | |
1164 const int args_length = args.length() - 4; | |
1165 ASSERT(args_length >= 0); | |
1166 | |
1167 Object* callback_obj = args[args_length]; | |
1168 | |
1169 v8::Arguments new_args = v8::ImplementationUtilities::NewArguments( | |
1170 &args[args_length + 1], | |
1171 &args[0] - 1, | |
1172 args_length - 1, | |
1173 is_construct); | |
1174 | |
1175 #ifdef DEBUG | |
1176 VerifyTypeCheck(Utils::OpenHandle(*new_args.Holder()), | |
1177 Utils::OpenHandle(*new_args.Callee())); | |
1178 #endif | |
1179 HandleScope scope(isolate); | |
1180 Object* result; | |
1181 v8::Handle<v8::Value> value; | |
1182 { | |
1183 // Leaving JavaScript. | |
1184 VMState state(isolate, EXTERNAL); | |
1185 ExternalCallbackScope call_scope(isolate, | |
1186 v8::ToCData<Address>(callback_obj)); | |
1187 v8::InvocationCallback callback = | |
1188 v8::ToCData<v8::InvocationCallback>(callback_obj); | |
1189 | |
1190 value = callback(new_args); | |
1191 } | |
1192 if (value.IsEmpty()) { | |
1193 result = heap->undefined_value(); | |
1194 } else { | |
1195 result = *reinterpret_cast<Object**>(*value); | |
1196 } | |
1197 | |
1198 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | |
1199 return result; | |
1200 } | |
1201 | |
1202 | |
1203 // Helper function to handle calls to non-function objects created through the | 1141 // Helper function to handle calls to non-function objects created through the |
1204 // API. The object can be called as either a constructor (using new) or just as | 1142 // API. The object can be called as either a constructor (using new) or just as |
1205 // a function (without new). | 1143 // a function (without new). |
1206 MUST_USE_RESULT static MaybeObject* HandleApiCallAsFunctionOrConstructor( | 1144 MUST_USE_RESULT static MaybeObject* HandleApiCallAsFunctionOrConstructor( |
1207 Isolate* isolate, | 1145 Isolate* isolate, |
1208 bool is_construct_call, | 1146 bool is_construct_call, |
1209 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { | 1147 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { |
1210 // Non-functions are never called as constructors. Even if this is an object | 1148 // Non-functions are never called as constructors. Even if this is an object |
1211 // called as a constructor the delegate call is not a construct call. | 1149 // called as a constructor the delegate call is not a construct call. |
1212 ASSERT(!CalledAsConstructor(isolate)); | 1150 ASSERT(!CalledAsConstructor(isolate)); |
(...skipping 18 matching lines...) Expand all Loading... |
1231 v8::ToCData<v8::InvocationCallback>(callback_obj); | 1169 v8::ToCData<v8::InvocationCallback>(callback_obj); |
1232 | 1170 |
1233 // Get the data for the call and perform the callback. | 1171 // Get the data for the call and perform the callback. |
1234 Object* result; | 1172 Object* result; |
1235 { | 1173 { |
1236 HandleScope scope(isolate); | 1174 HandleScope scope(isolate); |
1237 LOG(isolate, ApiObjectAccess("call non-function", obj)); | 1175 LOG(isolate, ApiObjectAccess("call non-function", obj)); |
1238 | 1176 |
1239 CustomArguments custom(isolate); | 1177 CustomArguments custom(isolate); |
1240 v8::ImplementationUtilities::PrepareArgumentsData(custom.end(), | 1178 v8::ImplementationUtilities::PrepareArgumentsData(custom.end(), |
1241 call_data->data(), constructor, obj); | 1179 isolate, call_data->data(), constructor, obj); |
1242 v8::Arguments new_args = v8::ImplementationUtilities::NewArguments( | 1180 v8::Arguments new_args = v8::ImplementationUtilities::NewArguments( |
1243 custom.end(), | 1181 custom.end(), |
1244 &args[0] - 1, | 1182 &args[0] - 1, |
1245 args.length() - 1, | 1183 args.length() - 1, |
1246 is_construct_call); | 1184 is_construct_call); |
1247 v8::Handle<v8::Value> value; | 1185 v8::Handle<v8::Value> value; |
1248 { | 1186 { |
1249 // Leaving JavaScript. | 1187 // Leaving JavaScript. |
1250 VMState state(isolate, EXTERNAL); | 1188 VMState state(isolate, EXTERNAL); |
1251 ExternalCallbackScope call_scope(isolate, | 1189 ExternalCallbackScope call_scope(isolate, |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1735 return Handle<Code>(code_address); \ | 1673 return Handle<Code>(code_address); \ |
1736 } | 1674 } |
1737 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1675 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1738 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1676 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1739 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1677 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1740 #undef DEFINE_BUILTIN_ACCESSOR_C | 1678 #undef DEFINE_BUILTIN_ACCESSOR_C |
1741 #undef DEFINE_BUILTIN_ACCESSOR_A | 1679 #undef DEFINE_BUILTIN_ACCESSOR_A |
1742 | 1680 |
1743 | 1681 |
1744 } } // namespace v8::internal | 1682 } } // namespace v8::internal |
OLD | NEW |