зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #15453 - Inline unwrapCastableObject into its only caller (from servo:unwrapCastableObject); r=nox
Source-Repo: https://github.com/servo/servo Source-Revision: 6d1d4b57838d930e6ce39be720ef6c6dbb74af26 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : aecc6676c1dc24a8d8e08123d13172c1646b6387
This commit is contained in:
Родитель
6629ee4a4a
Коммит
76f8130812
|
@ -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():
|
||||
|
|
Загрузка…
Ссылка в новой задаче