| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 'Dictionary': 'Dictionary', | 241 'Dictionary': 'Dictionary', |
| 242 'EventHandler': 'EventListener*', | 242 'EventHandler': 'EventListener*', |
| 243 'Promise': 'ScriptPromise', | 243 'Promise': 'ScriptPromise', |
| 244 'ScriptValue': 'ScriptValue', | 244 'ScriptValue': 'ScriptValue', |
| 245 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345
529 | 245 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345
529 |
| 246 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', | 246 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', |
| 247 'boolean': 'bool', | 247 'boolean': 'bool', |
| 248 } | 248 } |
| 249 | 249 |
| 250 | 250 |
| 251 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False): | 251 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False, will_be
_in_heap_object=False): |
| 252 """Returns C++ type corresponding to IDL type.""" | 252 """Returns C++ type corresponding to IDL type. |
| 253 |
| 254 Args: |
| 255 used_as_argument: bool, True if idl_type's raw/primitive C++ type |
| 256 should be returned. |
| 257 will_be_in_heap_object: bool, True if idl_type will be part |
| 258 of a possibly heap allocated object (e.g., appears as an |
| 259 element of a C++ heap vector type.) The C++ type of an |
| 260 interface type changes, if so. |
| 261 """ |
| 253 def string_mode(): | 262 def string_mode(): |
| 254 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString', | 263 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString', |
| 255 # but we use NullString for performance. | 264 # but we use NullString for performance. |
| 256 if extended_attributes.get('TreatNullAs') != 'NullString': | 265 if extended_attributes.get('TreatNullAs') != 'NullString': |
| 257 return '' | 266 return '' |
| 258 if extended_attributes.get('TreatUndefinedAs') != 'NullString': | 267 if extended_attributes.get('TreatUndefinedAs') != 'NullString': |
| 259 return 'WithNullCheck' | 268 return 'WithNullCheck' |
| 260 return 'WithUndefinedOrNullCheck' | 269 return 'WithUndefinedOrNullCheck' |
| 261 | 270 |
| 262 extended_attributes = extended_attributes or {} | 271 extended_attributes = extended_attributes or {} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 276 if not used_as_argument: | 285 if not used_as_argument: |
| 277 return 'String' | 286 return 'String' |
| 278 return 'V8StringResource<%s>' % string_mode() | 287 return 'V8StringResource<%s>' % string_mode() |
| 279 if is_union_type(idl_type): | 288 if is_union_type(idl_type): |
| 280 # Attribute 'union_member_types' use is ok, but pylint can't infer this | 289 # Attribute 'union_member_types' use is ok, but pylint can't infer this |
| 281 # pylint: disable=E1103 | 290 # pylint: disable=E1103 |
| 282 return (cpp_type(union_member_type) | 291 return (cpp_type(union_member_type) |
| 283 for union_member_type in idl_type.union_member_types) | 292 for union_member_type in idl_type.union_member_types) |
| 284 this_array_or_sequence_type = array_or_sequence_type(idl_type) | 293 this_array_or_sequence_type = array_or_sequence_type(idl_type) |
| 285 if this_array_or_sequence_type: | 294 if this_array_or_sequence_type: |
| 286 return cpp_template_type('Vector', cpp_type(this_array_or_sequence_type)
) | 295 will_be_garbage_collected = is_will_be_garbage_collected(this_array_or_s
equence_type) |
| 296 vector_type = 'WillBeHeapVector' if will_be_garbage_collected else 'Vect
or' |
| 297 return cpp_template_type(vector_type, cpp_type(this_array_or_sequence_ty
pe, will_be_in_heap_object=will_be_garbage_collected)) |
| 287 | 298 |
| 288 if is_typed_array_type(idl_type) and used_as_argument: | 299 if is_typed_array_type(idl_type) and used_as_argument: |
| 289 return idl_type + '*' | 300 return idl_type + '*' |
| 290 if is_interface_type(idl_type): | 301 if is_interface_type(idl_type): |
| 291 implemented_as_class = implemented_as(idl_type) | 302 implemented_as_class = implemented_as(idl_type) |
| 292 if used_as_argument: | 303 if used_as_argument: |
| 293 return implemented_as_class + '*' | 304 return implemented_as_class + '*' |
| 294 if is_will_be_garbage_collected(idl_type): | 305 if is_will_be_garbage_collected(idl_type): |
| 295 return cpp_template_type('RefPtrWillBeRawPtr', implemented_as_class) | 306 ref_ptr_type = 'RefPtrWillBeMember' if will_be_in_heap_object else '
RefPtrWillBeRawPtr' |
| 307 return cpp_template_type(ref_ptr_type, implemented_as_class) |
| 296 return cpp_template_type('RefPtr', implemented_as_class) | 308 return cpp_template_type('RefPtr', implemented_as_class) |
| 297 # Default, assume native type is a pointer with same type name as idl type | 309 # Default, assume native type is a pointer with same type name as idl type |
| 298 return idl_type + '*' | 310 return idl_type + '*' |
| 299 | 311 |
| 300 | 312 |
| 301 def cpp_template_type(template, inner_type): | 313 def cpp_template_type(template, inner_type): |
| 302 """Returns C++ template specialized to type, with space added if needed.""" | 314 """Returns C++ template specialized to type, with space added if needed.""" |
| 303 if inner_type.endswith('>'): | 315 if inner_type.endswith('>'): |
| 304 format_string = '{template}<{inner_type} >' | 316 format_string = '{template}<{inner_type} >' |
| 305 else: | 317 else: |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 def v8_value_to_cpp_value_array_or_sequence(this_array_or_sequence_type, v8_valu
e, index): | 476 def v8_value_to_cpp_value_array_or_sequence(this_array_or_sequence_type, v8_valu
e, index): |
| 465 # Index is None for setters, index (starting at 0) for method arguments, | 477 # Index is None for setters, index (starting at 0) for method arguments, |
| 466 # and is used to provide a human-readable exception message | 478 # and is used to provide a human-readable exception message |
| 467 if index is None: | 479 if index is None: |
| 468 index = 0 # special case, meaning "setter" | 480 index = 0 # special case, meaning "setter" |
| 469 else: | 481 else: |
| 470 index += 1 # human-readable index | 482 index += 1 # human-readable index |
| 471 if (is_interface_type(this_array_or_sequence_type) and | 483 if (is_interface_type(this_array_or_sequence_type) and |
| 472 this_array_or_sequence_type != 'Dictionary'): | 484 this_array_or_sequence_type != 'Dictionary'): |
| 473 this_cpp_type = None | 485 this_cpp_type = None |
| 474 expression_format = '(toRefPtrNativeArray<{array_or_sequence_type}, V8{a
rray_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' | 486 ref_ptr_type = 'Member' if is_will_be_garbage_collected(this_array_or_se
quence_type) else 'RefPtr' |
| 487 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ
e}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' |
| 475 add_includes_for_type(this_array_or_sequence_type) | 488 add_includes_for_type(this_array_or_sequence_type) |
| 476 else: | 489 else: |
| 490 ref_ptr_type = None |
| 477 this_cpp_type = cpp_type(this_array_or_sequence_type) | 491 this_cpp_type = cpp_type(this_array_or_sequence_type) |
| 478 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info
.GetIsolate())' | 492 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info
.GetIsolate())' |
| 479 expression = expression_format.format(array_or_sequence_type=this_array_or_s
equence_type, cpp_type=this_cpp_type, index=index, v8_value=v8_value) | 493 expression = expression_format.format(array_or_sequence_type=this_array_or_s
equence_type, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_type, v8
_value=v8_value) |
| 480 return expression | 494 return expression |
| 481 | 495 |
| 482 | 496 |
| 483 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, index=None): | 497 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, index=None): |
| 484 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" | 498 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" |
| 485 this_cpp_type = cpp_type(idl_type, extended_attributes=extended_attributes,
used_as_argument=True) | 499 this_cpp_type = cpp_type(idl_type, extended_attributes=extended_attributes,
used_as_argument=True) |
| 486 | 500 |
| 487 idl_type = preprocess_idl_type(idl_type) | 501 idl_type = preprocess_idl_type(idl_type) |
| 488 if idl_type == 'DOMString': | 502 if idl_type == 'DOMString': |
| 489 format_string = 'V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID({cpp_type}, {varia
ble_name}, {cpp_value})' | 503 format_string = 'V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID({cpp_type}, {varia
ble_name}, {cpp_value})' |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 | 671 |
| 658 | 672 |
| 659 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea
tion_context='', extended_attributes=None): | 673 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea
tion_context='', extended_attributes=None): |
| 660 """Returns an expression that converts a C++ value to a V8 value.""" | 674 """Returns an expression that converts a C++ value to a V8 value.""" |
| 661 # the isolate parameter is needed for callback interfaces | 675 # the isolate parameter is needed for callback interfaces |
| 662 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext
ended_attributes) | 676 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext
ended_attributes) |
| 663 this_v8_conversion_type = v8_conversion_type(idl_type, extended_attributes) | 677 this_v8_conversion_type = v8_conversion_type(idl_type, extended_attributes) |
| 664 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] | 678 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] |
| 665 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat
ion_context=creation_context) | 679 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat
ion_context=creation_context) |
| 666 return statement | 680 return statement |
| OLD | NEW |