1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 10:57:58 +01:00

Make objectToString work better with generators and arrays

This commit is contained in:
Kris Maglione
2008-11-01 19:10:28 +00:00
parent dcff71b235
commit 6be68bad2c
2 changed files with 27 additions and 22 deletions

View File

@@ -310,12 +310,8 @@ function CommandLine() //{{{
if (typeof arg === "object") if (typeof arg === "object")
arg = util.objectToString(arg, useColor); arg = util.objectToString(arg, useColor);
else if (typeof arg === "function") else if (typeof arg != "xml")
arg = util.escapeHTML(arg.toString()); arg = String(arg);
else if (typeof arg === "number" || typeof arg === "boolean")
arg = "" + arg;
else if (typeof arg === "undefined")
arg = "undefined";
return arg; return arg;
} }

View File

@@ -287,6 +287,7 @@ const util = { //{{{
* when they expect :map <C-f> :foo. * when they expect :map <C-f> :foo.
*/ */
XML.prettyPrinting = false; XML.prettyPrinting = false;
XML.ignoreWhitespace = false;
if (object === null) if (object === null)
return "null"; return "null";
@@ -294,45 +295,53 @@ const util = { //{{{
if (typeof object != "object") if (typeof object != "object")
return false; return false;
var string = "";
var obj = "";
try try
{ // for window.JSON { // for window.JSON
obj = object.toString(); var obj = String(object);
} }
catch (e) catch (e)
{ {
obj = "<Object>"; obj = "[Object]";
} }
let string = <><span class="hl-Title hl-Object">{obj}</span>::<br/>&#xa;</>;
if (color)
obj = <span class="hl-Title hl-Object">{obj}</span>.toXMLString();
string += obj + "::\n";
let keys = []; let keys = [];
try // window.content often does not want to be queried with "var i in object" try // window.content often does not want to be queried with "var i in object"
{ {
let hasValue = !("__iterator__" in object);
for (let i in object) for (let i in object)
{ {
let value = "<no value>"; let value = <![CDATA[<no value>]]>;
try try
{ {
value = object[i]; value = object[i];
} }
catch (e) {} catch (e) {}
if (!hasValue)
value = template.highlight(value, true);
if (color)
{ {
value = value.toXMLString(); if(i instanceof Array && i.length == 2)
i = <span style="font-weight: bold;">{i}</span>.toXMLString(); [i, value] = i;
else
var noVal = true;
} }
keys.push(i + ": " + value); value = template.highlight(value, true);
// FIXME: Inline style.
key = <span style="font-weight: bold;">{i}</span>;
if (!isNaN(i))
i = parseInt(i);
keys.push([i, <>{key}{noVal ? "" : <>:{value}</>}<br/>&#xa;</>]);
} }
} }
catch (e) {} catch (e) {}
return string + keys.sort().join("\n") + "\n"; function compare(a, b)
{
if (!isNaN(a[0]) && !isNaN(b[0]))
return a[0] - b[0];
return String.localeCompare(a, b);
}
string += template.map(keys.sort(compare), function (f) f[1]);
return color ? string : [s for each (s in string)].join("");
}, },
range: function (start, end) range: function (start, end)