diff --git a/lib/util.js b/lib/util.js index 79f3cc7205398b..900ced1b46133f 100644 --- a/lib/util.js +++ b/lib/util.js @@ -488,7 +488,23 @@ function formatValue(ctx, value, recurseTimes) { if (ctx.showHidden) { keys = Object.getOwnPropertyNames(value); } 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) symbols = symbols.filter((key) => propertyIsEnumerable.call(value, key)); } @@ -782,7 +798,7 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) { try { output[i] = formatProperty(ctx, value, recurseTimes, keys[i], 0); } catch (err) { - if (!(err instanceof ReferenceError)) { + if (!(types.isNativeError(err) && err.name === 'ReferenceError')) { throw err; } // Use the existing functionality. This makes sure the indentation and