Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: third_party/WebKit/Source/bindings/templates/interface_base.cpp

Issue 1758113003: bindings: Makes not call installDOMClassTemplate twice for the same interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 {% include 'copyright_block.txt' %} 1 {% include 'copyright_block.txt' %}
2 #include "{{v8_class_or_partial}}.h" 2 #include "{{v8_class_or_partial}}.h"
3 3
4 {% for filename in cpp_includes if filename != '%s.h' % cpp_class_or_partial %} 4 {% for filename in cpp_includes if filename != '%s.h' % cpp_class_or_partial %}
5 #include "{{filename}}" 5 #include "{{filename}}"
6 {% endfor %} 6 {% endfor %}
7 7
8 namespace blink { 8 namespace blink {
9 {% set visit_dom_wrapper = '%s::visitDOMWrapper' % v8_class 9 {% set visit_dom_wrapper = '%s::visitDOMWrapper' % v8_class
10 if has_visit_dom_wrapper else '0' %} 10 if has_visit_dom_wrapper else '0' %}
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 {##############################################################################} 261 {##############################################################################}
262 {% block named_constructor %}{% endblock %} 262 {% block named_constructor %}{% endblock %}
263 {% block constructor_callback %}{% endblock %} 263 {% block constructor_callback %}{% endblock %}
264 {##############################################################################} 264 {##############################################################################}
265 {% block install_dom_template %} 265 {% block install_dom_template %}
266 {% if not is_array_buffer_or_view %} 266 {% if not is_array_buffer_or_view %}
267 {% from 'methods.cpp' import install_custom_signature with context %} 267 {% from 'methods.cpp' import install_custom_signature with context %}
268 {% from 'attributes.cpp' import attribute_configuration with context %} 268 {% from 'attributes.cpp' import attribute_configuration with context %}
269 {% from 'constants.cpp' import install_constants with context %} 269 {% from 'constants.cpp' import install_constants with context %}
270 {% if has_partial_interface or is_partial %} 270 {% if has_partial_interface or is_partial %}
271 void {{v8_class_or_partial}}::install{{v8_class}}Template(v8::Local<v8::Function Template> functionTemplate, v8::Isolate* isolate) 271 void {{v8_class_or_partial}}::install{{v8_class}}Template(v8::Local<v8::Function Template> interfaceTemplate, v8::Isolate* isolate)
272 {% else %} 272 {% else %}
273 static void install{{v8_class}}Template(v8::Local<v8::FunctionTemplate> function Template, v8::Isolate* isolate) 273 static void install{{v8_class}}Template(v8::Local<v8::FunctionTemplate> interfac eTemplate, v8::Isolate* isolate)
274 {% endif %} 274 {% endif %}
275 { 275 {
276 {% set newline = '' %}
277 // Initialize the interface object's template.
276 {% if is_partial %} 278 {% if is_partial %}
277 {{v8_class}}::install{{v8_class}}Template(functionTemplate, isolate); 279 {{v8_class}}::install{{v8_class}}Template(interfaceTemplate, isolate);
278 {% else %} 280 {% else %}
279 functionTemplate->ReadOnlyPrototype(); 281 {% set parent_interface_template =
280 {% endif %}
281
282 v8::Local<v8::Signature> defaultSignature;
283 {% set parent_template =
284 '%s::domTemplateForNamedPropertiesObject(isolate)' % v8_class 282 '%s::domTemplateForNamedPropertiesObject(isolate)' % v8_class
285 if has_named_properties_object else 283 if has_named_properties_object else
286 'V8%s::domTemplate(isolate)' % parent_interface 284 'V8%s::domTemplate(isolate)' % parent_interface
287 if parent_interface else 'v8::Local<v8::FunctionTemplate>()' %} 285 if parent_interface else
286 'v8::Local<v8::FunctionTemplate>()' %}
287 V8DOMConfiguration::initializeDOMInterfaceTemplate(isolate, interfaceTemplat e, {{v8_class}}::wrapperTypeInfo.interfaceName, {{parent_interface_template}}, { {v8_class}}::internalFieldCount);
288 {% if constructors or has_custom_constructor or has_event_constructor %}
289 interfaceTemplate->SetCallHandler({{v8_class}}::constructorCallback);
290 interfaceTemplate->SetLength({{interface_length}});
291 {% endif %}
292 {% endif %}{# is_partial #}
293 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTe mplate);
294 ALLOW_UNUSED_LOCAL(signature);
295 v8::Local<v8::ObjectTemplate> instanceTemplate = interfaceTemplate->Instance Template();
296 ALLOW_UNUSED_LOCAL(instanceTemplate);
297 v8::Local<v8::ObjectTemplate> prototypeTemplate = interfaceTemplate->Prototy peTemplate();
298 ALLOW_UNUSED_LOCAL(prototypeTemplate);
299
300 {%- if not is_partial %}
301 {% if interface_name == 'Window' %}{{newline}}
302 prototypeTemplate->SetInternalFieldCount(V8Window::internalFieldCount);
303 {% endif %}
304 {% if is_global or interface_name == 'HTMLDocument' %}{{newline}}
305 interfaceTemplate->SetHiddenPrototype(true);
306 {% endif %}
307 {% endif %}
308
309 // Register DOM constants, attributes and operations.
288 {% if runtime_enabled_function %} 310 {% if runtime_enabled_function %}
289 if (!{{runtime_enabled_function}}()) 311 if ({{runtime_enabled_function}}()) {
290 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(isolate, functionTemplate, {{v8_class}}::wrapperTypeInfo.interfaceName, {{parent_template }}, {{v8_class}}::internalFieldCount, 0, 0, 0, 0, 0, 0);
291 else
292 {% endif %} 312 {% endif %}
293 {% set runtime_enabled_indent = 4 if runtime_enabled_function else 0 %} 313 {% filter indent(4 if runtime_enabled_function else 0, true) %}
294 {% filter indent(runtime_enabled_indent, true) %} 314 {% if constants %}
295 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(isolate, func tionTemplate, {{v8_class}}::wrapperTypeInfo.interfaceName, {{parent_template}}, {{v8_class}}::internalFieldCount, 315 {{install_constants() | indent}}
296 {# Test needed as size 0 arrays definitions are not allowed per standard 316 {% endif %}
297 (so objects have distinct addresses), which is enforced by MSVC. 317 {% if has_attribute_configuration %}
298 8.5.1 Aggregates [dcl.init.aggr] 318 V8DOMConfiguration::installAttributes(isolate, instanceTemplate, prototypeTe mplate, {{'%sAttributes' % v8_class}}, {{'WTF_ARRAY_LENGTH(%sAttributes)' % v8_c lass}});
299 An array of unknown size initialized with a brace-enclosed 319 {% endif %}
300 initializer-list containing n initializer-clauses, where n shall be 320 {% if has_accessor_configuration %}
301 greater than zero, is defined as having n elements (8.3.4). #} 321 V8DOMConfiguration::installAccessors(isolate, instanceTemplate, prototypeTem plate, interfaceTemplate, signature, {{'%sAccessors' % v8_class}}, {{'WTF_ARRAY_ LENGTH(%sAccessors)' % v8_class}});
302 {% set attributes_name, attributes_length = 322 {% endif %}
303 ('%sAttributes' % v8_class, 323 {% if method_configuration_methods %}
304 'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class) 324 V8DOMConfiguration::installMethods(isolate, instanceTemplate, prototypeTempl ate, interfaceTemplate, signature, {{'%sMethods' % v8_class}}, {{'WTF_ARRAY_LENG TH(%sMethods)' % v8_class}});
305 if has_attribute_configuration else (0, 0) %} 325 {% endif %}
306 {% set accessors_name, accessors_length = 326 {% endfilter %}{{newline}}
307 ('%sAccessors' % v8_class, 327 {% if runtime_enabled_function %}
308 'WTF_ARRAY_LENGTH(%sAccessors)' % v8_class) 328 } // if ({{runtime_enabled_function}}())
309 if has_accessor_configuration else (0, 0) %} 329 {% endif %}
310 {% set methods_name, methods_length =
311 ('%sMethods' % v8_class,
312 'WTF_ARRAY_LENGTH(%sMethods)' % v8_class)
313 if method_configuration_methods else (0, 0) %}
314 {{attributes_name}}, {{attributes_length}},
315 {{accessors_name}}, {{accessors_length}},
316 {{methods_name}}, {{methods_length}});
317 {% endfilter %}
318 330
319 {% if constructors or has_custom_constructor or has_event_constructor %} 331 {%- if has_access_check_callbacks %}{{newline}}
320 functionTemplate->SetCallHandler({{v8_class}}::constructorCallback); 332 // Cross-origin access check
321 functionTemplate->SetLength({{interface_length}});
322 {% endif %}
323 v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceT emplate();
324 ALLOW_UNUSED_LOCAL(instanceTemplate);
325 v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->Prototyp eTemplate();
326 ALLOW_UNUSED_LOCAL(prototypeTemplate);
327 {% if not is_partial %}
328 {# TODO(yukishiino): We should set the class string to the platform object
329 (|instanceTemplate|), too. The reason that we don\'t set it is that
330 it prevents minor GC to collect unreachable DOM objects (a layout test
331 fast/dom/minor-dom-gc.html fails if we set the class string).
332 See also http://heycam.github.io/webidl/#es-platform-objects #}
333 V8DOMConfiguration::setClassString(isolate, prototypeTemplate, {{v8_class}}: :wrapperTypeInfo.interfaceName);
334 {% endif %}
335 {% if custom_registration_methods %}
336 ExecutionContext* context = currentExecutionContext(isolate);
337 ALLOW_UNUSED_LOCAL(context);
338 {% endif %}
339 {% if has_access_check_callbacks %}
340 instanceTemplate->SetAccessCheckCallback({{cpp_class}}V8Internal::securityCh eck, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&{{v8_class}}::wrap perTypeInfo))); 333 instanceTemplate->SetAccessCheckCallback({{cpp_class}}V8Internal::securityCh eck, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&{{v8_class}}::wrap perTypeInfo)));
341 {% endif %} 334 {% endif %}
342 {% if has_array_iterator %} 335
336 {%- if has_array_iterator %}{{newline}}
337 // Array iterator
343 {% filter runtime_enabled('RuntimeEnabledFeatures::iterableCollectionsEnable d') %} 338 {% filter runtime_enabled('RuntimeEnabledFeatures::iterableCollectionsEnable d') %}
344 {% if is_global %} 339 {% if is_global %}
345 instanceTemplate->SetIntrinsicDataProperty(v8::Symbol::GetIterator(isolate), v8::kArrayProto_values, v8::DontEnum); 340 instanceTemplate->SetIntrinsicDataProperty(v8::Symbol::GetIterator(isolate), v8::kArrayProto_values, v8::DontEnum);
346 {% else %} 341 {% else %}
347 prototypeTemplate->SetIntrinsicDataProperty(v8::Symbol::GetIterator(isolate) , v8::kArrayProto_values, v8::DontEnum); 342 prototypeTemplate->SetIntrinsicDataProperty(v8::Symbol::GetIterator(isolate) , v8::kArrayProto_values, v8::DontEnum);
348 {% endif %} 343 {% endif %}
349 {% endfilter %}{# runtime_enabled() #} 344 {% endfilter %}
350 {% endif %} 345 {% endif %}
351 {% set runtime_enabled_features = dict() %} 346
347 {%- set runtime_enabled_features = dict() %}
352 {% for attribute in attributes 348 {% for attribute in attributes
353 if attribute.runtime_enabled_function and 349 if attribute.runtime_enabled_function and
354 not attribute.exposed_test %} 350 not attribute.exposed_test %}
355 {% if attribute.runtime_enabled_function not in runtime_enabled_features %} 351 {% if attribute.runtime_enabled_function not in runtime_enabled_features %}
356 {% set unused = runtime_enabled_features.update({attribute.runtime_e nabled_function: []}) %} 352 {% set unused = runtime_enabled_features.update({attribute.runtime_e nabled_function: []}) %}
357 {% endif %} 353 {% endif %}
358 {% set unused = runtime_enabled_features.get(attribute.runtime_enabled_f unction).append(attribute) %} 354 {% set unused = runtime_enabled_features.get(attribute.runtime_enabled_f unction).append(attribute) %}
359 {% endfor %} 355 {% endfor %}
360 {% for runtime_enabled_feature in runtime_enabled_features | sort %} 356 {% for runtime_enabled_feature in runtime_enabled_features | sort %}{{newlin e}}
361 if ({{runtime_enabled_feature}}()) { 357 if ({{runtime_enabled_feature}}()) {
362 {% set distinct_attributes = [] %} 358 {% set distinct_attributes = [] %}
363 {% for attribute in runtime_enabled_features.get(runtime_enabled_feature ) | sort 359 {% for attribute in runtime_enabled_features.get(runtime_enabled_feature ) | sort
364 if attribute.name not in distinct_attributes %} 360 if attribute.name not in distinct_attributes %}
365 {% set unused = distinct_attributes.append(attribute.name) %} 361 {% set unused = distinct_attributes.append(attribute.name) %}
366 {% if attribute.is_data_type_property %} 362 {% if attribute.is_data_type_property %}
367 const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.na me}}Configuration = \ 363 const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.na me}}Configuration = \
368 {{attribute_configuration(attribute)}}; 364 {{attribute_configuration(attribute)}};
369 V8DOMConfiguration::installAttribute(isolate, instanceTemplate, prototyp eTemplate, attribute{{attribute.name}}Configuration); 365 V8DOMConfiguration::installAttribute(isolate, instanceTemplate, prototyp eTemplate, attribute{{attribute.name}}Configuration);
370 {% else %} 366 {% else %}
371 const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.name }}Configuration = \ 367 const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.name }}Configuration = \
372 {{attribute_configuration(attribute)}}; 368 {{attribute_configuration(attribute)}};
373 V8DOMConfiguration::installAccessor(isolate, instanceTemplate, prototype Template, functionTemplate, defaultSignature, accessor{{attribute.name}}Configur ation); 369 V8DOMConfiguration::installAccessor(isolate, instanceTemplate, prototype Template, interfaceTemplate, signature, accessor{{attribute.name}}Configuration) ;
374 {% endif %} 370 {% endif %}
375 {% endfor %} 371 {% endfor %}
376 } 372 }
377 {% endfor %} 373 {% endfor %}
378 {% if constants %} 374
379 {{install_constants() | indent}} 375 {%- if indexed_property_getter %}{{newline}}
380 {% endif %} 376 // Indexed properties
381 {# Special operations #}
382 {% if indexed_property_getter %}
383 {{install_indexed_property_handler('instanceTemplate') | indent}} 377 {{install_indexed_property_handler('instanceTemplate') | indent}}
384 {% endif %} 378 {% endif %}
385 {% if named_property_getter and not has_named_properties_object %} 379 {% if named_property_getter and not has_named_properties_object %}
380 // Named properties
386 {{install_named_property_handler('instanceTemplate') | indent}} 381 {{install_named_property_handler('instanceTemplate') | indent}}
387 {% endif %} 382 {% endif %}
388 {% if iterator_method %} 383
384 {%- if iterator_method %}{{newline}}
389 {% filter exposed(iterator_method.exposed_test) %} 385 {% filter exposed(iterator_method.exposed_test) %}
390 {% filter runtime_enabled(iterator_method.runtime_enabled_function) %} 386 {% filter runtime_enabled(iterator_method.runtime_enabled_function) %}
387 // Iterator (@@iterator)
391 const V8DOMConfiguration::SymbolKeyedMethodConfiguration symbolKeyedIterator Configuration = { v8::Symbol::GetIterator, {{cpp_class_or_partial}}V8Internal::i teratorMethodCallback, 0, v8::DontDelete, V8DOMConfiguration::ExposedToAllScript s, V8DOMConfiguration::OnPrototype }; 388 const V8DOMConfiguration::SymbolKeyedMethodConfiguration symbolKeyedIterator Configuration = { v8::Symbol::GetIterator, {{cpp_class_or_partial}}V8Internal::i teratorMethodCallback, 0, v8::DontDelete, V8DOMConfiguration::ExposedToAllScript s, V8DOMConfiguration::OnPrototype };
392 V8DOMConfiguration::installMethod(isolate, prototypeTemplate, defaultSignatu re, symbolKeyedIteratorConfiguration); 389 V8DOMConfiguration::installMethod(isolate, prototypeTemplate, signature, sym bolKeyedIteratorConfiguration);
393 {% endfilter %}{# runtime_enabled() #} 390 {% endfilter %}
394 {% endfilter %}{# exposed() #} 391 {% endfilter %}
395 {% endif %} 392 {% endif %}
396 {# End special operations #} 393
397 {% if has_custom_legacy_call_as_function %} 394 {%- if has_custom_legacy_call_as_function %}{{newline}}
398 functionTemplate->InstanceTemplate()->SetCallAsFunctionHandler({{v8_class}}: :legacyCallCustom); 395 instanceTemplate->SetCallAsFunctionHandler({{v8_class}}::legacyCallCustom);
399 {% endif %} 396 {% endif %}
400 {% if interface_name == 'HTMLAllCollection' %} 397
401 {# Needed for legacy support of document.all #} 398 {%- if interface_name == 'HTMLAllCollection' %}{{newline}}
402 functionTemplate->InstanceTemplate()->MarkAsUndetectable(); 399 // Needed for legacy support of document.all
400 instanceTemplate->MarkAsUndetectable();
403 {% endif %} 401 {% endif %}
402
403 {%- if custom_registration_methods %}{{newline}}
404 {% for method in custom_registration_methods %} 404 {% for method in custom_registration_methods %}
405 {# install_custom_signature #} 405 {# install_custom_signature #}
406 {% filter exposed(method.overloads.exposed_test_all 406 {% filter exposed(method.overloads.exposed_test_all
407 if method.overloads else 407 if method.overloads else
408 method.exposed_test) %} 408 method.exposed_test) %}
409 {% filter runtime_enabled(method.overloads.runtime_enabled_function_all 409 {% filter runtime_enabled(method.overloads.runtime_enabled_function_all
410 if method.overloads else 410 if method.overloads else
411 method.runtime_enabled_function) %} 411 method.runtime_enabled_function) %}
412 {% if method.is_do_not_check_security %} 412 {% if method.is_do_not_check_security %}
413 {{install_do_not_check_security_method(method, '', 'instanceTemplate', 'prot otypeTemplate') | indent}} 413 {{install_do_not_check_security_method(method, '', 'instanceTemplate', 'prot otypeTemplate') | indent}}
414 {% else %}{# is_do_not_check_security #} 414 {% else %}
415 {% set signature = 'v8::Local<v8::Signature>()' if method.is_do_not_check_si gnature else 'defaultSignature' %} 415 {% set signature = 'v8::Local<v8::Signature>()' if method.is_do_not_check_si gnature else 'signature' %}
416 {{install_custom_signature(method, 'instanceTemplate', 'prototypeTemplate', 'functionTemplate', signature) | indent}} 416 {{install_custom_signature(method, 'instanceTemplate', 'prototypeTemplate', 'interfaceTemplate', signature) | indent}}
417 {% endif %}{# is_do_not_check_security #} 417 {% endif %}
418 {% endfilter %}{# runtime_enabled() #} 418 {% endfilter %}
419 {% endfilter %}{# exposed() #} 419 {% endfilter %}
420 {% endfor %} 420 {% endfor %}
421 {# Special interfaces #}
422 {% if not is_partial %}
423 {% if interface_name == 'Window' %}
424
425 instanceTemplate->SetInternalFieldCount(V8Window::internalFieldCount);
426 prototypeTemplate->SetInternalFieldCount(V8Window::internalFieldCount);
427 {% endif %}
428 {% if is_global or interface_name == 'HTMLDocument' %}
429 functionTemplate->SetHiddenPrototype(true);
430 {% endif %}
431 {% endif %} 421 {% endif %}
432 } 422 }
433 423
434 {% endif %}{# not is_array_buffer_or_view #} 424 {% endif %}{# not is_array_buffer_or_view #}
435 {% endblock %} 425 {% endblock %}
436 {##############################################################################} 426 {##############################################################################}
437 {% block get_dom_template %}{% endblock %} 427 {% block get_dom_template %}{% endblock %}
438 {% block get_dom_template_for_named_properties_object %}{% endblock %} 428 {% block get_dom_template_for_named_properties_object %}{% endblock %}
439 {% block has_instance %}{% endblock %} 429 {% block has_instance %}{% endblock %}
440 {% block to_impl %}{% endblock %} 430 {% block to_impl %}{% endblock %}
441 {% block to_impl_with_type_check %}{% endblock %} 431 {% block to_impl_with_type_check %}{% endblock %}
442 {% block install_conditional_attributes %}{% endblock %} 432 {% block install_conditional_attributes %}{% endblock %}
443 {##############################################################################} 433 {##############################################################################}
444 {% block prepare_prototype_and_interface_object %}{% endblock %} 434 {% block prepare_prototype_and_interface_object %}{% endblock %}
445 {##############################################################################} 435 {##############################################################################}
446 {% block ref_object_and_deref_object %}{% endblock %} 436 {% block ref_object_and_deref_object %}{% endblock %}
447 {% for method in methods if method.is_implemented_in_private_script and method.v isible %} 437 {% for method in methods if method.is_implemented_in_private_script and method.v isible %}
448 {{method_implemented_in_private_script(method)}} 438 {{method_implemented_in_private_script(method)}}
449 {% endfor %} 439 {% endfor %}
450 {% for attribute in attributes if attribute.is_implemented_in_private_script %} 440 {% for attribute in attributes if attribute.is_implemented_in_private_script %}
451 {{attribute_getter_implemented_in_private_script(attribute)}} 441 {{attribute_getter_implemented_in_private_script(attribute)}}
452 {% if attribute.has_setter %} 442 {% if attribute.has_setter %}
453 {{attribute_setter_implemented_in_private_script(attribute)}} 443 {{attribute_setter_implemented_in_private_script(attribute)}}
454 {% endif %} 444 {% endif %}
455 {% endfor %} 445 {% endfor %}
456 {% block partial_interface %}{% endblock %} 446 {% block partial_interface %}{% endblock %}
457 } // namespace blink 447 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698