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 <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
2f9775995f
commit
f2d112c6b7
@ -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}` : ''}`;
|
||||
|
@ -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' }");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user