| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 return base_idl_type | 160 return base_idl_type |
| 161 if base_idl_type in CPP_INT_TYPES: | 161 if base_idl_type in CPP_INT_TYPES: |
| 162 return 'int' | 162 return 'int' |
| 163 if base_idl_type in CPP_UNSIGNED_TYPES: | 163 if base_idl_type in CPP_UNSIGNED_TYPES: |
| 164 return 'unsigned' | 164 return 'unsigned' |
| 165 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: | 165 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: |
| 166 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] | 166 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] |
| 167 | 167 |
| 168 if base_idl_type in NON_WRAPPER_TYPES: | 168 if base_idl_type in NON_WRAPPER_TYPES: |
| 169 return 'RefPtr<%s>' % base_idl_type | 169 return 'RefPtr<%s>' % base_idl_type |
| 170 if base_idl_type == 'DOMString': | 170 if base_idl_type in ('DOMString', 'ByteString'): |
| 171 if not used_as_argument: | 171 if not used_as_argument: |
| 172 return 'String' | 172 return 'String' |
| 173 return 'V8StringResource<%s>' % string_mode() | 173 return 'V8StringResource<%s>' % string_mode() |
| 174 | 174 |
| 175 if idl_type.is_typed_array_type and used_as_argument: | 175 if idl_type.is_typed_array_type and used_as_argument: |
| 176 return base_idl_type + '*' | 176 return base_idl_type + '*' |
| 177 if idl_type.is_interface_type: | 177 if idl_type.is_interface_type: |
| 178 implemented_as_class = idl_type.implemented_as | 178 implemented_as_class = idl_type.implemented_as |
| 179 if used_as_argument: | 179 if used_as_argument: |
| 180 return implemented_as_class + '*' | 180 return implemented_as_class + '*' |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 357 |
| 358 | 358 |
| 359 ################################################################################ | 359 ################################################################################ |
| 360 # V8 -> C++ | 360 # V8 -> C++ |
| 361 ################################################################################ | 361 ################################################################################ |
| 362 | 362 |
| 363 V8_VALUE_TO_CPP_VALUE = { | 363 V8_VALUE_TO_CPP_VALUE = { |
| 364 # Basic | 364 # Basic |
| 365 'Date': 'toCoreDate({v8_value})', | 365 'Date': 'toCoreDate({v8_value})', |
| 366 'DOMString': '{v8_value}', | 366 'DOMString': '{v8_value}', |
| 367 'ByteString': 'toByteString({arguments})', |
| 367 'boolean': '{v8_value}->BooleanValue()', | 368 'boolean': '{v8_value}->BooleanValue()', |
| 368 'float': 'static_cast<float>({v8_value}->NumberValue())', | 369 'float': 'static_cast<float>({v8_value}->NumberValue())', |
| 369 'unrestricted float': 'static_cast<float>({v8_value}->NumberValue())', | 370 'unrestricted float': 'static_cast<float>({v8_value}->NumberValue())', |
| 370 'double': 'static_cast<double>({v8_value}->NumberValue())', | 371 'double': 'static_cast<double>({v8_value}->NumberValue())', |
| 371 'unrestricted double': 'static_cast<double>({v8_value}->NumberValue())', | 372 'unrestricted double': 'static_cast<double>({v8_value}->NumberValue())', |
| 372 'byte': 'toInt8({arguments})', | 373 'byte': 'toInt8({arguments})', |
| 373 'octet': 'toUInt8({arguments})', | 374 'octet': 'toUInt8({arguments})', |
| 374 'short': 'toInt16({arguments})', | 375 'short': 'toInt16({arguments})', |
| 375 'unsigned short': 'toUInt16({arguments})', | 376 'unsigned short': 'toUInt16({arguments})', |
| 376 'long': 'toInt32({arguments})', | 377 'long': 'toInt32({arguments})', |
| (...skipping 20 matching lines...) Expand all Loading... |
| 397 if array_or_sequence_type: | 398 if array_or_sequence_type: |
| 398 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v
8_value, index) | 399 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v
8_value, index) |
| 399 | 400 |
| 400 # Simple types | 401 # Simple types |
| 401 idl_type = idl_type.preprocessed_type | 402 idl_type = idl_type.preprocessed_type |
| 402 add_includes_for_type(idl_type) | 403 add_includes_for_type(idl_type) |
| 403 base_idl_type = idl_type.base_type | 404 base_idl_type = idl_type.base_type |
| 404 | 405 |
| 405 if 'EnforceRange' in extended_attributes: | 406 if 'EnforceRange' in extended_attributes: |
| 406 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) | 407 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) |
| 407 elif idl_type.is_integer_type: # NormalConversion | 408 elif idl_type.is_integer_type or idl_type.name == 'ByteString': # NormalCon
version |
| 408 arguments = ', '.join([v8_value, 'exceptionState']) | 409 arguments = ', '.join([v8_value, 'exceptionState']) |
| 409 else: | 410 else: |
| 410 arguments = v8_value | 411 arguments = v8_value |
| 411 | 412 |
| 412 if base_idl_type in V8_VALUE_TO_CPP_VALUE: | 413 if base_idl_type in V8_VALUE_TO_CPP_VALUE: |
| 413 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] | 414 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] |
| 414 elif idl_type.is_typed_array_type: | 415 elif idl_type.is_typed_array_type: |
| 415 cpp_expression_format = ( | 416 cpp_expression_format = ( |
| 416 '{v8_value}->Is{idl_type}() ? ' | 417 '{v8_value}->Is{idl_type}() ? ' |
| 417 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value})
) : 0') | 418 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value})
) : 0') |
| (...skipping 27 matching lines...) Expand all Loading... |
| 445 | 446 |
| 446 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, index=None, declare_variable=True): | 447 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
e_name, index=None, declare_variable=True): |
| 447 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" | 448 """Returns an expression that converts a V8 value to a C++ value and stores
it as a local value.""" |
| 448 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, used_as_argument=True) | 449 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, used_as_argument=True) |
| 449 | 450 |
| 450 idl_type = idl_type.preprocessed_type | 451 idl_type = idl_type.preprocessed_type |
| 451 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i
ndex) | 452 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i
ndex) |
| 452 args = [variable_name, cpp_value] | 453 args = [variable_name, cpp_value] |
| 453 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type
: | 454 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type
: |
| 454 macro = 'TOSTRING_VOID' | 455 macro = 'TOSTRING_VOID' |
| 455 elif idl_type.is_integer_type: | 456 elif idl_type.is_integer_type or idl_type.name == 'ByteString': |
| 456 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' | 457 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' |
| 457 args.append('exceptionState') | 458 args.append('exceptionState') |
| 458 else: | 459 else: |
| 459 macro = 'TONATIVE_VOID' | 460 macro = 'TONATIVE_VOID' |
| 460 | 461 |
| 461 # Macros come in several variants, to minimize expensive creation of | 462 # Macros come in several variants, to minimize expensive creation of |
| 462 # v8::TryCatch. | 463 # v8::TryCatch. |
| 463 suffix = '' | 464 suffix = '' |
| 464 | 465 |
| 465 if declare_variable: | 466 if declare_variable: |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 return 'DOMWrapper' | 557 return 'DOMWrapper' |
| 557 | 558 |
| 558 IdlType.v8_conversion_type = v8_conversion_type | 559 IdlType.v8_conversion_type = v8_conversion_type |
| 559 | 560 |
| 560 | 561 |
| 561 V8_SET_RETURN_VALUE = { | 562 V8_SET_RETURN_VALUE = { |
| 562 'boolean': 'v8SetReturnValueBool(info, {cpp_value})', | 563 'boolean': 'v8SetReturnValueBool(info, {cpp_value})', |
| 563 'int': 'v8SetReturnValueInt(info, {cpp_value})', | 564 'int': 'v8SetReturnValueInt(info, {cpp_value})', |
| 564 'unsigned': 'v8SetReturnValueUnsigned(info, {cpp_value})', | 565 'unsigned': 'v8SetReturnValueUnsigned(info, {cpp_value})', |
| 565 'DOMString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())', | 566 'DOMString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())', |
| 567 'ByteString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())'
, |
| 566 # [TreatNullReturnValueAs] | 568 # [TreatNullReturnValueAs] |
| 567 'StringOrNull': 'v8SetReturnValueStringOrNull(info, {cpp_value}, info.GetIso
late())', | 569 'StringOrNull': 'v8SetReturnValueStringOrNull(info, {cpp_value}, info.GetIso
late())', |
| 568 'StringOrUndefined': 'v8SetReturnValueStringOrUndefined(info, {cpp_value}, i
nfo.GetIsolate())', | 570 'StringOrUndefined': 'v8SetReturnValueStringOrUndefined(info, {cpp_value}, i
nfo.GetIsolate())', |
| 569 'void': '', | 571 'void': '', |
| 570 # No special v8SetReturnValue* function (set value directly) | 572 # No special v8SetReturnValue* function (set value directly) |
| 571 'float': 'v8SetReturnValue(info, {cpp_value})', | 573 'float': 'v8SetReturnValue(info, {cpp_value})', |
| 572 'unrestricted float': 'v8SetReturnValue(info, {cpp_value})', | 574 'unrestricted float': 'v8SetReturnValue(info, {cpp_value})', |
| 573 'double': 'v8SetReturnValue(info, {cpp_value})', | 575 'double': 'v8SetReturnValue(info, {cpp_value})', |
| 574 'unrestricted double': 'v8SetReturnValue(info, {cpp_value})', | 576 'unrestricted double': 'v8SetReturnValue(info, {cpp_value})', |
| 575 # No special v8SetReturnValue* function, but instead convert value to V8 | 577 # No special v8SetReturnValue* function, but instead convert value to V8 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 IdlType.release = property(lambda self: self.is_interface_type) | 637 IdlType.release = property(lambda self: self.is_interface_type) |
| 636 IdlUnionType.release = property( | 638 IdlUnionType.release = property( |
| 637 lambda self: [member_type.is_interface_type | 639 lambda self: [member_type.is_interface_type |
| 638 for member_type in self.member_types]) | 640 for member_type in self.member_types]) |
| 639 | 641 |
| 640 | 642 |
| 641 CPP_VALUE_TO_V8_VALUE = { | 643 CPP_VALUE_TO_V8_VALUE = { |
| 642 # Built-in types | 644 # Built-in types |
| 643 'Date': 'v8DateOrNaN({cpp_value}, {isolate})', | 645 'Date': 'v8DateOrNaN({cpp_value}, {isolate})', |
| 644 'DOMString': 'v8String({isolate}, {cpp_value})', | 646 'DOMString': 'v8String({isolate}, {cpp_value})', |
| 647 'ByteString': 'v8String({isolate}, {cpp_value})', |
| 645 'boolean': 'v8Boolean({cpp_value}, {isolate})', | 648 'boolean': 'v8Boolean({cpp_value}, {isolate})', |
| 646 'int': 'v8::Integer::New({isolate}, {cpp_value})', | 649 'int': 'v8::Integer::New({isolate}, {cpp_value})', |
| 647 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', | 650 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', |
| 648 'float': 'v8::Number::New({isolate}, {cpp_value})', | 651 'float': 'v8::Number::New({isolate}, {cpp_value})', |
| 649 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})', | 652 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})', |
| 650 'double': 'v8::Number::New({isolate}, {cpp_value})', | 653 'double': 'v8::Number::New({isolate}, {cpp_value})', |
| 651 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})', | 654 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})', |
| 652 'void': 'v8Undefined()', | 655 'void': 'v8Undefined()', |
| 653 # Special cases | 656 # Special cases |
| 654 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener
::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v
8::Value>(v8::Null({isolate}))', | 657 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener
::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v
8::Value>(v8::Null({isolate}))', |
| 655 'ScriptValue': '{cpp_value}.v8Value()', | 658 'ScriptValue': '{cpp_value}.v8Value()', |
| 656 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han
dle<v8::Value>(v8::Null({isolate}))', | 659 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han
dle<v8::Value>(v8::Null({isolate}))', |
| 657 # General | 660 # General |
| 658 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})', | 661 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})', |
| 659 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})', | 662 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})', |
| 660 } | 663 } |
| 661 | 664 |
| 662 | 665 |
| 663 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea
tion_context='info.Holder()', extended_attributes=None): | 666 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea
tion_context='info.Holder()', extended_attributes=None): |
| 664 """Returns an expression that converts a C++ value to a V8 value.""" | 667 """Returns an expression that converts a C++ value to a V8 value.""" |
| 665 # the isolate parameter is needed for callback interfaces | 668 # the isolate parameter is needed for callback interfaces |
| 666 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext
ended_attributes) | 669 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext
ended_attributes) |
| 667 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) | 670 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) |
| 668 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] | 671 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] |
| 669 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat
ion_context=creation_context) | 672 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat
ion_context=creation_context) |
| 670 return statement | 673 return statement |
| 671 | 674 |
| 672 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value | 675 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value |
| OLD | NEW |