Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 10 matching lines...) Expand all Loading... | |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "bindings/core/v8/V8DOMConfiguration.h" | 29 #include "bindings/core/v8/V8DOMConfiguration.h" |
| 30 | 30 |
| 31 #include "bindings/core/v8/V8SnapshotUtil.h" | |
| 31 #include "platform/bindings/V8ObjectConstructor.h" | 32 #include "platform/bindings/V8ObjectConstructor.h" |
| 32 #include "platform/bindings/V8PerContextData.h" | 33 #include "platform/bindings/V8PerContextData.h" |
| 33 #include "platform/instrumentation/tracing/TraceEvent.h" | 34 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 34 | 35 |
| 35 namespace blink { | 36 namespace blink { |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 template <class Configuration> | 40 template <class Configuration> |
| 40 bool WorldConfigurationApplies(const Configuration& config, | 41 bool WorldConfigurationApplies(const Configuration& config, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 v8::AccessorNameGetterCallback getter = config.getter; | 101 v8::AccessorNameGetterCallback getter = config.getter; |
| 101 v8::AccessorNameSetterCallback setter = config.setter; | 102 v8::AccessorNameSetterCallback setter = config.setter; |
| 102 v8::Local<v8::Value> data = | 103 v8::Local<v8::Value> data = |
| 103 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(config.data)); | 104 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(config.data)); |
| 104 v8::PropertyAttribute attribute = | 105 v8::PropertyAttribute attribute = |
| 105 static_cast<v8::PropertyAttribute>(config.attribute); | 106 static_cast<v8::PropertyAttribute>(config.attribute); |
| 106 unsigned location = config.property_location_configuration; | 107 unsigned location = config.property_location_configuration; |
| 107 | 108 |
| 108 DCHECK(location); | 109 DCHECK(location); |
| 109 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 110 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 110 if (location & V8DOMConfiguration::kOnInstance) { | 111 if (location & V8DOMConfiguration::kOnInstance && !instance.IsEmpty()) { |
| 111 instance | 112 instance |
| 112 ->SetNativeDataProperty(context, name, getter, setter, data, attribute) | 113 ->SetNativeDataProperty(context, name, getter, setter, data, attribute) |
| 113 .ToChecked(); | 114 .ToChecked(); |
| 114 } | 115 } |
| 115 if (location & V8DOMConfiguration::kOnPrototype) { | 116 if (location & V8DOMConfiguration::kOnPrototype && !prototype.IsEmpty()) { |
| 116 prototype | 117 prototype |
| 117 ->SetNativeDataProperty(context, name, getter, setter, data, attribute) | 118 ->SetNativeDataProperty(context, name, getter, setter, data, attribute) |
| 118 .ToChecked(); | 119 .ToChecked(); |
| 119 } | 120 } |
| 120 if (location & V8DOMConfiguration::kOnInterface) | 121 if (location & V8DOMConfiguration::kOnInterface) |
| 121 NOTREACHED(); | 122 NOTREACHED(); |
| 122 } | 123 } |
| 123 | 124 |
| 124 void InstallLazyDataAttributeInternal( | 125 void InstallLazyDataAttributeInternal( |
| 125 v8::Isolate* isolate, | 126 v8::Isolate* isolate, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 | 235 |
| 235 // Support [LenientThis] by not specifying the signature. V8 does not do | 236 // Support [LenientThis] by not specifying the signature. V8 does not do |
| 236 // the type checking against holder if no signature is specified. Note that | 237 // the type checking against holder if no signature is specified. Note that |
| 237 // info.Holder() passed to callbacks will be *unsafe*. | 238 // info.Holder() passed to callbacks will be *unsafe*. |
| 238 if (accessor.holder_check_configuration == | 239 if (accessor.holder_check_configuration == |
| 239 V8DOMConfiguration::kDoNotCheckHolder) | 240 V8DOMConfiguration::kDoNotCheckHolder) |
| 240 signature = v8::Local<v8::Signature>(); | 241 signature = v8::Local<v8::Signature>(); |
| 241 v8::Local<v8::Value> data = | 242 v8::Local<v8::Value> data = |
| 242 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)); | 243 v8::External::New(isolate, const_cast<WrapperTypeInfo*>(accessor.data)); |
| 243 | 244 |
| 244 DCHECK(accessor.property_location_configuration); | 245 const unsigned location = accessor.property_location_configuration; |
| 245 if (accessor.property_location_configuration & | 246 DCHECK(location); |
| 247 if (location & | |
| 246 (V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) { | 248 (V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) { |
| 247 v8::Local<FunctionOrTemplate> getter = | 249 v8::Local<FunctionOrTemplate> getter = |
| 248 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( | 250 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( |
| 249 isolate, getter_callback, cached_property_key, data, signature, 0); | 251 isolate, getter_callback, cached_property_key, data, signature, 0); |
| 250 v8::Local<FunctionOrTemplate> setter = | 252 v8::Local<FunctionOrTemplate> setter = |
| 251 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( | 253 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( |
| 252 isolate, setter_callback, nullptr, data, signature, 1); | 254 isolate, setter_callback, nullptr, data, signature, 1); |
| 253 if (accessor.property_location_configuration & | 255 if (location & V8DOMConfiguration::kOnInstance && |
| 254 V8DOMConfiguration::kOnInstance) { | 256 !instance_or_template.IsEmpty()) { |
| 255 instance_or_template->SetAccessorProperty( | 257 instance_or_template->SetAccessorProperty( |
| 256 name, getter, setter, | 258 name, getter, setter, |
| 257 static_cast<v8::PropertyAttribute>(accessor.attribute)); | 259 static_cast<v8::PropertyAttribute>(accessor.attribute)); |
| 258 } | 260 } |
| 259 if (accessor.property_location_configuration & | 261 if (location & V8DOMConfiguration::kOnPrototype && |
| 260 V8DOMConfiguration::kOnPrototype) { | 262 !prototype_or_template.IsEmpty()) { |
| 261 prototype_or_template->SetAccessorProperty( | 263 prototype_or_template->SetAccessorProperty( |
| 262 name, getter, setter, | 264 name, getter, setter, |
| 263 static_cast<v8::PropertyAttribute>(accessor.attribute)); | 265 static_cast<v8::PropertyAttribute>(accessor.attribute)); |
| 264 } | 266 } |
| 265 } | 267 } |
| 266 if (accessor.property_location_configuration & | 268 if (location & V8DOMConfiguration::kOnInterface && |
| 267 V8DOMConfiguration::kOnInterface) { | 269 !interface_or_template.IsEmpty()) { |
| 268 // Attributes installed on the interface object must be static | 270 // Attributes installed on the interface object must be static |
| 269 // attributes, so no need to specify a signature, i.e. no need to do | 271 // attributes, so no need to specify a signature, i.e. no need to do |
| 270 // type check against a holder. | 272 // type check against a holder. |
| 271 v8::Local<FunctionOrTemplate> getter = | 273 v8::Local<FunctionOrTemplate> getter = |
| 272 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( | 274 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( |
| 273 isolate, getter_callback, nullptr, data, v8::Local<v8::Signature>(), | 275 isolate, getter_callback, nullptr, data, v8::Local<v8::Signature>(), |
| 274 0); | 276 0); |
| 275 v8::Local<FunctionOrTemplate> setter = | 277 v8::Local<FunctionOrTemplate> setter = |
| 276 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( | 278 CreateAccessorFunctionOrTemplate<FunctionOrTemplate>( |
| 277 isolate, setter_callback, nullptr, data, v8::Local<v8::Signature>(), | 279 isolate, setter_callback, nullptr, data, v8::Local<v8::Signature>(), |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 v8::FunctionCallback callback = method.callback; | 432 v8::FunctionCallback callback = method.callback; |
| 431 // Promise-returning functions need to return a reject promise when | 433 // Promise-returning functions need to return a reject promise when |
| 432 // an exception occurs. This includes a case that the receiver object is not | 434 // 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 | 435 // 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 | 436 // side so that V8 won't throw. Instead, we do the check on Blink side and |
| 435 // convert an exception to a reject promise. | 437 // convert an exception to a reject promise. |
| 436 if (method.holder_check_configuration == | 438 if (method.holder_check_configuration == |
| 437 V8DOMConfiguration::kDoNotCheckHolder) | 439 V8DOMConfiguration::kDoNotCheckHolder) |
| 438 signature = v8::Local<v8::Signature>(); | 440 signature = v8::Local<v8::Signature>(); |
| 439 | 441 |
| 440 DCHECK(method.property_location_configuration); | 442 const unsigned location = method.property_location_configuration; |
| 441 if (method.property_location_configuration & | 443 DCHECK(location); |
| 444 if (location & | |
| 442 (V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) { | 445 (V8DOMConfiguration::kOnInstance | V8DOMConfiguration::kOnPrototype)) { |
| 443 v8::Local<v8::FunctionTemplate> function_template = | 446 v8::Local<v8::FunctionTemplate> function_template = |
| 444 v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), | 447 v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), |
| 445 signature, method.length); | 448 signature, method.length); |
| 446 function_template->RemovePrototype(); | 449 function_template->RemovePrototype(); |
| 447 if (method.access_check_configuration == V8DOMConfiguration::kCheckAccess) | 450 if (method.access_check_configuration == V8DOMConfiguration::kCheckAccess) |
| 448 function_template->SetAcceptAnyReceiver(false); | 451 function_template->SetAcceptAnyReceiver(false); |
| 449 v8::Local<v8::Function> function = | 452 v8::Local<v8::Function> function = |
| 450 function_template->GetFunction(isolate->GetCurrentContext()) | 453 function_template->GetFunction(isolate->GetCurrentContext()) |
| 451 .ToLocalChecked(); | 454 .ToLocalChecked(); |
| 452 if (method.property_location_configuration & | 455 if (location & V8DOMConfiguration::kOnInstance && !instance.IsEmpty()) { |
| 453 V8DOMConfiguration::kOnInstance) | |
| 454 instance | 456 instance |
| 455 ->DefineOwnProperty( | 457 ->DefineOwnProperty( |
| 456 isolate->GetCurrentContext(), name, function, | 458 isolate->GetCurrentContext(), name, function, |
| 457 static_cast<v8::PropertyAttribute>(method.attribute)) | 459 static_cast<v8::PropertyAttribute>(method.attribute)) |
| 458 .ToChecked(); | 460 .ToChecked(); |
| 459 if (method.property_location_configuration & | 461 } |
| 460 V8DOMConfiguration::kOnPrototype) | 462 if (location & V8DOMConfiguration::kOnPrototype && !prototype.IsEmpty()) { |
| 461 prototype | 463 prototype |
| 462 ->DefineOwnProperty( | 464 ->DefineOwnProperty( |
| 463 isolate->GetCurrentContext(), name, function, | 465 isolate->GetCurrentContext(), name, function, |
| 464 static_cast<v8::PropertyAttribute>(method.attribute)) | 466 static_cast<v8::PropertyAttribute>(method.attribute)) |
| 465 .ToChecked(); | 467 .ToChecked(); |
| 468 } | |
| 466 } | 469 } |
| 467 if (method.property_location_configuration & | 470 if (location & V8DOMConfiguration::kOnInterface && !interface.IsEmpty()) { |
| 468 V8DOMConfiguration::kOnInterface) { | |
| 469 // Operations installed on the interface object must be static | 471 // Operations installed on the interface object must be static |
| 470 // operations, so no need to specify a signature, i.e. no need to do | 472 // operations, so no need to specify a signature, i.e. no need to do |
| 471 // type check against a holder. | 473 // type check against a holder. |
| 472 v8::Local<v8::FunctionTemplate> function_template = | 474 v8::Local<v8::FunctionTemplate> function_template = |
| 473 v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), | 475 v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), |
| 474 v8::Local<v8::Signature>(), method.length); | 476 v8::Local<v8::Signature>(), method.length); |
| 475 function_template->RemovePrototype(); | 477 function_template->RemovePrototype(); |
| 476 v8::Local<v8::Function> function = | 478 v8::Local<v8::Function> function = |
| 477 function_template->GetFunction(isolate->GetCurrentContext()) | 479 function_template->GetFunction(isolate->GetCurrentContext()) |
| 478 .ToLocalChecked(); | 480 .ToLocalChecked(); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 723 prototype_template->SetInternalFieldCount(kV8PrototypeInternalFieldcount); | 725 prototype_template->SetInternalFieldCount(kV8PrototypeInternalFieldcount); |
| 724 } | 726 } |
| 725 } | 727 } |
| 726 | 728 |
| 727 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::DomClassTemplate( | 729 v8::Local<v8::FunctionTemplate> V8DOMConfiguration::DomClassTemplate( |
| 728 v8::Isolate* isolate, | 730 v8::Isolate* isolate, |
| 729 const DOMWrapperWorld& world, | 731 const DOMWrapperWorld& world, |
| 730 WrapperTypeInfo* wrapper_type_info, | 732 WrapperTypeInfo* wrapper_type_info, |
| 731 InstallTemplateFunction configure_dom_class_template) { | 733 InstallTemplateFunction configure_dom_class_template) { |
| 732 V8PerIsolateData* data = V8PerIsolateData::From(isolate); | 734 V8PerIsolateData* data = V8PerIsolateData::From(isolate); |
| 733 v8::Local<v8::FunctionTemplate> result = | 735 v8::Local<v8::FunctionTemplate> interface_template = |
| 734 data->FindInterfaceTemplate(world, wrapper_type_info); | 736 data->FindInterfaceTemplate(world, wrapper_type_info); |
| 735 if (!result.IsEmpty()) | 737 if (!interface_template.IsEmpty()) |
| 736 return result; | 738 return interface_template; |
| 737 | 739 |
| 738 result = v8::FunctionTemplate::New( | 740 interface_template = V8SnapshotUtil::InterfaceTemplateFromSnapshot( |
|
Yuki
2017/06/20 14:20:11
Do we really need this code?
V8SnapshotUtil::Ensur
peria
2017/06/21 07:19:16
Done.
| |
| 739 isolate, V8ObjectConstructor::IsValidConstructorMode); | 741 isolate, world, wrapper_type_info); |
| 740 configure_dom_class_template(isolate, world, result); | 742 |
| 741 data->SetInterfaceTemplate(world, wrapper_type_info, result); | 743 if (interface_template.IsEmpty()) { |
| 742 return result; | 744 interface_template = v8::FunctionTemplate::New( |
| 745 isolate, V8ObjectConstructor::IsValidConstructorMode); | |
| 746 configure_dom_class_template(isolate, world, interface_template); | |
| 747 } | |
| 748 data->SetInterfaceTemplate(world, wrapper_type_info, interface_template); | |
| 749 return interface_template; | |
| 743 } | 750 } |
| 744 | 751 |
| 745 void V8DOMConfiguration::SetClassString( | 752 void V8DOMConfiguration::SetClassString( |
| 746 v8::Isolate* isolate, | 753 v8::Isolate* isolate, |
| 747 v8::Local<v8::ObjectTemplate> object_template, | 754 v8::Local<v8::ObjectTemplate> object_template, |
| 748 const char* class_string) { | 755 const char* class_string) { |
| 749 object_template->Set( | 756 object_template->Set( |
| 750 v8::Symbol::GetToStringTag(isolate), | 757 v8::Symbol::GetToStringTag(isolate), |
| 751 V8AtomicString(isolate, class_string), | 758 V8AtomicString(isolate, class_string), |
| 752 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); | 759 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); |
| 753 } | 760 } |
| 754 | 761 |
| 755 } // namespace blink | 762 } // namespace blink |
| OLD | NEW |