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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 v8::Local<v8::FunctionTemplate> {{v8_class}}Constructor::domTemplate(v8::Isolate * isolate, const DOMWrapperWorld& world) { | 544 v8::Local<v8::FunctionTemplate> {{v8_class}}Constructor::domTemplate(v8::Isolate * isolate, const DOMWrapperWorld& world) { |
545 static int domTemplateKey; // This address is used for a key to look up the do m template. | 545 static int domTemplateKey; // This address is used for a key to look up the do m template. |
546 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 546 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
547 v8::Local<v8::FunctionTemplate> result = data->findInterfaceTemplate(world, &d omTemplateKey); | 547 v8::Local<v8::FunctionTemplate> result = data->findInterfaceTemplate(world, &d omTemplateKey); |
548 if (!result.IsEmpty()) | 548 if (!result.IsEmpty()) |
549 return result; | 549 return result; |
550 | 550 |
551 result = v8::FunctionTemplate::New(isolate, {{v8_class}}ConstructorCallback); | 551 result = v8::FunctionTemplate::New(isolate, {{v8_class}}ConstructorCallback); |
552 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate(); | 552 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate(); |
553 instanceTemplate->SetInternalFieldCount({{v8_class}}::internalFieldCount); | 553 instanceTemplate->SetInternalFieldCount({{v8_class}}::internalFieldCount); |
554 result->SetClassName(v8AtomicString(isolate, "{{cpp_class}}")); | 554 result->SetClassName(v8AtomicString(isolate, "{{cpp_class}}")); |
Yuki
2017/02/23 06:26:10
You need to set the class name to "Image" instead
sashab
2017/02/24 03:06:13
Done! :) This fixes the problem.
| |
555 result->Inherit({{v8_class}}::domTemplate(isolate, world)); | 555 result->Inherit({{v8_class}}::domTemplate(isolate, world)); |
Yuki
2017/02/23 06:26:10
IIUC, now we don't need this line, because you set
sashab
2017/02/24 03:06:13
When I remove this I get the runtime error:
[7903
| |
556 data->setInterfaceTemplate(world, &domTemplateKey, result); | 556 data->setInterfaceTemplate(world, &domTemplateKey, result); |
557 return result; | 557 return result; |
558 } | 558 } |
559 | 559 |
560 void {{v8_class}}Constructor::NamedConstructorAttributeGetter( | |
561 v8::Local<v8::Name> propertyName, | |
562 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
563 v8::Local<v8::Context> creationContext = info.Holder()->CreationContext(); | |
564 V8PerContextData* perContextData = V8PerContextData::from(creationContext); | |
565 if (!perContextData) { | |
566 // TODO(yukishiino): Return a valid named constructor even after the context is detached | |
567 return; | |
568 } | |
569 | |
570 v8::Local<v8::Function> namedConstructor = perContextData->constructorForType( &{{v8_class}}Constructor::wrapperTypeInfo); | |
571 | |
572 // Set the prototype of named constructors to the regular constructor. | |
573 auto privateProperty = V8PrivateProperty::getNamedConstructorInitialized(info. GetIsolate()); | |
574 v8::Local<v8::Context> currentContext = info.GetIsolate()->GetCurrentContext() ; | |
575 v8::Local<v8::Value> privateValue = privateProperty.get(currentContext, namedC onstructor); | |
576 | |
577 if (privateValue.IsEmpty()) { | |
578 v8::Local<v8::Function> interface = perContextData->constructorForType(&{{v8 _class}}::wrapperTypeInfo); | |
579 v8::Local<v8::Value> interfacePrototype = interface->Get(currentContext, v8A tomicString(info.GetIsolate(), "prototype")).ToLocalChecked(); | |
580 bool result = namedConstructor->Set(currentContext, v8AtomicString(info.GetI solate(), "prototype"), interfacePrototype).ToChecked(); | |
581 if (!result) | |
582 return; | |
583 privateProperty.set(currentContext, namedConstructor, v8::True(info.GetIsola te())); | |
584 } | |
585 | |
586 v8SetReturnValue(info, namedConstructor); | |
587 } | |
588 | |
560 {% endif %} | 589 {% endif %} |
561 {% endblock %} | 590 {% endblock %} |
562 | 591 |
563 {##############################################################################} | 592 {##############################################################################} |
564 {% block overloaded_constructor %} | 593 {% block overloaded_constructor %} |
565 {% if constructor_overloads %} | 594 {% if constructor_overloads %} |
566 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) { | 595 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) { |
567 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionC ontext, "{{interface_name}}"); | 596 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionC ontext, "{{interface_name}}"); |
568 {# 2. Initialize argcount to be min(maxarg, n). #} | 597 {# 2. Initialize argcount to be min(maxarg, n). #} |
569 switch (std::min({{constructor_overloads.maxarg}}, info.Length())) { | 598 switch (std::min({{constructor_overloads.maxarg}}, info.Length())) { |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
892 } | 921 } |
893 | 922 |
894 {% for method in methods if method.overloads and method.overloads.has_partial_ov erloads %} | 923 {% for method in methods if method.overloads and method.overloads.has_partial_ov erloads %} |
895 void {{v8_class}}::register{{method.name | blink_capitalize}}MethodForPartialInt erface(void (*method)(const v8::FunctionCallbackInfo<v8::Value>&)) { | 924 void {{v8_class}}::register{{method.name | blink_capitalize}}MethodForPartialInt erface(void (*method)(const v8::FunctionCallbackInfo<v8::Value>&)) { |
896 {{cpp_class}}V8Internal::{{method.name}}MethodForPartialInterface = method; | 925 {{cpp_class}}V8Internal::{{method.name}}MethodForPartialInterface = method; |
897 } | 926 } |
898 | 927 |
899 {% endfor %} | 928 {% endfor %} |
900 {% endif %} | 929 {% endif %} |
901 {% endblock %} | 930 {% endblock %} |
OLD | NEW |