Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: src/api.cc

Issue 1474543004: Implement Fast Accessor Builder (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Review feedback. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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-experimental.h"
13 #include "include/v8-profiler.h" 14 #include "include/v8-profiler.h"
14 #include "include/v8-testing.h" 15 #include "include/v8-testing.h"
16 #include "src/api-experimental.h"
15 #include "src/api-natives.h" 17 #include "src/api-natives.h"
16 #include "src/assert-scope.h" 18 #include "src/assert-scope.h"
17 #include "src/background-parsing-task.h" 19 #include "src/background-parsing-task.h"
18 #include "src/base/functional.h" 20 #include "src/base/functional.h"
19 #include "src/base/platform/platform.h" 21 #include "src/base/platform/platform.h"
20 #include "src/base/platform/time.h" 22 #include "src/base/platform/time.h"
21 #include "src/base/utils/random-number-generator.h" 23 #include "src/base/utils/random-number-generator.h"
22 #include "src/bootstrapper.h" 24 #include "src/bootstrapper.h"
23 #include "src/char-predicates-inl.h" 25 #include "src/char-predicates-inl.h"
24 #include "src/code-stubs.h" 26 #include "src/code-stubs.h"
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 auto info = Utils::OpenHandle(this); 992 auto info = Utils::OpenHandle(this);
991 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit"); 993 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit");
992 i::Isolate* isolate = info->GetIsolate(); 994 i::Isolate* isolate = info->GetIsolate();
993 ENTER_V8(isolate); 995 ENTER_V8(isolate);
994 info->set_parent_template(*Utils::OpenHandle(*value)); 996 info->set_parent_template(*Utils::OpenHandle(*value));
995 } 997 }
996 998
997 999
998 static Local<FunctionTemplate> FunctionTemplateNew( 1000 static Local<FunctionTemplate> FunctionTemplateNew(
999 i::Isolate* isolate, FunctionCallback callback, 1001 i::Isolate* isolate, FunctionCallback callback,
1000 v8::Local<Value> fast_handler, v8::Local<Value> data, 1002 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data,
1001 v8::Local<Signature> signature, int length, bool do_not_cache) { 1003 v8::Local<Signature> signature, int length, bool do_not_cache) {
1002 i::Handle<i::Struct> struct_obj = 1004 i::Handle<i::Struct> struct_obj =
1003 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); 1005 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE);
1004 i::Handle<i::FunctionTemplateInfo> obj = 1006 i::Handle<i::FunctionTemplateInfo> obj =
1005 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); 1007 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj);
1006 InitializeFunctionTemplate(obj); 1008 InitializeFunctionTemplate(obj);
1007 obj->set_do_not_cache(do_not_cache); 1009 obj->set_do_not_cache(do_not_cache);
1008 int next_serial_number = 0; 1010 int next_serial_number = 0;
1009 if (!do_not_cache) { 1011 if (!do_not_cache) {
1010 next_serial_number = isolate->next_serial_number() + 1; 1012 next_serial_number = isolate->next_serial_number() + 1;
(...skipping 20 matching lines...) Expand all
1031 FunctionCallback callback, 1033 FunctionCallback callback,
1032 v8::Local<Value> data, 1034 v8::Local<Value> data,
1033 v8::Local<Signature> signature, 1035 v8::Local<Signature> signature,
1034 int length) { 1036 int length) {
1035 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 1037 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
1036 // 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
1037 // function templates when the isolate is created for serialization. 1039 // function templates when the isolate is created for serialization.
1038 DCHECK(!i_isolate->serializer_enabled()); 1040 DCHECK(!i_isolate->serializer_enabled());
1039 LOG_API(i_isolate, "FunctionTemplate::New"); 1041 LOG_API(i_isolate, "FunctionTemplate::New");
1040 ENTER_V8(i_isolate); 1042 ENTER_V8(i_isolate);
1041 return FunctionTemplateNew(i_isolate, callback, v8::Local<Value>(), data, 1043 return FunctionTemplateNew(i_isolate, callback, nullptr, data, signature,
1042 signature, length, false); 1044 length, false);
1043 } 1045 }
1044 1046
1045 1047
1046 Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler( 1048 Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler(
1047 Isolate* isolate, FunctionCallback callback, v8::Local<Value> fast_handler, 1049 Isolate* isolate, FunctionCallback callback,
1048 v8::Local<Value> data, v8::Local<Signature> signature, int length) { 1050 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data,
1051 v8::Local<Signature> signature, int length) {
1049 // TODO(vogelheim): 'fast_handler' should have a more specific type than 1052 // TODO(vogelheim): 'fast_handler' should have a more specific type than
1050 // Local<Value>. 1053 // Local<Value>.
1051 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 1054 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
1052 DCHECK(!i_isolate->serializer_enabled()); 1055 DCHECK(!i_isolate->serializer_enabled());
1053 LOG_API(i_isolate, "FunctionTemplate::NewWithFastHandler"); 1056 LOG_API(i_isolate, "FunctionTemplate::NewWithFastHandler");
1054 ENTER_V8(i_isolate); 1057 ENTER_V8(i_isolate);
1055 return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature, 1058 return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature,
1056 length, false); 1059 length, false);
1057 } 1060 }
1058 1061
1059 1062
1060 Local<Signature> Signature::New(Isolate* isolate, 1063 Local<Signature> Signature::New(Isolate* isolate,
1061 Local<FunctionTemplate> receiver) { 1064 Local<FunctionTemplate> receiver) {
1062 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); 1065 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver));
1063 } 1066 }
1064 1067
1065 1068
1066 Local<AccessorSignature> AccessorSignature::New( 1069 Local<AccessorSignature> AccessorSignature::New(
1067 Isolate* isolate, Local<FunctionTemplate> receiver) { 1070 Isolate* isolate, Local<FunctionTemplate> receiver) {
1068 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); 1071 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver));
1069 } 1072 }
1070 1073
1071 1074
1072 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ 1075 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \
1073 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ 1076 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \
1074 (obj)->setter(*foreign); \ 1077 (obj)->setter(*foreign); \
1075 } while (false) 1078 } while (false)
1076 1079
1077 1080
1078 void FunctionTemplate::SetCallHandler(FunctionCallback callback, 1081 void FunctionTemplate::SetCallHandler(
1079 v8::Local<Value> data, 1082 FunctionCallback callback, v8::Local<Value> data,
1080 v8::Local<Value> fast_handler) { 1083 experimental::FastAccessorBuilder* fast_handler) {
1081 auto info = Utils::OpenHandle(this); 1084 auto info = Utils::OpenHandle(this);
1082 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); 1085 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler");
1083 i::Isolate* isolate = info->GetIsolate(); 1086 i::Isolate* isolate = info->GetIsolate();
1084 ENTER_V8(isolate); 1087 ENTER_V8(isolate);
1085 i::HandleScope scope(isolate); 1088 i::HandleScope scope(isolate);
1086 i::Handle<i::Struct> struct_obj = 1089 i::Handle<i::Struct> struct_obj =
1087 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); 1090 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE);
1088 i::Handle<i::CallHandlerInfo> obj = 1091 i::Handle<i::CallHandlerInfo> obj =
1089 i::Handle<i::CallHandlerInfo>::cast(struct_obj); 1092 i::Handle<i::CallHandlerInfo>::cast(struct_obj);
1090 SET_FIELD_WRAPPED(obj, set_callback, callback); 1093 SET_FIELD_WRAPPED(obj, set_callback, callback);
1091 if (!fast_handler.IsEmpty()) { 1094 i::MaybeHandle<i::Code> code =
1092 i::Handle<i::Object> code = Utils::OpenHandle(*fast_handler); 1095 i::experimental::BuildCodeFromFastAccessorBuilder(fast_handler);
1093 CHECK(code->IsCode()); 1096 if (!code.is_null()) {
1094 obj->set_fast_handler(*code); 1097 obj->set_fast_handler(*code.ToHandleChecked());
1095 } 1098 }
1096 if (data.IsEmpty()) { 1099 if (data.IsEmpty()) {
1097 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); 1100 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1098 } 1101 }
1099 obj->set_data(*Utils::OpenHandle(*data)); 1102 obj->set_data(*Utils::OpenHandle(*data));
1100 info->set_call_code(*obj); 1103 info->set_call_code(*obj);
1101 } 1104 }
1102 1105
1103 1106
1104 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( 1107 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties(
(...skipping 3243 matching lines...) Expand 10 before | Expand all | Expand 10 after
4348 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); 4351 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value);
4349 } 4352 }
4350 4353
4351 4354
4352 MaybeLocal<Function> Function::New(Local<Context> context, 4355 MaybeLocal<Function> Function::New(Local<Context> context,
4353 FunctionCallback callback, Local<Value> data, 4356 FunctionCallback callback, Local<Value> data,
4354 int length) { 4357 int length) {
4355 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); 4358 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
4356 LOG_API(isolate, "Function::New"); 4359 LOG_API(isolate, "Function::New");
4357 ENTER_V8(isolate); 4360 ENTER_V8(isolate);
4358 return FunctionTemplateNew(isolate, callback, Local<Value>(), data, 4361 return FunctionTemplateNew(isolate, callback, nullptr, data,
4359 Local<Signature>(), length, true) 4362 Local<Signature>(), length, true)
4360 ->GetFunction(context); 4363 ->GetFunction(context);
4361 } 4364 }
4362 4365
4363 4366
4364 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, 4367 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback,
4365 Local<Value> data, int length) { 4368 Local<Value> data, int length) {
4366 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length) 4369 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length)
4367 .FromMaybe(Local<Function>()); 4370 .FromMaybe(Local<Function>());
4368 } 4371 }
(...skipping 4127 matching lines...) Expand 10 before | Expand all | Expand 10 after
8496 Address callback_address = 8499 Address callback_address =
8497 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8500 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8498 VMState<EXTERNAL> state(isolate); 8501 VMState<EXTERNAL> state(isolate);
8499 ExternalCallbackScope call_scope(isolate, callback_address); 8502 ExternalCallbackScope call_scope(isolate, callback_address);
8500 callback(info); 8503 callback(info);
8501 } 8504 }
8502 8505
8503 8506
8504 } // namespace internal 8507 } // namespace internal
8505 } // namespace v8 8508 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698