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

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

Issue 2746713003: bindings: Add support for nested union types (Closed)
Patch Set: Improve documentation Created 3 years, 9 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 | « no previous file | third_party/WebKit/Source/bindings/scripts/idl_types_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/bindings/scripts/idl_types.py
diff --git a/third_party/WebKit/Source/bindings/scripts/idl_types.py b/third_party/WebKit/Source/bindings/scripts/idl_types.py
index 5cb0a791a791c93c2971681a3b9c783e01adef4b..dbfb3e95873eef19a8ae11da55759b312fd45cae 100644
--- a/third_party/WebKit/Source/bindings/scripts/idl_types.py
+++ b/third_party/WebKit/Source/bindings/scripts/idl_types.py
@@ -298,11 +298,37 @@ class IdlUnionType(IdlTypeBase):
self.member_types = state['member_types']
@property
+ def flattened_member_types(self):
+ """Returns the set of the union's flattened member types.
+
+ https://heycam.github.io/webidl/#dfn-flattened-union-member-types
+ """
+ # We cannot use a set directly because each member is an IdlTypeBase-derived class, and
+ # comparing two objects of the same type is not the same as comparing their names. In
+ # other words:
+ # x = IdlType('ByteString')
+ # y = IdlType('ByteString')
+ # x == y # False
+ # x.name == y.name # True
+ # |flattened_members|'s keys are type names, the values are type |objects.
+ # We assume we can use two IDL objects of the same type interchangeably.
+ flattened_members = {}
+ for member in self.member_types:
+ if member.is_nullable:
+ member = member.inner_type
+ if member.is_union_type:
+ for inner_member in member.flattened_member_types:
+ flattened_members[inner_member.name] = inner_member
+ else:
+ flattened_members[member.name] = member
+ return set(flattened_members.values())
+
+ @property
def is_union_type(self):
return True
def single_matching_member_type(self, predicate):
- matching_types = filter(predicate, self.member_types)
+ matching_types = filter(predicate, self.flattened_member_types)
if len(matching_types) > 1:
raise "%s is ambigious." % self.name
return matching_types[0] if matching_types else None
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/idl_types_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698