-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
util: fix inspection of module namespaces #20962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -478,7 +478,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)); | ||
| } | ||
|
|
@@ -772,7 +788,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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the error checks be simplified all up? If namespace objects can only error by throwing a reference error then we can assume that the error accessing it is because of the reference error and remove the error checks and rethrow code above. We could also simplify the initial check by doing: try {
keys = Object.keys(value);
} catch (err) {
if (types.isModuleNamespaceObject(value)) {
keys = Object.getOwnPropertyNames(value);
} else {
throw err;
}
}Here erroring should be rare and when it does error it is likely a namespace object so the check up-front on error should be fine.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think its best to explicitly check if its a reference error, do you feel strongly about this?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dig it if code could be simpler, and still correct, that it be simpler is all. |
||
| } | ||
| // Use the existing functionality. This makes sure the indentation and | ||
|
|
||
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.