| 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 v8::Local<v8::FunctionTemplate> {{v8_class}}Constructor::domTemplate(v8::Isolate
* isolate, const DOMWrapperWorld& world) { | 541 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. | 542 static int domTemplateKey; // This address is used for a key to look up the do
m template. |
| 543 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | 543 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
| 544 v8::Local<v8::FunctionTemplate> result = data->findInterfaceTemplate(world, &d
omTemplateKey); | 544 v8::Local<v8::FunctionTemplate> result = data->findInterfaceTemplate(world, &d
omTemplateKey); |
| 545 if (!result.IsEmpty()) | 545 if (!result.IsEmpty()) |
| 546 return result; | 546 return result; |
| 547 | 547 |
| 548 result = v8::FunctionTemplate::New(isolate, {{v8_class}}ConstructorCallback); | 548 result = v8::FunctionTemplate::New(isolate, {{v8_class}}ConstructorCallback); |
| 549 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate(); | 549 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate(); |
| 550 instanceTemplate->SetInternalFieldCount({{v8_class}}::internalFieldCount); | 550 instanceTemplate->SetInternalFieldCount({{v8_class}}::internalFieldCount); |
| 551 result->SetClassName(v8AtomicString(isolate, "{{cpp_class}}")); | 551 result->SetClassName(v8AtomicString(isolate, "{{named_constructor.name}}")); |
| 552 result->Inherit({{v8_class}}::domTemplate(isolate, world)); | 552 result->Inherit({{v8_class}}::domTemplate(isolate, world)); |
| 553 data->setInterfaceTemplate(world, &domTemplateKey, result); | 553 data->setInterfaceTemplate(world, &domTemplateKey, result); |
| 554 return result; | 554 return result; |
| 555 } | 555 } |
| 556 | 556 |
| 557 void {{v8_class}}Constructor::NamedConstructorAttributeGetter( |
| 558 v8::Local<v8::Name> propertyName, |
| 559 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 560 v8::Local<v8::Value> data = info.Data(); |
| 561 DCHECK(data->IsExternal()); |
| 562 V8PerContextData* perContextData = |
| 563 V8PerContextData::from(info.Holder()->CreationContext()); |
| 564 if (!perContextData) |
| 565 return; |
| 566 |
| 567 v8::Local<v8::Function> namedConstructor = perContextData->constructorForType(
&{{v8_class}}Constructor::wrapperTypeInfo); |
| 568 v8::Local<v8::Function> interface = perContextData->constructorForType(&{{v8_c
lass}}::wrapperTypeInfo); |
| 569 |
| 570 // Set the prototype of named constructors to the regular constructor. |
| 571 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); |
| 572 auto privateProperty = V8PrivateProperty::getNamedConstructorInitialized(info.
GetIsolate()); |
| 573 v8::Local<v8::Value> privateValue = privateProperty.get(context, namedConstruc
tor); |
| 574 if (privateValue.IsEmpty()) { |
| 575 // Only Window exposes named constructors, so that will always be the interf
ace name. |
| 576 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::GetterConte
xt, "Window", "{{named_constructor.name}}"); |
| 577 v8::MaybeLocal<v8::Value> interfacePrototype = interface->Get(context, v8Ato
micString(info.GetIsolate(), "prototype")); |
| 578 if (interfacePrototype.IsEmpty()) { |
| 579 exceptionState.throwTypeError("Could not get prototype for {{v8_class}}.")
; |
| 580 return; |
| 581 } |
| 582 |
| 583 v8::Maybe<bool> setResult = namedConstructor->Set(context, v8AtomicString(in
fo.GetIsolate(), "prototype"), interfacePrototype.ToLocalChecked()); |
| 584 if (setResult.IsNothing() || setResult.ToChecked() != true) { |
| 585 exceptionState.throwTypeError("Could not set prototype for {{named_constru
ctor.name}}."); |
| 586 return; |
| 587 } |
| 588 |
| 589 privateProperty.set(context, namedConstructor, v8::True(info.GetIsolate())); |
| 590 } |
| 591 |
| 592 v8SetReturnValue(info, namedConstructor); |
| 593 } |
| 594 |
| 557 {% endif %} | 595 {% endif %} |
| 558 {% endblock %} | 596 {% endblock %} |
| 559 | 597 |
| 560 {##############################################################################} | 598 {##############################################################################} |
| 561 {% block overloaded_constructor %} | 599 {% block overloaded_constructor %} |
| 562 {% if constructor_overloads %} | 600 {% if constructor_overloads %} |
| 563 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) { | 601 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 564 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionC
ontext, "{{interface_name}}"); | 602 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionC
ontext, "{{interface_name}}"); |
| 565 {# 2. Initialize argcount to be min(maxarg, n). #} | 603 {# 2. Initialize argcount to be min(maxarg, n). #} |
| 566 switch (std::min({{constructor_overloads.maxarg}}, info.Length())) { | 604 switch (std::min({{constructor_overloads.maxarg}}, info.Length())) { |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 } | 994 } |
| 957 | 995 |
| 958 {% for method in methods if method.overloads and method.overloads.has_partial_ov
erloads %} | 996 {% 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>&)) { | 997 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; | 998 {{cpp_class}}V8Internal::{{method.name}}MethodForPartialInterface = method; |
| 961 } | 999 } |
| 962 | 1000 |
| 963 {% endfor %} | 1001 {% endfor %} |
| 964 {% endif %} | 1002 {% endif %} |
| 965 {% endblock %} | 1003 {% endblock %} |
| OLD | NEW |