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

Side by Side Diff: sky/engine/bindings2/scripts/templates/attributes_cpp.template

Issue 914413004: Add a new bindings2/scripts directory for Dart bindings (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Remove idlrenderer.py it's not used Created 5 years, 10 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 {##############################################################################}
2 {% macro attribute_getter(cpp_class, attribute) %}
3 static void {{static_attribute_name(attribute, 'Getter')}}(Dart_NativeArguments args) {
4 {% if attribute.is_getter_raises_exception or attribute.is_call_with_execution_c ontext %}
5 Dart_Handle exception = nullptr;
6 {% endif %}
7 {
8 {% if attribute.is_call_with_execution_context %}
9 ExecutionContext* context = DOMDartState::CurrentDocument();
10 if (!context) {
11 exception = Dart_NewStringFromCString("Failed to retrieve a context");
12 goto fail;
13 }
14 {% endif %}
15 {% if attribute.is_call_with_script_state %}
16 DartState* dart_state = DartState::Current();
17 DCHECK(state);
18 {% endif %}
19 {% if attribute.dart_set_return_value and not attribute.is_static %}
20 {{cpp_class}}* receiver = GetReceiver<{{cpp_class}}>(args);
21 {% else %}
22 // FIXME: Need receiver setup too.
23 {% endif %}
24 {% if attribute.reflect_only %}
25 {{generate_reflects(attribute)|indent(4)}}
26 {% endif %}
27 {{callback_return(attribute)|indent(4)}}
28 return;
29 }
30 {% if attribute.is_getter_raises_exception or attribute.is_call_with_execution_c ontext %}
31 fail:
32 Dart_ThrowException(exception);
33 ASSERT_NOT_REACHED();
34 {% endif %}
35 }
36 {% endmacro %}
37
38
39 {##############################################################################}
40 {% macro callback_return(attribute) %}
41 {% if attribute.dart_set_return_value %}
42 {% if attribute.is_nullable %}
43 bool is_null = false;
44 {% endif %}
45 {% if attribute.is_getter_raises_exception or
46 attribute.is_nullable %}
47 ExceptionState es;
48 {% endif %}
49 {% if attribute.cached_attribute_validation_method or
50 attribute.is_getter_raises_exception or
51 attribute.is_nullable or
52 attribute.idl_type == 'EventHandler' %}
53 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_original} };
54 {% endif %}
55 {% if attribute.is_nullable %}
56 if (is_null)
57 return;
58 {% endif %}
59 {% if attribute.is_getter_raises_exception %}
60 if (es.had_exception()) {
61 exception = es.GetDartException(args, {{attribute.auto_scope}});
62 goto fail;
63 }
64 {% endif %}
65 {{attribute.dart_set_return_value}};
66 {% else %}
67 // FIXME: Need to convert this properly.
68 DART_UNIMPLEMENTED();
69 {% endif %}
70 {% endmacro %}
71
72
73 {##############################################################################}
74 {% macro attribute_setter(cpp_class, attribute) %}
75 static void {{static_attribute_name(attribute, 'Setter')}}(Dart_NativeArguments args)
76 {
77 {% if attribute.idl_type == "EventHandler" or not attribute.cpp_setter %}
78 {# TODO(terry): Need to fix properly. #}
79 // FIXME: proper implementation.
80 DART_UNIMPLEMENTED();
81 {% else %}
82 Dart_Handle exception = nullptr;
83 {
84 {{cpp_class}}* receiver = GetReceiver<{{cpp_class}}>(args);
85 {% if attribute.is_custom_element_callbacks %}
86 CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
87 {% endif %}
88 {% set attribute_name = attribute.name if not attribute.put_forwards else 'value ' %}
89
90 {{attribute.local_cpp_type}} {{attribute.setter_lvalue}} = {{attribute.d art_value_to_local_cpp_value}};
91 if (exception)
92 goto fail;
93 {% if attribute.is_call_with_execution_context or
94 attribute.is_setter_call_with_execution_context %}
95
96 ExecutionContext* context = DOMDartState::CurrentDocument();
97 if (!context) {
98 exception = Dart_NewStringFromCString("Failed to retrieve a context" );
99 goto fail;
100 }
101
102 {% endif %}
103
104 {% if attribute.is_call_with_script_state %}
105 ScriptState* state = DartUtilities::currentScriptState();
106 if (!state) {
107 exception = Dart_NewStringFromCString("Failed to retrieve a script s tate");
108 goto fail;
109 }
110 {% endif %}
111 {% if attribute.is_setter_raises_exception %}
112 ExceptionState es;
113 {% endif %}
114 {{attribute.cpp_setter}};
115 {% if attribute.is_setter_raises_exception %}
116 if (es.had_exception()) {
117 exception = es.GetDartException(args, {{attribute.auto_scope}});
118 goto fail;
119 }
120 {% endif %}
121 return;
122 }
123
124 fail:
125 Dart_ThrowException(exception);
126 ASSERT_NOT_REACHED();
127 {% endif %}
128 }
129 {% endmacro %}
130
131
132 {######################################}
133 {% macro generate_reflects(attribute) %}
134 {% set reflect_only_values = attribute.reflect_only %}
135 {% set reflect_missing = attribute.reflect_missing %}
136 {% set reflect_invalid = attribute.reflect_invalid %}
137 {% set reflect_empty = attribute.reflect_empty %}
138 {{attribute.cpp_type}} result = {{attribute.cpp_value_original}};
139
140 {# Attribute is limited to only known values: check that the attribute value is
141 one of those. If not, set it to the empty string.
142 http://www.whatwg.org/specs/web-apps/current-work/#limited-to-only-known-valu es #}
143 {% if reflect_empty %}
144 if (result.isNull()) {
145 {% if reflect_missing %}
146 result = "{{reflect_missing}}";
147 {% else %}
148 ;
149 {% endif %}
150 } else if (result.isEmpty()) {
151 result = "{{reflect_empty}}";
152 {% else %}
153 if (result.isEmpty()) {
154 {# FIXME: should use [ReflectEmpty] instead; need to change IDL files #}
155 {% if reflect_missing %}
156 result = "{{reflect_missing}}";
157 {% else %}
158 ;
159 {% endif %}
160 {% endif %}
161 {% for value in reflect_only_values %}
162 } else if (equalIgnoringCase(result, "{{value}}")) {
163 result = "{{value}}";
164 {% endfor %}
165 } else {
166 result = "{{reflect_invalid}}";
167 }
168
169 {% endmacro %}
170
171
172 {##############################################################################}
173 {% macro static_attribute_name(attribute, setter_or_getter) -%}
174 {{attribute.name}}{{setter_or_getter}}
175 {%- endmacro -%}
176
177
178 {##############################################################################}
179 {% macro generate_attribute_resolver_body(dart_class, class_name, attribute) %}
180 if (argumentCount == 1 && name == "{{attribute.native_entry_getter.resolver_stri ng}}") {
181 *autoSetupScope = {{attribute.auto_scope}};
182 return {{dart_class}}Internal::{{static_attribute_name(attribute, 'Getter')} };
183 }
184 {# FIXME Disabling PutForwards for now #}
185 {# {% if not attribute.is_read_only or attribute.put_forwards %} #}
186 {% if not attribute.is_read_only %}
187 if (argumentCount == 2 && name == "{{attribute.native_entry_setter.resolver_stri ng}}") {
188 *autoSetupScope = {{attribute.auto_scope}};
189 return {{dart_class}}Internal::{{static_attribute_name(attribute, 'Setter')} };
190 }
191 {% endif %}
192 {% endmacro %}
193
194 {##############################################################################}
195 {% macro generate_attribute_symbolizer_body(dart_class, class_name, attribute) % }
196 if (native_function == {{dart_class}}Internal::{{static_attribute_name(attribute , 'Getter')}}) {
197 return reinterpret_cast<const uint8_t*>("{{attribute.native_entry_getter.res olver_string}}");
198 }
199 {% if not attribute.is_read_only %}
200 if (native_function == {{dart_class}}Internal::{{static_attribute_name(attribute , 'Setter')}}) {
201 return reinterpret_cast<const uint8_t*>("{{attribute.native_entry_setter.res olver_string}}");
202 }
203 {% endif %}
204 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698