GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — util: fix inspection of module namespaces · nodejs/node@b2808ed

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • util.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/util.js‎

Copy file name to clipboardExpand all lines: lib/util.js
+18-2Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,23 @@ function formatValue(ctx, value, recurseTimes) {
488488
if (ctx.showHidden) {
489489
keys = Object.getOwnPropertyNames(value);
490490
} else {
491-
keys = Object.keys(value);
491+
// This might throw if `value` is a Module Namespace Object from an
492+
// unevaluated module, but we don't want to perform the actual type
493+
// check because it's expensive.
494+
// TODO(devsnek): track https://github.com/tc39/ecma262/issues/1209
495+
// and modify this logic as needed.
496+
try {
497+
keys = Object.keys(value);
498+
} catch (err) {
499+
if (types.isNativeError(err) &&
500+
err.name === 'ReferenceError' &&
501+
types.isModuleNamespaceObject(value)) {
502+
keys = Object.getOwnPropertyNames(value);
503+
} else {
504+
throw err;
505+
}
506+
}
507+
492508
if (symbols.length !== 0)
493509
symbols = symbols.filter((key) => propertyIsEnumerable.call(value, key));
494510
}
@@ -782,7 +798,7 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) {
782798
try {
783799
output[i] = formatProperty(ctx, value, recurseTimes, keys[i], 0);
784800
} catch (err) {
785-
if (!(err instanceof ReferenceError)) {
801+
if (!(types.isNativeError(err) && err.name === 'ReferenceError')) {
786802
throw err;
787803
}
788804
// Use the existing functionality. This makes sure the indentation and

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.