Repository navigation
util: support inspecting Map, Set, and Promise #1471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
613a63b
21e4e92
87e36a6
10d88e5
1185ff3
c4d2cd0
ba53e97
79627ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: we should be able to do something like |
||
| 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); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similarly, |
||
| keys.forEach(function(key) { | ||
|
|
@@ -493,8 +492,8 @@ function formatPromise(ctx, value, recurseTimes, visibleKeys, keys) { | |
| if (internals.status === 'pending') { | ||
| output.push('<pending>'); | ||
| } 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('<rejected> ' + str); | ||
| } else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, is there a reason to keep the instanceof check out of inspectPromise?