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