| 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 1d1db395fd020fa5787c018aa58ca4b1322fc3e4..4f3629d8df3bc3d29b983b18b3a7bb780bc0f0aa 100644
|
| --- a/third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl
|
| +++ b/third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl
|
| @@ -548,12 +548,50 @@ 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::Value> data = info.Data();
|
| + DCHECK(data->IsExternal());
|
| + V8PerContextData* perContextData =
|
| + V8PerContextData::from(info.Holder()->CreationContext());
|
| + if (!perContextData)
|
| + return;
|
| +
|
| + v8::Local<v8::Function> namedConstructor = perContextData->constructorForType(&{{v8_class}}Constructor::wrapperTypeInfo);
|
| + v8::Local<v8::Function> interface = perContextData->constructorForType(&{{v8_class}}::wrapperTypeInfo);
|
| +
|
| + // Set the prototype of named constructors to the regular constructor.
|
| + v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
|
| + auto privateProperty = V8PrivateProperty::getNamedConstructorInitialized(info.GetIsolate());
|
| + v8::Local<v8::Value> privateValue = privateProperty.get(context, namedConstructor);
|
| + if (privateValue.IsEmpty()) {
|
| + // Only Window exposes named constructors, so that will always be the interface name.
|
| + ExceptionState exceptionState(info.GetIsolate(), ExceptionState::GetterContext, "Window", "{{named_constructor.name}}");
|
| + v8::MaybeLocal<v8::Value> interfacePrototype = interface->Get(context, v8AtomicString(info.GetIsolate(), "prototype"));
|
| + if (interfacePrototype.IsEmpty()) {
|
| + exceptionState.throwTypeError("Could not get prototype for {{v8_class}}.");
|
| + return;
|
| + }
|
| +
|
| + v8::Maybe<bool> setResult = namedConstructor->Set(context, v8AtomicString(info.GetIsolate(), "prototype"), interfacePrototype.ToLocalChecked());
|
| + if (setResult.IsNothing() || setResult.ToChecked() != true) {
|
| + exceptionState.throwTypeError("Could not set prototype for {{named_constructor.name}}.");
|
| + return;
|
| + }
|
| +
|
| + privateProperty.set(context, namedConstructor, v8::True(info.GetIsolate()));
|
| + }
|
| +
|
| + v8SetReturnValue(info, namedConstructor);
|
| +}
|
| +
|
| {% endif %}
|
| {% endblock %}
|
|
|
|
|