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

Side by Side Diff: Source/bindings/scripts/v8_special_accessors.py

Issue 17572008: WIP IDL compiler rewrite (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Branch: const + primitive type readonly attributes Created 7 years, 4 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
« no previous file with comments | « Source/bindings/scripts/v8_interface_header.py ('k') | Source/bindings/scripts/v8_types.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 from v8_types import get_is_null_expression, get_native_type, has_custom_impleme ntation, is_union_type
30 from v8_utilities import get_raises_exception, implemented_as_cpp_name
31 from v8_values import get_js_value_to_native_statement, get_native_to_js_value_s tatement, get_pass_owner_expression
32
33
34 # GenerateMethodCall in perl
35 def get_function_call_statements(return_type, variable_name, function_expression , first_argument, raises_exceptions=False):
36 arguments = [first_argument]
37 if raises_exceptions:
38 arguments.append('es')
39 if is_union_type(return_type):
40 code = ''
41 for i, union_member_type in enumerate(return_type.union_member_types):
42 native_type = get_native_type(union_member_type)
43 union_member_number = i
44 union_member_variable = '%s%d' % (variable_name, union_member_number )
45 union_member_enabled_variable = '%s%dEnabled' % (variable_name, unio n_member_number)
46 union_member_native_value = get_pass_owner_expression(union_member_t ype, union_member_variable)
47 code += ' bool %s = false;\n' % union_member_enabled_variable
48 code += ' %s %s;\n' % (native_type, union_member_variable)
49 arguments.append(union_member_enabled_variable)
50 arguments.append(union_member_variable)
51 code += ' %s(%s);' % (function_expression, ', '.join(arguments))
52 return code
53 else:
54 native_type = get_native_type(return_type)
55 return ' %s %s = %s(%s);' % (native_type, variable_name, function_exp ression, ', '.join(arguments))
56
57
58 def get_indexed_property_getter_parameter(interface):
59 cpp_class_name = implemented_as_cpp_name(interface)
60 indexed_getter_function = get_indexed_getter_operation(interface)
61 includes = []
62 callback_name = '0'
63 function_call = ''
64 return_type_is_union = ''
65 return_js_value_statement = ''
66 is_null_expression = ''
67 raises_exceptions = False
68 is_custom = False
69 not_enumerable = False
70
71 if indexed_getter_function:
72 # js_to_native_statement, js_value_to_native_includes = get_js_value_to_ native_statement(parameter.data_type, parameter.extended_attributes, js_value, p arameter.name, 'args.GetIsolate()')
73 # my $methodCallCode = GenerateMethodCall($returnType, 'element', 'collectio n->${methodName}', 'index', $raisesExceptions)
74 # function_call_parameter, function_call_includes = get_function_call_pa rameter(indexed_getter_function)
75 # includes += function_call_includes
76
77 is_custom = 'Custom' in indexed_getter_function.extended_attributes
78 raises_exceptions = get_raises_exception(indexed_getter_function)
79 function_call = get_function_call_statements(indexed_getter_function.dat a_type, 'element', 'collection->' + implemented_as_cpp_name(indexed_getter_funct ion), 'index', raises_exceptions=raises_exceptions)
80 return_type_is_union = False
81 native_value = get_pass_owner_expression(indexed_getter_function.data_ty pe, 'element')
82 return_js_value_statement, return_js_value_includes = get_native_to_js_v alue_statement(indexed_getter_function.data_type, indexed_getter_function.extend ed_attributes, native_value, creation_context='info.Holder()', isolate='info.Get Isolate()', callback_info='info', script_wrappable='collection', used_as_return_ value=True)
83 includes += return_js_value_includes
84 is_null_expression = get_is_null_expression(indexed_getter_function.data _type, 'element')
85 callback_name = '%sV8Internal::indexedPropertyGetterCallback' % cpp_clas s_name
86 not_enumerable = 'NotEnumerable' in indexed_getter_function.extended_att ributes
87
88 parameter = {
89 'enabled': indexed_getter_function,
90 'callback_name': callback_name,
91 'is_custom': is_custom,
92 'function_call': function_call,
93 # 'function_call_parameter': function_call_parameter,
94 'return_type_is_union': return_type_is_union,
95 'return_js_value_statement': return_js_value_statement,
96 'is_null_expression': is_null_expression,
97 'raises_exceptions': raises_exceptions,
98 'not_enumerable': not_enumerable,
99 }
100 return parameter, includes
101
102
103 def get_indexed_property_setter_parameter(interface):
104 cpp_class_name = implemented_as_cpp_name(interface)
105 indexed_setter_function = get_indexed_setter_operation(interface)
106 includes = []
107 callback_name = '0'
108 is_custom = False
109 condition_and_statements = []
110 raises_exceptions = False
111 js_to_native_statement = ''
112
113 if indexed_setter_function:
114 method_name = implemented_as_cpp_name(indexed_setter_function)
115 callback_name = '%sV8Internal::indexedPropertySetterCallback' % cpp_clas s_name
116 is_custom = 'Custom' in indexed_setter_function.extended_attributes
117 raises_exceptions = 'RaisesException' in indexed_setter_function.extende d_attributes
118 treat_null_as = indexed_setter_function.arguments[1].extended_attributes .get('TreatNullAs')
119 treat_undefined_as = indexed_setter_function.arguments[1].extended_attri butes.get('TreatUndefinedAs')
120 js_value = 'value'
121 native_variable_name = 'propertyValue'
122 js_to_native_statement, js_to_native_includes = get_js_value_to_native_s tatement(indexed_setter_function.arguments[1].data_type, indexed_setter_function .extended_attributes, js_value, native_variable_name, 'info.GetIsolate()')
123 if not is_custom:
124 includes += js_to_native_includes
125
126 extra_arguments = []
127 if raises_exceptions:
128 extra_arguments = ['es']
129 if treat_null_as and treat_null_as != 'NullString':
130 arguments = ['index']
131 if raises_exceptions:
132 arguments += extra_arguments
133 condition_and_statements.append({'condition': 'value->IsNull()', 'st atement': 'collection->%s(%s);' % (treat_null_as, ', '.join(arguments))})
134 if treat_undefined_as and treat_undefined_as != 'NullString':
135 arguments = ['index']
136 if raises_exceptions:
137 arguments += extra_arguments
138 condition_and_statements.append({'condition': 'value->IsUndefined()' , 'statement': 'collection->%s(%s);' % (treat_undefined_as, ', '.join(arguments) )})
139 arguments = ['index', 'propertyValue']
140 if raises_exceptions:
141 arguments += extra_arguments
142 condition_and_statements.append({'condition': '', 'statement': 'collecti on->%s(%s);' % (method_name, ', '.join(arguments))})
143 parameter = {
144 'enabled': indexed_setter_function,
145 'callback_name': callback_name,
146 'is_custom': is_custom,
147 'condition_and_statements': condition_and_statements,
148 'raises_exceptions': raises_exceptions,
149 'js_to_native_statement': js_to_native_statement,
150 }
151 return parameter, includes
152
153
154 def get_indexed_property_deleter_parameter(interface):
155 cpp_class_name = implemented_as_cpp_name(interface)
156 indexed_deleter_function = get_indexed_deleter_operation(interface)
157 includes = []
158 callback_name = '0'
159 is_custom = False
160 if indexed_deleter_function:
161 callback_name = '%sV8Internal::indexedPropertyDeleterCallback' % cpp_cla ss_name
162 is_custom = 'Custom' in indexed_deleter_function.extended_attributes
163 parameter = {
164 'enabled': indexed_deleter_function,
165 'callback_name': callback_name,
166 'is_custom': is_custom,
167 }
168 return parameter, includes
169
170
171 def get_named_property_getter_parameter(interface):
172 cpp_class_name = implemented_as_cpp_name(interface)
173 named_getter_function = get_named_getter_operation(interface)
174 includes = []
175 callback_name = '0'
176 function_call = ''
177 return_type_is_union = ''
178 return_js_value_statement = ''
179 is_null_expression = ''
180 raises_exceptions = False
181 is_custom = False
182 not_enumerable = False
183 return_js_value_code = ''
184 is_null_expression = ''
185 raises_exceptions = False
186 override_builtins = False
187 is_return_type_union = False
188
189 if named_getter_function:
190 is_return_type_union = is_union_type(named_getter_function.data_type)
191 override_builtins = 'OverrideBuiltins' in named_getter_function.extended _attributes
192 raises_exceptions = 'RaisesException' in named_getter_function.extended_ attributes
193 is_custom = 'Custom' in named_getter_function.extended_attributes
194 callback_name = '%sV8Internal::namedPropertyGetterCallback' % cpp_class_ name
195 not_enumerable = 'NotEnumerable' in named_getter_function.extended_attri butes
196 function_call = get_function_call_statements(named_getter_function.data_ type, 'element', 'collection->' + implemented_as_cpp_name(named_getter_function) , 'propertyName', raises_exceptions=raises_exceptions)
197 is_null_expression = get_is_null_expression(named_getter_function.data_t ype, 'element')
198 native_value = get_pass_owner_expression(named_getter_function.data_type , 'element')
199 return_js_value_code, return_js_value_includes = get_native_to_js_value_ statement(named_getter_function.data_type, named_getter_function.extended_attrib utes, native_value, creation_context='info.Holder()', script_wrappable='collecti on', isolate='info.GetIsolate()', callback_info='info', used_as_return_value=Tru e, indent=' ')
200 if not is_custom:
201 includes += return_js_value_includes
202
203 parameter = {
204 'enabled': named_getter_function,
205 'callback_name': callback_name,
206 'not_enumerable': not_enumerable,
207 'is_custom': is_custom,
208 'override_builtins': override_builtins,
209 'function_call': function_call,
210 'is_null_expression': is_null_expression,
211 'return_js_value_code': return_js_value_code,
212 'is_return_type_union': is_return_type_union,
213 }
214 return parameter, includes
215
216
217 def get_named_property_setter_parameter(interface):
218 cpp_class_name = implemented_as_cpp_name(interface)
219 named_setter_function = get_named_setter_operation(interface)
220 includes = []
221 callback_name = '0'
222 is_custom = False
223 if named_setter_function:
224 is_custom = 'Custom' in named_setter_function.extended_attributes
225 callback_name = '%sV8Internal::namedPropertySetterCallback' % cpp_class_ name
226 parameter = {
227 'enabled': named_setter_function,
228 'callback_name': callback_name,
229 'is_custom': is_custom,
230 }
231 return parameter, includes
232
233
234 def get_named_property_deleter_parameter(interface):
235 cpp_class_name = implemented_as_cpp_name(interface)
236 named_deleter_function = get_named_deleter_operation(interface)
237 includes = []
238 callback_name = '0'
239 is_custom = False
240 if named_deleter_function:
241 is_custom = 'Custom' in named_deleter_function.extended_attributes
242 callback_name = '%sV8Internal::namedPropertyDeleterCallback' % cpp_class _name
243 parameter = {
244 'enabled': named_deleter_function,
245 'callback_name': callback_name,
246 'is_custom': is_custom,
247 }
248 return parameter, includes
249
250
251 def get_special_accessors_parameter(interface):
252 includes = []
253 cpp_class_name = implemented_as_cpp_name(interface)
254
255 indexed_getter_parameter, indexed_getter_includes = get_indexed_property_get ter_parameter(interface)
256 includes += indexed_getter_includes
257 indexed_setter_parameter, indexed_setter_includes = get_indexed_property_set ter_parameter(interface)
258 includes += indexed_setter_includes
259 indexed_deleter_parameter, indexed_deleter_includes = get_indexed_property_d eleter_parameter(interface)
260 includes += indexed_deleter_includes
261
262 named_getter_parameter, named_getter_includes = get_named_property_getter_pa rameter(interface)
263 includes += named_getter_includes
264 named_setter_parameter, named_setter_includes = get_named_property_setter_pa rameter(interface)
265 includes += named_setter_includes
266 named_deleter_parameter, named_deleter_includes = get_named_property_deleter _parameter(interface)
267 includes += named_deleter_includes
268
269 has_indexed_enumerator = indexed_getter_parameter['enabled']
270 has_indexed_query = False
271 if indexed_getter_parameter['not_enumerable']:
272 has_indexed_enumerator = False
273 has_named_enumerator = named_getter_parameter['enabled']
274 if named_getter_parameter['not_enumerable']:
275 has_named_enumerator = False
276 has_named_query = has_named_enumerator
277
278 indexed_enumerator_parameter = {
279 'enabled': has_indexed_enumerator,
280 'callback_name': has_indexed_enumerator and 'indexedPropertyEnumerator<% s>' % cpp_class_name or '0',
281 }
282 indexed_query_parameter = {
283 'enabled': has_indexed_query,
284 'callback_name': has_indexed_query and '%sV8Internal::indexedPropertyQue ryCallback' % cpp_class_name or '0',
285 }
286 named_enumerator_parameter = {
287 'enabled': has_named_enumerator,
288 'callback_name': has_named_enumerator and '%sV8Internal::namedPropertyEn umeratorCallback' % cpp_class_name or '0',
289 }
290 named_query_parameter = {
291 'enabled': has_named_query,
292 'callback_name': has_named_query and '%sV8Internal::namedPropertyQueryCa llback' % cpp_class_name or '0',
293 }
294
295 set_on = 'Instance'
296 if interface.name == 'Window':
297 set_on = 'Prototype'
298
299 parameter = {
300 'set_on': set_on,
301 'indexed': {
302 'getter': indexed_getter_parameter,
303 'setter': indexed_setter_parameter,
304 'deleter': indexed_deleter_parameter,
305 'enumerator': indexed_enumerator_parameter,
306 'query': indexed_query_parameter,
307 },
308 'named': {
309 'getter': named_getter_parameter,
310 'setter': named_setter_parameter,
311 'deleter': named_deleter_parameter,
312 'enumerator': named_enumerator_parameter,
313 'query': named_query_parameter,
314 },
315 }
316 return parameter, includes
317
318
319 def get_special_accessor_operation_for_type(interface, special, first_parameter_ type, number_of_parameters):
320 for operation in interface.operations:
321 if (special in operation.specials and
322 len(operation.arguments) == number_of_parameters and
323 operation.arguments[0].data_type == first_parameter_type):
324 return operation
325 return None
326
327
328 def get_indexed_getter_operation(interface):
329 return get_special_accessor_operation_for_type(interface, 'getter', 'unsigne d long', 1)
330
331
332 def get_indexed_setter_operation(interface):
333 return get_special_accessor_operation_for_type(interface, 'setter', 'unsigne d long', 2)
334
335
336 def get_indexed_deleter_operation(interface):
337 return get_special_accessor_operation_for_type(interface, 'deleter', 'unsign ed long', 1)
338
339
340 def get_named_getter_operation(interface):
341 return get_special_accessor_operation_for_type(interface, 'getter', 'DOMStri ng', 1)
342
343
344 def get_named_setter_operation(interface):
345 return get_special_accessor_operation_for_type(interface, 'setter', 'DOMStri ng', 2)
346
347
348 def get_named_deleter_operation(interface):
349 return get_special_accessor_operation_for_type(interface, 'deleter', 'DOMStr ing', 1)
350
351
352 def has_custom_accessors(interface):
353 return {
354 'has_custom_indexed_getter': has_custom_implementation(get_indexed_gette r_operation(interface)),
355 'has_custom_indexed_setter': has_custom_implementation(get_indexed_sette r_operation(interface)),
356 'has_custom_indexed_deleter': has_custom_implementation(get_indexed_dele ter_operation(interface)),
357 'has_custom_named_getter': has_custom_implementation(get_named_getter_op eration(interface)),
358 'has_custom_named_setter': has_custom_implementation(get_named_setter_op eration(interface)),
359 'has_custom_named_deleter': has_custom_implementation(get_named_deleter_ operation(interface)),
360 }
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_interface_header.py ('k') | Source/bindings/scripts/v8_types.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698