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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: Support runtime feature on templates Created 3 years, 6 months 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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 v8::AccessorNameGetterCallback getter = config.getter; 100 v8::AccessorNameGetterCallback getter = config.getter;
101 v8::AccessorNameSetterCallback setter = config.setter; 101 v8::AccessorNameSetterCallback setter = config.setter;
102 v8::Local<v8::Value> data = 102 v8::Local<v8::Value> data =
103 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(config.data)); 103 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(config.data));
104 v8::PropertyAttribute attribute = 104 v8::PropertyAttribute attribute =
105 static_cast<v8::PropertyAttribute>(config.attribute); 105 static_cast<v8::PropertyAttribute>(config.attribute);
106 unsigned location = config.property_location_configuration; 106 unsigned location = config.property_location_configuration;
107 107
108 DCHECK(location); 108 DCHECK(location);
109 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 109 v8::Local<v8::Context> context = isolate->GetCurrentContext();
110 if (location & V8DOMConfiguration::kOnInstance) { 110 if (location & V8DOMConfiguration::kOnInstance && !instance.IsEmpty()) {
111 instance 111 instance
112 ->SetNativeDataProperty(context, name, getter, setter, data, attribute) 112 ->SetNativeDataProperty(context, name, getter, setter, data, attribute)
113 .ToChecked(); 113 .ToChecked();
114 } 114 }
115 if (location & V8DOMConfiguration::kOnPrototype) { 115 if (location & V8DOMConfiguration::kOnPrototype && !prototype.IsEmpty()) {
116 prototype 116 prototype
117 ->SetNativeDataProperty(context, name, getter, setter, data, attribute) 117 ->SetNativeDataProperty(context, name, getter, setter, data, attribute)
118 .ToChecked(); 118 .ToChecked();
119 } 119 }
120 if (location & V8DOMConfiguration::kOnInterface) 120 if (location & V8DOMConfiguration::kOnInterface)
121 NOTREACHED(); 121 NOTREACHED();
122 } 122 }
123 123
124 void InstallLazyDataAttributeInternal( 124 void InstallLazyDataAttributeInternal(
125 v8::Isolate* isolate, 125 v8::Isolate* isolate,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 // Support [LenientThis] by not specifying the signature. V8 does not do 235 // Support [LenientThis] by not specifying the signature. V8 does not do
236 // the type checking against holder if no signature is specified. Note that 236 // the type checking against holder if no signature is specified. Note that
237 // info.Holder() passed to callbacks will be *unsafe*. 237 // info.Holder() passed to callbacks will be *unsafe*.
238 if (accessor.holder_check_configuration == 238 if (accessor.holder_check_configuration ==
239 V8DOMConfiguration::kDoNotCheckHolder) 239 V8DOMConfiguration::kDoNotCheckHolder)
240 signature = v8::Local<v8::Signature>(); 240 signature = v8::Local<v8::Signature>();
241 v8::Local<v8::Value> data = 241 v8::Local<v8::Value> data =
242 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)); 242 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data));
243 243
244 DCHECK(accessor.property_location_configuration); 244 const unsigned location = accessor.property_location_configuration;
245 if (accessor.property_location_configuration & 245 DCHECK(location);
246 if (location &
246 (V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) { 247 (V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) {
247 v8::Local<FunctionOrTemplate> getter = 248 v8::Local<FunctionOrTemplate> getter =
248 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( 249 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>(
249 isolate, getter_callback, cached_property_key, data, signature, 0); 250 isolate, getter_callback, cached_property_key, data, signature, 0);
250 v8::Local<FunctionOrTemplate> setter = 251 v8::Local<FunctionOrTemplate> setter =
251 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( 252 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>(
252 isolate, setter_callback, nullptr, data, signature, 1); 253 isolate, setter_callback, nullptr, data, signature, 1);
253 if (accessor.property_location_configuration & 254 if (location & V8DOMConfiguration::kOnInstance &&
254 V8DOMConfiguration::kOnInstance) { 255 !instance_or_template.IsEmpty()) {
255 instance_or_template->SetAccessorProperty( 256 instance_or_template->SetAccessorProperty(
256 name, getter, setter, 257 name, getter, setter,
257 static_cast<v8::PropertyAttribute>(accessor.attribute)); 258 static_cast<v8::PropertyAttribute>(accessor.attribute));
258 } 259 }
259 if (accessor.property_location_configuration & 260 if (location & V8DOMConfiguration::kOnPrototype &&
260 V8DOMConfiguration::kOnPrototype) { 261 !prototype_or_template.IsEmpty()) {
261 prototype_or_template->SetAccessorProperty( 262 prototype_or_template->SetAccessorProperty(
262 name, getter, setter, 263 name, getter, setter,
263 static_cast<v8::PropertyAttribute>(accessor.attribute)); 264 static_cast<v8::PropertyAttribute>(accessor.attribute));
264 } 265 }
265 } 266 }
266 if (accessor.property_location_configuration & 267 if (location & V8DOMConfiguration::kOnInterface &&
267 V8DOMConfiguration::kOnInterface) { 268 !interface_or_template.IsEmpty()) {
268 // Attributes installed on the interface object must be static 269 // Attributes installed on the interface object must be static
269 // attributes, so no need to specify a signature, i.e. no need to do 270 // attributes, so no need to specify a signature, i.e. no need to do
270 // type check against a holder. 271 // type check against a holder.
271 v8::Local<FunctionOrTemplate> getter = 272 v8::Local<FunctionOrTemplate> getter =
272 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( 273 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>(
273 isolate, getter_callback, nullptr, data, v8::Local<v8::Signature>(), 274 isolate, getter_callback, nullptr, data, v8::Local<v8::Signature>(),
274 0); 275 0);
275 v8::Local<FunctionOrTemplate> setter = 276 v8::Local<FunctionOrTemplate> setter =
276 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( 277 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>(
277 isolate, setter_callback, nullptr, data, v8::Local<v8::Signature>(), 278 isolate, setter_callback, nullptr, data, v8::Local<v8::Signature>(),
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 v8::FunctionCallback callback = method.callback; 431 v8::FunctionCallback callback = method.callback;
431 // Promise-returning functions need to return a reject promise when 432 // Promise-returning functions need to return a reject promise when
432 // an exception occurs. This includes a case that the receiver object is not 433 // an exception occurs. This includes a case that the receiver object is not
433 // of the type. So, we disable the type check of the receiver object on V8 434 // of the type. So, we disable the type check of the receiver object on V8
434 // side so that V8 won't throw. Instead, we do the check on Blink side and 435 // side so that V8 won't throw. Instead, we do the check on Blink side and
435 // convert an exception to a reject promise. 436 // convert an exception to a reject promise.
436 if (method.holder_check_configuration == 437 if (method.holder_check_configuration ==
437 V8DOMConfiguration::kDoNotCheckHolder) 438 V8DOMConfiguration::kDoNotCheckHolder)
438 signature = v8::Local<v8::Signature>(); 439 signature = v8::Local<v8::Signature>();
439 440
440 DCHECK(method.property_location_configuration); 441 const unsigned location = method.property_location_configuration;
441 if (method.property_location_configuration & 442 DCHECK(location);
443 if (location &
442 (V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) { 444 (V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) {
443 v8::Local<v8::FunctionTemplate> function_template = 445 v8::Local<v8::FunctionTemplate> function_template =
444 v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), 446 v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(),
445 signature, method.length); 447 signature, method.length);
446 function_template->RemovePrototype(); 448 function_template->RemovePrototype();
447 if (method.access_check_configuration == V8DOMConfiguration::kCheckAccess) 449 if (method.access_check_configuration == V8DOMConfiguration::kCheckAccess)
448 function_template->SetAcceptAnyReceiver(false); 450 function_template->SetAcceptAnyReceiver(false);
449 v8::Local<v8::Function> function = 451 v8::Local<v8::Function> function =
450 function_template->GetFunction(isolate->GetCurrentContext()) 452 function_template->GetFunction(isolate->GetCurrentContext())
451 .ToLocalChecked(); 453 .ToLocalChecked();
452 if (method.property_location_configuration & 454 if (location & V8DOMConfiguration::kOnInstance && !instance.IsEmpty()) {
453 V8DOMConfiguration::kOnInstance)
454 instance 455 instance
455 ->DefineOwnProperty( 456 ->DefineOwnProperty(
456 isolate->GetCurrentContext(), name, function, 457 isolate->GetCurrentContext(), name, function,
457 static_cast<v8::PropertyAttribute>(method.attribute)) 458 static_cast<v8::PropertyAttribute>(method.attribute))
458 .ToChecked(); 459 .ToChecked();
459 if (method.property_location_configuration & 460 }
460 V8DOMConfiguration::kOnPrototype) 461 if (location & V8DOMConfiguration::kOnPrototype && !prototype.IsEmpty()) {
461 prototype 462 prototype
462 ->DefineOwnProperty( 463 ->DefineOwnProperty(
463 isolate->GetCurrentContext(), name, function, 464 isolate->GetCurrentContext(), name, function,
464 static_cast<v8::PropertyAttribute>(method.attribute)) 465 static_cast<v8::PropertyAttribute>(method.attribute))
465 .ToChecked(); 466 .ToChecked();
467 }
466 } 468 }
467 if (method.property_location_configuration & 469 if (location & V8DOMConfiguration::kOnInterface && !interface.IsEmpty()) {
468 V8DOMConfiguration::kOnInterface) {
469 // Operations installed on the interface object must be static 470 // Operations installed on the interface object must be static
470 // operations, so no need to specify a signature, i.e. no need to do 471 // operations, so no need to specify a signature, i.e. no need to do
471 // type check against a holder. 472 // type check against a holder.
472 v8::Local<v8::FunctionTemplate> function_template = 473 v8::Local<v8::FunctionTemplate> function_template =
473 v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), 474 v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(),
474 v8::Local<v8::Signature>(), method.length); 475 v8::Local<v8::Signature>(), method.length);
475 function_template->RemovePrototype(); 476 function_template->RemovePrototype();
476 v8::Local<v8::Function> function = 477 v8::Local<v8::Function> function =
477 function_template->GetFunction(isolate->GetCurrentContext()) 478 function_template->GetFunction(isolate->GetCurrentContext())
478 .ToLocalChecked(); 479 .ToLocalChecked();
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 prototype_template->SetInternalFieldCount(kV8PrototypeInternalFieldcount); 724 prototype_template->SetInternalFieldCount(kV8PrototypeInternalFieldcount);
724 } 725 }
725 } 726 }
726 727
727 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::DomClassTemplate( 728 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::DomClassTemplate(
728 v8::Isolate* isolate, 729 v8::Isolate* isolate,
729 const DOMWrapperWorld& world, 730 const DOMWrapperWorld& world,
730 WrapperTypeInfo* wrapper_type_info, 731 WrapperTypeInfo* wrapper_type_info,
731 InstallTemplateFunction configure_dom_class_template) { 732 InstallTemplateFunction configure_dom_class_template) {
732 V8PerIsolateData* data = V8PerIsolateData::From(isolate); 733 V8PerIsolateData* data = V8PerIsolateData::From(isolate);
733 v8::Local<v8::FunctionTemplate> result = 734 v8::Local<v8::FunctionTemplate> interface_template =
734 data->FindInterfaceTemplate(world, wrapper_type_info); 735 data->FindInterfaceTemplate(world, wrapper_type_info);
735 if (!result.IsEmpty()) 736 if (!interface_template.IsEmpty())
736 return result; 737 return interface_template;
737 738
738 result = v8::FunctionTemplate::New( 739 interface_template = v8::FunctionTemplate::New(
739 isolate, V8ObjectConstructor::IsValidConstructorMode); 740 isolate, V8ObjectConstructor::IsValidConstructorMode);
740 configure_dom_class_template(isolate, world, result); 741 configure_dom_class_template(isolate, world, interface_template);
741 data->SetInterfaceTemplate(world, wrapper_type_info, result); 742 data->SetInterfaceTemplate(world, wrapper_type_info, interface_template);
742 return result; 743 return interface_template;
743 } 744 }
744 745
745 void V8DOMConfiguration::SetClassString( 746 void V8DOMConfiguration::SetClassString(
746 v8::Isolate* isolate, 747 v8::Isolate* isolate,
747 v8::Local<v8::ObjectTemplate> object_template, 748 v8::Local<v8::ObjectTemplate> object_template,
748 const char* class_string) { 749 const char* class_string) {
749 object_template->Set( 750 object_template->Set(
750 v8::Symbol::GetToStringTag(isolate), 751 v8::Symbol::GetToStringTag(isolate),
751 V8AtomicString(isolate, class_string), 752 V8AtomicString(isolate, class_string),
752 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); 753 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum));
753 } 754 }
754 755
755 } // namespace blink 756 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698