| Index: third_party/WebKit/Source/bindings/scripts/v8_types.py
|
| diff --git a/third_party/WebKit/Source/bindings/scripts/v8_types.py b/third_party/WebKit/Source/bindings/scripts/v8_types.py
|
| index 1b50fee8e9186d4baacf5ef73debb492495f08b8..2c0b58d8e1802e6d678e7f39b1784ce247ade0e8 100644
|
| --- a/third_party/WebKit/Source/bindings/scripts/v8_types.py
|
| +++ b/third_party/WebKit/Source/bindings/scripts/v8_types.py
|
| @@ -145,15 +145,6 @@ def cpp_type(idl_type, extended_attributes=None, raw_type=False, used_as_rvalue_
|
| bool, True if the C++ type is used as an element of a container.
|
| Containers can be an array, a sequence or a dictionary.
|
| """
|
| - def string_mode():
|
| - if idl_type.is_nullable:
|
| - return 'TreatNullAndUndefinedAsNullString'
|
| - if extended_attributes.get('TreatNullAs') == 'EmptyString':
|
| - return 'TreatNullAsEmptyString'
|
| - if extended_attributes.get('TreatNullAs') == 'NullString':
|
| - return 'TreatNullAsNullString'
|
| - return ''
|
| -
|
| extended_attributes = extended_attributes or {}
|
| idl_type = idl_type.preprocessed_type
|
|
|
| @@ -186,7 +177,7 @@ def cpp_type(idl_type, extended_attributes=None, raw_type=False, used_as_rvalue_
|
| if idl_type.is_string_type:
|
| if not raw_type:
|
| return 'String'
|
| - return 'V8StringResource<%s>' % string_mode()
|
| + return 'V8StringResource<>'
|
|
|
| if base_idl_type == 'ArrayBufferView' and 'FlexibleArrayBufferView' in extended_attributes:
|
| return 'FlexibleArrayBufferView'
|
| @@ -374,7 +365,7 @@ def includes_for_type(idl_type, extended_attributes=None):
|
| set(['bindings/%s/v8/V8%s.h' % (component_dir[base_idl_type], base_idl_type)])
|
| )
|
| if idl_type.is_basic_type:
|
| - return set()
|
| + return set(['bindings/core/v8/IDLTypes.h'])
|
| if base_idl_type.endswith('ConstructorConstructor'):
|
| # FIXME: rename to NamedConstructor
|
| # FIXME: replace with a [NamedConstructorAttribute] extended attribute
|
| @@ -393,7 +384,8 @@ def includes_for_type(idl_type, extended_attributes=None):
|
| if base_idl_type not in component_dir:
|
| return set()
|
| return set(['bindings/%s/v8/V8%s.h' % (component_dir[base_idl_type],
|
| - base_idl_type)])
|
| + base_idl_type),
|
| + 'bindings/core/v8/IDLTypes.h'])
|
|
|
| IdlType.includes_for_type = includes_for_type
|
|
|
| @@ -484,32 +476,9 @@ def set_component_dirs(new_component_dirs):
|
| ################################################################################
|
|
|
| V8_VALUE_TO_CPP_VALUE = {
|
| - # Basic
|
| - 'Date': 'toCoreDate({isolate}, {v8_value}, exceptionState)',
|
| - 'DOMString': '{v8_value}',
|
| - 'ByteString': 'toByteString({isolate}, {arguments})',
|
| - 'USVString': 'toUSVString({isolate}, {arguments})',
|
| - 'boolean': 'toBoolean({isolate}, {arguments})',
|
| - 'float': 'toRestrictedFloat({isolate}, {arguments})',
|
| - 'unrestricted float': 'toFloat({isolate}, {arguments})',
|
| - 'double': 'toRestrictedDouble({isolate}, {arguments})',
|
| - 'unrestricted double': 'toDouble({isolate}, {arguments})',
|
| - 'byte': 'toInt8({isolate}, {arguments})',
|
| - 'octet': 'toUInt8({isolate}, {arguments})',
|
| - 'short': 'toInt16({isolate}, {arguments})',
|
| - 'unsigned short': 'toUInt16({isolate}, {arguments})',
|
| - 'long': 'toInt32({isolate}, {arguments})',
|
| - 'unsigned long': 'toUInt32({isolate}, {arguments})',
|
| - 'long long': 'toInt64({isolate}, {arguments})',
|
| - 'unsigned long long': 'toUInt64({isolate}, {arguments})',
|
| # Interface types
|
| - 'Dictionary': 'Dictionary({isolate}, {v8_value}, exceptionState)',
|
| 'FlexibleArrayBufferView': 'toFlexibleArrayBufferView({isolate}, {v8_value}, {variable_name}, allocateFlexibleArrayBufferViewStorage({v8_value}))',
|
| 'NodeFilter': 'toNodeFilter({v8_value}, info.Holder(), ScriptState::current({isolate}))',
|
| - 'Promise': 'ScriptPromise::cast(ScriptState::current({isolate}), {v8_value})',
|
| - 'SerializedScriptValue': 'SerializedScriptValue::serialize({isolate}, {v8_value}, nullptr, nullptr, exceptionState)',
|
| - 'ScriptValue': 'ScriptValue(ScriptState::current({isolate}), {v8_value})',
|
| - 'Window': 'toDOMWindow({isolate}, {v8_value})',
|
| 'XPathNSResolver': 'toXPathNSResolver(ScriptState::current({isolate}), {v8_value})',
|
| }
|
|
|
| @@ -518,6 +487,7 @@ def v8_conversion_needs_exception_state(idl_type):
|
| return (idl_type.is_numeric_type or
|
| idl_type.is_enum or
|
| idl_type.is_dictionary or
|
| + idl_type.is_string_type or
|
| idl_type.name in ('Boolean', 'ByteString', 'Date', 'Dictionary', 'USVString', 'SerializedScriptValue'))
|
|
|
| IdlType.v8_conversion_needs_exception_state = property(v8_conversion_needs_exception_state)
|
| @@ -545,18 +515,38 @@ def v8_conversion_is_trivial(idl_type):
|
| IdlType.v8_conversion_is_trivial = property(v8_conversion_is_trivial)
|
|
|
|
|
| +def idl_type_name(idl_type):
|
| + idl_type = idl_type.preprocessed_type
|
| + if idl_type.native_array_element_type:
|
| + return 'idl::Sequence<%s>' % idl_type_name(idl_type.native_array_element_type)
|
| + elif idl_type.is_union_type:
|
| + return idl_type.as_union_type.name
|
| + elif idl_type.is_basic_type:
|
| + return 'idl::%s' % idl_type.name
|
| + elif idl_type.implemented_as is not None:
|
| + return idl_type.implemented_as
|
| + return idl_type.name
|
| +
|
| +
|
| def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name, index, isolate):
|
| if idl_type.name == 'void':
|
| return ''
|
|
|
| - # Array or sequence types
|
| - native_array_element_type = idl_type.native_array_element_type
|
| - if native_array_element_type:
|
| - return v8_value_to_cpp_value_array_or_sequence(native_array_element_type, v8_value, index, isolate)
|
| + def string_mode(idl_type):
|
| + if idl_type.is_nullable:
|
| + return 'TreatNullAndUndefinedAsNullString'
|
| + if extended_attributes.get('TreatNullAs') == 'EmptyString':
|
| + return 'TreatNullAsEmptyString'
|
| + if extended_attributes.get('TreatNullAs') == 'NullString':
|
| + return 'TreatNullAsNullString'
|
| + return 'DefaultMode'
|
|
|
| # Simple types
|
| idl_type = idl_type.preprocessed_type
|
| - base_idl_type = idl_type.as_union_type.name if idl_type.is_union_type else idl_type.base_type
|
| + if idl_type.is_union_type:
|
| + base_idl_type = idl_type.as_union_type.name
|
| + else:
|
| + base_idl_type = idl_type.base_type
|
|
|
| if 'FlexibleArrayBufferView' in extended_attributes:
|
| if base_idl_type not in TYPED_ARRAY_TYPES.union(set(['ArrayBufferView'])):
|
| @@ -569,53 +559,36 @@ def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name
|
| configuration = 'EnforceRange'
|
| elif 'Clamp' in extended_attributes:
|
| configuration = 'Clamp'
|
| - arguments = ', '.join([v8_value, configuration, 'exceptionState'])
|
| - elif idl_type.v8_conversion_needs_exception_state:
|
| - arguments = ', '.join([v8_value, 'exceptionState'])
|
| + arguments = ', '.join([v8_value, 'exceptionState', configuration])
|
| + elif idl_type.native_array_element_type:
|
| + # Index is None for setters, index (starting at 0) for method arguments,
|
| + # and is used to provide a human-readable exception message
|
| + if index is None:
|
| + index = 0 # special case, meaning "setter"
|
| + else:
|
| + index += 1 # human-readable index
|
| + arguments = ', '.join([v8_value, 'exceptionState', str(index)])
|
| else:
|
| - arguments = v8_value
|
| + arguments = ', '.join([v8_value, 'exceptionState'])
|
| +
|
| if base_idl_type in V8_VALUE_TO_CPP_VALUE:
|
| cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type]
|
| - elif idl_type.is_array_buffer_or_view:
|
| - cpp_expression_format = (
|
| - '{v8_value}->Is{idl_type}() ? '
|
| - 'V8{idl_type}::toImpl(v8::Local<v8::{idl_type}>::Cast({v8_value})) : 0')
|
| - elif idl_type.is_union_type:
|
| - nullable = 'UnionTypeConversionMode::Nullable' if idl_type.includes_nullable_type else 'UnionTypeConversionMode::NotNullable'
|
| - cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {variable_name}, %s, exceptionState)' % nullable
|
| - elif idl_type.use_output_parameter_for_result:
|
| - cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, {variable_name}, exceptionState)'
|
| - elif idl_type.is_callback_function:
|
| - cpp_expression_format = (
|
| - '{idl_type}::create(ScriptState::current({isolate}), {v8_value})')
|
| else:
|
| - cpp_expression_format = (
|
| - 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})')
|
| -
|
| - return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_type, v8_value=v8_value, variable_name=variable_name, isolate=isolate)
|
| + str_mode = string_mode(idl_type)
|
|
|
| + if idl_type.is_nullable:
|
| + idl_type = idl_type.inner_type
|
| + base_idl_type = idl_type_name(idl_type)
|
|
|
| -def v8_value_to_cpp_value_array_or_sequence(native_array_element_type, v8_value, index, isolate='info.GetIsolate()'):
|
| - # Index is None for setters, index (starting at 0) for method arguments,
|
| - # and is used to provide a human-readable exception message
|
| - if index is None:
|
| - index = 0 # special case, meaning "setter"
|
| - else:
|
| - index += 1 # human-readable index
|
| - if (native_array_element_type.is_interface_type and
|
| - native_array_element_type.name != 'Dictionary'):
|
| - this_cpp_type = None
|
| - expression_format = 'toMemberNativeArray<{native_array_element_type}>({v8_value}, {index}, {isolate}, exceptionState)'
|
| - else:
|
| - this_cpp_type = native_array_element_type.cpp_type
|
| - if native_array_element_type.is_dictionary or native_array_element_type.is_union_type:
|
| - vector_type = 'HeapVector'
|
| + if base_idl_type == 'idl::String':
|
| + nvt_args = '<%s>' % str_mode
|
| else:
|
| - vector_type = 'Vector'
|
| - expression_format = 'toImplArray<%s<{cpp_type}>>({v8_value}, {index}, {isolate}, exceptionState)' % vector_type
|
| - expression = expression_format.format(native_array_element_type=native_array_element_type.name, cpp_type=this_cpp_type,
|
| - index=index, v8_value=v8_value, isolate=isolate)
|
| - return expression
|
| + nvt_args = ''
|
| +
|
| + cpp_expression_format = (
|
| + 'NativeValueTraits<{idl_type}>::nativeValue%s({isolate}, {arguments})' % nvt_args)
|
| +
|
| + return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_type, v8_value=v8_value, variable_name=variable_name, isolate=isolate)
|
|
|
|
|
| # FIXME: this function should be refactored, as this takes too many flags.
|
| @@ -638,24 +611,10 @@ def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
|
| # meaningful if 'check_expression' is not None.
|
| return_expression = bailout_return_value
|
|
|
| - if idl_type.is_string_type or idl_type.v8_conversion_needs_exception_state:
|
| + if idl_type.v8_conversion_needs_exception_state:
|
| # Types for which conversion can fail and that need error handling.
|
| -
|
| check_expression = 'exceptionState.hadException()'
|
| -
|
| - if idl_type.is_dictionary or idl_type.is_union_type:
|
| - set_expression = cpp_value
|
| - else:
|
| - assign_expression = cpp_value
|
| - # Note: 'not idl_type.v8_conversion_needs_exception_state' implies
|
| - # 'idl_type.is_string_type', but there are types for which both are
|
| - # true (ByteString and USVString), so using idl_type.is_string_type
|
| - # as the condition here would be wrong.
|
| - if not idl_type.v8_conversion_needs_exception_state:
|
| - if use_exception_state:
|
| - check_expression = '!%s.prepare(exceptionState)' % variable_name
|
| - else:
|
| - check_expression = '!%s.prepare()' % variable_name
|
| + assign_expression = cpp_value
|
| elif not idl_type.v8_conversion_is_trivial and not idl_type.is_callback_function:
|
| return {
|
| 'error_message': 'no V8 -> C++ conversion for IDL type: %s' % idl_type.name
|
|
|