Skip to content

Commit

Permalink
Fixup v8 weakref hook spec
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Feb 21, 2020
1 parent 1033f18 commit 4d72e13
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions shell/app/node_main.cc
Expand Up @@ -74,6 +74,17 @@ void SetNodeCliFlags() {
ProcessGlobalArgs(&args, nullptr, &errors, node::kDisallowedInEnvironment);
}

// TODO(codebytere): expose this from Node.js itself?
void HostCleanupFinalizationGroupCallback(
v8::Local<v8::Context> context,
v8::Local<v8::FinalizationGroup> group) {
node::Environment* env = node::Environment::GetCurrent(context);
if (env == nullptr) {
return;
}
env->RegisterFinalizationGroupForCleanup(group);
}

} // namespace

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

// This is needed in order to enable v8 host weakref hooks.
gin_env.isolate()->SetHostCleanupFinalizationGroupCallback(
HostCleanupFinalizationGroupCallback);

gin_helper::Dictionary process(gin_env.isolate(), env->process_object());
#if defined(OS_WIN)
process.SetMethod("log", &ElectronBindings::Log);
Expand Down

0 comments on commit 4d72e13

Please sign in to comment.