Chromium Code Reviews| 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 23 matching lines...) Expand all Loading... | |
| 34 class methods. | 34 class methods. |
| 35 | 35 |
| 36 Spec: | 36 Spec: |
| 37 http://www.w3.org/TR/WebIDL/#es-type-mapping | 37 http://www.w3.org/TR/WebIDL/#es-type-mapping |
| 38 | 38 |
| 39 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 39 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
| 40 """ | 40 """ |
| 41 | 41 |
| 42 import posixpath | 42 import posixpath |
| 43 | 43 |
| 44 from idl_types import IdlTypeBase, IdlType, IdlUnionType, IdlArrayOrSequenceType , IdlNullableType | 44 from idl_types import IdlArrayOrSequenceType |
| 45 from idl_types import IdlNullableType | |
| 46 from idl_types import IdlRecordType | |
| 47 from idl_types import IdlType | |
| 48 from idl_types import IdlTypeBase | |
| 49 from idl_types import IdlUnionType | |
| 45 import v8_attributes # for IdlType.constructor_type_name | 50 import v8_attributes # for IdlType.constructor_type_name |
| 46 from v8_globals import includes | 51 from v8_globals import includes |
| 47 from v8_utilities import extended_attribute_value_contains | 52 from v8_utilities import extended_attribute_value_contains |
| 48 | 53 |
| 49 | 54 |
| 50 ################################################################################ | 55 ################################################################################ |
| 51 # V8-specific handling of IDL types | 56 # V8-specific handling of IDL types |
| 52 ################################################################################ | 57 ################################################################################ |
| 53 | 58 |
| 54 NON_WRAPPER_TYPES = frozenset([ | 59 NON_WRAPPER_TYPES = frozenset([ |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 IdlType | 138 IdlType |
| 134 raw_type: | 139 raw_type: |
| 135 bool, True if idl_type's raw/primitive C++ type should be returned. | 140 bool, True if idl_type's raw/primitive C++ type should be returned. |
| 136 used_as_rvalue_type: | 141 used_as_rvalue_type: |
| 137 bool, True if the C++ type is used as an argument or the return | 142 bool, True if the C++ type is used as an argument or the return |
| 138 type of a method. | 143 type of a method. |
| 139 used_as_variadic_argument: | 144 used_as_variadic_argument: |
| 140 bool, True if the C++ type is used as a variadic argument of a metho d. | 145 bool, True if the C++ type is used as a variadic argument of a metho d. |
| 141 used_in_cpp_sequence: | 146 used_in_cpp_sequence: |
| 142 bool, True if the C++ type is used as an element of a container. | 147 bool, True if the C++ type is used as an element of a container. |
| 143 Containers can be an array, a sequence or a dictionary. | 148 Containers can be an array, a sequence, a dictionary or a record. |
| 144 """ | 149 """ |
| 145 def string_mode(): | 150 def string_mode(): |
| 146 if idl_type.is_nullable: | 151 if idl_type.is_nullable: |
| 147 return 'TreatNullAndUndefinedAsNullString' | 152 return 'TreatNullAndUndefinedAsNullString' |
| 148 if extended_attributes.get('TreatNullAs') == 'EmptyString': | 153 if extended_attributes.get('TreatNullAs') == 'EmptyString': |
| 149 return 'TreatNullAsEmptyString' | 154 return 'TreatNullAsEmptyString' |
| 150 if extended_attributes.get('TreatNullAs') == 'NullString': | 155 if extended_attributes.get('TreatNullAs') == 'NullString': |
| 151 return 'TreatNullAsNullString' | 156 return 'TreatNullAsNullString' |
| 152 return '' | 157 return '' |
| 153 | 158 |
| 154 extended_attributes = extended_attributes or {} | 159 extended_attributes = extended_attributes or {} |
| 155 idl_type = idl_type.preprocessed_type | 160 idl_type = idl_type.preprocessed_type |
| 156 | 161 |
| 157 # Array or sequence types | 162 # Array or sequence types |
| 158 if used_as_variadic_argument: | 163 if used_as_variadic_argument: |
| 159 native_array_element_type = idl_type | 164 native_array_element_type = idl_type |
| 160 else: | 165 else: |
| 161 native_array_element_type = idl_type.native_array_element_type | 166 native_array_element_type = idl_type.native_array_element_type |
| 162 if native_array_element_type: | 167 if native_array_element_type: |
| 163 vector_type = cpp_ptr_type('Vector', 'HeapVector', native_array_element_ type.is_gc_type) | 168 vector_type = cpp_ptr_type('Vector', 'HeapVector', native_array_element_ type.is_gc_type) |
| 164 vector_template_type = cpp_template_type(vector_type, native_array_eleme nt_type.cpp_type_args(used_in_cpp_sequence=True)) | 169 vector_template_type = cpp_template_type(vector_type, native_array_eleme nt_type.cpp_type_args(used_in_cpp_sequence=True)) |
| 165 if used_as_rvalue_type: | 170 if used_as_rvalue_type: |
| 166 return 'const %s&' % vector_template_type | 171 return 'const %s&' % vector_template_type |
| 167 return vector_template_type | 172 return vector_template_type |
| 168 | 173 |
| 174 # Record types. | |
| 175 if idl_type.is_record_type: | |
| 176 vector_type = cpp_ptr_type('Vector', 'HeapVector', idl_type.value_type.i s_gc_type) | |
| 177 value_type = idl_type.value_type.cpp_type_args(used_in_cpp_sequence=True ) | |
| 178 vector_template_type = cpp_template_type(vector_type, | |
| 179 'std::pair<String, %s>' % value _type) | |
| 180 if used_as_rvalue_type: | |
| 181 return 'const %s&' % vector_template_type | |
| 182 return vector_template_type | |
| 183 | |
| 169 # Simple types | 184 # Simple types |
| 170 base_idl_type = idl_type.base_type | 185 base_idl_type = idl_type.base_type |
| 171 | 186 |
| 172 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE: | 187 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE: |
| 173 return base_idl_type | 188 return base_idl_type |
| 174 if base_idl_type in CPP_INTEGER_CONVERSION_RULES: | 189 if base_idl_type in CPP_INTEGER_CONVERSION_RULES: |
| 175 return CPP_INTEGER_CONVERSION_RULES[base_idl_type] | 190 return CPP_INTEGER_CONVERSION_RULES[base_idl_type] |
| 176 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: | 191 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: |
| 177 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] | 192 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] |
| 178 | 193 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 IdlTypeBase.is_gc_type = property(is_gc_type) | 325 IdlTypeBase.is_gc_type = property(is_gc_type) |
| 311 | 326 |
| 312 | 327 |
| 313 def is_traceable(idl_type): | 328 def is_traceable(idl_type): |
| 314 return (idl_type.is_garbage_collected or idl_type.is_dictionary) | 329 return (idl_type.is_garbage_collected or idl_type.is_dictionary) |
| 315 | 330 |
| 316 IdlTypeBase.is_traceable = property(is_traceable) | 331 IdlTypeBase.is_traceable = property(is_traceable) |
| 317 IdlUnionType.is_traceable = property(lambda self: True) | 332 IdlUnionType.is_traceable = property(lambda self: True) |
| 318 IdlArrayOrSequenceType.is_traceable = property( | 333 IdlArrayOrSequenceType.is_traceable = property( |
| 319 lambda self: self.element_type.is_traceable) | 334 lambda self: self.element_type.is_traceable) |
| 335 IdlRecordType.is_traceable = property( | |
| 336 lambda self: self.value_type.is_traceable) | |
| 320 | 337 |
| 321 | 338 |
| 322 ################################################################################ | 339 ################################################################################ |
| 323 # Includes | 340 # Includes |
| 324 ################################################################################ | 341 ################################################################################ |
| 325 | 342 |
| 326 INCLUDES_FOR_TYPE = { | 343 INCLUDES_FOR_TYPE = { |
| 327 'object': set(), | 344 'object': set(), |
| 328 'ArrayBufferView': set(['bindings/core/v8/V8ArrayBufferView.h', | 345 'ArrayBufferView': set(['bindings/core/v8/V8ArrayBufferView.h', |
| 329 'core/dom/FlexibleArrayBufferView.h']), | 346 'core/dom/FlexibleArrayBufferView.h']), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 | 413 |
| 397 IdlUnionType.includes_for_type = includes_for_union_type | 414 IdlUnionType.includes_for_type = includes_for_union_type |
| 398 | 415 |
| 399 | 416 |
| 400 def includes_for_array_or_sequence_type(idl_type, extended_attributes=None): | 417 def includes_for_array_or_sequence_type(idl_type, extended_attributes=None): |
| 401 return idl_type.element_type.includes_for_type(extended_attributes) | 418 return idl_type.element_type.includes_for_type(extended_attributes) |
| 402 | 419 |
| 403 IdlArrayOrSequenceType.includes_for_type = includes_for_array_or_sequence_type | 420 IdlArrayOrSequenceType.includes_for_type = includes_for_array_or_sequence_type |
| 404 | 421 |
| 405 | 422 |
| 423 def includes_for_record_type(idl_type, extended_attributes=None): | |
| 424 return set.union(idl_type.key_type.includes_for_type(extended_attributes), | |
| 425 idl_type.value_type.includes_for_type(extended_attributes)) | |
| 426 | |
| 427 IdlRecordType.includes_for_type = includes_for_record_type | |
| 428 | |
| 429 | |
| 406 def add_includes_for_type(idl_type, extended_attributes=None): | 430 def add_includes_for_type(idl_type, extended_attributes=None): |
| 407 includes.update(idl_type.includes_for_type(extended_attributes)) | 431 includes.update(idl_type.includes_for_type(extended_attributes)) |
| 408 | 432 |
| 409 IdlTypeBase.add_includes_for_type = add_includes_for_type | 433 IdlTypeBase.add_includes_for_type = add_includes_for_type |
| 410 | 434 |
| 411 | 435 |
| 412 def includes_for_interface(interface_name): | 436 def includes_for_interface(interface_name): |
| 413 return IdlType(interface_name).includes_for_type() | 437 return IdlType(interface_name).includes_for_type() |
| 414 | 438 |
| 415 | 439 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 | 516 |
| 493 | 517 |
| 494 def v8_conversion_needs_exception_state(idl_type): | 518 def v8_conversion_needs_exception_state(idl_type): |
| 495 return (idl_type.is_numeric_type or | 519 return (idl_type.is_numeric_type or |
| 496 idl_type.is_enum or | 520 idl_type.is_enum or |
| 497 idl_type.is_dictionary or | 521 idl_type.is_dictionary or |
| 498 idl_type.name in ('Boolean', 'ByteString', 'Date', 'Dictionary', 'US VString', 'SerializedScriptValue')) | 522 idl_type.name in ('Boolean', 'ByteString', 'Date', 'Dictionary', 'US VString', 'SerializedScriptValue')) |
| 499 | 523 |
| 500 IdlType.v8_conversion_needs_exception_state = property(v8_conversion_needs_excep tion_state) | 524 IdlType.v8_conversion_needs_exception_state = property(v8_conversion_needs_excep tion_state) |
| 501 IdlArrayOrSequenceType.v8_conversion_needs_exception_state = True | 525 IdlArrayOrSequenceType.v8_conversion_needs_exception_state = True |
| 526 IdlRecordType.v8_conversion_needs_exception_state = True | |
| 502 IdlUnionType.v8_conversion_needs_exception_state = True | 527 IdlUnionType.v8_conversion_needs_exception_state = True |
| 503 | 528 |
| 504 | 529 |
| 505 TRIVIAL_CONVERSIONS = frozenset([ | 530 TRIVIAL_CONVERSIONS = frozenset([ |
| 506 'any', | 531 'any', |
| 507 'boolean', | 532 'boolean', |
| 508 'Date', | 533 'Date', |
| 509 'Dictionary', | 534 'Dictionary', |
| 510 'NodeFilter', | 535 'NodeFilter', |
| 511 'XPathNSResolver', | 536 'XPathNSResolver', |
| 512 'Promise' | 537 'Promise' |
| 513 ]) | 538 ]) |
| 514 | 539 |
| 515 | 540 |
| 516 def v8_conversion_is_trivial(idl_type): | 541 def v8_conversion_is_trivial(idl_type): |
| 517 # The conversion is a simple expression that returns the converted value and | 542 # The conversion is a simple expression that returns the converted value and |
| 518 # cannot raise an exception. | 543 # cannot raise an exception. |
| 519 return (idl_type.base_type in TRIVIAL_CONVERSIONS or | 544 return (idl_type.base_type in TRIVIAL_CONVERSIONS or |
| 520 idl_type.is_wrapper_type) | 545 idl_type.is_wrapper_type) |
| 521 | 546 |
| 522 IdlType.v8_conversion_is_trivial = property(v8_conversion_is_trivial) | 547 IdlType.v8_conversion_is_trivial = property(v8_conversion_is_trivial) |
| 523 | 548 |
| 524 | 549 |
| 550 def native_value_traits_type_name(idl_type): | |
| 551 if idl_type.is_nullable: | |
| 552 idl_type = idl_type.inner_type | |
| 553 | |
| 554 if idl_type.native_array_element_type: | |
| 555 name = 'IDLSequence<%s>' % native_value_traits_type_name(idl_type.native _array_element_type) | |
| 556 elif idl_type.is_record_type: | |
| 557 name = 'IDLRecord<%s, %s>' % (native_value_traits_type_name(idl_type.key _type), | |
| 558 native_value_traits_type_name(idl_type.val ue_type)) | |
| 559 elif idl_type.is_basic_type or idl_type.name in ('Date', 'Promise'): | |
|
haraken
2017/03/09 12:52:55
I think Date is included in basic types.
Raphael Kubo da Costa (rakuco)
2017/03/09 16:08:34
Indeed. I'll fix this.
| |
| 560 name = 'IDL%s' % idl_type.name | |
| 561 elif idl_type.implemented_as is not None: | |
| 562 name = idl_type.implemented_as | |
| 563 else: | |
| 564 name = idl_type.name | |
| 565 return name | |
| 566 | |
| 567 | |
| 525 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name , index, isolate): | 568 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name , index, isolate): |
| 526 if idl_type.name == 'void': | 569 if idl_type.name == 'void': |
| 527 return '' | 570 return '' |
| 528 | 571 |
| 529 # Array or sequence types | 572 # Array or sequence types |
| 530 native_array_element_type = idl_type.native_array_element_type | 573 native_array_element_type = idl_type.native_array_element_type |
| 531 if native_array_element_type: | 574 if native_array_element_type: |
| 532 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate) | 575 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate) |
| 533 | 576 |
| 534 # Simple types | 577 # Simple types |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 562 nullable = 'UnionTypeConversionMode::Nullable' if idl_type.includes_null able_type else 'UnionTypeConversionMode::NotNullable' | 605 nullable = 'UnionTypeConversionMode::Nullable' if idl_type.includes_null able_type else 'UnionTypeConversionMode::NotNullable' |
| 563 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, %s, exceptionState)' % nullable | 606 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, %s, exceptionState)' % nullable |
| 564 elif idl_type.use_output_parameter_for_result: | 607 elif idl_type.use_output_parameter_for_result: |
| 565 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, exceptionState)' | 608 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, exceptionState)' |
| 566 elif idl_type.is_callback_function: | 609 elif idl_type.is_callback_function: |
| 567 cpp_expression_format = ( | 610 cpp_expression_format = ( |
| 568 '{idl_type}::create(ScriptState::current({isolate}), {v8_value})') | 611 '{idl_type}::create(ScriptState::current({isolate}), {v8_value})') |
| 569 elif idl_type.v8_conversion_needs_exception_state: | 612 elif idl_type.v8_conversion_needs_exception_state: |
| 570 # Effectively, this if branch means everything with v8_conversion_needs_ exception_state == True | 613 # Effectively, this if branch means everything with v8_conversion_needs_ exception_state == True |
| 571 # except for unions, sequences and dictionary interfaces. | 614 # except for unions, sequences and dictionary interfaces. |
| 572 if idl_type.is_nullable: | 615 base_idl_type = native_value_traits_type_name(idl_type) |
| 573 idl_type = idl_type.inner_type | |
| 574 if idl_type.is_primitive_type or idl_type.name in ('ByteString', 'Date', 'Promise', 'USVString'): | |
| 575 trait_type = 'IDL%s' % idl_type.name | |
| 576 else: | |
| 577 trait_type = idl_type.name | |
| 578 cpp_expression_format = ( | 616 cpp_expression_format = ( |
| 579 'NativeValueTraits<%s>::nativeValue({isolate}, {arguments})' % trait _type) | 617 'NativeValueTraits<{idl_type}>::nativeValue({isolate}, {arguments})' ) |
| 580 else: | 618 else: |
| 581 cpp_expression_format = ( | 619 cpp_expression_format = ( |
| 582 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})') | 620 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})') |
| 583 | 621 |
| 584 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t ype, v8_value=v8_value, variable_name=variable_name, isolate=isolate) | 622 return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_t ype, v8_value=v8_value, variable_name=variable_name, isolate=isolate) |
| 585 | 623 |
| 586 | 624 |
| 587 def v8_value_to_cpp_value_array_or_sequence(native_array_element_type, v8_value, index, isolate='info.GetIsolate()'): | 625 def v8_value_to_cpp_value_array_or_sequence(native_array_element_type, v8_value, index, isolate='info.GetIsolate()'): |
| 588 # Index is None for setters, index (starting at 0) for method arguments, | 626 # Index is None for setters, index (starting at 0) for method arguments, |
| 589 # and is used to provide a human-readable exception message | 627 # and is used to provide a human-readable exception message |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 741 return 'NullableDictionary' | 779 return 'NullableDictionary' |
| 742 | 780 |
| 743 if idl_type.is_dictionary or idl_type.is_union_type: | 781 if idl_type.is_dictionary or idl_type.is_union_type: |
| 744 return 'DictionaryOrUnion' | 782 return 'DictionaryOrUnion' |
| 745 | 783 |
| 746 # Array or sequence types | 784 # Array or sequence types |
| 747 native_array_element_type = idl_type.native_array_element_type | 785 native_array_element_type = idl_type.native_array_element_type |
| 748 if native_array_element_type: | 786 if native_array_element_type: |
| 749 return 'FrozenArray' if idl_type.is_frozen_array else 'array' | 787 return 'FrozenArray' if idl_type.is_frozen_array else 'array' |
| 750 | 788 |
| 789 # Record types. | |
| 790 if idl_type.is_record_type: | |
| 791 return 'Record' | |
| 792 | |
| 751 # Simple types | 793 # Simple types |
| 752 base_idl_type = idl_type.base_type | 794 base_idl_type = idl_type.base_type |
| 753 # Basic types, without additional includes | 795 # Basic types, without additional includes |
| 754 if base_idl_type in CPP_INTEGER_CONVERSION_RULES: | 796 if base_idl_type in CPP_INTEGER_CONVERSION_RULES: |
| 755 return CPP_INTEGER_CONVERSION_RULES[base_idl_type] | 797 return CPP_INTEGER_CONVERSION_RULES[base_idl_type] |
| 756 if idl_type.is_string_type: | 798 if idl_type.is_string_type: |
| 757 if idl_type.is_nullable: | 799 if idl_type.is_nullable: |
| 758 return 'StringOrNull' | 800 return 'StringOrNull' |
| 759 return base_idl_type | 801 return base_idl_type |
| 760 if idl_type.is_basic_type or base_idl_type == 'ScriptValue': | 802 if idl_type.is_basic_type or base_idl_type == 'ScriptValue': |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 'double': 'v8SetReturnValue(info, {cpp_value})', | 837 'double': 'v8SetReturnValue(info, {cpp_value})', |
| 796 'unrestricted double': 'v8SetReturnValue(info, {cpp_value})', | 838 'unrestricted double': 'v8SetReturnValue(info, {cpp_value})', |
| 797 # No special v8SetReturnValue* function, but instead convert value to V8 | 839 # No special v8SetReturnValue* function, but instead convert value to V8 |
| 798 # and then use general v8SetReturnValue. | 840 # and then use general v8SetReturnValue. |
| 799 'array': 'v8SetReturnValue(info, {cpp_value})', | 841 'array': 'v8SetReturnValue(info, {cpp_value})', |
| 800 'FrozenArray': 'v8SetReturnValue(info, {cpp_value})', | 842 'FrozenArray': 'v8SetReturnValue(info, {cpp_value})', |
| 801 'Date': 'v8SetReturnValue(info, {cpp_value})', | 843 'Date': 'v8SetReturnValue(info, {cpp_value})', |
| 802 'EventHandler': 'v8SetReturnValue(info, {cpp_value})', | 844 'EventHandler': 'v8SetReturnValue(info, {cpp_value})', |
| 803 'ScriptValue': 'v8SetReturnValue(info, {cpp_value})', | 845 'ScriptValue': 'v8SetReturnValue(info, {cpp_value})', |
| 804 'SerializedScriptValue': 'v8SetReturnValue(info, {cpp_value})', | 846 'SerializedScriptValue': 'v8SetReturnValue(info, {cpp_value})', |
| 847 # Records. | |
| 848 'Record': 'v8SetReturnValue(info, ToV8({cpp_value}, info.Holder(), info.GetI solate()))', | |
| 805 # DOMWrapper | 849 # DOMWrapper |
| 806 'DOMWrapperForMainWorld': 'v8SetReturnValueForMainWorld(info, {cpp_value})', | 850 'DOMWrapperForMainWorld': 'v8SetReturnValueForMainWorld(info, {cpp_value})', |
| 807 'DOMWrapperFast': 'v8SetReturnValueFast(info, {cpp_value}, {script_wrappable })', | 851 'DOMWrapperFast': 'v8SetReturnValueFast(info, {cpp_value}, {script_wrappable })', |
| 808 'DOMWrapperDefault': 'v8SetReturnValue(info, {cpp_value})', | 852 'DOMWrapperDefault': 'v8SetReturnValue(info, {cpp_value})', |
| 809 # If [CheckSecurity=ReturnValue] is specified, the returned object must be | 853 # If [CheckSecurity=ReturnValue] is specified, the returned object must be |
| 810 # wrapped in its own realm, which can be different from the realm of the | 854 # wrapped in its own realm, which can be different from the realm of the |
| 811 # receiver object. | 855 # receiver object. |
| 812 # | 856 # |
| 813 # [CheckSecurity=ReturnValue] is used only for contentDocument and | 857 # [CheckSecurity=ReturnValue] is used only for contentDocument and |
| 814 # getSVGDocument attributes of HTML{IFrame,Frame,Object,Embed}Element, | 858 # getSVGDocument attributes of HTML{IFrame,Frame,Object,Embed}Element, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 869 format_string = V8_SET_RETURN_VALUE[this_v8_conversion_type] | 913 format_string = V8_SET_RETURN_VALUE[this_v8_conversion_type] |
| 870 statement = format_string.format(cpp_value=cpp_value, script_wrappable=scrip t_wrappable) | 914 statement = format_string.format(cpp_value=cpp_value, script_wrappable=scrip t_wrappable) |
| 871 return statement | 915 return statement |
| 872 | 916 |
| 873 | 917 |
| 874 IdlTypeBase.v8_set_return_value = v8_set_return_value | 918 IdlTypeBase.v8_set_return_value = v8_set_return_value |
| 875 | 919 |
| 876 | 920 |
| 877 CPP_VALUE_TO_V8_VALUE = { | 921 CPP_VALUE_TO_V8_VALUE = { |
| 878 # Built-in types | 922 # Built-in types |
| 879 'Date': 'v8DateOrNaN({isolate}, {cpp_value})', | 923 'Date': 'v8DateOrNaN({isolate}, {cpp_value})', |
|
haraken
2017/03/09 12:52:55
Not related to this CL, do you think it's a good i
Yuki
2017/03/09 13:00:56
We already have support of ToV8 for primitive type
| |
| 880 'DOMString': 'v8String({isolate}, {cpp_value})', | 924 'DOMString': 'v8String({isolate}, {cpp_value})', |
| 881 'ByteString': 'v8String({isolate}, {cpp_value})', | 925 'ByteString': 'v8String({isolate}, {cpp_value})', |
| 882 'USVString': 'v8String({isolate}, {cpp_value})', | 926 'USVString': 'v8String({isolate}, {cpp_value})', |
| 883 'boolean': 'v8Boolean({cpp_value}, {isolate})', | 927 'boolean': 'v8Boolean({cpp_value}, {isolate})', |
| 884 # All the int types below are converted to (u)int32_t in the v8::Integer::Ne w*() calls. | 928 # All the int types below are converted to (u)int32_t in the v8::Integer::Ne w*() calls. |
| 885 # The 64-bit int types have already been converted to double when CPP_VALUE_ TO_V8_VALUE is used, so they are not | 929 # The 64-bit int types have already been converted to double when CPP_VALUE_ TO_V8_VALUE is used, so they are not |
| 886 # listed here. | 930 # listed here. |
| 887 'int8_t': 'v8::Integer::New({isolate}, {cpp_value})', | 931 'int8_t': 'v8::Integer::New({isolate}, {cpp_value})', |
| 888 'int16_t': 'v8::Integer::New({isolate}, {cpp_value})', | 932 'int16_t': 'v8::Integer::New({isolate}, {cpp_value})', |
| 889 'int32_t': 'v8::Integer::New({isolate}, {cpp_value})', | 933 'int32_t': 'v8::Integer::New({isolate}, {cpp_value})', |
| 890 'uint8_t': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', | 934 'uint8_t': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', |
| 891 'uint16_t': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', | 935 'uint16_t': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', |
| 892 'uint32_t': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', | 936 'uint32_t': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', |
| 893 'float': 'v8::Number::New({isolate}, {cpp_value})', | 937 'float': 'v8::Number::New({isolate}, {cpp_value})', |
| 894 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})', | 938 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})', |
| 895 'double': 'v8::Number::New({isolate}, {cpp_value})', | 939 'double': 'v8::Number::New({isolate}, {cpp_value})', |
| 896 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})', | 940 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})', |
| 897 'void': 'v8Undefined()', | 941 'void': 'v8Undefined()', |
| 898 'StringOrNull': '{cpp_value}.isNull() ? v8::Local<v8::Value>(v8::Null({isola te})) : v8String({isolate}, {cpp_value})', | 942 'StringOrNull': '{cpp_value}.isNull() ? v8::Local<v8::Value>(v8::Null({isola te})) : v8String({isolate}, {cpp_value})', |
| 899 # Special cases | 943 # Special cases |
| 900 'Dictionary': '{cpp_value}.v8Value()', | 944 'Dictionary': '{cpp_value}.v8Value()', |
| 901 'EventHandler': ( | 945 'EventHandler': ( |
| 902 '{cpp_value} ? ' + | 946 '{cpp_value} ? ' + |
| 903 'V8AbstractEventListener::cast({cpp_value})->getListenerOrNull(' + | 947 'V8AbstractEventListener::cast({cpp_value})->getListenerOrNull(' + |
| 904 '{isolate}, impl->getExecutionContext()) : ' + | 948 '{isolate}, impl->getExecutionContext()) : ' + |
| 905 'v8::Null({isolate}).As<v8::Value>()'), | 949 'v8::Null({isolate}).As<v8::Value>()'), |
| 950 'Record': 'ToV8({cpp_value}, {creation_context}, {isolate})', | |
| 906 'ScriptValue': '{cpp_value}.v8Value()', | 951 'ScriptValue': '{cpp_value}.v8Value()', |
| 907 'SerializedScriptValue': 'v8Deserialize({isolate}, {cpp_value})', | 952 'SerializedScriptValue': 'v8Deserialize({isolate}, {cpp_value})', |
| 908 # General | 953 # General |
| 909 'array': 'ToV8({cpp_value}, {creation_context}, {isolate})', | 954 'array': 'ToV8({cpp_value}, {creation_context}, {isolate})', |
| 910 'FrozenArray': 'freezeV8Object(ToV8({cpp_value}, {creation_context}, {isolat e}), {isolate})', | 955 'FrozenArray': 'freezeV8Object(ToV8({cpp_value}, {creation_context}, {isolat e}), {isolate})', |
| 911 'DOMWrapper': 'ToV8({cpp_value}, {creation_context}, {isolate})', | 956 'DOMWrapper': 'ToV8({cpp_value}, {creation_context}, {isolate})', |
| 912 # Passing nullable dictionaries isn't a pattern currently used | 957 # Passing nullable dictionaries isn't a pattern currently used |
| 913 # anywhere in the web platform, and more work would be needed in | 958 # anywhere in the web platform, and more work would be needed in |
| 914 # the code generator to distinguish between passing null, and | 959 # the code generator to distinguish between passing null, and |
| 915 # passing an object which happened to not contain any of the | 960 # passing an object which happened to not contain any of the |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1029 number_of_nullable_member_types_union) | 1074 number_of_nullable_member_types_union) |
| 1030 | 1075 |
| 1031 | 1076 |
| 1032 def includes_nullable_type_union(idl_type): | 1077 def includes_nullable_type_union(idl_type): |
| 1033 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type | 1078 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type |
| 1034 return idl_type.number_of_nullable_member_types == 1 | 1079 return idl_type.number_of_nullable_member_types == 1 |
| 1035 | 1080 |
| 1036 IdlTypeBase.includes_nullable_type = False | 1081 IdlTypeBase.includes_nullable_type = False |
| 1037 IdlNullableType.includes_nullable_type = True | 1082 IdlNullableType.includes_nullable_type = True |
| 1038 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) | 1083 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) |
| OLD | NEW |