mirror of
https://github.com/servo/servo.git
synced 2025-06-17 04:44:28 +00:00
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.
This commit is contained in:
parent
b193767350
commit
ab1b429aef
1 changed files with 12 additions and 12 deletions
|
@ -104,12 +104,12 @@ class CastableObjectUnwrapper():
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return string.Template(
|
return string.Template(
|
||||||
"""match unwrap_jsmanaged(${source}, ${prototype}, ${depth}) {
|
"""${target} = match unwrap_jsmanaged(${source}, ${prototype}, ${depth}) {
|
||||||
Ok(val) => ${target} = ${unwrapped_val},
|
Ok(val) => ${unwrapped_val},
|
||||||
Err(()) => {
|
Err(()) => {
|
||||||
${codeOnFailure}
|
${codeOnFailure}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
""").substitute(self.substitution)
|
""").substitute(self.substitution)
|
||||||
|
|
||||||
#"""{
|
#"""{
|
||||||
|
@ -586,10 +586,10 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
declType = CGWrapper(declType, pre="Option<", post=" >")
|
declType = CGWrapper(declType, pre="Option<", post=" >")
|
||||||
value = CGWrapper(value, pre="Some(", 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"
|
" Err(()) => { %s },\n"
|
||||||
" Ok(value) => ${declName} = %s,\n"
|
" Ok(value) => %s,\n"
|
||||||
"}" % (type.name, exceptionCode, value.define()))
|
"};" % (type.name, exceptionCode, value.define()))
|
||||||
|
|
||||||
if type.nullable():
|
if type.nullable():
|
||||||
templateBody = CGIfElseWrapper(
|
templateBody = CGIfElseWrapper(
|
||||||
|
@ -668,10 +668,10 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
strval = "Some(%s)" % strval
|
strval = "Some(%s)" % strval
|
||||||
|
|
||||||
conversionCode = (
|
conversionCode = (
|
||||||
"match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n"
|
"${declName} = match FromJSValConvertible::from_jsval(cx, ${val}, %s) {\n"
|
||||||
" Ok(strval) => ${declName} = %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
|
||||||
|
@ -837,10 +837,10 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
|
|
||||||
#XXXjdm support conversionBehavior here
|
#XXXjdm support conversionBehavior here
|
||||||
template = (
|
template = (
|
||||||
"match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
|
"${declName} = match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
|
||||||
" Ok(v) => ${declName} = %s,\n"
|
" Ok(v) => %s,\n"
|
||||||
" Err(_) => { %s }\n"
|
" Err(_) => { %s }\n"
|
||||||
"}" % (value, exceptionCode))
|
"};" % (value, exceptionCode))
|
||||||
|
|
||||||
if defaultValue is not None:
|
if defaultValue is not None:
|
||||||
if isinstance(defaultValue, IDLNullValue):
|
if isinstance(defaultValue, IDLNullValue):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue