From f753b8986b32a410f0f4cc73192634c1c76260a7 Mon Sep 17 00:00:00 2001 From: Matthew Gaudet Date: Wed, 16 Oct 2024 15:58:19 +0000 Subject: [PATCH] Bug 1924888 - Swap order of arguments to DescribeScriptedCaller r=sfink It's not a standard exception throwing JSAPI function. The one caveat here is that I couldn't put JSContext in last position: There are default params to preserve. So instead it's in second position, which still communicates that it's not an exception throwing function Differential Revision: https://phabricator.services.mozilla.com/D225726 --- dom/base/Document.cpp | 2 +- dom/base/SourceLocation.cpp | 2 +- dom/base/nsGlobalWindowInner.cpp | 2 +- dom/events/EventListenerManager.cpp | 2 +- dom/system/IOUtils.cpp | 2 +- dom/websocket/WebSocket.cpp | 4 ++-- dom/workers/WorkerPrivate.cpp | 2 +- js/src/builtin/TestingFunctions.cpp | 2 +- js/src/jsapi.cpp | 2 +- js/src/jsapi.h | 2 +- js/src/shell/OSObject.cpp | 3 ++- js/src/shell/js.cpp | 4 ++-- js/src/wasm/WasmJS.cpp | 2 +- js/xpconnect/loader/mozJSSubScriptLoader.cpp | 2 +- js/xpconnect/src/XPCJSContext.cpp | 2 +- js/xpconnect/src/XPCShellImpl.cpp | 2 +- js/xpconnect/wrappers/XrayWrapper.cpp | 2 +- toolkit/components/resistfingerprinting/nsRFPService.cpp | 2 +- 18 files changed, 21 insertions(+), 20 deletions(-) diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index ea5c051b784f..1ee3da0da486 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -4430,7 +4430,7 @@ void Document::NoteScriptTrackingStatus(const nsACString& aURL, bool Document::IsScriptTracking(JSContext* aCx) const { JS::AutoFilename filename; - if (!JS::DescribeScriptedCaller(aCx, &filename)) { + if (!JS::DescribeScriptedCaller(&filename, aCx)) { return false; } return mTrackingScripts.Contains(nsDependentCString(filename.get())); diff --git a/dom/base/SourceLocation.cpp b/dom/base/SourceLocation.cpp index 5f0dc746fe1d..35a98362adbf 100644 --- a/dom/base/SourceLocation.cpp +++ b/dom/base/SourceLocation.cpp @@ -52,7 +52,7 @@ JSCallingLocation JSCallingLocation::Get(JSContext* aCx) { JS::AutoFilename filename; uint32_t line; JS::ColumnNumberOneOrigin column; - if (!JS::DescribeScriptedCaller(aCx, &filename, &line, &column)) { + if (!JS::DescribeScriptedCaller(&filename, aCx, &line, &column)) { return result; } nsCString file; diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 89cd0f306904..9d2327bd22ee 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -5008,7 +5008,7 @@ nsGlobalWindowInner::ShowSlowScriptDialog(JSContext* aCx, // minified scripts which is more common in Web content that is loaded in the // content process. uint32_t* linenop = XRE_IsParentProcess() ? &lineno : nullptr; - bool hasFrame = JS::DescribeScriptedCaller(aCx, &filename, linenop); + bool hasFrame = JS::DescribeScriptedCaller(&filename, aCx, linenop); // Record the slow script event if we haven't done so already for this inner // window (which represents a particular page to the user). diff --git a/dom/events/EventListenerManager.cpp b/dom/events/EventListenerManager.cpp index 1ea1fa09c094..c58a3a6ce9d7 100644 --- a/dom/events/EventListenerManager.cpp +++ b/dom/events/EventListenerManager.cpp @@ -1030,7 +1030,7 @@ nsresult EventListenerManager::SetEventHandler(nsAtom* aName, JS::ColumnNumberOneOrigin columnNum; JSContext* cx = nsContentUtils::GetCurrentJSContext(); - if (cx && !JS::DescribeScriptedCaller(cx, nullptr, &lineNum, &columnNum)) { + if (cx && !JS::DescribeScriptedCaller(nullptr, cx, &lineNum, &columnNum)) { JS_ClearPendingException(cx); } diff --git a/dom/system/IOUtils.cpp b/dom/system/IOUtils.cpp index 4b989c6c0cf6..de320cb79d4c 100644 --- a/dom/system/IOUtils.cpp +++ b/dom/system/IOUtils.cpp @@ -283,7 +283,7 @@ static bool AssertParentProcessWithCallerLocationImpl(GlobalObject& aGlobal, JS::ColumnNumberOneOrigin colNo; NS_ENSURE_TRUE( - JS::DescribeScriptedCaller(cx, &scriptFilename, &lineNo, &colNo), false); + JS::DescribeScriptedCaller(&scriptFilename, cx, &lineNo, &colNo), false); NS_ENSURE_TRUE(scriptFilename.get(), false); diff --git a/dom/websocket/WebSocket.cpp b/dom/websocket/WebSocket.cpp index f04f5e9673dc..78536d85bd7a 100644 --- a/dom/websocket/WebSocket.cpp +++ b/dom/websocket/WebSocket.cpp @@ -1417,7 +1417,7 @@ already_AddRefed WebSocket::ConstructorCommon( uint32_t lineno; JS::ColumnNumberOneOrigin column; JS::AutoFilename file; - if (!JS::DescribeScriptedCaller(aGlobal.Context(), &file, &lineno, + if (!JS::DescribeScriptedCaller(&file, aGlobal.Context(), &lineno, &column)) { NS_WARNING("Failed to get line number and filename in workers."); } @@ -1664,7 +1664,7 @@ nsresult WebSocketImpl::Init(nsIGlobalObject* aWindowGlobal, JSContext* aCx, uint32_t lineno; JS::ColumnNumberOneOrigin column; JS::AutoFilename file; - if (JS::DescribeScriptedCaller(aCx, &file, &lineno, &column)) { + if (JS::DescribeScriptedCaller(&file, aCx, &lineno, &column)) { mScriptFile = file.get(); mScriptLine = lineno; mScriptColumn = column.oneOriginValue(); diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 80d211aed269..930a65d60010 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -3152,7 +3152,7 @@ nsresult WorkerPrivate::GetLoadInfo( // We're being created outside of a window. Need to figure out the script // that is creating us in order for us to use relative URIs later on. JS::AutoFilename fileName; - if (JS::DescribeScriptedCaller(aCx, &fileName)) { + if (JS::DescribeScriptedCaller(&fileName, aCx)) { // In most cases, fileName is URI. In a few other cases // (e.g. xpcshell), fileName is a file path. Ideally, we would // prefer testing whether fileName parses as an URI and fallback diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index 026ccdee65df..b77f7636ee22 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -7241,7 +7241,7 @@ static bool EvalReturningScope(JSContext* cx, unsigned argc, Value* vp) { JS::AutoFilename filename; uint32_t lineno; - JS::DescribeScriptedCaller(cx, &filename, &lineno); + JS::DescribeScriptedCaller(&filename, cx, &lineno); // CompileOption should be created in the target global's realm. RootedObject global(cx); diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index b02e53c1e95a..497c48334eba 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -4674,7 +4674,7 @@ const char* AutoFilename::get() const { return filename_.as().get(); } -JS_PUBLIC_API bool DescribeScriptedCaller(JSContext* cx, AutoFilename* filename, +JS_PUBLIC_API bool DescribeScriptedCaller(AutoFilename* filename, JSContext* cx, uint32_t* lineno, JS::ColumnNumberOneOrigin* column) { if (filename) { diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 6ccefaec6af8..1f6b72fb8c57 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -954,7 +954,7 @@ class MOZ_RAII JS_PUBLIC_API AutoFilename { * record, this will also return false. */ extern JS_PUBLIC_API bool DescribeScriptedCaller( - JSContext* cx, AutoFilename* filename, uint32_t* lineno = nullptr, + AutoFilename* filename, JSContext* cx, uint32_t* lineno = nullptr, JS::ColumnNumberOneOrigin* column = nullptr); extern JS_PUBLIC_API JSObject* GetScriptedCallerGlobal(JSContext* cx); diff --git a/js/src/shell/OSObject.cpp b/js/src/shell/OSObject.cpp index 673566fb72b9..12375b33deb4 100644 --- a/js/src/shell/OSObject.cpp +++ b/js/src/shell/OSObject.cpp @@ -194,7 +194,8 @@ JSString* ResolvePath(JSContext* cx, HandleString filenameStr, JS::AutoFilename scriptFilename; if (resolveMode == ScriptRelative) { // Get the currently executing script's name. - if (!DescribeScriptedCaller(cx, &scriptFilename) || !scriptFilename.get()) { + + if (!DescribeScriptedCaller(&scriptFilename, cx) || !scriptFilename.get()) { JS_ReportErrorASCII( cx, "cannot resolve path due to hidden or unscripted caller"); return nullptr; diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 76db3c487ad2..19235c7e7b8a 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -4432,7 +4432,7 @@ static bool EvalInContext(JSContext* cx, unsigned argc, Value* vp) { JS::AutoFilename filename; uint32_t lineno; - DescribeScriptedCaller(cx, &filename, &lineno); + DescribeScriptedCaller(&filename, cx, &lineno); { sobj = UncheckedUnwrap(sobj, true); @@ -6967,7 +6967,7 @@ static bool ThisFilename(JSContext* cx, unsigned argc, Value* vp) { CallArgs args = CallArgsFromVp(argc, vp); JS::AutoFilename filename; - if (!DescribeScriptedCaller(cx, &filename) || !filename.get()) { + if (!DescribeScriptedCaller(&filename, cx) || !filename.get()) { args.rval().setString(cx->runtime()->emptyString); return true; } diff --git a/js/src/wasm/WasmJS.cpp b/js/src/wasm/WasmJS.cpp index cc994650e133..9f7eee559879 100644 --- a/js/src/wasm/WasmJS.cpp +++ b/js/src/wasm/WasmJS.cpp @@ -380,7 +380,7 @@ static bool DescribeScriptedCaller(JSContext* cx, ScriptedCaller* caller, // back to the more ordinary false-if-error form. JS::AutoFilename af; - if (JS::DescribeScriptedCaller(cx, &af, &caller->line)) { + if (JS::DescribeScriptedCaller(&af, cx, &caller->line)) { caller->filename = FormatIntroducedFilename(af.get(), caller->line, introducer); if (!caller->filename) { diff --git a/js/xpconnect/loader/mozJSSubScriptLoader.cpp b/js/xpconnect/loader/mozJSSubScriptLoader.cpp index 33192bff29a8..a2834e1f3bc6 100644 --- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp +++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp @@ -349,7 +349,7 @@ nsresult mozJSSubScriptLoader::DoLoadSubScriptWithOptions( // Figure out who's calling us JS::AutoFilename filename; - if (!JS::DescribeScriptedCaller(cx, &filename)) { + if (!JS::DescribeScriptedCaller(&filename, cx)) { // No scripted frame means we don't know who's calling, bail. return NS_ERROR_FAILURE; } diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index d112972a17fb..3a5f54971184 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -599,7 +599,7 @@ bool XPCJSContext::InterruptCallback(JSContext* cx) { JS::AutoFilename scriptFilename; // Computing the line number can be very expensive (see bug 1330231 for // example), so don't request it here. - if (JS::DescribeScriptedCaller(cx, &scriptFilename)) { + if (JS::DescribeScriptedCaller(&scriptFilename, cx)) { if (const char* file = scriptFilename.get()) { filename.Assign(file, strlen(file)); } diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index fd4c060ebfee..b601acba8b08 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -163,7 +163,7 @@ static bool GetLocationProperty(JSContext* cx, unsigned argc, Value* vp) { return false; #else JS::AutoFilename filename; - if (JS::DescribeScriptedCaller(cx, &filename) && filename.get()) { + if (JS::DescribeScriptedCaller(&filename, cx) && filename.get()) { NS_ConvertUTF8toUTF16 filenameString(filename.get()); # if defined(XP_WIN) diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index 80e7719c6304..62522c3e9790 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -220,7 +220,7 @@ bool ReportWrapperDenial(JSContext* cx, HandleId id, WrapperDenialType type, AutoFilename filename; uint32_t line = 0; JS::ColumnNumberOneOrigin column; - DescribeScriptedCaller(cx, &filename, &line, &column); + DescribeScriptedCaller(&filename, cx, &line, &column); // Warn to the terminal for the logs. NS_WARNING( diff --git a/toolkit/components/resistfingerprinting/nsRFPService.cpp b/toolkit/components/resistfingerprinting/nsRFPService.cpp index a7b9bd739ef7..e169118de10a 100644 --- a/toolkit/components/resistfingerprinting/nsRFPService.cpp +++ b/toolkit/components/resistfingerprinting/nsRFPService.cpp @@ -1731,7 +1731,7 @@ static void MaybeCurrentCaller(nsACString& aFilename, uint32_t& aLineNum, JS::AutoFilename scriptFilename; JS::ColumnNumberOneOrigin columnNum; - if (JS::DescribeScriptedCaller(cx, &scriptFilename, &aLineNum, &columnNum)) { + if (JS::DescribeScriptedCaller(&scriptFilename, cx, &aLineNum, &columnNum)) { if (const char* file = scriptFilename.get()) { aFilename = nsDependentCString(file); }