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

Side by Side Diff: bindings/dart/scripts/dart_methods.py

Issue 540533002: Roll IDL to Dartium37 (r181268) (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « bindings/dart/scripts/dart_interface.py ('k') | bindings/dart/scripts/dart_tests.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 """Generate template values for methods.
30
31 Extends IdlType and IdlUnionType with property |union_arguments|.
32
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
34 """
35
36 from idl_types import IdlType, IdlUnionType, inherits_interface
37 import dart_types
38 from dart_utilities import DartUtilities
39 from v8_globals import includes
40
41
42 def generate_method(interface, method):
43 arguments = method.arguments
44 extended_attributes = method.extended_attributes
45 idl_type = method.idl_type
46 is_static = method.is_static
47 name = method.name
48
49 idl_type.add_includes_for_type()
50 this_cpp_value = cpp_value(interface, method, len(arguments))
51
52 def function_template():
53 if is_static:
54 return 'functionTemplate'
55 if 'Unforgeable' in extended_attributes:
56 return 'instanceTemplate'
57 return 'prototypeTemplate'
58
59 is_call_with_script_arguments = DartUtilities.has_extended_attribute_value(m ethod, 'CallWith', 'ScriptArguments')
60 if is_call_with_script_arguments:
61 includes.update(['bindings/v8/ScriptCallStackFactory.h',
62 'core/inspector/ScriptArguments.h'])
63 is_call_with_script_state = DartUtilities.has_extended_attribute_value(metho d, 'CallWith', 'ScriptState')
64 if is_call_with_script_state:
65 includes.add('bindings/dart/DartScriptState.h')
66 is_check_security_for_node = 'CheckSecurity' in extended_attributes
67 if is_check_security_for_node:
68 includes.add('bindings/common/BindingSecurity.h')
69 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s
70 if is_custom_element_callbacks:
71 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')
72
73 has_event_listener_argument = any(
74 argument for argument in arguments
75 if argument.idl_type.name == 'EventListener')
76 is_check_security_for_frame = (
77 'CheckSecurity' in interface.extended_attributes and
78 'DoNotCheckSecurity' not in extended_attributes)
79 is_raises_exception = 'RaisesException' in extended_attributes
80
81 if idl_type.union_arguments and len(idl_type.union_arguments) > 0:
82 this_cpp_type = []
83 for cpp_type in idl_type.member_types:
84 this_cpp_type.append("RefPtr<%s>" % cpp_type)
85 else:
86 this_cpp_type = idl_type.cpp_type
87
88 is_auto_scope = not 'DartNoAutoScope' in extended_attributes
89 method_data = {
90 'activity_logging_world_list': DartUtilities.activity_logging_world_list (method), # [ActivityLogging]
91 'arguments': [generate_argument(interface, method, argument, index)
92 for index, argument in enumerate(arguments)],
93 'conditional_string': DartUtilities.conditional_string(method),
94 'cpp_type': this_cpp_type,
95 'cpp_value': this_cpp_value,
96 'dart_name': extended_attributes.get('DartName'),
97 'deprecate_as': DartUtilities.deprecate_as(method), # [DeprecateAs]
98 'do_not_check_signature': not(is_static or
99 DartUtilities.has_extended_attribute(method,
100 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable',
101 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])),
102 'function_template': function_template(),
103 'idl_type': idl_type.base_type,
104 'has_event_listener_argument': has_event_listener_argument,
105 'has_exception_state':
106 has_event_listener_argument or
107 is_raises_exception or
108 is_check_security_for_frame or
109 any(argument for argument in arguments
110 if argument.idl_type.name == 'SerializedScriptValue' or
111 argument.idl_type.is_integer_type),
112 'is_auto_scope': is_auto_scope,
113 'auto_scope': DartUtilities.bool_to_cpp(is_auto_scope),
114 'is_call_with_execution_context': DartUtilities.has_extended_attribute_v alue(method, 'CallWith', 'ExecutionContext'),
115 'is_call_with_script_arguments': is_call_with_script_arguments,
116 'is_call_with_script_state': is_call_with_script_state,
117 'is_check_security_for_frame': is_check_security_for_frame,
118 'is_check_security_for_node': is_check_security_for_node,
119 'is_custom': 'Custom' in extended_attributes or 'DartCustom' in extended _attributes,
120 'is_custom_dart': 'DartCustom' in extended_attributes,
121 'is_custom_dart_new': DartUtilities.has_extended_attribute_value(method, 'DartCustom', 'New'),
122 'is_custom_element_callbacks': is_custom_element_callbacks,
123 'is_do_not_check_security': 'DoNotCheckSecurity' in extended_attributes,
124 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attribute s,
125 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in extend ed_attributes,
126 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
127 'is_raises_exception': is_raises_exception,
128 'is_read_only': 'ReadOnly' in extended_attributes,
129 'is_static': is_static,
130 # FIXME(terry): StrictTypeChecking no longer supported; TypeChecking is
131 # new extended attribute.
132 'is_strict_type_checking':
133 'StrictTypeChecking' in extended_attributes or
134 'StrictTypeChecking' in interface.extended_attributes,
135 'is_variadic': arguments and arguments[-1].is_variadic,
136 'measure_as': DartUtilities.measure_as(method), # [MeasureAs]
137 'name': name,
138 'number_of_arguments': len(arguments),
139 'number_of_required_arguments': len([
140 argument for argument in arguments
141 if not ((argument.is_optional and not ('Default' in argument.extende d_attributes or argument.default_value)) or
142 argument.is_variadic)]),
143 'number_of_required_or_variadic_arguments': len([
144 argument for argument in arguments
145 if not argument.is_optional]),
146 'per_context_enabled_function': DartUtilities.per_context_enabled_functi on_name(method), # [PerContextEnabled]
147 'property_attributes': property_attributes(method),
148 'runtime_enabled_function': DartUtilities.runtime_enabled_function_name( method), # [RuntimeEnabled]
149 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature',
150 'suppressed': (arguments and arguments[-1].is_variadic), # FIXME: imple ment variadic
151 'union_arguments': idl_type.union_arguments,
152 'dart_set_return_value': dart_set_return_value(interface.name, method, t his_cpp_value),
153 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings]
154 }
155 return method_data
156
157
158 def generate_argument(interface, method, argument, index):
159 extended_attributes = argument.extended_attributes
160 idl_type = argument.idl_type
161 this_cpp_value = cpp_value(interface, method, index)
162 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type
163 use_heap_vector_type = is_variadic_wrapper_type and idl_type.is_will_be_garb age_collected
164 auto_scope = not 'DartNoAutoScope' in extended_attributes
165 this_has_default = 'Default' in extended_attributes
166 arg_index = index + 1 if not method.is_static else index
167 preprocessed_type = str(idl_type.preprocessed_type)
168 # FIXMEDART: handle the drift between preprocessed type names in 1847 and
169 # 1985 dartium builds in a more generic way.
170 if preprocessed_type == 'unrestricted float':
171 preprocessed_type = 'float'
172 if preprocessed_type == 'unrestricted double':
173 preprocessed_type = 'double'
174 argument_data = {
175 'cpp_type': idl_type.cpp_type_args(used_in_cpp_sequence=use_heap_vector_ type),
176 'cpp_value': this_cpp_value,
177 'local_cpp_type': idl_type.cpp_type_args(argument.extended_attributes, u sed_as_argument=True),
178 # FIXME: check that the default value's type is compatible with the argu ment's
179 'default_value': str(argument.default_value) if argument.default_value e lse None,
180 'enum_validation_expression': idl_type.enum_validation_expression,
181 # Ignore 'Default' in extended_attributes not exposed in dart:html.
182 'has_default': False,
183 'has_event_listener_argument': any(
184 argument_so_far for argument_so_far in method.arguments[:index]
185 if argument_so_far.idl_type.name == 'EventListener'),
186 'idl_type_object': idl_type,
187 'preprocessed_type': preprocessed_type,
188 # Dictionary is special-cased, but arrays and sequences shouldn't be
189 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type,
190 'index': index,
191 'is_array_or_sequence_type': not not idl_type.array_or_sequence_type,
192 'is_clamp': 'Clamp' in extended_attributes,
193 'is_callback_interface': idl_type.is_callback_interface,
194 'is_nullable': idl_type.is_nullable,
195 # Only expose as optional if no default value.
196 'is_optional': argument.is_optional and not (this_has_default or argumen t.default_value),
197 'is_strict_type_checking': 'StrictTypeChecking' in extended_attributes,
198 'is_variadic_wrapper_type': is_variadic_wrapper_type,
199 'vector_type': 'WillBeHeapVector' if use_heap_vector_type else 'Vector',
200 'is_wrapper_type': idl_type.is_wrapper_type,
201 'name': argument.name,
202 'dart_set_return_value_for_main_world': dart_set_return_value(interface. name, method, this_cpp_value, for_main_world=True),
203 'dart_set_return_value': dart_set_return_value(interface.name, method, t his_cpp_value),
204 'arg_index': arg_index,
205 'dart_value_to_local_cpp_value': dart_value_to_local_cpp_value(interface , argument, arg_index, auto_scope),
206 }
207 return argument_data
208
209
210 ################################################################################
211 # Value handling
212 ################################################################################
213
214 def cpp_value(interface, method, number_of_arguments):
215 def cpp_argument(argument):
216 argument_name = dart_types.check_reserved_name(argument.name)
217 idl_type = argument.idl_type
218
219 if idl_type.is_typed_array_type:
220 return '%s.get()' % argument_name
221
222 if idl_type.name == 'EventListener':
223 if (interface.name == 'EventTarget' and
224 method.name == 'removeEventListener'):
225 # FIXME: remove this special case by moving get() into
226 # EventTarget::removeEventListener
227 return '%s.get()' % argument_name
228 return argument.name
229 if (idl_type.is_callback_interface or
230 idl_type.name in ['NodeFilter', 'XPathNSResolver']):
231 # FIXME: remove this special case
232 return '%s.release()' % argument_name
233 return argument_name
234
235 # Truncate omitted optional arguments
236 arguments = method.arguments[:number_of_arguments]
237 cpp_arguments = DartUtilities.call_with_arguments(method)
238 if ('PartialInterfaceImplementedAs' in method.extended_attributes and not me thod.is_static):
239 cpp_arguments.append('*receiver')
240
241 cpp_arguments.extend(cpp_argument(argument) for argument in arguments)
242 this_union_arguments = method.idl_type.union_arguments
243 if this_union_arguments:
244 cpp_arguments.extend(this_union_arguments)
245
246 if 'RaisesException' in method.extended_attributes:
247 cpp_arguments.append('es')
248
249 cpp_method_name = DartUtilities.scoped_name(interface, method, DartUtilities .cpp_name(method))
250 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
251
252
253 # Mapping of IDL type to DartUtilities helper types.
254 def dart_arg_type(argument_type):
255 if (argument_type.cpp_type == 'String'):
256 return 'DartStringAdapter'
257
258 return argument_type.cpp_type
259
260
261 def dart_set_return_value(interface_name, method, cpp_value, for_main_world=Fals e):
262 idl_type = method.idl_type
263 extended_attributes = method.extended_attributes
264 if idl_type.name == 'void':
265 return None
266
267 release = False
268
269 if idl_type.is_union_type:
270 release = idl_type.release
271
272 # [CallWith=ScriptState], [RaisesException]
273 # TODO(terry): Disable ScriptState temporarily need to handle.
274 # if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
275 # 'RaisesException' in extended_attributes or
276 # idl_type.is_union_type):
277 # cpp_value = 'result' # use local variable for value
278 # release = idl_type.release
279
280 auto_scope = not 'DartNoAutoScope' in extended_attributes
281 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
282 return idl_type.dart_set_return_value(cpp_value, extended_attributes,
283 script_wrappable=script_wrappable,
284 release=release,
285 for_main_world=for_main_world,
286 auto_scope=auto_scope)
287
288
289 def dart_value_to_local_cpp_value(interface, argument, index, auto_scope=True):
290 extended_attributes = argument.extended_attributes
291 interface_extended_attributes = interface.extended_attributes
292 idl_type = argument.idl_type
293 name = argument.name
294 # TODO(terry): Variadic arguments are not handled but treated as one argumen t.
295 # if argument.is_variadic:
296 # vector_type = 'WillBeHeapVector' if idl_type.is_will_be_garbage_col lected else 'Vector'
297 # return 'V8TRYCATCH_VOID({vector_type}<{cpp_type}>, {name}, toNative Arguments<{cpp_type}>(info, {index}))'.format(
298 # cpp_type=idl_type.cpp_type, name=name, index=index, vector_ type=vector_type)
299
300 # FIXME: V8 has some special logic around the addEventListener and
301 # removeEventListener methods that should be added in somewhere.
302 # There is also some logic in systemnative.py to force a null check
303 # for the useCapture argument of those same methods that we may need to
304 # pull over.
305 null_check = (argument.is_optional and \
306 (idl_type.is_callback_interface or idl_type == 'Dictionary')) or \
307 (argument.default_value and argument.default_value.is_null)
308
309 return idl_type.dart_value_to_local_cpp_value(
310 interface_extended_attributes, extended_attributes, name, null_check,
311 index=index, auto_scope=auto_scope)
312
313
314 ################################################################################
315 # Auxiliary functions
316 ################################################################################
317
318 # [NotEnumerable]
319 def property_attributes(method):
320 extended_attributes = method.extended_attributes
321 property_attributes_list = []
322 if 'NotEnumerable' in extended_attributes:
323 property_attributes_list.append('v8::DontEnum')
324 if 'ReadOnly' in extended_attributes:
325 property_attributes_list.append('v8::ReadOnly')
326 if property_attributes_list:
327 property_attributes_list.insert(0, 'v8::DontDelete')
328 return property_attributes_list
329
330
331 def union_arguments(idl_type):
332 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value"""
333 return [arg
334 for i in range(len(idl_type.member_types))
335 for arg in ['result%sEnabled' % i, 'result%s' % i]]
336
337 IdlType.union_arguments = property(lambda self: None)
338 IdlUnionType.union_arguments = property(union_arguments)
OLDNEW
« no previous file with comments | « bindings/dart/scripts/dart_interface.py ('k') | bindings/dart/scripts/dart_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698