vm: reject in importModuleDynamically without --experimental-vm-modules - #50137
vm: reject in importModuleDynamically without --experimental-vm-modules#50137joyeecheung wants to merge 3 commits into
Conversation
|
Review requested:
|
3ab08c0 to
def4010
Compare
|
This is a follow up of #49950 so that older versions of Jest (and any other packages that are doing a similar custom error in the cc @SimenB |
|
This is awesome, thank you so much for your time and efforts here! |
|
Local numbers of the compile-script-in-isolate-cache.js benchmark - similar to #49950 hitting the cache results in a ~100x speedup (note that in the benchmark the import callback isn't doing anything useful because the script does not actually invoke |
def4010 to
96bd70f
Compare
|
Fixed linter errors |
GeoffreyBooth
left a comment
There was a problem hiding this comment.
Thank you for doing this! I’ve been working with some of these files lately and this is a great improvement!
JakobJingleheimer
left a comment
There was a problem hiding this comment.
No idea what's happening here, but the code certainly looks much much cleaner, and the code comments are great!
|
I'm running tests locally. This will be pushed shortly. |
Set a default host-defined option for vm.compileFunction so that it's consistent with vm.Script. PR-URL: #50137 Refs: #35375 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Instead of using the public versions of the vm APIs internally, use the internal versions so that we can skip unnecessary argument validation. The public versions would need special care to the generation of host-defined options to hit the isolate compilation cache when imporModuleDynamically isn't used, while internally it's almost always used, so this allows us to handle the host-defined options separately. PR-URL: #50137 Refs: #35375 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Users cannot access any API that can be used to return a module or module namespace in this callback without --experimental-vm-modules anyway, so this would eventually lead to a rejection. This patch rejects in this case with our own error message and use a constant host-defined option for the rejection, so that scripts with the same source can still be compiled using the compilation cache if no `import()` is actually called in the script. PR-URL: #50137 Refs: #35375 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
|
The
notable-change
Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section. |
|
Add a post-mortem notable-change label so that we don't miss sending the words out in v18.x again. Copying text from v21.1.0: |
|
@joyeecheung I see the backport to 20.x was merged. Will this also be backported to 18.x? |
|
I have no plan to backport it as it's out of my competence, but I would like to see it backported :) |
|
Oh I thought it should land cleanly after that. If not I can backport it myself. |
|
hmm I just realized that to backport the whole thing, we will need to backport Symbols as WeakMap keys to v18.x (it might be possible to just backport the cache fix, but then that's probably not enough to unblock upgrades because without Symbols as WeakMap keys we won't be able to backport the memory fixes, so people are still going to run into seg faults and leaks). I'm not sure about our policy regarding backporting language features from V8 to maintenance LTS though. Setting policies aside, it's not actually that big of a change so it shouldn't be too hard to backport it to v18.x. |
|
So I got some confirmations that it's okay to backport Symbols as WeakMap keys to v18.x, I have the Node.js part backport done in https://github.com/joyeecheung/node/tree/backport-50137-to-18, currenly working on the V8 part |
vm: unify host-defined option generation in vm.compileFunction
Set a default host-defined option for vm.compileFunction so that
it's consistent with vm.Script.
vm: use internal versions of compileFunction and Script
Instead of using the public versions of the vm APIs internally,
use the internal versions so that we can skip unnecessary
argument validation.
The public versions would need special care to the generation
of host-defined options to hit the isolate compilation cache
when imporModuleDynamically isn't used, while internally it's
almost always used, so this allows us to handle the host-defined
options separately.
vm: reject in importModuleDynamically without --experimental-vm-modules
Users cannot access any API that can be used to return a module or
module namespace in this callback without --experimental-vm-modules
anyway, so this would eventually lead to a rejection. This patch
rejects in this case with our own error message and use a constant
host-defined option for the rejection, so that scripts with the
same source can still be compiled using the compilation cache
if no
import()is actually called in the script.Refs: #35375
with-dynamic-import-callbackis Jest's current behavior which blocks users from upgrading from v16.x (see #49950 (comment)).