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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 'Float32Array', | 67 'Float32Array', |
68 'Float64Array', | 68 'Float64Array', |
69 'Int8Array', | 69 'Int8Array', |
70 'Int16Array', | 70 'Int16Array', |
71 'Int32Array', | 71 'Int32Array', |
72 'Uint8Array', | 72 'Uint8Array', |
73 'Uint8ClampedArray', | 73 'Uint8ClampedArray', |
74 'Uint16Array', | 74 'Uint16Array', |
75 'Uint32Array', | 75 'Uint32Array', |
76 ]) | 76 ]) |
| 77 ARRAY_BUFFER_VIEW_AND_TYPED_ARRAY_TYPES = TYPED_ARRAY_TYPES.union(frozenset([ |
| 78 'ArrayBufferView' |
| 79 ])) |
77 ARRAY_BUFFER_AND_VIEW_TYPES = TYPED_ARRAY_TYPES.union(frozenset([ | 80 ARRAY_BUFFER_AND_VIEW_TYPES = TYPED_ARRAY_TYPES.union(frozenset([ |
78 'ArrayBuffer', | 81 'ArrayBuffer', |
79 'ArrayBufferView', | 82 'ArrayBufferView', |
80 'DataView', | 83 'DataView', |
81 'SharedArrayBuffer', | 84 'SharedArrayBuffer', |
82 ])) | 85 ])) |
83 | 86 |
84 | 87 |
85 IdlType.is_array_buffer_or_view = property( | 88 IdlType.is_array_buffer_or_view = property( |
86 lambda self: self.base_type in ARRAY_BUFFER_AND_VIEW_TYPES) | 89 lambda self: self.base_type in ARRAY_BUFFER_AND_VIEW_TYPES) |
87 | 90 |
| 91 IdlType.is_array_buffer_view_or_typed_array = property( |
| 92 lambda self: self.base_type in ARRAY_BUFFER_VIEW_AND_TYPED_ARRAY_TYPES) |
| 93 |
88 IdlType.is_typed_array = property( | 94 IdlType.is_typed_array = property( |
89 lambda self: self.base_type in TYPED_ARRAY_TYPES) | 95 lambda self: self.base_type in TYPED_ARRAY_TYPES) |
90 | 96 |
91 IdlType.is_wrapper_type = property( | 97 IdlType.is_wrapper_type = property( |
92 lambda self: (self.is_interface_type and | 98 lambda self: (self.is_interface_type and |
93 not self.is_callback_interface and | 99 not self.is_callback_interface and |
94 self.base_type not in NON_WRAPPER_TYPES)) | 100 self.base_type not in NON_WRAPPER_TYPES)) |
95 | 101 |
96 | 102 |
97 ################################################################################ | 103 ################################################################################ |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 return ('PassRefPtr<%s>' if used_as_rvalue_type else 'RefPtr<%s>') % bas
e_idl_type | 201 return ('PassRefPtr<%s>' if used_as_rvalue_type else 'RefPtr<%s>') % bas
e_idl_type |
196 if idl_type.is_string_type: | 202 if idl_type.is_string_type: |
197 if not raw_type: | 203 if not raw_type: |
198 return 'String' | 204 return 'String' |
199 return 'V8StringResource<%s>' % string_mode() | 205 return 'V8StringResource<%s>' % string_mode() |
200 | 206 |
201 if base_idl_type == 'ArrayBufferView' and 'FlexibleArrayBufferView' in exten
ded_attributes: | 207 if base_idl_type == 'ArrayBufferView' and 'FlexibleArrayBufferView' in exten
ded_attributes: |
202 return 'FlexibleArrayBufferView' | 208 return 'FlexibleArrayBufferView' |
203 if base_idl_type in TYPED_ARRAY_TYPES and 'FlexibleArrayBufferView' in exten
ded_attributes: | 209 if base_idl_type in TYPED_ARRAY_TYPES and 'FlexibleArrayBufferView' in exten
ded_attributes: |
204 return 'Flexible' + base_idl_type + 'View' | 210 return 'Flexible' + base_idl_type + 'View' |
| 211 if base_idl_type in ARRAY_BUFFER_VIEW_AND_TYPED_ARRAY_TYPES: |
| 212 if not used_in_cpp_sequence: |
| 213 return cpp_template_type('NotShared', idl_type.implemented_as) |
205 if idl_type.is_interface_type: | 214 if idl_type.is_interface_type: |
206 implemented_as_class = idl_type.implemented_as | 215 implemented_as_class = idl_type.implemented_as |
207 if raw_type or (used_as_rvalue_type and idl_type.is_garbage_collected) o
r not used_in_cpp_sequence: | 216 if raw_type or (used_as_rvalue_type and idl_type.is_garbage_collected) o
r not used_in_cpp_sequence: |
208 return implemented_as_class + '*' | 217 return implemented_as_class + '*' |
209 if not used_in_cpp_sequence: | 218 if not used_in_cpp_sequence: |
210 return implemented_as_class + '*' | 219 return implemented_as_class + '*' |
211 return cpp_template_type('Member', implemented_as_class) | 220 return cpp_template_type('Member', implemented_as_class) |
212 if idl_type.is_dictionary: | 221 if idl_type.is_dictionary: |
213 if used_as_rvalue_type: | 222 if used_as_rvalue_type: |
214 return 'const %s&' % base_idl_type | 223 return 'const %s&' % base_idl_type |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 lambda self: self.value_type.is_traceable) | 345 lambda self: self.value_type.is_traceable) |
337 | 346 |
338 | 347 |
339 ################################################################################ | 348 ################################################################################ |
340 # Includes | 349 # Includes |
341 ################################################################################ | 350 ################################################################################ |
342 | 351 |
343 INCLUDES_FOR_TYPE = { | 352 INCLUDES_FOR_TYPE = { |
344 'object': set(), | 353 'object': set(), |
345 'ArrayBufferView': set(['bindings/core/v8/V8ArrayBufferView.h', | 354 'ArrayBufferView': set(['bindings/core/v8/V8ArrayBufferView.h', |
| 355 'core/dom/NotShared.h', |
346 'core/dom/FlexibleArrayBufferView.h']), | 356 'core/dom/FlexibleArrayBufferView.h']), |
347 'Dictionary': set(['bindings/core/v8/Dictionary.h']), | 357 'Dictionary': set(['bindings/core/v8/Dictionary.h']), |
348 'EventHandler': set(['bindings/core/v8/V8AbstractEventListener.h', | 358 'EventHandler': set(['bindings/core/v8/V8AbstractEventListener.h', |
349 'bindings/core/v8/V8EventListenerHelper.h']), | 359 'bindings/core/v8/V8EventListenerHelper.h']), |
350 'EventListener': set(['bindings/core/v8/BindingSecurity.h', | 360 'EventListener': set(['bindings/core/v8/BindingSecurity.h', |
351 'bindings/core/v8/V8EventListenerHelper.h', | 361 'bindings/core/v8/V8EventListenerHelper.h', |
352 'core/frame/LocalDOMWindow.h']), | 362 'core/frame/LocalDOMWindow.h']), |
353 'HTMLCollection': set(['bindings/core/v8/V8HTMLCollection.h', | 363 'HTMLCollection': set(['bindings/core/v8/V8HTMLCollection.h', |
354 'core/dom/ClassCollection.h', | 364 'core/dom/ClassCollection.h', |
355 'core/dom/TagCollection.h', | 365 'core/dom/TagCollection.h', |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 includes_for_type.add('platform/wtf/Vector.h') | 462 includes_for_type.add('platform/wtf/Vector.h') |
453 | 463 |
454 base_idl_type = idl_type.base_type | 464 base_idl_type = idl_type.base_type |
455 if idl_type.is_string_type: | 465 if idl_type.is_string_type: |
456 includes_for_type.add('platform/wtf/text/WTFString.h') | 466 includes_for_type.add('platform/wtf/text/WTFString.h') |
457 if base_idl_type in interfaces_info: | 467 if base_idl_type in interfaces_info: |
458 interface_info = interfaces_info[base_idl_type] | 468 interface_info = interfaces_info[base_idl_type] |
459 includes_for_type.add(interface_info['include_path']) | 469 includes_for_type.add(interface_info['include_path']) |
460 if base_idl_type in INCLUDES_FOR_TYPE: | 470 if base_idl_type in INCLUDES_FOR_TYPE: |
461 includes_for_type.update(INCLUDES_FOR_TYPE[base_idl_type]) | 471 includes_for_type.update(INCLUDES_FOR_TYPE[base_idl_type]) |
462 if idl_type.is_typed_array: | 472 if idl_type.is_array_buffer_view_or_typed_array: |
463 return set(['core/dom/DOMTypedArray.h']) | 473 return set(['core/dom/DOMTypedArray.h', 'core/dom/NotShared.h']) |
464 return includes_for_type | 474 return includes_for_type |
465 | 475 |
466 | 476 |
467 def impl_includes_for_type_union(idl_type, interfaces_info): | 477 def impl_includes_for_type_union(idl_type, interfaces_info): |
468 includes_for_type = set() | 478 includes_for_type = set() |
469 for member_type in idl_type.member_types: | 479 for member_type in idl_type.member_types: |
470 includes_for_type.update(member_type.impl_includes_for_type(interfaces_i
nfo)) | 480 includes_for_type.update(member_type.impl_includes_for_type(interfaces_i
nfo)) |
471 return includes_for_type | 481 return includes_for_type |
472 | 482 |
473 IdlTypeBase.impl_includes_for_type = impl_includes_for_type | 483 IdlTypeBase.impl_includes_for_type = impl_includes_for_type |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 'ScriptValue': 'ScriptValue(ScriptState::Current({isolate}), {v8_value})', | 522 'ScriptValue': 'ScriptValue(ScriptState::Current({isolate}), {v8_value})', |
513 'Window': 'ToDOMWindow({isolate}, {v8_value})', | 523 'Window': 'ToDOMWindow({isolate}, {v8_value})', |
514 'XPathNSResolver': 'ToXPathNSResolver(ScriptState::Current({isolate}), {v8_v
alue})', | 524 'XPathNSResolver': 'ToXPathNSResolver(ScriptState::Current({isolate}), {v8_v
alue})', |
515 } | 525 } |
516 | 526 |
517 | 527 |
518 def v8_conversion_needs_exception_state(idl_type): | 528 def v8_conversion_needs_exception_state(idl_type): |
519 return (idl_type.is_numeric_type or | 529 return (idl_type.is_numeric_type or |
520 idl_type.is_enum or | 530 idl_type.is_enum or |
521 idl_type.is_dictionary or | 531 idl_type.is_dictionary or |
| 532 idl_type.is_array_buffer_view_or_typed_array or |
522 idl_type.name in ('Boolean', 'ByteString', 'Date', 'Dictionary', 'US
VString', 'SerializedScriptValue')) | 533 idl_type.name in ('Boolean', 'ByteString', 'Date', 'Dictionary', 'US
VString', 'SerializedScriptValue')) |
523 | 534 |
524 IdlType.v8_conversion_needs_exception_state = property(v8_conversion_needs_excep
tion_state) | 535 IdlType.v8_conversion_needs_exception_state = property(v8_conversion_needs_excep
tion_state) |
525 IdlArrayOrSequenceType.v8_conversion_needs_exception_state = True | 536 IdlArrayOrSequenceType.v8_conversion_needs_exception_state = True |
526 IdlRecordType.v8_conversion_needs_exception_state = True | 537 IdlRecordType.v8_conversion_needs_exception_state = True |
527 IdlUnionType.v8_conversion_needs_exception_state = True | 538 IdlUnionType.v8_conversion_needs_exception_state = True |
528 | 539 |
529 | 540 |
530 TRIVIAL_CONVERSIONS = frozenset([ | 541 TRIVIAL_CONVERSIONS = frozenset([ |
531 'any', | 542 'any', |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 # Array or sequence types | 585 # Array or sequence types |
575 native_array_element_type = idl_type.native_array_element_type | 586 native_array_element_type = idl_type.native_array_element_type |
576 if native_array_element_type: | 587 if native_array_element_type: |
577 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type
, v8_value, index, isolate) | 588 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type
, v8_value, index, isolate) |
578 | 589 |
579 # Simple types | 590 # Simple types |
580 idl_type = idl_type.preprocessed_type | 591 idl_type = idl_type.preprocessed_type |
581 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i
dl_type.base_type | 592 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i
dl_type.base_type |
582 | 593 |
583 if 'FlexibleArrayBufferView' in extended_attributes: | 594 if 'FlexibleArrayBufferView' in extended_attributes: |
584 if base_idl_type not in TYPED_ARRAY_TYPES.union(set(['ArrayBufferView'])
): | 595 if base_idl_type not in ARRAY_BUFFER_VIEW_AND_TYPED_ARRAY_TYPES: |
585 raise ValueError("Unrecognized base type for extended attribute 'Fle
xibleArrayBufferView': %s" % (idl_type.base_type)) | 596 raise ValueError("Unrecognized base type for extended attribute 'Fle
xibleArrayBufferView': %s" % (idl_type.base_type)) |
586 base_idl_type = 'FlexibleArrayBufferView' | 597 base_idl_type = 'FlexibleArrayBufferView' |
587 | 598 |
588 if idl_type.is_integer_type: | 599 if idl_type.is_integer_type: |
589 configuration = 'kNormalConversion' | 600 configuration = 'kNormalConversion' |
590 if 'EnforceRange' in extended_attributes: | 601 if 'EnforceRange' in extended_attributes: |
591 configuration = 'kEnforceRange' | 602 configuration = 'kEnforceRange' |
592 elif 'Clamp' in extended_attributes: | 603 elif 'Clamp' in extended_attributes: |
593 configuration = 'kClamp' | 604 configuration = 'kClamp' |
594 arguments = ', '.join([v8_value, 'exceptionState', configuration]) | 605 arguments = ', '.join([v8_value, 'exceptionState', configuration]) |
595 elif idl_type.v8_conversion_needs_exception_state: | 606 elif idl_type.v8_conversion_needs_exception_state: |
596 arguments = ', '.join([v8_value, 'exceptionState']) | 607 arguments = ', '.join([v8_value, 'exceptionState']) |
597 else: | 608 else: |
598 arguments = v8_value | 609 arguments = v8_value |
599 | 610 |
600 if base_idl_type in V8_VALUE_TO_CPP_VALUE: | 611 if base_idl_type in V8_VALUE_TO_CPP_VALUE: |
601 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] | 612 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] |
602 elif idl_type.is_array_buffer_or_view: | 613 elif idl_type.name == 'ArrayBuffer': |
603 cpp_expression_format = ( | 614 cpp_expression_format = ( |
604 '{v8_value}->Is{idl_type}() ? ' | 615 '{v8_value}->Is{idl_type}() ? ' |
605 'V8{idl_type}::toImpl(v8::Local<v8::{idl_type}>::Cast({v8_value})) :
0') | 616 'V8{idl_type}::toImpl(v8::Local<v8::{idl_type}>::Cast({v8_value})) :
0') |
| 617 elif idl_type.is_array_buffer_view_or_typed_array: |
| 618 this_cpp_type = idl_type.cpp_type |
| 619 cpp_expression_format = ('ToNotShared<%s>({isolate}, {v8_value}, excepti
onState)' % this_cpp_type) |
606 elif idl_type.is_union_type: | 620 elif idl_type.is_union_type: |
607 nullable = 'UnionTypeConversionMode::kNullable' if idl_type.includes_nul
lable_type \ | 621 nullable = 'UnionTypeConversionMode::kNullable' if idl_type.includes_nul
lable_type \ |
608 else 'UnionTypeConversionMode::kNotNullable' | 622 else 'UnionTypeConversionMode::kNotNullable' |
609 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va
riable_name}, %s, exceptionState)' % nullable | 623 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va
riable_name}, %s, exceptionState)' % nullable |
610 elif idl_type.use_output_parameter_for_result: | 624 elif idl_type.use_output_parameter_for_result: |
611 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va
riable_name}, exceptionState)' | 625 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va
riable_name}, exceptionState)' |
612 elif idl_type.is_callback_function: | 626 elif idl_type.is_callback_function: |
613 cpp_expression_format = ( | 627 cpp_expression_format = ( |
614 '{idl_type}::Create(ScriptState::Current({isolate}), {v8_value})') | 628 '{idl_type}::Create(ScriptState::Current({isolate}), {v8_value})') |
615 elif idl_type.v8_conversion_needs_exception_state: | 629 elif idl_type.v8_conversion_needs_exception_state: |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 # Optional expression that returns a value to be assigned to the local varia
ble. | 684 # Optional expression that returns a value to be assigned to the local varia
ble. |
671 assign_expression = None | 685 assign_expression = None |
672 # Optional void expression executed unconditionally. | 686 # Optional void expression executed unconditionally. |
673 set_expression = None | 687 set_expression = None |
674 # Optional expression that returns true if the conversion fails. | 688 # Optional expression that returns true if the conversion fails. |
675 check_expression = None | 689 check_expression = None |
676 # Optional expression used as the return value when returning. Only | 690 # Optional expression used as the return value when returning. Only |
677 # meaningful if 'check_expression' is not None. | 691 # meaningful if 'check_expression' is not None. |
678 return_expression = bailout_return_value | 692 return_expression = bailout_return_value |
679 | 693 |
680 if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state: | 694 if 'FlexibleArrayBufferView' in extended_attributes: |
| 695 if idl_type.base_type not in ARRAY_BUFFER_VIEW_AND_TYPED_ARRAY_TYPES: |
| 696 raise ValueError("Unrecognized base type for extended attribute 'Fle
xibleArrayBufferView': %s" % (idl_type.base_type)) |
| 697 set_expression = cpp_value |
| 698 elif idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state
: |
681 # Types for which conversion can fail and that need error handling. | 699 # Types for which conversion can fail and that need error handling. |
682 | 700 |
683 check_expression = 'exceptionState.HadException()' | 701 check_expression = 'exceptionState.HadException()' |
684 | 702 |
685 if idl_type.is_dictionary or idl_type.is_union_type: | 703 if idl_type.is_dictionary or idl_type.is_union_type: |
686 set_expression = cpp_value | 704 set_expression = cpp_value |
687 else: | 705 else: |
688 assign_expression = cpp_value | 706 assign_expression = cpp_value |
689 # Note: 'not idl_type.v8_conversion_needs_exception_state' implies | 707 # Note: 'not idl_type.v8_conversion_needs_exception_state' implies |
690 # 'idl_type.is_string_type', but there are types for which both are | 708 # 'idl_type.is_string_type', but there are types for which both are |
691 # true (ByteString and USVString), so using idl_type.is_string_type | 709 # true (ByteString and USVString), so using idl_type.is_string_type |
692 # as the condition here would be wrong. | 710 # as the condition here would be wrong. |
693 if not idl_type.v8_conversion_needs_exception_state: | 711 if not idl_type.v8_conversion_needs_exception_state: |
694 if use_exception_state: | 712 if use_exception_state: |
695 check_expression = '!%s.Prepare(exceptionState)' % variable_
name | 713 check_expression = '!%s.Prepare(exceptionState)' % variable_
name |
696 else: | 714 else: |
697 check_expression = '!%s.Prepare()' % variable_name | 715 check_expression = '!%s.Prepare()' % variable_name |
698 elif not idl_type.v8_conversion_is_trivial and not idl_type.is_callback_func
tion: | 716 elif not idl_type.v8_conversion_is_trivial and not idl_type.is_callback_func
tion: |
699 return { | 717 return { |
700 'error_message': 'no V8 -> C++ conversion for IDL type: %s' % idl_ty
pe.name | 718 'error_message': 'no V8 -> C++ conversion for IDL type: %s' % idl_ty
pe.name |
701 } | 719 } |
702 elif 'FlexibleArrayBufferView' in extended_attributes: | |
703 if idl_type.base_type not in TYPED_ARRAY_TYPES.union(set(['ArrayBufferVi
ew'])): | |
704 raise ValueError("Unrecognized base type for extended attribute 'Fle
xibleArrayBufferView': %s" % (idl_type.base_type)) | |
705 set_expression = cpp_value | |
706 else: | 720 else: |
707 assign_expression = cpp_value | 721 assign_expression = cpp_value |
708 | 722 |
709 # Types that don't need error handling, and simply assign a value to the | 723 # Types that don't need error handling, and simply assign a value to the |
710 # local variable. | 724 # local variable. |
711 | 725 |
712 return { | 726 return { |
713 'assign_expression': assign_expression, | 727 'assign_expression': assign_expression, |
714 'check_expression': check_expression, | 728 'check_expression': check_expression, |
715 'cpp_type': this_cpp_type, | 729 'cpp_type': this_cpp_type, |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) | 1085 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) |
1072 | 1086 |
1073 | 1087 |
1074 def includes_nullable_type_union(idl_type): | 1088 def includes_nullable_type_union(idl_type): |
1075 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type | 1089 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type |
1076 return idl_type.number_of_nullable_member_types == 1 | 1090 return idl_type.number_of_nullable_member_types == 1 |
1077 | 1091 |
1078 IdlTypeBase.includes_nullable_type = False | 1092 IdlTypeBase.includes_nullable_type = False |
1079 IdlNullableType.includes_nullable_type = True | 1093 IdlNullableType.includes_nullable_type = True |
1080 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) | 1094 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) |
OLD | NEW |