Support dictionary members without default values.

This commit is contained in:
Ms2ger 2014-06-02 15:52:36 +02:00
parent ebd9b9a519
commit dea8a4ffcb
2 changed files with 26 additions and 22 deletions

View file

@ -4119,7 +4119,9 @@ class CGDictionary(CGThing):
return "/* uh oh */ %s" % name
def getMemberType(self, memberInfo):
_, (_, _, declType, _) = memberInfo
member, (_, _, declType, _) = memberInfo
if not member.defaultValue:
declType = CGWrapper(declType, pre="Option<", post=">")
return declType.define()
def getMemberConversion(self, memberInfo):
@ -4127,12 +4129,14 @@ class CGDictionary(CGThing):
return CGIndenter(CGGeneric(s), 8).define()
member, (templateBody, default, declType, _) = memberInfo
if not member.defaultValue:
raise TypeError("We don't support dictionary members without a "
"default value.")
replacements = { "val": "value" }
conversion = string.Template(templateBody).substitute(replacements)
assert (member.defaultValue is None) == (default is None)
if not default:
default = "None"
conversion = "Some(%s)" % conversion
conversion = (
"match get_dictionary_property(cx, object, \"%s\") {\n"
" Err(()) => return Err(()),\n"

View file

@ -4,23 +4,23 @@
enum TestEnum { "", "foo", "bar" };
/* dictionary TestDictionary {
// boolean booleanValue;
// byte byteValue;
// octet octetValue;
// short shortValue;
// unsigned short unsignedShortValue;
// long longValue;
// unsigned long unsignedLongValue;
// long long longLongValue;
// unsigned long long unsignedLongLongValue;
// float floatValue;
// double doubleValue;
// DOMString stringValue;
// TestEnum enumValue;
// Blob interfaceValue;
// any anyValue;
}; */
dictionary TestDictionary {
boolean booleanValue;
byte byteValue;
octet octetValue;
short shortValue;
unsigned short unsignedShortValue;
long longValue;
unsigned long unsignedLongValue;
long long longLongValue;
unsigned long long unsignedLongLongValue;
float floatValue;
double doubleValue;
DOMString stringValue;
TestEnum enumValue;
Blob interfaceValue;
any anyValue;
};
dictionary TestDictionaryDefaults {
boolean booleanValue = false;