mirror of
https://github.com/servo/servo.git
synced 2025-06-09 09:03:23 +00: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")
|
||||
|
||||
declType = CGGeneric(type.name)
|
||||
value = CGGeneric("value")
|
||||
if type.nullable():
|
||||
declType = CGWrapper(declType, pre="Option<", post=" >")
|
||||
value = CGWrapper(value, pre="Some(", post=")")
|
||||
|
||||
templateBody = CGGeneric("match FromJSValConvertible::from_jsval(cx, ${val}, ()) {\n"
|
||||
" Ok(value) => value,\n"
|
||||
" Err(()) => { %s },\n"
|
||||
" Ok(value) => %s,\n"
|
||||
"}" % (exceptionCode, value.define()))
|
||||
|
||||
if type.nullable():
|
||||
templateBody = CGIfElseWrapper(
|
||||
"(${val}).is_null_or_undefined()",
|
||||
CGGeneric("None"),
|
||||
templateBody)
|
||||
"}" % exceptionCode)
|
||||
|
||||
templateBody = handleDefaultNull(templateBody.define(),
|
||||
"None")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue