Browse Source

Fix inspect for the special case of an Object that inherits from Array, but has other properties.

v0.7.4-release
Tim Caswell 15 years ago
committed by Ryan Dahl
parent
commit
732c6f2036
  1. 2
      lib/sys.js
  2. 6
      test/mjsunit/test-sys.js

2
lib/sys.js

@ -92,7 +92,7 @@ var formatter = function(value, indent, parents) {
if (parents.indexOf(value) >= 0) return '[Circular]';
parents.push(value);
if (value instanceof Array) {
if (value instanceof Array && Object.keys(value).length === value.length) {
return formatObject(value, indent, parents, '[]', function(x, f) {
return f(value[x]);
});

6
test/mjsunit/test-sys.js

@ -13,6 +13,7 @@ assert.equal('null', inspect(null));
assert.equal("\"\\n\\u0001\"", inspect("\n\u0001"));
assert.equal('[]', inspect([]));
assert.equal('[]', inspect(Object.create([])));
assert.equal('[\n 1,\n 2\n]', inspect([1, 2]));
assert.equal('[\n 1,\n [\n 2,\n 3\n ]\n]', inspect([1, [2, 3]]));
@ -23,6 +24,9 @@ assert.equal('{\n "a": 1,\n "b": 2\n}', inspect({a: 1, b: 2}));
assert.equal('{\n "a": {}\n}', inspect({'a': {}}));
assert.equal('{\n "a": {\n "b": 2\n }\n}', inspect({'a': {'b': 2}}));
var value = {}
var value = {};
value['a'] = value;
assert.equal('{\n "a": [Circular]\n}', inspect(value));
value = Object.create([]);
value.push(1);
assert.equal('{\n "0": 1,\n "length": 1\n}', inspect(value));
Loading…
Cancel
Save