Chromium Code Reviews| Index: Source/bindings/scripts/v8_types.py |
| diff --git a/Source/bindings/scripts/v8_types.py b/Source/bindings/scripts/v8_types.py |
| index 6b76eadd2ed7dc13771662500cd2f0ec0926d251..a4a4a02d7609fec78e4adc79ff1ce64b12d865dc 100644 |
| --- a/Source/bindings/scripts/v8_types.py |
| +++ b/Source/bindings/scripts/v8_types.py |
| @@ -594,64 +594,65 @@ def v8_value_to_cpp_value_array_or_sequence(native_array_element_type, v8_value, |
| # FIXME: this function should be refactored, as this takes too many flags. |
| -def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variable_name=None, index=None, declare_variable=True, isolate='info.GetIsolate()', used_in_private_script=False, return_promise=False, needs_exception_state_for_string=False, restricted_float=False): |
| +def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variable_name, index=None, declare_variable=True, isolate='info.GetIsolate()', bailout_return_value=None, use_exception_state=False, restricted_float=False): |
| """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" |
| this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attributes, raw_type=True) |
| idl_type = idl_type.preprocessed_type |
| if idl_type.base_type in ('void', 'object', 'EventHandler', 'EventListener'): |
| - return '/* no V8 -> C++ conversion for IDL type: %s */' % idl_type.name |
| + return { |
| + 'error_message': 'no V8 -> C++ conversion for IDL type: %s' % idl_type.name |
| + } |
| cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name, index, isolate, restricted_float=restricted_float) |
| - if idl_type.is_dictionary or idl_type.is_union_type: |
| - return 'TONATIVE_VOID_EXCEPTIONSTATE_ARGINTERNAL(%s, exceptionState)' % cpp_value |
| + # Optional expression that returns a value to be assigned to the local variable. |
| + assign_expression = None |
| + # Optional expression that returns true if the conversion fails. |
| + check_expression = None |
| + # Next two: only meaningful if 'check_expression' is not None. |
| + # Optional expression executed before returning. |
| + throw_expression = None |
| + # Optional expression used as the return value when returning. |
| + return_expression = bailout_return_value |
| if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state: |
| - # Types that need error handling and use one of a group of (C++) macros |
| - # to take care of this. |
| - |
| - args = [variable_name, cpp_value] |
| + # Types for which conversion can fail and that need error handling. |
| - if idl_type.v8_conversion_needs_exception_state: |
| - macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE' |
| - elif return_promise or needs_exception_state_for_string: |
| - macro = 'TOSTRING_VOID_EXCEPTIONSTATE' |
| + if idl_type.is_dictionary or idl_type.is_union_type: |
| + check_expression = '!' + cpp_value |
| + if not use_exception_state: |
| + throw_expression = 'exceptionState.throwIfNeeded()' |
| else: |
| - macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_VOID' |
| - |
| - if macro.endswith('_EXCEPTIONSTATE'): |
| - args.append('exceptionState') |
| - |
| - if used_in_private_script: |
| - args.append('false') |
| - |
| - suffix = '' |
| - |
| - if return_promise: |
| - suffix += '_PROMISE' |
| - args.append('info') |
| - if macro.endswith('_EXCEPTIONSTATE'): |
| - args.append('ScriptState::current(%s)' % isolate) |
| - |
| - if declare_variable: |
| - args.insert(0, this_cpp_type) |
| - else: |
| - suffix += '_INTERNAL' |
| - |
| - return '%s(%s)' % (macro + suffix, ', '.join(args)) |
| + assign_expression = cpp_value |
| + if idl_type.v8_conversion_needs_exception_state: |
| + if use_exception_state: |
| + check_expression = 'exceptionState.hadException()' |
| + else: |
| + check_expression = 'exceptionState.throwIfNeeded()' |
|
haraken
2015/02/24 15:59:38
It seems a bit confusing that we use exceptionStat
Jens Widell
2015/02/24 16:15:58
Yeah, "use_exception_state" is not a variable name
|
| + else: # idl_type.is_string_type |
| + if use_exception_state: |
| + check_expression = '!%s.prepare(exceptionState)' % variable_name |
| + else: |
| + check_expression = '!%s.prepare()' % variable_name |
| + elif not idl_type.v8_conversion_is_trivial: |
| + raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % idl_type.name) |
| + else: |
| + assign_expression = cpp_value |
| # Types that don't need error handling, and simply assign a value to the |
| # local variable. |
| - if not idl_type.v8_conversion_is_trivial: |
| - raise Exception('unclassified V8 -> C++ conversion for IDL type: %s' % idl_type.name) |
| - |
| - assignment = '%s = %s' % (variable_name, cpp_value) |
| - if declare_variable: |
| - return '%s %s' % (this_cpp_type, assignment) |
| - return assignment |
| + return { |
| + 'assign_expression': assign_expression, |
| + 'check_expression': check_expression, |
| + 'cpp_type': this_cpp_type, |
| + 'cpp_name': variable_name, |
| + 'declare_variable': declare_variable, |
| + 'return_expression': bailout_return_value, |
| + 'throw_expression': throw_expression, |
| + } |
| IdlTypeBase.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value |