diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-05-14 02:53:22 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-05-20 14:20:59 +0200 |
commit | 9f71dbc33466f26f3fa9a797ace8aa1f285cb890 (patch) | |
tree | 3b23696e622d2adffd64c72c269e68eacc81c204 /test/parallel | |
parent | 5518664d41b8916dfbe2eca2180d760db632748e (diff) | |
download | android-node-v8-9f71dbc33466f26f3fa9a797ace8aa1f285cb890.tar.gz android-node-v8-9f71dbc33466f26f3fa9a797ace8aa1f285cb890.tar.bz2 android-node-v8-9f71dbc33466f26f3fa9a797ace8aa1f285cb890.zip |
util: include reference anchor for circular structures
This adds a reference anchor to circular structures when using
`util.inspect`. That way it's possible to identify with what object
the circular reference corresponds too.
PR-URL: https://github.com/nodejs/node/pull/27685
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'test/parallel')
-rw-r--r-- | test/parallel/test-assert.js | 3 | ||||
-rw-r--r-- | test/parallel/test-util-format.js | 24 | ||||
-rw-r--r-- | test/parallel/test-util-inspect.js | 46 |
3 files changed, 48 insertions, 25 deletions
diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 34dc8fabde..d9ba3716a2 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -298,7 +298,8 @@ testAssertionMessage({}, '{}'); testAssertionMessage([1, 2, 3], '[\n+ 1,\n+ 2,\n+ 3\n+ ]'); testAssertionMessage(function f() {}, '[Function: f]'); testAssertionMessage(function() {}, '[Function (anonymous)]'); -testAssertionMessage(circular, '{\n+ x: [Circular],\n+ y: 1\n+ }'); +testAssertionMessage(circular, + '<ref *1> {\n+ x: [Circular *1],\n+ y: 1\n+ }'); testAssertionMessage({ a: undefined, b: null }, '{\n+ a: undefined,\n+ b: null\n+ }'); testAssertionMessage({ a: NaN, b: Infinity, c: -Infinity }, diff --git a/test/parallel/test-util-format.js b/test/parallel/test-util-format.js index 5b012dd64d..a83a6f3c20 100644 --- a/test/parallel/test-util-format.js +++ b/test/parallel/test-util-format.js @@ -195,10 +195,10 @@ assert.strictEqual( '{\n' + ' foo: \'bar\',\n' + ' foobar: 1,\n' + - ' func: [Function: func] {\n' + + ' func: <ref *1> [Function: func] {\n' + ' [length]: 0,\n' + ' [name]: \'func\',\n' + - ' [prototype]: func { [constructor]: [Circular] }\n' + + ' [prototype]: func { [constructor]: [Circular *1] }\n' + ' }\n' + '}'); assert.strictEqual( @@ -208,10 +208,10 @@ assert.strictEqual( ' foobar: 1,\n' + ' func: [\n' + ' {\n' + - ' a: [Function: a] {\n' + + ' a: <ref *1> [Function: a] {\n' + ' [length]: 0,\n' + ' [name]: \'a\',\n' + - ' [prototype]: a { [constructor]: [Circular] }\n' + + ' [prototype]: a { [constructor]: [Circular *1] }\n' + ' }\n' + ' },\n' + ' [length]: 1\n' + @@ -223,10 +223,10 @@ assert.strictEqual( ' foo: \'bar\',\n' + ' foobar: {\n' + ' foo: \'bar\',\n' + - ' func: [Function: func] {\n' + + ' func: <ref *1> [Function: func] {\n' + ' [length]: 0,\n' + ' [name]: \'func\',\n' + - ' [prototype]: func { [constructor]: [Circular] }\n' + + ' [prototype]: func { [constructor]: [Circular *1] }\n' + ' }\n' + ' }\n' + '}'); @@ -235,18 +235,18 @@ assert.strictEqual( '{\n' + ' foo: \'bar\',\n' + ' foobar: 1,\n' + - ' func: [Function: func] {\n' + + ' func: <ref *1> [Function: func] {\n' + ' [length]: 0,\n' + ' [name]: \'func\',\n' + - ' [prototype]: func { [constructor]: [Circular] }\n' + + ' [prototype]: func { [constructor]: [Circular *1] }\n' + ' }\n' + '} {\n' + ' foo: \'bar\',\n' + ' foobar: 1,\n' + - ' func: [Function: func] {\n' + + ' func: <ref *1> [Function: func] {\n' + ' [length]: 0,\n' + ' [name]: \'func\',\n' + - ' [prototype]: func { [constructor]: [Circular] }\n' + + ' [prototype]: func { [constructor]: [Circular *1] }\n' + ' }\n' + '}'); assert.strictEqual( @@ -254,10 +254,10 @@ assert.strictEqual( '{\n' + ' foo: \'bar\',\n' + ' foobar: 1,\n' + - ' func: [Function: func] {\n' + + ' func: <ref *1> [Function: func] {\n' + ' [length]: 0,\n' + ' [name]: \'func\',\n' + - ' [prototype]: func { [constructor]: [Circular] }\n' + + ' [prototype]: func { [constructor]: [Circular *1] }\n' + ' }\n' + '} %o'); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index a1ce4903de..16ea2a40e8 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -338,7 +338,7 @@ assert.strictEqual( const value = {}; value.a = value; - assert.strictEqual(util.inspect(value), '{ a: [Circular] }'); + assert.strictEqual(util.inspect(value), '<ref *1> { a: [Circular *1] }'); } // Array with dynamic properties. @@ -993,7 +993,7 @@ if (typeof Symbol !== 'undefined') { { const set = new Set(); set.add(set); - assert.strictEqual(util.inspect(set), 'Set { [Circular] }'); + assert.strictEqual(util.inspect(set), '<ref *1> Set { [Circular *1] }'); } // Test Map. @@ -1011,12 +1011,32 @@ if (typeof Symbol !== 'undefined') { { const map = new Map(); map.set(map, 'map'); - assert.strictEqual(util.inspect(map), "Map { [Circular] => 'map' }"); + assert.strictEqual(inspect(map), "<ref *1> Map { [Circular *1] => 'map' }"); map.set(map, map); - assert.strictEqual(util.inspect(map), 'Map { [Circular] => [Circular] }'); + assert.strictEqual( + inspect(map), + '<ref *1> Map { [Circular *1] => [Circular *1] }' + ); map.delete(map); map.set('map', map); - assert.strictEqual(util.inspect(map), "Map { 'map' => [Circular] }"); + assert.strictEqual(inspect(map), "<ref *1> Map { 'map' => [Circular *1] }"); +} + +// Test multiple circular references. +{ + const obj = {}; + obj.a = [obj]; + obj.b = {}; + obj.b.inner = obj.b; + obj.b.obj = obj; + + assert.strictEqual( + inspect(obj), + '<ref *1> {\n' + + ' a: [ [Circular *1] ],\n' + + ' b: <ref *2> { inner: [Circular *2], obj: [Circular *1] }\n' + + '}' + ); } // Test Promise. @@ -1214,7 +1234,9 @@ if (typeof Symbol !== 'undefined') { arr[0][0][0] = { a: 2 }; assert.strictEqual(util.inspect(arr), '[ [ [ [Object] ] ] ]'); arr[0][0][0] = arr; - assert.strictEqual(util.inspect(arr), '[ [ [ [Circular] ] ] ]'); + assert.strictEqual(util.inspect(arr), '<ref *1> [ [ [ [Circular *1] ] ] ]'); + arr[0][0][0] = arr[0][0]; + assert.strictEqual(util.inspect(arr), '[ [ <ref *1> [ [Circular *1] ] ] ]'); } // Corner cases. @@ -1608,7 +1630,7 @@ util.inspect(process); ' 2,', ' [length]: 2', ' ]', - ' } => [Map Iterator] {', + ' } => <ref *1> [Map Iterator] {', ' Uint8Array [', ' [BYTES_PER_ELEMENT]: 1,', ' [length]: 0,', @@ -1619,7 +1641,7 @@ util.inspect(process); ' foo: true', ' }', ' ],', - ' [Circular]', + ' [Circular *1]', ' },', ' [size]: 2', '}' @@ -1647,7 +1669,7 @@ util.inspect(process); ' [byteOffset]: 0,', ' [buffer]: ArrayBuffer { byteLength: 0, foo: true }', ' ],', - ' [Set Iterator] { [ 1, 2, [length]: 2 ] } => [Map Iterator] {', + ' [Set Iterator] { [ 1, 2, [length]: 2 ] } => <ref *1> [Map Iterator] {', ' Uint8Array [', ' [BYTES_PER_ELEMENT]: 1,', ' [length]: 0,', @@ -1655,7 +1677,7 @@ util.inspect(process); ' [byteOffset]: 0,', ' [buffer]: ArrayBuffer { byteLength: 0, foo: true }', ' ],', - ' [Circular]', + ' [Circular *1]', ' },', ' [size]: 2', '}' @@ -1687,7 +1709,7 @@ util.inspect(process); ' [Set Iterator] {', ' [ 1,', ' 2,', - ' [length]: 2 ] } => [Map Iterator] {', + ' [length]: 2 ] } => <ref *1> [Map Iterator] {', ' Uint8Array [', ' [BYTES_PER_ELEMENT]: 1,', ' [length]: 0,', @@ -1696,7 +1718,7 @@ util.inspect(process); ' [buffer]: ArrayBuffer {', ' byteLength: 0,', ' foo: true } ],', - ' [Circular] },', + ' [Circular *1] },', ' [size]: 2 }' ].join('\n'); |