diff options
author | Gus Caplan <me@gus.host> | 2019-10-11 15:53:41 -0700 |
---|---|---|
committer | Gus Caplan <me@gus.host> | 2019-10-13 15:45:36 -0700 |
commit | 545f7282d126ee43cf9cfeb66c83d0cbd2c60614 (patch) | |
tree | 8cd69c849fb60a6a84af8894c16f02c7723a7dcf /src/api | |
parent | ea3d5ff785e5f7b327942f9b47b3bd958e77c51f (diff) | |
download | android-node-v8-545f7282d126ee43cf9cfeb66c83d0cbd2c60614.tar.gz android-node-v8-545f7282d126ee43cf9cfeb66c83d0cbd2c60614.tar.bz2 android-node-v8-545f7282d126ee43cf9cfeb66c83d0cbd2c60614.zip |
src: implement v8 host weakref hooks
PR-URL: https://github.com/nodejs/node/pull/29874
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/callback.cc | 3 | ||||
-rw-r--r-- | src/api/environment.cc | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/api/callback.cc b/src/api/callback.cc index e6098d5921..6d4e28e1d9 100644 --- a/src/api/callback.cc +++ b/src/api/callback.cc @@ -100,6 +100,9 @@ void InternalCallbackScope::Close() { TickInfo* tick_info = env_->tick_info(); if (!env_->can_call_into_js()) return; + + OnScopeLeave weakref_cleanup([&]() { env_->RunWeakRefCleanup(); }); + if (!tick_info->has_tick_scheduled()) { MicrotasksScope::PerformCheckpoint(env_->isolate()); } diff --git a/src/api/environment.cc b/src/api/environment.cc index 2c0fe13063..3c5665a2d2 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -12,6 +12,7 @@ using errors::TryCatchScope; using v8::Array; using v8::Context; using v8::EscapableHandleScope; +using v8::FinalizationGroup; using v8::Function; using v8::HandleScope; using v8::Isolate; @@ -76,6 +77,15 @@ static MaybeLocal<Value> PrepareStackTraceCallback(Local<Context> context, return result; } +static void HostCleanupFinalizationGroupCallback( + Local<Context> context, Local<FinalizationGroup> group) { + Environment* env = Environment::GetCurrent(context); + if (env == nullptr) { + return; + } + env->RegisterFinalizationGroupForCleanup(group); +} + void* NodeArrayBufferAllocator::Allocate(size_t size) { if (zero_fill_field_ || per_process::cli_options->zero_fill_all_buffers) return UncheckedCalloc(size); @@ -203,6 +213,8 @@ void SetIsolateUpForNode(v8::Isolate* isolate, IsolateSettingCategories cat) { isolate->SetAllowWasmCodeGenerationCallback( AllowWasmCodeGenerationCallback); isolate->SetPromiseRejectCallback(task_queue::PromiseRejectCallback); + isolate->SetHostCleanupFinalizationGroupCallback( + HostCleanupFinalizationGroupCallback); v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate); break; default: |