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

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

Issue 611453002: IDL: Clean up argument conversion error handling (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/templates/methods.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola te}, exceptionState)' 558 expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isola te}, exceptionState)'
559 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) 559 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)
560 return expression 560 return expression
561 561
562 562
563 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True, isolate='info.GetIsolate()', used_in_ private_script=False, return_promise=False): 563 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True, isolate='info.GetIsolate()', used_in_ private_script=False, return_promise=False):
564 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" 564 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value."""
565 565
566 # FIXME: Support union type. 566 # FIXME: Support union type.
567 if idl_type.is_union_type: 567 if idl_type.is_union_type:
568 return '' 568 return '/* no V8 -> C++ conversion for IDL union type: %s */' % idl_type .name
haraken 2014/09/26 09:49:29 Can we raise an exception instead?
569 569
570 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True) 570 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True)
571 idl_type = idl_type.preprocessed_type
571 572
572 idl_type = idl_type.preprocessed_type 573 if idl_type.base_type in ('void', 'object', 'EventHandler', 'EventListener') :
Jens Widell 2014/09/26 09:45:57 These are IDL types where we don't have meaningful
574 return '/* no V8 -> C++ conversion for IDL type: %s */' % idl_type.name
575
573 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex, isolate) 576 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex, isolate)
574 args = [variable_name, cpp_value] 577 if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state:
575 if idl_type.base_type == 'DOMString': 578 # Types that need error handling and use one of a group of (C++) macros
576 if return_promise: 579 # to take care of this.
580
581 args = [variable_name, cpp_value]
582
583 if idl_type.v8_conversion_needs_exception_state:
584 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE'
585 elif return_promise:
577 macro = 'TOSTRING_VOID_EXCEPTIONSTATE' 586 macro = 'TOSTRING_VOID_EXCEPTIONSTATE'
578 else: 587 else:
579 macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_ VOID' 588 macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_ VOID'
580 elif idl_type.v8_conversion_needs_exception_state: 589
581 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE' 590 if macro.endswith('_EXCEPTIONSTATE'):
582 elif idl_type.v8_conversion_is_trivial: 591 args.append('exceptionState')
583 assignment = '%s = %s' % (variable_name, cpp_value) 592
593 if used_in_private_script:
594 args.append('false')
595
596 suffix = ''
597
598 if return_promise:
599 suffix += '_PROMISE'
600 args.append('info')
601 if macro.endswith('_EXCEPTIONSTATE'):
602 args.append('ScriptState::current(%s)' % isolate)
603
584 if declare_variable: 604 if declare_variable:
585 return '%s %s' % (this_cpp_type, assignment) 605 args.insert(0, this_cpp_type)
586 return assignment 606 else:
587 else: 607 suffix += '_INTERNAL'
588 macro = 'TONATIVE_DEFAULT' if used_in_private_script else 'TONATIVE_VOID '
589 608
590 if macro.endswith('_EXCEPTIONSTATE'): 609 return '%s(%s)' % (macro + suffix, ', '.join(args))
591 args.append('exceptionState')
592 610
593 if used_in_private_script: 611 # Types that don't need error handling, and simply assign a value to the
594 args.append('false') 612 # local variable.
595 613
596 # Macros come in several variants, to minimize expensive creation of 614 if not idl_type.v8_conversion_is_trivial:
597 # v8::TryCatch. 615 raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % i dl_type.name)
598 suffix = ''
599 616
600 if return_promise: 617 assignment = '%s = %s' % (variable_name, cpp_value)
601 suffix += '_PROMISE' 618 if declare_variable:
602 args.append('info') 619 return '%s %s' % (this_cpp_type, assignment)
603 if macro.endswith('_EXCEPTIONSTATE'): 620 return assignment
604 args.append('ScriptState::current(%s)' % isolate)
605 621
606 if declare_variable:
607 args.insert(0, this_cpp_type)
608 else:
609 suffix += '_INTERNAL'
610
611 return '%s(%s)' % (macro + suffix, ', '.join(args))
612 622
613 IdlTypeBase.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value 623 IdlTypeBase.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value
614 624
615 625
616 ################################################################################ 626 ################################################################################
617 # C++ -> V8 627 # C++ -> V8
618 ################################################################################ 628 ################################################################################
619 629
620 def preprocess_idl_type(idl_type): 630 def preprocess_idl_type(idl_type):
621 if idl_type.is_enum: 631 if idl_type.is_enum:
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 864
855 865
856 def is_explicit_nullable(idl_type): 866 def is_explicit_nullable(idl_type):
857 # Nullable type that isn't implicit nullable (see above.) For such types, 867 # Nullable type that isn't implicit nullable (see above.) For such types,
858 # we use Nullable<T> or similar explicit ways to represent a null value. 868 # we use Nullable<T> or similar explicit ways to represent a null value.
859 return idl_type.is_nullable and not idl_type.is_implicit_nullable 869 return idl_type.is_nullable and not idl_type.is_implicit_nullable
860 870
861 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable) 871 IdlTypeBase.is_implicit_nullable = property(is_implicit_nullable)
862 IdlUnionType.is_implicit_nullable = False 872 IdlUnionType.is_implicit_nullable = False
863 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable) 873 IdlTypeBase.is_explicit_nullable = property(is_explicit_nullable)
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/templates/methods.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698