Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote branch 'ry/master' into url-module

  • Loading branch information...
commit 837c2b284a40229120aad4cb4b3b854c481ebdca 2 parents b3b57eb + fd184ee
isaacs authored
Showing with 36 additions and 3 deletions.
  1. +17 −2 lib/sys.js
  2. +19 −1 test/mjsunit/test-sys.js
View
19 lib/sys.js
@@ -92,13 +92,27 @@ 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]);
});
} else {
return formatObject(value, indent, parents, '{}', function(x, f) {
- return f(x) + ': ' + f(value[x]);
+ var child;
+ if (value.__lookupGetter__(x)) {
+ if (value.__lookupSetter__(x)) {
+ child = "[Getter/Setter]";
+ } else {
+ child = "[Getter]";
+ }
+ } else {
+ if (value.__lookupSetter__(x)) {
+ child = "[Setter]";
+ } else {
+ child = f(value[x]);
+ }
+ }
+ return f(x) + ': ' + child;
});
}
return buffer;
@@ -113,6 +127,7 @@ var formatter = function(value, indent, parents) {
var formatObject = function(obj, indent, parents, parenthesis, entryFormatter) {
var buffer = parenthesis[0];
var values = [];
+ var x;
var localFormatter = function(value) {
return formatter(value, indent + ' ', parents);
View
20 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,23 @@ 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 = {}
+// Dynamic properties
+assert.equal(
+ "{\n \"readonly\": [Getter],\n \"readwrite\": [Getter/Setter],\n \"writeonly\": [Setter]\n}",
+ inspect({get readonly(){},get readwrite(){},set readwrite(val){},set writeonly(val){}})
+);
+
+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));
+
+// Array with dynamic properties
+value = [1,2,3];
+value.__defineGetter__('growingLength', function () { this.push(true); return this.length; });
+assert.equal(
+ "{\n \"0\": 1,\n \"1\": 2,\n \"2\": 3,\n \"growingLength\": [Getter]\n}",
+ inspect(value)
+);
Please sign in to comment.
Something went wrong with that request. Please try again.