Chromium Code Reviews| Index: Source/bindings/scripts/idl_definitions.py |
| diff --git a/Source/bindings/scripts/idl_definitions.py b/Source/bindings/scripts/idl_definitions.py |
| index 50664ba12ef7addd5cb3cbc69484e0629231ba3d..45428e6883bc08b16567d95a85818401d9ca2f7e 100644 |
| --- a/Source/bindings/scripts/idl_definitions.py |
| +++ b/Source/bindings/scripts/idl_definitions.py |
| @@ -48,8 +48,10 @@ IdlDefinitions |
| IdlInterface |
| IdlAttribute < TypedObject |
| IdlConstant < TypedObject |
| + IdlLiteral |
| IdlOperation < TypedObject |
| IdlArgument < TypedObject |
| + IdlStringifier |
| IdlException < IdlInterface |
| (same contents as IdlInterface) |
| @@ -261,6 +263,7 @@ class IdlInterface(object): |
| self.extended_attributes = {} |
| self.operations = [] |
| self.parent = None |
| + self.stringifier = None |
| if not node: # Early exit for IdlException.__init__ |
| return |
| @@ -287,6 +290,9 @@ class IdlInterface(object): |
| self.operations.append(IdlOperation(child)) |
| elif child_class == 'Inherit': |
| self.parent = child.GetName() |
| + elif child_class == 'Stringifier': |
| + self.stringifier = IdlStringifier(child) |
| + self.process_stringifier() |
| else: |
| raise ValueError('Unrecognized node class: %s' % child_class) |
| @@ -302,6 +308,17 @@ class IdlInterface(object): |
| for operation in self.operations: |
| operation.resolve_typedefs(typedefs) |
| + def process_stringifier(self): |
| + """Add the stringifier's synthesized 'toString' operation. |
| + |
| + Also add the stringifier's attribute or named operation child, if it has |
| + one, as a regular attribute/operation of this interface.""" |
| + if self.stringifier.attribute: |
| + self.attributes.append(self.stringifier.attribute) |
| + elif self.stringifier.operation and self.stringifier.operation.name: |
| + self.operations.append(self.stringifier.operation) |
| + self.operations.append(self.stringifier.synthesized_operation()) |
| + |
| def merge(self, other): |
| """Merge in another interface's members (e.g., partial interface)""" |
| self.attributes.extend(other.attributes) |
| @@ -562,6 +579,46 @@ def arguments_node_to_arguments(node): |
| ################################################################################ |
| +# Stringifiers |
| +################################################################################ |
| + |
| +class IdlStringifier(object): |
| + def __init__(self, node): |
| + self.attribute = None |
| + self.operation = None |
| + self.extended_attributes = {} |
| + |
| + for child in node.GetChildren(): |
| + child_class = child.GetClass() |
| + if child_class == 'Attribute': |
| + self.attribute = IdlAttribute(child) |
| + elif child_class == 'Operation': |
| + self.operation = IdlOperation(child) |
| + elif child_class == 'ExtAttributes': |
| + self.extended_attributes = ext_attributes_node_to_extended_attributes(child) |
| + else: |
| + raise ValueError('Unrecognized node class: %s' % child_class) |
| + |
| + # Copy the stringifier's extended attributes (such as [Unforgable]) onto |
| + # the underlying attribute or operation, if there is one. |
| + if self.attribute or self.operation: |
| + (self.attribute or self.operation).extended_attributes.update( |
| + self.extended_attributes) |
| + |
| + def synthesized_operation(self): |
| + """Return a synthesized 'toString' operation from the stringifier.""" |
|
Jens Widell
2014/06/23 14:08:07
I don't know if we think this is too much logic to
haraken
2014/06/23 16:33:18
Yeah, this looks like a bit too much logic in idl_
Jens Widell
2014/06/24 08:00:29
Moved this code into interface_context() in v8_int
|
| + operation = IdlOperation() |
| + operation.name = 'toString' |
| + operation.idl_type = IdlType('DOMString') |
| + operation.extended_attributes.update(self.extended_attributes) |
| + if self.attribute: |
| + operation.extended_attributes['ImplementedAs'] = self.attribute.name |
| + elif self.operation and self.operation.name: |
| + operation.extended_attributes['ImplementedAs'] = self.operation.name |
| + return operation |
| + |
| + |
| +################################################################################ |
| # Extended attributes |
| ################################################################################ |