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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: | 177 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: |
| 178 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] | 178 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] |
| 179 | 179 |
| 180 if base_idl_type in NON_WRAPPER_TYPES: | 180 if base_idl_type in NON_WRAPPER_TYPES: |
| 181 return ('PassRefPtr<%s>' if used_as_rvalue_type else 'RefPtr<%s>') % bas e_idl_type | 181 return ('PassRefPtr<%s>' if used_as_rvalue_type else 'RefPtr<%s>') % bas e_idl_type |
| 182 if idl_type.is_string_type: | 182 if idl_type.is_string_type: |
| 183 if not raw_type: | 183 if not raw_type: |
| 184 return 'String' | 184 return 'String' |
| 185 return 'V8StringResource<%s>' % string_mode() | 185 return 'V8StringResource<%s>' % string_mode() |
| 186 | 186 |
| 187 if idl_type.is_array_buffer_or_view and raw_type: | 187 if idl_type.base_type == 'ArrayBufferView' and 'FlexibleArrayBufferView' in extended_attributes: |
| 188 return idl_type.implemented_as + '*' | 188 return 'FlexibleArrayBufferView' |
| 189 if idl_type.base_type in TYPED_ARRAY_TYPES and 'FlexibleArrayBufferView' in extended_attributes: | |
| 190 return 'Flexible' + idl_type.base_type + 'View' | |
| 189 if idl_type.is_interface_type: | 191 if idl_type.is_interface_type: |
| 190 implemented_as_class = idl_type.implemented_as | 192 implemented_as_class = idl_type.implemented_as |
| 191 if raw_type or (used_as_rvalue_type and idl_type.is_garbage_collected): | 193 if raw_type or (used_as_rvalue_type and idl_type.is_garbage_collected): |
| 192 return implemented_as_class + '*' | 194 return implemented_as_class + '*' |
| 193 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' | 195 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' |
| 194 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_rvalue_type else 'RefPt r'), new_type, idl_type.gc_type) | 196 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_rvalue_type else 'RefPt r'), new_type, idl_type.gc_type) |
| 195 return cpp_template_type(ptr_type, implemented_as_class) | 197 return cpp_template_type(ptr_type, implemented_as_class) |
| 196 if idl_type.is_dictionary: | 198 if idl_type.is_dictionary: |
| 197 return base_idl_type | 199 return base_idl_type |
| 198 if idl_type.is_union_type: | 200 if idl_type.is_union_type: |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 | 371 |
| 370 | 372 |
| 371 def includes_for_type(idl_type, extended_attributes=None): | 373 def includes_for_type(idl_type, extended_attributes=None): |
| 372 idl_type = idl_type.preprocessed_type | 374 idl_type = idl_type.preprocessed_type |
| 373 extended_attributes = extended_attributes or {} | 375 extended_attributes = extended_attributes or {} |
| 374 | 376 |
| 375 # Simple types | 377 # Simple types |
| 376 base_idl_type = idl_type.base_type | 378 base_idl_type = idl_type.base_type |
| 377 if base_idl_type in INCLUDES_FOR_TYPE: | 379 if base_idl_type in INCLUDES_FOR_TYPE: |
| 378 return INCLUDES_FOR_TYPE[base_idl_type] | 380 return INCLUDES_FOR_TYPE[base_idl_type] |
| 381 if base_idl_type == 'ArrayBufferView' and 'FlexibleArrayBufferView' in exten ded_attributes: | |
|
haraken
2015/07/30 14:54:57
Can we add this to INCLUDES_FOR_TYPE instead of ha
Michael Lippautz
2015/07/30 17:06:15
Done.
| |
| 382 return set(['bindings/core/v8/V8ArrayBufferView.h', | |
| 383 'core/dom/FlexibleArrayBufferView.h']) | |
| 384 if idl_type.base_type in TYPED_ARRAY_TYPES and 'FlexibleArrayBufferView' in extended_attributes: | |
|
haraken
2015/07/30 14:54:57
Ditto.
Michael Lippautz
2015/07/30 17:06:15
For TYPED_ARRAY_TYPES we additionally need the
b
| |
| 385 return set(['bindings/core/v8/V8ArrayBufferView.h', | |
| 386 'core/dom/TypedFlexibleArrayBufferView.h', | |
| 387 'bindings/%s/v8/V8%s.h' % (component_dir[base_idl_type], | |
| 388 base_idl_type)]) | |
| 379 if idl_type.is_basic_type: | 389 if idl_type.is_basic_type: |
| 380 return set() | 390 return set() |
| 381 if base_idl_type.endswith('ConstructorConstructor'): | 391 if base_idl_type.endswith('ConstructorConstructor'): |
| 382 # FIXME: rename to NamedConstructor | 392 # FIXME: rename to NamedConstructor |
| 383 # FIXME: replace with a [NamedConstructorAttribute] extended attribute | 393 # FIXME: replace with a [NamedConstructorAttribute] extended attribute |
| 384 # Ending with 'ConstructorConstructor' indicates a named constructor, | 394 # Ending with 'ConstructorConstructor' indicates a named constructor, |
| 385 # and these do not have header files, as they are part of the generated | 395 # and these do not have header files, as they are part of the generated |
| 386 # bindings for the interface | 396 # bindings for the interface |
| 387 return set() | 397 return set() |
| 388 if base_idl_type.endswith('Constructor'): | 398 if base_idl_type.endswith('Constructor'): |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 'octet': 'toUInt8({isolate}, {arguments})', | 502 'octet': 'toUInt8({isolate}, {arguments})', |
| 493 'short': 'toInt16({isolate}, {arguments})', | 503 'short': 'toInt16({isolate}, {arguments})', |
| 494 'unsigned short': 'toUInt16({isolate}, {arguments})', | 504 'unsigned short': 'toUInt16({isolate}, {arguments})', |
| 495 'long': 'toInt32({isolate}, {arguments})', | 505 'long': 'toInt32({isolate}, {arguments})', |
| 496 'unsigned long': 'toUInt32({isolate}, {arguments})', | 506 'unsigned long': 'toUInt32({isolate}, {arguments})', |
| 497 'long long': 'toInt64({isolate}, {arguments})', | 507 'long long': 'toInt64({isolate}, {arguments})', |
| 498 'unsigned long long': 'toUInt64({isolate}, {arguments})', | 508 'unsigned long long': 'toUInt64({isolate}, {arguments})', |
| 499 # Interface types | 509 # Interface types |
| 500 'Dictionary': 'Dictionary({v8_value}, {isolate}, exceptionState)', | 510 'Dictionary': 'Dictionary({v8_value}, {isolate}, exceptionState)', |
| 501 'EventTarget': 'toEventTarget({isolate}, {v8_value})', | 511 'EventTarget': 'toEventTarget({isolate}, {v8_value})', |
| 512 'FlexibleArrayBufferView': 'toFlexibleArrayBufferView({isolate}, {v8_value}, {variable_name}, SMALL_ARRAY_BUFFER_VIEW_STORAGE({v8_value}))', | |
| 502 'NodeFilter': 'toNodeFilter({v8_value}, info.Holder(), ScriptState::current( {isolate}))', | 513 'NodeFilter': 'toNodeFilter({v8_value}, info.Holder(), ScriptState::current( {isolate}))', |
| 503 'Promise': 'ScriptPromise::cast(ScriptState::current({isolate}), {v8_value}) ', | 514 'Promise': 'ScriptPromise::cast(ScriptState::current({isolate}), {v8_value}) ', |
| 504 'SerializedScriptValue': 'SerializedScriptValueFactory::instance().create({i solate}, {v8_value}, 0, 0, exceptionState)', | 515 'SerializedScriptValue': 'SerializedScriptValueFactory::instance().create({i solate}, {v8_value}, 0, 0, exceptionState)', |
| 505 'ScriptValue': 'ScriptValue(ScriptState::current({isolate}), {v8_value})', | 516 'ScriptValue': 'ScriptValue(ScriptState::current({isolate}), {v8_value})', |
| 506 'Window': 'toDOMWindow({isolate}, {v8_value})', | 517 'Window': 'toDOMWindow({isolate}, {v8_value})', |
| 507 'XPathNSResolver': 'toXPathNSResolver(ScriptState::current({isolate}), {v8_v alue})', | 518 'XPathNSResolver': 'toXPathNSResolver(ScriptState::current({isolate}), {v8_v alue})', |
| 508 } | 519 } |
| 509 | 520 |
| 510 | 521 |
| 511 def v8_conversion_needs_exception_state(idl_type): | 522 def v8_conversion_needs_exception_state(idl_type): |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 | 556 |
| 546 # Array or sequence types | 557 # Array or sequence types |
| 547 native_array_element_type = idl_type.native_array_element_type | 558 native_array_element_type = idl_type.native_array_element_type |
| 548 if native_array_element_type: | 559 if native_array_element_type: |
| 549 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate) | 560 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate) |
| 550 | 561 |
| 551 # Simple types | 562 # Simple types |
| 552 idl_type = idl_type.preprocessed_type | 563 idl_type = idl_type.preprocessed_type |
| 553 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i dl_type.base_type | 564 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i dl_type.base_type |
| 554 | 565 |
| 566 if base_idl_type == 'ArrayBufferView' and 'FlexibleArrayBufferView' in exten ded_attributes: | |
| 567 base_idl_type = 'FlexibleArrayBufferView' | |
| 568 if idl_type.base_type in TYPED_ARRAY_TYPES and 'FlexibleArrayBufferView' in extended_attributes: | |
| 569 base_idl_type = 'FlexibleArrayBufferView' | |
|
haraken
2015/07/30 14:54:57
Shouldn't this be:
'Flexible' + idl_type.base_t
Michael Lippautz
2015/07/30 17:06:15
Nope, both, FlexibleArrayBufferView and TypedFlexi
| |
| 570 | |
| 555 if idl_type.is_integer_type: | 571 if idl_type.is_integer_type: |
| 556 configuration = 'NormalConversion' | 572 configuration = 'NormalConversion' |
| 557 if 'EnforceRange' in extended_attributes: | 573 if 'EnforceRange' in extended_attributes: |
| 558 configuration = 'EnforceRange' | 574 configuration = 'EnforceRange' |
| 559 elif 'Clamp' in extended_attributes: | 575 elif 'Clamp' in extended_attributes: |
| 560 configuration = 'Clamp' | 576 configuration = 'Clamp' |
| 561 arguments = ', '.join([v8_value, configuration, 'exceptionState']) | 577 arguments = ', '.join([v8_value, configuration, 'exceptionState']) |
| 562 elif idl_type.v8_conversion_needs_exception_state: | 578 elif idl_type.v8_conversion_needs_exception_state: |
| 563 arguments = ', '.join([v8_value, 'exceptionState']) | 579 arguments = ', '.join([v8_value, 'exceptionState']) |
| 564 else: | 580 else: |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 # as the condition here would be wrong. | 657 # as the condition here would be wrong. |
| 642 if not idl_type.v8_conversion_needs_exception_state: | 658 if not idl_type.v8_conversion_needs_exception_state: |
| 643 if use_exception_state: | 659 if use_exception_state: |
| 644 check_expression = '!%s.prepare(exceptionState)' % variable_ name | 660 check_expression = '!%s.prepare(exceptionState)' % variable_ name |
| 645 else: | 661 else: |
| 646 check_expression = '!%s.prepare()' % variable_name | 662 check_expression = '!%s.prepare()' % variable_name |
| 647 elif not idl_type.v8_conversion_is_trivial: | 663 elif not idl_type.v8_conversion_is_trivial: |
| 648 return { | 664 return { |
| 649 'error_message': 'no V8 -> C++ conversion for IDL type: %s' % idl_ty pe.name | 665 'error_message': 'no V8 -> C++ conversion for IDL type: %s' % idl_ty pe.name |
| 650 } | 666 } |
| 667 elif idl_type.base_type == 'ArrayBufferView' and 'FlexibleArrayBufferView' i n extended_attributes: | |
| 668 set_expression = cpp_value | |
| 669 elif idl_type.base_type in TYPED_ARRAY_TYPES and 'FlexibleArrayBufferView' i n extended_attributes: | |
|
haraken
2015/07/30 14:54:57
Slightly better:
elif 'FlexibleArrayBufferView' i
Michael Lippautz
2015/07/30 17:06:15
Done. Rewrote using regular if though as your sugg
| |
| 670 set_expression = cpp_value | |
| 651 else: | 671 else: |
| 652 assign_expression = cpp_value | 672 assign_expression = cpp_value |
| 653 | 673 |
| 654 # Types that don't need error handling, and simply assign a value to the | 674 # Types that don't need error handling, and simply assign a value to the |
| 655 # local variable. | 675 # local variable. |
| 656 | 676 |
| 657 return { | 677 return { |
| 658 'assign_expression': assign_expression, | 678 'assign_expression': assign_expression, |
| 659 'check_expression': check_expression, | 679 'check_expression': check_expression, |
| 660 'cpp_type': this_cpp_type, | 680 'cpp_type': this_cpp_type, |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 number_of_nullable_member_types_union) | 1018 number_of_nullable_member_types_union) |
| 999 | 1019 |
| 1000 | 1020 |
| 1001 def includes_nullable_type_union(idl_type): | 1021 def includes_nullable_type_union(idl_type): |
| 1002 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type | 1022 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type |
| 1003 return idl_type.number_of_nullable_member_types == 1 | 1023 return idl_type.number_of_nullable_member_types == 1 |
| 1004 | 1024 |
| 1005 IdlTypeBase.includes_nullable_type = False | 1025 IdlTypeBase.includes_nullable_type = False |
| 1006 IdlNullableType.includes_nullable_type = True | 1026 IdlNullableType.includes_nullable_type = True |
| 1007 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) | 1027 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) |
| OLD | NEW |