Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
(rebase) fix showHidden on empty set/map
we may mutate keys in the typecase, so don't check keys.length until no
more mutations.
  • Loading branch information
monsanto committed Apr 21, 2015
commit ba53e971475e13aab1cf746c3e00c341ae704105
11 changes: 7 additions & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ function formatValue(ctx, value, recurseTimes) {
}
}

var base = '', empty = keys.length === 0, braces, formatter;
var base = '', empty, braces, formatter;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferably assign empty = false and use strict checks below (i.e. empty = empty === true && keys.length === 0 and if (empty === true) {.)

It's a minor thing but V8 emits marginally tighter code for strict boolean comparisons.


if (Array.isArray(value)) {
braces = ['[', ']'];
empty = empty && value.length === 0;
empty = value.length === 0;
formatter = formatArray;
} else if (value instanceof Set) {
braces = ['Set {', '}'];
Expand All @@ -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
Expand All @@ -316,10 +316,13 @@ function formatValue(ctx, value, recurseTimes) {
formatter = formatPromise;
} else {
braces = ['{', '}'];
empty = true; // no other data than keys

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Femto-style nit: two spaces before the comment and please capitalize and punctuate it. Ditto for other comments.

formatter = formatObject;
}
}

empty = empty && keys.length === 0;

// Make functions say that they are functions
if (typeof value === 'function') {
var n = value.name ? ': ' + value.name : '';
Expand Down