mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Derive the Default trait for dictionaries containing GC values.
This commit is contained in:
parent
b169689f32
commit
16166d6673
6 changed files with 49 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue