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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 ################################################################################ | 338 ################################################################################ |
337 # Includes | 339 # Includes |
338 ################################################################################ | 340 ################################################################################ |
339 | 341 |
340 def includes_for_cpp_class(class_name, relative_dir_posix): | 342 def includes_for_cpp_class(class_name, relative_dir_posix): |
341 return set([posixpath.join('bindings', relative_dir_posix, class_name + '.h'
)]) | 343 return set([posixpath.join('bindings', relative_dir_posix, class_name + '.h'
)]) |
342 | 344 |
343 | 345 |
344 INCLUDES_FOR_TYPE = { | 346 INCLUDES_FOR_TYPE = { |
345 'object': set(), | 347 'object': set(), |
| 348 'ArrayBufferView': set(['bindings/core/v8/V8ArrayBufferView.h', |
| 349 'core/dom/FlexibleArrayBufferView.h']), |
346 'Dictionary': set(['bindings/core/v8/Dictionary.h']), | 350 'Dictionary': set(['bindings/core/v8/Dictionary.h']), |
347 'EventHandler': set(['bindings/core/v8/V8AbstractEventListener.h', | 351 'EventHandler': set(['bindings/core/v8/V8AbstractEventListener.h', |
348 'bindings/core/v8/V8EventListenerList.h']), | 352 'bindings/core/v8/V8EventListenerList.h']), |
349 'EventListener': set(['bindings/core/v8/BindingSecurity.h', | 353 'EventListener': set(['bindings/core/v8/BindingSecurity.h', |
350 'bindings/core/v8/V8EventListenerList.h', | 354 'bindings/core/v8/V8EventListenerList.h', |
351 'core/frame/LocalDOMWindow.h']), | 355 'core/frame/LocalDOMWindow.h']), |
352 'HTMLCollection': set(['bindings/core/v8/V8HTMLCollection.h', | 356 'HTMLCollection': set(['bindings/core/v8/V8HTMLCollection.h', |
353 'core/dom/ClassCollection.h', | 357 'core/dom/ClassCollection.h', |
354 'core/dom/TagCollection.h', | 358 'core/dom/TagCollection.h', |
355 'core/html/HTMLCollection.h', | 359 'core/html/HTMLCollection.h', |
(...skipping 13 matching lines...) Expand all Loading... |
369 | 373 |
370 | 374 |
371 def includes_for_type(idl_type, extended_attributes=None): | 375 def includes_for_type(idl_type, extended_attributes=None): |
372 idl_type = idl_type.preprocessed_type | 376 idl_type = idl_type.preprocessed_type |
373 extended_attributes = extended_attributes or {} | 377 extended_attributes = extended_attributes or {} |
374 | 378 |
375 # Simple types | 379 # Simple types |
376 base_idl_type = idl_type.base_type | 380 base_idl_type = idl_type.base_type |
377 if base_idl_type in INCLUDES_FOR_TYPE: | 381 if base_idl_type in INCLUDES_FOR_TYPE: |
378 return INCLUDES_FOR_TYPE[base_idl_type] | 382 return INCLUDES_FOR_TYPE[base_idl_type] |
| 383 if idl_type.base_type in TYPED_ARRAY_TYPES: |
| 384 return INCLUDES_FOR_TYPE['ArrayBufferView'].union( |
| 385 set(['bindings/%s/v8/V8%s.h' % (component_dir[base_idl_type], base_i
dl_type)]) |
| 386 ) |
379 if idl_type.is_basic_type: | 387 if idl_type.is_basic_type: |
380 return set() | 388 return set() |
381 if base_idl_type.endswith('ConstructorConstructor'): | 389 if base_idl_type.endswith('ConstructorConstructor'): |
382 # FIXME: rename to NamedConstructor | 390 # FIXME: rename to NamedConstructor |
383 # FIXME: replace with a [NamedConstructorAttribute] extended attribute | 391 # FIXME: replace with a [NamedConstructorAttribute] extended attribute |
384 # Ending with 'ConstructorConstructor' indicates a named constructor, | 392 # Ending with 'ConstructorConstructor' indicates a named constructor, |
385 # and these do not have header files, as they are part of the generated | 393 # and these do not have header files, as they are part of the generated |
386 # bindings for the interface | 394 # bindings for the interface |
387 return set() | 395 return set() |
388 if base_idl_type.endswith('Constructor'): | 396 if base_idl_type.endswith('Constructor'): |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 'octet': 'toUInt8({isolate}, {arguments})', | 500 'octet': 'toUInt8({isolate}, {arguments})', |
493 'short': 'toInt16({isolate}, {arguments})', | 501 'short': 'toInt16({isolate}, {arguments})', |
494 'unsigned short': 'toUInt16({isolate}, {arguments})', | 502 'unsigned short': 'toUInt16({isolate}, {arguments})', |
495 'long': 'toInt32({isolate}, {arguments})', | 503 'long': 'toInt32({isolate}, {arguments})', |
496 'unsigned long': 'toUInt32({isolate}, {arguments})', | 504 'unsigned long': 'toUInt32({isolate}, {arguments})', |
497 'long long': 'toInt64({isolate}, {arguments})', | 505 'long long': 'toInt64({isolate}, {arguments})', |
498 'unsigned long long': 'toUInt64({isolate}, {arguments})', | 506 'unsigned long long': 'toUInt64({isolate}, {arguments})', |
499 # Interface types | 507 # Interface types |
500 'Dictionary': 'Dictionary({v8_value}, {isolate}, exceptionState)', | 508 'Dictionary': 'Dictionary({v8_value}, {isolate}, exceptionState)', |
501 'EventTarget': 'toEventTarget({isolate}, {v8_value})', | 509 'EventTarget': 'toEventTarget({isolate}, {v8_value})', |
| 510 'FlexibleArrayBufferView': 'toFlexibleArrayBufferView({isolate}, {v8_value},
{variable_name}, allocateFlexibleArrayBufferViewStorage({v8_value}))', |
502 'NodeFilter': 'toNodeFilter({v8_value}, info.Holder(), ScriptState::current(
{isolate}))', | 511 'NodeFilter': 'toNodeFilter({v8_value}, info.Holder(), ScriptState::current(
{isolate}))', |
503 'Promise': 'ScriptPromise::cast(ScriptState::current({isolate}), {v8_value})
', | 512 'Promise': 'ScriptPromise::cast(ScriptState::current({isolate}), {v8_value})
', |
504 'SerializedScriptValue': 'SerializedScriptValueFactory::instance().create({i
solate}, {v8_value}, 0, 0, exceptionState)', | 513 'SerializedScriptValue': 'SerializedScriptValueFactory::instance().create({i
solate}, {v8_value}, 0, 0, exceptionState)', |
505 'ScriptValue': 'ScriptValue(ScriptState::current({isolate}), {v8_value})', | 514 'ScriptValue': 'ScriptValue(ScriptState::current({isolate}), {v8_value})', |
506 'Window': 'toDOMWindow({isolate}, {v8_value})', | 515 'Window': 'toDOMWindow({isolate}, {v8_value})', |
507 'XPathNSResolver': 'toXPathNSResolver(ScriptState::current({isolate}), {v8_v
alue})', | 516 'XPathNSResolver': 'toXPathNSResolver(ScriptState::current({isolate}), {v8_v
alue})', |
508 } | 517 } |
509 | 518 |
510 | 519 |
511 def v8_conversion_needs_exception_state(idl_type): | 520 def v8_conversion_needs_exception_state(idl_type): |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 | 554 |
546 # Array or sequence types | 555 # Array or sequence types |
547 native_array_element_type = idl_type.native_array_element_type | 556 native_array_element_type = idl_type.native_array_element_type |
548 if native_array_element_type: | 557 if native_array_element_type: |
549 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type
, v8_value, index, isolate) | 558 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type
, v8_value, index, isolate) |
550 | 559 |
551 # Simple types | 560 # Simple types |
552 idl_type = idl_type.preprocessed_type | 561 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 | 562 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i
dl_type.base_type |
554 | 563 |
| 564 if 'FlexibleArrayBufferView' in extended_attributes: |
| 565 if base_idl_type not in TYPED_ARRAY_TYPES.union(set(['ArrayBufferView'])
): |
| 566 raise "Unrecognized base type for extended attribute 'FlexibleArrayB
ufferView': %s" % (idl_type.base_type) |
| 567 base_idl_type = 'FlexibleArrayBufferView' |
| 568 |
555 if idl_type.is_integer_type: | 569 if idl_type.is_integer_type: |
556 configuration = 'NormalConversion' | 570 configuration = 'NormalConversion' |
557 if 'EnforceRange' in extended_attributes: | 571 if 'EnforceRange' in extended_attributes: |
558 configuration = 'EnforceRange' | 572 configuration = 'EnforceRange' |
559 elif 'Clamp' in extended_attributes: | 573 elif 'Clamp' in extended_attributes: |
560 configuration = 'Clamp' | 574 configuration = 'Clamp' |
561 arguments = ', '.join([v8_value, configuration, 'exceptionState']) | 575 arguments = ', '.join([v8_value, configuration, 'exceptionState']) |
562 elif idl_type.v8_conversion_needs_exception_state: | 576 elif idl_type.v8_conversion_needs_exception_state: |
563 arguments = ', '.join([v8_value, 'exceptionState']) | 577 arguments = ', '.join([v8_value, 'exceptionState']) |
564 else: | 578 else: |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 # as the condition here would be wrong. | 655 # as the condition here would be wrong. |
642 if not idl_type.v8_conversion_needs_exception_state: | 656 if not idl_type.v8_conversion_needs_exception_state: |
643 if use_exception_state: | 657 if use_exception_state: |
644 check_expression = '!%s.prepare(exceptionState)' % variable_
name | 658 check_expression = '!%s.prepare(exceptionState)' % variable_
name |
645 else: | 659 else: |
646 check_expression = '!%s.prepare()' % variable_name | 660 check_expression = '!%s.prepare()' % variable_name |
647 elif not idl_type.v8_conversion_is_trivial: | 661 elif not idl_type.v8_conversion_is_trivial: |
648 return { | 662 return { |
649 'error_message': 'no V8 -> C++ conversion for IDL type: %s' % idl_ty
pe.name | 663 'error_message': 'no V8 -> C++ conversion for IDL type: %s' % idl_ty
pe.name |
650 } | 664 } |
| 665 elif 'FlexibleArrayBufferView' in extended_attributes: |
| 666 if idl_type.base_type not in TYPED_ARRAY_TYPES.union(set(['ArrayBufferVi
ew'])): |
| 667 raise "Unrecognized base type for extended attribute 'FlexibleArrayB
ufferView': %s" % (idl_type.base_type) |
| 668 set_expression = cpp_value |
651 else: | 669 else: |
652 assign_expression = cpp_value | 670 assign_expression = cpp_value |
653 | 671 |
654 # Types that don't need error handling, and simply assign a value to the | 672 # Types that don't need error handling, and simply assign a value to the |
655 # local variable. | 673 # local variable. |
656 | 674 |
657 return { | 675 return { |
658 'assign_expression': assign_expression, | 676 'assign_expression': assign_expression, |
659 'check_expression': check_expression, | 677 'check_expression': check_expression, |
660 'cpp_type': this_cpp_type, | 678 '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) | 1016 number_of_nullable_member_types_union) |
999 | 1017 |
1000 | 1018 |
1001 def includes_nullable_type_union(idl_type): | 1019 def includes_nullable_type_union(idl_type): |
1002 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type | 1020 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type |
1003 return idl_type.number_of_nullable_member_types == 1 | 1021 return idl_type.number_of_nullable_member_types == 1 |
1004 | 1022 |
1005 IdlTypeBase.includes_nullable_type = False | 1023 IdlTypeBase.includes_nullable_type = False |
1006 IdlNullableType.includes_nullable_type = True | 1024 IdlNullableType.includes_nullable_type = True |
1007 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) | 1025 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) |
OLD | NEW |