tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit bf9cf5a1b0bc95e4a7521c1935a1038ba305ef69
parent 47eb3572473dfdb826a1b32dc1913b5e37fdf188
Author: Alexandre Poirot <poirot.alex@gmail.com>
Date:   Tue,  6 Jan 2026 15:39:47 +0000

Bug 1990493 - Expose last out of memory stack trace to privileged JavaScript. r=bthrall

Differential Revision: https://phabricator.services.mozilla.com/D265977

Diffstat:
Mdom/base/ChromeUtils.cpp | 6++++++
Mdom/base/ChromeUtils.h | 1+
Mdom/chrome-webidl/ChromeUtils.webidl | 5+++++
Mjs/public/Debug.h | 2++
Mjs/src/debugger/Debugger.cpp | 4++++
5 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp @@ -2807,4 +2807,10 @@ void ChromeUtils::EncodeURIForSrcset(GlobalObject&, const nsACString& aIn, } } +void ChromeUtils::GetLastOOMStackTrace(GlobalObject& aGlobal, + nsAString& aRetval) { + JSContext* cx = aGlobal.Context(); + aRetval = NS_ConvertUTF8toUTF16(JS_GetLastOOMStackTrace(cx)); +} + } // namespace mozilla::dom diff --git a/dom/base/ChromeUtils.h b/dom/base/ChromeUtils.h @@ -347,6 +347,7 @@ class ChromeUtils { static Nullable<bool> GetGlobalWindowCommandEnabled(GlobalObject&, const nsACString& aName); + static void GetLastOOMStackTrace(GlobalObject& aGlobal, nsAString& aRetval); static void EncodeURIForSrcset(GlobalObject&, const nsACString& aIn, nsACString& aOut); diff --git a/dom/chrome-webidl/ChromeUtils.webidl b/dom/chrome-webidl/ChromeUtils.webidl @@ -864,6 +864,11 @@ partial namespace ChromeUtils { [Throws] Promise<imgIContainer> fetchDecodedImage(URI uri, MozChannel channel); + + // Returns the stack trace captured from the most recent out-of-memory exception, + // or null if no OOM stack trace is available. The stack trace shows the JavaScript + // call stack at the time the out-of-memory condition occurred + DOMString getLastOOMStackTrace(); }; /* diff --git a/js/public/Debug.h b/js/public/Debug.h @@ -29,6 +29,8 @@ class Debugger; extern JS_PUBLIC_API bool JS_DefineDebuggerObject(JSContext* cx, JS::HandleObject obj); +extern JS_PUBLIC_API const char* JS_GetLastOOMStackTrace(JSContext* cx); + // If the JS execution tracer is running, this will generate a // ENTRY_KIND_LABEL_ENTER entry with the specified label. // The consumer of the trace can then, for instance, correlate all code running diff --git a/js/src/debugger/Debugger.cpp b/js/src/debugger/Debugger.cpp @@ -7411,6 +7411,10 @@ extern JS_PUBLIC_API bool JS_DefineDebuggerObject(JSContext* cx, return true; } +extern JS_PUBLIC_API const char* JS_GetLastOOMStackTrace(JSContext* cx) { + return cx->getOOMStackTrace(); +} + JS_PUBLIC_API bool JS::dbg::IsDebugger(JSObject& obj) { /* We only care about debugger objects, so CheckedUnwrapStatic is OK. */ JSObject* unwrapped = CheckedUnwrapStatic(&obj);