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'));
|
Object.assign(types, require('internal/util/types'));
|
||||||
const {
|
const {
|
||||||
isAnyArrayBuffer,
|
isAnyArrayBuffer,
|
||||||
|
isArgumentsObject,
|
||||||
isDataView,
|
isDataView,
|
||||||
isExternal,
|
isExternal,
|
||||||
isMap,
|
isMap,
|
||||||
@ -538,9 +539,13 @@ function formatValue(ctx, value, recurseTimes, ln) {
|
|||||||
if (noIterator) {
|
if (noIterator) {
|
||||||
braces = ['{', '}'];
|
braces = ['{', '}'];
|
||||||
if (prefix === 'Object ') {
|
if (prefix === 'Object ') {
|
||||||
// Object fast path
|
if (isArgumentsObject(value)) {
|
||||||
if (keyLength === 0)
|
braces[0] = '[Arguments] {';
|
||||||
|
if (keyLength === 0)
|
||||||
|
return '[Arguments] {}';
|
||||||
|
} else if (keyLength === 0) {
|
||||||
return '{}';
|
return '{}';
|
||||||
|
}
|
||||||
} else if (typeof value === 'function') {
|
} else if (typeof value === 'function') {
|
||||||
const name =
|
const name =
|
||||||
`${constructor || tag}${value.name ? `: ${value.name}` : ''}`;
|
`${constructor || tag}${value.name ? `: ${value.name}` : ''}`;
|
||||||
|
@ -1399,3 +1399,8 @@ util.inspect(process);
|
|||||||
'extra: true }';
|
'extra: true }';
|
||||||
assert(out === expect || out === expectAlt);
|
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