diff --git a/caps/nsScriptSecurityManager.cpp b/caps/nsScriptSecurityManager.cpp index 84703d482503..3158a01d6f85 100644 --- a/caps/nsScriptSecurityManager.cpp +++ b/caps/nsScriptSecurityManager.cpp @@ -71,6 +71,7 @@ #include "nsContentUtils.h" #include "nsJSUtils.h" #include "nsILoadInfo.h" +#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin // This should be probably defined on some other place... but I couldn't find it #define WEBAPPS_PERM_NAME "webapps-manage" @@ -532,7 +533,7 @@ bool nsScriptSecurityManager::ContentSecurityPolicyPermitsJSAction( JS::AutoFilename scriptFilename; nsAutoString fileName; uint32_t lineNum = 0; - uint32_t columnNum = 0; + JS::ColumnNumberZeroOrigin columnNum; if (JS::DescribeScriptedCaller(cx, &scriptFilename, &lineNum, &columnNum)) { if (const char* file = scriptFilename.get()) { CopyUTF8toUTF16(nsDependentCString(file), fileName); @@ -554,7 +555,7 @@ bool nsScriptSecurityManager::ContentSecurityPolicyPermitsJSAction( csp->LogViolationDetails(violationType, nullptr, // triggering element cspEventListener, fileName, scriptSample, lineNum, - columnNum, u""_ns, u""_ns); + columnNum.zeroOriginValue(), u""_ns, u""_ns); } return evalOK; diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 65efca6c0f87..c4badeae0380 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -4323,9 +4323,7 @@ void Document::NoteScriptTrackingStatus(const nsACString& aURL, bool Document::IsScriptTracking(JSContext* aCx) const { JS::AutoFilename filename; - uint32_t line = 0; - uint32_t column = 0; - if (!JS::DescribeScriptedCaller(aCx, &filename, &line, &column)) { + if (!JS::DescribeScriptedCaller(aCx, &filename)) { return false; } return mTrackingScripts.Contains(nsDependentCString(filename.get())); diff --git a/dom/base/nsJSUtils.cpp b/dom/base/nsJSUtils.cpp index 34d37dcb8093..66b0a09dda9e 100644 --- a/dom/base/nsJSUtils.cpp +++ b/dom/base/nsJSUtils.cpp @@ -51,9 +51,13 @@ using namespace mozilla::dom; bool nsJSUtils::GetCallingLocation(JSContext* aContext, nsACString& aFilename, uint32_t* aLineno, uint32_t* aColumn) { JS::AutoFilename filename; - if (!JS::DescribeScriptedCaller(aContext, &filename, aLineno, aColumn)) { + JS::ColumnNumberZeroOrigin column; + if (!JS::DescribeScriptedCaller(aContext, &filename, aLineno, &column)) { return false; } + if (aColumn) { + *aColumn = column.zeroOriginValue(); + } return aFilename.Assign(filename.get(), fallible); } @@ -61,9 +65,13 @@ bool nsJSUtils::GetCallingLocation(JSContext* aContext, nsACString& aFilename, bool nsJSUtils::GetCallingLocation(JSContext* aContext, nsAString& aFilename, uint32_t* aLineno, uint32_t* aColumn) { JS::AutoFilename filename; - if (!JS::DescribeScriptedCaller(aContext, &filename, aLineno, aColumn)) { + JS::ColumnNumberZeroOrigin column; + if (!JS::DescribeScriptedCaller(aContext, &filename, aLineno, &column)) { return false; } + if (aColumn) { + *aColumn = column.zeroOriginValue(); + } return aFilename.Assign(NS_ConvertUTF8toUTF16(filename.get()), fallible); } diff --git a/dom/events/EventListenerManager.cpp b/dom/events/EventListenerManager.cpp index 660bf6a75208..0c7bbe47e5d7 100644 --- a/dom/events/EventListenerManager.cpp +++ b/dom/events/EventListenerManager.cpp @@ -7,6 +7,7 @@ // Microsoft's API Name hackery sucks #undef CreateEvent +#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin #include "js/loader/LoadedScript.h" #include "mozilla/BasicEvents.h" #include "mozilla/BinarySearch.h" @@ -1028,7 +1029,7 @@ nsresult EventListenerManager::SetEventHandler(nsAtom* aName, // Perform CSP check nsCOMPtr csp = doc->GetCsp(); uint32_t lineNum = 0; - uint32_t columnNum = 0; + JS::ColumnNumberZeroOrigin columnNum; JSContext* cx = nsContentUtils::GetCurrentJSContext(); if (cx && !JS::DescribeScriptedCaller(cx, nullptr, &lineNum, &columnNum)) { @@ -1044,7 +1045,7 @@ nsresult EventListenerManager::SetEventHandler(nsAtom* aName, true, // aParserCreated (true because attribute event handler) aElement, nullptr, // nsICSPEventListener - aBody, lineNum, columnNum, &allowsInlineScript); + aBody, lineNum, columnNum.zeroOriginValue(), &allowsInlineScript); NS_ENSURE_SUCCESS(rv, rv); // return early if CSP wants us to block inline scripts diff --git a/dom/system/IOUtils.cpp b/dom/system/IOUtils.cpp index b6b8191ece48..798034b635d2 100644 --- a/dom/system/IOUtils.cpp +++ b/dom/system/IOUtils.cpp @@ -10,6 +10,7 @@ #include "ErrorList.h" #include "js/ArrayBuffer.h" +#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin #include "js/JSON.h" #include "js/Utility.h" #include "js/experimental/TypedData.h" @@ -290,7 +291,7 @@ static bool AssertParentProcessWithCallerLocationImpl(GlobalObject& aGlobal, JS::AutoFilename scriptFilename; uint32_t lineNo = 0; - uint32_t colNo = 0; + JS::ColumnNumberZeroOrigin colNo; NS_ENSURE_TRUE( JS::DescribeScriptedCaller(cx, &scriptFilename, &lineNo, &colNo), false); @@ -298,7 +299,7 @@ static bool AssertParentProcessWithCallerLocationImpl(GlobalObject& aGlobal, NS_ENSURE_TRUE(scriptFilename.get(), false); reason.AppendPrintf(" Called from %s:%d:%d.", scriptFilename.get(), lineNo, - colNo); + colNo.zeroOriginValue()); return false; } diff --git a/dom/websocket/WebSocket.cpp b/dom/websocket/WebSocket.cpp index 4e0fd892af5e..57ace3fabf7e 100644 --- a/dom/websocket/WebSocket.cpp +++ b/dom/websocket/WebSocket.cpp @@ -8,6 +8,7 @@ #include "mozilla/dom/WebSocketBinding.h" #include "mozilla/net/WebSocketChannel.h" +#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin #include "jsapi.h" #include "jsfriendapi.h" #include "mozilla/Atomics.h" @@ -1371,7 +1372,8 @@ already_AddRefed WebSocket::ConstructorCommon( WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); MOZ_ASSERT(workerPrivate); - uint32_t lineno, column; + uint32_t lineno; + JS::ColumnNumberZeroOrigin column; JS::AutoFilename file; if (!JS::DescribeScriptedCaller(aGlobal.Context(), &file, &lineno, &column)) { @@ -1381,7 +1383,8 @@ already_AddRefed WebSocket::ConstructorCommon( RefPtr runnable = new InitRunnable( workerPrivate, webSocketImpl, workerPrivate->GlobalScope()->GetClientInfo(), !!aTransportProvider, - aUrl, protocolArray, nsDependentCString(file.get()), lineno, column); + aUrl, protocolArray, nsDependentCString(file.get()), lineno, + column.zeroOriginValue()); runnable->Dispatch(Canceling, aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; @@ -1608,12 +1611,13 @@ nsresult WebSocketImpl::Init(JSContext* aCx, bool aIsSecure, } else { MOZ_ASSERT(aCx); - uint32_t lineno, column; + uint32_t lineno; + JS::ColumnNumberZeroOrigin column; JS::AutoFilename file; if (JS::DescribeScriptedCaller(aCx, &file, &lineno, &column)) { mScriptFile = file.get(); mScriptLine = lineno; - mScriptColumn = column; + mScriptColumn = column.zeroOriginValue(); } } diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index ee85b105cd5f..9c49ad97054e 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -21,6 +21,7 @@ #include #include "mozilla/ipc/BackgroundChild.h" #include "GeckoProfiler.h" +#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin #include "js/experimental/CTypes.h" // JS::CTypesActivityType, JS::SetCTypesActivityCallback #include "jsfriendapi.h" #include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_* @@ -518,7 +519,7 @@ bool ContentSecurityPolicyAllows(JSContext* aCx, JS::RuntimeCode aKind, if (reportViolation) { nsString fileName; uint32_t lineNum = 0; - uint32_t columnNum = 0; + JS::ColumnNumberZeroOrigin columnNum; JS::AutoFilename file; if (JS::DescribeScriptedCaller(aCx, &file, &lineNum, &columnNum) && @@ -530,7 +531,8 @@ bool ContentSecurityPolicyAllows(JSContext* aCx, JS::RuntimeCode aKind, RefPtr runnable = new LogViolationDetailsRunnable(worker, violationType, fileName, - lineNum, columnNum, scriptSample); + lineNum, columnNum.zeroOriginValue(), + scriptSample); ErrorResult rv; runnable->Dispatch(Killing, rv); diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 26dfc2dac41b..7bf005d18faf 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -42,7 +42,7 @@ #include "jit/JitSpewer.h" #include "js/CallAndConstruct.h" // JS::IsCallable #include "js/CharacterEncoding.h" -#include "js/ColumnNumber.h" // JS::TaggedColumnNumberZeroOrigin, JS::ColumnNumberOneOrigin +#include "js/ColumnNumber.h" // JS::TaggedColumnNumberZeroOrigin, JS::ColumnNumberZeroOrigin, JS::ColumnNumberOneOrigin #include "js/CompileOptions.h" #include "js/ContextOptions.h" // JS::ContextOptions{,Ref} #include "js/Conversions.h" @@ -4524,7 +4524,8 @@ const char* AutoFilename::get() const { } JS_PUBLIC_API bool DescribeScriptedCaller(JSContext* cx, AutoFilename* filename, - uint32_t* lineno, uint32_t* column) { + uint32_t* lineno, + JS::ColumnNumberZeroOrigin* column) { if (filename) { filename->reset(); } @@ -4532,7 +4533,7 @@ JS_PUBLIC_API bool DescribeScriptedCaller(JSContext* cx, AutoFilename* filename, *lineno = 0; } if (column) { - *column = 0; + *column = JS::ColumnNumberZeroOrigin::zero(); } if (!cx->compartment()) { @@ -4569,12 +4570,12 @@ JS_PUBLIC_API bool DescribeScriptedCaller(JSContext* cx, AutoFilename* filename, JS::TaggedColumnNumberZeroOrigin columnNumber; *lineno = i.computeLine(&columnNumber); if (column) { - *column = columnNumber.zeroOriginValue(); + *column = JS::ColumnNumberZeroOrigin(columnNumber.zeroOriginValue()); } } else if (column) { JS::TaggedColumnNumberZeroOrigin columnNumber; i.computeLine(&columnNumber); - *column = columnNumber.zeroOriginValue(); + *column = JS::ColumnNumberZeroOrigin(columnNumber.zeroOriginValue()); } return true; diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 05cb8258843f..f5a5680d9cee 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -934,7 +934,7 @@ class MOZ_RAII JS_PUBLIC_API AutoFilename { */ extern JS_PUBLIC_API bool DescribeScriptedCaller( JSContext* cx, AutoFilename* filename = nullptr, uint32_t* lineno = nullptr, - uint32_t* column = nullptr); + JS::ColumnNumberZeroOrigin* column = nullptr); extern JS_PUBLIC_API JSObject* GetScriptedCallerGlobal(JSContext* cx); diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index 0d5e91eee756..3c833c012f2b 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -16,6 +16,7 @@ #include "jsapi.h" #include "js/CallAndConstruct.h" // JS::Call, JS::Construct, JS::IsCallable +#include "js/ColumnNumber.h" // JS::ColumnNumberZeroOrigin #include "js/experimental/TypedData.h" // JS_GetTypedArrayLength #include "js/friend/WindowProxy.h" // js::IsWindowProxy #include "js/friend/XrayJitInfo.h" // JS::XrayJitInfo @@ -217,14 +218,15 @@ bool ReportWrapperDenial(JSContext* cx, HandleId id, WrapperDenialType type, return false; } AutoFilename filename; - uint32_t line = 0, column = 0; + uint32_t line = 0; + JS::ColumnNumberZeroOrigin column; DescribeScriptedCaller(cx, &filename, &line, &column); // Warn to the terminal for the logs. NS_WARNING( nsPrintfCString("Silently denied access to property %s: %s (@%s:%u:%u)", NS_LossyConvertUTF16toASCII(propertyName).get(), reason, - filename.get(), line, column) + filename.get(), line, column.zeroOriginValue()) .get()); // If this isn't the first warning on this topic for this global, we've @@ -271,7 +273,8 @@ bool ReportWrapperDenial(JSContext* cx, HandleId id, WrapperDenialType type, nsString filenameStr(NS_ConvertASCIItoUTF16(filename.get())); nsresult rv = errorObject->InitWithWindowID( NS_ConvertASCIItoUTF16(errorMessage.ref()), filenameStr, u""_ns, line, - column, nsIScriptError::warningFlag, "XPConnect", windowId); + column.zeroOriginValue(), nsIScriptError::warningFlag, "XPConnect", + windowId); NS_ENSURE_SUCCESS(rv, true); rv = consoleService->LogMessage(errorObject); NS_ENSURE_SUCCESS(rv, true);