diff --git a/content/liberator.js b/content/liberator.js index 6af476ae..9881ab78 100644 --- a/content/liberator.js +++ b/content/liberator.js @@ -1095,7 +1095,7 @@ const liberator = (function () //{{{ Components.utils.reportError(error); let obj = { toString: function () error.toString(), - stack: { toString: function () "\n" + error.stack.replace(/^/mg, "\t") } + stack: <>{error.stack.replace(/^/mg, "\t")} }; for (let [k, v] in Iterator(error)) { diff --git a/content/template.js b/content/template.js index 89547a19..10f6f8a5 100644 --- a/content/template.js +++ b/content/template.js @@ -64,28 +64,31 @@ const template = { ; }, + filter: function (str) {str}, + // if "processStrings" is true, any passed strings will be surrounded by " and // any line breaks are displayed as \n - highlight: function highlight(arg, processStrings) + highlight: function highlight(arg, processStrings, clip) { // some objects like window.JSON or getBrowsers()._browsers need the try/catch + let str = clip ? util.clip(String(arg), clip) : String(arg); try { switch (arg == null ? "undefined" : typeof arg) { case "number": - return {arg}; + return {str}; case "string": if (processStrings) - arg = <>{util.escapeString(arg)}; - return {arg}; + str = <>{util.escapeString(str)}; + return {str}; case "boolean": - return {arg}; + return {str}; case "function": // Vim generally doesn't like /foo*/, because */ looks like a comment terminator. // Using /foo*(:?)/ instead. if (processStrings) - return {String(arg).replace(/\{(.|\n)*(?:)/g, "{ ... }")}; + return {str.replace(/\{(.|\n)*(?:)/g, "{ ... }")}; return <>{arg}; case "undefined": return {arg}; @@ -95,8 +98,10 @@ const template = { if (/^\[JavaPackage.*\]$/.test(arg)) return <>[JavaPackage]; if (processStrings && false) - arg = String(arg).replace("\n", "\\n", "g"); - return {arg}; + str = template.highlightFilter(str, "\n", function () ^J); + return {str}; + case "xml": + return arg; default: return ]]>; } @@ -107,7 +112,7 @@ const template = { } }, - highlightFilter: function highlightFilter(str, filter) + highlightFilter: function highlightFilter(str, filter, highlight) { if (typeof str == "xml") return str; @@ -122,10 +127,10 @@ const template = { yield [start, filter.length]; start += filter.length; } - })()); + })(), highlight || template.filter); }, - highlightRegexp: function highlightRegexp(str, re) + highlightRegexp: function highlightRegexp(str, re, highlight) { if (typeof str == "xml") return str; @@ -134,10 +139,10 @@ const template = { { while (res = re.exec(str)) yield [res.index, res[0].length]; - })()); + })(), highlight || template.filter); }, - highlightSubstrings: function highlightSubstrings(str, iter) + highlightSubstrings: function highlightSubstrings(str, iter, highlight) { if (typeof str == "xml") return str; @@ -151,7 +156,7 @@ const template = { { XML.ignoreWhitespace = false; s += <>{str.substring(start, i)}; - s += {str.substr(i, length)}; + s += highlight(str.substr(i, length)); start = i + length; } return s + <>{str.substr(start)}; diff --git a/content/util.js b/content/util.js index dd68e02c..54f6920a 100644 --- a/content/util.js +++ b/content/util.js @@ -305,6 +305,7 @@ const util = { //{{{ { obj = "[Object]"; } + obj = template.highlightFilter(util.clip(obj, 150), "\n", !color ? function () "^J" : function () ^J); let string = <>{obj}::
; let keys = []; @@ -326,7 +327,7 @@ const util = { //{{{ else var noVal = true; } - value = template.highlight(value, true); + value = template.highlight(value, true, 150); // FIXME: Inline style. key = {i}; if (!isNaN(i))