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', 'ScalarValueString'): | 170 if base_idl_type in ('DOMString', 'ByteString', 'ScalarValueString'): |
jsbell
2014/06/19 20:49:20
Use idl_type.is_string_type ?
sof
2014/06/20 07:21:16
Done.
| |
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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 if array_or_sequence_type: | 410 if array_or_sequence_type: |
411 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v 8_value, index) | 411 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v 8_value, index) |
412 | 412 |
413 # Simple types | 413 # Simple types |
414 idl_type = idl_type.preprocessed_type | 414 idl_type = idl_type.preprocessed_type |
415 add_includes_for_type(idl_type) | 415 add_includes_for_type(idl_type) |
416 base_idl_type = idl_type.base_type | 416 base_idl_type = idl_type.base_type |
417 | 417 |
418 if 'EnforceRange' in extended_attributes: | 418 if 'EnforceRange' in extended_attributes: |
419 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) | 419 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) |
420 elif (idl_type.is_integer_type or # NormalConversion | 420 elif idl_type.may_raise_exception_on_conversion: |
421 idl_type.name in ('ByteString', 'ScalarValueString')): | |
422 arguments = ', '.join([v8_value, 'exceptionState']) | 421 arguments = ', '.join([v8_value, 'exceptionState']) |
423 else: | 422 else: |
424 arguments = v8_value | 423 arguments = v8_value |
425 | 424 |
426 if base_idl_type in V8_VALUE_TO_CPP_VALUE: | 425 if base_idl_type in V8_VALUE_TO_CPP_VALUE: |
427 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] | 426 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] |
428 elif idl_type.is_typed_array_type: | 427 elif idl_type.is_typed_array_type: |
429 cpp_expression_format = ( | 428 cpp_expression_format = ( |
430 '{v8_value}->Is{idl_type}() ? ' | 429 '{v8_value}->Is{idl_type}() ? ' |
431 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value}) ) : 0') | 430 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value}) ) : 0') |
(...skipping 27 matching lines...) Expand all Loading... | |
459 | 458 |
460 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True): | 459 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.""" | 460 """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) | 461 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, used_as_argument=True) |
463 | 462 |
464 idl_type = idl_type.preprocessed_type | 463 idl_type = idl_type.preprocessed_type |
465 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex) | 464 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex) |
466 args = [variable_name, cpp_value] | 465 args = [variable_name, cpp_value] |
467 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type : | 466 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type : |
468 macro = 'TOSTRING_VOID' | 467 macro = 'TOSTRING_VOID' |
469 elif (idl_type.is_integer_type or | 468 elif idl_type.may_raise_exception_on_conversion: |
470 idl_type.name in ('ByteString', 'ScalarValueString')): | |
471 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' | 469 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' |
472 args.append('exceptionState') | 470 args.append('exceptionState') |
473 else: | 471 else: |
474 macro = 'TONATIVE_VOID' | 472 macro = 'TONATIVE_VOID' |
475 | 473 |
476 # Macros come in several variants, to minimize expensive creation of | 474 # Macros come in several variants, to minimize expensive creation of |
477 # v8::TryCatch. | 475 # v8::TryCatch. |
478 suffix = '' | 476 suffix = '' |
479 | 477 |
480 if declare_variable: | 478 if declare_variable: |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 add_includes_for_type(array_or_sequence_type) | 541 add_includes_for_type(array_or_sequence_type) |
544 return 'array' | 542 return 'array' |
545 | 543 |
546 # Simple types | 544 # Simple types |
547 base_idl_type = idl_type.base_type | 545 base_idl_type = idl_type.base_type |
548 # Basic types, without additional includes | 546 # Basic types, without additional includes |
549 if base_idl_type in CPP_INT_TYPES: | 547 if base_idl_type in CPP_INT_TYPES: |
550 return 'int' | 548 return 'int' |
551 if base_idl_type in CPP_UNSIGNED_TYPES: | 549 if base_idl_type in CPP_UNSIGNED_TYPES: |
552 return 'unsigned' | 550 return 'unsigned' |
553 if base_idl_type in ('DOMString', 'ByteString', 'ScalarValueString'): | 551 if base_idl_type in ('DOMString', 'ByteString', 'ScalarValueString'): |
jsbell
2014/06/19 20:49:19
Use idl_type.is_string_type ?
sof
2014/06/20 07:21:16
Done.
| |
554 if 'TreatReturnedNullStringAs' not in extended_attributes: | 552 if 'TreatReturnedNullStringAs' not in extended_attributes: |
555 return base_idl_type | 553 return base_idl_type |
556 treat_returned_null_string_as = extended_attributes['TreatReturnedNullSt ringAs'] | 554 treat_returned_null_string_as = extended_attributes['TreatReturnedNullSt ringAs'] |
557 if treat_returned_null_string_as == 'Null': | 555 if treat_returned_null_string_as == 'Null': |
558 return 'StringOrNull' | 556 return 'StringOrNull' |
559 if treat_returned_null_string_as == 'Undefined': | 557 if treat_returned_null_string_as == 'Undefined': |
560 return 'StringOrUndefined' | 558 return 'StringOrUndefined' |
561 raise 'Unrecognized TreatReturnNullStringAs value: "%s"' % treat_returne d_null_string_as | 559 raise 'Unrecognized TreatReturnNullStringAs value: "%s"' % treat_returne d_null_string_as |
562 if idl_type.is_basic_type or base_idl_type == 'ScriptValue': | 560 if idl_type.is_basic_type or base_idl_type == 'ScriptValue': |
563 return base_idl_type | 561 return base_idl_type |
(...skipping 118 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): | 680 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.""" | 681 """Returns an expression that converts a C++ value to a V8 value.""" |
684 # the isolate parameter is needed for callback interfaces | 682 # 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) | 683 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) | 684 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) |
687 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] | 685 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) | 686 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) |
689 return statement | 687 return statement |
690 | 688 |
691 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value | 689 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value |
OLD | NEW |