aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2017-05-26 13:46:13 -0400
committerJosh Matthews <josh@joshmatthews.net>2017-09-25 16:10:58 -0400
commit16166d66731d7040a91ddbed6ffd05d4fc64c97b (patch)
treeb1c20d92de7a3cc5a87e2d1c6ebfefa6a872c84d /components/script/dom/bindings/codegen
parentb169689f32db6d497b04f3a5b173cba4acd33e93 (diff)
downloadservo-16166d66731d7040a91ddbed6ffd05d4fc64c97b.tar.gz
servo-16166d66731d7040a91ddbed6ffd05d4fc64c97b.zip
Derive the Default trait for dictionaries containing GC values.
Diffstat (limited to 'components/script/dom/bindings/codegen')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 5b2b987c233..aa58afe1913 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -4028,12 +4028,18 @@ impl super::%s {
}
}
+impl Default for super::%s {
+ fn default() -> super::%s {
+ pairs[0].1
+ }
+}
+
impl ToJSValConvertible for super::%s {
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
pairs[*self as usize].0.to_jsval(cx, rval);
}
}
- """ % (ident, pairs, ident, ident)
+ """ % (ident, pairs, ident, ident, ident, ident)
self.cgRoot = CGList([
CGGeneric(decl),
CGNamespace.build([ident + "Values"],
@@ -6038,17 +6044,22 @@ class CGDictionary(CGThing):
(self.makeMemberName(m[0].identifier.name), self.getMemberType(m))
for m in self.memberInfo]
- mustRoot = "#[must_root]\n" if self.membersNeedTracing() else ""
+ derive = ["JSTraceable"]
+ mustRoot = ""
+ if self.membersNeedTracing():
+ mustRoot = "#[must_root]\n"
+ derive += ["Default"]
return (string.Template(
- "#[derive(JSTraceable)]\n"
+ "#[derive(${derive})]\n"
"${mustRoot}" +
"pub struct ${selfName} {\n" +
"${inheritance}" +
"\n".join(memberDecls) + "\n" +
"}").substitute({"selfName": self.makeClassName(d),
"inheritance": inheritance,
- "mustRoot": mustRoot}))
+ "mustRoot": mustRoot,
+ "derive": ', '.join(derive)}))
def impl(self):
d = self.dictionary