aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/Configuration.py
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2016-07-28 18:41:30 -0400
committerJosh Matthews <josh@joshmatthews.net>2016-08-24 11:26:01 -0400
commit812a761abf9722985692684454e6418d737d7add (patch)
tree5cecae83b0ee9229a0ea3606f2306e9efbb7574a /components/script/dom/bindings/codegen/Configuration.py
parent34bb937aeea9a48b1b4d8dc7c49f375203be4e7e (diff)
downloadservo-812a761abf9722985692684454e6418d737d7add.tar.gz
servo-812a761abf9722985692684454e6418d737d7add.zip
Implement pair iterators in WebIDL interfaces.
Diffstat (limited to 'components/script/dom/bindings/codegen/Configuration.py')
-rw-r--r--components/script/dom/bindings/codegen/Configuration.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/components/script/dom/bindings/codegen/Configuration.py b/components/script/dom/bindings/codegen/Configuration.py
index fd005bc6e05..c8f92472618 100644
--- a/components/script/dom/bindings/codegen/Configuration.py
+++ b/components/script/dom/bindings/codegen/Configuration.py
@@ -89,6 +89,8 @@ class Configuration:
getter = lambda x: x.isGlobal()
elif key == 'isExposedConditionally':
getter = lambda x: x.interface.isExposedConditionally()
+ elif key == 'isIteratorInterface':
+ getter = lambda x: x.interface.isIteratorInterface()
else:
getter = lambda x: getattr(x, key)
curr = filter(lambda x: getter(x) == val, curr)
@@ -177,7 +179,19 @@ class Descriptor(DescriptorProvider):
# Read the desc, and fill in the relevant defaults.
ifaceName = self.interface.identifier.name
- typeName = desc.get('nativeType', ifaceName)
+ nativeTypeDefault = ifaceName
+
+ # For generated iterator interfaces for other iterable interfaces, we
+ # just use IterableIterator as the native type, templated on the
+ # nativeType of the iterable interface. That way we can have a
+ # templated implementation for all the duplicated iterator
+ # functionality.
+ if self.interface.isIteratorInterface():
+ itrName = self.interface.iterableInterface.identifier.name
+ itrDesc = self.getDescriptor(itrName)
+ nativeTypeDefault = iteratorNativeType(itrDesc)
+
+ typeName = desc.get('nativeType', nativeTypeDefault)
# Callback types do not use JS smart pointers, so we should not use the
# built-in rooting mechanisms for them.
@@ -193,7 +207,10 @@ class Descriptor(DescriptorProvider):
self.returnType = "Root<%s>" % typeName
self.argumentType = "&%s" % typeName
self.nativeType = "*const %s" % typeName
- pathDefault = 'dom::types::%s' % typeName
+ if self.interface.isIteratorInterface():
+ pathDefault = 'dom::bindings::iterable::IterableIterator'
+ else:
+ pathDefault = 'dom::types::%s' % typeName
self.concreteType = typeName
self.register = desc.get('register', True)
@@ -427,3 +444,10 @@ def getTypesFromCallback(callback):
types = [sig[0]] # Return type
types.extend(arg.type for arg in sig[1]) # Arguments
return types
+
+
+def iteratorNativeType(descriptor, infer=False):
+ assert descriptor.interface.isIterable()
+ iterableDecl = descriptor.interface.maplikeOrSetlikeOrIterable
+ assert iterableDecl.isPairIterator()
+ return "IterableIterator%s" % ("" if infer else '<%s>' % descriptor.interface.identifier.name)