mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 13:42:27 +01:00
Improve objectToString a bit
This commit is contained in:
@@ -1095,7 +1095,7 @@ const liberator = (function () //{{{
|
|||||||
Components.utils.reportError(error);
|
Components.utils.reportError(error);
|
||||||
let obj = {
|
let obj = {
|
||||||
toString: function () error.toString(),
|
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))
|
for (let [k, v] in Iterator(error))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -64,28 +64,31 @@ const template = {
|
|||||||
</ul>;
|
</ul>;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
filter: function (str) <span class="hl-Filter">{str}</span>,
|
||||||
|
|
||||||
// if "processStrings" is true, any passed strings will be surrounded by " and
|
// if "processStrings" is true, any passed strings will be surrounded by " and
|
||||||
// any line breaks are displayed as \n
|
// 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
|
// some objects like window.JSON or getBrowsers()._browsers need the try/catch
|
||||||
|
let str = clip ? util.clip(String(arg), clip) : String(arg);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
switch (arg == null ? "undefined" : typeof arg)
|
switch (arg == null ? "undefined" : typeof arg)
|
||||||
{
|
{
|
||||||
case "number":
|
case "number":
|
||||||
return <span class="hl-Number">{arg}</span>;
|
return <span class="hl-Number">{str}</span>;
|
||||||
case "string":
|
case "string":
|
||||||
if (processStrings)
|
if (processStrings)
|
||||||
arg = <>{util.escapeString(arg)}</>;
|
str = <>{util.escapeString(str)}</>;
|
||||||
return <span class="hl-String">{arg}</span>;
|
return <span class="hl-String">{str}</span>;
|
||||||
case "boolean":
|
case "boolean":
|
||||||
return <span class="hl-Boolean">{arg}</span>;
|
return <span class="hl-Boolean">{str}</span>;
|
||||||
case "function":
|
case "function":
|
||||||
// Vim generally doesn't like /foo*/, because */ looks like a comment terminator.
|
// Vim generally doesn't like /foo*/, because */ looks like a comment terminator.
|
||||||
// Using /foo*(:?)/ instead.
|
// Using /foo*(:?)/ instead.
|
||||||
if (processStrings)
|
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}</>;
|
return <>{arg}</>;
|
||||||
case "undefined":
|
case "undefined":
|
||||||
return <span class="hl-Null">{arg}</span>;
|
return <span class="hl-Null">{arg}</span>;
|
||||||
@@ -95,8 +98,10 @@ const template = {
|
|||||||
if (/^\[JavaPackage.*\]$/.test(arg))
|
if (/^\[JavaPackage.*\]$/.test(arg))
|
||||||
return <>[JavaPackage]</>;
|
return <>[JavaPackage]</>;
|
||||||
if (processStrings && false)
|
if (processStrings && false)
|
||||||
arg = String(arg).replace("\n", "\\n", "g");
|
str = template.highlightFilter(str, "\n", function () <span class="hl-NonText">^J</span>);
|
||||||
return <span class="hl-Object">{arg}</span>;
|
return <span class="hl-Object">{str}</span>;
|
||||||
|
case "xml":
|
||||||
|
return arg;
|
||||||
default:
|
default:
|
||||||
return <![CDATA[<unknown type>]]>;
|
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")
|
if (typeof str == "xml")
|
||||||
return str;
|
return str;
|
||||||
@@ -122,10 +127,10 @@ const template = {
|
|||||||
yield [start, filter.length];
|
yield [start, filter.length];
|
||||||
start += filter.length;
|
start += filter.length;
|
||||||
}
|
}
|
||||||
})());
|
})(), highlight || template.filter);
|
||||||
},
|
},
|
||||||
|
|
||||||
highlightRegexp: function highlightRegexp(str, re)
|
highlightRegexp: function highlightRegexp(str, re, highlight)
|
||||||
{
|
{
|
||||||
if (typeof str == "xml")
|
if (typeof str == "xml")
|
||||||
return str;
|
return str;
|
||||||
@@ -134,10 +139,10 @@ const template = {
|
|||||||
{
|
{
|
||||||
while (res = re.exec(str))
|
while (res = re.exec(str))
|
||||||
yield [res.index, res[0].length];
|
yield [res.index, res[0].length];
|
||||||
})());
|
})(), highlight || template.filter);
|
||||||
},
|
},
|
||||||
|
|
||||||
highlightSubstrings: function highlightSubstrings(str, iter)
|
highlightSubstrings: function highlightSubstrings(str, iter, highlight)
|
||||||
{
|
{
|
||||||
if (typeof str == "xml")
|
if (typeof str == "xml")
|
||||||
return str;
|
return str;
|
||||||
@@ -151,7 +156,7 @@ const template = {
|
|||||||
{
|
{
|
||||||
XML.ignoreWhitespace = false;
|
XML.ignoreWhitespace = false;
|
||||||
s += <>{str.substring(start, i)}</>;
|
s += <>{str.substring(start, i)}</>;
|
||||||
s += <span class="hl-Filter">{str.substr(i, length)}</span>;
|
s += highlight(str.substr(i, length));
|
||||||
start = i + length;
|
start = i + length;
|
||||||
}
|
}
|
||||||
return s + <>{str.substr(start)}</>;
|
return s + <>{str.substr(start)}</>;
|
||||||
|
|||||||
@@ -305,6 +305,7 @@ const util = { //{{{
|
|||||||
{
|
{
|
||||||
obj = "[Object]";
|
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/>
</>;
|
let string = <><span class="hl-Title hl-Object">{obj}</span>::<br/>
</>;
|
||||||
|
|
||||||
let keys = [];
|
let keys = [];
|
||||||
@@ -326,7 +327,7 @@ const util = { //{{{
|
|||||||
else
|
else
|
||||||
var noVal = true;
|
var noVal = true;
|
||||||
}
|
}
|
||||||
value = template.highlight(value, true);
|
value = template.highlight(value, true, 150);
|
||||||
// FIXME: Inline style.
|
// FIXME: Inline style.
|
||||||
key = <span style="font-weight: bold;">{i}</span>;
|
key = <span style="font-weight: bold;">{i}</span>;
|
||||||
if (!isNaN(i))
|
if (!isNaN(i))
|
||||||
|
|||||||
Reference in New Issue
Block a user