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

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

Issue 2970003002: Add code generation for ConditionalFeatures bindings code (Closed)
Patch Set: Readability fixes Created 3 years, 5 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
(Empty)
1 {% filter format_blink_cpp_source_code %}
2
3 {% include 'copyright_block.txt' %}
4
5 #include "bindings/modules/v8/ConditionalFeaturesForModules.h"
6
7 #include "bindings/core/v8/ConditionalFeaturesForCore.h"
8 {% for include in includes %}
9 #include "{{include}}"
10 {% endfor %}
11
12 namespace blink {
13
14 namespace {
15 InstallConditionalFeaturesFunction
16 g_original_install_conditional_features_function = nullptr;
17 InstallPendingConditionalFeatureFunction
18 g_original_install_pending_conditional_feature_function = nullptr;
19 }
20
21 void InstallConditionalFeaturesForModules(
22 const WrapperTypeInfo* wrapper_type_info,
23 const ScriptState* script_state,
24 v8::Local<v8::Object> prototype_object,
25 v8::Local<v8::Function> interface_object) {
26 (*g_original_install_conditional_features_function)(
27 wrapper_type_info, script_state, prototype_object, interface_object);
28
29 {% if installers_by_interface %}
30 ExecutionContext* execution_context = ExecutionContext::From(script_state);
31 if (!execution_context)
32 return;
33 v8::Isolate* isolate = script_state->GetIsolate();
34 const DOMWrapperWorld& world = script_state->World();
35 // TODO(iclelland): Extract this common code out of ConditionalFeaturesForCore
36 // and ConditionalFeaturesForModules into a block.
37 {% for interface in installers_by_interface %}
38 if (wrapper_type_info == &{{interface.v8_class}}::wrapperTypeInfo) {
39 {% if interface.is_global %}
40 v8::Local<v8::Object> instance_object =
41 script_state->GetContext()->Global();
42 {% endif %}
43 {% for installer in interface.installers %}
44 if ({{installer.condition}}(execution_context)) {
45 {{installer.v8_class_or_partial}}::{{installer.install_method}}(
46 isolate, world, {% if interface.is_global %}instance_object{% else %}v 8::Local<v8::Object>(){% endif %}, prototype_object, interface_object);
47 }
48 {% endfor %}
49 }
50 {% endfor %}
51 {% endif %}
52 }
53
54 void InstallPendingConditionalFeatureForModules(
55 const String& feature,
56 const ScriptState* script_state) {
57 (*g_original_install_pending_conditional_feature_function)(feature,
58 script_state);
59
60 // TODO(iclelland): Extract this common code out of ConditionalFeaturesForCore
61 // and ConditionalFeaturesForModules into a block.
62 {% if installers_by_feature %}
63 v8::Local<v8::Object> prototype_object;
64 v8::Local<v8::Function> interface_object;
65 v8::Isolate* isolate = script_state->GetIsolate();
66 const DOMWrapperWorld& world = script_state->World();
67 V8PerContextData* context_data = script_state->PerContextData();
68 {% for feature in installers_by_feature %}
69 if (feature == "{{feature.name}}") {
70 {% for installer in feature.installers %}
71 if (context_data->GetExistingConstructorAndPrototypeForType(
72 &{{installer.v8_class}}::wrapperTypeInfo, &prototype_object, &interf ace_object)) {
73 {{installer.v8_class_or_partial}}::{{installer.install_method}}(
74 isolate, world, v8::Local<v8::Object>(), prototype_object, interface_o bject);
75 }
76 {% endfor %}
77 return;
78 }
79 {% endfor %}
80 {% endif %}
81 }
82
83 void RegisterInstallConditionalFeaturesForModules() {
84 RegisterInstallConditionalFeaturesForCore();
85 g_original_install_conditional_features_function =
86 SetInstallConditionalFeaturesFunction(
87 &InstallConditionalFeaturesForModules);
88 g_original_install_pending_conditional_feature_function =
89 SetInstallPendingConditionalFeatureFunction(
90 &InstallPendingConditionalFeatureForModules);
91 }
92
93 } // namespace blink
94
95 {% endfilter %}{# format_blink_cpp_source_code #}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698