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 179 matching lines...) Loading... |
190 extended_attributes = argument.extended_attributes | 190 extended_attributes = argument.extended_attributes |
191 idl_type = argument.idl_type | 191 idl_type = argument.idl_type |
192 this_cpp_value = cpp_value(interface, method, index) | 192 this_cpp_value = cpp_value(interface, method, index) |
193 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type | 193 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type |
194 | 194 |
195 type_checking_interface = ( | 195 type_checking_interface = ( |
196 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or | 196 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or |
197 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and | 197 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and |
198 idl_type.is_wrapper_type) | 198 idl_type.is_wrapper_type) |
199 | 199 |
200 type_checked = (type_checking_interface and | |
201 # These allow null and undefined values, so a type-check is
still required. | |
202 not idl_type.is_nullable and | |
203 not (argument.is_optional and | |
204 'Default' in extended_attributes)) | |
205 | |
206 if ('ImplementedInPrivateScript' in extended_attributes and | 200 if ('ImplementedInPrivateScript' in extended_attributes and |
207 not idl_type.is_wrapper_type and | 201 not idl_type.is_wrapper_type and |
208 not idl_type.is_basic_type): | 202 not idl_type.is_basic_type): |
209 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') | 203 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') |
210 | 204 |
| 205 convert_v8_value_to_local_cpp_value = v8_value_to_local_cpp_value( |
| 206 argument, index, return_promise=method.returns_promise) |
| 207 |
| 208 # "Unsafe" conversion, to use when the argument's type has already been |
| 209 # checked. Set to None if same as regular conversion, to avoid emitting |
| 210 # duplicate copies of the same code. |
| 211 convert_v8_value_to_local_cpp_value_without_type_check = v8_value_to_local_c
pp_value( |
| 212 argument, index, needs_type_check=False, return_promise=method.returns_p
romise) |
| 213 if convert_v8_value_to_local_cpp_value == convert_v8_value_to_local_cpp_valu
e_without_type_check: |
| 214 convert_v8_value_to_local_cpp_value_without_type_check = None |
| 215 |
211 default_cpp_value = argument.default_cpp_value | 216 default_cpp_value = argument.default_cpp_value |
212 return { | 217 return { |
213 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, | 218 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, |
214 raw_type=True, | 219 raw_type=True, |
215 used_as_variadic_argument=argument.is
_variadic), | 220 used_as_variadic_argument=argument.is
_variadic), |
216 'cpp_value': this_cpp_value, | 221 'cpp_value': this_cpp_value, |
217 # FIXME: check that the default value's type is compatible with the argu
ment's | 222 # FIXME: check that the default value's type is compatible with the argu
ment's |
218 'default_value': default_cpp_value, | 223 'default_value': default_cpp_value, |
219 'enum_validation_expression': idl_type.enum_validation_expression, | 224 'enum_validation_expression': idl_type.enum_validation_expression, |
220 'handle': '%sHandle' % argument.name, | 225 'handle': '%sHandle' % argument.name, |
(...skipping 14 matching lines...) Loading... |
235 'is_nullable': idl_type.is_nullable, | 240 'is_nullable': idl_type.is_nullable, |
236 'is_optional': argument.is_optional, | 241 'is_optional': argument.is_optional, |
237 'is_variadic_wrapper_type': is_variadic_wrapper_type, | 242 'is_variadic_wrapper_type': is_variadic_wrapper_type, |
238 'is_wrapper_type': idl_type.is_wrapper_type, | 243 'is_wrapper_type': idl_type.is_wrapper_type, |
239 'name': argument.name, | 244 'name': argument.name, |
240 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 245 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
241 argument.name, isolate='scriptState->isolate()', | 246 argument.name, isolate='scriptState->isolate()', |
242 creation_context='scriptState->context()->Global()'), | 247 creation_context='scriptState->context()->Global()'), |
243 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), | 248 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), |
244 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), | 249 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), |
245 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex, type_checked, return_promise=method.returns_promise), | 250 'v8_value_to_local_cpp_value': convert_v8_value_to_local_cpp_value, |
| 251 'v8_value_to_local_cpp_value_without_type_check': convert_v8_value_to_lo
cal_cpp_value_without_type_check, |
246 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), | 252 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), |
247 } | 253 } |
248 | 254 |
249 | 255 |
250 def argument_declarations_for_private_script(interface, method): | 256 def argument_declarations_for_private_script(interface, method): |
251 argument_declarations = ['LocalFrame* frame'] | 257 argument_declarations = ['LocalFrame* frame'] |
252 argument_declarations.append('%s* holderImpl' % interface.name) | 258 argument_declarations.append('%s* holderImpl' % interface.name) |
253 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( | 259 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( |
254 used_as_rvalue_type=True), argument.name) for argument in method.argumen
ts]) | 260 used_as_rvalue_type=True), argument.name) for argument in method.argumen
ts]) |
255 if method.idl_type.name != 'void': | 261 if method.idl_type.name != 'void': |
(...skipping 107 matching lines...) Loading... |
363 | 369 |
364 if return_promise: | 370 if return_promise: |
365 suffix += '_PROMISE' | 371 suffix += '_PROMISE' |
366 macro_args.extend(['info', 'ScriptState::current(info.GetIsolate())']) | 372 macro_args.extend(['info', 'ScriptState::current(info.GetIsolate())']) |
367 | 373 |
368 suffix += '_INTERNAL' | 374 suffix += '_INTERNAL' |
369 | 375 |
370 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args)) | 376 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args)) |
371 | 377 |
372 | 378 |
373 def v8_value_to_local_cpp_value(argument, index, type_checked, return_promise=Fa
lse): | 379 def v8_value_to_local_cpp_value(argument, index, needs_type_check=True, return_p
romise=False): |
374 extended_attributes = argument.extended_attributes | 380 extended_attributes = argument.extended_attributes |
375 idl_type = argument.idl_type | 381 idl_type = argument.idl_type |
376 name = argument.name | 382 name = argument.name |
377 if argument.is_variadic: | 383 if argument.is_variadic: |
378 return v8_value_to_local_cpp_variadic_value(argument, index, return_prom
ise) | 384 return v8_value_to_local_cpp_variadic_value(argument, index, return_prom
ise) |
379 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]'
% index, | 385 return idl_type.v8_value_to_local_cpp_value( |
380 name, needs_type_check=not type_
checked, index=index, declare_variable=False, return_promise=return_promise) | 386 extended_attributes, 'info[%s]' % index, name, needs_type_check=needs_ty
pe_check, |
| 387 index=index, declare_variable=False, return_promise=return_promise) |
381 | 388 |
382 | 389 |
383 ################################################################################ | 390 ################################################################################ |
384 # Auxiliary functions | 391 # Auxiliary functions |
385 ################################################################################ | 392 ################################################################################ |
386 | 393 |
387 # [NotEnumerable] | 394 # [NotEnumerable] |
388 def property_attributes(method): | 395 def property_attributes(method): |
389 extended_attributes = method.extended_attributes | 396 extended_attributes = method.extended_attributes |
390 property_attributes_list = [] | 397 property_attributes_list = [] |
(...skipping 58 matching lines...) Loading... |
449 | 456 |
450 IdlOperation.returns_promise = property(method_returns_promise) | 457 IdlOperation.returns_promise = property(method_returns_promise) |
451 | 458 |
452 | 459 |
453 def argument_conversion_needs_exception_state(method, argument): | 460 def argument_conversion_needs_exception_state(method, argument): |
454 idl_type = argument.idl_type | 461 idl_type = argument.idl_type |
455 return (idl_type.v8_conversion_needs_exception_state or | 462 return (idl_type.v8_conversion_needs_exception_state or |
456 argument.is_variadic or | 463 argument.is_variadic or |
457 (method.returns_promise and (idl_type.is_string_type or | 464 (method.returns_promise and (idl_type.is_string_type or |
458 idl_type.is_enum))) | 465 idl_type.is_enum))) |
OLD | NEW |