mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Auto merge of #15453 - servo:unwrapCastableObject, r=nox
Inline unwrapCastableObject into its only caller. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15453) <!-- Reviewable:end -->
This commit is contained in:
commit
6d1d4b5783
1 changed files with 11 additions and 24 deletions
|
@ -134,28 +134,6 @@ numericTags = [
|
|||
]
|
||||
|
||||
|
||||
def unwrapCastableObject(descriptor, source, codeOnFailure, conversionFunction):
|
||||
"""
|
||||
A function for unwrapping an object named by the "source" argument
|
||||
based on the passed-in descriptor. Returns the string of the Rust expression of
|
||||
the appropriate type.
|
||||
|
||||
codeOnFailure is the code to run if unwrapping fails.
|
||||
"""
|
||||
args = {
|
||||
"failureCode": CGIndenter(CGGeneric(codeOnFailure), 8).define(),
|
||||
"function": conversionFunction,
|
||||
"source": source,
|
||||
}
|
||||
return """\
|
||||
match %(function)s(%(source)s) {
|
||||
Ok(val) => val,
|
||||
Err(()) => {
|
||||
%(failureCode)s
|
||||
}
|
||||
}""" % args
|
||||
|
||||
|
||||
# We'll want to insert the indent at the beginnings of lines, but we
|
||||
# don't want to indent empty lines. So only indent lines that have a
|
||||
# non-newline character on them.
|
||||
|
@ -862,8 +840,17 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
else:
|
||||
unwrapFailureCode = failureCode
|
||||
|
||||
templateBody = unwrapCastableObject(
|
||||
descriptor, "${val}", unwrapFailureCode, conversionFunction)
|
||||
templateBody = fill(
|
||||
"""
|
||||
match ${function}($${val}) {
|
||||
Ok(val) => val,
|
||||
Err(()) => {
|
||||
$*{failureCode}
|
||||
}
|
||||
}
|
||||
""",
|
||||
failureCode=unwrapFailureCode + "\n",
|
||||
function=conversionFunction)
|
||||
|
||||
declType = CGGeneric(descriptorType)
|
||||
if type.nullable():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue