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

Unified Diff: bindings/scripts/v8_types.py

Issue 959933002: Move IDLs to 39 roll (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bindings/scripts/v8_methods.py ('k') | bindings/scripts/v8_utilities.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bindings/scripts/v8_types.py
diff --git a/bindings/scripts/v8_types.py b/bindings/scripts/v8_types.py
index 1ee093ab1596acd2b799e5af022bb5d76bee6198..a332f4a0bbc5300c43e4ccb5d6e4fcb16fbe1539 100644
--- a/bindings/scripts/v8_types.py
+++ b/bindings/scripts/v8_types.py
@@ -39,7 +39,7 @@ Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
import posixpath
-from idl_types import IdlTypeBase, IdlType, IdlUnionType, IdlArrayOrSequenceType
+from idl_types import IdlTypeBase, IdlType, IdlUnionType, IdlArrayOrSequenceType, IdlNullableType
import v8_attributes # for IdlType.constructor_type_name
from v8_globals import includes
@@ -49,11 +49,9 @@ from v8_globals import includes
################################################################################
NON_WRAPPER_TYPES = frozenset([
- 'CompareHow',
'Dictionary',
'EventHandler',
'EventListener',
- 'MediaQueryListListener',
'NodeFilter',
'SerializedScriptValue',
])
@@ -72,12 +70,9 @@ TYPED_ARRAYS = {
'Uint32Array': ('unsigned int', 'v8::kExternalUnsignedIntArray'),
}
-IdlTypeBase.is_typed_array_element_type = False
IdlType.is_typed_array_element_type = property(
lambda self: self.base_type in TYPED_ARRAYS)
-
-IdlTypeBase.is_wrapper_type = False
IdlType.is_wrapper_type = property(
lambda self: (self.is_interface_type and
self.base_type not in NON_WRAPPER_TYPES))
@@ -105,11 +100,9 @@ CPP_UNSIGNED_TYPES = set([
'unsigned short',
])
CPP_SPECIAL_CONVERSION_RULES = {
- 'CompareHow': 'Range::CompareHow',
'Date': 'double',
'Dictionary': 'Dictionary',
'EventHandler': 'EventListener*',
- 'MediaQueryListListener': 'RefPtrWillBeRawPtr<MediaQueryListListener>',
'NodeFilter': 'RefPtrWillBeRawPtr<NodeFilter>',
'Promise': 'ScriptPromise',
'ScriptValue': 'ScriptValue',
@@ -203,13 +196,24 @@ def cpp_type_initializer(idl_type):
|idl_type| argument is of type IdlType.
"""
- if (idl_type.is_numeric_type):
+ base_idl_type = idl_type.base_type
+
+ if idl_type.native_array_element_type:
+ return ''
+ if idl_type.is_numeric_type:
return ' = 0'
- if idl_type.base_type == 'boolean':
+ if base_idl_type == 'boolean':
return ' = false'
if idl_type.base_type == 'Promise':
return '(nullptr)'
- return ''
+
+ if (base_idl_type in NON_WRAPPER_TYPES or
+ base_idl_type in CPP_SPECIAL_CONVERSION_RULES or
+ base_idl_type == 'any' or
+ idl_type.is_string_type or
+ idl_type.is_enum):
+ return ''
+ return ' = nullptr'
def cpp_type_union(idl_type, extended_attributes=None, raw_type=False):
@@ -231,7 +235,6 @@ IdlUnionType.cpp_type_initializer = property(cpp_type_initializer_union)
IdlUnionType.cpp_type_args = cpp_type_union
-IdlTypeBase.native_array_element_type = None
IdlArrayOrSequenceType.native_array_element_type = property(
lambda self: self.element_type)
@@ -287,7 +290,6 @@ IdlType.set_implemented_as_interfaces = classmethod(
# [GarbageCollected]
IdlType.garbage_collected_types = set()
-IdlTypeBase.is_garbage_collected = False
IdlType.is_garbage_collected = property(
lambda self: self.base_type in IdlType.garbage_collected_types)
@@ -299,7 +301,6 @@ IdlType.set_garbage_collected_types = classmethod(
# [WillBeGarbageCollected]
IdlType.will_be_garbage_collected_types = set()
-IdlTypeBase.is_will_be_garbage_collected = False
IdlType.is_will_be_garbage_collected = property(
lambda self: self.base_type in IdlType.will_be_garbage_collected_types)
@@ -328,7 +329,6 @@ def includes_for_cpp_class(class_name, relative_dir_posix):
INCLUDES_FOR_TYPE = {
'object': set(),
- 'CompareHow': set(),
'Dictionary': set(['bindings/core/v8/Dictionary.h']),
'EventHandler': set(['bindings/core/v8/V8AbstractEventListener.h',
'bindings/core/v8/V8EventListenerList.h']),
@@ -339,9 +339,9 @@ INCLUDES_FOR_TYPE = {
'core/dom/ClassCollection.h',
'core/dom/TagCollection.h',
'core/html/HTMLCollection.h',
+ 'core/html/HTMLDataListOptionsCollection.h',
'core/html/HTMLFormControlsCollection.h',
'core/html/HTMLTableRowsCollection.h']),
- 'MediaQueryListListener': set(['core/css/MediaQueryListListener.h']),
'NodeList': set(['bindings/core/v8/V8NodeList.h',
'core/dom/NameNodeList.h',
'core/dom/NodeList.h',
@@ -381,7 +381,7 @@ def includes_for_type(idl_type):
IdlType.includes_for_type = property(includes_for_type)
IdlUnionType.includes_for_type = property(
- lambda self: set.union(*[includes_for_type(member_type)
+ lambda self: set.union(*[member_type.includes_for_type
for member_type in self.member_types]))
IdlArrayOrSequenceType.includes_for_type = property(
lambda self: self.element_type.includes_for_type)
@@ -420,11 +420,14 @@ def impl_includes_for_type(idl_type, interfaces_info):
native_array_element_type, interfaces_info))
includes_for_type.add('wtf/Vector.h')
+ base_idl_type = idl_type.base_type
if idl_type.is_string_type:
includes_for_type.add('wtf/text/WTFString.h')
- if idl_type.name in interfaces_info:
- interface_info = interfaces_info[idl_type.name]
+ if base_idl_type in interfaces_info:
+ interface_info = interfaces_info[idl_type.base_type]
includes_for_type.add(interface_info['include_path'])
+ if base_idl_type in INCLUDES_FOR_TYPE:
+ includes_for_type.update(INCLUDES_FOR_TYPE[base_idl_type])
return includes_for_type
IdlTypeBase.impl_includes_for_type = impl_includes_for_type
@@ -448,10 +451,10 @@ V8_VALUE_TO_CPP_VALUE = {
'ByteString': 'toByteString({arguments})',
'ScalarValueString': 'toScalarValueString({arguments})',
'boolean': '{v8_value}->BooleanValue()',
- 'float': 'static_cast<float>({v8_value}->NumberValue())',
- 'unrestricted float': 'static_cast<float>({v8_value}->NumberValue())',
- 'double': 'static_cast<double>({v8_value}->NumberValue())',
- 'unrestricted double': 'static_cast<double>({v8_value}->NumberValue())',
+ 'float': 'toFloat({arguments})',
+ 'unrestricted float': 'toFloat({arguments})',
+ 'double': 'toDouble({arguments})',
+ 'unrestricted double': 'toDouble({arguments})',
'byte': 'toInt8({arguments})',
'octet': 'toUInt8({arguments})',
'short': 'toInt16({arguments})',
@@ -461,19 +464,46 @@ V8_VALUE_TO_CPP_VALUE = {
'long long': 'toInt64({arguments})',
'unsigned long long': 'toUInt64({arguments})',
# Interface types
- 'CompareHow': 'static_cast<Range::CompareHow>({v8_value}->Int32Value())',
'Dictionary': 'Dictionary({v8_value}, {isolate})',
'EventTarget': 'V8DOMWrapper::isDOMWrapper({v8_value}) ? toWrapperTypeInfo(v8::Handle<v8::Object>::Cast({v8_value}))->toEventTarget(v8::Handle<v8::Object>::Cast({v8_value})) : 0',
- 'MediaQueryListListener': 'MediaQueryListListener::create(V8ScriptState::current({isolate}), ScriptValue(V8ScriptState::current({isolate}), {v8_value}))',
'NodeFilter': 'toNodeFilter({v8_value}, info.Holder(), V8ScriptState::current({isolate}))',
'Promise': 'V8ScriptPromise::cast(V8ScriptState::current({isolate}), {v8_value})',
- 'SerializedScriptValue': 'SerializedScriptValue::create({v8_value}, {isolate})',
+ 'SerializedScriptValue': 'SerializedScriptValue::create({v8_value}, 0, 0, exceptionState, {isolate})',
'ScriptValue': 'ScriptValue(V8ScriptState::current({isolate}), {v8_value})',
'Window': 'toDOMWindow({v8_value}, {isolate})',
'XPathNSResolver': 'toXPathNSResolver({v8_value}, {isolate})',
}
+def v8_conversion_needs_exception_state(idl_type):
+ return (idl_type.is_numeric_type or
+ idl_type.is_dictionary or
+ idl_type.name in ('ByteString', 'ScalarValueString', 'SerializedScriptValue'))
+
+IdlType.v8_conversion_needs_exception_state = property(v8_conversion_needs_exception_state)
+IdlArrayOrSequenceType.v8_conversion_needs_exception_state = True
+
+
+TRIVIAL_CONVERSIONS = frozenset([
+ 'any',
+ 'boolean',
+ 'Date',
+ 'Dictionary',
+ 'NodeFilter',
+ 'XPathNSResolver',
+ 'Promise'
+])
+
+
+def v8_conversion_is_trivial(idl_type):
+ # The conversion is a simple expression that returns the converted value and
+ # cannot raise an exception.
+ return (idl_type.base_type in TRIVIAL_CONVERSIONS or
+ idl_type.is_wrapper_type)
+
+IdlType.v8_conversion_is_trivial = property(v8_conversion_is_trivial)
+
+
def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index, isolate):
if idl_type.name == 'void':
return ''
@@ -490,7 +520,9 @@ def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index, isolat
if 'EnforceRange' in extended_attributes:
arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState'])
- elif idl_type.may_raise_exception_on_conversion:
+ elif 'Clamp' in extended_attributes:
+ arguments = ', '.join([v8_value, 'Clamp', 'exceptionState'])
+ elif idl_type.v8_conversion_needs_exception_state:
arguments = ', '.join([v8_value, 'exceptionState'])
else:
arguments = v8_value
@@ -500,12 +532,12 @@ def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index, isolat
elif idl_type.is_typed_array_element_type:
cpp_expression_format = (
'{v8_value}->Is{idl_type}() ? '
- 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value})) : 0')
+ 'V8{idl_type}::toImpl(v8::Handle<v8::{idl_type}>::Cast({v8_value})) : 0')
elif idl_type.is_dictionary:
- cpp_expression_format = 'V8{idl_type}::toNative({isolate}, {v8_value})'
+ cpp_expression_format = 'V8{idl_type}::toImpl({isolate}, {v8_value}, exceptionState)'
else:
cpp_expression_format = (
- 'V8{idl_type}::toNativeWithTypeCheck({isolate}, {v8_value})')
+ 'V8{idl_type}::toImplWithTypeCheck({isolate}, {v8_value})')
return cpp_expression_format.format(arguments=arguments, idl_type=base_idl_type, v8_value=v8_value, isolate=isolate)
@@ -521,12 +553,12 @@ def v8_value_to_cpp_value_array_or_sequence(native_array_element_type, v8_value,
native_array_element_type.name != 'Dictionary'):
this_cpp_type = None
ref_ptr_type = cpp_ptr_type('RefPtr', 'Member', native_array_element_type.gc_type)
- expression_format = '(to{ref_ptr_type}NativeArray<{native_array_element_type}, V8{native_array_element_type}>({v8_value}, {index}, {isolate}))'
+ expression_format = '(to{ref_ptr_type}NativeArray<{native_array_element_type}, V8{native_array_element_type}>({v8_value}, {index}, {isolate}, exceptionState))'
add_includes_for_type(native_array_element_type)
else:
ref_ptr_type = None
this_cpp_type = native_array_element_type.cpp_type
- expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, {isolate})'
+ expression_format = 'toImplArray<{cpp_type}>({v8_value}, {index}, {isolate}, exceptionState)'
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_type, v8_value=v8_value, isolate=isolate)
return expression
@@ -536,40 +568,60 @@ def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl
# FIXME: Support union type.
if idl_type.is_union_type:
- return ''
+ return '/* no V8 -> C++ conversion for IDL union type: %s */' % idl_type.name
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
+
cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index, isolate)
- args = [variable_name, cpp_value]
- if idl_type.base_type == 'DOMString':
- macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_VOID'
- elif idl_type.may_raise_exception_on_conversion:
- macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE'
- args.append('exceptionState')
- else:
- macro = 'TONATIVE_DEFAULT' if used_in_private_script else 'TONATIVE_VOID'
+ 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.
- if used_in_private_script:
- args.append('false')
+ args = [variable_name, cpp_value]
- # Macros come in several variants, to minimize expensive creation of
- # v8::TryCatch.
- suffix = ''
+ if idl_type.v8_conversion_needs_exception_state:
+ macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE'
+ elif return_promise:
+ macro = 'TOSTRING_VOID_EXCEPTIONSTATE'
+ else:
+ macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_VOID'
- if return_promise:
- suffix += '_PROMISE'
- args.append('info')
- if macro == 'TONATIVE_VOID_EXCEPTIONSTATE':
- args.append('V8ScriptState::current(%s)' % isolate)
+ 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('V8ScriptState::current(%s)' % isolate)
+
+ if declare_variable:
+ args.insert(0, this_cpp_type)
+ else:
+ suffix += '_INTERNAL'
+
+ return '%s(%s)' % (macro + suffix, ', '.join(args))
+
+ # 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:
- args.insert(0, this_cpp_type)
- else:
- suffix += '_INTERNAL'
+ return '%s %s' % (this_cpp_type, assignment)
+ return assignment
- return '%s(%s)' % (macro + suffix, ', '.join(args))
IdlTypeBase.v8_value_to_local_cpp_value = v8_value_to_local_cpp_value
@@ -582,7 +634,7 @@ def preprocess_idl_type(idl_type):
if idl_type.is_enum:
# Enumerations are internally DOMStrings
return IdlType('DOMString')
- if (idl_type.name == 'Any' or idl_type.is_callback_function):
+ if (idl_type.name in ['Any', 'Object'] or idl_type.is_callback_function):
return IdlType('ScriptValue')
return idl_type
@@ -597,7 +649,10 @@ def preprocess_idl_type_and_value(idl_type, cpp_value, extended_attributes):
if idl_type.base_type in ['long long', 'unsigned long long']:
# long long and unsigned long long are not representable in ECMAScript;
# we represent them as doubles.
- idl_type = IdlType('double', is_nullable=idl_type.is_nullable)
+ is_nullable = idl_type.is_nullable
+ idl_type = IdlType('double')
+ if is_nullable:
+ idl_type = IdlNullableType(idl_type)
cpp_value = 'static_cast<double>(%s)' % cpp_value
# HTML5 says that unsigned reflected attributes should be in the range
# [0, 2^31). When a value isn't in this range, a default value (or 0)
@@ -734,7 +789,6 @@ IdlType.release = property(lambda self: self.is_interface_type)
IdlUnionType.release = property(
lambda self: [member_type.is_interface_type
for member_type in self.member_types])
-IdlArrayOrSequenceType.release = False
CPP_VALUE_TO_V8_VALUE = {
@@ -795,9 +849,14 @@ IdlType.literal_cpp_value = literal_cpp_value
def cpp_type_has_null_value(idl_type):
# - String types (String/AtomicString) represent null as a null string,
# i.e. one for which String::isNull() returns true.
+ # - Enum types, as they are implemented as Strings.
# - Wrapper types (raw pointer or RefPtr/PassRefPtr) represent null as
# a null pointer.
- return idl_type.is_string_type or idl_type.is_wrapper_type
+ # - Dictionary types represent null as a null pointer. They are garbage
+ # collected so their type is raw pointer.
+ # - 'Object' type. We use ScriptValue for object type.
+ return (idl_type.is_string_type or idl_type.is_wrapper_type or
+ idl_type.is_enum or idl_type.is_dictionary or idl_type.base_type == 'object')
IdlTypeBase.cpp_type_has_null_value = property(cpp_type_has_null_value)
« no previous file with comments | « bindings/scripts/v8_methods.py ('k') | bindings/scripts/v8_utilities.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698