diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/bindings/scripts/web_idl/interface.py')
-rw-r--r-- | chromium/third_party/blink/renderer/bindings/scripts/web_idl/interface.py | 351 |
1 files changed, 256 insertions, 95 deletions
diff --git a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/interface.py b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/interface.py index f3f81408a0e..ae67aab3fc9 100644 --- a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/interface.py +++ b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/interface.py @@ -9,6 +9,7 @@ from .composition_parts import WithComponent from .composition_parts import WithDebugInfo from .composition_parts import WithExposure from .composition_parts import WithExtendedAttributes +from .composition_parts import WithIdentifier from .composition_parts import WithOwner from .constant import Constant from .constructor import Constructor @@ -37,7 +38,9 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, attributes=None, constants=None, constructors=None, + named_constructors=None, operations=None, + indexed_and_named_properties=None, stringifier=None, iterable=None, maplike=None, @@ -52,7 +55,11 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, assert constants is None or isinstance(constants, (list, tuple)) assert constructors is None or isinstance(constructors, (list, tuple)) + assert named_constructors is None or isinstance( + named_constructors, (list, tuple)) assert operations is None or isinstance(operations, (list, tuple)) + assert indexed_and_named_properties is None or isinstance( + indexed_and_named_properties, IndexedAndNamedProperties.IR) assert stringifier is None or isinstance(stringifier, Stringifier.IR) assert iterable is None or isinstance(iterable, Iterable) @@ -62,6 +69,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, attributes = attributes or [] constants = constants or [] constructors = constructors or [] + named_constructors = named_constructors or [] operations = operations or [] assert all( isinstance(attribute, Attribute.IR) @@ -72,6 +80,9 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, isinstance(constructor, Constructor.IR) for constructor in constructors) assert all( + isinstance(named_constructor, Constructor.IR) + for named_constructor in named_constructors) + assert all( isinstance(operation, Operation.IR) for operation in operations) @@ -100,8 +111,13 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, self.constants = list(constants) self.constructors = list(constructors) self.constructor_groups = [] + self.named_constructors = list(named_constructors) + self.named_constructor_groups = [] self.operations = list(operations) self.operation_groups = [] + self.exposed_constructs = [] + self.legacy_window_aliases = [] + self.indexed_and_named_properties = indexed_and_named_properties self.stringifier = stringifier self.iterable = iterable self.maplike = maplike @@ -114,6 +130,8 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, yield constant for constructor in self.constructors: yield constructor + for named_constructor in self.named_constructors: + yield named_constructor for operation in self.operations: yield operation @@ -123,7 +141,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, ir = make_copy(ir) UserDefinedType.__init__(self, ir.identifier) - WithExtendedAttributes.__init__(self, ir) + WithExtendedAttributes.__init__(self, ir, readonly=True) WithCodeGeneratorInfo.__init__(self, ir, readonly=True) WithExposure.__init__(self, ir, readonly=True) WithComponent.__init__(self, ir, readonly=True) @@ -144,24 +162,43 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, ]) self._constructor_groups = tuple([ ConstructorGroup( - constructor_group_ir, - filter( - lambda x: x.identifier == constructor_group_ir.identifier, - self._constructors), - owner=self) for constructor_group_ir in ir.constructor_groups + group_ir, + filter(lambda x: x.identifier == group_ir.identifier, + self._constructors), + owner=self) for group_ir in ir.constructor_groups ]) assert len(self._constructor_groups) <= 1 + self._named_constructors = tuple([ + Constructor(named_constructor_ir, owner=self) + for named_constructor_ir in ir.named_constructors + ]) + self._named_constructor_groups = tuple([ + ConstructorGroup( + group_ir, + filter(lambda x: x.identifier == group_ir.identifier, + self._named_constructors), + owner=self) for group_ir in ir.named_constructor_groups + ]) self._operations = tuple([ Operation(operation_ir, owner=self) for operation_ir in ir.operations ]) self._operation_groups = tuple([ OperationGroup( - operation_group_ir, - filter(lambda x: x.identifier == operation_group_ir.identifier, + group_ir, + filter(lambda x: x.identifier == group_ir.identifier, self._operations), - owner=self) for operation_group_ir in ir.operation_groups + owner=self) for group_ir in ir.operation_groups ]) + self._exposed_constructs = tuple(ir.exposed_constructs) + self._legacy_window_aliases = tuple(ir.legacy_window_aliases) + self._indexed_and_named_properties = None + if ir.indexed_and_named_properties: + operations = filter( + lambda x: x.is_indexed_or_named_property_operation, + self._operations) + self._indexed_and_named_properties = IndexedAndNamedProperties( + ir.indexed_and_named_properties, operations, owner=self) self._stringifier = None if ir.stringifier: operations = filter(lambda x: x.is_stringifier, self._operations) @@ -205,6 +242,17 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, interface = interface.inherited return result + def does_implement(self, identifier): + """ + Returns True if this is or inherits from the given interface. + """ + assert isinstance(identifier, str) + + for interface in self.inclusive_inherited_interfaces: + if interface.identifier == identifier: + return True + return False + @property def attributes(self): """ @@ -232,6 +280,16 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, return self._constructor_groups @property + def named_constructors(self): + """Returns named constructors.""" + return self._named_constructors + + @property + def named_constructor_groups(self): + """Returns groups of overloaded named constructors.""" + return self._named_constructor_groups + + @property def operations(self): """ Returns all operations, including special operations without an @@ -254,38 +312,22 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, return self._operation_groups @property - def named_constructor(self): - """Returns a named constructor or None.""" - assert False, "Not implemented yet." - - @property - def exposed_interfaces(self): + def exposed_constructs(self): """ - Returns a tuple of interfaces that are exposed to this interface, if - this is a global interface. Returns None otherwise. + Returns a list of the constructs that are exposed on this global object. """ - assert False, "Not implemented yet." + return tuple( + map(lambda ref: ref.target_object, self._exposed_constructs)) - # Special operations @property - def indexed_property_handler(self): - """ - Returns a set of handlers (getter/setter/deleter) for the indexed - property. - @return IndexedPropertyHandler? - """ - # TODO: Include anonymous handlers of ancestors. https://crbug.com/695972 - assert False, "Not implemented yet." + def legacy_window_aliases(self): + """Returns a list of properties exposed as [LegacyWindowAlias].""" + return self._legacy_window_aliases @property - def named_property_handler(self): - """ - Returns a set of handlers (getter/setter/deleter) for the named - property. - @return NamedPropertyHandler? - """ - # TODO: Include anonymous handlers of ancestors. https://crbug.com/695972 - assert False, "Not implemented yet." + def indexed_and_named_properties(self): + """Returns a IndexedAndNamedProperties or None.""" + return self._indexed_and_named_properties @property def stringifier(self): @@ -313,6 +355,183 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, return True +class LegacyWindowAlias(WithIdentifier, WithExtendedAttributes, WithExposure): + """ + Represents a property exposed on a Window object as [LegacyWindowAlias]. + """ + + def __init__(self, identifier, original, extended_attributes, exposure): + assert isinstance(original, RefById) + + WithIdentifier.__init__(self, identifier) + WithExtendedAttributes.__init__( + self, extended_attributes, readonly=True) + WithExposure.__init__(self, exposure, readonly=True) + + self._original = original + + @property + def original(self): + """Returns the original object of this alias.""" + return self._original.target_object + + +class IndexedAndNamedProperties(WithOwner, WithDebugInfo): + """ + Represents a set of indexed/named getter/setter/deleter. + + https://heycam.github.io/webidl/#idl-indexed-properties + https://heycam.github.io/webidl/#idl-named-properties + """ + + class IR(WithDebugInfo): + def __init__(self, operations, debug_info=None): + assert isinstance(operations, (list, tuple)) + assert all( + isinstance(operation, Operation.IR) + for operation in operations) + + WithDebugInfo.__init__(self, debug_info) + + self.indexed_getter = None + self.indexed_setter = None + self.named_getter = None + self.named_setter = None + self.named_deleter = None + + for operation in operations: + arg1_type = operation.arguments[0].idl_type + if arg1_type.is_integer: + if operation.is_getter: + assert self.indexed_getter is None + self.indexed_getter = operation + elif operation.is_setter: + assert self.indexed_setter is None + self.indexed_setter = operation + else: + assert False + elif arg1_type.is_string: + if operation.is_getter: + assert self.named_getter is None + self.named_getter = operation + elif operation.is_setter: + assert self.named_setter is None + self.named_setter = operation + elif operation.is_deleter: + assert self.named_deleter is None + self.named_deleter = operation + else: + assert False + else: + assert False + + def __init__(self, ir, operations, owner): + assert isinstance(ir, IndexedAndNamedProperties.IR) + assert isinstance(operations, (list, tuple)) + assert all( + isinstance(operation, Operation) for operation in operations) + + WithOwner.__init__(self, owner) + WithDebugInfo.__init__(self, ir) + + self._own_indexed_getter = None + self._own_indexed_setter = None + self._own_named_getter = None + self._own_named_setter = None + self._own_named_deleter = None + + for operation in operations: + arg1_type = operation.arguments[0].idl_type + if arg1_type.is_integer: + if operation.is_getter: + assert self._own_indexed_getter is None + self._own_indexed_getter = operation + elif operation.is_setter: + assert self._own_indexed_setter is None + self._own_indexed_setter = operation + else: + assert False + elif arg1_type.is_string: + if operation.is_getter: + assert self._own_named_getter is None + self._own_named_getter = operation + elif operation.is_setter: + assert self._own_named_setter is None + self._own_named_setter = operation + elif operation.is_deleter: + assert self._own_named_deleter is None + self._own_named_deleter = operation + else: + assert False + else: + assert False + + @property + def has_indexed_properties(self): + return self.indexed_getter or self.indexed_setter + + @property + def has_named_properties(self): + return self.named_getter or self.named_setter or self.named_deleter + + @property + def is_named_property_enumerable(self): + named_getter = self.named_getter + return bool(named_getter + and 'NotEnumerable' not in named_getter.extended_attributes + and 'LegacyUnenumerableNamedProperties' not in self.owner. + extended_attributes) + + @property + def indexed_getter(self): + return self._find_accessor('own_indexed_getter') + + @property + def indexed_setter(self): + return self._find_accessor('own_indexed_setter') + + @property + def named_getter(self): + return self._find_accessor('own_named_getter') + + @property + def named_setter(self): + return self._find_accessor('own_named_setter') + + @property + def named_deleter(self): + return self._find_accessor('own_named_deleter') + + @property + def own_indexed_getter(self): + return self._own_indexed_getter + + @property + def own_indexed_setter(self): + return self._own_indexed_setter + + @property + def own_named_getter(self): + return self._own_named_getter + + @property + def own_named_setter(self): + return self._own_named_setter + + @property + def own_named_deleter(self): + return self._own_named_deleter + + def _find_accessor(self, attr): + for interface in self.owner.inclusive_inherited_interfaces: + props = interface.indexed_and_named_properties + if props: + accessor = getattr(props, attr) + if accessor: + return accessor + return None + + class Stringifier(WithOwner, WithDebugInfo): """https://heycam.github.io/webidl/#idl-stringifiers""" @@ -349,10 +568,7 @@ class Stringifier(WithOwner, WithDebugInfo): class Iterable(WithDebugInfo): """https://heycam.github.io/webidl/#idl-iterable""" - def __init__(self, - key_type=None, - value_type=None, - debug_info=None): + def __init__(self, key_type=None, value_type=None, debug_info=None): assert key_type is None or isinstance(key_type, IdlType) # iterable is declared in either form of # iterable<value_type> @@ -423,10 +639,7 @@ class Maplike(WithDebugInfo): class Setlike(WithDebugInfo): """https://heycam.github.io/webidl/#idl-setlike""" - def __init__(self, - value_type, - is_readonly=False, - debug_info=None): + def __init__(self, value_type, is_readonly=False, debug_info=None): assert isinstance(value_type, IdlType) assert isinstance(is_readonly, bool) @@ -450,55 +663,3 @@ class Setlike(WithDebugInfo): @return bool """ return self._is_readonly - - -class IndexedPropertyHandler(object): - @property - def getter(self): - """ - Returns an Operation for indexed property getter. - @return Operation? - """ - assert False, "Not implemented yet." - - @property - def setter(self): - """ - Returns an Operation for indexed property setter. - @return Operation? - """ - assert False, "Not implemented yet." - - @property - def deleter(self): - """ - Returns an Operation for indexed property deleter. - @return Operation? - """ - assert False, "Not implemented yet." - - -class NamedPropertyHandler(object): - @property - def getter(self): - """ - Returns an Operation for named property getter. - @return Operation? - """ - assert False, "Not implemented yet." - - @property - def setter(self): - """ - Returns an Operation for named property setter. - @return Operation? - """ - assert False, "Not implemented yet." - - @property - def deleter(self): - """ - Returns an Operation for named property deleter. - @return Operation? - """ - assert False, "Not implemented yet." |