| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 'Promise': 'ScriptPromise', | 112 'Promise': 'ScriptPromise', |
| 113 'ScriptValue': 'ScriptValue', | 113 'ScriptValue': 'ScriptValue', |
| 114 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345
529 | 114 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345
529 |
| 115 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', | 115 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', |
| 116 'boolean': 'bool', | 116 'boolean': 'bool', |
| 117 'unrestricted double': 'double', | 117 'unrestricted double': 'double', |
| 118 'unrestricted float': 'float', | 118 'unrestricted float': 'float', |
| 119 } | 119 } |
| 120 | 120 |
| 121 | 121 |
| 122 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False, used_as
_variadic_argument=False, used_in_cpp_sequence=False): | 122 def cpp_type(idl_type, extended_attributes=None, used_as_raw_type=False, used_as
_argument=False, used_as_variadic_argument=False, used_in_cpp_sequence=False): |
| 123 """Returns C++ type corresponding to IDL type. | 123 """Returns C++ type corresponding to IDL type. |
| 124 | 124 |
| 125 |idl_type| argument is of type IdlType, while return value is a string | 125 |idl_type| argument is of type IdlType, while return value is a string |
| 126 | 126 |
| 127 Args: | 127 Args: |
| 128 idl_type: | 128 idl_type: |
| 129 IdlType | 129 IdlType |
| 130 used_as_raw_type: |
| 131 bool, True if idl_type's raw/primitive C++ type should be returned. |
| 130 used_as_argument: | 132 used_as_argument: |
| 131 bool, True if idl_type's raw/primitive C++ type should be returned. | 133 bool, True if the C++ type is used as an argument of a method. |
| 134 used_as_variadic_argument: |
| 135 bool, True if the C++ type is used as a variadic argument of a metho
d. |
| 132 used_in_cpp_sequence: | 136 used_in_cpp_sequence: |
| 133 bool, True if the C++ type is used as an element of an array or sequ
ence. | 137 bool, True if the C++ type is used as an element of an array or sequ
ence. |
| 134 """ | 138 """ |
| 135 def string_mode(): | 139 def string_mode(): |
| 136 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString', | 140 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString', |
| 137 # but we use NullString for performance. | 141 # but we use NullString for performance. |
| 138 if extended_attributes.get('TreatNullAs') != 'NullString': | 142 if extended_attributes.get('TreatNullAs') != 'NullString': |
| 139 return '' | 143 return '' |
| 140 if extended_attributes.get('TreatUndefinedAs') != 'NullString': | 144 if extended_attributes.get('TreatUndefinedAs') != 'NullString': |
| 141 return 'WithNullCheck' | 145 return 'WithNullCheck' |
| (...skipping 17 matching lines...) Expand all Loading... |
| 159 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE: | 163 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE: |
| 160 return base_idl_type | 164 return base_idl_type |
| 161 if base_idl_type in CPP_INT_TYPES: | 165 if base_idl_type in CPP_INT_TYPES: |
| 162 return 'int' | 166 return 'int' |
| 163 if base_idl_type in CPP_UNSIGNED_TYPES: | 167 if base_idl_type in CPP_UNSIGNED_TYPES: |
| 164 return 'unsigned' | 168 return 'unsigned' |
| 165 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: | 169 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: |
| 166 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] | 170 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] |
| 167 | 171 |
| 168 if base_idl_type in NON_WRAPPER_TYPES: | 172 if base_idl_type in NON_WRAPPER_TYPES: |
| 169 return 'RefPtr<%s>' % base_idl_type | 173 return ('PassRefPtr<%s>' if used_as_argument else 'RefPtr<%s>') % base_i
dl_type |
| 170 if base_idl_type in ('DOMString', 'ByteString', 'ScalarValueString'): | 174 if base_idl_type in ('DOMString', 'ByteString', 'ScalarValueString'): |
| 171 if not used_as_argument: | 175 if not used_as_raw_type: |
| 172 return 'String' | 176 return 'String' |
| 173 return 'V8StringResource<%s>' % string_mode() | 177 return 'V8StringResource<%s>' % string_mode() |
| 174 | 178 |
| 175 if idl_type.is_typed_array_type and used_as_argument: | 179 if idl_type.is_typed_array_type and used_as_raw_type: |
| 176 return base_idl_type + '*' | 180 return base_idl_type + '*' |
| 177 if idl_type.is_interface_type: | 181 if idl_type.is_interface_type: |
| 178 implemented_as_class = idl_type.implemented_as | 182 implemented_as_class = idl_type.implemented_as |
| 179 if used_as_argument: | 183 if used_as_raw_type: |
| 180 return implemented_as_class + '*' | 184 return implemented_as_class + '*' |
| 181 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' | 185 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' |
| 182 ptr_type = cpp_ptr_type('RefPtr', new_type, idl_type.gc_type) | 186 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_argument else 'RefPtr')
, new_type, idl_type.gc_type) |
| 183 return cpp_template_type(ptr_type, implemented_as_class) | 187 return cpp_template_type(ptr_type, implemented_as_class) |
| 184 # Default, assume native type is a pointer with same type name as idl type | 188 # Default, assume native type is a pointer with same type name as idl type |
| 185 return base_idl_type + '*' | 189 return base_idl_type + '*' |
| 186 | 190 |
| 187 | 191 |
| 188 def cpp_type_union(idl_type, extended_attributes=None, used_as_argument=False): | 192 def cpp_type_union(idl_type, extended_attributes=None): |
| 189 return (member_type.cpp_type for member_type in idl_type.member_types) | 193 return (member_type.cpp_type for member_type in idl_type.member_types) |
| 190 | 194 |
| 191 | 195 |
| 192 # Allow access as idl_type.cpp_type if no arguments | 196 # Allow access as idl_type.cpp_type if no arguments |
| 193 IdlType.cpp_type = property(cpp_type) | 197 IdlType.cpp_type = property(cpp_type) |
| 194 IdlUnionType.cpp_type = property(cpp_type_union) | 198 IdlUnionType.cpp_type = property(cpp_type_union) |
| 195 IdlType.cpp_type_args = cpp_type | 199 IdlType.cpp_type_args = cpp_type |
| 196 IdlUnionType.cpp_type_args = cpp_type_union | 200 IdlUnionType.cpp_type_args = cpp_type_union |
| 197 | 201 |
| 198 | 202 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 'byte': 'toInt8({arguments})', | 389 'byte': 'toInt8({arguments})', |
| 386 'octet': 'toUInt8({arguments})', | 390 'octet': 'toUInt8({arguments})', |
| 387 'short': 'toInt16({arguments})', | 391 'short': 'toInt16({arguments})', |
| 388 'unsigned short': 'toUInt16({arguments})', | 392 'unsigned short': 'toUInt16({arguments})', |
| 389 'long': 'toInt32({arguments})', | 393 'long': 'toInt32({arguments})', |
| 390 'unsigned long': 'toUInt32({arguments})', | 394 'unsigned long': 'toUInt32({arguments})', |
| 391 'long long': 'toInt64({arguments})', | 395 'long long': 'toInt64({arguments})', |
| 392 'unsigned long long': 'toUInt64({arguments})', | 396 'unsigned long long': 'toUInt64({arguments})', |
| 393 # Interface types | 397 # Interface types |
| 394 'CompareHow': 'static_cast<Range::CompareHow>({v8_value}->Int32Value())', | 398 'CompareHow': 'static_cast<Range::CompareHow>({v8_value}->Int32Value())', |
| 395 'Dictionary': 'Dictionary({v8_value}, info.GetIsolate())', | 399 'Dictionary': 'Dictionary({v8_value}, {isolate})', |
| 396 'EventTarget': 'V8DOMWrapper::isDOMWrapper({v8_value}) ? toWrapperTypeInfo(v
8::Handle<v8::Object>::Cast({v8_value}))->toEventTarget(v8::Handle<v8::Object>::
Cast({v8_value})) : 0', | 400 'EventTarget': 'V8DOMWrapper::isDOMWrapper({v8_value}) ? toWrapperTypeInfo(v
8::Handle<v8::Object>::Cast({v8_value}))->toEventTarget(v8::Handle<v8::Object>::
Cast({v8_value})) : 0', |
| 397 'MediaQueryListListener': 'MediaQueryListListener::create(ScriptState::curre
nt(info.GetIsolate()), ScriptValue(ScriptState::current(info.GetIsolate()), {v8_
value}))', | 401 'MediaQueryListListener': 'MediaQueryListListener::create(ScriptState::curre
nt({isolate}), ScriptValue(ScriptState::current({isolate}), {v8_value}))', |
| 398 'NodeFilter': 'toNodeFilter({v8_value}, info.Holder(), ScriptState::current(
info.GetIsolate()))', | 402 'NodeFilter': 'toNodeFilter({v8_value}, info.Holder(), ScriptState::current(
{isolate}))', |
| 399 'Promise': 'ScriptPromise::cast(ScriptState::current(info.GetIsolate()), {v8
_value})', | 403 'Promise': 'ScriptPromise::cast(ScriptState::current({isolate}), {v8_value})
', |
| 400 'SerializedScriptValue': 'SerializedScriptValue::create({v8_value}, info.Get
Isolate())', | 404 'SerializedScriptValue': 'SerializedScriptValue::create({v8_value}, {isolate
})', |
| 401 'ScriptValue': 'ScriptValue(ScriptState::current(info.GetIsolate()), {v8_val
ue})', | 405 'ScriptValue': 'ScriptValue(ScriptState::current({isolate}), {v8_value})', |
| 402 'Window': 'toDOMWindow({v8_value}, info.GetIsolate())', | 406 'Window': 'toDOMWindow({v8_value}, {isolate})', |
| 403 'XPathNSResolver': 'toXPathNSResolver({v8_value}, info.GetIsolate())', | 407 'XPathNSResolver': 'toXPathNSResolver({v8_value}, {isolate})', |
| 404 } | 408 } |
| 405 | 409 |
| 406 | 410 |
| 407 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index): | 411 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index, isolat
e='info.GetIsolate()'): |
| 412 if idl_type.name == 'void': |
| 413 return '' |
| 414 |
| 408 # Composite types | 415 # Composite types |
| 409 array_or_sequence_type = idl_type.array_or_sequence_type | 416 array_or_sequence_type = idl_type.array_or_sequence_type |
| 410 if array_or_sequence_type: | 417 if array_or_sequence_type: |
| 411 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v
8_value, index) | 418 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v
8_value, index) |
| 412 | 419 |
| 413 # Simple types | 420 # Simple types |
| 414 idl_type = idl_type.preprocessed_type | 421 idl_type = idl_type.preprocessed_type |
| 415 add_includes_for_type(idl_type) | 422 add_includes_for_type(idl_type) |
| 416 base_idl_type = idl_type.base_type | 423 base_idl_type = idl_type.base_type |
| 417 | 424 |
| 418 if 'EnforceRange' in extended_attributes: | 425 if 'EnforceRange' in extended_attributes: |
| 419 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) | 426 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) |
| 420 elif (idl_type.is_integer_type or # NormalConversion | 427 elif (idl_type.is_integer_type or # NormalConversion |
| 421 idl_type.name in ('ByteString', 'ScalarValueString')): | 428 idl_type.name in ('ByteString', 'ScalarValueString')): |
| 422 arguments = ', '.join([v8_value, 'exceptionState']) | 429 arguments = ', '.join([v8_value, 'exceptionState']) |
| 423 else: | 430 else: |
| 424 arguments = v8_value | 431 arguments = v8_value |
| 425 | 432 |
| 426 if base_idl_type in V8_VALUE_TO_CPP_VALUE: | 433 if base_idl_type in V8_VALUE_TO_CPP_VALUE: |
| 427 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] | 434 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] |
| 428 elif idl_type.is_typed_array_type: | 435 elif idl_type.is_typed_array_type: |
| 429 cpp_expression_format = ( | 436 cpp_expression_format = ( |
| 430 '{v8_value}->Is{idl_type}() ? ' | 437 '{v8_value}->Is{idl_type}() ? ' |
| 431 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value})
) : 0') | 438 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value})
) : 0') |
| 432 else: | 439 else: |
| 433 cpp_expression_format = ( | 440 cpp_expression_format = ( |
| 434 'V8{idl_type}::toNativeWithTypeCheck(info.GetIsolate(), {v8_value})'
) | 441 'V8{idl_type}::toNativeWithTypeCheck({isolate}, {v8_value})') |
| 435 | 442 |
| 436 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t
ype, v8_value=v8_value) | 443 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t
ype, v8_value=v8_value, isolate=isolate) |
| 437 | 444 |
| 438 | 445 |
| 439 def v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v8_value, in
dex): | 446 def v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v8_value, in
dex, isolate='info.GetIsolate()'): |
| 440 # Index is None for setters, index (starting at 0) for method arguments, | 447 # Index is None for setters, index (starting at 0) for method arguments, |
| 441 # and is used to provide a human-readable exception message | 448 # and is used to provide a human-readable exception message |
| 442 if index is None: | 449 if index is None: |
| 443 index = 0 # special case, meaning "setter" | 450 index = 0 # special case, meaning "setter" |
| 444 else: | 451 else: |
| 445 index += 1 # human-readable index | 452 index += 1 # human-readable index |
| 446 if (array_or_sequence_type.is_interface_type and | 453 if (array_or_sequence_type.is_interface_type and |
| 447 array_or_sequence_type.name != 'Dictionary'): | 454 array_or_sequence_type.name != 'Dictionary'): |
| 448 this_cpp_type = None | 455 this_cpp_type = None |
| 449 ref_ptr_type = cpp_ptr_type('RefPtr', 'Member', array_or_sequence_type.g
c_type) | 456 ref_ptr_type = cpp_ptr_type('RefPtr', 'Member', array_or_sequence_type.g
c_type) |
| 450 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ
e}, V8{array_or_sequence_type}>({v8_value}, {index}, info.GetIsolate()))' | 457 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ
e}, V8{array_or_sequence_type}>({v8_value}, {index}, {isolate}))' |
| 451 add_includes_for_type(array_or_sequence_type) | 458 add_includes_for_type(array_or_sequence_type) |
| 452 else: | 459 else: |
| 453 ref_ptr_type = None | 460 ref_ptr_type = None |
| 454 this_cpp_type = array_or_sequence_type.cpp_type | 461 this_cpp_type = array_or_sequence_type.cpp_type |
| 455 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, info
.GetIsolate())' | 462 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, {iso
late})' |
| 456 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) | 463 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, isolate=isolate) |
| 457 return expression | 464 return expression |
| 458 | 465 |
| 459 | 466 |
| 460 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, index=None, declare_variable=True): | 467 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, index=None, declare_variable=True): |
| 461 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" | 468 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" |
| 462 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, used_as_argument=True) | 469 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, used_as_raw_type=True) |
| 463 | 470 |
| 464 idl_type = idl_type.preprocessed_type | 471 idl_type = idl_type.preprocessed_type |
| 465 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i
ndex) | 472 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i
ndex) |
| 466 args = [variable_name, cpp_value] | 473 args = [variable_name, cpp_value] |
| 467 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type
: | 474 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type
: |
| 468 macro = 'TOSTRING_VOID' | 475 macro = 'TOSTRING_VOID' |
| 469 elif (idl_type.is_integer_type or | 476 elif (idl_type.is_integer_type or |
| 470 idl_type.name in ('ByteString', 'ScalarValueString')): | 477 idl_type.name in ('ByteString', 'ScalarValueString')): |
| 471 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' | 478 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' |
| 472 args.append('exceptionState') | 479 args.append('exceptionState') |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea
tion_context='info.Holder()', extended_attributes=None): | 689 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea
tion_context='info.Holder()', extended_attributes=None): |
| 683 """Returns an expression that converts a C++ value to a V8 value.""" | 690 """Returns an expression that converts a C++ value to a V8 value.""" |
| 684 # the isolate parameter is needed for callback interfaces | 691 # the isolate parameter is needed for callback interfaces |
| 685 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext
ended_attributes) | 692 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext
ended_attributes) |
| 686 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) | 693 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) |
| 687 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] | 694 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] |
| 688 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat
ion_context=creation_context) | 695 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat
ion_context=creation_context) |
| 689 return statement | 696 return statement |
| 690 | 697 |
| 691 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value | 698 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value |
| OLD | NEW |