fix: JSON.stringify() throws StackOverflow for Java objects

This commit is contained in:
hyb1996
2017-11-02 15:27:49 +08:00
parent 9b9b37b940
commit 37445b7905
8 changed files with 546 additions and 9 deletions

View File

@@ -24,7 +24,9 @@ exports.format = function(f) {
if (!isString(f)) {
var objects = [];
for (var i = 0; i < arguments.length; i++) {
objects.push(inspect(arguments[i]));
var v = isJavaObject(arguments[i]) ? arguments[i].toString() :
arguments[i];
objects.push(inspect(v));
}
return objects.join(' ');
}
@@ -445,6 +447,10 @@ function reduceToSingleString(output, base, braces) {
}
function isJavaObject(obj){
return !!obj.getClass;
}
// NOTE: These type checking functions intentionally don't use `instanceof`
// because it is fragile and can be easily faked with `Object.create()`.
function isArray(ar) {