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

Side by Side Diff: src/api.cc

Issue 2405213002: V8 support for cached accessors. (Closed)
Patch Set: Toon's feedback. Created 4 years, 1 month 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 | « include/v8.h ('k') | src/crankshaft/hydrogen.cc » ('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
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 templ->set_serial_number(i::Smi::kZero); 1090 templ->set_serial_number(i::Smi::kZero);
1091 if (templ->IsFunctionTemplateInfo()) { 1091 if (templ->IsFunctionTemplateInfo()) {
1092 i::Handle<i::FunctionTemplateInfo>::cast(templ)->set_do_not_cache(true); 1092 i::Handle<i::FunctionTemplateInfo>::cast(templ)->set_do_not_cache(true);
1093 } 1093 }
1094 } 1094 }
1095 i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name), 1095 i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
1096 value_obj, 1096 value_obj,
1097 static_cast<i::PropertyAttributes>(attribute)); 1097 static_cast<i::PropertyAttributes>(attribute));
1098 } 1098 }
1099 1099
1100 void Template::SetPrivate(v8::Local<Private> name, v8::Local<Data> value,
1101 v8::PropertyAttribute attribute) {
1102 Set(Utils::ToLocal(Utils::OpenHandle(reinterpret_cast<Name*>(*name))), value,
1103 attribute);
1104 }
1100 1105
1101 void Template::SetAccessorProperty( 1106 void Template::SetAccessorProperty(
1102 v8::Local<v8::Name> name, 1107 v8::Local<v8::Name> name,
1103 v8::Local<FunctionTemplate> getter, 1108 v8::Local<FunctionTemplate> getter,
1104 v8::Local<FunctionTemplate> setter, 1109 v8::Local<FunctionTemplate> setter,
1105 v8::PropertyAttribute attribute, 1110 v8::PropertyAttribute attribute,
1106 v8::AccessControl access_control) { 1111 v8::AccessControl access_control) {
1107 // TODO(verwaest): Remove |access_control|. 1112 // TODO(verwaest): Remove |access_control|.
1108 DCHECK_EQ(v8::DEFAULT, access_control); 1113 DCHECK_EQ(v8::DEFAULT, access_control);
1109 auto templ = Utils::OpenHandle(this); 1114 auto templ = Utils::OpenHandle(this);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 1158
1154 1159
1155 void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) { 1160 void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) {
1156 auto info = Utils::OpenHandle(this); 1161 auto info = Utils::OpenHandle(this);
1157 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit"); 1162 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit");
1158 i::Isolate* isolate = info->GetIsolate(); 1163 i::Isolate* isolate = info->GetIsolate();
1159 ENTER_V8(isolate); 1164 ENTER_V8(isolate);
1160 info->set_parent_template(*Utils::OpenHandle(*value)); 1165 info->set_parent_template(*Utils::OpenHandle(*value));
1161 } 1166 }
1162 1167
1163
1164 static Local<FunctionTemplate> FunctionTemplateNew( 1168 static Local<FunctionTemplate> FunctionTemplateNew(
1165 i::Isolate* isolate, FunctionCallback callback, 1169 i::Isolate* isolate, FunctionCallback callback,
1166 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, 1170 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data,
1167 v8::Local<Signature> signature, int length, bool do_not_cache) { 1171 v8::Local<Signature> signature, int length, bool do_not_cache,
1172 v8::Local<Private> cached_property_name = v8::Local<Private>()) {
1168 i::Handle<i::Struct> struct_obj = 1173 i::Handle<i::Struct> struct_obj =
1169 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); 1174 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE);
1170 i::Handle<i::FunctionTemplateInfo> obj = 1175 i::Handle<i::FunctionTemplateInfo> obj =
1171 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); 1176 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj);
1172 InitializeFunctionTemplate(obj); 1177 InitializeFunctionTemplate(obj);
1173 obj->set_do_not_cache(do_not_cache); 1178 obj->set_do_not_cache(do_not_cache);
1174 int next_serial_number = 0; 1179 int next_serial_number = 0;
1175 if (!do_not_cache) { 1180 if (!do_not_cache) {
1176 next_serial_number = isolate->heap()->GetNextTemplateSerialNumber(); 1181 next_serial_number = isolate->heap()->GetNextTemplateSerialNumber();
1177 } 1182 }
1178 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); 1183 obj->set_serial_number(i::Smi::FromInt(next_serial_number));
1179 if (callback != 0) { 1184 if (callback != 0) {
1180 if (data.IsEmpty()) { 1185 if (data.IsEmpty()) {
1181 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); 1186 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1182 } 1187 }
1183 Utils::ToLocal(obj)->SetCallHandler(callback, data, fast_handler); 1188 Utils::ToLocal(obj)->SetCallHandler(callback, data, fast_handler);
1184 } 1189 }
1185 obj->set_length(length); 1190 obj->set_length(length);
1186 obj->set_undetectable(false); 1191 obj->set_undetectable(false);
1187 obj->set_needs_access_check(false); 1192 obj->set_needs_access_check(false);
1188 obj->set_accept_any_receiver(true); 1193 obj->set_accept_any_receiver(true);
1189 if (!signature.IsEmpty()) 1194 if (!signature.IsEmpty())
1190 obj->set_signature(*Utils::OpenHandle(*signature)); 1195 obj->set_signature(*Utils::OpenHandle(*signature));
1196 obj->set_cached_property_name(
1197 cached_property_name.IsEmpty()
1198 ? isolate->heap()->the_hole_value()
1199 : *Utils::OpenHandle(*cached_property_name));
1191 return Utils::ToLocal(obj); 1200 return Utils::ToLocal(obj);
1192 } 1201 }
1193 1202
1194 Local<FunctionTemplate> FunctionTemplate::New( 1203 Local<FunctionTemplate> FunctionTemplate::New(
1195 Isolate* isolate, FunctionCallback callback, v8::Local<Value> data, 1204 Isolate* isolate, FunctionCallback callback, v8::Local<Value> data,
1196 v8::Local<Signature> signature, int length, ConstructorBehavior behavior) { 1205 v8::Local<Signature> signature, int length, ConstructorBehavior behavior) {
1197 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 1206 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
1198 // Changes to the environment cannot be captured in the snapshot. Expect no 1207 // Changes to the environment cannot be captured in the snapshot. Expect no
1199 // function templates when the isolate is created for serialization. 1208 // function templates when the isolate is created for serialization.
1200 LOG_API(i_isolate, FunctionTemplate, New); 1209 LOG_API(i_isolate, FunctionTemplate, New);
(...skipping 24 matching lines...) Expand all
1225 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, 1234 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data,
1226 v8::Local<Signature> signature, int length) { 1235 v8::Local<Signature> signature, int length) {
1227 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 1236 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
1228 DCHECK(!i_isolate->serializer_enabled()); 1237 DCHECK(!i_isolate->serializer_enabled());
1229 LOG_API(i_isolate, FunctionTemplate, NewWithFastHandler); 1238 LOG_API(i_isolate, FunctionTemplate, NewWithFastHandler);
1230 ENTER_V8(i_isolate); 1239 ENTER_V8(i_isolate);
1231 return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature, 1240 return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature,
1232 length, false); 1241 length, false);
1233 } 1242 }
1234 1243
1244 Local<FunctionTemplate> FunctionTemplate::NewWithCache(
1245 Isolate* isolate, FunctionCallback callback, Local<Private> cache_property,
1246 Local<Value> data, Local<Signature> signature, int length) {
1247 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
1248 DCHECK(!i_isolate->serializer_enabled());
1249 LOG_API(i_isolate, FunctionTemplate, NewWithFastHandler);
1250 ENTER_V8(i_isolate);
1251 return FunctionTemplateNew(i_isolate, callback, nullptr, data, signature,
1252 length, false, cache_property);
1253 }
1235 1254
1236 Local<Signature> Signature::New(Isolate* isolate, 1255 Local<Signature> Signature::New(Isolate* isolate,
1237 Local<FunctionTemplate> receiver) { 1256 Local<FunctionTemplate> receiver) {
1238 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); 1257 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver));
1239 } 1258 }
1240 1259
1241 1260
1242 Local<AccessorSignature> AccessorSignature::New( 1261 Local<AccessorSignature> AccessorSignature::New(
1243 Isolate* isolate, Local<FunctionTemplate> receiver) { 1262 Isolate* isolate, Local<FunctionTemplate> receiver) {
1244 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); 1263 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver));
(...skipping 8392 matching lines...) Expand 10 before | Expand all | Expand 10 after
9637 Address callback_address = 9656 Address callback_address =
9638 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9657 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9639 VMState<EXTERNAL> state(isolate); 9658 VMState<EXTERNAL> state(isolate);
9640 ExternalCallbackScope call_scope(isolate, callback_address); 9659 ExternalCallbackScope call_scope(isolate, callback_address);
9641 callback(info); 9660 callback(info);
9642 } 9661 }
9643 9662
9644 9663
9645 } // namespace internal 9664 } // namespace internal
9646 } // namespace v8 9665 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/crankshaft/hydrogen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698