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 3d037f89185d9b6db639b90cccbfc117d0743919..9916135172fa078b40f439fa1cc4de9115cd307c 100644 |
--- a/third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl |
+++ b/third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl |
@@ -542,12 +542,41 @@ v8::Local<v8::FunctionTemplate> {{v8_class}}Constructor::domTemplate(v8::Isolate |
result = v8::FunctionTemplate::New(isolate, {{v8_class}}ConstructorCallback); |
v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate(); |
instanceTemplate->SetInternalFieldCount({{v8_class}}::internalFieldCount); |
- result->SetClassName(v8AtomicString(isolate, "{{cpp_class}}")); |
+ result->SetClassName(v8AtomicString(isolate, "{{named_constructor.name}}")); |
result->Inherit({{v8_class}}::domTemplate(isolate, world)); |
data->setInterfaceTemplate(world, &domTemplateKey, result); |
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 %} |