Rewrite the DOMString unwrapping to return an expression.

This commit is contained in:
Ms2ger 2014-04-17 12:15:28 +02:00
parent 4905b22673
commit 1027801b04

View file

@ -665,17 +665,17 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
strval = "Some(%s)" % strval strval = "Some(%s)" % strval
conversionCode = ( conversionCode = (
"${declName} = match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n" "match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n"
" Ok(strval) => %s,\n" " Ok(strval) => %s,\n"
" Err(_) => { %s },\n" " Err(_) => { %s },\n"
"};" % (nullBehavior, strval, exceptionCode)) "}" % (nullBehavior, strval, exceptionCode))
if defaultValue is None: if defaultValue is None:
return conversionCode return conversionCode
if isinstance(defaultValue, IDLNullValue): if isinstance(defaultValue, IDLNullValue):
assert(type.nullable()) assert(type.nullable())
return handleDefault(conversionCode, "${declName} = None;") return handleDefault(conversionCode, "None")
value = "str::from_utf8(data).unwrap().to_owned()" value = "str::from_utf8(data).unwrap().to_owned()"
if type.nullable(): if type.nullable():
@ -683,7 +683,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
default = ( default = (
"static data: [u8, ..%s] = [ %s ];\n" "static data: [u8, ..%s] = [ %s ];\n"
"${declName} = %s;" % "%s" %
(len(defaultValue.value) + 1, (len(defaultValue.value) + 1,
", ".join(["'" + char + "' as u8" for char in defaultValue.value] + ["0"]), ", ".join(["'" + char + "' as u8" for char in defaultValue.value] + ["0"]),
value)) value))
@ -700,8 +700,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
initialValue = "None" initialValue = "None"
return ( return (
"%s\n" % "${declName} = %s;" % getConversionCode(isOptional),
(getConversionCode(isOptional)),
CGGeneric(declType), None, #CGGeneric("FakeDependentString"), CGGeneric(declType), None, #CGGeneric("FakeDependentString"),
False, False,
initialValue) initialValue)