Skip to content

Commit c46dd77

Browse files
committed
deps: V8: backport 4bf051d536a1
Original commit message: [api] Add Context::GetMicrotaskQueue method Add a method that returns the microtask queue that is being used by the `v8::Context`. This is helpful in non-monolithic embedders like Node.js, which accept Contexts created by its own embedders like Electron, or for native Node.js addons. In particular, it enables: 1. Making sure that “nested” `Context`s use the correct microtask queue, i.e. the one from the outer Context. 2. Enqueueing microtasks into the correct microtask queue. Previously, these things only worked when the microtask queue for a given Context was the Isolate’s default queue. As an alternative, I considered adding a way to make new `Context`s inherit the queue from the `Context` that was entered at the time of their creation, but that seemed a bit more “magic”, less flexible, and didn’t take care of concern 2 listed above. Change-Id: I15ed796df90f23c97a545a8e1b30a3bf4a5c4320 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2579914 Reviewed-by: Toon Verwaest <verwaest@chromium.org> Commit-Queue: Toon Verwaest <verwaest@chromium.org> Cr-Commit-Position: refs/heads/master@{#71710} Refs: v8/v8@4bf051d PR-URL: nodejs#36482 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 55d0cd8 commit c46dd77

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.67',
39+
'v8_embedder_string': '-node.68',
4040

4141
##### V8 defaults for Node.js #####
4242

deps/v8/include/v8.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -10381,9 +10381,12 @@ class V8_EXPORT Context {
1038110381
*/
1038210382
void Exit();
1038310383

10384-
/** Returns an isolate associated with a current context. */
10384+
/** Returns the isolate associated with a current context. */
1038510385
Isolate* GetIsolate();
1038610386

10387+
/** Returns the microtask queue associated with a current context. */
10388+
MicrotaskQueue* GetMicrotaskQueue();
10389+
1038710390
/**
1038810391
* The field at kDebugIdIndex used to be reserved for the inspector.
1038910392
* It now serves no purpose.

deps/v8/src/api/api.cc

+6
Original file line numberDiff line numberDiff line change
@@ -6000,6 +6000,12 @@ v8::Isolate* Context::GetIsolate() {
60006000
return reinterpret_cast<Isolate*>(env->GetIsolate());
60016001
}
60026002

6003+
v8::MicrotaskQueue* Context::GetMicrotaskQueue() {
6004+
i::Handle<i::Context> env = Utils::OpenHandle(this);
6005+
CHECK(env->IsNativeContext());
6006+
return i::Handle<i::NativeContext>::cast(env)->microtask_queue();
6007+
}
6008+
60036009
v8::Local<v8::Object> Context::Global() {
60046010
i::Handle<i::Context> context = Utils::OpenHandle(this);
60056011
i::Isolate* isolate = context->GetIsolate();

deps/v8/test/cctest/test-api.cc

+10
Original file line numberDiff line numberDiff line change
@@ -27402,3 +27402,13 @@ TEST(FastApiCalls) {
2740227402
// are compared against the slow optimized calls.
2740327403
#endif // V8_LITE_MODE
2740427404
}
27405+
27406+
THREADED_TEST(MicrotaskQueueOfContext) {
27407+
auto microtask_queue = v8::MicrotaskQueue::New(CcTest::isolate());
27408+
v8::HandleScope scope(CcTest::isolate());
27409+
v8::Local<Context> context = Context::New(
27410+
CcTest::isolate(), nullptr, v8::MaybeLocal<ObjectTemplate>(),
27411+
v8::MaybeLocal<Value>(), v8::DeserializeInternalFieldsCallback(),
27412+
microtask_queue.get());
27413+
CHECK_EQ(context->GetMicrotaskQueue(), microtask_queue.get());
27414+
}

0 commit comments

Comments
 (0)