Bug 1585684. Fix error message for permission failures when passing a union member. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 09 Oct 2019 09:22:05 +0000
changeset 497303 624eb2d8080b1e7a19d6207f8232d6a185f65293
parent 497302 aedc45de64b3e561e8f4ddd9311ac99af5367aff
child 497304 b085b41c10ce17ce0315234a48292e14513bca6f
push id36682
push userncsoregi@mozilla.com
push dateSat, 12 Oct 2019 09:52:03 +0000
treeherdermozilla-central@06ea2371f897 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1585684
milestone71.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
Bug 1585684. Fix error message for permission failures when passing a union member. r=peterv The new error message is still not great, but it's a lot better than having %s as the description of what's going on. Differential Revision: https://phabricator.services.mozilla.com/D47915
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -10239,21 +10239,23 @@ def getUnionTypeTemplateVars(unionType, 
     # constructed as some type, since we've been trying to convert into the
     # corresponding member.
     prefix = "" if ownsMembers else "mUnion."
     tryNextCode = ("$*{destroyHolder}\n"
                    "%sDestroy%s();\n"
                    "tryNext = true;\n"
                    "return true;\n" % (prefix, name))
 
+    sourceDescription = "member of %s" % unionType
+
     conversionInfo = getJSToNativeConversionInfo(
         type, descriptorProvider, failureCode=tryNextCode,
         isDefinitelyObject=not type.isDictionary(),
         isMember=("OwningUnion" if ownsMembers else None),
-        sourceDescription="member of %s" % unionType)
+        sourceDescription=sourceDescription)
 
     if conversionInfo.holderType is not None:
         assert not ownsMembers
         destroyHolder = "%s.reset();\n" % holderName
     else:
         destroyHolder = ""
 
     ctorNeedsCx = conversionInfo.declArgs == "cx"
@@ -10274,23 +10276,25 @@ def getUnionTypeTemplateVars(unionType, 
                 MOZ_ASSERT(mUnion.mType == mUnion.eUninitialized);
                 mUnion.mValue.mObject.SetValue(cx, obj);
                 mUnion.mType = mUnion.eObject;
                 """)
 
         # It's a bit sketchy to do the security check after setting the value,
         # but it keeps the code cleaner and lets us avoid rooting |obj| over the
         # call to CallerSubsumes().
-        body = body + dedent("""
+        body = body + fill(
+            """
             if (passedToJSImpl && !CallerSubsumes(obj)) {
-              ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "%s");
+              ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "${sourceDescription}");
               return false;
             }
             return true;
-            """)
+            """,
+            sourceDescription=sourceDescription)
 
         setter = ClassMethod("SetToObject", "bool",
                              [Argument("JSContext*", "cx"),
                               Argument("JSObject*", "obj"),
                               Argument("bool", "passedToJSImpl", default="false")],
                              inline=True, bodyInHeader=True,
                              body=body)