From 613a63b225a6e50890361fb701b803eb915b9eef Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Sun, 19 Apr 2015 20:29:59 -0400 Subject: [PATCH 1/8] util: support inspecting Map and Set The output format is inspired by Chrome DevTools. --- lib/util.js | 68 +++++++++++++++++++++++++++--- test/parallel/test-util-inspect.js | 14 ++++++ 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/lib/util.js b/lib/util.js index a04c19c7353fdf..653237d88e2ba0 100644 --- a/lib/util.js +++ b/lib/util.js @@ -276,12 +276,24 @@ function formatValue(ctx, value, recurseTimes) { } } - var base = '', array = false, braces = ['{', '}']; + var base = '', braces; - // Make Array say that they are Array if (Array.isArray(value)) { - array = true; braces = ['[', ']']; + } else if (value instanceof Set) { + braces = ['Set {', '}']; + // With `showHidden`, `length` will display as a hidden property for + // arrays. For consistency's sake, do the same for `size`, even though this + // property isn't selected by Object.getOwnPropertyNames(). + if (ctx.showHidden) + keys.unshift('size'); + } else if (value instanceof Map) { + braces = ['Map {', '}']; + // ditto + if (ctx.showHidden) + keys.unshift('size'); + } else { + braces = ['{', '}']; } // Make functions say that they are functions @@ -323,7 +335,10 @@ function formatValue(ctx, value, recurseTimes) { base = ' ' + '[Boolean: ' + formatted + ']'; } - if (keys.length === 0 && (!array || value.length === 0)) { + if (keys.length === 0 && + (!Array.isArray(value) || value.length === 0) && + (!(value instanceof Set) || value.size === 0) && + (!(value instanceof Map) || value.size === 0)) { return braces[0] + base + braces[1]; } @@ -338,11 +353,15 @@ function formatValue(ctx, value, recurseTimes) { ctx.seen.push(value); var output; - if (array) { + if (Array.isArray(value)) { output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); + } else if (value instanceof Set) { + output = formatSet(ctx, value, recurseTimes, visibleKeys, keys); + } else if (value instanceof Map) { + output = formatMap(ctx, value, recurseTimes, visibleKeys, keys); } else { output = keys.map(function(key) { - return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); + return formatProperty(ctx, value, recurseTimes, visibleKeys, key, false); }); } @@ -417,6 +436,38 @@ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { } +function formatSet(ctx, value, recurseTimes, visibleKeys, keys) { + var output = []; + value.forEach(function(v) { + var str = formatValue(ctx, v, + recurseTimes === null ? null : recurseTimes - 1); + output.push(str); + }); + keys.forEach(function(key) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + key, false)); + }); + return output; +} + + +function formatMap(ctx, value, recurseTimes, visibleKeys, keys) { + var output = []; + value.forEach(function(v, k) { + var str = formatValue(ctx, k, + recurseTimes === null ? null : recurseTimes - 1); + str += ' => '; + str += formatValue(ctx, v, recurseTimes === null ? null : recurseTimes - 1); + output.push(str); + }); + keys.forEach(function(key) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + key, false)); + }); + return output; +} + + function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { var name, str, desc; desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; @@ -488,7 +539,10 @@ function reduceToSingleString(output, base, braces) { if (length > 60) { return braces[0] + - (base === '' ? '' : base + '\n ') + + // If the opening "brace" is too large, like in the case of "Set {", + // we need to force the first item to be on the next line or the + // items will not line up correctly. + (base === '' && braces[0].length === 1 ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index f4aeced4d98abc..0cd46595f441d4 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -235,3 +235,17 @@ if (typeof Symbol !== 'undefined') { assert.equal(util.inspect(subject, options), '[ 1, 2, 3, [length]: 3, [Symbol(symbol)]: 42 ]'); } + +// test Set +assert.equal(util.inspect(new Set), 'Set {}') +assert.equal(util.inspect(new Set([1, 2, 3])), 'Set { 1, 2, 3 }') +var set = new Set(["foo"]) +set.bar = 42 +assert.equal(util.inspect(set, true), 'Set { \'foo\', [size]: 1, bar: 42 }') + +// test Map +assert.equal(util.inspect(new Map), 'Map {}') +assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])), 'Map { 1 => \'a\', 2 => \'b\', 3 => \'c\' }') +var map = new Map([["foo", null]]) +map.bar = 42 +assert.equal(util.inspect(map, true), 'Map { \'foo\' => null, [size]: 1, bar: 42 }') From 21e4e92503c4193c05596a4ad64a28dc99423fc2 Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Sun, 19 Apr 2015 23:01:07 -0400 Subject: [PATCH 2/8] (rebase) add semicolons to test --- test/parallel/test-util-inspect.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 0cd46595f441d4..0129a848eb1e2c 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -237,15 +237,15 @@ if (typeof Symbol !== 'undefined') { } // test Set -assert.equal(util.inspect(new Set), 'Set {}') -assert.equal(util.inspect(new Set([1, 2, 3])), 'Set { 1, 2, 3 }') -var set = new Set(["foo"]) -set.bar = 42 -assert.equal(util.inspect(set, true), 'Set { \'foo\', [size]: 1, bar: 42 }') +assert.equal(util.inspect(new Set), 'Set {}'); +assert.equal(util.inspect(new Set([1, 2, 3])), 'Set { 1, 2, 3 }'); +var set = new Set(["foo"]); +set.bar = 42; +assert.equal(util.inspect(set, true), 'Set { \'foo\', [size]: 1, bar: 42 }'); // test Map -assert.equal(util.inspect(new Map), 'Map {}') -assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])), 'Map { 1 => \'a\', 2 => \'b\', 3 => \'c\' }') -var map = new Map([["foo", null]]) -map.bar = 42 -assert.equal(util.inspect(map, true), 'Map { \'foo\' => null, [size]: 1, bar: 42 }') +assert.equal(util.inspect(new Map), 'Map {}'); +assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])), 'Map { 1 => \'a\', 2 => \'b\', 3 => \'c\' }'); +var map = new Map([["foo", null]]); +map.bar = 42; +assert.equal(util.inspect(map, true), 'Map { \'foo\' => null, [size]: 1, bar: 42 }'); From 87e36a6bd6abe4b2e7fb8411b9b1c78d2f07ba03 Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Sun, 19 Apr 2015 23:31:31 -0400 Subject: [PATCH 3/8] (rebase) check alignment of objects --- test/parallel/test-util-inspect.js | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 0129a848eb1e2c..a698ad7dfccc8c 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -249,3 +249,35 @@ assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])), 'Map { 1 => var map = new Map([["foo", null]]); map.bar = 42; assert.equal(util.inspect(map, true), 'Map { \'foo\' => null, [size]: 1, bar: 42 }'); + +// Test alignment of items in container +// Assumes that the first numeric character is the start of an item. + +function checkAlignment(container) { + var lines = util.inspect(container).split("\n"); + var pos; + lines.forEach(function(line) { + var npos = line.search(/\d/); + if (npos !== -1) { + if (pos !== undefined) + assert.equal(pos, npos, "container items not aligned"); + pos = npos; + } + }); +} + +var big_array = []; +for (var i = 0; i < 100; i++) { + big_array.push(i); +} + +checkAlignment(big_array); +checkAlignment(function(){ + var obj = {}; + big_array.forEach(function(v) { + obj[v] = null; + }) + return obj; +}()); +checkAlignment(new Set(big_array)); +checkAlignment(new Map(big_array.map(function (y) { return [y, null] }))); From 10d88e52a7c74185bacdd5ea155bf0f5304f7efe Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Sun, 19 Apr 2015 23:39:21 -0400 Subject: [PATCH 4/8] (rebase) these semicolons are going to be the end of me --- test/parallel/test-util-inspect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index a698ad7dfccc8c..a9f0949609831e 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -276,7 +276,7 @@ checkAlignment(function(){ var obj = {}; big_array.forEach(function(v) { obj[v] = null; - }) + }); return obj; }()); checkAlignment(new Set(big_array)); From 1185ff314155e7e2827fe7d5a534eacea354bcf4 Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Mon, 20 Apr 2015 03:21:01 -0400 Subject: [PATCH 5/8] util: support inspecting Promises --- lib/util.js | 41 +++++++++++++++++++++++++++++- test/parallel/test-util-inspect.js | 17 +++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index 653237d88e2ba0..1713feaf4decda 100644 --- a/lib/util.js +++ b/lib/util.js @@ -192,6 +192,16 @@ function arrayToHash(array) { } +function inspectPromise(p) { + // FIXME cache? + var Debug = require('vm').runInDebugContext('Debug'); + var mirror = Debug.MakeMirror(p); + if (!mirror.isPromise()) + return null; + return {status: mirror.status(), value: mirror.promiseValue().value_}; +} + + function formatValue(ctx, value, recurseTimes) { // Provide a hook for user-specified inspect functions. // Check that value is an object with an inspect function on it @@ -292,6 +302,8 @@ function formatValue(ctx, value, recurseTimes) { // ditto if (ctx.showHidden) keys.unshift('size'); + } else if (inspectPromise(value)) { // not instanceof in case of polyfill + braces = ['Promise {', '}']; } else { braces = ['{', '}']; } @@ -338,7 +350,9 @@ function formatValue(ctx, value, recurseTimes) { if (keys.length === 0 && (!Array.isArray(value) || value.length === 0) && (!(value instanceof Set) || value.size === 0) && - (!(value instanceof Map) || value.size === 0)) { + (!(value instanceof Map) || value.size === 0) && + // FIXME stop calling inspectPromise so much + (!inspectPromise(value))) { return braces[0] + base + braces[1]; } @@ -359,6 +373,8 @@ function formatValue(ctx, value, recurseTimes) { output = formatSet(ctx, value, recurseTimes, visibleKeys, keys); } else if (value instanceof Map) { output = formatMap(ctx, value, recurseTimes, visibleKeys, keys); + } else if (inspectPromise(value)) { + output = formatPromise(ctx, value, recurseTimes, visibleKeys, keys); } else { output = keys.map(function(key) { return formatProperty(ctx, value, recurseTimes, visibleKeys, key, false); @@ -468,6 +484,29 @@ function formatMap(ctx, value, recurseTimes, visibleKeys, keys) { } +function formatPromise(ctx, value, recurseTimes, visibleKeys, keys) { + // FIXME cache? + var output = []; + var internals = inspectPromise(value); + if (internals.status === 'pending') { + output.push(''); + } else { + var str = formatValue(ctx, internals.value, + recurseTimes === null ? null : recurseTimes - 1); + if (internals.status === 'rejected') { + output.push(' ' + str); + } else { + output.push(str); + } + } + keys.forEach(function(key) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + key, false)); + }); + return output; +} + + function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { var name, str, desc; desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index a9f0949609831e..6ef4a2d7f0e9fc 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -250,6 +250,23 @@ var map = new Map([["foo", null]]); map.bar = 42; assert.equal(util.inspect(map, true), 'Map { \'foo\' => null, [size]: 1, bar: 42 }'); +// test Promise +assert.equal(util.inspect(Promise.resolve(3)), 'Promise { 3 }'); +assert.equal(util.inspect(Promise.reject(3)), 'Promise { 3 }'); +assert.equal(util.inspect(new Promise(function() {})), 'Promise { }'); +var promise = Promise.resolve('foo'); +promise.bar = 42; +assert.equal(util.inspect(promise), 'Promise { \'foo\', bar: 42 }'); + +// Make sure it doesn't choke on polyfills. Unlike Set/Map, there is no standard +// interface to synchronously inspect a Promise, so our techniques only work on +// a bonafide native Promise. +var oldPromise = Promise; +global.Promise = function() { this.bar = 42; }; +assert.equal(util.inspect(new Promise), '{ bar: 42 }'); +global.Promise = oldPromise; + + // Test alignment of items in container // Assumes that the first numeric character is the start of an item. From c4d2cd045b7d51f3c38216adde689354ae2f2a20 Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Mon, 20 Apr 2015 17:19:28 -0400 Subject: [PATCH 6/8] (rebase) promise fixes --- lib/util.js | 57 ++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/lib/util.js b/lib/util.js index 1713feaf4decda..d8e519b02d365a 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,6 +1,7 @@ 'use strict'; const uv = process.binding('uv'); +const Debug = require('vm').runInDebugContext('Debug'); const formatRegExp = /%[sdj%]/g; exports.format = function(f) { @@ -193,9 +194,7 @@ function arrayToHash(array) { function inspectPromise(p) { - // FIXME cache? - var Debug = require('vm').runInDebugContext('Debug'); - var mirror = Debug.MakeMirror(p); + var mirror = Debug.MakeMirror(p, true); if (!mirror.isPromise()) return null; return {status: mirror.status(), value: mirror.promiseValue().value_}; @@ -286,10 +285,12 @@ function formatValue(ctx, value, recurseTimes) { } } - var base = '', braces; + var base = '', empty = keys.length === 0, braces, formatter; if (Array.isArray(value)) { braces = ['[', ']']; + empty = empty && value.length === 0; + formatter = formatArray; } else if (value instanceof Set) { braces = ['Set {', '}']; // With `showHidden`, `length` will display as a hidden property for @@ -297,15 +298,26 @@ function formatValue(ctx, value, recurseTimes) { // property isn't selected by Object.getOwnPropertyNames(). if (ctx.showHidden) keys.unshift('size'); + empty = empty && value.size === 0; + formatter = formatSet; } else if (value instanceof Map) { braces = ['Map {', '}']; // ditto if (ctx.showHidden) keys.unshift('size'); - } else if (inspectPromise(value)) { // not instanceof in case of polyfill - braces = ['Promise {', '}']; + empty = empty && value.size === 0; + formatter = formatMap; } else { - braces = ['{', '}']; + // Only create a mirror if the object superficially looks like a Promise + var promiseInternals = value instanceof Promise && inspectPromise(value); + if (promiseInternals) { + braces = ['Promise {', '}']; + empty = false; + formatter = formatPromise; + } else { + braces = ['{', '}']; + formatter = formatObject; + } } // Make functions say that they are functions @@ -347,12 +359,7 @@ function formatValue(ctx, value, recurseTimes) { base = ' ' + '[Boolean: ' + formatted + ']'; } - if (keys.length === 0 && - (!Array.isArray(value) || value.length === 0) && - (!(value instanceof Set) || value.size === 0) && - (!(value instanceof Map) || value.size === 0) && - // FIXME stop calling inspectPromise so much - (!inspectPromise(value))) { + if (empty) { return braces[0] + base + braces[1]; } @@ -366,20 +373,7 @@ function formatValue(ctx, value, recurseTimes) { ctx.seen.push(value); - var output; - if (Array.isArray(value)) { - output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); - } else if (value instanceof Set) { - output = formatSet(ctx, value, recurseTimes, visibleKeys, keys); - } else if (value instanceof Map) { - output = formatMap(ctx, value, recurseTimes, visibleKeys, keys); - } else if (inspectPromise(value)) { - output = formatPromise(ctx, value, recurseTimes, visibleKeys, keys); - } else { - output = keys.map(function(key) { - return formatProperty(ctx, value, recurseTimes, visibleKeys, key, false); - }); - } + var output = formatter(ctx, value, recurseTimes, visibleKeys, keys); ctx.seen.pop(); @@ -432,6 +426,13 @@ function formatError(value) { } +function formatObject(ctx, value, recurseTimes, visibleKeys, keys) { + return keys.map(function(key) { + return formatProperty(ctx, value, recurseTimes, visibleKeys, key, false); + }); +} + + function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { var output = []; for (var i = 0, l = value.length; i < l; ++i) { @@ -483,9 +484,7 @@ function formatMap(ctx, value, recurseTimes, visibleKeys, keys) { return output; } - function formatPromise(ctx, value, recurseTimes, visibleKeys, keys) { - // FIXME cache? var output = []; var internals = inspectPromise(value); if (internals.status === 'pending') { From ba53e971475e13aab1cf746c3e00c341ae704105 Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Mon, 20 Apr 2015 20:00:35 -0400 Subject: [PATCH 7/8] (rebase) fix showHidden on empty set/map we may mutate keys in the typecase, so don't check keys.length until no more mutations. --- lib/util.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/util.js b/lib/util.js index d8e519b02d365a..4502e188299724 100644 --- a/lib/util.js +++ b/lib/util.js @@ -285,11 +285,11 @@ function formatValue(ctx, value, recurseTimes) { } } - var base = '', empty = keys.length === 0, braces, formatter; + var base = '', empty, braces, formatter; if (Array.isArray(value)) { braces = ['[', ']']; - empty = empty && value.length === 0; + empty = value.length === 0; formatter = formatArray; } else if (value instanceof Set) { braces = ['Set {', '}']; @@ -298,14 +298,14 @@ function formatValue(ctx, value, recurseTimes) { // property isn't selected by Object.getOwnPropertyNames(). if (ctx.showHidden) keys.unshift('size'); - empty = empty && value.size === 0; + empty = value.size === 0; formatter = formatSet; } else if (value instanceof Map) { braces = ['Map {', '}']; // ditto if (ctx.showHidden) keys.unshift('size'); - empty = empty && value.size === 0; + empty = value.size === 0; formatter = formatMap; } else { // Only create a mirror if the object superficially looks like a Promise @@ -316,10 +316,13 @@ function formatValue(ctx, value, recurseTimes) { formatter = formatPromise; } else { braces = ['{', '}']; + empty = true; // no other data than keys formatter = formatObject; } } + empty = empty && keys.length === 0; + // Make functions say that they are functions if (typeof value === 'function') { var n = value.name ? ': ' + value.name : ''; From 79627ae18edb973d0a9742341c3e301c7b0db035 Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Thu, 23 Apr 2015 11:10:25 -0400 Subject: [PATCH 8/8] nits n stuff --- lib/util.js | 27 +++++++++++++-------------- test/parallel/test-util-inspect.js | 16 +++++++++------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/util.js b/lib/util.js index 4502e188299724..9293587d58787a 100644 --- a/lib/util.js +++ b/lib/util.js @@ -285,7 +285,7 @@ function formatValue(ctx, value, recurseTimes) { } } - var base = '', empty, braces, formatter; + var base = '', empty = false, braces, formatter; if (Array.isArray(value)) { braces = ['[', ']']; @@ -302,26 +302,25 @@ function formatValue(ctx, value, recurseTimes) { formatter = formatSet; } else if (value instanceof Map) { braces = ['Map {', '}']; - // ditto + // Ditto. if (ctx.showHidden) keys.unshift('size'); empty = value.size === 0; formatter = formatMap; } else { - // Only create a mirror if the object superficially looks like a Promise + // Only create a mirror if the object superficially looks like a Promise. var promiseInternals = value instanceof Promise && inspectPromise(value); if (promiseInternals) { braces = ['Promise {', '}']; - empty = false; formatter = formatPromise; } else { braces = ['{', '}']; - empty = true; // no other data than keys + empty = true; // No other data than keys. formatter = formatObject; } } - empty = empty && keys.length === 0; + empty = empty === true && keys.length === 0; // Make functions say that they are functions if (typeof value === 'function') { @@ -362,7 +361,7 @@ function formatValue(ctx, value, recurseTimes) { base = ' ' + '[Boolean: ' + formatted + ']'; } - if (empty) { + if (empty === true) { return braces[0] + base + braces[1]; } @@ -459,8 +458,8 @@ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { function formatSet(ctx, value, recurseTimes, visibleKeys, keys) { var output = []; value.forEach(function(v) { - var str = formatValue(ctx, v, - recurseTimes === null ? null : recurseTimes - 1); + var nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1; + var str = formatValue(ctx, v, nextRecurseTimes); output.push(str); }); keys.forEach(function(key) { @@ -474,10 +473,10 @@ function formatSet(ctx, value, recurseTimes, visibleKeys, keys) { function formatMap(ctx, value, recurseTimes, visibleKeys, keys) { var output = []; value.forEach(function(v, k) { - var str = formatValue(ctx, k, - recurseTimes === null ? null : recurseTimes - 1); + var nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1; + var str = formatValue(ctx, k, nextRecurseTimes); str += ' => '; - str += formatValue(ctx, v, recurseTimes === null ? null : recurseTimes - 1); + str += formatValue(ctx, v, nextRecurseTimes); output.push(str); }); keys.forEach(function(key) { @@ -493,8 +492,8 @@ function formatPromise(ctx, value, recurseTimes, visibleKeys, keys) { if (internals.status === 'pending') { output.push(''); } else { - var str = formatValue(ctx, internals.value, - recurseTimes === null ? null : recurseTimes - 1); + var nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1; + var str = formatValue(ctx, internals.value, nextRecurseTimes); if (internals.status === 'rejected') { output.push(' ' + str); } else { diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 6ef4a2d7f0e9fc..ac4bb0e84706b9 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -239,16 +239,18 @@ if (typeof Symbol !== 'undefined') { // test Set assert.equal(util.inspect(new Set), 'Set {}'); assert.equal(util.inspect(new Set([1, 2, 3])), 'Set { 1, 2, 3 }'); -var set = new Set(["foo"]); +var set = new Set(['foo']); set.bar = 42; assert.equal(util.inspect(set, true), 'Set { \'foo\', [size]: 1, bar: 42 }'); // test Map assert.equal(util.inspect(new Map), 'Map {}'); -assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])), 'Map { 1 => \'a\', 2 => \'b\', 3 => \'c\' }'); -var map = new Map([["foo", null]]); +assert.equal(util.inspect(new Map([[1, 'a'], [2, 'b'], [3, 'c']])), + 'Map { 1 => \'a\', 2 => \'b\', 3 => \'c\' }'); +var map = new Map([['foo', null]]); map.bar = 42; -assert.equal(util.inspect(map, true), 'Map { \'foo\' => null, [size]: 1, bar: 42 }'); +assert.equal(util.inspect(map, true), + 'Map { \'foo\' => null, [size]: 1, bar: 42 }'); // test Promise assert.equal(util.inspect(Promise.resolve(3)), 'Promise { 3 }'); @@ -271,13 +273,13 @@ global.Promise = oldPromise; // Assumes that the first numeric character is the start of an item. function checkAlignment(container) { - var lines = util.inspect(container).split("\n"); + var lines = util.inspect(container).split('\n'); var pos; lines.forEach(function(line) { var npos = line.search(/\d/); if (npos !== -1) { if (pos !== undefined) - assert.equal(pos, npos, "container items not aligned"); + assert.equal(pos, npos, 'container items not aligned'); pos = npos; } }); @@ -289,7 +291,7 @@ for (var i = 0; i < 100; i++) { } checkAlignment(big_array); -checkAlignment(function(){ +checkAlignment(function() { var obj = {}; big_array.forEach(function(v) { obj[v] = null;