-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
Conversation
dab4ed2
to
e93d419
Compare
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`module.link`
-> `module.link()`
?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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), { |
There was a problem hiding this comment.
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) => |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, | ||
}); |
There was a problem hiding this comment.
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()
.
I came up with an alternative approach to this which should be a bit nicer |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes