util: fix inspection of module namespaces
PR-URL: https://github.com/nodejs/node/pull/20962 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
6d5847917c
commit
a25730bda3
20
lib/util.js
20
lib/util.js
@ -478,7 +478,23 @@ function formatValue(ctx, value, recurseTimes) {
|
|||||||
if (ctx.showHidden) {
|
if (ctx.showHidden) {
|
||||||
keys = Object.getOwnPropertyNames(value);
|
keys = Object.getOwnPropertyNames(value);
|
||||||
} else {
|
} else {
|
||||||
keys = Object.keys(value);
|
// This might throw if `value` is a Module Namespace Object from an
|
||||||
|
// unevaluated module, but we don't want to perform the actual type
|
||||||
|
// check because it's expensive.
|
||||||
|
// TODO(devsnek): track https://github.com/tc39/ecma262/issues/1209
|
||||||
|
// and modify this logic as needed.
|
||||||
|
try {
|
||||||
|
keys = Object.keys(value);
|
||||||
|
} catch (err) {
|
||||||
|
if (types.isNativeError(err) &&
|
||||||
|
err.name === 'ReferenceError' &&
|
||||||
|
types.isModuleNamespaceObject(value)) {
|
||||||
|
keys = Object.getOwnPropertyNames(value);
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (symbols.length !== 0)
|
if (symbols.length !== 0)
|
||||||
symbols = symbols.filter((key) => propertyIsEnumerable.call(value, key));
|
symbols = symbols.filter((key) => propertyIsEnumerable.call(value, key));
|
||||||
}
|
}
|
||||||
@ -772,7 +788,7 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) {
|
|||||||
try {
|
try {
|
||||||
output[i] = formatProperty(ctx, value, recurseTimes, keys[i], 0);
|
output[i] = formatProperty(ctx, value, recurseTimes, keys[i], 0);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!(err instanceof ReferenceError)) {
|
if (!(types.isNativeError(err) && err.name === 'ReferenceError')) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// Use the existing functionality. This makes sure the indentation and
|
// Use the existing functionality. This makes sure the indentation and
|
||||||
|
Loading…
x
Reference in New Issue
Block a user