8000 deps: V8: backport 4bf051d536a1 · nodejs/node@21fbcb6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 21fbcb6

Browse files
addaleaxtargos
authored andcommitted
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 96c095f commit 21fbcb6

File tree

4 files changed

+21
-2
lines changed
  • test/cctest
  • 4 files changed

    +21
    -2
    lines changed

    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.22',
    39+
    'v8_embedder_string': '-node.23',
    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
    @@ -10390,9 +10390,12 @@ class V8_EXPORT Context {
    1039010390
    */
    1039110391
    void Exit();
    1039210392

    10393-
    /** Returns an isolate associated with a current context. */
    10393+
    /** Returns the isolate associated with a current context. */
    1039410394
    Isolate* GetIsolate();
    1039510395

    10396+
    /** Returns the microtask queue associated with a current context. */
    10397+
    MicrotaskQueue* GetMicrotaskQueue();
    10398+
    1039610399
    /**
    1039710400
    * The field at kDebugIdIndex used to be reserved for the inspector.
    1039810401
    * 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
    @@ -6075,6 +6075,12 @@ v8::Isolate* Context::GetIsolate() {
    60756075
    return reinterpret_cast<Isolate*>(env->GetIsolate());
    60766076
    }
    60776077

    6078+
    v8::MicrotaskQueue* Context::GetMicrotaskQueue() {
    6079+
    i::Handle<i::Context> env = Utils::OpenHandle(this);
    6080+
    CHECK(env->IsNativeContext());
    6081+
    return i::Handle<i::NativeContext>::cast(env)->microtask_queue();
    6082+
    }
    6083+
    60786084
    v8::Local<v8::Object> Context::Global() {
    60796085
    i::Handle<i::Context> context = Utils::OpenHandle(this);
    60806086
    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
    @@ -28312,3 +28312,13 @@ TEST(TriggerThreadSafeMetricsEvent) {
    2831228312
    CHECK_EQ(recorder->count_, 1); // Increased.
    2831328313
    CHECK_EQ(recorder->module_count_, 42);
    2831428314
    }
    28315+
    28316+
    THREADED_TEST(MicrotaskQueueOfContext) {
    28317+
    auto microtask_queue = v8::MicrotaskQueue::New(CcTest::isolate());
    28318+
    v8::HandleScope scope(CcTest::isolate());
    28319+
    v8::Local<Context> context = Context::New(
    28320+
    CcTest::isolate(), nullptr, v8::MaybeLocal<ObjectTemplate>(),
    28321+
    v8::MaybeLocal<Value>(), v8::DeserializeInternalFieldsCallback(),
    28322+
    microtask_queue.get());
    28323+
    CHECK_EQ(context->GetMicrotaskQueue(), microtask_queue.get());
    28324+
    }

    0 commit comments

    Comments
     (0)
    0