diff --git a/content/ui.js b/content/ui.js index b136888b..915046e7 100644 --- a/content/ui.js +++ b/content/ui.js @@ -310,12 +310,8 @@ function CommandLine() //{{{ if (typeof arg === "object") arg = util.objectToString(arg, useColor); - else if (typeof arg === "function") - arg = util.escapeHTML(arg.toString()); - else if (typeof arg === "number" || typeof arg === "boolean") - arg = "" + arg; - else if (typeof arg === "undefined") - arg = "undefined"; + else if (typeof arg != "xml") + arg = String(arg); return arg; } diff --git a/content/util.js b/content/util.js index 60a60e4c..2c106b0e 100644 --- a/content/util.js +++ b/content/util.js @@ -287,6 +287,7 @@ const util = { //{{{ * when they expect :map :foo. */ XML.prettyPrinting = false; + XML.ignoreWhitespace = false; if (object === null) return "null"; @@ -294,45 +295,53 @@ const util = { //{{{ if (typeof object != "object") return false; - var string = ""; - var obj = ""; try { // for window.JSON - obj = object.toString(); + var obj = String(object); } catch (e) { - obj = ""; + obj = "[Object]"; } - - if (color) - obj = {obj}.toXMLString(); - string += obj + "::\n"; + let string = <>{obj}::
; let keys = []; 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) { - let value = ""; + let value = ]]>; try { value = object[i]; } catch (e) {} - - value = template.highlight(value, true); - if (color) + if (!hasValue) { - value = value.toXMLString(); - i = {i}.toXMLString(); + if(i instanceof Array && i.length == 2) + [i, value] = i; + else + var noVal = true; } - keys.push(i + ": " + value); + value = template.highlight(value, true); + // FIXME: Inline style. + key = {i}; + if (!isNaN(i)) + i = parseInt(i); + keys.push([i, <>{key}{noVal ? "" : <>:{value}}
]); } } 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)