Skip to content

Commit 21c0130

Browse files
authored
[v8] Prepare for migrating v8::MicrotaskQueue to cppgc (#258)
1 parent 1d23037 commit 21c0130

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

src/node_contextify.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ ContextifyContext* ContextifyContext::New(Environment* env,
125125

126126
MicrotaskQueue* queue =
127127
options->own_microtask_queue
128+
#ifdef V8_CPPGC_MICROTASK_QUEUE
129+
? options->own_microtask_queue
130+
#else
128131
? options->own_microtask_queue.get()
132+
#endif
129133
: env->isolate()->GetCurrentContext()->GetMicrotaskQueue();
130134

131135
Local<Context> v8_context;
@@ -146,9 +150,14 @@ ContextifyContext::ContextifyContext(Environment* env,
146150
Local<Object> wrapper,
147151
Local<Context> v8_context,
148152
ContextOptions* options)
153+
#ifdef V8_CPPGC_MICROTASK_QUEUE
154+
: microtask_queue_(options->own_microtask_queue)
155+
#else
149156
: microtask_queue_(options->own_microtask_queue
150157
? options->own_microtask_queue.release()
151-
: nullptr) {
158+
: nullptr)
159+
#endif
160+
{
152161
CppgcMixin::Wrap(this, env, wrapper);
153162

154163
context_.Reset(env->isolate(), v8_context);

src/node_contextify.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ struct ContextOptions {
1818
v8::Local<v8::String> origin;
1919
v8::Local<v8::Boolean> allow_code_gen_strings;
2020
v8::Local<v8::Boolean> allow_code_gen_wasm;
21+
#ifdef V8_CPPGC_MICROTASK_QUEUE
22+
v8::MicrotaskQueue* own_microtask_queue = nullptr;
23+
#else
2124
std::unique_ptr<v8::MicrotaskQueue> own_microtask_queue;
25+
#endif
2226
v8::Local<v8::Symbol> host_defined_options_id;
2327
bool vanilla = false;
2428
};
@@ -122,7 +126,11 @@ class ContextifyContext final : CPPGC_MIXIN(ContextifyContext) {
122126
}
123127

124128
inline v8::MicrotaskQueue* microtask_queue() const {
129+
#ifdef V8_CPPGC_MICROTASK_QUEUE
130+
return microtask_queue_;
131+
#else
125132
return microtask_queue_.get();
133+
#endif
126134
}
127135

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

188196
v8::TracedReference<v8::Context> context_;
197+
#ifdef V8_CPPGC_MICROTASK_QUEUE
198+
cppgc::Persistent<v8::MicrotaskQueue> microtask_queue_;
199+
#else
189200
std::unique_ptr<v8::MicrotaskQueue> microtask_queue_;
201+
#endif
190202
};
191203

192204
class ContextifyScript final : CPPGC_MIXIN(ContextifyScript) {

test/cctest/test_environment.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,15 +750,26 @@ TEST_F(EnvironmentTest, NestedMicrotaskQueue) {
750750
const v8::HandleScope handle_scope(isolate_);
751751
const Argv argv;
752752

753-
std::unique_ptr<v8::MicrotaskQueue> queue = v8::MicrotaskQueue::New(
754-
isolate_, v8::MicrotasksPolicy::kExplicit);
753+
#ifdef V8_CPPGC_MICROTASK_QUEUE
754+
v8::MicrotaskQueue*
755+
#else
756+
std::unique_ptr<v8::MicrotaskQueue>
757+
#endif
758+
queue =
759+
v8::MicrotaskQueue::New(isolate_, v8::MicrotasksPolicy::kExplicit);
760+
755761
v8::Local<v8::Context> context =
756762
v8::Context::New(isolate_,
757763
nullptr,
758764
{},
759765
{},
760766
v8::DeserializeInternalFieldsCallback(),
761-
queue.get());
767+
#ifdef V8_CPPGC_MICROTASK_QUEUE
768+
queue
769+
#else
770+
queue.get()
771+
#endif
772+
);
762773
node::InitializeContext(context);
763774
v8::Context::Scope context_scope(context);
764775

0 commit comments

Comments
 (0)