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

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

Issue 2873543002: First implementation of lazily cached accessor for DOM attributes. (Closed)
Patch Set: Created 3 years, 7 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 {% filter format_blink_cpp_source_code %} 1 {% filter format_blink_cpp_source_code %}
2 2
3 {% include 'copyright_block.txt' %} 3 {% include 'copyright_block.txt' %}
4 #include "{{v8_class_or_partial}}.h" 4 #include "{{v8_class_or_partial}}.h"
5 5
6 {% for filename in cpp_includes if filename != '%s.h' % cpp_class_or_partial %} 6 {% for filename in cpp_includes if filename != '%s.h' % cpp_class_or_partial %}
7 #include "{{filename}}" 7 #include "{{filename}}"
8 {% endfor %} 8 {% endfor %}
9 9
10 namespace blink { 10 namespace blink {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 {% if not is_array_buffer_or_view %} 70 {% if not is_array_buffer_or_view %}
71 namespace {{cpp_class_or_partial}}V8Internal { 71 namespace {{cpp_class_or_partial}}V8Internal {
72 {% if has_partial_interface %} 72 {% if has_partial_interface %}
73 {% for method in methods if method.overloads and method.overloads.has_partial_ov erloads %} 73 {% for method in methods if method.overloads and method.overloads.has_partial_ov erloads %}
74 static void (*{{method.name}}MethodForPartialInterface)(const v8::FunctionCallba ckInfo<v8::Value>&) = 0; 74 static void (*{{method.name}}MethodForPartialInterface)(const v8::FunctionCallba ckInfo<v8::Value>&) = 0;
75 {% endfor %} 75 {% endfor %}
76 {% endif %} 76 {% endif %}
77 77
78 {##############################################################################} 78 {##############################################################################}
79 {# Attributes #} 79 {# Attributes #}
80 {% from 'attributes.cpp.tmpl' import attribute_getter, attribute_setter with con text %} 80 {% from 'attributes.cpp.tmpl' import attribute_getter,
81 attribute_setter,
82 attribute_cache_init_callback,
83 with context %}
81 {% for attribute in attributes %} 84 {% for attribute in attributes %}
85 {% if attribute.is_lazy_cached_accessor %}
86 {{attribute_cache_init_callback(attribute)}}
87 {% endif %}
82 {% for world_suffix in attribute.world_suffixes %} 88 {% for world_suffix in attribute.world_suffixes %}
83 {% if not attribute.has_custom_getter and not attribute.constructor_type %} 89 {% if not attribute.has_custom_getter and not attribute.constructor_type %}
84 {{attribute_getter(attribute, world_suffix)}} 90 {{attribute_getter(attribute, world_suffix)}}
85 {% endif %} 91 {% endif %}
86 {% if attribute.has_setter and not attribute.has_custom_setter %} 92 {% if attribute.has_setter and not attribute.has_custom_setter %}
87 {{attribute_setter(attribute, world_suffix)}} 93 {{attribute_setter(attribute, world_suffix)}}
88 {% endif %} 94 {% endif %}
89 {% endfor %} 95 {% endfor %}
90 {% endfor %} 96 {% endfor %}
91 {##############################################################################} 97 {##############################################################################}
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 {% endfor %} 368 {% endfor %}
363 }; 369 };
364 #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) 370 #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG)
365 #pragma clang diagnostic pop 371 #pragma clang diagnostic pop
366 #endif 372 #endif
367 373
368 {% endif %} 374 {% endif %}
369 {% endblock %} 375 {% endblock %}
370 {##############################################################################} 376 {##############################################################################}
371 {% block install_accessors %} 377 {% block install_accessors %}
372 {% from 'attributes.cpp.tmpl' import attribute_configuration with context %} 378 {% from 'attributes.cpp.tmpl' import accessor_configuration with context %}
373 {% if accessors %} 379 {% if accessors %}
374 static const V8DOMConfiguration::AccessorConfiguration {{v8_class}}Accessors[] = { 380 static const V8DOMConfiguration::AccessorConfiguration {{v8_class}}Accessors[] = {
375 {% for accessor in accessors %} 381 {% for accessor in accessors %}
376 {{attribute_configuration(accessor) | indent(4)}}, 382 {{accessor_configuration(accessor) | indent(4)}},
377 {% endfor %} 383 {% endfor %}
378 }; 384 };
379 385
380 {% endif %} 386 {% endif %}
381 {% endblock %} 387 {% endblock %}
382 {##############################################################################} 388 {##############################################################################}
383 {% block install_methods %} 389 {% block install_methods %}
384 {% from 'methods.cpp.tmpl' import method_configuration with context %} 390 {% from 'methods.cpp.tmpl' import method_configuration with context %}
385 {% if methods | has_method_configuration(is_partial) %} 391 {% if methods | has_method_configuration(is_partial) %}
386 static const V8DOMConfiguration::MethodConfiguration {{v8_class}}Methods[] = { 392 static const V8DOMConfiguration::MethodConfiguration {{v8_class}}Methods[] = {
387 {% for method in methods | has_method_configuration(is_partial) %} 393 {% for method in methods | has_method_configuration(is_partial) %}
388 {{method_configuration(method) | indent(4)}}, 394 {{method_configuration(method) | indent(4)}},
389 {% endfor %} 395 {% endfor %}
390 }; 396 };
391 397
392 {% endif %} 398 {% endif %}
393 {% endblock %} 399 {% endblock %}
394 {% endif %}{# not is_array_buffer_or_view #} 400 {% endif %}{# not is_array_buffer_or_view #}
395 {##############################################################################} 401 {##############################################################################}
396 {% block named_constructor %}{% endblock %} 402 {% block named_constructor %}{% endblock %}
397 {% block constructor_callback %}{% endblock %} 403 {% block constructor_callback %}{% endblock %}
398 {##############################################################################} 404 {##############################################################################}
399 {% block install_dom_template %} 405 {% block install_dom_template %}
400 {% if not is_array_buffer_or_view %} 406 {% if not is_array_buffer_or_view %}
401 {% from 'methods.cpp.tmpl' import install_custom_signature with context %} 407 {% from 'methods.cpp.tmpl' import install_custom_signature with context %}
402 {% from 'attributes.cpp.tmpl' import attribute_configuration with context %} 408 {% from 'attributes.cpp.tmpl' import accessor_configuration,
409 attribute_configuration,
410 with context %}
403 {% from 'constants.cpp.tmpl' import install_constants with context %} 411 {% from 'constants.cpp.tmpl' import install_constants with context %}
404 {% from 'methods.cpp.tmpl' import method_configuration with context %} 412 {% from 'methods.cpp.tmpl' import method_configuration with context %}
405 {% if has_partial_interface or is_partial %} 413 {% if has_partial_interface or is_partial %}
406 void {{v8_class_or_partial}}::install{{v8_class}}Template(v8::Isolate* isolate, const DOMWrapperWorld& world, v8::Local<v8::FunctionTemplate> interfaceTemplate) { 414 void {{v8_class_or_partial}}::install{{v8_class}}Template(v8::Isolate* isolate, const DOMWrapperWorld& world, v8::Local<v8::FunctionTemplate> interfaceTemplate) {
407 {% else %} 415 {% else %}
408 static void install{{v8_class}}Template(v8::Isolate* isolate, const DOMWrapperWo rld& world, v8::Local<v8::FunctionTemplate> interfaceTemplate) { 416 static void install{{v8_class}}Template(v8::Isolate* isolate, const DOMWrapperWo rld& world, v8::Local<v8::FunctionTemplate> interfaceTemplate) {
409 {% endif %} 417 {% endif %}
410 // Initialize the interface object's template. 418 // Initialize the interface object's template.
411 {% if is_partial %} 419 {% if is_partial %}
412 {{v8_class}}::install{{v8_class}}Template(isolate, world, interfaceTemplate); 420 {{v8_class}}::install{{v8_class}}Template(isolate, world, interfaceTemplate);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 {% filter runtime_enabled(feature_name) %} 489 {% filter runtime_enabled(feature_name) %}
482 {% for attribute in attribute_list | unique_by('name') | sort %} 490 {% for attribute in attribute_list | unique_by('name') | sort %}
483 {% if attribute.is_data_type_property %} 491 {% if attribute.is_data_type_property %}
484 static const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.n ame}}Configuration[] = { 492 static const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.n ame}}Configuration[] = {
485 {{attribute_configuration(attribute) | indent(2)}} 493 {{attribute_configuration(attribute) | indent(2)}}
486 }; 494 };
487 for (const auto& attributeConfig : attribute{{attribute.name}}Configuration) 495 for (const auto& attributeConfig : attribute{{attribute.name}}Configuration)
488 V8DOMConfiguration::InstallAttribute(isolate, world, instanceTemplate, proto typeTemplate, attributeConfig); 496 V8DOMConfiguration::InstallAttribute(isolate, world, instanceTemplate, proto typeTemplate, attributeConfig);
489 {% else %} 497 {% else %}
490 static const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.nam e}}Configuration[] = { 498 static const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.nam e}}Configuration[] = {
491 {{attribute_configuration(attribute) | indent(2)}} 499 {{accessor_configuration(attribute) | indent(2)}}
492 }; 500 };
493 for (const auto& accessorConfig : accessor{{attribute.name}}Configuration) 501 for (const auto& accessorConfig : accessor{{attribute.name}}Configuration)
494 V8DOMConfiguration::InstallAccessor(isolate, world, instanceTemplate, protot ypeTemplate, interfaceTemplate, signature, accessorConfig); 502 V8DOMConfiguration::InstallAccessor(isolate, world, instanceTemplate, protot ypeTemplate, interfaceTemplate, signature, accessorConfig);
495 {% endif %} 503 {% endif %}
496 {% endfor %} 504 {% endfor %}
497 {% endfilter %} 505 {% endfilter %}
498 {% endfor %} 506 {% endfor %}
499 507
500 {% if (indexed_property_getter or named_property_getter) and not is_partial %} 508 {% if (indexed_property_getter or named_property_getter) and not is_partial %}
501 // Indexed properties 509 // Indexed properties
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 {% endfilter %} 617 {% endfilter %}
610 {% endfor %} 618 {% endfor %}
611 {% endif %} 619 {% endif %}
612 } 620 }
613 621
614 {% endif %}{# not is_array_buffer_or_view #} 622 {% endif %}{# not is_array_buffer_or_view #}
615 {% endblock %} 623 {% endblock %}
616 {##############################################################################} 624 {##############################################################################}
617 {% block install_runtime_enabled %} 625 {% block install_runtime_enabled %}
618 {% if needs_runtime_enabled_installer %} 626 {% if needs_runtime_enabled_installer %}
619 {% from 'attributes.cpp.tmpl' import attribute_configuration with context %} 627 {% from 'attributes.cpp.tmpl' import accessor_configuration,
628 attribute_configuration,
629 with context %}
620 {% from 'methods.cpp.tmpl' import install_custom_signature with context %} 630 {% from 'methods.cpp.tmpl' import install_custom_signature with context %}
621 void {{v8_class_or_partial}}::installRuntimeEnabledFeatures(v8::Isolate* isolate , const DOMWrapperWorld& world, v8::Local<v8::Object> instance, v8::Local<v8::Ob ject> prototype, v8::Local<v8::Function> interface) { 631 void {{v8_class_or_partial}}::installRuntimeEnabledFeatures(v8::Isolate* isolate , const DOMWrapperWorld& world, v8::Local<v8::Object> instance, v8::Local<v8::Ob ject> prototype, v8::Local<v8::Function> interface) {
622 {% if runtime_enabled_feature_name %} 632 {% if runtime_enabled_feature_name %}
623 #error "We don't expect a runtime enabled interface {{v8_class_or_partial}} to h ave installRuntimeEnabledFeatures()." 633 #error "We don't expect a runtime enabled interface {{v8_class_or_partial}} to h ave installRuntimeEnabledFeatures()."
624 {% endif %} 634 {% endif %}
625 635
626 {% if is_partial %} 636 {% if is_partial %}
627 {{v8_class}}::installRuntimeEnabledFeatures(isolate, world, instance, prototyp e, interface); 637 {{v8_class}}::installRuntimeEnabledFeatures(isolate, world, instance, prototyp e, interface);
628 {% endif %} 638 {% endif %}
629 639
630 v8::Local<v8::FunctionTemplate> interfaceTemplate = {{v8_class}}::wrapperTypeI nfo.domTemplate(isolate, world); 640 v8::Local<v8::FunctionTemplate> interfaceTemplate = {{v8_class}}::wrapperTypeI nfo.domTemplate(isolate, world);
631 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTemp late); 641 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTemp late);
632 ALLOW_UNUSED_LOCAL(signature); 642 ALLOW_UNUSED_LOCAL(signature);
633 643
634 {# TODO(peria): Generate code to install constants. It depends on runtime_enab led_feaure of this interface. #} 644 {# TODO(peria): Generate code to install constants. It depends on runtime_enab led_feaure of this interface. #}
635 645
636 {% for feature_name, attrs in runtime_enabled_attributes | groupby('runtime_en abled_feature_name') %} 646 {% for feature_name, attrs in runtime_enabled_attributes | groupby('runtime_en abled_feature_name') %}
637 {% filter runtime_enabled(feature_name) %} 647 {% filter runtime_enabled(feature_name) %}
638 {% for attribute in attrs | unique_by('name') | sort %} 648 {% for attribute in attrs | unique_by('name') | sort %}
639 {% if attribute.is_data_type_property %} 649 {% if attribute.is_data_type_property %}
640 static const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.n ame}}Configuration[] = { 650 static const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.n ame}}Configuration[] = {
641 {{attribute_configuration(attribute) | indent(2)}} 651 {{attribute_configuration(attribute) | indent(2)}}
642 }; 652 };
643 for (const auto& attributeConfig : attribute{{attribute.name}}Configuration) 653 for (const auto& attributeConfig : attribute{{attribute.name}}Configuration)
644 V8DOMConfiguration::InstallAttribute(isolate, world, instance, prototype, at tributeConfig); 654 V8DOMConfiguration::InstallAttribute(isolate, world, instance, prototype, at tributeConfig);
645 {% else %} 655 {% else %}
646 static const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.nam e}}Configuration[] = { 656 static const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.nam e}}Configuration[] = {
647 {{attribute_configuration(attribute) | indent(2)}} 657 {{accessor_configuration(attribute) | indent(2)}}
648 }; 658 };
649 for (const auto& accessorConfig : accessor{{attribute.name}}Configuration) 659 for (const auto& accessorConfig : accessor{{attribute.name}}Configuration)
650 V8DOMConfiguration::InstallAccessor(isolate, world, instance, prototype, int erface, signature, accessorConfig); 660 V8DOMConfiguration::InstallAccessor(isolate, world, instance, prototype, int erface, signature, accessorConfig);
651 {% endif %} 661 {% endif %}
652 {% endfor %} 662 {% endfor %}
653 {% endfilter %} 663 {% endfilter %}
654 {% endfor %} 664 {% endfor %}
655 665
656 {% if iterator_method and iterator_method.runtime_enabled_feature_name %} 666 {% if iterator_method and iterator_method.runtime_enabled_feature_name %}
657 {% filter exposed(iterator_method.exposed_test) %} 667 {% filter exposed(iterator_method.exposed_test) %}
(...skipping 21 matching lines...) Expand all
679 {% endif %} 689 {% endif %}
680 {% endfilter %} 690 {% endfilter %}
681 {% endfor %} 691 {% endfor %}
682 {% endif %} 692 {% endif %}
683 } 693 }
684 694
685 {% endif %}{# needs_runtime_enabled_installer #} 695 {% endif %}{# needs_runtime_enabled_installer #}
686 {% endblock %} 696 {% endblock %}
687 {##############################################################################} 697 {##############################################################################}
688 {% block origin_trials %} 698 {% block origin_trials %}
689 {% from 'attributes.cpp.tmpl' import attribute_configuration with context %} 699 {% from 'attributes.cpp.tmpl' import accessor_configuration,
700 attribute_configuration,
701 with context %}
690 {% from 'constants.cpp.tmpl' import constant_configuration with context %} 702 {% from 'constants.cpp.tmpl' import constant_configuration with context %}
691 {% from 'methods.cpp.tmpl' import method_configuration with context %} 703 {% from 'methods.cpp.tmpl' import method_configuration with context %}
692 {% for feature in origin_trial_features %} 704 {% for feature in origin_trial_features %}
693 void {{v8_class_or_partial}}::install{{feature.name}}(v8::Isolate* isolate, cons t DOMWrapperWorld& world, v8::Local<v8::Object> instance, v8::Local<v8::Object> prototype, v8::Local<v8::Function> interface) { 705 void {{v8_class_or_partial}}::install{{feature.name}}(v8::Isolate* isolate, cons t DOMWrapperWorld& world, v8::Local<v8::Object> instance, v8::Local<v8::Object> prototype, v8::Local<v8::Function> interface) {
694 {% if feature.attributes or feature.methods %} 706 {% if feature.attributes or feature.methods %}
695 v8::Local<v8::FunctionTemplate> interfaceTemplate = {{v8_class}}::wrapperTypeI nfo.domTemplate(isolate, world); 707 v8::Local<v8::FunctionTemplate> interfaceTemplate = {{v8_class}}::wrapperTypeI nfo.domTemplate(isolate, world);
696 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTemp late); 708 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTemp late);
697 ALLOW_UNUSED_LOCAL(signature); 709 ALLOW_UNUSED_LOCAL(signature);
698 {% endif %} 710 {% endif %}
699 {# Origin-Trial-enabled attributes #} 711 {# Origin-Trial-enabled attributes #}
700 {% for attribute in feature.attributes %} 712 {% for attribute in feature.attributes %}
701 {% if attribute.is_data_type_property %} 713 {% if attribute.is_data_type_property %}
702 static const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.n ame}}Configuration[] = { 714 static const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.n ame}}Configuration[] = {
703 {{attribute_configuration(attribute) | indent(2)}} 715 {{attribute_configuration(attribute) | indent(2)}}
704 }; 716 };
705 for (const auto& attributeConfig : attribute{{attribute.name}}Configuration) 717 for (const auto& attributeConfig : attribute{{attribute.name}}Configuration)
706 V8DOMConfiguration::InstallAttribute(isolate, world, instance, prototype, at tributeConfig); 718 V8DOMConfiguration::InstallAttribute(isolate, world, instance, prototype, at tributeConfig);
707 {% else %} 719 {% else %}
708 static const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.nam e}}Configuration[] = { 720 static const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.nam e}}Configuration[] = {
709 {{attribute_configuration(attribute) | indent(2)}} 721 {{accessor_configuration(attribute) | indent(2)}}
710 }; 722 };
711 for (const auto& accessorConfig : accessor{{attribute.name}}Configuration) 723 for (const auto& accessorConfig : accessor{{attribute.name}}Configuration)
712 V8DOMConfiguration::InstallAccessor(isolate, world, instance, prototype, int erface, signature, accessorConfig); 724 V8DOMConfiguration::InstallAccessor(isolate, world, instance, prototype, int erface, signature, accessorConfig);
713 {% endif %} 725 {% endif %}
714 {% endfor %} 726 {% endfor %}
715 {# Origin-Trial-enabled constants #} 727 {# Origin-Trial-enabled constants #}
716 {% for constant in feature.constants %} 728 {% for constant in feature.constants %}
717 {% set constant_name = constant.name.title().replace('_', '') %} 729 {% set constant_name = constant.name.title().replace('_', '') %}
718 const V8DOMConfiguration::ConstantConfiguration constant{{constant_name}}Confi guration = {{constant_configuration(constant)}}; 730 const V8DOMConfiguration::ConstantConfiguration constant{{constant_name}}Confi guration = {{constant_configuration(constant)}};
719 V8DOMConfiguration::InstallConstant(isolate, interface, prototype, constant{{c onstant_name}}Configuration); 731 V8DOMConfiguration::InstallConstant(isolate, interface, prototype, constant{{c onstant_name}}Configuration);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 {% endif %} 803 {% endif %}
792 } 804 }
793 {% endif %} 805 {% endif %}
794 806
795 {% endblock %} 807 {% endblock %}
796 {##############################################################################} 808 {##############################################################################}
797 {% block partial_interface %}{% endblock %} 809 {% block partial_interface %}{% endblock %}
798 } // namespace blink 810 } // namespace blink
799 811
800 {% endfilter %}{# format_blink_cpp_source_code #} 812 {% endfilter %}{# format_blink_cpp_source_code #}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698