servo: Merge #15453 - Inline unwrapCastableObject into its only caller (from servo:unwrapCastableObject); r=nox
authorMs2ger <Ms2ger@gmail.com>
Wed, 08 Feb 2017 06:38:44 -0800
changeset 341508 d96e28eeca03a19aea9c8a635d954ca9c1484742
parent 341507 c55740ba06b5656c95f92c78876a290ac4d1acf7
child 341509 e2e4a36e18a26357a4955a4444c4f295f0d92399
push id86727
push userkwierso@gmail.com
push dateThu, 09 Feb 2017 00:21:26 +0000
treeherdermozilla-inbound@55a4f5189115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnox
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #15453 - Inline unwrapCastableObject into its only caller (from servo:unwrapCastableObject); r=nox Source-Repo: https://github.com/servo/servo Source-Revision: 6d1d4b57838d930e6ce39be720ef6c6dbb74af26
servo/components/script/dom/bindings/codegen/CodegenRust.py
--- a/servo/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/servo/components/script/dom/bindings/codegen/CodegenRust.py
@@ -129,38 +129,16 @@ numericTags = [
     IDLType.Tags.int16, IDLType.Tags.uint16,
     IDLType.Tags.int32, IDLType.Tags.uint32,
     IDLType.Tags.int64, IDLType.Tags.uint64,
     IDLType.Tags.unrestricted_float,
     IDLType.Tags.unrestricted_double
 ]
 
 
-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.
 lineStartDetector = re.compile("^(?=[^\n#])", re.MULTILINE)
 
 
 def indent(s, indentLevel=2):
     """
@@ -857,18 +835,27 @@ def getJSToNativeConversionInfo(type, de
                 }
                 unwrapFailureCode = string.Template(
                     'throw_type_error(cx, "${sourceDescription} does not '
                     'implement interface ${interface}.");\n'
                     '${exceptionCode}').substitute(substitutions)
             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():
             templateBody = "Some(%s)" % templateBody
             declType = CGWrapper(declType, pre="Option<", post=">")
 
         templateBody = wrapObjectTemplate(templateBody, "None",
                                           isDefinitelyObject, type, failureCode)