From ee55f89823d9d890f3baaa220c9d12a77fa66908 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 23 Aug 2011 02:03:18 -0400 Subject: [PATCH] Fix Firefox exploding with OOM errors when stringifying certain functions. --- common/modules/template.jsm | 21 ++++++++++++++++++++- common/modules/util.jsm | 4 +++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/common/modules/template.jsm b/common/modules/template.jsm index d232855e..852dd2e8 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -255,13 +255,32 @@ var Template = Module("Template", { })(), template[help ? "HelpLink" : "helpLink"]); }, + // Fixes some strange stack rewinds on NS_ERROR_OUT_OF_MEMORY + // exceptions that we can't catch. + stringify: function (arg) { + if (!callable(arg)) + return String(arg); + + try { + this._sandbox.arg = arg; + return Cu.evalInSandbox("String(arg)", this._sandbox); + } + finally { + this._sandbox.arg = null; + } + }, + + _sandbox: Class.Memoize(function () Cu.Sandbox(this, { wantXrays: false })), + // if "processStrings" is true, any passed strings will be surrounded by " and // any line breaks are displayed as \n highlight: function highlight(arg, processStrings, clip) { XML.ignoreWhitespace = false; XML.prettyPrinting = false; // some objects like window.JSON or getBrowsers()._browsers need the try/catch try { - let str = clip ? util.clip(String(arg), clip) : String(arg); + let str = this.stringify(arg); + if (clip) + str = util.clip(str, clip); switch (arg == null ? "undefined" : typeof arg) { case "number": return {str}; diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 383a9e5e..63fb0c3b 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -898,7 +898,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), keys.push([i, <>{key}{noVal ? "" : <>: {value}} ]); } } - catch (e) {} + catch (e) { + util.reportError(e); + } function compare(a, b) { if (!isNaN(a[0]) && !isNaN(b[0]))