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 |
11 #include <cmath> // For isnan. | 11 #include <cmath> // For isnan. |
12 #include <limits> | 12 #include <limits> |
13 #include <vector> | 13 #include <vector> |
14 #include "include/v8-debug.h" | 14 #include "include/v8-debug.h" |
15 #include "include/v8-experimental.h" | |
16 #include "include/v8-profiler.h" | 15 #include "include/v8-profiler.h" |
17 #include "include/v8-testing.h" | 16 #include "include/v8-testing.h" |
18 #include "src/api-experimental.h" | |
19 #include "src/api-natives.h" | 17 #include "src/api-natives.h" |
20 #include "src/assert-scope.h" | 18 #include "src/assert-scope.h" |
21 #include "src/background-parsing-task.h" | 19 #include "src/background-parsing-task.h" |
22 #include "src/base/functional.h" | 20 #include "src/base/functional.h" |
23 #include "src/base/platform/platform.h" | 21 #include "src/base/platform/platform.h" |
24 #include "src/base/platform/time.h" | 22 #include "src/base/platform/time.h" |
25 #include "src/base/utils/random-number-generator.h" | 23 #include "src/base/utils/random-number-generator.h" |
26 #include "src/bootstrapper.h" | 24 #include "src/bootstrapper.h" |
27 #include "src/char-predicates-inl.h" | 25 #include "src/char-predicates-inl.h" |
28 #include "src/code-stubs.h" | 26 #include "src/code-stubs.h" |
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 auto info = Utils::OpenHandle(this); | 992 auto info = Utils::OpenHandle(this); |
995 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit"); | 993 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit"); |
996 i::Isolate* isolate = info->GetIsolate(); | 994 i::Isolate* isolate = info->GetIsolate(); |
997 ENTER_V8(isolate); | 995 ENTER_V8(isolate); |
998 info->set_parent_template(*Utils::OpenHandle(*value)); | 996 info->set_parent_template(*Utils::OpenHandle(*value)); |
999 } | 997 } |
1000 | 998 |
1001 | 999 |
1002 static Local<FunctionTemplate> FunctionTemplateNew( | 1000 static Local<FunctionTemplate> FunctionTemplateNew( |
1003 i::Isolate* isolate, FunctionCallback callback, | 1001 i::Isolate* isolate, FunctionCallback callback, |
1004 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, | 1002 v8::Local<Value> fast_handler, v8::Local<Value> data, |
1005 v8::Local<Signature> signature, int length, bool do_not_cache) { | 1003 v8::Local<Signature> signature, int length, bool do_not_cache) { |
1006 i::Handle<i::Struct> struct_obj = | 1004 i::Handle<i::Struct> struct_obj = |
1007 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); | 1005 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
1008 i::Handle<i::FunctionTemplateInfo> obj = | 1006 i::Handle<i::FunctionTemplateInfo> obj = |
1009 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); | 1007 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
1010 InitializeFunctionTemplate(obj); | 1008 InitializeFunctionTemplate(obj); |
1011 obj->set_do_not_cache(do_not_cache); | 1009 obj->set_do_not_cache(do_not_cache); |
1012 int next_serial_number = 0; | 1010 int next_serial_number = 0; |
1013 if (!do_not_cache) { | 1011 if (!do_not_cache) { |
1014 next_serial_number = isolate->next_serial_number() + 1; | 1012 next_serial_number = isolate->next_serial_number() + 1; |
(...skipping 20 matching lines...) Expand all Loading... |
1035 FunctionCallback callback, | 1033 FunctionCallback callback, |
1036 v8::Local<Value> data, | 1034 v8::Local<Value> data, |
1037 v8::Local<Signature> signature, | 1035 v8::Local<Signature> signature, |
1038 int length) { | 1036 int length) { |
1039 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 1037 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
1040 // Changes to the environment cannot be captured in the snapshot. Expect no | 1038 // Changes to the environment cannot be captured in the snapshot. Expect no |
1041 // function templates when the isolate is created for serialization. | 1039 // function templates when the isolate is created for serialization. |
1042 DCHECK(!i_isolate->serializer_enabled()); | 1040 DCHECK(!i_isolate->serializer_enabled()); |
1043 LOG_API(i_isolate, "FunctionTemplate::New"); | 1041 LOG_API(i_isolate, "FunctionTemplate::New"); |
1044 ENTER_V8(i_isolate); | 1042 ENTER_V8(i_isolate); |
1045 return FunctionTemplateNew(i_isolate, callback, nullptr, data, signature, | 1043 return FunctionTemplateNew(i_isolate, callback, v8::Local<Value>(), data, |
1046 length, false); | 1044 signature, length, false); |
1047 } | 1045 } |
1048 | 1046 |
1049 | 1047 |
1050 Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler( | 1048 Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler( |
1051 Isolate* isolate, FunctionCallback callback, | 1049 Isolate* isolate, FunctionCallback callback, v8::Local<Value> fast_handler, |
1052 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, | 1050 v8::Local<Value> data, v8::Local<Signature> signature, int length) { |
1053 v8::Local<Signature> signature, int length) { | |
1054 // TODO(vogelheim): 'fast_handler' should have a more specific type than | 1051 // TODO(vogelheim): 'fast_handler' should have a more specific type than |
1055 // Local<Value>. | 1052 // Local<Value>. |
1056 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 1053 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
1057 DCHECK(!i_isolate->serializer_enabled()); | 1054 DCHECK(!i_isolate->serializer_enabled()); |
1058 LOG_API(i_isolate, "FunctionTemplate::NewWithFastHandler"); | 1055 LOG_API(i_isolate, "FunctionTemplate::NewWithFastHandler"); |
1059 ENTER_V8(i_isolate); | 1056 ENTER_V8(i_isolate); |
1060 return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature, | 1057 return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature, |
1061 length, false); | 1058 length, false); |
1062 } | 1059 } |
1063 | 1060 |
1064 | 1061 |
1065 Local<Signature> Signature::New(Isolate* isolate, | 1062 Local<Signature> Signature::New(Isolate* isolate, |
1066 Local<FunctionTemplate> receiver) { | 1063 Local<FunctionTemplate> receiver) { |
1067 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); | 1064 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); |
1068 } | 1065 } |
1069 | 1066 |
1070 | 1067 |
1071 Local<AccessorSignature> AccessorSignature::New( | 1068 Local<AccessorSignature> AccessorSignature::New( |
1072 Isolate* isolate, Local<FunctionTemplate> receiver) { | 1069 Isolate* isolate, Local<FunctionTemplate> receiver) { |
1073 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); | 1070 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); |
1074 } | 1071 } |
1075 | 1072 |
1076 | 1073 |
1077 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ | 1074 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ |
1078 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ | 1075 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ |
1079 (obj)->setter(*foreign); \ | 1076 (obj)->setter(*foreign); \ |
1080 } while (false) | 1077 } while (false) |
1081 | 1078 |
1082 | 1079 |
1083 void FunctionTemplate::SetCallHandler( | 1080 void FunctionTemplate::SetCallHandler(FunctionCallback callback, |
1084 FunctionCallback callback, v8::Local<Value> data, | 1081 v8::Local<Value> data, |
1085 experimental::FastAccessorBuilder* fast_handler) { | 1082 v8::Local<Value> fast_handler) { |
1086 auto info = Utils::OpenHandle(this); | 1083 auto info = Utils::OpenHandle(this); |
1087 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); | 1084 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); |
1088 i::Isolate* isolate = info->GetIsolate(); | 1085 i::Isolate* isolate = info->GetIsolate(); |
1089 ENTER_V8(isolate); | 1086 ENTER_V8(isolate); |
1090 i::HandleScope scope(isolate); | 1087 i::HandleScope scope(isolate); |
1091 i::Handle<i::Struct> struct_obj = | 1088 i::Handle<i::Struct> struct_obj = |
1092 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); | 1089 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
1093 i::Handle<i::CallHandlerInfo> obj = | 1090 i::Handle<i::CallHandlerInfo> obj = |
1094 i::Handle<i::CallHandlerInfo>::cast(struct_obj); | 1091 i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
1095 SET_FIELD_WRAPPED(obj, set_callback, callback); | 1092 SET_FIELD_WRAPPED(obj, set_callback, callback); |
1096 i::MaybeHandle<i::Code> code = | 1093 if (!fast_handler.IsEmpty()) { |
1097 i::experimental::BuildCodeFromFastAccessorBuilder(fast_handler); | 1094 i::Handle<i::Object> code = Utils::OpenHandle(*fast_handler); |
1098 if (!code.is_null()) { | 1095 CHECK(code->IsCode()); |
1099 obj->set_fast_handler(*code.ToHandleChecked()); | 1096 obj->set_fast_handler(*code); |
1100 } | 1097 } |
1101 if (data.IsEmpty()) { | 1098 if (data.IsEmpty()) { |
1102 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 1099 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
1103 } | 1100 } |
1104 obj->set_data(*Utils::OpenHandle(*data)); | 1101 obj->set_data(*Utils::OpenHandle(*data)); |
1105 info->set_call_code(*obj); | 1102 info->set_call_code(*obj); |
1106 } | 1103 } |
1107 | 1104 |
1108 | 1105 |
1109 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( | 1106 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( |
(...skipping 3254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4364 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); | 4361 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); |
4365 } | 4362 } |
4366 | 4363 |
4367 | 4364 |
4368 MaybeLocal<Function> Function::New(Local<Context> context, | 4365 MaybeLocal<Function> Function::New(Local<Context> context, |
4369 FunctionCallback callback, Local<Value> data, | 4366 FunctionCallback callback, Local<Value> data, |
4370 int length) { | 4367 int length) { |
4371 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); | 4368 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); |
4372 LOG_API(isolate, "Function::New"); | 4369 LOG_API(isolate, "Function::New"); |
4373 ENTER_V8(isolate); | 4370 ENTER_V8(isolate); |
4374 return FunctionTemplateNew(isolate, callback, nullptr, data, | 4371 return FunctionTemplateNew(isolate, callback, Local<Value>(), data, |
4375 Local<Signature>(), length, true) | 4372 Local<Signature>(), length, true) |
4376 ->GetFunction(context); | 4373 ->GetFunction(context); |
4377 } | 4374 } |
4378 | 4375 |
4379 | 4376 |
4380 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, | 4377 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, |
4381 Local<Value> data, int length) { | 4378 Local<Value> data, int length) { |
4382 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length) | 4379 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length) |
4383 .FromMaybe(Local<Function>()); | 4380 .FromMaybe(Local<Function>()); |
4384 } | 4381 } |
(...skipping 4151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8536 Address callback_address = | 8533 Address callback_address = |
8537 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8534 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8538 VMState<EXTERNAL> state(isolate); | 8535 VMState<EXTERNAL> state(isolate); |
8539 ExternalCallbackScope call_scope(isolate, callback_address); | 8536 ExternalCallbackScope call_scope(isolate, callback_address); |
8540 callback(info); | 8537 callback(info); |
8541 } | 8538 } |
8542 | 8539 |
8543 | 8540 |
8544 } // namespace internal | 8541 } // namespace internal |
8545 } // namespace v8 | 8542 } // namespace v8 |
OLD | NEW |