| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 21fbcb6 commit 5ff7f42
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -827,7 +827,8 @@ void AsyncWrap::EmitDestroy(Environment* env, double async_id) { | |||
| 827 | 827 | // interrupt to get this Microtask scheduled as fast as possible. | |
| 828 | 828 | if (env->destroy_async_id_list()->size() == 16384) { | |
| 829 | 829 | env->RequestInterrupt([](Environment* env) { | |
| 830 | - env->isolate()->EnqueueMicrotask( | ||
| 830 | + env->context()->GetMicrotaskQueue()->EnqueueMicrotask( | ||
| 831 | + env->isolate(), | ||
| 831 | 832 | [](void* arg) { | |
| 832 | 833 | DestroyAsyncIdsCallback(static_cast<Environment*>(arg)); | |
| 833 | 834 | }, env); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -199,7 +199,9 @@ MaybeLocal<Context> ContextifyContext::CreateV8Context( | |||
| 199 | 199 | object_template, | |
| 200 | 200 | {}, // global object | |
| 201 | 201 | {}, // deserialization callback | |
| 202 | - microtask_queue() ? microtask_queue().get() : nullptr); | ||
| 202 | + microtask_queue() ? | ||
| 203 | + microtask_queue().get() : | ||
| 204 | + env->isolate()->GetCurrentContext()->GetMicrotaskQueue()); | ||
| 203 | 205 | if (ctx.IsEmpty()) return MaybeLocal<Context>(); | |
| 204 | 206 | // Only partially initialize the context - the primordials are left out | |
| 205 | 207 | // and only initialized when necessary. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -96,7 +96,8 @@ static void EnqueueMicrotask(const FunctionCallbackInfo<Value>& args) { | |||
| 96 | 96 | ||
| 97 | 97 | CHECK(args[0]->IsFunction()); | |
| 98 | 98 | ||
| 99 | - isolate->EnqueueMicrotask(args[0].As<Function>()); | ||
| 99 | + isolate->GetCurrentContext()->GetMicrotaskQueue() | ||
| 100 | + ->EnqueueMicrotask(isolate, args[0].As<Function>()); | ||
| 100 | 101 | } | |
| 101 | 102 | ||
| 102 | 103 | static void RunMicrotasks(const FunctionCallbackInfo<Value>& args) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -618,3 +618,58 @@ TEST_F(NodeZeroIsolateTestFixture, CtrlCWithOnlySafeTerminationTest) { | |||
| 618 | 618 | isolate->Dispose(); | |
| 619 | 619 | } | |
| 620 | 620 | #endif // _WIN32 | |
| 621 | + | ||
| 622 | + TEST_F(EnvironmentTest, NestedMicrotaskQueue) { | ||
| 623 | + const v8::HandleScope handle_scope(isolate_); | ||
| 624 | + const Argv argv; | ||
| 625 | + | ||
| 626 | + std::unique_ptr<v8::MicrotaskQueue> queue = v8::MicrotaskQueue::New(isolate_); | ||
| 627 | + v8::Local<v8::Context> context = v8::Context::New( | ||
| 628 | + isolate_, nullptr, {}, {}, {}, queue.get()); | ||
| 629 | + node::InitializeContext(context); | ||
| 630 | + v8::Context::Scope context_scope(context); | ||
| 631 | + | ||
| 632 | + int callback_calls = 0; | ||
| 633 | + v8::Local<v8::Function> must_call = v8::Function::New( | ||
| 634 | + context, | ||
| 635 | + [](const v8::FunctionCallbackInfo<v8::Value>& info) { | ||
| 636 | + int* callback_calls = | ||
| 637 | + static_cast<int*>(info.Data().As<v8::External>()->Value()); | ||
| 638 | + *callback_calls |= info[0].As<v8::Int32>()->Value(); | ||
| 639 | + }, | ||
| 640 | + v8::External::New(isolate_, static_cast<void*>(&callback_calls))) | ||
| 641 | + .ToLocalChecked(); | ||
| 642 | + context->Global()->Set( | ||
| 643 | + context, | ||
| 644 | + v8::String::NewFromUtf8Literal(isolate_, "mustCall"), | ||
| 645 | + must_call).Check(); | ||
| 646 | + | ||
| 647 | + node::IsolateData* isolate_data = node::CreateIsolateData( | ||
| 648 | + isolate_, &NodeTestFixture::current_loop, platform.get()); | ||
| 649 | + CHECK_NE(nullptr, isolate_data); | ||
| 650 | + | ||
| 651 | + node::Environment* env = node::CreateEnvironment( | ||
| 652 | + isolate_data, context, {}, {}); | ||
| 653 | + CHECK_NE(nullptr, env); | ||
| 654 | + | ||
| 655 | + node::LoadEnvironment( | ||
| 656 | + env, | ||
| 657 | + "Promise.resolve().then(() => mustCall(1 << 0));\n" | ||
| 658 | + "require('vm').runInNewContext(" | ||
| 659 | + " 'Promise.resolve().then(() => mustCall(1 << 1))'," | ||
| 660 | + " { mustCall }," | ||
| 661 | + " { microtaskMode: 'afterEvaluate' }" | ||
| 662 | + ");" | ||
| 663 | + "require('vm').runInNewContext(" | ||
| 664 | + " 'Promise.resolve().then(() => mustCall(1 << 2))'," | ||
| 665 | + " { mustCall }" | ||
| 666 | + ");").ToLocalChecked(); | ||
| 667 | + EXPECT_EQ(callback_calls, 1 << 1); | ||
| 668 | + isolate_->PerformMicrotaskCheckpoint(); | ||
| 669 | + EXPECT_EQ(callback_calls, 1 << 1); | ||
| 670 | + queue->PerformCheckpoint(isolate_); | ||
| 671 | + EXPECT_EQ(callback_calls, (1 << 0) | (1 << 1) | (1 << 2)); | ||
| 672 | + | ||
| 673 | + node::FreeEnvironment(env); | ||
| 674 | + node::FreeIsolateData(isolate_data); | ||
| 675 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments