aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py52
1 files changed, 51 insertions, 1 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 01b52d916ae..ae76667707e 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -2116,6 +2116,10 @@ class CGDOMJSClass(CGThing):
self.descriptor = descriptor
def define(self):
+ parentName = self.descriptor.getParentName()
+ if not parentName:
+ parentName = "::dom::bindings::reflector::Reflector"
+
args = {
"domClass": DOMClass(self.descriptor),
"enumerateHook": "None",
@@ -2161,7 +2165,51 @@ static Class: DOMJSClass = DOMJSClass {
reserved: [0 as *mut _; 3],
},
dom_class: %(domClass)s
-};""" % args
+};
+""" % args
+
+
+class CGAssertInheritance(CGThing):
+ """
+ Generate a type assertion for inheritance
+ """
+ def __init__(self, descriptor):
+ CGThing.__init__(self)
+ self.descriptor = descriptor
+
+ def define(self):
+ parent = self.descriptor.interface.parent
+ parentName = ""
+ if parent:
+ parentName = parent.identifier.name
+ else:
+ parentName = "::dom::bindings::reflector::Reflector"
+
+ selfName = self.descriptor.interface.identifier.name
+
+ if selfName == "PaintRenderingContext2D":
+ # PaintRenderingContext2D embeds a CanvasRenderingContext2D
+ # instead of a Reflector as an optimization,
+ # but this is fine since CanvasRenderingContext2D
+ # also has a reflector
+ #
+ # FIXME *RenderingContext2D should use Inline
+ parentName = "::dom::canvasrenderingcontext2d::CanvasRenderingContext2D"
+ args = {
+ "parentName": parentName,
+ "selfName": selfName,
+ }
+
+ return """\
+impl %(selfName)s {
+ fn __assert_parent_type(&self) {
+ use dom::bindings::inheritance::HasParent;
+ // If this type assertion fails, make sure the first field of your
+ // DOM struct is of the correct type -- it must be the parent class.
+ let _: &%(parentName)s = self.as_parent();
+ }
+}
+""" % args
def str_to_const_array(s):
@@ -6011,6 +6059,8 @@ class CGDescriptor(CGThing):
pass
else:
cgThings.append(CGDOMJSClass(descriptor))
+ if not descriptor.interface.isIteratorInterface():
+ cgThings.append(CGAssertInheritance(descriptor))
pass
if descriptor.isGlobal():