mirror of
https://github.com/servo/servo.git
synced 2025-06-16 20:34:30 +00:00
Common up some code in the conversion to nullable and non-nullable primitive types.
This commit is contained in:
parent
54a59b9d38
commit
922d191948
1 changed files with 11 additions and 19 deletions
|
@ -1238,17 +1238,17 @@ for (uint32_t i = 0; i < length; ++i) {
|
|||
if failureCode is None:
|
||||
failureCode = 'return 0'
|
||||
|
||||
if type.nullable():
|
||||
successVal = "v"
|
||||
if preSuccess or postSuccess:
|
||||
successVal = preSuccess + successVal + postSuccess
|
||||
#XXXjdm support conversionBehavior here
|
||||
template = (
|
||||
"match JSValConvertible::from_jsval(cx, ${val}) {\n"
|
||||
" Ok(v) => ${declName} = %s,\n"
|
||||
" Err(_) => %s\n"
|
||||
"}" % (successVal, failureCode))
|
||||
successVal = "v"
|
||||
if preSuccess or postSuccess:
|
||||
successVal = preSuccess + successVal + postSuccess
|
||||
#XXXjdm support conversionBehavior here
|
||||
template = (
|
||||
"match JSValConvertible::from_jsval(cx, ${val}) {\n"
|
||||
" Ok(v) => ${declName} = %s,\n"
|
||||
" Err(_) => %s\n"
|
||||
"}" % (successVal, failureCode))
|
||||
|
||||
if type.nullable():
|
||||
if defaultValue is not None and isinstance(defaultValue, IDLNullValue):
|
||||
template = CGWrapper(CGIndenter(CGGeneric(template)),
|
||||
pre="if ${haveValue} {\n",
|
||||
|
@ -1261,16 +1261,8 @@ for (uint32_t i = 0; i < length; ++i) {
|
|||
else:
|
||||
assert(defaultValue is None or
|
||||
not isinstance(defaultValue, IDLNullValue))
|
||||
#XXXjdm conversionBehavior should be used
|
||||
successVal = "v"
|
||||
if preSuccess or postSuccess:
|
||||
successVal = preSuccess + successVal + postSuccess
|
||||
template = (
|
||||
"match JSValConvertible::from_jsval(cx, ${val}) {\n"
|
||||
" Err(_) => %s,\n"
|
||||
" Ok(v) => ${declName} = %s\n"
|
||||
"}" % (failureCode, successVal))
|
||||
declType = CGGeneric(typeName)
|
||||
|
||||
if (defaultValue is not None and
|
||||
# We already handled IDLNullValue, so just deal with the other ones
|
||||
not isinstance(defaultValue, IDLNullValue)):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue