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

Unified Diff: Source/bindings/scripts/v8_union.py

Issue 680193003: IDL: Generate union type containers (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 side-by-side diff with in-line comments
Download patch
Index: Source/bindings/scripts/v8_union.py
diff --git a/Source/bindings/scripts/v8_union.py b/Source/bindings/scripts/v8_union.py
index 994deb70f1c801390f944db5192e12c31f6aeabd..fab726e59ebf04553547ce817cb35ad7512580e8 100644
--- a/Source/bindings/scripts/v8_union.py
+++ b/Source/bindings/scripts/v8_union.py
@@ -2,15 +2,90 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import v8_utilities
-def union_context(union_types):
+
+UNION_H_INCLUDES = frozenset([
+ 'bindings/core/v8/ExceptionState.h',
+ 'bindings/core/v8/V8Binding.h',
+ 'platform/heap/Handle.h',
+])
+
+cpp_includes = set()
+header_forward_decls = set()
+
+
+def union_context(union_types, interfaces_info):
return {
- 'containers': [container_context(union_type)
+ 'containers': [container_context(union_type, interfaces_info)
for union_type in union_types],
+ 'cpp_includes': sorted(cpp_includes),
+ 'header_forward_decls': sorted(header_forward_decls),
+ 'header_includes': sorted(UNION_H_INCLUDES),
}
-def container_context(union_type):
+def container_context(union_type, interfaces_info):
+ members = []
+
+ # These variables refer to member contexts if the given union type has
+ # corresponding types. They are used for V8 -> impl conversion.
+ boolean_type = None
+ dictionary_type = None
+ interface_types = []
+ numeric_type = None
+ string_type = None
+ for member in union_type.member_types:
+ context = member_context(member, interfaces_info)
+ members.append(context)
+ if member.is_interface_type:
+ interface_types.append(context)
+ elif member.is_dictionary:
+ if dictionary_type:
+ raise Exception('%s is ambiguous.' % union_type.name)
+ dictionary_type = context
+ elif member.base_type == 'boolean':
+ if boolean_type:
+ raise Exception('%s is ambiguous.' % union_type.name)
+ boolean_type = context
+ elif member.is_numeric_type:
+ if numeric_type:
+ raise Exception('%s is ambiguous.' % union_type.name)
+ numeric_type = context
+ elif member.is_string_type:
+ if string_type:
+ raise Exception('%s is ambiguous.' % union_type.name)
+ string_type = context
+ else:
+ raise Exception('%s is not supported as an union member.' % member.name)
+
return {
+ 'boolean_type': boolean_type,
'cpp_class': union_type.name,
+ 'dictionary_type': dictionary_type,
+ 'interface_types': interface_types,
+ 'members': members,
+ 'numeric_type': numeric_type,
+ 'string_type': string_type,
+ }
+
+
+def member_context(member, interfaces_info):
+ cpp_includes.update(member.includes_for_type)
+ interface_info = interfaces_info.get(member.name, None)
+ if interface_info:
+ cpp_includes.update(interface_info.get('dependencies_include_paths', []))
+ header_forward_decls.add(member.name)
+ return {
+ 'cpp_name': v8_utilities.uncapitalize(member.name),
+ 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True),
+ 'cpp_local_type': member.cpp_type,
+ 'cpp_value_to_v8_value': member.cpp_value_to_v8_value(
+ cpp_value='impl.getAs%s()' % member.name, isolate='isolate',
+ creation_context='creationContext'),
+ 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True),
+ 'specific_type_enum': 'SpecificType' + member.name,
+ 'type_name': member.name,
+ 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value(
+ {}, 'v8Value', 'cppValue', needs_exception_state_for_string=True),
}

Powered by Google App Engine
This is Rietveld 408576698