mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Support dictionary members without default values.
This commit is contained in:
parent
ebd9b9a519
commit
dea8a4ffcb
2 changed files with 26 additions and 22 deletions
|
@ -4119,7 +4119,9 @@ class CGDictionary(CGThing):
|
||||||
return "/* uh oh */ %s" % name
|
return "/* uh oh */ %s" % name
|
||||||
|
|
||||||
def getMemberType(self, memberInfo):
|
def getMemberType(self, memberInfo):
|
||||||
_, (_, _, declType, _) = memberInfo
|
member, (_, _, declType, _) = memberInfo
|
||||||
|
if not member.defaultValue:
|
||||||
|
declType = CGWrapper(declType, pre="Option<", post=">")
|
||||||
return declType.define()
|
return declType.define()
|
||||||
|
|
||||||
def getMemberConversion(self, memberInfo):
|
def getMemberConversion(self, memberInfo):
|
||||||
|
@ -4127,12 +4129,14 @@ class CGDictionary(CGThing):
|
||||||
return CGIndenter(CGGeneric(s), 8).define()
|
return CGIndenter(CGGeneric(s), 8).define()
|
||||||
|
|
||||||
member, (templateBody, default, declType, _) = memberInfo
|
member, (templateBody, default, declType, _) = memberInfo
|
||||||
if not member.defaultValue:
|
|
||||||
raise TypeError("We don't support dictionary members without a "
|
|
||||||
"default value.")
|
|
||||||
|
|
||||||
replacements = { "val": "value" }
|
replacements = { "val": "value" }
|
||||||
conversion = string.Template(templateBody).substitute(replacements)
|
conversion = string.Template(templateBody).substitute(replacements)
|
||||||
|
|
||||||
|
assert (member.defaultValue is None) == (default is None)
|
||||||
|
if not default:
|
||||||
|
default = "None"
|
||||||
|
conversion = "Some(%s)" % conversion
|
||||||
|
|
||||||
conversion = (
|
conversion = (
|
||||||
"match get_dictionary_property(cx, object, \"%s\") {\n"
|
"match get_dictionary_property(cx, object, \"%s\") {\n"
|
||||||
" Err(()) => return Err(()),\n"
|
" Err(()) => return Err(()),\n"
|
||||||
|
|
|
@ -4,23 +4,23 @@
|
||||||
|
|
||||||
enum TestEnum { "", "foo", "bar" };
|
enum TestEnum { "", "foo", "bar" };
|
||||||
|
|
||||||
/* dictionary TestDictionary {
|
dictionary TestDictionary {
|
||||||
// boolean booleanValue;
|
boolean booleanValue;
|
||||||
// byte byteValue;
|
byte byteValue;
|
||||||
// octet octetValue;
|
octet octetValue;
|
||||||
// short shortValue;
|
short shortValue;
|
||||||
// unsigned short unsignedShortValue;
|
unsigned short unsignedShortValue;
|
||||||
// long longValue;
|
long longValue;
|
||||||
// unsigned long unsignedLongValue;
|
unsigned long unsignedLongValue;
|
||||||
// long long longLongValue;
|
long long longLongValue;
|
||||||
// unsigned long long unsignedLongLongValue;
|
unsigned long long unsignedLongLongValue;
|
||||||
// float floatValue;
|
float floatValue;
|
||||||
// double doubleValue;
|
double doubleValue;
|
||||||
// DOMString stringValue;
|
DOMString stringValue;
|
||||||
// TestEnum enumValue;
|
TestEnum enumValue;
|
||||||
// Blob interfaceValue;
|
Blob interfaceValue;
|
||||||
// any anyValue;
|
any anyValue;
|
||||||
}; */
|
};
|
||||||
|
|
||||||
dictionary TestDictionaryDefaults {
|
dictionary TestDictionaryDefaults {
|
||||||
boolean booleanValue = false;
|
boolean booleanValue = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue