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

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

Issue 713683003: IDL: Support optional union type arguments with default values (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add unit tests Created 6 years, 1 month 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/idl_types.py
diff --git a/Source/bindings/scripts/idl_types.py b/Source/bindings/scripts/idl_types.py
index fa7d00b7f434737f3a2c60d5178752a41ac1962f..e4be490a95c46eb30a6161e8b1ed0453f7895ecf 100644
--- a/Source/bindings/scripts/idl_types.py
+++ b/Source/bindings/scripts/idl_types.py
@@ -273,6 +273,28 @@ class IdlUnionType(IdlTypeBase):
def is_union_type(self):
return True
+ def single_matching_member_type(self, predicate):
+ matching_types = filter(predicate, self.member_types)
+ if len(matching_types) > 1:
+ raise "%s is ambigious." % self.name
+ return matching_types[0] if matching_types else None
+
+ @property
+ def string_member_type(self):
+ return self.single_matching_member_type(
+ lambda member_type: (member_type.is_string_type or
+ member_type.is_enum))
+
+ @property
+ def numeric_member_type(self):
+ return self.single_matching_member_type(
+ lambda member_type: member_type.is_numeric_type)
+
+ @property
+ def boolean_member_type(self):
+ return self.single_matching_member_type(
+ lambda member_type: member_type.base_type == 'boolean')
+
@property
def as_union_type(self):
# Note: Use this to "look through" a possible IdlNullableType wrapper.

Powered by Google App Engine
This is Rietveld 408576698