mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 13:22:28 +01:00
Make objectToString work better with generators and arrays
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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/>
</>;
|
||||||
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/>
</>]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user