Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: Source/bindings/scripts/v8_types.py

Issue 1091543002: IDL: Add [FlexibleArrayBufferView] and use for bufferSubData Base URL: https://chromium.googlesource.com/chromium/blink.git@idl-includes-for-type-tuning
Patch Set: add warning about the storage's life-time Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: 174 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES:
175 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] 175 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type]
176 176
177 if base_idl_type in NON_WRAPPER_TYPES: 177 if base_idl_type in NON_WRAPPER_TYPES:
178 return ('PassRefPtr<%s>' if used_as_rvalue_type else 'RefPtr<%s>') % bas e_idl_type 178 return ('PassRefPtr<%s>' if used_as_rvalue_type else 'RefPtr<%s>') % bas e_idl_type
179 if idl_type.is_string_type: 179 if idl_type.is_string_type:
180 if not raw_type: 180 if not raw_type:
181 return 'String' 181 return 'String'
182 return 'V8StringResource<%s>' % string_mode() 182 return 'V8StringResource<%s>' % string_mode()
183 183
184 if idl_type.is_array_buffer_or_view and raw_type: 184 if idl_type.base_type == 'ArrayBufferView' and 'FlexibleArrayBufferView' in extended_attributes:
185 return idl_type.implemented_as + '*' 185 return 'FlexibleArrayBufferView'
186 if idl_type.is_interface_type: 186 if idl_type.is_interface_type:
187 implemented_as_class = idl_type.implemented_as 187 implemented_as_class = idl_type.implemented_as
188 if raw_type or (used_as_rvalue_type and idl_type.is_garbage_collected): 188 if raw_type or (used_as_rvalue_type and idl_type.is_garbage_collected):
189 return implemented_as_class + '*' 189 return implemented_as_class + '*'
190 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' 190 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr'
191 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_rvalue_type else 'RefPt r'), new_type, idl_type.gc_type) 191 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_rvalue_type else 'RefPt r'), new_type, idl_type.gc_type)
192 return cpp_template_type(ptr_type, implemented_as_class) 192 return cpp_template_type(ptr_type, implemented_as_class)
193 if idl_type.is_dictionary: 193 if idl_type.is_dictionary:
194 return base_idl_type 194 return base_idl_type
195 if idl_type.is_union_type: 195 if idl_type.is_union_type:
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 367
368 368
369 def includes_for_type(idl_type, extended_attributes=None): 369 def includes_for_type(idl_type, extended_attributes=None):
370 idl_type = idl_type.preprocessed_type 370 idl_type = idl_type.preprocessed_type
371 extended_attributes = extended_attributes or {} 371 extended_attributes = extended_attributes or {}
372 372
373 # Simple types 373 # Simple types
374 base_idl_type = idl_type.base_type 374 base_idl_type = idl_type.base_type
375 if base_idl_type in INCLUDES_FOR_TYPE: 375 if base_idl_type in INCLUDES_FOR_TYPE:
376 return INCLUDES_FOR_TYPE[base_idl_type] 376 return INCLUDES_FOR_TYPE[base_idl_type]
377 if base_idl_type == 'ArrayBufferView' and 'FlexibleArrayBufferView' in exten ded_attributes:
378 return set(['bindings/core/v8/V8ArrayBufferView.h',
379 'core/dom/FlexibleArrayBufferView.h'])
377 if idl_type.is_basic_type: 380 if idl_type.is_basic_type:
378 return set() 381 return set()
379 if base_idl_type.endswith('ConstructorConstructor'): 382 if base_idl_type.endswith('ConstructorConstructor'):
380 # FIXME: rename to NamedConstructor 383 # FIXME: rename to NamedConstructor
381 # FIXME: replace with a [NamedConstructorAttribute] extended attribute 384 # FIXME: replace with a [NamedConstructorAttribute] extended attribute
382 # Ending with 'ConstructorConstructor' indicates a named constructor, 385 # Ending with 'ConstructorConstructor' indicates a named constructor,
383 # and these do not have header files, as they are part of the generated 386 # and these do not have header files, as they are part of the generated
384 # bindings for the interface 387 # bindings for the interface
385 return set() 388 return set()
386 if base_idl_type.endswith('Constructor'): 389 if base_idl_type.endswith('Constructor'):
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 'octet': 'toUInt8({isolate}, {arguments})', 493 'octet': 'toUInt8({isolate}, {arguments})',
491 'short': 'toInt16({isolate}, {arguments})', 494 'short': 'toInt16({isolate}, {arguments})',
492 'unsigned short': 'toUInt16({isolate}, {arguments})', 495 'unsigned short': 'toUInt16({isolate}, {arguments})',
493 'long': 'toInt32({isolate}, {arguments})', 496 'long': 'toInt32({isolate}, {arguments})',
494 'unsigned long': 'toUInt32({isolate}, {arguments})', 497 'unsigned long': 'toUInt32({isolate}, {arguments})',
495 'long long': 'toInt64({isolate}, {arguments})', 498 'long long': 'toInt64({isolate}, {arguments})',
496 'unsigned long long': 'toUInt64({isolate}, {arguments})', 499 'unsigned long long': 'toUInt64({isolate}, {arguments})',
497 # Interface types 500 # Interface types
498 'Dictionary': 'Dictionary({v8_value}, {isolate}, exceptionState)', 501 'Dictionary': 'Dictionary({v8_value}, {isolate}, exceptionState)',
499 'EventTarget': 'toEventTarget({isolate}, {v8_value})', 502 'EventTarget': 'toEventTarget({isolate}, {v8_value})',
503 'FlexibleArrayBufferView': 'toFlexibleArrayBufferView({isolate}, {v8_value}, {variable_name}, SMALL_ARRAY_BUFFER_VIEW_STORAGE({v8_value}))',
500 'NodeFilter': 'toNodeFilter({v8_value}, info.Holder(), ScriptState::current( {isolate}))', 504 'NodeFilter': 'toNodeFilter({v8_value}, info.Holder(), ScriptState::current( {isolate}))',
501 'Promise': 'ScriptPromise::cast(ScriptState::current({isolate}), {v8_value}) ', 505 'Promise': 'ScriptPromise::cast(ScriptState::current({isolate}), {v8_value}) ',
502 'SerializedScriptValue': 'SerializedScriptValueFactory::instance().create({v 8_value}, 0, 0, exceptionState, {isolate})', 506 'SerializedScriptValue': 'SerializedScriptValueFactory::instance().create({v 8_value}, 0, 0, exceptionState, {isolate})',
503 'ScriptValue': 'ScriptValue(ScriptState::current({isolate}), {v8_value})', 507 'ScriptValue': 'ScriptValue(ScriptState::current({isolate}), {v8_value})',
504 'Window': 'toDOMWindow({isolate}, {v8_value})', 508 'Window': 'toDOMWindow({isolate}, {v8_value})',
505 'XPathNSResolver': 'toXPathNSResolver({isolate}, {v8_value})', 509 'XPathNSResolver': 'toXPathNSResolver({isolate}, {v8_value})',
506 } 510 }
507 511
508 512
509 def v8_conversion_needs_exception_state(idl_type): 513 def v8_conversion_needs_exception_state(idl_type):
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 547
544 # Array or sequence types 548 # Array or sequence types
545 native_array_element_type = idl_type.native_array_element_type 549 native_array_element_type = idl_type.native_array_element_type
546 if native_array_element_type: 550 if native_array_element_type:
547 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate) 551 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate)
548 552
549 # Simple types 553 # Simple types
550 idl_type = idl_type.preprocessed_type 554 idl_type = idl_type.preprocessed_type
551 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i dl_type.base_type 555 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i dl_type.base_type
552 556
557 if base_idl_type == 'ArrayBufferView' and 'FlexibleArrayBufferView' in exten ded_attributes:
558 base_idl_type = 'FlexibleArrayBufferView'
559
553 if idl_type.is_integer_type: 560 if idl_type.is_integer_type:
554 configuration = 'NormalConversion' 561 configuration = 'NormalConversion'
555 if 'EnforceRange' in extended_attributes: 562 if 'EnforceRange' in extended_attributes:
556 configuration = 'EnforceRange' 563 configuration = 'EnforceRange'
557 elif 'Clamp' in extended_attributes: 564 elif 'Clamp' in extended_attributes:
558 configuration = 'Clamp' 565 configuration = 'Clamp'
559 arguments = ', '.join([v8_value, configuration, 'exceptionState']) 566 arguments = ', '.join([v8_value, configuration, 'exceptionState'])
560 elif idl_type.v8_conversion_needs_exception_state: 567 elif idl_type.v8_conversion_needs_exception_state:
561 arguments = ', '.join([v8_value, 'exceptionState']) 568 arguments = ', '.join([v8_value, 'exceptionState'])
562 else: 569 else:
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 # 'idl_type.is_string_type', but there are types for which both are 645 # 'idl_type.is_string_type', but there are types for which both are
639 # true (ByteString and USVString), so using idl_type.is_string_type 646 # true (ByteString and USVString), so using idl_type.is_string_type
640 # as the condition here would be wrong. 647 # as the condition here would be wrong.
641 if not idl_type.v8_conversion_needs_exception_state: 648 if not idl_type.v8_conversion_needs_exception_state:
642 if use_exception_state: 649 if use_exception_state:
643 check_expression = '!%s.prepare(exceptionState)' % variable_ name 650 check_expression = '!%s.prepare(exceptionState)' % variable_ name
644 else: 651 else:
645 check_expression = '!%s.prepare()' % variable_name 652 check_expression = '!%s.prepare()' % variable_name
646 elif not idl_type.v8_conversion_is_trivial: 653 elif not idl_type.v8_conversion_is_trivial:
647 raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % i dl_type.name) 654 raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % i dl_type.name)
655 elif idl_type.base_type == 'ArrayBufferView' and 'FlexibleArrayBufferView' i n extended_attributes:
656 set_expression = cpp_value
648 else: 657 else:
649 assign_expression = cpp_value 658 assign_expression = cpp_value
650 659
651 # Types that don't need error handling, and simply assign a value to the 660 # Types that don't need error handling, and simply assign a value to the
652 # local variable. 661 # local variable.
653 662
654 return { 663 return {
655 'assign_expression': assign_expression, 664 'assign_expression': assign_expression,
656 'check_expression': check_expression, 665 'check_expression': check_expression,
657 'cpp_type': this_cpp_type, 666 'cpp_type': this_cpp_type,
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 number_of_nullable_member_types_union) 983 number_of_nullable_member_types_union)
975 984
976 985
977 def includes_nullable_type_union(idl_type): 986 def includes_nullable_type_union(idl_type):
978 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type 987 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type
979 return idl_type.number_of_nullable_member_types == 1 988 return idl_type.number_of_nullable_member_types == 1
980 989
981 IdlTypeBase.includes_nullable_type = False 990 IdlTypeBase.includes_nullable_type = False
982 IdlNullableType.includes_nullable_type = True 991 IdlNullableType.includes_nullable_type = True
983 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) 992 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union)
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/V8BindingMacros.h ('k') | Source/bindings/tests/idls/core/TestObject.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698