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

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

Issue 860353002: IDL: Add toRestricted{Float,Double}() helpers to V8Binding.h (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add FIXME comment Created 5 years, 11 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 # V8 -> C++ 469 # V8 -> C++
470 ################################################################################ 470 ################################################################################
471 471
472 V8_VALUE_TO_CPP_VALUE = { 472 V8_VALUE_TO_CPP_VALUE = {
473 # Basic 473 # Basic
474 'Date': 'toCoreDate({v8_value})', 474 'Date': 'toCoreDate({v8_value})',
475 'DOMString': '{v8_value}', 475 'DOMString': '{v8_value}',
476 'ByteString': 'toByteString({arguments})', 476 'ByteString': 'toByteString({arguments})',
477 'USVString': 'toUSVString({arguments})', 477 'USVString': 'toUSVString({arguments})',
478 'boolean': '{v8_value}->BooleanValue()', 478 'boolean': '{v8_value}->BooleanValue()',
479 'float': 'toFloat({arguments})', 479 'float': 'toRestrictedFloat({arguments})',
480 'unrestricted float': 'toFloat({arguments})', 480 'unrestricted float': 'toFloat({arguments})',
481 'double': 'toDouble({arguments})', 481 'double': 'toRestrictedDouble({arguments})',
482 'unrestricted double': 'toDouble({arguments})', 482 'unrestricted double': 'toDouble({arguments})',
483 'byte': 'toInt8({arguments})', 483 'byte': 'toInt8({arguments})',
484 'octet': 'toUInt8({arguments})', 484 'octet': 'toUInt8({arguments})',
485 'short': 'toInt16({arguments})', 485 'short': 'toInt16({arguments})',
486 'unsigned short': 'toUInt16({arguments})', 486 'unsigned short': 'toUInt16({arguments})',
487 'long': 'toInt32({arguments})', 487 'long': 'toInt32({arguments})',
488 'unsigned long': 'toUInt32({arguments})', 488 'unsigned long': 'toUInt32({arguments})',
489 'long long': 'toInt64({arguments})', 489 'long long': 'toInt64({arguments})',
490 'unsigned long long': 'toUInt64({arguments})', 490 'unsigned long long': 'toUInt64({arguments})',
491 # Interface types 491 # Interface types
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 523
524 def v8_conversion_is_trivial(idl_type): 524 def v8_conversion_is_trivial(idl_type):
525 # The conversion is a simple expression that returns the converted value and 525 # The conversion is a simple expression that returns the converted value and
526 # cannot raise an exception. 526 # cannot raise an exception.
527 return (idl_type.base_type in TRIVIAL_CONVERSIONS or 527 return (idl_type.base_type in TRIVIAL_CONVERSIONS or
528 idl_type.is_wrapper_type) 528 idl_type.is_wrapper_type)
529 529
530 IdlType.v8_conversion_is_trivial = property(v8_conversion_is_trivial) 530 IdlType.v8_conversion_is_trivial = property(v8_conversion_is_trivial)
531 531
532 532
533 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name , index, isolate): 533 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name , index, isolate, restricted_float=False):
534 if idl_type.name == 'void': 534 if idl_type.name == 'void':
535 return '' 535 return ''
536 536
537 # Array or sequence types 537 # Array or sequence types
538 native_array_element_type = idl_type.native_array_element_type 538 native_array_element_type = idl_type.native_array_element_type
539 if native_array_element_type: 539 if native_array_element_type:
540 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate) 540 return v8_value_to_cpp_value_array_or_sequence(native_array_element_type , v8_value, index, isolate)
541 541
542 # Simple types 542 # Simple types
543 idl_type = idl_type.preprocessed_type 543 idl_type = idl_type.preprocessed_type
544 add_includes_for_type(idl_type) 544 add_includes_for_type(idl_type)
545 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i dl_type.base_type 545 base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else i dl_type.base_type
546 546
547 if 'EnforceRange' in extended_attributes: 547 if 'EnforceRange' in extended_attributes:
548 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) 548 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState'])
549 elif 'Clamp' in extended_attributes: 549 elif 'Clamp' in extended_attributes:
550 arguments = ', '.join([v8_value, 'Clamp', 'exceptionState']) 550 arguments = ', '.join([v8_value, 'Clamp', 'exceptionState'])
551 elif idl_type.v8_conversion_needs_exception_state: 551 elif idl_type.v8_conversion_needs_exception_state:
552 arguments = ', '.join([v8_value, 'exceptionState']) 552 arguments = ', '.join([v8_value, 'exceptionState'])
553 else: 553 else:
554 arguments = v8_value 554 arguments = v8_value
555 555
556 if base_idl_type in V8_VALUE_TO_CPP_VALUE: 556 if base_idl_type in V8_VALUE_TO_CPP_VALUE:
557 # FIXME: Once float/double are implemented per-specification (without
558 # [TypeChecking=Unrestricted]) this special handling can be dropped.
559 # http://crbug.com/354298
560 if base_idl_type in ('float', 'double') and not restricted_float:
561 base_idl_type = 'unrestricted ' + base_idl_type
557 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] 562 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type]
558 elif idl_type.is_array_buffer_or_view: 563 elif idl_type.is_array_buffer_or_view:
559 cpp_expression_format = ( 564 cpp_expression_format = (
560 '{v8_value}->Is{idl_type}() ? ' 565 '{v8_value}->Is{idl_type}() ? '
561 'V8{idl_type}::toImpl(v8::Local<v8::{idl_type}>::Cast({v8_value})) : 0') 566 'V8{idl_type}::toImpl(v8::Local<v8::{idl_type}>::Cast({v8_value})) : 0')
562 elif idl_type.use_output_parameter_for_result: 567 elif idl_type.use_output_parameter_for_result:
563 if idl_type.includes_nullable_type: 568 if idl_type.includes_nullable_type:
564 base_idl_type = idl_type.cpp_type + 'OrNull' 569 base_idl_type = idl_type.cpp_type + 'OrNull'
565 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, exceptionState)' 570 cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {va riable_name}, exceptionState)'
566 else: 571 else:
(...skipping 18 matching lines...) Expand all
585 add_includes_for_type(native_array_element_type) 590 add_includes_for_type(native_array_element_type)
586 else: 591 else:
587 ref_ptr_type = None 592 ref_ptr_type = None
588 this_cpp_type = native_array_element_type.cpp_type 593 this_cpp_type = native_array_element_type.cpp_type
589 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola te}, exceptionState)' 594 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola te}, exceptionState)'
590 expression = expression_format.format(native_array_element_type=native_array _element_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_ty pe, v8_value=v8_value, isolate=isolate) 595 expression = expression_format.format(native_array_element_type=native_array _element_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_ty pe, v8_value=v8_value, isolate=isolate)
591 return expression 596 return expression
592 597
593 598
594 # FIXME: this function should be refactored, as this takes too many flags. 599 # FIXME: this function should be refactored, as this takes too many flags.
595 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name=None, index=None, declare_variable=True, isolate='info.GetIsolate()', use d_in_private_script=False, return_promise=False, needs_exception_state_for_strin g=False): 600 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name=None, index=None, declare_variable=True, isolate='info.GetIsolate()', use d_in_private_script=False, return_promise=False, needs_exception_state_for_strin g=False, restricted_float=False):
596 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" 601 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value."""
597 602
598 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True) 603 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True)
599 idl_type = idl_type.preprocessed_type 604 idl_type = idl_type.preprocessed_type
600 605
601 if idl_type.base_type in ('void', 'object', 'EventHandler', 'EventListener') : 606 if idl_type.base_type in ('void', 'object', 'EventHandler', 'EventListener') :
602 return '/* no V8 -> C++ conversion for IDL type: %s */' % idl_type.name 607 return '/* no V8 -> C++ conversion for IDL type: %s */' % idl_type.name
603 608
604 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v ariable_name, index, isolate) 609 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, v ariable_name, index, isolate, restricted_float=restricted_float)
605 610
606 if idl_type.is_dictionary or idl_type.is_union_type: 611 if idl_type.is_dictionary or idl_type.is_union_type:
607 return 'TONATIVE_VOID_EXCEPTIONSTATE_ARGINTERNAL(%s, exceptionState)' % cpp_value 612 return 'TONATIVE_VOID_EXCEPTIONSTATE_ARGINTERNAL(%s, exceptionState)' % cpp_value
608 613
609 if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state: 614 if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state:
610 # Types that need error handling and use one of a group of (C++) macros 615 # Types that need error handling and use one of a group of (C++) macros
611 # to take care of this. 616 # to take care of this.
612 617
613 args = [variable_name, cpp_value] 618 args = [variable_name, cpp_value]
614 619
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 number_of_nullable_member_types_union) 950 number_of_nullable_member_types_union)
946 951
947 952
948 def includes_nullable_type_union(idl_type): 953 def includes_nullable_type_union(idl_type):
949 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type 954 # http://heycam.github.io/webidl/#dfn-includes-a-nullable-type
950 return idl_type.number_of_nullable_member_types == 1 955 return idl_type.number_of_nullable_member_types == 1
951 956
952 IdlTypeBase.includes_nullable_type = False 957 IdlTypeBase.includes_nullable_type = False
953 IdlNullableType.includes_nullable_type = True 958 IdlNullableType.includes_nullable_type = True
954 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union) 959 IdlUnionType.includes_nullable_type = property(includes_nullable_type_union)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698