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

Unified Diff: third_party/WebKit/Source/bindings/scripts/v8_types.py

Issue 2709983004: WIP bindings: Add support for the record<K,V> WebIDL type. (Closed)
Patch Set: Rebased patch using NativeValueTraits for IDL types Created 3 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
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..0a690946bc7fa8d03e52db276bc87dad7425a334 100644
--- a/third_party/WebKit/Source/bindings/scripts/v8_types.py
+++ b/third_party/WebKit/Source/bindings/scripts/v8_types.py
@@ -41,7 +41,12 @@ Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
import posixpath
-from idl_types import IdlTypeBase, IdlType, IdlUnionType, IdlArrayOrSequenceType, IdlNullableType
+from idl_types import IdlArrayOrSequenceType
+from idl_types import IdlNullableType
+from idl_types import IdlRecordType
+from idl_types import IdlType
+from idl_types import IdlTypeBase
+from idl_types import IdlUnionType
import v8_attributes # for IdlType.constructor_type_name
from v8_globals import includes
from v8_utilities import extended_attribute_value_contains
@@ -143,7 +148,7 @@ def cpp_type(idl_type, extended_attributes=None, raw_type=False, used_as_rvalue_
bool, True if the C++ type is used as a variadic argument of a method.
used_in_cpp_sequence:
bool, True if the C++ type is used as an element of a container.
- Containers can be an array, a sequence or a dictionary.
+ Containers can be an array, a sequence, a dictionary or a record.
"""
def string_mode():
if idl_type.is_nullable:
@@ -169,6 +174,16 @@ def cpp_type(idl_type, extended_attributes=None, raw_type=False, used_as_rvalue_
return 'const %s&' % vector_template_type
return vector_template_type
+ # Record types.
+ if idl_type.is_record_type:
+ vector_type = cpp_ptr_type('Vector', 'HeapVector', idl_type.value_type.is_gc_type)
+ value_type = idl_type.value_type.cpp_type_args(used_in_cpp_sequence=True)
+ vector_template_type = cpp_template_type(vector_type,
+ 'std::pair<String, %s>' % value_type)
+ if used_as_rvalue_type:
+ return 'const %s&' % vector_template_type
+ return vector_template_type
+
# Simple types
base_idl_type = idl_type.base_type
@@ -322,6 +337,8 @@ IdlTypeBase.is_traceable = property(is_traceable)
IdlUnionType.is_traceable = property(lambda self: True)
IdlArrayOrSequenceType.is_traceable = property(
lambda self: self.element_type.is_traceable)
+IdlRecordType.is_traceable = property(
+ lambda self: self.value_type.is_traceable)
################################################################################
@@ -411,6 +428,14 @@ def includes_for_array_or_sequence_type(idl_type, extended_attributes=None):
IdlArrayOrSequenceType.includes_for_type = includes_for_array_or_sequence_type
+def includes_for_record_type(idl_type, extended_attributes=None):
+ return set.union(set(['bindings/core/v8/IDLTypes.h']),
+ idl_type.key_type.includes_for_type(extended_attributes),
+ idl_type.value_type.includes_for_type(extended_attributes))
+
+IdlRecordType.includes_for_type = includes_for_record_type
+
+
def add_includes_for_type(idl_type, extended_attributes=None):
includes.update(idl_type.includes_for_type(extended_attributes))
@@ -522,6 +547,7 @@ def v8_conversion_needs_exception_state(idl_type):
IdlType.v8_conversion_needs_exception_state = property(v8_conversion_needs_exception_state)
IdlArrayOrSequenceType.v8_conversion_needs_exception_state = True
+IdlRecordType.v8_conversion_needs_exception_state = True
IdlUnionType.v8_conversion_needs_exception_state = True
@@ -580,6 +606,34 @@ def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name
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_record_type:
+ # This function is not record-specific, but for now we are using
+ # NativeValueTraits<> and the idl:: types only with this IDL type.
+ 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_record_type:
+ return 'idl::Record<%s, %s>' % (idl_type_name(idl_type.key_type),
+ idl_type_name(idl_type.value_type))
+ elif idl_type.is_union_type:
+ return idl_type.as_union_type.name
+ elif idl_type.is_basic_type or idl_type.name == 'Promise':
+ return 'idl::%s' % idl_type.name
+ elif idl_type.implemented_as is not None:
+ return idl_type.implemented_as
+ return idl_type.name
+
+ if idl_type.is_nullable:
+ type_name = idl_type.inner_type.name
+ else:
+ type_name = idl_type.name
+
+ k = idl_type_name(idl_type.key_type)
+ v = idl_type_name(idl_type.value_type)
+
+ cpp_expression_format = (
+ 'NativeValueTraits<idl::Record<%s, %s>>::nativeValue({isolate}, {v8_value}, exceptionState)' % (k, v))
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
@@ -759,6 +813,10 @@ def v8_conversion_type(idl_type, extended_attributes):
if native_array_element_type:
return 'FrozenArray' if idl_type.is_frozen_array else 'array'
+ # Record types.
+ if idl_type.is_record_type:
+ return 'Record'
+
# Simple types
base_idl_type = idl_type.base_type
# Basic types, without additional includes
@@ -808,6 +866,8 @@ V8_SET_RETURN_VALUE = {
'EventHandler': 'v8SetReturnValue(info, {cpp_value})',
'ScriptValue': 'v8SetReturnValue(info, {cpp_value})',
'SerializedScriptValue': 'v8SetReturnValue(info, {cpp_value})',
+ # Records.
+ 'Record': 'v8SetReturnValue(info, ToV8({cpp_value}, info.Holder(), info.GetIsolate()))',
# DOMWrapper
'DOMWrapperForMainWorld': 'v8SetReturnValueForMainWorld(info, {cpp_value})',
'DOMWrapperFast': 'v8SetReturnValueFast(info, {cpp_value}, {script_wrappable})',
@@ -902,6 +962,7 @@ CPP_VALUE_TO_V8_VALUE = {
'V8AbstractEventListener::cast({cpp_value})->getListenerOrNull(' +
'{isolate}, impl->getExecutionContext()) : ' +
'v8::Null({isolate}).As<v8::Value>()'),
+ 'Record': 'ToV8({cpp_value}, {creation_context}, {isolate})',
'ScriptValue': '{cpp_value}.v8Value()',
'SerializedScriptValue': 'v8Deserialize({isolate}, {cpp_value})',
# General

Powered by Google App Engine
This is Rietveld 408576698