-
Notifications
You must be signed in to change notification settings - Fork 30k
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
vm: SourceTextModule refactor #29776
Conversation
bd941bd
to
2dd3bfb
Compare
cc @nodejs/vm |
6fc2a13
to
907f427
Compare
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.
Great to see these refinements.
this.#error; | ||
} catch { | ||
throw new ERR_VM_MODULE_NOT_MODULE(); | ||
} |
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 suggest to abstract this into a private function for less repetition. That way it could be used as: this.#getPrivateProperty(name)
where name would e.g., be '#error'
.
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.
obj['#error']
is not the same as obj.#error
, also you have to check for this.#getPrivateProperty
in the first place 🙃
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.
Uh, of course! Too bad that it seems like there's no nice way around this 😞
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.
It's pretty ugly but it should be possible to abstract it like this:
function getPrivateProperty(module, name) {
try {
switch (name) {
case 'error':
return module.#error;
...
}
} catch {
throw new ERR_VM_MODULE_NOT_MODULE();
}
}
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 think how the current code is the best we can get it. you can blame tc39 for not generalizing private fields better 🤷
- Removes redundant `instantiate` method - Refactors `link` to match the spec linking steps more accurately - Removes URL validation from SourceTextModule specifiers - DRYs some dynamic import logic Closes nodejs#29030 Co-Authored-By: Michaël Zasso <targos@protonmail.com>
- Removes redundant `instantiate` method - Refactors `link` to match the spec linking steps more accurately - Removes URL validation from SourceTextModule specifiers - DRYs some dynamic import logic Closes: #29030 Co-Authored-By: Michaël Zasso <targos@protonmail.com> PR-URL: #29776 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Landed in 5e7946f |
- Removes redundant `instantiate` method - Refactors `link` to match the spec linking steps more accurately - Removes URL validation from SourceTextModule specifiers - DRYs some dynamic import logic Closes: #29030 Co-Authored-By: Michaël Zasso <targos@protonmail.com> PR-URL: #29776 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
instantiate
methodlink
to match the spec linking steps more accuratelyCloses #29030
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes