Bug 1475177 - Change sendCommand xpcshell function to only accept plain JSFunction callbacks. r=evilpie
authorJan de Mooij <jdemooij@mozilla.com>
Mon, 16 Jul 2018 14:02:16 +0200
changeset 426709 bb9cb191c067fad734ece7f89708de01fb66b341
parent 426708 37bd009f11f4e05b02a6219a01616331a315efd0
child 426710 97322a202c754fc0de70ae71ee0d55904f8947be
push id34284
push userbtara@mozilla.com
push dateMon, 16 Jul 2018 21:55:18 +0000
treeherdermozilla-central@da5b3e1dca89 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersevilpie
bugs1475177
milestone63.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 1475177 - Change sendCommand xpcshell function to only accept plain JSFunction callbacks. r=evilpie
ipc/testshell/TestShellParent.cpp
js/xpconnect/src/XPCShellImpl.cpp
toolkit/xre/nsEmbedFunctions.cpp
xpcom/build/nsXULAppAPI.h
--- a/ipc/testshell/TestShellParent.cpp
+++ b/ipc/testshell/TestShellParent.cpp
@@ -62,16 +62,18 @@ TestShellCommandParent::SetCallback(JSCo
   return true;
 }
 
 bool
 TestShellCommandParent::RunCallback(const nsString& aResponse)
 {
   NS_ENSURE_TRUE(mCallback.isObject(), false);
 
+  MOZ_RELEASE_ASSERT(js::IsFunctionObject(&mCallback.toObject()));
+
   // We're about to run script via JS_CallFunctionValue, so we need an
   // AutoEntryScript. This is just for testing and not in any spec.
   dom::AutoEntryScript aes(&mCallback.toObject(), "TestShellCommand");
   JSContext* cx = aes.cx();
   JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));
 
   JSString* str = JS_NewUCStringCopyN(cx, aResponse.get(), aResponse.Length());
   NS_ENSURE_TRUE(str, false);
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -450,17 +450,17 @@ SendCommand(JSContext* cx, unsigned argc
     }
 
     RootedString str(cx, ToString(cx, args[0]));
     if (!str) {
         JS_ReportErrorASCII(cx, "Could not convert argument 1 to string!");
         return false;
     }
 
-    if (args.length() > 1 && JS_TypeOfValue(cx, args[1]) != JSTYPE_FUNCTION) {
+    if (args.get(1).isObject() && !JS_ObjectIsFunction(cx, &args[1].toObject())) {
         JS_ReportErrorASCII(cx, "Could not convert argument 2 to function!");
         return false;
     }
 
     if (!XRE_SendTestShellCommand(cx, str, args.length() > 1 ? args[1].address() : nullptr)) {
         JS_ReportErrorASCII(cx, "Couldn't send command!");
         return false;
     }
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -974,35 +974,34 @@ TestShellParent* GetOrCreateTestShellPar
     return tsp;
 }
 
 } // namespace
 
 bool
 XRE_SendTestShellCommand(JSContext* aCx,
                          JSString* aCommand,
-                         void* aCallback)
+                         JS::Value* aCallback)
 {
     JS::RootedString cmd(aCx, aCommand);
     TestShellParent* tsp = GetOrCreateTestShellParent();
     NS_ENSURE_TRUE(tsp, false);
 
     nsAutoJSString command;
     NS_ENSURE_TRUE(command.init(aCx, cmd), false);
 
     if (!aCallback) {
         return tsp->SendExecuteCommand(command);
     }
 
     TestShellCommandParent* callback = static_cast<TestShellCommandParent*>(
         tsp->SendPTestShellCommandConstructor(command));
     NS_ENSURE_TRUE(callback, false);
 
-    JS::Value callbackVal = *reinterpret_cast<JS::Value*>(aCallback);
-    NS_ENSURE_TRUE(callback->SetCallback(aCx, callbackVal), false);
+    NS_ENSURE_TRUE(callback->SetCallback(aCx, *aCallback), false);
 
     return true;
 }
 
 bool
 XRE_ShutdownTestShell()
 {
     if (!gContentParent) {
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -501,17 +501,17 @@ XRE_API(void,
         XRE_ShutdownChildProcess, ())
 
 XRE_API(MessageLoop*,
         XRE_GetIOMessageLoop, ())
 
 XRE_API(bool,
         XRE_SendTestShellCommand, (JSContext* aCx,
                                    JSString* aCommand,
-                                   void* aCallback))
+                                   JS::Value* aCallback))
 XRE_API(bool,
         XRE_ShutdownTestShell, ())
 
 XRE_API(void,
         XRE_InstallX11ErrorHandler, ())
 
 XRE_API(void,
         XRE_TelemetryAccumulate, (int aID, uint32_t aSample))