diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-07-15 22:17:45 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-08-01 00:51:43 +0200 |
commit | 5207dec0175de92116262e8382d6ac57def3a203 (patch) | |
tree | e90e855f7a8a228e00fe0d49fb311b319de74c3d /src/node_perf.cc | |
parent | 61f3a5c60ad78506e9e0caae061a04ccab878ca1 (diff) | |
download | android-node-v8-5207dec0175de92116262e8382d6ac57def3a203.tar.gz android-node-v8-5207dec0175de92116262e8382d6ac57def3a203.tar.bz2 android-node-v8-5207dec0175de92116262e8382d6ac57def3a203.zip |
src: allow generic C++ callables in SetImmediate()
Modify the native `SetImmediate()` functions to take generic C++
callables as arguments. This makes passing arguments to the callback
easier, and in particular, it allows passing `std::unique_ptr`s
directly, which in turn makes sure that the data they point to is
deleted if the `Environment` is torn down before the callback can run.
PR-URL: https://github.com/nodejs/node/pull/28704
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_perf.cc')
-rw-r--r-- | src/node_perf.cc | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/node_perf.cc b/src/node_perf.cc index 45adcf332a..3efaca6065 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -229,9 +229,8 @@ void SetupPerformanceObservers(const FunctionCallbackInfo<Value>& args) { } // Creates a GC Performance Entry and passes it to observers -void PerformanceGCCallback(Environment* env, void* ptr) { - std::unique_ptr<GCPerformanceEntry> entry{ - static_cast<GCPerformanceEntry*>(ptr)}; +void PerformanceGCCallback(Environment* env, + std::unique_ptr<GCPerformanceEntry> entry) { HandleScope scope(env->isolate()); Local<Context> context = env->context(); @@ -268,13 +267,14 @@ void MarkGarbageCollectionEnd(Isolate* isolate, // If no one is listening to gc performance entries, do not create them. if (!state->observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]) return; - GCPerformanceEntry* entry = - new GCPerformanceEntry(env, - static_cast<PerformanceGCKind>(type), - state->performance_last_gc_start_mark, - PERFORMANCE_NOW()); - env->SetUnrefImmediate(PerformanceGCCallback, - entry); + auto entry = std::make_unique<GCPerformanceEntry>( + env, + static_cast<PerformanceGCKind>(type), + state->performance_last_gc_start_mark, + PERFORMANCE_NOW()); + env->SetUnrefImmediate([entry = std::move(entry)](Environment* env) mutable { + PerformanceGCCallback(env, std::move(entry)); + }); } static void SetupGarbageCollectionTracking( |