Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ ContextifyContext* ContextifyContext::New(Environment* env,

MicrotaskQueue* queue =
options->own_microtask_queue
#ifdef V8_CPPGC_MICROTASK_QUEUE
? options->own_microtask_queue
#else
? options->own_microtask_queue.get()
#endif
: env->isolate()->GetCurrentContext()->GetMicrotaskQueue();

Local<Context> v8_context;
Expand All @@ -146,9 +150,14 @@ ContextifyContext::ContextifyContext(Environment* env,
Local<Object> wrapper,
Local<Context> v8_context,
ContextOptions* options)
#ifdef V8_CPPGC_MICROTASK_QUEUE
: microtask_queue_(options->own_microtask_queue)
#else
: microtask_queue_(options->own_microtask_queue
? options->own_microtask_queue.release()
: nullptr) {
: nullptr)
#endif
{
CppgcMixin::Wrap(this, env, wrapper);

context_.Reset(env->isolate(), v8_context);
Expand Down
12 changes: 12 additions & 0 deletions src/node_contextify.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ struct ContextOptions {
v8::Local<v8::String> origin;
v8::Local<v8::Boolean> allow_code_gen_strings;
v8::Local<v8::Boolean> allow_code_gen_wasm;
#ifdef V8_CPPGC_MICROTASK_QUEUE
v8::MicrotaskQueue* own_microtask_queue = nullptr;
#else
std::unique_ptr<v8::MicrotaskQueue> own_microtask_queue;
#endif
v8::Local<v8::Symbol> host_defined_options_id;
bool vanilla = false;
};
Expand Down Expand Up @@ -122,7 +126,11 @@ class ContextifyContext final : CPPGC_MIXIN(ContextifyContext) {
}

inline v8::MicrotaskQueue* microtask_queue() const {
#ifdef V8_CPPGC_MICROTASK_QUEUE
return microtask_queue_;
#else
return microtask_queue_.get();
#endif
}

template <typename T>
Expand Down Expand Up @@ -186,7 +194,11 @@ class ContextifyContext final : CPPGC_MIXIN(ContextifyContext) {
const v8::PropertyCallbackInfo<v8::Array>& args);

v8::TracedReference<v8::Context> context_;
#ifdef V8_CPPGC_MICROTASK_QUEUE
cppgc::Persistent<v8::MicrotaskQueue> microtask_queue_;
#else
std::unique_ptr<v8::MicrotaskQueue> microtask_queue_;
#endif
};

class ContextifyScript final : CPPGC_MIXIN(ContextifyScript) {
Expand Down
17 changes: 14 additions & 3 deletions test/cctest/test_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -750,15 +750,26 @@ TEST_F(EnvironmentTest, NestedMicrotaskQueue) {
const v8::HandleScope handle_scope(isolate_);
const Argv argv;

std::unique_ptr<v8::MicrotaskQueue> queue = v8::MicrotaskQueue::New(
isolate_, v8::MicrotasksPolicy::kExplicit);
#ifdef V8_CPPGC_MICROTASK_QUEUE
v8::MicrotaskQueue*
#else
std::unique_ptr<v8::MicrotaskQueue>
#endif
queue =
v8::MicrotaskQueue::New(isolate_, v8::MicrotasksPolicy::kExplicit);

v8::Local<v8::Context> context =
v8::Context::New(isolate_,
nullptr,
{},
{},
v8::DeserializeInternalFieldsCallback(),
queue.get());
#ifdef V8_CPPGC_MICROTASK_QUEUE
queue
#else
queue.get()
#endif
);
node::InitializeContext(context);
v8::Context::Scope context_scope(context);

Expand Down
Loading