aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-06-09 22:29:32 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-06-09 22:29:32 +0800
commitfda49f2b5216c7d5655d19efe54651593874adf8 (patch)
tree1ff3b8badd7f6b6b3f90b7a885dbad60d960d193
parentc71ab2a6a33685af5097aad86105cab6f5a5e131 (diff)
parentd6f4c515f5a1fa8818bb82beff24f179a9162b0b (diff)
downloaddexon-fda49f2b5216c7d5655d19efe54651593874adf8.tar
dexon-fda49f2b5216c7d5655d19efe54651593874adf8.tar.gz
dexon-fda49f2b5216c7d5655d19efe54651593874adf8.tar.bz2
dexon-fda49f2b5216c7d5655d19efe54651593874adf8.tar.lz
dexon-fda49f2b5216c7d5655d19efe54651593874adf8.tar.xz
dexon-fda49f2b5216c7d5655d19efe54651593874adf8.tar.zst
dexon-fda49f2b5216c7d5655d19efe54651593874adf8.zip
Merge pull request #1213 from karalabe/polish-console-prettyprinter
jsre: patch up the pretty printer to have a decent look
-rw-r--r--jsre/pp_js.go39
1 files changed, 28 insertions, 11 deletions
diff --git a/jsre/pp_js.go b/jsre/pp_js.go
index 5c09b2586..20821e4a1 100644
--- a/jsre/pp_js.go
+++ b/jsre/pp_js.go
@@ -26,19 +26,19 @@ function pp(object, indent) {
} else if(typeof(object) === "object") {
str += "{\n";
indent += " ";
- var last = getFields(object).pop()
- getFields(object).forEach(function (k) {
- str += indent + k + ": ";
+
+ var fields = getFields(object);
+ var last = fields[fields.length - 1];
+ fields.forEach(function (key) {
+ str += indent + key + ": ";
try {
- str += pp(object[k], indent);
+ str += pp(object[key], indent);
} catch (e) {
str += pp(e, indent);
}
-
- if(k !== last) {
+ if(key !== last) {
str += ",";
}
-
str += "\n";
});
str += indent.substr(2, indent.length) + "}";
@@ -49,7 +49,7 @@ function pp(object, indent) {
} else if(typeof(object) === "number") {
str += "\033[31m" + object;
} else if(typeof(object) === "function") {
- str += "\033[35m[Function]";
+ str += "\033[35m" + object.toString().split(" {")[0];
} else {
str += object;
}
@@ -70,15 +70,32 @@ var redundantFields = [
];
var getFields = function (object) {
- var result = Object.getOwnPropertyNames(object);
+ var members = Object.getOwnPropertyNames(object);
if (object.constructor && object.constructor.prototype) {
- result = result.concat(Object.getOwnPropertyNames(object.constructor.prototype));
+ members = members.concat(Object.getOwnPropertyNames(object.constructor.prototype));
}
- return result.filter(function (field) {
+
+ var fields = members.filter(function (member) {
+ return !isMemberFunction(object, member)
+ }).sort()
+ var funcs = members.filter(function (member) {
+ return isMemberFunction(object, member)
+ }).sort()
+
+ var results = fields.concat(funcs);
+ return results.filter(function (field) {
return redundantFields.indexOf(field) === -1;
});
};
+var isMemberFunction = function(object, member) {
+ try {
+ return typeof(object[member]) === "function";
+ } catch(e) {
+ return false;
+ }
+}
+
var isBigNumber = function (object) {
return typeof BigNumber !== 'undefined' && object instanceof BigNumber;
};