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