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 #ifdef V8_FAST_ACCESSORS |
| 1047 Local<FunctionTemplate> FunctionTemplate::New( |
| 1048 Isolate* isolate, v8::Local<Value> fast_handler, FunctionCallback callback, |
| 1049 v8::Local<Value> data, v8::Local<Signature> signature, int length) { |
| 1050 // TODO(vogelheim): 'fast_handler' should have a more specific type than |
| 1051 // Local<Value>. |
| 1052 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 1053 DCHECK(!i_isolate->serializer_enabled()); |
| 1054 LOG_API(i_isolate, "FunctionTemplate::New"); |
| 1055 ENTER_V8(i_isolate); |
| 1056 return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature, |
| 1057 length, false); |
| 1058 } |
| 1059 #endif |
| 1060 |
| 1061 |
1044 Local<Signature> Signature::New(Isolate* isolate, | 1062 Local<Signature> Signature::New(Isolate* isolate, |
1045 Local<FunctionTemplate> receiver) { | 1063 Local<FunctionTemplate> receiver) { |
1046 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); | 1064 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); |
1047 } | 1065 } |
1048 | 1066 |
1049 | 1067 |
1050 Local<AccessorSignature> AccessorSignature::New( | 1068 Local<AccessorSignature> AccessorSignature::New( |
1051 Isolate* isolate, Local<FunctionTemplate> receiver) { | 1069 Isolate* isolate, Local<FunctionTemplate> receiver) { |
1052 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); | 1070 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); |
1053 } | 1071 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 } | 1106 } |
1089 | 1107 |
1090 | 1108 |
1091 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ | 1109 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ |
1092 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ | 1110 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ |
1093 (obj)->setter(*foreign); \ | 1111 (obj)->setter(*foreign); \ |
1094 } while (false) | 1112 } while (false) |
1095 | 1113 |
1096 | 1114 |
1097 void FunctionTemplate::SetCallHandler(FunctionCallback callback, | 1115 void FunctionTemplate::SetCallHandler(FunctionCallback callback, |
1098 v8::Local<Value> data) { | 1116 v8::Local<Value> data, |
| 1117 v8::Local<Value> fast_handler) { |
1099 auto info = Utils::OpenHandle(this); | 1118 auto info = Utils::OpenHandle(this); |
1100 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); | 1119 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); |
1101 i::Isolate* isolate = info->GetIsolate(); | 1120 i::Isolate* isolate = info->GetIsolate(); |
1102 ENTER_V8(isolate); | 1121 ENTER_V8(isolate); |
1103 i::HandleScope scope(isolate); | 1122 i::HandleScope scope(isolate); |
1104 i::Handle<i::Struct> struct_obj = | 1123 i::Handle<i::Struct> struct_obj = |
1105 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); | 1124 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
1106 i::Handle<i::CallHandlerInfo> obj = | 1125 i::Handle<i::CallHandlerInfo> obj = |
1107 i::Handle<i::CallHandlerInfo>::cast(struct_obj); | 1126 i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
1108 SET_FIELD_WRAPPED(obj, set_callback, callback); | 1127 SET_FIELD_WRAPPED(obj, set_callback, callback); |
| 1128 if (!fast_handler.IsEmpty()) { |
| 1129 i::Handle<i::Object> code = Utils::OpenHandle(*fast_handler); |
| 1130 CHECK(code->IsCode()); |
| 1131 obj->set_fast_handler(*code); |
| 1132 } |
1109 if (data.IsEmpty()) { | 1133 if (data.IsEmpty()) { |
1110 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 1134 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
1111 } | 1135 } |
1112 obj->set_data(*Utils::OpenHandle(*data)); | 1136 obj->set_data(*Utils::OpenHandle(*data)); |
1113 info->set_call_code(*obj); | 1137 info->set_call_code(*obj); |
1114 } | 1138 } |
1115 | 1139 |
1116 | 1140 |
1117 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( | 1141 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( |
1118 i::Handle<i::AccessorInfo> obj, v8::Local<Name> name, | 1142 i::Handle<i::AccessorInfo> obj, v8::Local<Name> name, |
(...skipping 3220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4339 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); | 4363 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); |
4340 } | 4364 } |
4341 | 4365 |
4342 | 4366 |
4343 MaybeLocal<Function> Function::New(Local<Context> context, | 4367 MaybeLocal<Function> Function::New(Local<Context> context, |
4344 FunctionCallback callback, Local<Value> data, | 4368 FunctionCallback callback, Local<Value> data, |
4345 int length) { | 4369 int length) { |
4346 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); | 4370 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); |
4347 LOG_API(isolate, "Function::New"); | 4371 LOG_API(isolate, "Function::New"); |
4348 ENTER_V8(isolate); | 4372 ENTER_V8(isolate); |
4349 return FunctionTemplateNew(isolate, callback, data, Local<Signature>(), | 4373 return FunctionTemplateNew(isolate, callback, Local<Value>(), data, |
4350 length, true)->GetFunction(context); | 4374 Local<Signature>(), length, true) |
| 4375 ->GetFunction(context); |
4351 } | 4376 } |
4352 | 4377 |
4353 | 4378 |
4354 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, | 4379 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, |
4355 Local<Value> data, int length) { | 4380 Local<Value> data, int length) { |
4356 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length) | 4381 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length) |
4357 .FromMaybe(Local<Function>()); | 4382 .FromMaybe(Local<Function>()); |
4358 } | 4383 } |
4359 | 4384 |
4360 | 4385 |
(...skipping 4139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8500 Address callback_address = | 8525 Address callback_address = |
8501 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8526 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8502 VMState<EXTERNAL> state(isolate); | 8527 VMState<EXTERNAL> state(isolate); |
8503 ExternalCallbackScope call_scope(isolate, callback_address); | 8528 ExternalCallbackScope call_scope(isolate, callback_address); |
8504 callback(info); | 8529 callback(info); |
8505 } | 8530 } |
8506 | 8531 |
8507 | 8532 |
8508 } // namespace internal | 8533 } // namespace internal |
8509 } // namespace v8 | 8534 } // namespace v8 |
OLD | NEW |