| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings], | 185 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings], |
| 186 } | 186 } |
| 187 | 187 |
| 188 | 188 |
| 189 def argument_context(interface, method, argument, index): | 189 def argument_context(interface, method, argument, index): |
| 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 = ( |
| 196 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or |
| 197 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and |
| 198 idl_type.is_wrapper_type) |
| 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 |
| 195 if ('ImplementedInPrivateScript' in extended_attributes and | 206 if ('ImplementedInPrivateScript' in extended_attributes and |
| 196 not idl_type.is_wrapper_type and | 207 not idl_type.is_wrapper_type and |
| 197 not idl_type.is_basic_type): | 208 not idl_type.is_basic_type): |
| 198 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') | 209 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') |
| 199 | 210 |
| 200 default_cpp_value = argument.default_cpp_value | 211 default_cpp_value = argument.default_cpp_value |
| 201 return { | 212 return { |
| 202 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, | 213 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, |
| 203 raw_type=True, | 214 raw_type=True, |
| 204 used_as_variadic_argument=argument.is
_variadic), | 215 used_as_variadic_argument=argument.is
_variadic), |
| 205 'cpp_value': this_cpp_value, | 216 'cpp_value': this_cpp_value, |
| 206 # FIXME: check that the default value's type is compatible with the argu
ment's | 217 # FIXME: check that the default value's type is compatible with the argu
ment's |
| 207 'default_value': default_cpp_value, | 218 'default_value': default_cpp_value, |
| 208 'enum_validation_expression': idl_type.enum_validation_expression, | 219 'enum_validation_expression': idl_type.enum_validation_expression, |
| 209 'handle': '%sHandle' % argument.name, | 220 'handle': '%sHandle' % argument.name, |
| 210 # FIXME: remove once [Default] removed and just use argument.default_val
ue | 221 # FIXME: remove once [Default] removed and just use argument.default_val
ue |
| 211 'has_default': 'Default' in extended_attributes or default_cpp_value, | 222 'has_default': 'Default' in extended_attributes or default_cpp_value, |
| 212 'has_type_checking_interface': | 223 'has_type_checking_interface': type_checking_interface, |
| 213 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface'
) or | |
| 214 has_extended_attribute_value(method, 'TypeChecking', 'Interface'))
and | |
| 215 idl_type.is_wrapper_type, | |
| 216 'has_type_checking_unrestricted': | 224 'has_type_checking_unrestricted': |
| 217 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict
ed') or | 225 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict
ed') or |
| 218 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted'
)) and | 226 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted'
)) and |
| 219 idl_type.name in ('Float', 'Double'), | 227 idl_type.name in ('Float', 'Double'), |
| 220 # Dictionary is special-cased, but arrays and sequences shouldn't be | 228 # Dictionary is special-cased, but arrays and sequences shouldn't be |
| 221 'idl_type': idl_type.base_type, | 229 'idl_type': idl_type.base_type, |
| 222 'idl_type_object': idl_type, | 230 'idl_type_object': idl_type, |
| 223 'index': index, | 231 'index': index, |
| 224 'is_callback_interface': idl_type.is_callback_interface, | 232 'is_callback_interface': idl_type.is_callback_interface, |
| 225 # FIXME: Remove generic 'Dictionary' special-casing | 233 # FIXME: Remove generic 'Dictionary' special-casing |
| 226 'is_dictionary': idl_type.is_dictionary or idl_type.base_type == 'Dictio
nary', | 234 'is_dictionary': idl_type.is_dictionary or idl_type.base_type == 'Dictio
nary', |
| 227 'is_nullable': idl_type.is_nullable, | 235 'is_nullable': idl_type.is_nullable, |
| 228 'is_optional': argument.is_optional, | 236 'is_optional': argument.is_optional, |
| 229 'is_variadic_wrapper_type': is_variadic_wrapper_type, | 237 'is_variadic_wrapper_type': is_variadic_wrapper_type, |
| 230 'is_wrapper_type': idl_type.is_wrapper_type, | 238 'is_wrapper_type': idl_type.is_wrapper_type, |
| 231 'name': argument.name, | 239 'name': argument.name, |
| 232 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 240 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
| 233 argument.name, isolate='scriptState->isolate()', | 241 argument.name, isolate='scriptState->isolate()', |
| 234 creation_context='scriptState->context()->Global()'), | 242 creation_context='scriptState->context()->Global()'), |
| 235 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), | 243 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), |
| 236 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), | 244 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), |
| 237 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex, return_promise=method.returns_promise), | 245 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind
ex, type_checked, return_promise=method.returns_promise), |
| 238 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), | 246 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc
_type), |
| 239 } | 247 } |
| 240 | 248 |
| 241 | 249 |
| 242 def argument_declarations_for_private_script(interface, method): | 250 def argument_declarations_for_private_script(interface, method): |
| 243 argument_declarations = ['LocalFrame* frame'] | 251 argument_declarations = ['LocalFrame* frame'] |
| 244 argument_declarations.append('%s* holderImpl' % interface.name) | 252 argument_declarations.append('%s* holderImpl' % interface.name) |
| 245 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( | 253 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( |
| 246 used_as_rvalue_type=True), argument.name) for argument in method.argumen
ts]) | 254 used_as_rvalue_type=True), argument.name) for argument in method.argumen
ts]) |
| 247 if method.idl_type.name != 'void': | 255 if method.idl_type.name != 'void': |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 363 |
| 356 if return_promise: | 364 if return_promise: |
| 357 suffix += '_PROMISE' | 365 suffix += '_PROMISE' |
| 358 macro_args.extend(['info', 'ScriptState::current(info.GetIsolate())']) | 366 macro_args.extend(['info', 'ScriptState::current(info.GetIsolate())']) |
| 359 | 367 |
| 360 suffix += '_INTERNAL' | 368 suffix += '_INTERNAL' |
| 361 | 369 |
| 362 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args)) | 370 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args)) |
| 363 | 371 |
| 364 | 372 |
| 365 def v8_value_to_local_cpp_value(argument, index, return_promise=False): | 373 def v8_value_to_local_cpp_value(argument, index, type_checked, return_promise=Fa
lse): |
| 366 extended_attributes = argument.extended_attributes | 374 extended_attributes = argument.extended_attributes |
| 367 idl_type = argument.idl_type | 375 idl_type = argument.idl_type |
| 368 name = argument.name | 376 name = argument.name |
| 369 if argument.is_variadic: | 377 if argument.is_variadic: |
| 370 return v8_value_to_local_cpp_variadic_value(argument, index, return_prom
ise) | 378 return v8_value_to_local_cpp_variadic_value(argument, index, return_prom
ise) |
| 371 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]'
% index, | 379 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]'
% index, |
| 372 name, index=index, declare_varia
ble=False, return_promise=return_promise) | 380 name, needs_type_check=not type_
checked, index=index, declare_variable=False, return_promise=return_promise) |
| 373 | 381 |
| 374 | 382 |
| 375 ################################################################################ | 383 ################################################################################ |
| 376 # Auxiliary functions | 384 # Auxiliary functions |
| 377 ################################################################################ | 385 ################################################################################ |
| 378 | 386 |
| 379 # [NotEnumerable] | 387 # [NotEnumerable] |
| 380 def property_attributes(method): | 388 def property_attributes(method): |
| 381 extended_attributes = method.extended_attributes | 389 extended_attributes = method.extended_attributes |
| 382 property_attributes_list = [] | 390 property_attributes_list = [] |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 449 |
| 442 IdlOperation.returns_promise = property(method_returns_promise) | 450 IdlOperation.returns_promise = property(method_returns_promise) |
| 443 | 451 |
| 444 | 452 |
| 445 def argument_conversion_needs_exception_state(method, argument): | 453 def argument_conversion_needs_exception_state(method, argument): |
| 446 idl_type = argument.idl_type | 454 idl_type = argument.idl_type |
| 447 return (idl_type.v8_conversion_needs_exception_state or | 455 return (idl_type.v8_conversion_needs_exception_state or |
| 448 argument.is_variadic or | 456 argument.is_variadic or |
| 449 (method.returns_promise and (idl_type.is_string_type or | 457 (method.returns_promise and (idl_type.is_string_type or |
| 450 idl_type.is_enum))) | 458 idl_type.is_enum))) |
| OLD | NEW |