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

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: Remove impl_ cleanup. Drop tests for --optimize-for-size. Also rebase. 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
« no previous file with comments | « src/DEPS ('k') | src/api-experimental.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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
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
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 3250 matching lines...) Expand 10 before | Expand all | Expand 10 after
4357 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); 4360 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value);
4358 } 4361 }
4359 4362
4360 4363
4361 MaybeLocal<Function> Function::New(Local<Context> context, 4364 MaybeLocal<Function> Function::New(Local<Context> context,
4362 FunctionCallback callback, Local<Value> data, 4365 FunctionCallback callback, Local<Value> data,
4363 int length) { 4366 int length) {
4364 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); 4367 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
4365 LOG_API(isolate, "Function::New"); 4368 LOG_API(isolate, "Function::New");
4366 ENTER_V8(isolate); 4369 ENTER_V8(isolate);
4367 return FunctionTemplateNew(isolate, callback, Local<Value>(), data, 4370 return FunctionTemplateNew(isolate, callback, nullptr, data,
4368 Local<Signature>(), length, true) 4371 Local<Signature>(), length, true)
4369 ->GetFunction(context); 4372 ->GetFunction(context);
4370 } 4373 }
4371 4374
4372 4375
4373 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, 4376 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback,
4374 Local<Value> data, int length) { 4377 Local<Value> data, int length) {
4375 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length) 4378 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length)
4376 .FromMaybe(Local<Function>()); 4379 .FromMaybe(Local<Function>());
4377 } 4380 }
(...skipping 4151 matching lines...) Expand 10 before | Expand all | Expand 10 after
8529 Address callback_address = 8532 Address callback_address =
8530 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8533 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8531 VMState<EXTERNAL> state(isolate); 8534 VMState<EXTERNAL> state(isolate);
8532 ExternalCallbackScope call_scope(isolate, callback_address); 8535 ExternalCallbackScope call_scope(isolate, callback_address);
8533 callback(info); 8536 callback(info);
8534 } 8537 }
8535 8538
8536 8539
8537 } // namespace internal 8540 } // namespace internal
8538 } // namespace v8 8541 } // namespace v8
OLDNEW
« no previous file with comments | « src/DEPS ('k') | src/api-experimental.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698