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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 'Date': 'double', | 240 'Date': 'double', |
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 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False): | 250 |
251 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False, used_as _member=False): | |
haraken
2014/02/27 15:32:43
Is |used_as_member| necessary?
Nils Barth (inactive)
2014/03/03 02:47:53
Keishi, could you add some documentation to the do
| |
251 """Returns C++ type corresponding to IDL type.""" | 252 """Returns C++ type corresponding to IDL type.""" |
252 def string_mode(): | 253 def string_mode(): |
253 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString', | 254 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString', |
254 # but we use NullString for performance. | 255 # but we use NullString for performance. |
255 if extended_attributes.get('TreatNullAs') != 'NullString': | 256 if extended_attributes.get('TreatNullAs') != 'NullString': |
256 return '' | 257 return '' |
257 if extended_attributes.get('TreatUndefinedAs') != 'NullString': | 258 if extended_attributes.get('TreatUndefinedAs') != 'NullString': |
258 return 'WithNullCheck' | 259 return 'WithNullCheck' |
259 return 'WithUndefinedOrNullCheck' | 260 return 'WithUndefinedOrNullCheck' |
260 | 261 |
(...skipping 14 matching lines...) Expand all Loading... | |
275 if not used_as_argument: | 276 if not used_as_argument: |
276 return 'String' | 277 return 'String' |
277 return 'V8StringResource<%s>' % string_mode() | 278 return 'V8StringResource<%s>' % string_mode() |
278 if is_union_type(idl_type): | 279 if is_union_type(idl_type): |
279 # Attribute 'union_member_types' use is ok, but pylint can't infer this | 280 # Attribute 'union_member_types' use is ok, but pylint can't infer this |
280 # pylint: disable=E1103 | 281 # pylint: disable=E1103 |
281 return (cpp_type(union_member_type) | 282 return (cpp_type(union_member_type) |
282 for union_member_type in idl_type.union_member_types) | 283 for union_member_type in idl_type.union_member_types) |
283 this_array_or_sequence_type = array_or_sequence_type(idl_type) | 284 this_array_or_sequence_type = array_or_sequence_type(idl_type) |
284 if this_array_or_sequence_type: | 285 if this_array_or_sequence_type: |
286 if is_will_be_garbage_collected(this_array_or_sequence_type): | |
287 return cpp_template_type('WillBeHeapVector', cpp_type(this_array_or_ sequence_type, used_as_member=True)) | |
haraken
2014/02/27 15:32:43
I don't quite understand that you're adding |used_
Nils Barth (inactive)
2014/03/03 02:47:53
? Keishi's code makes sense AFAICT;
it's using |us
| |
285 return cpp_template_type('Vector', cpp_type(this_array_or_sequence_type) ) | 288 return cpp_template_type('Vector', cpp_type(this_array_or_sequence_type) ) |
286 | 289 |
287 if is_typed_array_type(idl_type) and used_as_argument: | 290 if is_typed_array_type(idl_type) and used_as_argument: |
288 return idl_type + '*' | 291 return idl_type + '*' |
289 if is_interface_type(idl_type): | 292 if is_interface_type(idl_type): |
290 implemented_as_class = implemented_as(idl_type) | 293 implemented_as_class = implemented_as(idl_type) |
291 if used_as_argument: | 294 if used_as_argument: |
292 return implemented_as_class + '*' | 295 return implemented_as_class + '*' |
293 if is_will_be_garbage_collected(idl_type): | 296 if is_will_be_garbage_collected(idl_type): |
297 if used_as_member: | |
298 return cpp_template_type('RefPtrWillBeMember', implemented_as_cl ass) | |
294 return cpp_template_type('RefPtrWillBeRawPtr', implemented_as_class) | 299 return cpp_template_type('RefPtrWillBeRawPtr', implemented_as_class) |
295 return cpp_template_type('RefPtr', implemented_as_class) | 300 return cpp_template_type('RefPtr', implemented_as_class) |
296 # Default, assume native type is a pointer with same type name as idl type | 301 # Default, assume native type is a pointer with same type name as idl type |
297 return idl_type + '*' | 302 return idl_type + '*' |
298 | 303 |
299 | 304 |
300 def cpp_template_type(template, inner_type): | 305 def cpp_template_type(template, inner_type): |
301 """Returns C++ template specialized to type, with space added if needed.""" | 306 """Returns C++ template specialized to type, with space added if needed.""" |
302 if inner_type.endswith('>'): | 307 if inner_type.endswith('>'): |
303 format_string = '{template}<{inner_type} >' | 308 format_string = '{template}<{inner_type} >' |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 def v8_value_to_cpp_value_array_or_sequence(this_array_or_sequence_type, v8_valu e, index): | 467 def v8_value_to_cpp_value_array_or_sequence(this_array_or_sequence_type, v8_valu e, index): |
463 # Index is None for setters, index (starting at 0) for method arguments, | 468 # Index is None for setters, index (starting at 0) for method arguments, |
464 # and is used to provide a human-readable exception message | 469 # and is used to provide a human-readable exception message |
465 if index is None: | 470 if index is None: |
466 index = 0 # special case, meaning "setter" | 471 index = 0 # special case, meaning "setter" |
467 else: | 472 else: |
468 index += 1 # human-readable index | 473 index += 1 # human-readable index |
469 if (is_interface_type(this_array_or_sequence_type) and | 474 if (is_interface_type(this_array_or_sequence_type) and |
470 this_array_or_sequence_type != 'Dictionary'): | 475 this_array_or_sequence_type != 'Dictionary'): |
471 this_cpp_type = None | 476 this_cpp_type = None |
472 expression_format = '(toRefPtrNativeArray<{array_or_sequence_type}, V8{a rray_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' | 477 if is_will_be_garbage_collected(this_array_or_sequence_type): |
478 expression_format = '(toMemberNativeArray<{array_or_sequence_type}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' | |
sof
2014/03/02 20:10:55
To my eyes, it would read better if you instead cr
| |
479 else: | |
480 expression_format = '(toRefPtrNativeArray<{array_or_sequence_type}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' | |
473 add_includes_for_type(this_array_or_sequence_type) | 481 add_includes_for_type(this_array_or_sequence_type) |
474 else: | 482 else: |
475 this_cpp_type = cpp_type(this_array_or_sequence_type) | 483 this_cpp_type = cpp_type(this_array_or_sequence_type) |
476 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info .GetIsolate())' | 484 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info .GetIsolate())' |
477 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) | 485 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) |
478 return expression | 486 return expression |
479 | 487 |
480 | 488 |
481 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None): | 489 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None): |
482 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" | 490 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 | 663 |
656 | 664 |
657 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='', extended_attributes=None): | 665 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='', extended_attributes=None): |
658 """Returns an expression that converts a C++ value to a V8 value.""" | 666 """Returns an expression that converts a C++ value to a V8 value.""" |
659 # the isolate parameter is needed for callback interfaces | 667 # the isolate parameter is needed for callback interfaces |
660 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) | 668 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) |
661 this_v8_conversion_type = v8_conversion_type(idl_type, extended_attributes) | 669 this_v8_conversion_type = v8_conversion_type(idl_type, extended_attributes) |
662 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] | 670 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] |
663 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) | 671 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) |
664 return statement | 672 return statement |
OLD | NEW |