Conversation
Add `vm.createMicrotaskQueue()` and extend the `microtaskMode` option
to accept `{ type: 'manual', queue }`, so multiple vm contexts can
share a single, explicitly-drained microtask queue instead of each
having its own privately auto-drained one. This lets embedders (e.g.
implementing a Window/iframe pair) reproduce the spec's
same-microtask-queue ordering guarantees, which was not previously
possible from the public API.
`'afterEvaluate'` and `{ type: 'manual', queue }` are mutually
exclusive by construction, since they are two different values of the
same option.
Refs: nodejs#65555
Signed-off-by: agape1225 <49804691+agape1225@users.noreply.github.com>
Parse microtaskMode only in createContext() so convenience APIs do not read type and queue getters repeatedly. Add regression tests for getter access, invalid options, and shared manual queues during module evaluation. Clarify that the queue constructor is not exported and fix the C++ macro line length. Refs: nodejs#65555 Signed-off-by: leah-1ee <selee3196@gmail.com>
agape1225
force-pushed
the
vm-shared-microtask-queue
branch
from
October 2, 2026 13:38
ea0e9df to
eb20179
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #66461 +/- ##
==========================================
+ Coverage 90.33% 90.41% +0.08%
==========================================
Files 790 791 +1
Lines 273834 275693 +1859
Branches 52361 52861 +500
==========================================
+ Hits 247378 249280 +1902
+ Misses 16924 16817 -107
- Partials 9532 9596 +64
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extends the existing
microtaskModeoption (no new option) so multiplevmcontexts can share one explicitly-drained microtask queue:Today,
'afterEvaluate'gives each context its own private, auto-drainedqueue — there's no way for two contexts to share one and have it drained
together, in scheduling order, as the HTML spec requires for same-agent
realms (e.g. a
Windowand a same-originiframe).Design
microtaskModenow accepts either the existing string'afterEvaluate'or an object
{ type: 'manual', queue }, wherequeueis created viathe one new export,
vm.createMicrotaskQueue(). These are two valuesof the same option, so a context is either auto-drained with a private
queue or shared-and-manual — never both, by construction, with nothing
to validate for that combination at runtime.
MakeContext()signature areunchanged; the manual-mode queue is passed through the same slot that
used to only take a boolean.
ContextifyMicrotaskQueue) is a plainBaseObject:the underlying
v8::MicrotaskQueueis kept alive viastd::shared_ptr,shared between the JS handle and every
ContextifyContextusing it, sothe handle itself doesn't need cppgc tracking.
vm.MicrotaskQueue(a spoofedobject, a
Proxy, etc.) is rejected withERR_INVALID_ARG_TYPE,checked via
FunctionTemplate::HasInstance()rather than a JS-levelinstanceof.Testing
New tests in
test/parallel/test-vm-shared-microtask-queue*.jscoverthe issue's Window/iframe scenario, queue-spoofing rejection, GC of the
JS handle, and module evaluation.
make -j12and the fulltest/parallel/test-vm-*.jssuite pass (104/104).Refs: #65555
Refs: #65582