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 #include "src/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) { | 989 void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) { |
990 auto info = Utils::OpenHandle(this); | 990 auto info = Utils::OpenHandle(this); |
991 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit"); | 991 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit"); |
992 i::Isolate* isolate = info->GetIsolate(); | 992 i::Isolate* isolate = info->GetIsolate(); |
993 ENTER_V8(isolate); | 993 ENTER_V8(isolate); |
994 info->set_parent_template(*Utils::OpenHandle(*value)); | 994 info->set_parent_template(*Utils::OpenHandle(*value)); |
995 } | 995 } |
996 | 996 |
997 | 997 |
998 static Local<FunctionTemplate> FunctionTemplateNew( | 998 static Local<FunctionTemplate> FunctionTemplateNew( |
999 i::Isolate* isolate, FunctionCallback callback, v8::Local<Value> data, | 999 i::Isolate* isolate, FunctionCallback callback, |
| 1000 v8::Local<Value> fast_handler, v8::Local<Value> data, |
1000 v8::Local<Signature> signature, int length, bool do_not_cache) { | 1001 v8::Local<Signature> signature, int length, bool do_not_cache) { |
1001 i::Handle<i::Struct> struct_obj = | 1002 i::Handle<i::Struct> struct_obj = |
1002 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); | 1003 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
1003 i::Handle<i::FunctionTemplateInfo> obj = | 1004 i::Handle<i::FunctionTemplateInfo> obj = |
1004 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); | 1005 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
1005 InitializeFunctionTemplate(obj); | 1006 InitializeFunctionTemplate(obj); |
1006 obj->set_do_not_cache(do_not_cache); | 1007 obj->set_do_not_cache(do_not_cache); |
1007 int next_serial_number = 0; | 1008 int next_serial_number = 0; |
1008 if (!do_not_cache) { | 1009 if (!do_not_cache) { |
1009 next_serial_number = isolate->next_serial_number() + 1; | 1010 next_serial_number = isolate->next_serial_number() + 1; |
1010 isolate->set_next_serial_number(next_serial_number); | 1011 isolate->set_next_serial_number(next_serial_number); |
1011 } | 1012 } |
1012 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); | 1013 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
1013 if (callback != 0) { | 1014 if (callback != 0) { |
1014 if (data.IsEmpty()) { | 1015 if (data.IsEmpty()) { |
1015 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 1016 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
1016 } | 1017 } |
1017 Utils::ToLocal(obj)->SetCallHandler(callback, data); | 1018 Utils::ToLocal(obj)->SetCallHandler(callback, data, fast_handler); |
1018 } | 1019 } |
1019 obj->set_length(length); | 1020 obj->set_length(length); |
1020 obj->set_undetectable(false); | 1021 obj->set_undetectable(false); |
1021 obj->set_needs_access_check(false); | 1022 obj->set_needs_access_check(false); |
1022 obj->set_accept_any_receiver(true); | 1023 obj->set_accept_any_receiver(true); |
1023 if (!signature.IsEmpty()) | 1024 if (!signature.IsEmpty()) |
1024 obj->set_signature(*Utils::OpenHandle(*signature)); | 1025 obj->set_signature(*Utils::OpenHandle(*signature)); |
1025 return Utils::ToLocal(obj); | 1026 return Utils::ToLocal(obj); |
1026 } | 1027 } |
1027 | 1028 |
| 1029 |
1028 Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate, | 1030 Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate, |
1029 FunctionCallback callback, | 1031 FunctionCallback callback, |
1030 v8::Local<Value> data, | 1032 v8::Local<Value> data, |
1031 v8::Local<Signature> signature, | 1033 v8::Local<Signature> signature, |
1032 int length) { | 1034 int length) { |
1033 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 1035 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
1034 // Changes to the environment cannot be captured in the snapshot. Expect no | 1036 // Changes to the environment cannot be captured in the snapshot. Expect no |
1035 // function templates when the isolate is created for serialization. | 1037 // function templates when the isolate is created for serialization. |
1036 DCHECK(!i_isolate->serializer_enabled()); | 1038 DCHECK(!i_isolate->serializer_enabled()); |
1037 LOG_API(i_isolate, "FunctionTemplate::New"); | 1039 LOG_API(i_isolate, "FunctionTemplate::New"); |
1038 ENTER_V8(i_isolate); | 1040 ENTER_V8(i_isolate); |
1039 return FunctionTemplateNew( | 1041 return FunctionTemplateNew(i_isolate, callback, v8::Local<Value>(), data, |
1040 i_isolate, callback, data, signature, length, false); | 1042 signature, length, false); |
1041 } | 1043 } |
1042 | 1044 |
1043 | 1045 |
| 1046 Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler( |
| 1047 Isolate* isolate, FunctionCallback callback, v8::Local<Value> fast_handler, |
| 1048 v8::Local<Value> data, v8::Local<Signature> signature, int length) { |
| 1049 // TODO(vogelheim): 'fast_handler' should have a more specific type than |
| 1050 // Local<Value>. |
| 1051 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 1052 DCHECK(!i_isolate->serializer_enabled()); |
| 1053 LOG_API(i_isolate, "FunctionTemplate::NewWithFastHandler"); |
| 1054 ENTER_V8(i_isolate); |
| 1055 return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature, |
| 1056 length, false); |
| 1057 } |
| 1058 |
| 1059 |
1044 Local<Signature> Signature::New(Isolate* isolate, | 1060 Local<Signature> Signature::New(Isolate* isolate, |
1045 Local<FunctionTemplate> receiver) { | 1061 Local<FunctionTemplate> receiver) { |
1046 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); | 1062 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); |
1047 } | 1063 } |
1048 | 1064 |
1049 | 1065 |
1050 Local<AccessorSignature> AccessorSignature::New( | 1066 Local<AccessorSignature> AccessorSignature::New( |
1051 Isolate* isolate, Local<FunctionTemplate> receiver) { | 1067 Isolate* isolate, Local<FunctionTemplate> receiver) { |
1052 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); | 1068 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); |
1053 } | 1069 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 } | 1104 } |
1089 | 1105 |
1090 | 1106 |
1091 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ | 1107 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ |
1092 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ | 1108 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ |
1093 (obj)->setter(*foreign); \ | 1109 (obj)->setter(*foreign); \ |
1094 } while (false) | 1110 } while (false) |
1095 | 1111 |
1096 | 1112 |
1097 void FunctionTemplate::SetCallHandler(FunctionCallback callback, | 1113 void FunctionTemplate::SetCallHandler(FunctionCallback callback, |
1098 v8::Local<Value> data) { | 1114 v8::Local<Value> data, |
| 1115 v8::Local<Value> fast_handler) { |
1099 auto info = Utils::OpenHandle(this); | 1116 auto info = Utils::OpenHandle(this); |
1100 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); | 1117 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); |
1101 i::Isolate* isolate = info->GetIsolate(); | 1118 i::Isolate* isolate = info->GetIsolate(); |
1102 ENTER_V8(isolate); | 1119 ENTER_V8(isolate); |
1103 i::HandleScope scope(isolate); | 1120 i::HandleScope scope(isolate); |
1104 i::Handle<i::Struct> struct_obj = | 1121 i::Handle<i::Struct> struct_obj = |
1105 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); | 1122 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
1106 i::Handle<i::CallHandlerInfo> obj = | 1123 i::Handle<i::CallHandlerInfo> obj = |
1107 i::Handle<i::CallHandlerInfo>::cast(struct_obj); | 1124 i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
1108 SET_FIELD_WRAPPED(obj, set_callback, callback); | 1125 SET_FIELD_WRAPPED(obj, set_callback, callback); |
| 1126 if (!fast_handler.IsEmpty()) { |
| 1127 i::Handle<i::Object> code = Utils::OpenHandle(*fast_handler); |
| 1128 CHECK(code->IsCode()); |
| 1129 obj->set_fast_handler(*code); |
| 1130 } |
1109 if (data.IsEmpty()) { | 1131 if (data.IsEmpty()) { |
1110 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 1132 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
1111 } | 1133 } |
1112 obj->set_data(*Utils::OpenHandle(*data)); | 1134 obj->set_data(*Utils::OpenHandle(*data)); |
1113 info->set_call_code(*obj); | 1135 info->set_call_code(*obj); |
1114 } | 1136 } |
1115 | 1137 |
1116 | 1138 |
1117 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( | 1139 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( |
1118 i::Handle<i::AccessorInfo> obj, v8::Local<Name> name, | 1140 i::Handle<i::AccessorInfo> obj, v8::Local<Name> name, |
(...skipping 3242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4361 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); | 4383 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); |
4362 } | 4384 } |
4363 | 4385 |
4364 | 4386 |
4365 MaybeLocal<Function> Function::New(Local<Context> context, | 4387 MaybeLocal<Function> Function::New(Local<Context> context, |
4366 FunctionCallback callback, Local<Value> data, | 4388 FunctionCallback callback, Local<Value> data, |
4367 int length) { | 4389 int length) { |
4368 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); | 4390 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); |
4369 LOG_API(isolate, "Function::New"); | 4391 LOG_API(isolate, "Function::New"); |
4370 ENTER_V8(isolate); | 4392 ENTER_V8(isolate); |
4371 return FunctionTemplateNew(isolate, callback, data, Local<Signature>(), | 4393 return FunctionTemplateNew(isolate, callback, Local<Value>(), data, |
4372 length, true)->GetFunction(context); | 4394 Local<Signature>(), length, true) |
| 4395 ->GetFunction(context); |
4373 } | 4396 } |
4374 | 4397 |
4375 | 4398 |
4376 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, | 4399 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, |
4377 Local<Value> data, int length) { | 4400 Local<Value> data, int length) { |
4378 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length) | 4401 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length) |
4379 .FromMaybe(Local<Function>()); | 4402 .FromMaybe(Local<Function>()); |
4380 } | 4403 } |
4381 | 4404 |
4382 | 4405 |
(...skipping 4127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8510 Address callback_address = | 8533 Address callback_address = |
8511 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8534 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8512 VMState<EXTERNAL> state(isolate); | 8535 VMState<EXTERNAL> state(isolate); |
8513 ExternalCallbackScope call_scope(isolate, callback_address); | 8536 ExternalCallbackScope call_scope(isolate, callback_address); |
8514 callback(info); | 8537 callback(info); |
8515 } | 8538 } |
8516 | 8539 |
8517 | 8540 |
8518 } // namespace internal | 8541 } // namespace internal |
8519 } // namespace v8 | 8542 } // namespace v8 |
OLD | NEW |