diff --git a/lib/sys.js b/lib/sys.js index 4066ab917b..5ad68e4926 100644 --- a/lib/sys.js +++ b/lib/sys.js @@ -95,11 +95,11 @@ exports.inspect = function (obj, showHidden, depth) { return braces[0] + base + braces[1]; } - if( recurseTimes < 0 ) { + if (recurseTimes < 0) { if (value instanceof RegExp) { return '' + value; } else { - return "[object Object]"; + return "[Object]"; } } @@ -129,10 +129,17 @@ exports.inspect = function (obj, showHidden, depth) { else { str = format(value[key], recurseTimes - 1); } - if( str.indexOf('\n') > -1 ) { - str = '\n' + str.split('\n').map(function(line) { + if (str.indexOf('\n') > -1) { + if (value instanceof Array) { + str = str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n').substr(2); + } + else { + str = '\n' + str.split('\n').map(function(line) { return ' ' + line; }).join('\n'); + } } } else { str = '[Circular]'; @@ -143,7 +150,7 @@ exports.inspect = function (obj, showHidden, depth) { return str; } name = JSON.stringify('' + key); - if( name.match(/^"([a-zA-Z_0-9]+)"$/) ) { + if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { name = name.substr(1, name.length-2); } else { @@ -154,13 +161,17 @@ exports.inspect = function (obj, showHidden, depth) { return name + ": " + str; }); - + var numLinesEst = 0; var length = output.reduce(function(prev, cur) { + numLinesEst++; + if( cur.indexOf('\n') >= 0 ) { + numLinesEst++; + } return prev + cur.length + 1; },0); - if( length > 50 ) { - output = braces[0] + (base === '' ? '' : base + '\n,') + ' ' + output.join('\n, ') + '\n' +braces[1]; + if (length > 50) { + output = braces[0] + (base === '' ? '' : base + '\n,') + ' ' + output.join('\n, ') + (numLinesEst > 1 ? '\n' : ' ') + braces[1]; } else { output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; diff --git a/test/simple/test-sys.js b/test/simple/test-sys.js index 06fd6943e0..d2b50a3a1a 100644 --- a/test/simple/test-sys.js +++ b/test/simple/test-sys.js @@ -26,11 +26,11 @@ assert.equal('{ a: [Function] }', inspect({a: function() {}})); assert.equal('{ a: 1, b: 2 }', inspect({a: 1, b: 2})); assert.equal('{ a: {} }', inspect({'a': {}})); assert.equal('{ a: { b: 2 } }', inspect({'a': {'b': 2}})); -assert.equal('{ a: { b: { c: [object Object] } } }', inspect({'a': {'b': { 'c': { 'd': 2 }}}})); +assert.equal('{ a: { b: { c: [Object] } } }', inspect({'a': {'b': { 'c': { 'd': 2 }}}})); assert.equal('{ a: { b: { c: { d: 2 } } } }', inspect({'a': {'b': { 'c': { 'd': 2 }}}}, false, null)); assert.equal('[ 1, 2, 3, [length]: 3 ]', inspect([1,2,3], true)); -assert.equal('{ a: [object Object] }', inspect({'a': {'b': { 'c': 2}}},false,0)); -assert.equal('{ a: { b: [object Object] } }', inspect({'a': {'b': { 'c': 2}}},false,1)); +assert.equal('{ a: [Object] }', inspect({'a': {'b': { 'c': 2}}},false,0)); +assert.equal('{ a: { b: [Object] } }', inspect({'a': {'b': { 'c': 2}}},false,1)); assert.equal("{ visible: 1 }", inspect(Object.create({}, {visible:{value:1,enumerable:true},hidden:{value:2}})) );