Skip to content
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

esm custom loader: multiple calls to nextHook within the same loader result in different nextHooks #43238

Closed
JakobJingleheimer opened this issue May 29, 2022 · 1 comment · Fixed by #43303
Assignees
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders

Comments

@JakobJingleheimer
Copy link
Contributor

Version

pre-release / nightly

Platform

macOS 12.3.1, M1

Subsystem

esm, loaders

What steps will reproduce the bug?

loader-a.mjs
export function resolve(specifier, context, nextHook) {
  assert(nextHook() === nextHook());
}

How often does it reproduce? Is there a required condition?

100%

A loader hook must call nextHook() more than once to reproduce.

What is the expected behavior?

nextHook should be the same within the same loader

What do you see instead?

The first nextHook is correctly the next in the chain; however, subsequent calls erroneously continue along the hook chain.

Additional information

Thanks @cspotcode for reporting.

Note that this requires loader chaining (#42623), which has not yet been released.

The problem is caused by ESMLoader::resolve() and ESMLoader::load() decrementing hookIndex every time next<HookName> is called. I believe this can be addressed by using a factory to produce the next<HookName> and decrementing the counter in there instead.

@JakobJingleheimer JakobJingleheimer added esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders labels May 29, 2022
@JakobJingleheimer JakobJingleheimer self-assigned this May 29, 2022
@JakobJingleheimer
Copy link
Contributor Author

My proposed solution above will create a conflict with #43164 (merging soon), so I'll wait til that's merged before sending a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant