Support required dictionary members (fixes #7216)

This commit is contained in:
Anthony Ramine 2015-08-15 13:19:57 +02:00
parent efe982392e
commit 44aabbe64d
2 changed files with 7 additions and 2 deletions

View file

@ -4800,7 +4800,7 @@ class CGDictionary(CGThing):
def getMemberType(self, memberInfo):
member, info = memberInfo
declType = info.declType
if not member.defaultValue:
if member.optional and not member.defaultValue:
declType = CGWrapper(info.declType, pre="Option<", post=">")
return declType.define()
@ -4817,7 +4817,11 @@ class CGDictionary(CGThing):
conversion = "%s.get()" % conversion
assert (member.defaultValue is None) == (default is None)
if not default:
if not member.optional:
assert default is None
default = ("throw_type_error(cx, \"Missing required member \\\"%s\\\".\");\n"
"return Err(());") % member.identifier.name
elif not default:
default = "None"
conversion = "Some(%s)" % conversion

View file

@ -8,6 +8,7 @@
enum TestEnum { "", "foo", "bar" };
dictionary TestDictionary {
required boolean requiredValue;
boolean booleanValue;
byte byteValue;
octet octetValue;