mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Use FromJSValConvertible's nullable conversion code.
This commit is contained in:
parent
9cc5460dd6
commit
35f6a24de7
1 changed files with 2 additions and 10 deletions
|
@ -576,21 +576,13 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
"holderType")
|
"holderType")
|
||||||
|
|
||||||
declType = CGGeneric(type.name)
|
declType = CGGeneric(type.name)
|
||||||
value = CGGeneric("value")
|
|
||||||
if type.nullable():
|
if type.nullable():
|
||||||
declType = CGWrapper(declType, pre="Option<", post=" >")
|
declType = CGWrapper(declType, pre="Option<", post=" >")
|
||||||
value = CGWrapper(value, pre="Some(", post=")")
|
|
||||||
|
|
||||||
templateBody = CGGeneric("match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
|
templateBody = CGGeneric("match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
|
||||||
|
" Ok(value) => value,\n"
|
||||||
" Err(()) => { %s },\n"
|
" Err(()) => { %s },\n"
|
||||||
" Ok(value) => %s,\n"
|
"}" % exceptionCode)
|
||||||
"}" % (exceptionCode, value.define()))
|
|
||||||
|
|
||||||
if type.nullable():
|
|
||||||
templateBody = CGIfElseWrapper(
|
|
||||||
"(${val}).is_null_or_undefined()",
|
|
||||||
CGGeneric("None"),
|
|
||||||
templateBody)
|
|
||||||
|
|
||||||
templateBody = handleDefaultNull(templateBody.define(),
|
templateBody = handleDefaultNull(templateBody.define(),
|
||||||
"None")
|
"None")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue