OLD | NEW |
---|---|
1 {% extends 'interface_base.cpp.tmpl' %} | 1 {% extends 'interface_base.cpp.tmpl' %} |
2 | 2 |
3 {% set has_prepare_prototype_and_interface_object = | 3 {% set has_prepare_prototype_and_interface_object = |
4 unscopables or has_conditional_attributes_on_prototype or | 4 unscopables or has_conditional_attributes_on_prototype or |
5 methods | conditionally_exposed(is_partial) %} | 5 methods | conditionally_exposed(is_partial) %} |
6 {% set prepare_prototype_and_interface_object_func = | 6 {% set prepare_prototype_and_interface_object_func = |
7 '%s::preparePrototypeAndInterfaceObject' % v8_class | 7 '%s::preparePrototypeAndInterfaceObject' % v8_class |
8 if has_prepare_prototype_and_interface_object | 8 if has_prepare_prototype_and_interface_object |
9 else 'nullptr' %} | 9 else 'nullptr' %} |
10 | 10 |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 } | 515 } |
516 | 516 |
517 {% endif %} | 517 {% endif %} |
518 {% endblock %} | 518 {% endblock %} |
519 | 519 |
520 | 520 |
521 {##############################################################################} | 521 {##############################################################################} |
522 {% block named_constructor %} | 522 {% block named_constructor %} |
523 {% from 'methods.cpp.tmpl' import generate_constructor with context %} | 523 {% from 'methods.cpp.tmpl' import generate_constructor with context %} |
524 {% if named_constructor %} | 524 {% if named_constructor %} |
525 {% set parent_wrapper_type_info = '&V8%s::wrapperTypeInfo' % parent_interface | |
526 if parent_interface else '0' %} | |
525 {% set active_scriptwrappable_inheritance = | 527 {% set active_scriptwrappable_inheritance = |
526 'InheritFromActiveScriptWrappable' | 528 'InheritFromActiveScriptWrappable' |
527 if active_scriptwrappable else | 529 if active_scriptwrappable else |
528 'NotInheritFromActiveScriptWrappable' %} | 530 'NotInheritFromActiveScriptWrappable' %} |
529 // Suppress warning: global constructors, because struct WrapperTypeInfo is triv ial | 531 // Suppress warning: global constructors, because struct WrapperTypeInfo is triv ial |
530 // and does not depend on another global objects. | 532 // and does not depend on another global objects. |
531 #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) | 533 #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) |
532 #pragma clang diagnostic push | 534 #pragma clang diagnostic push |
533 #pragma clang diagnostic ignored "-Wglobal-constructors" | 535 #pragma clang diagnostic ignored "-Wglobal-constructors" |
534 #endif | 536 #endif |
535 const WrapperTypeInfo {{v8_class}}Constructor::wrapperTypeInfo = { gin::kEmbedde rBlink, {{v8_class}}Constructor::domTemplate, {{v8_class}}::trace, {{v8_class}}: :traceWrappers, 0, {{prepare_prototype_and_interface_object_func}}, "{{interface _name}}", 0, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::{{wra pper_class_id}}, WrapperTypeInfo::{{active_scriptwrappable_inheritance}}, Wrappe rTypeInfo::{{event_target_inheritance}}, WrapperTypeInfo::{{lifetime}} }; | 537 const WrapperTypeInfo {{v8_class}}Constructor::wrapperTypeInfo = { gin::kEmbedde rBlink, {{v8_class}}Constructor::domTemplate, {{v8_class}}::trace, {{v8_class}}: :traceWrappers, 0, {{prepare_prototype_and_interface_object_func}}, "{{interface _name}}", {{parent_wrapper_type_info}}, WrapperTypeInfo::WrapperTypeObjectProtot ype, WrapperTypeInfo::{{wrapper_class_id}}, WrapperTypeInfo::{{active_scriptwrap pable_inheritance}}, WrapperTypeInfo::{{event_target_inheritance}}, WrapperTypeI nfo::{{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.
| |
536 #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) | 538 #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) |
537 #pragma clang diagnostic pop | 539 #pragma clang diagnostic pop |
538 #endif | 540 #endif |
539 | 541 |
540 {{generate_constructor(named_constructor)}} | 542 {{generate_constructor(named_constructor)}} |
541 v8::Local<v8::FunctionTemplate> {{v8_class}}Constructor::domTemplate(v8::Isolate * isolate, const DOMWrapperWorld& world) { | 543 v8::Local<v8::FunctionTemplate> {{v8_class}}Constructor::domTemplate(v8::Isolate * isolate, const DOMWrapperWorld& world) { |
542 static int domTemplateKey; // This address is used for a key to look up the do m template. | 544 static int domTemplateKey; // This address is used for a key to look up the do m template. |
543 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 545 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
544 v8::Local<v8::FunctionTemplate> result = data->findInterfaceTemplate(world, &d omTemplateKey); | 546 v8::Local<v8::FunctionTemplate> result = data->findInterfaceTemplate(world, &d omTemplateKey); |
545 if (!result.IsEmpty()) | 547 if (!result.IsEmpty()) |
546 return result; | 548 return result; |
547 | 549 |
548 result = v8::FunctionTemplate::New(isolate, {{v8_class}}ConstructorCallback); | 550 result = v8::FunctionTemplate::New(isolate, {{v8_class}}ConstructorCallback); |
549 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate(); | 551 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate(); |
550 instanceTemplate->SetInternalFieldCount({{v8_class}}::internalFieldCount); | 552 instanceTemplate->SetInternalFieldCount({{v8_class}}::internalFieldCount); |
551 result->SetClassName(v8AtomicString(isolate, "{{cpp_class}}")); | 553 result->SetClassName(v8AtomicString(isolate, "{{named_constructor.name}}")); |
552 result->Inherit({{v8_class}}::domTemplate(isolate, world)); | 554 result->Inherit({{v8_class}}::domTemplate(isolate, world)); |
553 data->setInterfaceTemplate(world, &domTemplateKey, result); | 555 data->setInterfaceTemplate(world, &domTemplateKey, result); |
554 return result; | 556 return result; |
555 } | 557 } |
556 | 558 |
559 void {{v8_class}}Constructor::NamedConstructorAttributeGetter( | |
560 v8::Local<v8::Name> propertyName, | |
561 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
562 v8::Local<v8::Context> creationContext = info.Holder()->CreationContext(); | |
563 V8PerContextData* perContextData = V8PerContextData::from(creationContext); | |
Yuki
2017/01/26 07:08:53
This is okay that you're correctly using the *crea
| |
564 if (!perContextData) { | |
565 // TODO(yukishiino): Return a valid named constructor even after the context is detached | |
566 return; | |
567 } | |
568 | |
569 v8::Local<v8::Function> namedConstructor = perContextData->constructorForType( &{{v8_class}}Constructor::wrapperTypeInfo); | |
570 | |
571 // Set the prototype of named constructors to the regular constructor. | |
572 auto privateProperty = V8PrivateProperty::getNamedConstructorInitialized(info. GetIsolate()); | |
573 v8::Local<v8::Value> privateValue = privateProperty.get(creationContext, named Constructor); | |
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
| |
574 if (privateValue.IsEmpty()) { | |
575 v8::Local<v8::Function> interface = perContextData->constructorForType(&{{v8 _class}}::wrapperTypeInfo); | |
576 v8::Local<v8::Value> interfacePrototype = interface->Get(creationContext, v8 AtomicString(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.
| |
577 bool result = namedConstructor->Set(creationContext, v8AtomicString(info.Get Isolate(), "prototype"), interfacePrototype).ToChecked(); | |
578 if (!result) | |
579 return; | |
580 privateProperty.set(creationContext, namedConstructor, v8::True(info.GetIsol ate())); | |
Yuki
2017/01/26 07:08:53
This also should be currentContext instead of crea
sashab
2017/02/21 06:37:29
Done.
| |
581 } | |
582 | |
583 v8SetReturnValue(info, namedConstructor); | |
584 } | |
585 | |
557 {% endif %} | 586 {% endif %} |
558 {% endblock %} | 587 {% endblock %} |
559 | 588 |
560 {##############################################################################} | 589 {##############################################################################} |
561 {% block overloaded_constructor %} | 590 {% block overloaded_constructor %} |
562 {% if constructor_overloads %} | 591 {% if constructor_overloads %} |
563 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) { | 592 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) { |
564 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionC ontext, "{{interface_name}}"); | 593 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionC ontext, "{{interface_name}}"); |
565 {# 2. Initialize argcount to be min(maxarg, n). #} | 594 {# 2. Initialize argcount to be min(maxarg, n). #} |
566 switch (std::min({{constructor_overloads.maxarg}}, info.Length())) { | 595 switch (std::min({{constructor_overloads.maxarg}}, info.Length())) { |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
956 } | 985 } |
957 | 986 |
958 {% for method in methods if method.overloads and method.overloads.has_partial_ov erloads %} | 987 {% for method in methods if method.overloads and method.overloads.has_partial_ov erloads %} |
959 void {{v8_class}}::register{{method.name | blink_capitalize}}MethodForPartialInt erface(void (*method)(const v8::FunctionCallbackInfo<v8::Value>&)) { | 988 void {{v8_class}}::register{{method.name | blink_capitalize}}MethodForPartialInt erface(void (*method)(const v8::FunctionCallbackInfo<v8::Value>&)) { |
960 {{cpp_class}}V8Internal::{{method.name}}MethodForPartialInterface = method; | 989 {{cpp_class}}V8Internal::{{method.name}}MethodForPartialInterface = method; |
961 } | 990 } |
962 | 991 |
963 {% endfor %} | 992 {% endfor %} |
964 {% endif %} | 993 {% endif %} |
965 {% endblock %} | 994 {% endblock %} |
OLD | NEW |