diff options
author | Ms2ger <ms2ger@gmail.com> | 2013-11-10 14:11:15 +0100 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2013-11-12 13:57:18 +0100 |
commit | 08afc6d19d5875763a241e08534ba952e507b137 (patch) | |
tree | a3ca25a011543eb928aa7843cc39931b56063b33 /src/components/script/dom/bindings/codegen/CodegenRust.py | |
parent | 803cd4b7cfa0e846d5fa89be04ef4140e6f1a7d2 (diff) | |
download | servo-08afc6d19d5875763a241e08534ba952e507b137.tar.gz servo-08afc6d19d5875763a241e08534ba952e507b137.zip |
Don't pass nullable strings to native DOM methods that want non-nullable strings. Fixes #1207.
Diffstat (limited to 'src/components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r-- | src/components/script/dom/bindings/codegen/CodegenRust.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index c1739f1c13c..05255b95792 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -1066,9 +1066,6 @@ for (uint32_t i = 0; i < length; ++i) { def getConversionCode(varName, isOptional=False): strval = "strval" - if not type.nullable(): - # XXX #1207 Actually pass non-nullable strings to callees. - strval = "Some(%s)" % strval if isOptional: strval = "Some(%s)" % strval if type.nullable(): @@ -1092,7 +1089,7 @@ for (uint32_t i = 0; i < length; ++i) { return handleDefault( conversionCode, ("static data: [u8, ..%s] = [ %s ];\n" - "%s = Some(str::from_utf8(data));" % + "%s = str::from_utf8(data)" % (len(defaultValue.value) + 1, ", ".join(["'" + char + "' as u8" for char in defaultValue.value] + ["0"]), varName))) @@ -1109,12 +1106,14 @@ for (uint32_t i = 0; i < length; ++i) { "}\n" % CGIndenter(CGGeneric(getConversionCode("str"))).define(), declType, None, isOptional, None) + declType = "DOMString" + initialValue = None + if type.nullable(): + declType = "Option<%s>" % declType + if isOptional: - declType = "Option<Option<DOMString>>" + declType = "Option<%s>" % declType initialValue = "None" - else: - declType = "Option<DOMString>" - initialValue = None return ( "%s\n" % @@ -1587,8 +1586,7 @@ for (uint32_t i = 0; i < length; ++i) { if type.nullable(): return (wrapAndSetPtr("*${jsvalPtr} = domstring_to_jsval(cx, &%s)" % result), False) else: - #XXXjdm Can we be smarter when we know it's not nullable? - return (wrapAndSetPtr("*${jsvalPtr} = domstring_to_jsval(cx, &%s)" % result), False) + return (wrapAndSetPtr("*${jsvalPtr} = str_to_jsval(cx, &%s)" % result), False) if type.isEnum(): if type.nullable(): @@ -1722,7 +1720,10 @@ def getRetvalDeclarationForType(returnType, descriptorProvider, result = CGWrapper(result, pre="Nullable<", post=">") return result, False if returnType.isString(): - return CGGeneric("Option<DOMString>"), False + result = CGGeneric("DOMString") + if returnType.nullable(): + result = CGWrapper(result, pre="Option<", post=">") + return result, False if returnType.isEnum(): if returnType.nullable(): raise TypeError("We don't support nullable enum return values") |