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

Side by Side Diff: sky/engine/bindings-dart/dart/scripts/dart_methods.py

Issue 918273002: Remove bindings-dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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 # 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 inherits_interface
37 import dart_types
38 from dart_utilities import DartUtilities
39 from v8_globals import includes
40
41 import v8_methods
42
43
44 def method_context(interface, method):
45 context = v8_methods.method_context(interface, method)
46
47 arguments = method.arguments
48 extended_attributes = method.extended_attributes
49 idl_type = method.idl_type
50
51 # idl_type.add_includes_for_type()
52 this_cpp_value = cpp_value(interface, method, len(arguments))
53
54 if context['is_call_with_script_state']:
55 includes.add('bindings/core/dart/DartScriptState.h')
56
57 if idl_type.union_arguments and len(idl_type.union_arguments) > 0:
58 this_cpp_type = []
59 for cpp_type in idl_type.member_types:
60 # FIXMEDART: we shouldn't just assume RefPtr. We should append
61 # WillBeGC as appropriate.
62 this_cpp_type.append("RefPtr<%s>" % cpp_type)
63 else:
64 this_cpp_type = idl_type.cpp_type
65
66 is_auto_scope = not 'DartNoAutoScope' in extended_attributes
67
68 arguments_data = [argument_context(interface, method, argument, index)
69 for index, argument in enumerate(arguments)]
70
71 union_arguments = []
72 if idl_type.union_arguments:
73 union_arguments.extend([union_arg['cpp_value']
74 for union_arg in idl_type.union_arguments])
75
76 is_custom = 'Custom' in extended_attributes or 'DartCustom' in extended_attr ibutes
77
78 context.update({
79 'activity_logging_world_list': DartUtilities.activity_logging_world_list (method), # [ActivityLogging]
80 'arguments': arguments_data,
81 'cpp_type': this_cpp_type,
82 'cpp_value': this_cpp_value,
83 'dart_name': extended_attributes.get('DartName'),
84 'deprecate_as': DartUtilities.deprecate_as(method), # [DeprecateAs]
85 'do_not_check_signature': not(context['is_static'] or
86 DartUtilities.has_extended_attribute(method,
87 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable',
88 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])),
89 'has_exception_state':
90 context['is_raises_exception'] or
91 context['is_check_security_for_frame'] or
92 any(argument for argument in arguments
93 if argument.idl_type.name == 'SerializedScriptValue' or
94 argument.idl_type.is_integer_type),
95 'is_auto_scope': is_auto_scope,
96 'auto_scope': DartUtilities.bool_to_cpp(is_auto_scope),
97 'is_custom': is_custom,
98 'is_custom_dart': 'DartCustom' in extended_attributes,
99 'is_custom_dart_new': DartUtilities.has_extended_attribute_value(method, 'DartCustom', 'New'),
100 # FIXME(terry): DartStrictTypeChecking no longer supported; TypeChecking is
101 # new extended attribute.
102 'is_strict_type_checking':
103 'DartStrictTypeChecking' in extended_attributes or
104 'DartStrictTypeChecking' in interface.extended_attributes,
105 'measure_as': DartUtilities.measure_as(method), # [MeasureAs]
106 'suppressed': (arguments and arguments[-1].is_variadic), # FIXME: imple ment variadic
107 'union_arguments': union_arguments,
108 'dart_set_return_value': dart_set_return_value(interface.name, method, t his_cpp_value),
109 })
110 return context
111
112 def argument_context(interface, method, argument, index):
113 context = v8_methods.argument_context(interface, method, argument, index)
114
115 extended_attributes = argument.extended_attributes
116 idl_type = argument.idl_type
117 this_cpp_value = cpp_value(interface, method, index)
118 use_heap_vector_type = context['is_variadic_wrapper_type'] and idl_type.is_w ill_be_garbage_collected
119 auto_scope = not 'DartNoAutoScope' in extended_attributes
120 arg_index = index + 1 if not (method.is_static or method.is_constructor) els e index
121 preprocessed_type = str(idl_type.preprocessed_type)
122 local_cpp_type = idl_type.cpp_type_args(argument.extended_attributes, raw_ty pe=True)
123 default_value = argument.default_cpp_value
124 if context['has_default']:
125 default_value = (argument.default_cpp_value or
126 dart_types.default_cpp_value_for_cpp_type(idl_type))
127 # FIXMEDART: handle the drift between preprocessed type names in 1847 and
128 # 1985 dartium builds in a more generic way.
129 if preprocessed_type == 'unrestricted float':
130 preprocessed_type = 'float'
131 if preprocessed_type == 'unrestricted double':
132 preprocessed_type = 'double'
133 context.update({
134 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es,
135 raw_type=True,
136 used_in_cpp_sequence=use_heap_vector_ type),
137 'cpp_value': this_cpp_value,
138 'local_cpp_type': local_cpp_type,
139 # FIXME: check that the default value's type is compatible with the argu ment's
140 'default_value': default_value,
141 'enum_validation_expression': idl_type.enum_validation_expression,
142 'preprocessed_type': preprocessed_type,
143 'is_array_or_sequence_type': not not idl_type.native_array_element_type,
144 'is_strict_type_checking': 'DartStrictTypeChecking' in extended_attribut es,
145 'vector_type': 'WillBeHeapVector' if use_heap_vector_type else 'Vector',
146 'dart_set_return_value_for_main_world': dart_set_return_value(interface. name, method,
147 this_cpp_v alue, for_main_world=True),
148 'dart_set_return_value': dart_set_return_value(interface.name, method, t his_cpp_value),
149 'arg_index': arg_index,
150 'dart_value_to_local_cpp_value': dart_value_to_local_cpp_value(interface ,
151 context[' has_type_checking_interface'],
152 argument, arg_index, auto_scope),
153 })
154 return context
155
156
157 ################################################################################
158 # Value handling
159 ################################################################################
160
161 def cpp_value(interface, method, number_of_arguments):
162 def cpp_argument(argument):
163 argument_name = dart_types.check_reserved_name(argument.name)
164 idl_type = argument.idl_type
165
166 if idl_type.is_typed_array_type:
167 return '%s.get()' % argument_name
168
169 if idl_type.name == 'EventListener':
170 if (interface.name == 'EventTarget' and
171 method.name == 'removeEventListener'):
172 # FIXME: remove this special case by moving get() into
173 # EventTarget::removeEventListener
174 return '%s.get()' % argument_name
175 return argument.name
176 if (idl_type.is_callback_interface or
177 idl_type.name in ['NodeFilter', 'XPathNSResolver']):
178 # FIXME: remove this special case
179 return '%s.release()' % argument_name
180 return argument_name
181
182 # Truncate omitted optional arguments
183 arguments = method.arguments[:number_of_arguments]
184 if method.is_constructor:
185 call_with_values = interface.extended_attributes.get('ConstructorCallWit h')
186 else:
187 call_with_values = method.extended_attributes.get('CallWith')
188 cpp_arguments = DartUtilities.call_with_arguments(call_with_values)
189 if ('PartialInterfaceImplementedAs' in method.extended_attributes and not me thod.is_static):
190 cpp_arguments.append('*receiver')
191
192 cpp_arguments.extend(cpp_argument(argument) for argument in arguments)
193 this_union_arguments = method.idl_type and method.idl_type.union_arguments
194 if this_union_arguments:
195 cpp_arguments.extend([member_argument['cpp_value']
196 for member_argument in this_union_arguments])
197
198 if ('RaisesException' in method.extended_attributes or
199 (method.is_constructor and
200 DartUtilities.has_extended_attribute_value(interface, 'RaisesException' , 'Constructor'))):
201 cpp_arguments.append('es')
202
203 if method.name == 'Constructor':
204 base_name = 'create'
205 elif method.name == 'NamedConstructor':
206 base_name = 'createForJSConstructor'
207 else:
208 base_name = DartUtilities.cpp_name(method)
209 cpp_method_name = DartUtilities.scoped_name(interface, method, base_name)
210 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
211
212
213 # Mapping of IDL type to DartUtilities helper types.
214 def dart_arg_type(argument_type):
215 if (argument_type.cpp_type == 'String'):
216 return 'DartStringAdapter'
217
218 return argument_type.cpp_type
219
220
221 def dart_set_return_value(interface_name, method, cpp_value, for_main_world=Fals e):
222 idl_type = method.idl_type
223 extended_attributes = method.extended_attributes
224 if not idl_type or idl_type.name == 'void':
225 # Constructors and void methods don't have a return type
226 return None
227
228 release = False
229
230 if idl_type.is_union_type:
231 release = idl_type.release
232
233 # [CallWith=ScriptState], [RaisesException]
234 # TODO(terry): Disable ScriptState temporarily need to handle.
235 # if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
236 # 'RaisesException' in extended_attributes or
237 # idl_type.is_union_type):
238 # cpp_value = 'result' # use local variable for value
239 # release = idl_type.release
240
241 auto_scope = not 'DartNoAutoScope' in extended_attributes
242 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
243 return idl_type.dart_set_return_value(cpp_value, extended_attributes,
244 script_wrappable=script_wrappable,
245 release=release,
246 for_main_world=for_main_world,
247 auto_scope=auto_scope)
248
249
250 def dart_value_to_local_cpp_value(interface, has_type_checking_interface,
251 argument, index, auto_scope=True):
252 extended_attributes = argument.extended_attributes
253 idl_type = argument.idl_type
254 name = argument.name
255 # TODO(terry): Variadic arguments are not handled but treated as one argumen t.
256 # if argument.is_variadic:
257 # vector_type = 'WillBeHeapVector' if idl_type.is_will_be_garbage_col lected else 'Vector'
258 # return 'V8TRYCATCH_VOID({vector_type}<{cpp_type}>, {name}, toNative Arguments<{cpp_type}>(info, {index}))'.format(
259 # cpp_type=idl_type.cpp_type, name=name, index=index, vector_ type=vector_type)
260
261 # FIXME: V8 has some special logic around the addEventListener and
262 # removeEventListener methods that should be added in somewhere.
263 # There is also some logic in systemnative.py to force a null check
264 # for the useCapture argument of those same methods that we may need to
265 # pull over.
266 null_check = ((argument.is_optional and idl_type.is_callback_interface) or
267 (idl_type.name == 'Dictionary') or
268 (argument.default_value and argument.default_value.is_null))
269
270 return idl_type.dart_value_to_local_cpp_value(
271 extended_attributes, name, null_check, has_type_checking_interface,
272 index=index, auto_scope=auto_scope)
OLDNEW
« no previous file with comments | « sky/engine/bindings-dart/dart/scripts/dart_interface.py ('k') | sky/engine/bindings-dart/dart/scripts/dart_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698