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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 == 'DOMString': |
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 if base_idl_type == 'ByteString': | |
Nils Barth (inactive)
2014/06/02 03:20:16
Should this be merged with the DOMString above?
(P
jsbell
2014/06/03 23:22:36
This failed due to the generated (and de-macro-ifi
| |
175 return 'String' | |
174 | 176 |
175 if idl_type.is_typed_array_type and used_as_argument: | 177 if idl_type.is_typed_array_type and used_as_argument: |
176 return base_idl_type + '*' | 178 return base_idl_type + '*' |
177 if idl_type.is_interface_type: | 179 if idl_type.is_interface_type: |
178 implemented_as_class = idl_type.implemented_as | 180 implemented_as_class = idl_type.implemented_as |
179 if used_as_argument: | 181 if used_as_argument: |
180 return implemented_as_class + '*' | 182 return implemented_as_class + '*' |
181 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' | 183 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' |
182 ptr_type = cpp_ptr_type('RefPtr', new_type, idl_type.gc_type) | 184 ptr_type = cpp_ptr_type('RefPtr', new_type, idl_type.gc_type) |
183 return cpp_template_type(ptr_type, implemented_as_class) | 185 return cpp_template_type(ptr_type, implemented_as_class) |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 | 359 |
358 | 360 |
359 ################################################################################ | 361 ################################################################################ |
360 # V8 -> C++ | 362 # V8 -> C++ |
361 ################################################################################ | 363 ################################################################################ |
362 | 364 |
363 V8_VALUE_TO_CPP_VALUE = { | 365 V8_VALUE_TO_CPP_VALUE = { |
364 # Basic | 366 # Basic |
365 'Date': 'toCoreDate({v8_value})', | 367 'Date': 'toCoreDate({v8_value})', |
366 'DOMString': '{v8_value}', | 368 'DOMString': '{v8_value}', |
369 'ByteString': 'toByteString({arguments})', | |
367 'boolean': '{v8_value}->BooleanValue()', | 370 'boolean': '{v8_value}->BooleanValue()', |
368 'float': 'static_cast<float>({v8_value}->NumberValue())', | 371 'float': 'static_cast<float>({v8_value}->NumberValue())', |
369 'unrestricted float': 'static_cast<float>({v8_value}->NumberValue())', | 372 'unrestricted float': 'static_cast<float>({v8_value}->NumberValue())', |
370 'double': 'static_cast<double>({v8_value}->NumberValue())', | 373 'double': 'static_cast<double>({v8_value}->NumberValue())', |
371 'unrestricted double': 'static_cast<double>({v8_value}->NumberValue())', | 374 'unrestricted double': 'static_cast<double>({v8_value}->NumberValue())', |
372 'byte': 'toInt8({arguments})', | 375 'byte': 'toInt8({arguments})', |
373 'octet': 'toUInt8({arguments})', | 376 'octet': 'toUInt8({arguments})', |
374 'short': 'toInt16({arguments})', | 377 'short': 'toInt16({arguments})', |
375 'unsigned short': 'toUInt16({arguments})', | 378 'unsigned short': 'toUInt16({arguments})', |
376 'long': 'toInt32({arguments})', | 379 'long': 'toInt32({arguments})', |
(...skipping 20 matching lines...) Expand all Loading... | |
397 if array_or_sequence_type: | 400 if array_or_sequence_type: |
398 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v 8_value, index) | 401 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v 8_value, index) |
399 | 402 |
400 # Simple types | 403 # Simple types |
401 idl_type = idl_type.preprocessed_type | 404 idl_type = idl_type.preprocessed_type |
402 add_includes_for_type(idl_type) | 405 add_includes_for_type(idl_type) |
403 base_idl_type = idl_type.base_type | 406 base_idl_type = idl_type.base_type |
404 | 407 |
405 if 'EnforceRange' in extended_attributes: | 408 if 'EnforceRange' in extended_attributes: |
406 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) | 409 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) |
407 elif idl_type.is_integer_type: # NormalConversion | 410 elif idl_type.is_integer_type or idl_type.base_type == 'ByteString': # Norm alConversion |
408 arguments = ', '.join([v8_value, 'exceptionState']) | 411 arguments = ', '.join([v8_value, 'exceptionState']) |
409 else: | 412 else: |
410 arguments = v8_value | 413 arguments = v8_value |
411 | 414 |
412 if base_idl_type in V8_VALUE_TO_CPP_VALUE: | 415 if base_idl_type in V8_VALUE_TO_CPP_VALUE: |
413 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] | 416 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] |
414 elif idl_type.is_typed_array_type: | 417 elif idl_type.is_typed_array_type: |
415 cpp_expression_format = ( | 418 cpp_expression_format = ( |
416 '{v8_value}->Is{idl_type}() ? ' | 419 '{v8_value}->Is{idl_type}() ? ' |
417 '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... | |
445 | 448 |
446 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True, method_has_try_catch=False): | 449 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True, method_has_try_catch=False): |
447 """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.""" |
448 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) |
449 | 452 |
450 idl_type = idl_type.preprocessed_type | 453 idl_type = idl_type.preprocessed_type |
451 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) |
452 args = [variable_name, cpp_value] | 455 args = [variable_name, cpp_value] |
453 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 : |
454 macro = 'TOSTRING_VOID' | 457 macro = 'TOSTRING_VOID' |
455 elif idl_type.is_integer_type: | 458 elif idl_type.is_integer_type or idl_type.base_type == 'ByteString': |
456 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' | 459 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' |
457 args.append('exceptionState') | 460 args.append('exceptionState') |
458 else: | 461 else: |
459 macro = 'TONATIVE_VOID' | 462 macro = 'TONATIVE_VOID' |
460 | 463 |
461 # Macros come in several variants, to minimize expensive creation of | 464 # Macros come in several variants, to minimize expensive creation of |
462 # v8::TryCatch. | 465 # v8::TryCatch. |
463 suffix = '' | 466 suffix = '' |
464 | 467 |
465 if declare_variable: | 468 if declare_variable: |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 return 'DOMWrapper' | 568 return 'DOMWrapper' |
566 | 569 |
567 IdlType.v8_conversion_type = v8_conversion_type | 570 IdlType.v8_conversion_type = v8_conversion_type |
568 | 571 |
569 | 572 |
570 V8_SET_RETURN_VALUE = { | 573 V8_SET_RETURN_VALUE = { |
571 'boolean': 'v8SetReturnValueBool(info, {cpp_value})', | 574 'boolean': 'v8SetReturnValueBool(info, {cpp_value})', |
572 'int': 'v8SetReturnValueInt(info, {cpp_value})', | 575 'int': 'v8SetReturnValueInt(info, {cpp_value})', |
573 'unsigned': 'v8SetReturnValueUnsigned(info, {cpp_value})', | 576 'unsigned': 'v8SetReturnValueUnsigned(info, {cpp_value})', |
574 'DOMString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())', | 577 'DOMString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())', |
578 'ByteString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())' , | |
575 # [TreatNullReturnValueAs] | 579 # [TreatNullReturnValueAs] |
576 'StringOrNull': 'v8SetReturnValueStringOrNull(info, {cpp_value}, info.GetIso late())', | 580 'StringOrNull': 'v8SetReturnValueStringOrNull(info, {cpp_value}, info.GetIso late())', |
577 'StringOrUndefined': 'v8SetReturnValueStringOrUndefined(info, {cpp_value}, i nfo.GetIsolate())', | 581 'StringOrUndefined': 'v8SetReturnValueStringOrUndefined(info, {cpp_value}, i nfo.GetIsolate())', |
578 'void': '', | 582 'void': '', |
579 # No special v8SetReturnValue* function (set value directly) | 583 # No special v8SetReturnValue* function (set value directly) |
580 'float': 'v8SetReturnValue(info, {cpp_value})', | 584 'float': 'v8SetReturnValue(info, {cpp_value})', |
581 'unrestricted float': 'v8SetReturnValue(info, {cpp_value})', | 585 'unrestricted float': 'v8SetReturnValue(info, {cpp_value})', |
582 'double': 'v8SetReturnValue(info, {cpp_value})', | 586 'double': 'v8SetReturnValue(info, {cpp_value})', |
583 'unrestricted double': 'v8SetReturnValue(info, {cpp_value})', | 587 'unrestricted double': 'v8SetReturnValue(info, {cpp_value})', |
584 # No special v8SetReturnValue* function, but instead convert value to V8 | 588 # No special v8SetReturnValue* function, but instead convert value to V8 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 IdlType.release = property(lambda self: self.is_interface_type) | 648 IdlType.release = property(lambda self: self.is_interface_type) |
645 IdlUnionType.release = property( | 649 IdlUnionType.release = property( |
646 lambda self: [member_type.is_interface_type | 650 lambda self: [member_type.is_interface_type |
647 for member_type in self.member_types]) | 651 for member_type in self.member_types]) |
648 | 652 |
649 | 653 |
650 CPP_VALUE_TO_V8_VALUE = { | 654 CPP_VALUE_TO_V8_VALUE = { |
651 # Built-in types | 655 # Built-in types |
652 'Date': 'v8DateOrNaN({cpp_value}, {isolate})', | 656 'Date': 'v8DateOrNaN({cpp_value}, {isolate})', |
653 'DOMString': 'v8String({isolate}, {cpp_value})', | 657 'DOMString': 'v8String({isolate}, {cpp_value})', |
658 'ByteString': 'v8String({isolate}, {cpp_value})', | |
654 'boolean': 'v8Boolean({cpp_value}, {isolate})', | 659 'boolean': 'v8Boolean({cpp_value}, {isolate})', |
655 'int': 'v8::Integer::New({isolate}, {cpp_value})', | 660 'int': 'v8::Integer::New({isolate}, {cpp_value})', |
656 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', | 661 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', |
657 'float': 'v8::Number::New({isolate}, {cpp_value})', | 662 'float': 'v8::Number::New({isolate}, {cpp_value})', |
658 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})', | 663 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})', |
659 'double': 'v8::Number::New({isolate}, {cpp_value})', | 664 'double': 'v8::Number::New({isolate}, {cpp_value})', |
660 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})', | 665 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})', |
661 'void': 'v8Undefined()', | 666 'void': 'v8Undefined()', |
662 # Special cases | 667 # Special cases |
663 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))', | 668 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))', |
664 'ScriptValue': '{cpp_value}.v8Value()', | 669 'ScriptValue': '{cpp_value}.v8Value()', |
665 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))', | 670 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))', |
666 # General | 671 # General |
667 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})', | 672 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})', |
668 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})', | 673 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})', |
669 } | 674 } |
670 | 675 |
671 | 676 |
672 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='info.Holder()', extended_attributes=None): | 677 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='info.Holder()', extended_attributes=None): |
673 """Returns an expression that converts a C++ value to a V8 value.""" | 678 """Returns an expression that converts a C++ value to a V8 value.""" |
674 # the isolate parameter is needed for callback interfaces | 679 # the isolate parameter is needed for callback interfaces |
675 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) | 680 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) |
676 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) | 681 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) |
677 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] | 682 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] |
678 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) | 683 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) |
679 return statement | 684 return statement |
680 | 685 |
681 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value | 686 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value |
OLD | NEW |