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}} }; |
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> currentContext = info.Holder()->CreationContext(); | |
haraken
2017/01/25 03:37:16
currentContext => creationContext
sashab
2017/01/25 04:54:15
Done.
| |
563 V8PerContextData* perContextData = V8PerContextData::from(currentContext); | |
564 if (!perContextData) | |
haraken
2017/01/25 03:37:16
// TODO(yukishiino): Return a valid named construc
sashab
2017/01/25 04:54:15
Done :)
| |
565 return; | |
566 | |
567 v8::Local<v8::Function> namedConstructor = perContextData->constructorForType( &{{v8_class}}Constructor::wrapperTypeInfo); | |
568 | |
569 // Set the prototype of named constructors to the regular constructor. | |
570 auto privateProperty = V8PrivateProperty::getNamedConstructorInitialized(info. GetIsolate()); | |
571 v8::Local<v8::Value> privateValue = privateProperty.get(currentContext, namedC onstructor); | |
572 if (privateValue.IsEmpty()) { | |
573 v8::Local<v8::Function> interface = perContextData->constructorForType(&{{v8 _class}}::wrapperTypeInfo); | |
574 // Only Window exposes named constructors, so that will always be the interf ace name. | |
575 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::GetterConte xt, "Window", "{{named_constructor.name}}"); | |
576 v8::MaybeLocal<v8::Value> interfacePrototype = interface->Get(currentContext , v8AtomicString(info.GetIsolate(), "prototype")); | |
haraken
2017/01/25 03:37:16
We want to avoid using MaybeLocal. Also this Get s
sashab
2017/01/25 04:54:15
Sorry, did this locally but didn't upload it :/ Do
| |
577 if (interfacePrototype.IsEmpty()) { | |
578 exceptionState.throwTypeError("Could not get prototype for {{v8_class}}.") ; | |
579 return; | |
580 } | |
581 | |
582 v8::Maybe<bool> setResult = namedConstructor->Set(currentContext, v8AtomicSt ring(info.GetIsolate(), "prototype"), interfacePrototype.ToLocalChecked()); | |
haraken
2017/01/25 03:37:16
Ditto. Avoid using MaybeLocal. Also this Set shoul
sashab
2017/01/25 04:54:15
Done. Also removed exceptionContext and just retur
| |
583 if (setResult.IsNothing() || setResult.ToChecked() != true) { | |
584 exceptionState.throwTypeError("Could not set prototype for {{named_constru ctor.name}}."); | |
585 return; | |
586 } | |
587 | |
588 privateProperty.set(currentContext, namedConstructor, v8::True(info.GetIsola te())); | |
589 } | |
590 | |
591 v8SetReturnValue(info, namedConstructor); | |
592 } | |
593 | |
557 {% endif %} | 594 {% endif %} |
558 {% endblock %} | 595 {% endblock %} |
559 | 596 |
560 {##############################################################################} | 597 {##############################################################################} |
561 {% block overloaded_constructor %} | 598 {% block overloaded_constructor %} |
562 {% if constructor_overloads %} | 599 {% if constructor_overloads %} |
563 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) { | 600 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) { |
564 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionC ontext, "{{interface_name}}"); | 601 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionC ontext, "{{interface_name}}"); |
565 {# 2. Initialize argcount to be min(maxarg, n). #} | 602 {# 2. Initialize argcount to be min(maxarg, n). #} |
566 switch (std::min({{constructor_overloads.maxarg}}, info.Length())) { | 603 switch (std::min({{constructor_overloads.maxarg}}, info.Length())) { |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
956 } | 993 } |
957 | 994 |
958 {% for method in methods if method.overloads and method.overloads.has_partial_ov erloads %} | 995 {% 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>&)) { | 996 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; | 997 {{cpp_class}}V8Internal::{{method.name}}MethodForPartialInterface = method; |
961 } | 998 } |
962 | 999 |
963 {% endfor %} | 1000 {% endfor %} |
964 {% endif %} | 1001 {% endif %} |
965 {% endblock %} | 1002 {% endblock %} |
OLD | NEW |