1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-29 02:32:27 +01:00

Fix Firefox exploding with OOM errors when stringifying certain functions.

This commit is contained in:
Kris Maglione
2011-08-23 02:03:18 -04:00
parent 6ca4253ddf
commit ee55f89823
2 changed files with 23 additions and 2 deletions

View File

@@ -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 <span highlight="Number">{str}</span>;

View File

@@ -898,7 +898,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
keys.push([i, <>{key}{noVal ? "" : <>: {value}</>}&#x0a;</>]);
}
}
catch (e) {}
catch (e) {
util.reportError(e);
}
function compare(a, b) {
if (!isNaN(a[0]) && !isNaN(b[0]))