From f2d112c6b7e81263de7ff911fa189a336d863892 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 15 Mar 2018 20:24:10 +0100 Subject: [PATCH] util: inspect arguments properly Right now it is not possible to distinguish arguments from a regular object. This adds a arguments indicator. PR-URL: https://github.com/nodejs/node/pull/19467 Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- lib/util.js | 9 +++++++-- test/parallel/test-util-inspect.js | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/util.js b/lib/util.js index 0483e4e0675..737ad5d0b4d 100644 --- a/lib/util.js +++ b/lib/util.js @@ -49,6 +49,7 @@ const types = internalBinding('types'); Object.assign(types, require('internal/util/types')); const { isAnyArrayBuffer, + isArgumentsObject, isDataView, isExternal, isMap, @@ -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}` : ''}`; diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index bdf44641212..b5ef8dca083 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -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' }"); +}