Skip to content

Commit

Permalink
util: inspect arguments properly
Browse files Browse the repository at this point in the history
Right now it is not possible to distinguish arguments from a regular
object. This adds a arguments indicator.

PR-URL: #19467
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
BridgeAR authored and jasnell committed Apr 16, 2018
1 parent 846f4e1 commit f848c60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const types = internalBinding('types');
Object.assign(types, require('internal/util/types'));
const {
isAnyArrayBuffer,
isArgumentsObject,
isDataView,
isExternal,
isMap,
Expand Down Expand Up @@ -538,9 +539,13 @@ function formatValue(ctx, value, recurseTimes, ln) {
if (noIterator) {
braces = ['{', '}'];
if (prefix === 'Object ') {
// Object fast path
if (keyLength === 0)
if (isArgumentsObject(value)) {
braces[0] = '[Arguments] {';
if (keyLength === 0)
return '[Arguments] {}';
} else if (keyLength === 0) {
return '{}';
}
} else if (typeof value === 'function') {
const name =
`${constructor || tag}${value.name ? `: ${value.name}` : ''}`;
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1399,3 +1399,8 @@ util.inspect(process);
'extra: true }';
assert(out === expect || out === expectAlt);
}

{ // Test argument objects.
const args = (function() { return arguments; })('a');
assert.strictEqual(util.inspect(args), "[Arguments] { '0': 'a' }");
}

0 comments on commit f848c60

Please sign in to comment.