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

introduce loader hook context #20761

Closed
wants to merge 2 commits into from

Conversation

devsnek
Copy link
Member

@devsnek devsnek commented May 16, 2018

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the vm Issues and PRs related to the vm subsystem. label May 16, 2018
@devsnek devsnek added the esm Issues and PRs related to the ECMAScript Modules implementation. label May 16, 2018
@CedarXi
Copy link

CedarXi commented May 16, 2018

good

useful if resolve is not hooked.
- `specifier` {string} The specifier of the module to import.
- `parentURL` {string} The URL of the module that requested the specifier.
- `vmModuleLinkHook` {object} This value can be passed to [`module.link`][] to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`module.link` -> `module.link()`?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{object} -> {Object}.

@@ -253,6 +272,8 @@ With the list of module exports provided upfront, the `execute` function will
then be called at the exact point of module evaluation order for that module
in the import tree.

[`module.link`]: vm.html#vm_module_link_linker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`module.link` -> `module.link()`?

const k = Object.freeze(Object.create(null));
vmModuleLinkHookMap.set(k, this);

this.hookContext = Object.assign(Object.create(null), {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a different name since this has relations to vm and Context has a meaning of a Realm in the vm terminology.

This also seems to have some conflict with #18914 that I need to think on.

const linkingFromLoader = vmModuleLinkHookMap.has(linker);
if (linkingFromLoader) {
const loader = vmModuleLinkHookMap.get(linker);
linker = (specifier, parent) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason not to use an async function here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

habits are hard to break :) nice catch

defaultResolve,
resolve: (specifier, parentURL) => this.resolve(specifier, parentURL),
vmModuleLinkHook: k,
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to deny the hook context access to outside world, you are not – the [[Prototype]] of these functions are the %FunctionPrototype% of the outside world. It would be better to create these functions in the context directly, if possible, rather than using Object/Reflect.setPrototypeOf().

@devsnek
Copy link
Member Author

devsnek commented May 18, 2018

I came up with an alternative approach to this which should be a bit nicer

@devsnek devsnek closed this May 18, 2018
@devsnek devsnek deleted the feature/esm-hook-context branch May 18, 2018 15:44
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. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants