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

Unified Diff: third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl

Issue 2647643002: Fix V8 bindings for named constructors to set prototype object correctly (Closed)
Patch Set: Review feedback Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl
diff --git a/third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl b/third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl
index 9e0e34b4c0b90182edec736c3baa2777d8d7907b..25a7a0411da11851aa28fffec8261c970344edbf 100644
--- a/third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl
+++ b/third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl
@@ -557,6 +557,35 @@ v8::Local<v8::FunctionTemplate> {{v8_class}}Constructor::domTemplate(v8::Isolate
return result;
}
+void {{v8_class}}Constructor::NamedConstructorAttributeGetter(
+ v8::Local<v8::Name> propertyName,
+ const v8::PropertyCallbackInfo<v8::Value>& info) {
+ v8::Local<v8::Context> creationContext = info.Holder()->CreationContext();
+ V8PerContextData* perContextData = V8PerContextData::from(creationContext);
+ if (!perContextData) {
+ // TODO(yukishiino): Return a valid named constructor even after the context is detached
+ return;
+ }
+
+ v8::Local<v8::Function> namedConstructor = perContextData->constructorForType(&{{v8_class}}Constructor::wrapperTypeInfo);
+
+ // Set the prototype of named constructors to the regular constructor.
+ auto privateProperty = V8PrivateProperty::getNamedConstructorInitialized(info.GetIsolate());
+ v8::Local<v8::Context> currentContext = info.GetIsolate()->GetCurrentContext();
+ v8::Local<v8::Value> privateValue = privateProperty.get(currentContext, namedConstructor);
+
+ if (privateValue.IsEmpty()) {
+ v8::Local<v8::Function> interface = perContextData->constructorForType(&{{v8_class}}::wrapperTypeInfo);
+ v8::Local<v8::Value> interfacePrototype = interface->Get(currentContext, v8AtomicString(info.GetIsolate(), "prototype")).ToLocalChecked();
+ bool result = namedConstructor->Set(currentContext, v8AtomicString(info.GetIsolate(), "prototype"), interfacePrototype).ToChecked();
+ if (!result)
+ return;
+ privateProperty.set(currentContext, namedConstructor, v8::True(info.GetIsolate()));
+ }
+
+ v8SetReturnValue(info, namedConstructor);
+}
+
{% endif %}
{% endblock %}

Powered by Google App Engine
This is Rietveld 408576698