Commit 040755ec authored by peria's avatar peria Committed by Commit bot

Use SetNativeDataProperty to install features dynamically on instances

This CL replace DefineOwnProperty with SetNativeDataProperty in
InstallAttributeInternal<v8::Object>() not to create function
templates or instances on feature installations.

This change enables us to use the function for all data properties
and it improves performance of preparing origin-trial features
and dynamic installs of runtime enabled features.

BUG=617892

Review-Url: https://codereview.chromium.org/2815453005
Cr-Commit-Position: refs/heads/master@{#467260}
parent 9e289b3d
...@@ -91,41 +91,33 @@ void InstallAttributeInternal( ...@@ -91,41 +91,33 @@ void InstallAttributeInternal(
v8::Isolate* isolate, v8::Isolate* isolate,
v8::Local<v8::Object> instance, v8::Local<v8::Object> instance,
v8::Local<v8::Object> prototype, v8::Local<v8::Object> prototype,
const V8DOMConfiguration::AttributeConfiguration& attribute, const V8DOMConfiguration::AttributeConfiguration& config,
const DOMWrapperWorld& world) { const DOMWrapperWorld& world) {
if (!WorldConfigurationApplies(attribute, world)) if (!WorldConfigurationApplies(config, world))
return; return;
v8::Local<v8::Name> name = V8AtomicString(isolate, attribute.name);
// This method is only being used for installing interfaces which are
// enabled through origin trials. Assert here that it is being called with
// an attribute configuration for a constructor.
// TODO(iclelland): Relax this constraint and allow arbitrary data-type
// properties to be added here.
DCHECK_EQ(&V8ConstructorAttributeGetter, attribute.getter);
V8PerContextData* per_context_data = v8::Local<v8::Name> name = V8AtomicString(isolate, config.name);
V8PerContextData::From(isolate->GetCurrentContext()); v8::AccessorNameGetterCallback getter = config.getter;
v8::Local<v8::Function> data = v8::AccessorNameSetterCallback setter = config.setter;
per_context_data->ConstructorForType(attribute.data); v8::Local<v8::Value> data =
v8::External::New(isolate, const_cast<WrapperTypeInfo*>(config.data));
v8::PropertyAttribute attribute =
static_cast<v8::PropertyAttribute>(config.attribute);
unsigned location = config.property_location_configuration;
DCHECK(attribute.property_location_configuration); DCHECK(location);
if (attribute.property_location_configuration & v8::Local<v8::Context> context = isolate->GetCurrentContext();
V8DOMConfiguration::kOnInstance) if (location & V8DOMConfiguration::kOnInstance) {
instance instance
->DefineOwnProperty( ->SetNativeDataProperty(context, name, getter, setter, data, attribute)
isolate->GetCurrentContext(), name, data,
static_cast<v8::PropertyAttribute>(attribute.attribute))
.ToChecked(); .ToChecked();
if (attribute.property_location_configuration & }
V8DOMConfiguration::kOnPrototype) if (location & V8DOMConfiguration::kOnPrototype) {
prototype prototype
->DefineOwnProperty( ->SetNativeDataProperty(context, name, getter, setter, data, attribute)
isolate->GetCurrentContext(), name, data,
static_cast<v8::PropertyAttribute>(attribute.attribute))
.ToChecked(); .ToChecked();
if (attribute.property_location_configuration & }
V8DOMConfiguration::kOnInterface) if (location & V8DOMConfiguration::kOnInterface)
NOTREACHED(); NOTREACHED();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment