From 77fa310949cf926bf7befffff32616cb1ba1c41b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 27 Jan 2019 14:21:51 +0100 Subject: [PATCH] src: pass along errors from perf obj instantiation PR-URL: https://github.com/nodejs/node/pull/25734 Reviewed-By: James M Snell Reviewed-By: Gus Caplan --- src/node_http2.cc | 6 ++++-- src/node_perf.cc | 29 ++++++++++++++++++----------- src/node_perf.h | 2 +- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/node_http2.cc b/src/node_http2.cc index ea60fb459ceff1..5b172dfee78e87 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -697,7 +697,8 @@ void Http2Stream::EmitStatistics() { } buffer[IDX_STREAM_STATS_SENTBYTES] = entry->sent_bytes(); buffer[IDX_STREAM_STATS_RECEIVEDBYTES] = entry->received_bytes(); - entry->Notify(entry->ToObject()); + Local obj; + if (entry->ToObject().ToLocal(&obj)) entry->Notify(obj); }, static_cast(entry)); } @@ -726,7 +727,8 @@ void Http2Session::EmitStatistics() { buffer[IDX_SESSION_STATS_DATA_RECEIVED] = entry->data_received(); buffer[IDX_SESSION_STATS_MAX_CONCURRENT_STREAMS] = entry->max_concurrent_streams(); - entry->Notify(entry->ToObject()); + Local obj; + if (entry->ToObject().ToLocal(&obj)) entry->Notify(obj); }, static_cast(entry)); } diff --git a/src/node_perf.cc b/src/node_perf.cc index b3bbc16a3ebd89..9c0091d2bc9070 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -20,6 +20,7 @@ using v8::HandleScope; using v8::Integer; using v8::Isolate; using v8::Local; +using v8::MaybeLocal; using v8::Name; using v8::NewStringType; using v8::Number; @@ -102,10 +103,13 @@ inline void InitObject(const PerformanceEntry& entry, Local obj) { } // Create a new PerformanceEntry object -const Local PerformanceEntry::ToObject() const { - Local obj = - env_->performance_entry_template() - ->NewInstance(env_->context()).ToLocalChecked(); +MaybeLocal PerformanceEntry::ToObject() const { + Local obj; + if (!env_->performance_entry_template() + ->NewInstance(env_->context()) + .ToLocal(&obj)) { + return MaybeLocal(); + } InitObject(*this, obj); return obj; } @@ -154,7 +158,8 @@ void Mark(const FunctionCallbackInfo& args) { *name, now / 1000); PerformanceEntry entry(env, *name, "mark", now, now); - Local obj = entry.ToObject(); + Local obj; + if (!entry.ToObject().ToLocal(&obj)) return; PerformanceEntry::Notify(env, entry.kind(), obj); args.GetReturnValue().Set(obj); } @@ -217,7 +222,8 @@ void Measure(const FunctionCallbackInfo& args) { *name, *name, endTimestamp / 1000); PerformanceEntry entry(env, *name, "measure", startTimestamp, endTimestamp); - Local obj = entry.ToObject(); + Local obj; + if (!entry.ToObject().ToLocal(&obj)) return; PerformanceEntry::Notify(env, entry.kind(), obj); args.GetReturnValue().Set(obj); } @@ -242,14 +248,16 @@ void SetupPerformanceObservers(const FunctionCallbackInfo& args) { // Creates a GC Performance Entry and passes it to observers void PerformanceGCCallback(Environment* env, void* ptr) { - GCPerformanceEntry* entry = static_cast(ptr); + std::unique_ptr entry{ + static_cast(ptr)}; HandleScope scope(env->isolate()); Local context = env->context(); AliasedBuffer& observers = env->performance_state()->observers; if (observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]) { - Local obj = entry->ToObject(); + Local obj; + if (!entry->ToObject().ToLocal(&obj)) return; PropertyAttribute attr = static_cast(ReadOnly | DontDelete); obj->DefineOwnProperty(context, @@ -258,8 +266,6 @@ void PerformanceGCCallback(Environment* env, void* ptr) { attr).FromJust(); PerformanceEntry::Notify(env, entry->kind(), obj); } - - delete entry; } // Marks the start of a GC cycle @@ -359,7 +365,8 @@ void TimerFunctionCall(const FunctionCallbackInfo& args) { return; PerformanceEntry entry(env, *name, "function", start, end); - Local obj = entry.ToObject(); + Local obj; + if (!entry.ToObject().ToLocal(&obj)) return; for (idx = 0; idx < count; idx++) obj->Set(context, idx, args[idx]).FromJust(); PerformanceEntry::Notify(env, entry.kind(), obj); diff --git a/src/node_perf.h b/src/node_perf.h index fe418ad441718a..56140bd62dee51 100644 --- a/src/node_perf.h +++ b/src/node_perf.h @@ -75,7 +75,7 @@ class PerformanceEntry { virtual ~PerformanceEntry() { } - virtual const Local ToObject() const; + virtual v8::MaybeLocal ToObject() const; Environment* env() const { return env_; }