| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 'Promise': 'ScriptPromise', | 111 'Promise': 'ScriptPromise', |
| 112 'ScriptValue': 'ScriptValue', | 112 'ScriptValue': 'ScriptValue', |
| 113 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345
529 | 113 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345
529 |
| 114 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', | 114 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', |
| 115 'boolean': 'bool', | 115 'boolean': 'bool', |
| 116 'unrestricted double': 'double', | 116 'unrestricted double': 'double', |
| 117 'unrestricted float': 'float', | 117 'unrestricted float': 'float', |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False, used_in
_cpp_sequence=False): | 121 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False, used_as
_variadic_argument=False, used_in_cpp_sequence=False): |
| 122 """Returns C++ type corresponding to IDL type. | 122 """Returns C++ type corresponding to IDL type. |
| 123 | 123 |
| 124 |idl_type| argument is of type IdlType, while return value is a string | 124 |idl_type| argument is of type IdlType, while return value is a string |
| 125 | 125 |
| 126 Args: | 126 Args: |
| 127 idl_type: | 127 idl_type: |
| 128 IdlType | 128 IdlType |
| 129 used_as_argument: | 129 used_as_argument: |
| 130 bool, True if idl_type's raw/primitive C++ type should be returned. | 130 bool, True if idl_type's raw/primitive C++ type should be returned. |
| 131 used_in_cpp_sequence: | 131 used_in_cpp_sequence: |
| 132 bool, True if the C++ type is used as an element of an array or sequ
ence. | 132 bool, True if the C++ type is used as an element of an array or sequ
ence. |
| 133 """ | 133 """ |
| 134 def string_mode(): | 134 def string_mode(): |
| 135 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString', | 135 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString', |
| 136 # but we use NullString for performance. | 136 # but we use NullString for performance. |
| 137 if extended_attributes.get('TreatNullAs') != 'NullString': | 137 if extended_attributes.get('TreatNullAs') != 'NullString': |
| 138 return '' | 138 return '' |
| 139 if extended_attributes.get('TreatUndefinedAs') != 'NullString': | 139 if extended_attributes.get('TreatUndefinedAs') != 'NullString': |
| 140 return 'WithNullCheck' | 140 return 'WithNullCheck' |
| 141 return 'WithUndefinedOrNullCheck' | 141 return 'WithUndefinedOrNullCheck' |
| 142 | 142 |
| 143 extended_attributes = extended_attributes or {} | 143 extended_attributes = extended_attributes or {} |
| 144 idl_type = idl_type.preprocessed_type | 144 idl_type = idl_type.preprocessed_type |
| 145 | 145 |
| 146 # Composite types | 146 # Composite types |
| 147 array_or_sequence_type = idl_type.array_or_sequence_type | 147 if used_as_variadic_argument: |
| 148 array_or_sequence_type = idl_type |
| 149 else: |
| 150 array_or_sequence_type = idl_type.array_or_sequence_type |
| 148 if array_or_sequence_type: | 151 if array_or_sequence_type: |
| 149 vector_type = cpp_ptr_type('Vector', 'HeapVector', array_or_sequence_typ
e.gc_type) | 152 vector_type = cpp_ptr_type('Vector', 'HeapVector', array_or_sequence_typ
e.gc_type) |
| 150 return cpp_template_type(vector_type, array_or_sequence_type.cpp_type_ar
gs(used_in_cpp_sequence=True)) | 153 return cpp_template_type(vector_type, array_or_sequence_type.cpp_type_ar
gs(used_in_cpp_sequence=True)) |
| 151 | 154 |
| 152 # Simple types | 155 # Simple types |
| 153 base_idl_type = idl_type.base_type | 156 base_idl_type = idl_type.base_type |
| 154 | 157 |
| 155 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE: | 158 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE: |
| 156 return base_idl_type | 159 return base_idl_type |
| 157 if base_idl_type in CPP_INT_TYPES: | 160 if base_idl_type in CPP_INT_TYPES: |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ
e}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' | 427 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ
e}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' |
| 425 add_includes_for_type(array_or_sequence_type) | 428 add_includes_for_type(array_or_sequence_type) |
| 426 else: | 429 else: |
| 427 ref_ptr_type = None | 430 ref_ptr_type = None |
| 428 this_cpp_type = array_or_sequence_type.cpp_type | 431 this_cpp_type = array_or_sequence_type.cpp_type |
| 429 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info
.GetIsolate())' | 432 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info
.GetIsolate())' |
| 430 expression = expression_format.format(array_or_sequence_type=array_or_sequen
ce_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_type, v8
_value=v8_value) | 433 expression = expression_format.format(array_or_sequence_type=array_or_sequen
ce_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_type, v8
_value=v8_value) |
| 431 return expression | 434 return expression |
| 432 | 435 |
| 433 | 436 |
| 434 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, index=None): | 437 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, index=None, declare_variable=True): |
| 435 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" | 438 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" |
| 436 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, used_as_argument=True) | 439 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, used_as_argument=True) |
| 437 | 440 |
| 438 idl_type = idl_type.preprocessed_type | 441 idl_type = idl_type.preprocessed_type |
| 439 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i
ndex) | 442 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i
ndex) |
| 440 args = [this_cpp_type, variable_name, cpp_value] | 443 args = [variable_name, cpp_value] |
| 441 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type
: | 444 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type
: |
| 442 macro = 'TOSTRING_VOID' | 445 macro = 'TOSTRING_VOID' |
| 443 elif idl_type.is_integer_type: | 446 elif idl_type.is_integer_type: |
| 444 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' | 447 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' |
| 445 args.append('exceptionState') | 448 args.append('exceptionState') |
| 446 else: | 449 else: |
| 447 macro = 'TONATIVE_VOID' | 450 macro = 'TONATIVE_VOID' |
| 448 | 451 |
| 452 if declare_variable: |
| 453 args.insert(0, this_cpp_type) |
| 454 else: |
| 455 # Use a macro that assumes a previously declared local variable. |
| 456 macro += '_INTERNAL' |
| 457 |
| 449 return '%s(%s)' % (macro, ', '.join(args)) | 458 return '%s(%s)' % (macro, ', '.join(args)) |
| 450 | 459 |
| 451 IdlType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value | 460 IdlType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value |
| 452 IdlUnionType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value | 461 IdlUnionType.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value |
| 453 | 462 |
| 454 | 463 |
| 455 ################################################################################ | 464 ################################################################################ |
| 456 # C++ -> V8 | 465 # C++ -> V8 |
| 457 ################################################################################ | 466 ################################################################################ |
| 458 | 467 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea
tion_context='', extended_attributes=None): | 650 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea
tion_context='', extended_attributes=None): |
| 642 """Returns an expression that converts a C++ value to a V8 value.""" | 651 """Returns an expression that converts a C++ value to a V8 value.""" |
| 643 # the isolate parameter is needed for callback interfaces | 652 # the isolate parameter is needed for callback interfaces |
| 644 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext
ended_attributes) | 653 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext
ended_attributes) |
| 645 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) | 654 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) |
| 646 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] | 655 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] |
| 647 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat
ion_context=creation_context) | 656 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat
ion_context=creation_context) |
| 648 return statement | 657 return statement |
| 649 | 658 |
| 650 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value | 659 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value |
| OLD | NEW |