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 "include/v8-debug.h" | 12 #include "include/v8-debug.h" |
13 #include "include/v8-profiler.h" | 13 #include "include/v8-profiler.h" |
14 #include "include/v8-testing.h" | 14 #include "include/v8-testing.h" |
15 #include "src/api-natives.h" | 15 #include "src/api-natives.h" |
16 #include "src/assert-scope.h" | 16 #include "src/assert-scope.h" |
17 #include "src/background-parsing-task.h" | 17 #include "src/background-parsing-task.h" |
18 #include "src/base/functional.h" | 18 #include "src/base/functional.h" |
19 #include "src/base/platform/platform.h" | 19 #include "src/base/platform/platform.h" |
20 #include "src/base/platform/time.h" | 20 #include "src/base/platform/time.h" |
21 #include "src/base/utils/random-number-generator.h" | 21 #include "src/base/utils/random-number-generator.h" |
22 #include "src/bootstrapper.h" | 22 #include "src/bootstrapper.h" |
23 #include "src/char-predicates-inl.h" | 23 #include "src/char-predicates-inl.h" |
24 #include "src/code-stubs.h" | 24 #include "src/code-stubs.h" |
25 #include "src/compiler.h" | 25 #include "src/compiler.h" |
| 26 #include "src/compiler/fast-accessor-assembler.h" |
26 #include "src/context-measure.h" | 27 #include "src/context-measure.h" |
27 #include "src/contexts.h" | 28 #include "src/contexts.h" |
28 #include "src/conversions-inl.h" | 29 #include "src/conversions-inl.h" |
29 #include "src/counters.h" | 30 #include "src/counters.h" |
30 #include "src/debug/debug.h" | 31 #include "src/debug/debug.h" |
31 #include "src/deoptimizer.h" | 32 #include "src/deoptimizer.h" |
32 #include "src/execution.h" | 33 #include "src/execution.h" |
33 #include "src/global-handles.h" | 34 #include "src/global-handles.h" |
34 #include "src/icu_util.h" | 35 #include "src/icu_util.h" |
35 #include "src/isolate-inl.h" | 36 #include "src/isolate-inl.h" |
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 auto info = Utils::OpenHandle(this); | 991 auto info = Utils::OpenHandle(this); |
991 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit"); | 992 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit"); |
992 i::Isolate* isolate = info->GetIsolate(); | 993 i::Isolate* isolate = info->GetIsolate(); |
993 ENTER_V8(isolate); | 994 ENTER_V8(isolate); |
994 info->set_parent_template(*Utils::OpenHandle(*value)); | 995 info->set_parent_template(*Utils::OpenHandle(*value)); |
995 } | 996 } |
996 | 997 |
997 | 998 |
998 static Local<FunctionTemplate> FunctionTemplateNew( | 999 static Local<FunctionTemplate> FunctionTemplateNew( |
999 i::Isolate* isolate, FunctionCallback callback, | 1000 i::Isolate* isolate, FunctionCallback callback, |
1000 v8::Local<Value> fast_handler, v8::Local<Value> data, | 1001 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, |
1001 v8::Local<Signature> signature, int length, bool do_not_cache) { | 1002 v8::Local<Signature> signature, int length, bool do_not_cache) { |
1002 i::Handle<i::Struct> struct_obj = | 1003 i::Handle<i::Struct> struct_obj = |
1003 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); | 1004 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
1004 i::Handle<i::FunctionTemplateInfo> obj = | 1005 i::Handle<i::FunctionTemplateInfo> obj = |
1005 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); | 1006 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
1006 InitializeFunctionTemplate(obj); | 1007 InitializeFunctionTemplate(obj); |
1007 obj->set_do_not_cache(do_not_cache); | 1008 obj->set_do_not_cache(do_not_cache); |
1008 int next_serial_number = 0; | 1009 int next_serial_number = 0; |
1009 if (!do_not_cache) { | 1010 if (!do_not_cache) { |
1010 next_serial_number = isolate->next_serial_number() + 1; | 1011 next_serial_number = isolate->next_serial_number() + 1; |
(...skipping 20 matching lines...) Expand all Loading... |
1031 FunctionCallback callback, | 1032 FunctionCallback callback, |
1032 v8::Local<Value> data, | 1033 v8::Local<Value> data, |
1033 v8::Local<Signature> signature, | 1034 v8::Local<Signature> signature, |
1034 int length) { | 1035 int length) { |
1035 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 1036 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
1036 // Changes to the environment cannot be captured in the snapshot. Expect no | 1037 // Changes to the environment cannot be captured in the snapshot. Expect no |
1037 // function templates when the isolate is created for serialization. | 1038 // function templates when the isolate is created for serialization. |
1038 DCHECK(!i_isolate->serializer_enabled()); | 1039 DCHECK(!i_isolate->serializer_enabled()); |
1039 LOG_API(i_isolate, "FunctionTemplate::New"); | 1040 LOG_API(i_isolate, "FunctionTemplate::New"); |
1040 ENTER_V8(i_isolate); | 1041 ENTER_V8(i_isolate); |
1041 return FunctionTemplateNew(i_isolate, callback, v8::Local<Value>(), data, | 1042 return FunctionTemplateNew(i_isolate, callback, nullptr, data, signature, |
1042 signature, length, false); | 1043 length, false); |
1043 } | 1044 } |
1044 | 1045 |
1045 | 1046 |
1046 Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler( | 1047 Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler( |
1047 Isolate* isolate, FunctionCallback callback, v8::Local<Value> fast_handler, | 1048 Isolate* isolate, FunctionCallback callback, |
1048 v8::Local<Value> data, v8::Local<Signature> signature, int length) { | 1049 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, |
| 1050 v8::Local<Signature> signature, int length) { |
1049 // TODO(vogelheim): 'fast_handler' should have a more specific type than | 1051 // TODO(vogelheim): 'fast_handler' should have a more specific type than |
1050 // Local<Value>. | 1052 // Local<Value>. |
1051 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 1053 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
1052 DCHECK(!i_isolate->serializer_enabled()); | 1054 DCHECK(!i_isolate->serializer_enabled()); |
1053 LOG_API(i_isolate, "FunctionTemplate::NewWithFastHandler"); | 1055 LOG_API(i_isolate, "FunctionTemplate::NewWithFastHandler"); |
1054 ENTER_V8(i_isolate); | 1056 ENTER_V8(i_isolate); |
1055 return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature, | 1057 return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature, |
1056 length, false); | 1058 length, false); |
1057 } | 1059 } |
1058 | 1060 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 return 0; | 1105 return 0; |
1104 } | 1106 } |
1105 | 1107 |
1106 | 1108 |
1107 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ | 1109 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ |
1108 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ | 1110 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ |
1109 (obj)->setter(*foreign); \ | 1111 (obj)->setter(*foreign); \ |
1110 } while (false) | 1112 } while (false) |
1111 | 1113 |
1112 | 1114 |
1113 void FunctionTemplate::SetCallHandler(FunctionCallback callback, | 1115 void FunctionTemplate::SetCallHandler( |
1114 v8::Local<Value> data, | 1116 FunctionCallback callback, v8::Local<Value> data, |
1115 v8::Local<Value> fast_handler) { | 1117 experimental::FastAccessorBuilder* fast_handler) { |
1116 auto info = Utils::OpenHandle(this); | 1118 auto info = Utils::OpenHandle(this); |
1117 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); | 1119 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); |
1118 i::Isolate* isolate = info->GetIsolate(); | 1120 i::Isolate* isolate = info->GetIsolate(); |
1119 ENTER_V8(isolate); | 1121 ENTER_V8(isolate); |
1120 i::HandleScope scope(isolate); | 1122 i::HandleScope scope(isolate); |
1121 i::Handle<i::Struct> struct_obj = | 1123 i::Handle<i::Struct> struct_obj = |
1122 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); | 1124 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
1123 i::Handle<i::CallHandlerInfo> obj = | 1125 i::Handle<i::CallHandlerInfo> obj = |
1124 i::Handle<i::CallHandlerInfo>::cast(struct_obj); | 1126 i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
1125 SET_FIELD_WRAPPED(obj, set_callback, callback); | 1127 SET_FIELD_WRAPPED(obj, set_callback, callback); |
1126 if (!fast_handler.IsEmpty()) { | 1128 if (fast_handler != nullptr) { |
1127 i::Handle<i::Object> code = Utils::OpenHandle(*fast_handler); | 1129 auto faa = *reinterpret_cast<internal::compiler::FastAccessorAssembler**>( |
1128 CHECK(code->IsCode()); | 1130 fast_handler); |
| 1131 i::Handle<i::Code> code = faa->Build(); |
| 1132 CHECK(!code.is_null()); |
1129 obj->set_fast_handler(*code); | 1133 obj->set_fast_handler(*code); |
| 1134 delete fast_handler; |
1130 } | 1135 } |
1131 if (data.IsEmpty()) { | 1136 if (data.IsEmpty()) { |
1132 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 1137 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
1133 } | 1138 } |
1134 obj->set_data(*Utils::OpenHandle(*data)); | 1139 obj->set_data(*Utils::OpenHandle(*data)); |
1135 info->set_call_code(*obj); | 1140 info->set_call_code(*obj); |
1136 } | 1141 } |
1137 | 1142 |
1138 | 1143 |
1139 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( | 1144 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( |
(...skipping 3243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4383 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); | 4388 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); |
4384 } | 4389 } |
4385 | 4390 |
4386 | 4391 |
4387 MaybeLocal<Function> Function::New(Local<Context> context, | 4392 MaybeLocal<Function> Function::New(Local<Context> context, |
4388 FunctionCallback callback, Local<Value> data, | 4393 FunctionCallback callback, Local<Value> data, |
4389 int length) { | 4394 int length) { |
4390 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); | 4395 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); |
4391 LOG_API(isolate, "Function::New"); | 4396 LOG_API(isolate, "Function::New"); |
4392 ENTER_V8(isolate); | 4397 ENTER_V8(isolate); |
4393 return FunctionTemplateNew(isolate, callback, Local<Value>(), data, | 4398 return FunctionTemplateNew(isolate, callback, nullptr, data, |
4394 Local<Signature>(), length, true) | 4399 Local<Signature>(), length, true) |
4395 ->GetFunction(context); | 4400 ->GetFunction(context); |
4396 } | 4401 } |
4397 | 4402 |
4398 | 4403 |
4399 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, | 4404 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, |
4400 Local<Value> data, int length) { | 4405 Local<Value> data, int length) { |
4401 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length) | 4406 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length) |
4402 .FromMaybe(Local<Function>()); | 4407 .FromMaybe(Local<Function>()); |
4403 } | 4408 } |
(...skipping 3958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8362 | 8367 |
8363 | 8368 |
8364 // TODO(svenpanne) Deprecate this. | 8369 // TODO(svenpanne) Deprecate this. |
8365 void Testing::DeoptimizeAll() { | 8370 void Testing::DeoptimizeAll() { |
8366 i::Isolate* isolate = i::Isolate::Current(); | 8371 i::Isolate* isolate = i::Isolate::Current(); |
8367 i::HandleScope scope(isolate); | 8372 i::HandleScope scope(isolate); |
8368 internal::Deoptimizer::DeoptimizeAll(isolate); | 8373 internal::Deoptimizer::DeoptimizeAll(isolate); |
8369 } | 8374 } |
8370 | 8375 |
8371 | 8376 |
| 8377 namespace experimental { |
| 8378 |
| 8379 |
| 8380 FastAccessorBuilder::FastAccessorBuilder() : impl_(nullptr) {} |
| 8381 |
| 8382 |
| 8383 FastAccessorBuilder::~FastAccessorBuilder() { |
| 8384 CHECK_NOT_NULL(impl_); |
| 8385 delete reinterpret_cast<internal::compiler::FastAccessorAssembler*>(impl_); |
| 8386 } |
| 8387 |
| 8388 |
| 8389 FastAccessorBuilder* FastAccessorBuilder::New(Isolate* isolate) { |
| 8390 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 8391 internal::compiler::FastAccessorAssembler* faa = |
| 8392 new internal::compiler::FastAccessorAssembler(i_isolate); |
| 8393 FastAccessorBuilder* fab = new FastAccessorBuilder; |
| 8394 fab->impl_ = faa; |
| 8395 return fab; |
| 8396 } |
| 8397 |
| 8398 FastAccessorBuilder::ValueId FastAccessorBuilder::IntegerConstant( |
| 8399 int const_value) { |
| 8400 return reinterpret_cast<internal::compiler::FastAccessorAssembler*>(impl_) |
| 8401 ->IntegerConstant(const_value); |
| 8402 } |
| 8403 |
| 8404 |
| 8405 void FastAccessorBuilder::ReturnValue(ValueId value) { |
| 8406 reinterpret_cast<internal::compiler::FastAccessorAssembler*>(impl_) |
| 8407 ->ReturnValue(value); |
| 8408 } |
| 8409 |
| 8410 |
| 8411 FastAccessorBuilder::ValueId FastAccessorBuilder::GetCallTarget() { |
| 8412 return reinterpret_cast<internal::compiler::FastAccessorAssembler*>(impl_) |
| 8413 ->GetCallTarget(); |
| 8414 } |
| 8415 |
| 8416 FastAccessorBuilder::ValueId FastAccessorBuilder::GetParameter( |
| 8417 size_t parameter_no) { |
| 8418 return reinterpret_cast<internal::compiler::FastAccessorAssembler*>(impl_) |
| 8419 ->GetParameter(parameter_no); |
| 8420 } |
| 8421 |
| 8422 FastAccessorBuilder::ValueId FastAccessorBuilder::GetInternalField( |
| 8423 ValueId value, int field_no) { |
| 8424 return reinterpret_cast<internal::compiler::FastAccessorAssembler*>(impl_) |
| 8425 ->GetInternalField(value, field_no); |
| 8426 } |
| 8427 |
| 8428 } // namespace experimental |
| 8429 |
| 8430 |
8372 namespace internal { | 8431 namespace internal { |
8373 | 8432 |
8374 | 8433 |
8375 void HandleScopeImplementer::FreeThreadResources() { | 8434 void HandleScopeImplementer::FreeThreadResources() { |
8376 Free(); | 8435 Free(); |
8377 } | 8436 } |
8378 | 8437 |
8379 | 8438 |
8380 char* HandleScopeImplementer::ArchiveThread(char* storage) { | 8439 char* HandleScopeImplementer::ArchiveThread(char* storage) { |
8381 HandleScopeData* current = isolate_->handle_scope_data(); | 8440 HandleScopeData* current = isolate_->handle_scope_data(); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8533 Address callback_address = | 8592 Address callback_address = |
8534 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8593 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8535 VMState<EXTERNAL> state(isolate); | 8594 VMState<EXTERNAL> state(isolate); |
8536 ExternalCallbackScope call_scope(isolate, callback_address); | 8595 ExternalCallbackScope call_scope(isolate, callback_address); |
8537 callback(info); | 8596 callback(info); |
8538 } | 8597 } |
8539 | 8598 |
8540 | 8599 |
8541 } // namespace internal | 8600 } // namespace internal |
8542 } // namespace v8 | 8601 } // namespace v8 |
OLD | NEW |