From 732c6f2036a955e32e3f981f5681daefaeaf99a8 Mon Sep 17 00:00:00 2001 From: Tim Caswell Date: Thu, 31 Dec 2009 11:41:35 -0600 Subject: [PATCH] Fix inspect for the special case of an Object that inherits from Array, but has other properties. --- lib/sys.js | 2 +- test/mjsunit/test-sys.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/sys.js b/lib/sys.js index a2070b1fb4..b255cd6cec 100644 --- a/lib/sys.js +++ b/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]); }); diff --git a/test/mjsunit/test-sys.js b/test/mjsunit/test-sys.js index 1c114d8d2a..893efd0e3b 100644 --- a/test/mjsunit/test-sys.js +++ b/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)); \ No newline at end of file