Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Inline unwrapCastableObject into its only caller.
  • Loading branch information
Ms2ger committed Feb 8, 2017
1 parent 8ca1383 commit 350a970
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -134,28 +134,6 @@ def wrapInNativeContainerType(type, inner):
]


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.
Expand Down Expand Up @@ -867,8 +845,17 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type,
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():
Expand Down

0 comments on commit 350a970

Please sign in to comment.