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

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

Issue 312683005: IDL: Support optional argument default value syntax (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 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/idl_definitions.py
diff --git a/Source/bindings/scripts/idl_definitions.py b/Source/bindings/scripts/idl_definitions.py
index 2230c8f6e207153d8145a7d7dca1560077f1bf7b..7df366c7c34748a3c3476df947a271b5afa6e6f0 100644
--- a/Source/bindings/scripts/idl_definitions.py
+++ b/Source/bindings/scripts/idl_definitions.py
@@ -475,6 +475,7 @@ class IdlArgument(TypedObject):
self.is_optional = node.GetProperty('OPTIONAL') # syntax: (optional T)
self.is_variadic = False # syntax: (T...)
self.name = node.GetName()
+ self.default_value = None
children = node.GetChildren()
for child in children:
@@ -488,6 +489,8 @@ class IdlArgument(TypedObject):
if child_name != '...':
raise ValueError('Unrecognized Argument node; expected "...", got "%s"' % child_name)
self.is_variadic = child.GetProperty('ELLIPSIS') or False
+ elif child_class == 'Default':
+ self.default_value = IdlDefaultValue(child)
else:
raise ValueError('Unrecognized node class: %s' % child_class)
@@ -503,6 +506,23 @@ def arguments_node_to_arguments(node):
for argument_node in node.GetChildren()]
+class IdlDefaultValue(TypedObject):
Nils Barth (inactive) 2014/06/04 05:22:24 You don't need TypedObject here I don't think: Typ
+ def __init__(self, node):
+ self.value_type = node.GetProperty('TYPE')
Nils Barth (inactive) 2014/06/04 05:22:24 Naming: idl_type, rather than value_type. (might n
+ if self.value_type == 'DOMString':
Nils Barth (inactive) 2014/06/04 05:22:24 Could you factor out this evaluation into a functi
+ self.value = node.GetProperty('NAME')
+ elif self.value_type == 'integer':
+ self.value = eval(node.GetProperty('NAME'))
Nils Barth (inactive) 2014/06/04 05:22:24 !!! Could you please use constructors int() and fl
Jens Widell 2014/06/04 06:12:18 Using eval() here is clearly ridiculous. Sorry abo
Nils Barth (inactive) 2014/06/04 06:33:35 n/p, that makes sense -- I was wondering what exac
+ elif self.value_type == 'float':
+ self.value = eval(node.GetProperty('VALUE'))
Nils Barth (inactive) 2014/06/04 05:22:24 Could you add a FIXME for the irregular upstream t
+ elif self.value_type == 'boolean':
+ self.value = node.GetProperty('VALUE')
+ elif self.value_type == 'NULL':
Nils Barth (inactive) 2014/06/04 05:22:24 Handling null and undefined will be a bit ugly. We
+ self.value = None
+ else:
+ raise ValueError('Unrecognized default value type: %s' % self.value_type)
+
+
################################################################################
# Extended attributes
################################################################################

Powered by Google App Engine
This is Rietveld 408576698