1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 09:17:59 +01:00

Improve objectToString a bit

This commit is contained in:
Kris Maglione
2008-11-24 00:22:28 +00:00
parent 7d8eb88954
commit 0c003d63d6
3 changed files with 22 additions and 16 deletions

View File

@@ -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))
{

View File

@@ -64,28 +64,31 @@ const template = {
</ul>;
},
filter: function (str) <span class="hl-Filter">{str}</span>,
// 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 <span class="hl-Number">{arg}</span>;
return <span class="hl-Number">{str}</span>;
case "string":
if (processStrings)
arg = <>{util.escapeString(arg)}</>;
return <span class="hl-String">{arg}</span>;
str = <>{util.escapeString(str)}</>;
return <span class="hl-String">{str}</span>;
case "boolean":
return <span class="hl-Boolean">{arg}</span>;
return <span class="hl-Boolean">{str}</span>;
case "function":
// Vim generally doesn't like /foo*/, because */ looks like a comment terminator.
// Using /foo*(:?)/ instead.
if (processStrings)
return <span class="hl-Function">{String(arg).replace(/\{(.|\n)*(?:)/g, "{ ... }")}</span>;
return <span class="hl-Function">{str.replace(/\{(.|\n)*(?:)/g, "{ ... }")}</span>;
return <>{arg}</>;
case "undefined":
return <span class="hl-Null">{arg}</span>;
@@ -95,8 +98,10 @@ const template = {
if (/^\[JavaPackage.*\]$/.test(arg))
return <>[JavaPackage]</>;
if (processStrings && false)
arg = String(arg).replace("\n", "\\n", "g");
return <span class="hl-Object">{arg}</span>;
str = template.highlightFilter(str, "\n", function () <span class="hl-NonText">^J</span>);
return <span class="hl-Object">{str}</span>;
case "xml":
return arg;
default:
return <![CDATA[<unknown type>]]>;
}
@@ -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 += <span class="hl-Filter">{str.substr(i, length)}</span>;
s += highlight(str.substr(i, length));
start = i + length;
}
return s + <>{str.substr(start)}</>;

View File

@@ -305,6 +305,7 @@ const util = { //{{{
{
obj = "[Object]";
}
obj = template.highlightFilter(util.clip(obj, 150), "\n", !color ? function () "^J" : function () <span class="hl-NonText">^J</span>);
let string = <><span class="hl-Title hl-Object">{obj}</span>::<br/>&#xa;</>;
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 = <span style="font-weight: bold;">{i}</span>;
if (!isNaN(i))