OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 15 matching lines...) Expand all Loading... |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 """Generate template values for methods. | 29 """Generate template values for methods. |
30 | 30 |
31 Extends IdlType and IdlUnionType with property |union_arguments|. | 31 Extends IdlType and IdlUnionType with property |union_arguments|. |
32 | 32 |
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
34 """ | 34 """ |
35 | 35 |
36 from idl_types import IdlTypeBase, IdlType, IdlUnionType, inherits_interface, Id
lArrayOrSequenceType, IdlArrayType | 36 from idl_types import inherits_interface |
37 import dart_types | 37 import dart_types |
38 from idl_definitions import IdlArgument | |
39 from dart_utilities import DartUtilities | 38 from dart_utilities import DartUtilities |
40 from v8_globals import includes | 39 from v8_globals import includes |
41 | 40 |
| 41 import v8_methods |
42 | 42 |
43 def generate_method(interface, method): | 43 |
| 44 def method_context(interface, method): |
| 45 context = v8_methods.method_context(interface, method) |
| 46 |
44 arguments = method.arguments | 47 arguments = method.arguments |
45 extended_attributes = method.extended_attributes | 48 extended_attributes = method.extended_attributes |
46 idl_type = method.idl_type | 49 idl_type = method.idl_type |
47 is_static = method.is_static | |
48 name = method.name | |
49 | 50 |
50 idl_type.add_includes_for_type() | 51 # idl_type.add_includes_for_type() |
51 this_cpp_value = cpp_value(interface, method, len(arguments)) | 52 this_cpp_value = cpp_value(interface, method, len(arguments)) |
52 | 53 |
53 def function_template(): | 54 if context['is_call_with_script_state']: |
54 if is_static: | |
55 return 'functionTemplate' | |
56 if 'Unforgeable' in extended_attributes: | |
57 return 'instanceTemplate' | |
58 return 'prototypeTemplate' | |
59 | |
60 is_call_with_script_arguments = DartUtilities.has_extended_attribute_value(m
ethod, 'CallWith', 'ScriptArguments') | |
61 if is_call_with_script_arguments: | |
62 includes.update(['bindings/core/v8/ScriptCallStackFactory.h', | |
63 'core/inspector/ScriptArguments.h']) | |
64 is_call_with_script_state = DartUtilities.has_extended_attribute_value(metho
d, 'CallWith', 'ScriptState') | |
65 if is_call_with_script_state: | |
66 includes.add('bindings/core/dart/DartScriptState.h') | 55 includes.add('bindings/core/dart/DartScriptState.h') |
67 is_check_security_for_node = 'CheckSecurity' in extended_attributes | |
68 if is_check_security_for_node: | |
69 includes.add('bindings/common/BindingSecurity.h') | |
70 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute
s | |
71 if is_custom_element_callbacks: | |
72 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') | |
73 | |
74 has_event_listener_argument = any( | |
75 argument for argument in arguments | |
76 if argument.idl_type.name == 'EventListener') | |
77 is_check_security_for_frame = ( | |
78 'CheckSecurity' in interface.extended_attributes and | |
79 'DoNotCheckSecurity' not in extended_attributes) | |
80 is_raises_exception = 'RaisesException' in extended_attributes | |
81 | 56 |
82 if idl_type.union_arguments and len(idl_type.union_arguments) > 0: | 57 if idl_type.union_arguments and len(idl_type.union_arguments) > 0: |
83 this_cpp_type = [] | 58 this_cpp_type = [] |
84 for cpp_type in idl_type.member_types: | 59 for cpp_type in idl_type.member_types: |
85 # FIXMEDART: we shouldn't just assume RefPtr. We should append | 60 # FIXMEDART: we shouldn't just assume RefPtr. We should append |
86 # WillBeGC as appropriate. | 61 # WillBeGC as appropriate. |
87 this_cpp_type.append("RefPtr<%s>" % cpp_type) | 62 this_cpp_type.append("RefPtr<%s>" % cpp_type) |
88 else: | 63 else: |
89 this_cpp_type = idl_type.cpp_type | 64 this_cpp_type = idl_type.cpp_type |
90 | 65 |
91 is_auto_scope = not 'DartNoAutoScope' in extended_attributes | 66 is_auto_scope = not 'DartNoAutoScope' in extended_attributes |
92 | 67 |
93 number_of_arguments = len(arguments) | 68 arguments_data = [argument_context(interface, method, argument, index) |
| 69 for index, argument in enumerate(arguments)] |
94 | 70 |
95 number_of_required_arguments = \ | 71 union_arguments = [] |
96 len([ | 72 if idl_type.union_arguments: |
97 argument for argument in arguments | 73 union_arguments.extend([union_arg['cpp_value'] |
98 if not ((argument.is_optional and not ('Default' in argument.extende
d_attributes or argument.default_value)) or | 74 for union_arg in idl_type.union_arguments]) |
99 argument.is_variadic)]) | |
100 | |
101 arguments_data = [generate_argument(interface, method, argument, index) | |
102 for index, argument in enumerate(arguments)] | |
103 | 75 |
104 is_custom = 'Custom' in extended_attributes or 'DartCustom' in extended_attr
ibutes | 76 is_custom = 'Custom' in extended_attributes or 'DartCustom' in extended_attr
ibutes |
105 | 77 |
106 method_data = { | 78 context.update({ |
107 'activity_logging_world_list': DartUtilities.activity_logging_world_list
(method), # [ActivityLogging] | 79 'activity_logging_world_list': DartUtilities.activity_logging_world_list
(method), # [ActivityLogging] |
108 'arguments': arguments_data, | 80 'arguments': arguments_data, |
109 'conditional_string': DartUtilities.conditional_string(method), | |
110 'cpp_type': this_cpp_type, | 81 'cpp_type': this_cpp_type, |
111 'cpp_value': this_cpp_value, | 82 'cpp_value': this_cpp_value, |
112 'dart_name': extended_attributes.get('DartName'), | 83 'dart_name': extended_attributes.get('DartName'), |
113 'deprecate_as': DartUtilities.deprecate_as(method), # [DeprecateAs] | 84 'deprecate_as': DartUtilities.deprecate_as(method), # [DeprecateAs] |
114 'do_not_check_signature': not(is_static or | 85 'do_not_check_signature': not(context['is_static'] or |
115 DartUtilities.has_extended_attribute(method, | 86 DartUtilities.has_extended_attribute(method, |
116 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable', | 87 ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable', |
117 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])), | 88 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])), |
118 'function_template': function_template(), | |
119 'idl_type': idl_type.base_type, | |
120 'has_event_listener_argument': has_event_listener_argument, | |
121 'has_exception_state': | 89 'has_exception_state': |
122 has_event_listener_argument or | 90 context['is_raises_exception'] or |
123 is_raises_exception or | 91 context['is_check_security_for_frame'] or |
124 is_check_security_for_frame or | |
125 any(argument for argument in arguments | 92 any(argument for argument in arguments |
126 if argument.idl_type.name == 'SerializedScriptValue' or | 93 if argument.idl_type.name == 'SerializedScriptValue' or |
127 argument.idl_type.is_integer_type), | 94 argument.idl_type.is_integer_type), |
128 'is_auto_scope': is_auto_scope, | 95 'is_auto_scope': is_auto_scope, |
129 'auto_scope': DartUtilities.bool_to_cpp(is_auto_scope), | 96 'auto_scope': DartUtilities.bool_to_cpp(is_auto_scope), |
130 'is_call_with_execution_context': DartUtilities.has_extended_attribute_v
alue(method, 'CallWith', 'ExecutionContext'), | |
131 'is_call_with_script_arguments': is_call_with_script_arguments, | |
132 'is_call_with_script_state': is_call_with_script_state, | |
133 'is_check_security_for_frame': is_check_security_for_frame, | |
134 'is_check_security_for_node': is_check_security_for_node, | |
135 'is_custom': is_custom, | 97 'is_custom': is_custom, |
136 'is_custom_dart': 'DartCustom' in extended_attributes, | 98 'is_custom_dart': 'DartCustom' in extended_attributes, |
137 'is_custom_dart_new': DartUtilities.has_extended_attribute_value(method,
'DartCustom', 'New'), | 99 'is_custom_dart_new': DartUtilities.has_extended_attribute_value(method,
'DartCustom', 'New'), |
138 'is_custom_element_callbacks': is_custom_element_callbacks, | |
139 'is_do_not_check_security': 'DoNotCheckSecurity' in extended_attributes, | |
140 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attribute
s, | |
141 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in extend
ed_attributes, | |
142 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, | |
143 'is_raises_exception': is_raises_exception, | |
144 'is_read_only': 'ReadOnly' in extended_attributes, | |
145 'is_static': is_static, | |
146 # FIXME(terry): DartStrictTypeChecking no longer supported; TypeChecking
is | 100 # FIXME(terry): DartStrictTypeChecking no longer supported; TypeChecking
is |
147 # new extended attribute. | 101 # new extended attribute. |
148 'is_strict_type_checking': | 102 'is_strict_type_checking': |
149 'DartStrictTypeChecking' in extended_attributes or | 103 'DartStrictTypeChecking' in extended_attributes or |
150 'DartStrictTypeChecking' in interface.extended_attributes, | 104 'DartStrictTypeChecking' in interface.extended_attributes, |
151 'is_variadic': arguments and arguments[-1].is_variadic, | |
152 'measure_as': DartUtilities.measure_as(method), # [MeasureAs] | 105 'measure_as': DartUtilities.measure_as(method), # [MeasureAs] |
153 'name': name, | |
154 'number_of_arguments': number_of_arguments, | |
155 'number_of_required_arguments': number_of_required_arguments, | |
156 'number_of_required_or_variadic_arguments': len([ | |
157 argument for argument in arguments | |
158 if not argument.is_optional]), | |
159 'per_context_enabled_function': DartUtilities.per_context_enabled_functi
on_name(method), # [PerContextEnabled] | |
160 'property_attributes': property_attributes(method), | |
161 'runtime_enabled_function': DartUtilities.runtime_enabled_function_name(
method), # [RuntimeEnabled] | |
162 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig
nature' in extended_attributes else 'defaultSignature', | |
163 'suppressed': (arguments and arguments[-1].is_variadic), # FIXME: imple
ment variadic | 106 'suppressed': (arguments and arguments[-1].is_variadic), # FIXME: imple
ment variadic |
164 'union_arguments': idl_type.union_arguments, | 107 'union_arguments': union_arguments, |
165 'dart_set_return_value': dart_set_return_value(interface.name, method, t
his_cpp_value), | 108 'dart_set_return_value': dart_set_return_value(interface.name, method, t
his_cpp_value), |
166 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings] | 109 }) |
167 } | 110 return context |
168 return method_data | |
169 | 111 |
| 112 def argument_context(interface, method, argument, index): |
| 113 context = v8_methods.argument_context(interface, method, argument, index) |
170 | 114 |
171 def generate_argument(interface, method, argument, index): | |
172 extended_attributes = argument.extended_attributes | 115 extended_attributes = argument.extended_attributes |
173 idl_type = argument.idl_type | 116 idl_type = argument.idl_type |
174 this_cpp_value = cpp_value(interface, method, index) | 117 this_cpp_value = cpp_value(interface, method, index) |
175 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type | 118 use_heap_vector_type = context['is_variadic_wrapper_type'] and idl_type.is_w
ill_be_garbage_collected |
176 use_heap_vector_type = is_variadic_wrapper_type and idl_type.is_will_be_garb
age_collected | |
177 auto_scope = not 'DartNoAutoScope' in extended_attributes | 119 auto_scope = not 'DartNoAutoScope' in extended_attributes |
178 this_has_default = 'Default' in extended_attributes | 120 arg_index = index + 1 if not (method.is_static or method.is_constructor) els
e index |
179 arg_index = index + 1 if not method.is_static else index | |
180 preprocessed_type = str(idl_type.preprocessed_type) | 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)) |
181 # FIXMEDART: handle the drift between preprocessed type names in 1847 and | 127 # FIXMEDART: handle the drift between preprocessed type names in 1847 and |
182 # 1985 dartium builds in a more generic way. | 128 # 1985 dartium builds in a more generic way. |
183 if preprocessed_type == 'unrestricted float': | 129 if preprocessed_type == 'unrestricted float': |
184 preprocessed_type = 'float' | 130 preprocessed_type = 'float' |
185 if preprocessed_type == 'unrestricted double': | 131 if preprocessed_type == 'unrestricted double': |
186 preprocessed_type = 'double' | 132 preprocessed_type = 'double' |
187 argument_data = { | 133 |
| 134 dart_enum_expression = idl_type.enum_validation_expression |
| 135 if dart_enum_expression: |
| 136 dart_enum_expression = dart_enum_expression.format(param_name=argument.n
ame) |
| 137 context.update({ |
188 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, | 138 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, |
189 raw_type=True, | 139 raw_type=True, |
190 used_in_cpp_sequence=use_heap_vector_
type), | 140 used_in_cpp_sequence=use_heap_vector_
type), |
191 'cpp_value': this_cpp_value, | 141 'cpp_value': this_cpp_value, |
192 'local_cpp_type': idl_type.cpp_type_args(argument.extended_attributes, r
aw_type=True), | 142 'local_cpp_type': local_cpp_type, |
193 # FIXME: check that the default value's type is compatible with the argu
ment's | 143 # FIXME: check that the default value's type is compatible with the argu
ment's |
194 'default_value': str(argument.default_value) if argument.default_value e
lse None, | 144 'default_value': default_value, |
195 'enum_validation_expression': idl_type.enum_validation_expression, | 145 'enum_validation_expression': dart_enum_expression, |
196 # Ignore 'Default' in extended_attributes not exposed in dart:html. | |
197 'has_default': False, | |
198 'has_event_listener_argument': any( | |
199 argument_so_far for argument_so_far in method.arguments[:index] | |
200 if argument_so_far.idl_type.name == 'EventListener'), | |
201 'idl_type_object': idl_type, | |
202 'preprocessed_type': preprocessed_type, | 146 'preprocessed_type': preprocessed_type, |
203 # Dictionary is special-cased, but arrays and sequences shouldn't be | |
204 'idl_type': idl_type.base_type, | |
205 'index': index, | |
206 'is_array_or_sequence_type': not not idl_type.native_array_element_type, | 147 'is_array_or_sequence_type': not not idl_type.native_array_element_type, |
207 'is_clamp': 'Clamp' in extended_attributes, | |
208 'is_callback_interface': idl_type.is_callback_interface, | |
209 'is_nullable': idl_type.is_nullable, | |
210 # Only expose as optional if no default value. | |
211 'is_optional': argument.is_optional and not (this_has_default or argumen
t.default_value), | |
212 'is_strict_type_checking': 'DartStrictTypeChecking' in extended_attribut
es, | 148 'is_strict_type_checking': 'DartStrictTypeChecking' in extended_attribut
es, |
213 'is_variadic_wrapper_type': is_variadic_wrapper_type, | 149 'is_dictionary': idl_type.is_dictionary or idl_type.base_type == 'Dictio
nary', |
214 'vector_type': 'WillBeHeapVector' if use_heap_vector_type else 'Vector', | 150 'vector_type': 'WillBeHeapVector' if use_heap_vector_type else 'Vector', |
215 'is_wrapper_type': idl_type.is_wrapper_type, | 151 'dart_set_return_value_for_main_world': dart_set_return_value(interface.
name, method, |
216 'name': argument.name, | 152 this_cpp_v
alue, for_main_world=True), |
217 'dart_set_return_value_for_main_world': dart_set_return_value(interface.
name, method, this_cpp_value, for_main_world=True), | |
218 'dart_set_return_value': dart_set_return_value(interface.name, method, t
his_cpp_value), | 153 'dart_set_return_value': dart_set_return_value(interface.name, method, t
his_cpp_value), |
219 'arg_index': arg_index, | 154 'arg_index': arg_index, |
220 'dart_value_to_local_cpp_value': dart_value_to_local_cpp_value(interface
, argument, arg_index, auto_scope), | 155 'dart_value_dictionary_cpp_value': dart_dictionary_value_argument(argume
nt, arg_index), |
221 } | 156 'dart_value_to_local_cpp_value': dart_value_to_local_cpp_value(interface
, |
222 return argument_data | 157 context['
has_type_checking_interface'], |
| 158 argument,
arg_index, auto_scope), |
| 159 }) |
| 160 return context |
223 | 161 |
224 | 162 |
225 ################################################################################ | 163 ################################################################################ |
226 # Value handling | 164 # Value handling |
227 ################################################################################ | 165 ################################################################################ |
228 | 166 |
229 def cpp_value(interface, method, number_of_arguments): | 167 def cpp_value(interface, method, number_of_arguments): |
230 def cpp_argument(argument): | 168 def cpp_argument(argument): |
231 argument_name = dart_types.check_reserved_name(argument.name) | 169 argument_name = dart_types.check_reserved_name(argument.name) |
232 idl_type = argument.idl_type | 170 idl_type = argument.idl_type |
233 | 171 |
234 if idl_type.is_typed_array_type: | 172 if idl_type.is_typed_array_type: |
235 return '%s.get()' % argument_name | 173 return '%s.get()' % argument_name |
236 | 174 |
237 if idl_type.name == 'EventListener': | 175 if idl_type.name == 'EventListener': |
238 if (interface.name == 'EventTarget' and | 176 if (interface.name == 'EventTarget' and |
239 method.name == 'removeEventListener'): | 177 method.name == 'removeEventListener'): |
240 # FIXME: remove this special case by moving get() into | 178 # FIXME: remove this special case by moving get() into |
241 # EventTarget::removeEventListener | 179 # EventTarget::removeEventListener |
242 return '%s.get()' % argument_name | 180 return '%s.get()' % argument_name |
243 return argument.name | 181 return argument.name |
244 if (idl_type.is_callback_interface or | 182 if (idl_type.name in ['NodeFilter', 'NodeFilterOrNull', |
245 idl_type.name in ['NodeFilter', 'XPathNSResolver']): | 183 'XPathNSResolver', 'XPathNSResolverOrNull']): |
246 # FIXME: remove this special case | 184 # FIXME: remove this special case |
247 return '%s.release()' % argument_name | 185 return '%s.release()' % argument_name |
| 186 # Need to de-ref the generated dictionary class for create call. |
| 187 if (idl_type.is_dictionary): |
| 188 return '*%s' % argument_name |
248 return argument_name | 189 return argument_name |
249 | 190 |
250 # Truncate omitted optional arguments | 191 # Truncate omitted optional arguments |
251 arguments = method.arguments[:number_of_arguments] | 192 arguments = method.arguments[:number_of_arguments] |
252 cpp_arguments = DartUtilities.call_with_arguments(method) | 193 if method.is_constructor: |
| 194 call_with_values = interface.extended_attributes.get('ConstructorCallWit
h') |
| 195 else: |
| 196 call_with_values = method.extended_attributes.get('CallWith') |
| 197 cpp_arguments = DartUtilities.call_with_arguments(call_with_values) |
253 if ('PartialInterfaceImplementedAs' in method.extended_attributes and not me
thod.is_static): | 198 if ('PartialInterfaceImplementedAs' in method.extended_attributes and not me
thod.is_static): |
254 cpp_arguments.append('*receiver') | 199 cpp_arguments.append('*receiver') |
255 | 200 |
256 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) | 201 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) |
257 this_union_arguments = method.idl_type.union_arguments | 202 this_union_arguments = method.idl_type and method.idl_type.union_arguments |
258 if this_union_arguments: | 203 if this_union_arguments: |
259 cpp_arguments.extend(this_union_arguments) | 204 cpp_arguments.extend([member_argument['cpp_value'] |
| 205 for member_argument in this_union_arguments]) |
260 | 206 |
261 if 'RaisesException' in method.extended_attributes: | 207 if ('RaisesException' in method.extended_attributes or |
| 208 (method.is_constructor and |
| 209 DartUtilities.has_extended_attribute_value(interface, 'RaisesException'
, 'Constructor'))): |
262 cpp_arguments.append('es') | 210 cpp_arguments.append('es') |
263 | 211 |
264 cpp_method_name = DartUtilities.scoped_name(interface, method, DartUtilities
.cpp_name(method)) | 212 if method.name == 'Constructor': |
| 213 base_name = 'create' |
| 214 elif method.name == 'NamedConstructor': |
| 215 base_name = 'createForJSConstructor' |
| 216 else: |
| 217 base_name = DartUtilities.cpp_name(method) |
| 218 cpp_method_name = DartUtilities.scoped_name(interface, method, base_name) |
265 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) | 219 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) |
266 | 220 |
267 | 221 |
268 # Mapping of IDL type to DartUtilities helper types. | 222 # Mapping of IDL type to DartUtilities helper types. |
269 def dart_arg_type(argument_type): | 223 def dart_arg_type(argument_type): |
270 if (argument_type.cpp_type == 'String'): | 224 if (argument_type.cpp_type == 'String'): |
271 return 'DartStringAdapter' | 225 return 'DartStringAdapter' |
272 | 226 |
273 return argument_type.cpp_type | 227 return argument_type.cpp_type |
274 | 228 |
275 | 229 |
276 def dart_set_return_value(interface_name, method, cpp_value, for_main_world=Fals
e): | 230 def dart_set_return_value(interface_name, method, cpp_value, for_main_world=Fals
e): |
277 idl_type = method.idl_type | 231 idl_type = method.idl_type |
278 extended_attributes = method.extended_attributes | 232 extended_attributes = method.extended_attributes |
279 if idl_type.name == 'void': | 233 if not idl_type or idl_type.name == 'void': |
| 234 # Constructors and void methods don't have a return type |
280 return None | 235 return None |
281 | 236 |
282 release = False | 237 release = False |
283 | 238 |
284 if idl_type.is_union_type: | 239 if idl_type.is_union_type: |
285 release = idl_type.release | 240 release = idl_type.release |
286 | 241 |
287 # [CallWith=ScriptState], [RaisesException] | 242 # [CallWith=ScriptState], [RaisesException] |
288 # TODO(terry): Disable ScriptState temporarily need to handle. | 243 # TODO(terry): Disable ScriptState temporarily need to handle. |
289 # if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or | 244 # if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or |
290 # 'RaisesException' in extended_attributes or | 245 # 'RaisesException' in extended_attributes or |
291 # idl_type.is_union_type): | 246 # idl_type.is_union_type): |
292 # cpp_value = 'result' # use local variable for value | 247 # cpp_value = 'result' # use local variable for value |
293 # release = idl_type.release | 248 # release = idl_type.release |
294 | 249 |
295 auto_scope = not 'DartNoAutoScope' in extended_attributes | 250 auto_scope = not 'DartNoAutoScope' in extended_attributes |
296 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else
'' | 251 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else
'' |
297 return idl_type.dart_set_return_value(cpp_value, extended_attributes, | 252 return idl_type.dart_set_return_value(cpp_value, extended_attributes, |
298 script_wrappable=script_wrappable, | 253 script_wrappable=script_wrappable, |
299 release=release, | 254 release=release, |
300 for_main_world=for_main_world, | 255 for_main_world=for_main_world, |
301 auto_scope=auto_scope) | 256 auto_scope=auto_scope) |
302 | 257 |
303 | 258 |
304 def dart_value_to_local_cpp_value(interface, argument, index, auto_scope=True): | 259 def dart_dictionary_value_argument(argument, index): |
| 260 idl_type = argument.idl_type |
| 261 return idl_type.dart_dictionary_to_local_cpp_value(index=index) |
| 262 |
| 263 |
| 264 def dart_value_to_local_cpp_value(interface, has_type_checking_interface, |
| 265 argument, index, auto_scope=True): |
305 extended_attributes = argument.extended_attributes | 266 extended_attributes = argument.extended_attributes |
306 interface_extended_attributes = interface.extended_attributes | |
307 idl_type = argument.idl_type | 267 idl_type = argument.idl_type |
308 name = argument.name | 268 name = argument.name |
309 # TODO(terry): Variadic arguments are not handled but treated as one argumen
t. | 269 # TODO(terry): Variadic arguments are not handled but treated as one argumen
t. |
310 # if argument.is_variadic: | 270 # if argument.is_variadic: |
311 # vector_type = 'WillBeHeapVector' if idl_type.is_will_be_garbage_col
lected else 'Vector' | 271 # vector_type = 'WillBeHeapVector' if idl_type.is_will_be_garbage_col
lected else 'Vector' |
312 # return 'V8TRYCATCH_VOID({vector_type}<{cpp_type}>, {name}, toNative
Arguments<{cpp_type}>(info, {index}))'.format( | 272 # return 'V8TRYCATCH_VOID({vector_type}<{cpp_type}>, {name}, toNative
Arguments<{cpp_type}>(info, {index}))'.format( |
313 # cpp_type=idl_type.cpp_type, name=name, index=index, vector_
type=vector_type) | 273 # cpp_type=idl_type.cpp_type, name=name, index=index, vector_
type=vector_type) |
314 | 274 |
315 # FIXME: V8 has some special logic around the addEventListener and | 275 # FIXME: V8 has some special logic around the addEventListener and |
316 # removeEventListener methods that should be added in somewhere. | 276 # removeEventListener methods that should be added in somewhere. |
317 # There is also some logic in systemnative.py to force a null check | 277 # There is also some logic in systemnative.py to force a null check |
318 # for the useCapture argument of those same methods that we may need to | 278 # for the useCapture argument of those same methods that we may need to |
319 # pull over. | 279 # pull over. |
320 null_check = (argument.is_optional and \ | 280 null_check = ((argument.is_optional and idl_type.is_callback_interface) or |
321 (idl_type.is_callback_interface or idl_type == 'Dictionary'))
or \ | 281 (idl_type.name == 'Dictionary') or |
322 (argument.default_value and argument.default_value.is_null) | 282 (argument.default_value and argument.default_value.is_null)) |
323 | 283 |
324 return idl_type.dart_value_to_local_cpp_value( | 284 return idl_type.dart_value_to_local_cpp_value( |
325 interface_extended_attributes, extended_attributes, name, null_check, | 285 extended_attributes, name, null_check, has_type_checking_interface, |
326 index=index, auto_scope=auto_scope) | 286 index=index, auto_scope=auto_scope) |
327 | |
328 | |
329 ################################################################################ | |
330 # Auxiliary functions | |
331 ################################################################################ | |
332 | |
333 # [NotEnumerable] | |
334 def property_attributes(method): | |
335 extended_attributes = method.extended_attributes | |
336 property_attributes_list = [] | |
337 if 'NotEnumerable' in extended_attributes: | |
338 property_attributes_list.append('v8::DontEnum') | |
339 if 'ReadOnly' in extended_attributes: | |
340 property_attributes_list.append('v8::ReadOnly') | |
341 if property_attributes_list: | |
342 property_attributes_list.insert(0, 'v8::DontDelete') | |
343 return property_attributes_list | |
344 | |
345 | |
346 # FIXMEDART: better align this method with the v8 version. | |
347 def union_member_argument_context(idl_type, index): | |
348 """Returns a context of union member for argument.""" | |
349 return 'result%d' % index | |
350 | |
351 def union_arguments(idl_type): | |
352 return [union_member_argument_context(member_idl_type, index) | |
353 for index, member_idl_type | |
354 in enumerate(idl_type.member_types)] | |
355 | |
356 | |
357 def argument_default_cpp_value(argument): | |
358 if not argument.default_value: | |
359 return None | |
360 return argument.idl_type.literal_cpp_value(argument.default_value) | |
361 | |
362 | |
363 IdlTypeBase.union_arguments = None | |
364 IdlUnionType.union_arguments = property(union_arguments) | |
365 IdlArgument.default_cpp_value = property(argument_default_cpp_value) | |
366 #IdlType.union_arguments = property(lambda self: None) | |
367 #IdlUnionType.union_arguments = property(union_arguments) | |
OLD | NEW |