| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 # These allow null and undefined values, so a type-check is
still required. | 202 # These allow null and undefined values, so a type-check is
still required. |
| 203 not idl_type.is_nullable and | 203 not idl_type.is_nullable and |
| 204 not (argument.is_optional and | 204 not (argument.is_optional and |
| 205 'Default' in extended_attributes)) | 205 'Default' in extended_attributes)) |
| 206 | 206 |
| 207 if ('ImplementedInPrivateScript' in extended_attributes and | 207 if ('ImplementedInPrivateScript' in extended_attributes and |
| 208 not idl_type.is_wrapper_type and | 208 not idl_type.is_wrapper_type and |
| 209 not idl_type.is_basic_type): | 209 not idl_type.is_basic_type): |
| 210 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') | 210 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') |
| 211 | 211 |
| 212 default_cpp_value = argument.default_cpp_value | 212 set_default_value = argument.set_default_value |
| 213 return { | 213 return { |
| 214 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, | 214 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut
es, |
| 215 raw_type=True, | 215 raw_type=True, |
| 216 used_as_variadic_argument=argument.is
_variadic), | 216 used_as_variadic_argument=argument.is
_variadic), |
| 217 'cpp_value': this_cpp_value, | 217 'cpp_value': this_cpp_value, |
| 218 # FIXME: check that the default value's type is compatible with the argu
ment's | 218 # FIXME: check that the default value's type is compatible with the argu
ment's |
| 219 'default_value': default_cpp_value, | 219 'set_default_value': set_default_value, |
| 220 'enum_validation_expression': idl_type.enum_validation_expression, | 220 'enum_validation_expression': idl_type.enum_validation_expression, |
| 221 'handle': '%sHandle' % argument.name, | 221 'handle': '%sHandle' % argument.name, |
| 222 # FIXME: remove once [Default] removed and just use argument.default_val
ue | 222 # FIXME: remove once [Default] removed and just use argument.default_val
ue |
| 223 'has_default': 'Default' in extended_attributes or default_cpp_value, | 223 'has_default': 'Default' in extended_attributes or set_default_value, |
| 224 'has_type_checking_interface': type_checking_interface, | 224 'has_type_checking_interface': type_checking_interface, |
| 225 'has_type_checking_unrestricted': | 225 'has_type_checking_unrestricted': |
| 226 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict
ed') or | 226 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict
ed') or |
| 227 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted'
)) and | 227 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted'
)) and |
| 228 idl_type.name in ('Float', 'Double'), | 228 idl_type.name in ('Float', 'Double'), |
| 229 # Dictionary is special-cased, but arrays and sequences shouldn't be | 229 # Dictionary is special-cased, but arrays and sequences shouldn't be |
| 230 'idl_type': idl_type.base_type, | 230 'idl_type': idl_type.base_type, |
| 231 'idl_type_object': idl_type, | 231 'idl_type_object': idl_type, |
| 232 'index': index, | 232 'index': index, |
| 233 'is_callback_interface': idl_type.is_callback_interface, | 233 'is_callback_interface': idl_type.is_callback_interface, |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 property_attributes_list = [] | 390 property_attributes_list = [] |
| 391 if 'NotEnumerable' in extended_attributes: | 391 if 'NotEnumerable' in extended_attributes: |
| 392 property_attributes_list.append('v8::DontEnum') | 392 property_attributes_list.append('v8::DontEnum') |
| 393 if 'Unforgeable' in extended_attributes: | 393 if 'Unforgeable' in extended_attributes: |
| 394 property_attributes_list.append('v8::ReadOnly') | 394 property_attributes_list.append('v8::ReadOnly') |
| 395 if property_attributes_list: | 395 if property_attributes_list: |
| 396 property_attributes_list.insert(0, 'v8::DontDelete') | 396 property_attributes_list.insert(0, 'v8::DontDelete') |
| 397 return property_attributes_list | 397 return property_attributes_list |
| 398 | 398 |
| 399 | 399 |
| 400 def argument_default_cpp_value(argument): | 400 def argument_set_default_value(argument): |
| 401 if argument.idl_type.is_dictionary: | 401 idl_type = argument.idl_type |
| 402 default_value = argument.default_value |
| 403 if not default_value: |
| 402 return None | 404 return None |
| 403 if not argument.default_value: | 405 if idl_type.is_dictionary: |
| 406 if not argument.default_value.is_null: |
| 407 raise Exception('invalid default value for dictionary type') |
| 404 return None | 408 return None |
| 405 return argument.idl_type.literal_cpp_value(argument.default_value) | 409 if idl_type.is_union_type: |
| 410 if argument.default_value.is_null: |
| 411 if not idl_type.includes_nullable_type: |
| 412 raise Exception('invalid default value for union type: null for
%s' |
| 413 % idl_type.name) |
| 414 # Union container objects are "null" initially. |
| 415 return '/* null default value */' |
| 416 if isinstance(default_value.value, basestring): |
| 417 member_type = idl_type.string_member_type |
| 418 elif isinstance(default_value.value, (int, float)): |
| 419 member_type = idl_type.numeric_member_type |
| 420 elif isinstance(default_value.value, bool): |
| 421 member_type = idl_type.boolean_member_type |
| 422 else: |
| 423 member_type = None |
| 424 if member_type is None: |
| 425 raise Exception('invalid default value for union type: %r for %s' |
| 426 % (default_value.value, idl_type.name)) |
| 427 member_type_name = (member_type.inner_type.name |
| 428 if member_type.is_nullable else |
| 429 member_type.name) |
| 430 return '%s.set%s(%s)' % (argument.name, member_type_name, |
| 431 member_type.literal_cpp_value(default_value)) |
| 432 return '%s = %s' % (argument.name, |
| 433 idl_type.literal_cpp_value(default_value)) |
| 406 | 434 |
| 407 IdlArgument.default_cpp_value = property(argument_default_cpp_value) | 435 IdlArgument.set_default_value = property(argument_set_default_value) |
| 408 | 436 |
| 409 | 437 |
| 410 def method_returns_promise(method): | 438 def method_returns_promise(method): |
| 411 return method.idl_type and method.idl_type.name == 'Promise' | 439 return method.idl_type and method.idl_type.name == 'Promise' |
| 412 | 440 |
| 413 IdlOperation.returns_promise = property(method_returns_promise) | 441 IdlOperation.returns_promise = property(method_returns_promise) |
| 414 | 442 |
| 415 | 443 |
| 416 def argument_conversion_needs_exception_state(method, argument): | 444 def argument_conversion_needs_exception_state(method, argument): |
| 417 idl_type = argument.idl_type | 445 idl_type = argument.idl_type |
| 418 return (idl_type.v8_conversion_needs_exception_state or | 446 return (idl_type.v8_conversion_needs_exception_state or |
| 419 argument.is_variadic or | 447 argument.is_variadic or |
| 420 (method.returns_promise and (idl_type.is_string_type or | 448 (method.returns_promise and (idl_type.is_string_type or |
| 421 idl_type.is_enum))) | 449 idl_type.is_enum))) |
| OLD | NEW |