Chromium Code Reviews| 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 a7e7b2ecbddb5cbcc66f4c711f6351ebb845ecc9..213b41fe3825a301d2f267f17b863ad5aadf1668 100644 |
| --- a/third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl |
| +++ b/third_party/WebKit/Source/bindings/templates/interface.cpp.tmpl |
| @@ -522,6 +522,8 @@ static void {{cpp_class}}OriginSafeMethodSetter(v8::Local<v8::Name> name, v8::Lo |
| {% block named_constructor %} |
| {% from 'methods.cpp.tmpl' import generate_constructor with context %} |
| {% if named_constructor %} |
| +{% set parent_wrapper_type_info = '&V8%s::wrapperTypeInfo' % parent_interface |
| + if parent_interface else '0' %} |
| {% set active_scriptwrappable_inheritance = |
| 'InheritFromActiveScriptWrappable' |
| if active_scriptwrappable else |
| @@ -532,7 +534,7 @@ static void {{cpp_class}}OriginSafeMethodSetter(v8::Local<v8::Name> name, v8::Lo |
| #pragma clang diagnostic push |
| #pragma clang diagnostic ignored "-Wglobal-constructors" |
| #endif |
| -const WrapperTypeInfo {{v8_class}}Constructor::wrapperTypeInfo = { gin::kEmbedderBlink, {{v8_class}}Constructor::domTemplate, {{v8_class}}::trace, {{v8_class}}::traceWrappers, 0, {{prepare_prototype_and_interface_object_func}}, "{{interface_name}}", 0, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::{{wrapper_class_id}}, WrapperTypeInfo::{{active_scriptwrappable_inheritance}}, WrapperTypeInfo::{{event_target_inheritance}}, WrapperTypeInfo::{{lifetime}} }; |
| +const WrapperTypeInfo {{v8_class}}Constructor::wrapperTypeInfo = { gin::kEmbedderBlink, {{v8_class}}Constructor::domTemplate, {{v8_class}}::trace, {{v8_class}}::traceWrappers, 0, {{prepare_prototype_and_interface_object_func}}, "{{interface_name}}", {{parent_wrapper_type_info}}, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::{{wrapper_class_id}}, WrapperTypeInfo::{{active_scriptwrappable_inheritance}}, WrapperTypeInfo::{{event_target_inheritance}}, WrapperTypeInfo::{{lifetime}} }; |
|
Yuki
2017/01/26 07:42:26
I'm very sorry that I was wrong about this.
We sh
sashab
2017/02/21 06:37:29
No prob :) Done.
|
| #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) |
| #pragma clang diagnostic pop |
| #endif |
| @@ -548,12 +550,39 @@ 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); |
|
Yuki
2017/01/26 07:08:53
This is okay that you're correctly using the *crea
|
| + 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::Value> privateValue = privateProperty.get(creationContext, namedConstructor); |
|
Yuki
2017/01/26 07:08:53
It's quite confusing, but *current context* can be
haraken
2017/01/26 09:43:55
How can |creationContext| be different from |curre
Yuki
2017/01/26 10:07:11
Access to |anotherWindow.Image|, then you're in th
sashab
2017/02/21 06:37:29
I don't understand the conversation, but changed t
|
| + if (privateValue.IsEmpty()) { |
| + v8::Local<v8::Function> interface = perContextData->constructorForType(&{{v8_class}}::wrapperTypeInfo); |
| + v8::Local<v8::Value> interfacePrototype = interface->Get(creationContext, v8AtomicString(info.GetIsolate(), "prototype")).ToLocalChecked(); |
|
Yuki
2017/01/26 07:08:53
These interface-Get and namedConstructor-Set shoul
sashab
2017/02/21 06:37:29
Done.
|
| + bool result = namedConstructor->Set(creationContext, v8AtomicString(info.GetIsolate(), "prototype"), interfacePrototype).ToChecked(); |
| + if (!result) |
| + return; |
| + privateProperty.set(creationContext, namedConstructor, v8::True(info.GetIsolate())); |
|
Yuki
2017/01/26 07:08:53
This also should be currentContext instead of crea
sashab
2017/02/21 06:37:29
Done.
|
| + } |
| + |
| + v8SetReturnValue(info, namedConstructor); |
| +} |
| + |
| {% endif %} |
| {% endblock %} |