Skip to content

Commit a91a95f

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: #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 d313bf7 commit a91a95f

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

common.gypi

Lines changed: 1 addition & 1 deletion
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.20',
39+
'v8_embedder_string': '-node.21',
4040

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

deps/v8/include/v8.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10417,9 +10417,12 @@ class V8_EXPORT Context {
1041710417
*/
1041810418
void Exit();
1041910419

10420-
/** Returns an isolate associated with a current context. */
10420+
/** Returns the isolate associated with a current context. */
1042110421
Isolate* GetIsolate();
1042210422

10423+
/** Returns the microtask queue associated with a current context. */
10424+
MicrotaskQueue* GetMicrotaskQueue();
10425+
1042310426
/**
1042410427
* The field at kDebugIdIndex used to be reserved for the inspector.
1042510428
* It now serves no purpose.

deps/v8/src/api/api.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6118,6 +6118,12 @@ v8::Isolate* Context::GetIsolate() {
61186118
return reinterpret_cast<Isolate*>(env->GetIsolate());
61196119
}
61206120

6121+
v8::MicrotaskQueue* Context::GetMicrotaskQueue() {
6122+
i::Handle<i::Context> env = Utils::OpenHandle(this);
6123+
CHECK(env->IsNativeContext());
6124+
return i::Handle<i::NativeContext>::cast(env)->microtask_queue();
6125+
}
6126+
61216127
v8::Local<v8::Object> Context::Global() {
61226128
i::Handle<i::Context> context = Utils::OpenHandle(this);
61236129
i::Isolate* isolate = context->GetIsolate();

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28348,3 +28348,13 @@ TEST(TriggerThreadSafeMetricsEvent) {
2834828348
CHECK_EQ(recorder->count_, 1); // Increased.
2834928349
CHECK_EQ(recorder->module_count_, 42);
2835028350
}
28351+
28352+
THREADED_TEST(MicrotaskQueueOfContext) {
28353+
auto microtask_queue = v8::MicrotaskQueue::New(CcTest::isolate());
28354+
v8::HandleScope scope(CcTest::isolate());
28355+
v8::Local<Context> context = Context::New(
28356+
CcTest::isolate(), nullptr, v8::MaybeLocal<ObjectTemplate>(),
28357+
v8::MaybeLocal<Value>(), v8::DeserializeInternalFieldsCallback(),
28358+
microtask_queue.get());
28359+
CHECK_EQ(context->GetMicrotaskQueue(), microtask_queue.get());
28360+
}

0 commit comments

Comments
 (0)