Skip to content

Commit fee8d72

Browse files
committed
Fixup v8 weakref hook spec
nodejs/node#29874
1 parent f50ef63 commit fee8d72

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

shell/app/node_main.cc

+15
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ void SetNodeCliFlags() {
7474
ProcessGlobalArgs(&args, nullptr, &errors, node::kDisallowedInEnvironment);
7575
}
7676

77+
// TODO(codebytere): expose this from Node.js itself?
78+
void HostCleanupFinalizationGroupCallback(
79+
v8::Local<v8::Context> context,
80+
v8::Local<v8::FinalizationGroup> group) {
81+
node::Environment* env = node::Environment::GetCurrent(context);
82+
if (env == nullptr) {
83+
return;
84+
}
85+
env->RegisterFinalizationGroupForCleanup(group);
86+
}
87+
7788
} // namespace
7889

7990
namespace electron {
@@ -143,6 +154,10 @@ int NodeMain(int argc, char* argv[]) {
143154
node::BootstrapEnvironment(env);
144155
env->InitializeDiagnostics();
145156

157+
// This is needed in order to enable v8 host weakref hooks.
158+
gin_env.isolate()->SetHostCleanupFinalizationGroupCallback(
159+
HostCleanupFinalizationGroupCallback);
160+
146161
gin_helper::Dictionary process(gin_env.isolate(), env->process_object());
147162
#if defined(OS_WIN)
148163
process.SetMethod("log", &ElectronBindings::Log);

0 commit comments

Comments
 (0)