Skip to content

Commit e60d1c2

Browse files
isheludkonodejs-github-bot
authored andcommitted
[v8] Prepare for migrating v8::MicrotaskQueue to cppgc (#258)
Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
1 parent bf2629e commit e60d1c2

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
@@ -155,7 +155,11 @@ ContextifyContext* ContextifyContext::New(Environment* env,
155155

156156
MicrotaskQueue* queue =
157157
options->own_microtask_queue
158+
#ifdef V8_CPPGC_MICROTASK_QUEUE
159+
? options->own_microtask_queue
160+
#else
158161
? options->own_microtask_queue.get()
162+
#endif
159163
: env->isolate()->GetCurrentContext()->GetMicrotaskQueue();
160164

161165
Local<Context> v8_context;
@@ -176,9 +180,14 @@ ContextifyContext::ContextifyContext(Environment* env,
176180
Local<Object> wrapper,
177181
Local<Context> v8_context,
178182
ContextOptions* options)
183+
#ifdef V8_CPPGC_MICROTASK_QUEUE
184+
: microtask_queue_(options->own_microtask_queue)
185+
#else
179186
: microtask_queue_(options->own_microtask_queue
180187
? options->own_microtask_queue.release()
181-
: nullptr) {
188+
: nullptr)
189+
#endif
190+
{
182191
CppgcMixin::Wrap(this, env, wrapper);
183192

184193
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
@@ -923,15 +923,26 @@ TEST_F(EnvironmentTest, NestedMicrotaskQueue) {
923923
const v8::HandleScope handle_scope(isolate_);
924924
const Argv argv;
925925

926-
std::unique_ptr<v8::MicrotaskQueue> queue = v8::MicrotaskQueue::New(
927-
isolate_, v8::MicrotasksPolicy::kExplicit);
926+
#ifdef V8_CPPGC_MICROTASK_QUEUE
927+
v8::MicrotaskQueue*
928+
#else
929+
std::unique_ptr<v8::MicrotaskQueue>
930+
#endif
931+
queue =
932+
v8::MicrotaskQueue::New(isolate_, v8::MicrotasksPolicy::kExplicit);
933+
928934
v8::Local<v8::Context> context =
929935
v8::Context::New(isolate_,
930936
nullptr,
931937
{},
932938
{},
933939
v8::DeserializeInternalFieldsCallback(),
934-
queue.get());
940+
#ifdef V8_CPPGC_MICROTASK_QUEUE
941+
queue
942+
#else
943+
queue.get()
944+
#endif
945+
);
935946
node::InitializeContext(context);
936947
v8::Context::Scope context_scope(context);
937948

0 commit comments

Comments
 (0)