Skip to content

Commit

Permalink
codegen: Don't unconditionally set non-required dictionary attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed May 13, 2016
1 parent f893a2e commit 92ba0b9
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions components/script/dom/bindings/codegen/CodegenRust.py
Original file line number Diff line number Diff line change
Expand Up @@ -5295,14 +5295,23 @@ def memberInit(memberInfo):
conversion = self.getMemberConversion(memberInfo, member.type)
return CGGeneric("%s: %s,\n" % (name, conversion.define()))

def varInsert(varName, dictionaryName):
insertion = ("let mut %s_js = RootedValue::new(cx, UndefinedValue());\n"
"%s.to_jsval(cx, %s_js.handle_mut());\n"
"set_dictionary_property(cx, obj.handle(), \"%s\", %s_js.handle()).unwrap();"
% (varName, varName, varName, dictionaryName, varName))
return CGGeneric(insertion)

def memberInsert(memberInfo):
member, _ = memberInfo
name = self.makeMemberName(member.identifier.name)
insertion = ("let mut %s = RootedValue::new(cx, UndefinedValue());\n"
"self.%s.to_jsval(cx, %s.handle_mut());\n"
"set_dictionary_property(cx, obj.handle(), \"%s\", %s.handle()).unwrap();"
% (name, name, name, member.identifier.name, name))
return CGGeneric("%s\n" % insertion)
if member.optional and not member.defaultValue:
insertion = CGIfWrapper("let Some(ref %s) = self.%s" % (name, name),
varInsert(name, member.identifier.name))
else:
insertion = CGGeneric("let %s = &self.%s;\n%s" %
(name, name, varInsert(name, member.identifier.name).define()))
return CGGeneric("%s\n" % insertion.define())

memberInits = CGList([memberInit(m) for m in self.memberInfo])
memberInserts = CGList([memberInsert(m) for m in self.memberInfo])
Expand Down

0 comments on commit 92ba0b9

Please sign in to comment.