Skip to content

Commit 162c47b

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 23005cb commit 162c47b

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
@@ -1062,15 +1062,26 @@ TEST_F(EnvironmentTest, NestedMicrotaskQueue) {
10621062
const v8::HandleScope handle_scope(isolate_);
10631063
const Argv argv;
10641064

1065-
std::unique_ptr<v8::MicrotaskQueue> queue = v8::MicrotaskQueue::New(
1066-
isolate_, v8::MicrotasksPolicy::kExplicit);
1065+
#ifdef V8_CPPGC_MICROTASK_QUEUE
1066+
v8::MicrotaskQueue*
1067+
#else
1068+
std::unique_ptr<v8::MicrotaskQueue>
1069+
#endif
1070+
queue =
1071+
v8::MicrotaskQueue::New(isolate_, v8::MicrotasksPolicy::kExplicit);
1072+
10671073
v8::Local<v8::Context> context =
10681074
v8::Context::New(isolate_,
10691075
nullptr,
10701076
{},
10711077
{},
10721078
v8::DeserializeInternalFieldsCallback(),
1073-
queue.get());
1079+
#ifdef V8_CPPGC_MICROTASK_QUEUE
1080+
queue
1081+
#else
1082+
queue.get()
1083+
#endif
1084+
);
10741085
node::InitializeContext(context);
10751086
v8::Context::Scope context_scope(context);
10761087

0 commit comments

Comments
 (0)