From ab1b429aefce97474b6bb40567b653ec6ec70b54 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 16 Apr 2014 14:33:13 +0200 Subject: Move assignments outside match expressions in getJSToNativeConversionTemplate. This is a first step towards making getJSToNativeConversionTemplate return an expression, which will improve dictionary codegen in particular. --- .../script/dom/bindings/codegen/CodegenRust.py | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/components/script/dom/bindings/codegen/CodegenRust.py') diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index cba5bd0b333..320224c3fab 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -104,12 +104,12 @@ class CastableObjectUnwrapper(): def __str__(self): return string.Template( -"""match unwrap_jsmanaged(${source}, ${prototype}, ${depth}) { - Ok(val) => ${target} = ${unwrapped_val}, +"""${target} = match unwrap_jsmanaged(${source}, ${prototype}, ${depth}) { + Ok(val) => ${unwrapped_val}, Err(()) => { ${codeOnFailure} } -} +}; """).substitute(self.substitution) #"""{ @@ -586,10 +586,10 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, declType = CGWrapper(declType, pre="Option<", post=" >") value = CGWrapper(value, pre="Some(", post=")") - templateBody = CGGeneric("match %s::from_value(cx, ${val}) {\n" + templateBody = CGGeneric("${declName} = match %s::from_value(cx, ${val}) {\n" " Err(()) => { %s },\n" - " Ok(value) => ${declName} = %s,\n" - "}" % (type.name, exceptionCode, value.define())) + " Ok(value) => %s,\n" + "};" % (type.name, exceptionCode, value.define())) if type.nullable(): templateBody = CGIfElseWrapper( @@ -668,10 +668,10 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, strval = "Some(%s)" % strval conversionCode = ( - "match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n" - " Ok(strval) => ${declName} = %s,\n" + "${declName} = match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n" + " Ok(strval) => %s,\n" " Err(_) => { %s },\n" - "}" % (nullBehavior, strval, exceptionCode)) + "};" % (nullBehavior, strval, exceptionCode)) if defaultValue is None: return conversionCode @@ -837,10 +837,10 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, #XXXjdm support conversionBehavior here template = ( - "match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n" - " Ok(v) => ${declName} = %s,\n" + "${declName} = match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n" + " Ok(v) => %s,\n" " Err(_) => { %s }\n" - "}" % (value, exceptionCode)) + "};" % (value, exceptionCode)) if defaultValue is not None: if isinstance(defaultValue, IDLNullValue): -- cgit v1.2.3