diff options
author | Ms2ger <ms2ger@gmail.com> | 2014-06-02 15:52:36 +0200 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2014-06-02 19:37:06 +0200 |
commit | dea8a4ffcbc653b640a1f67ad6c224bd22c94b42 (patch) | |
tree | 7452fc6f80673308c6d71c7df757a78afb9a06db | |
parent | ebd9b9a519d06dffdb3b48fa6f940df4126fd568 (diff) | |
download | servo-dea8a4ffcbc653b640a1f67ad6c224bd22c94b42.tar.gz servo-dea8a4ffcbc653b640a1f67ad6c224bd22c94b42.zip |
Support dictionary members without default values.
-rw-r--r-- | src/components/script/dom/bindings/codegen/CodegenRust.py | 14 | ||||
-rw-r--r-- | src/components/script/dom/webidls/TestBinding.webidl | 34 |
2 files changed, 26 insertions, 22 deletions
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index ed70d7a1ecb..a161dbc54ee 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -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" diff --git a/src/components/script/dom/webidls/TestBinding.webidl b/src/components/script/dom/webidls/TestBinding.webidl index 578a2d3948b..e2e45b03c83 100644 --- a/src/components/script/dom/webidls/TestBinding.webidl +++ b/src/components/script/dom/webidls/TestBinding.webidl @@ -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; |