Skip to content

Commit f848c60

Browse files
BridgeARjasnell
authored andcommitted
util: inspect arguments properly
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 <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 846f4e1 commit f848c60

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/util.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const types = internalBinding('types');
4949
Object.assign(types, require('internal/util/types'));
5050
const {
5151
isAnyArrayBuffer,
52+
isArgumentsObject,
5253
isDataView,
5354
isExternal,
5455
isMap,
@@ -538,9 +539,13 @@ function formatValue(ctx, value, recurseTimes, ln) {
538539
if (noIterator) {
539540
braces = ['{', '}'];
540541
if (prefix === 'Object ') {
541-
// Object fast path
542-
if (keyLength === 0)
542+
if (isArgumentsObject(value)) {
543+
braces[0] = '[Arguments] {';
544+
if (keyLength === 0)
545+
return '[Arguments] {}';
546+
} else if (keyLength === 0) {
543547
return '{}';
548+
}
544549
} else if (typeof value === 'function') {
545550
const name =
546551
`${constructor || tag}${value.name ? `: ${value.name}` : ''}`;

test/parallel/test-util-inspect.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,3 +1399,8 @@ util.inspect(process);
13991399
'extra: true }';
14001400
assert(out === expect || out === expectAlt);
14011401
}
1402+
1403+
{ // Test argument objects.
1404+
const args = (function() { return arguments; })('a');
1405+
assert.strictEqual(util.inspect(args), "[Arguments] { '0': 'a' }");
1406+
}

0 commit comments

Comments
 (0)