diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-01-27 14:21:51 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-01-29 20:02:02 +0100 |
commit | 77fa310949cf926bf7befffff32616cb1ba1c41b (patch) | |
tree | d97cd0f6be56fae1255b2ed3aa0be398173b449d | |
parent | 95571ac1e9acd09d0b06b2315aabb0cc4e158572 (diff) | |
download | android-node-v8-77fa310949cf926bf7befffff32616cb1ba1c41b.tar.gz android-node-v8-77fa310949cf926bf7befffff32616cb1ba1c41b.tar.bz2 android-node-v8-77fa310949cf926bf7befffff32616cb1ba1c41b.zip |
src: pass along errors from perf obj instantiation
PR-URL: https://github.com/nodejs/node/pull/25734
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
-rw-r--r-- | src/node_http2.cc | 6 | ||||
-rw-r--r-- | src/node_perf.cc | 29 | ||||
-rw-r--r-- | 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 ea60fb459c..5b172dfee7 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<Object> obj; + if (entry->ToObject().ToLocal(&obj)) entry->Notify(obj); }, static_cast<void*>(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<Object> obj; + if (entry->ToObject().ToLocal(&obj)) entry->Notify(obj); }, static_cast<void*>(entry)); } diff --git a/src/node_perf.cc b/src/node_perf.cc index b3bbc16a3e..9c0091d2bc 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<Object> obj) { } // Create a new PerformanceEntry object -const Local<Object> PerformanceEntry::ToObject() const { - Local<Object> obj = - env_->performance_entry_template() - ->NewInstance(env_->context()).ToLocalChecked(); +MaybeLocal<Object> PerformanceEntry::ToObject() const { + Local<Object> obj; + if (!env_->performance_entry_template() + ->NewInstance(env_->context()) + .ToLocal(&obj)) { + return MaybeLocal<Object>(); + } InitObject(*this, obj); return obj; } @@ -154,7 +158,8 @@ void Mark(const FunctionCallbackInfo<Value>& args) { *name, now / 1000); PerformanceEntry entry(env, *name, "mark", now, now); - Local<Object> obj = entry.ToObject(); + Local<Object> 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<Value>& args) { *name, *name, endTimestamp / 1000); PerformanceEntry entry(env, *name, "measure", startTimestamp, endTimestamp); - Local<Object> obj = entry.ToObject(); + Local<Object> 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<Value>& args) { // Creates a GC Performance Entry and passes it to observers void PerformanceGCCallback(Environment* env, void* ptr) { - GCPerformanceEntry* entry = static_cast<GCPerformanceEntry*>(ptr); + std::unique_ptr<GCPerformanceEntry> entry{ + static_cast<GCPerformanceEntry*>(ptr)}; HandleScope scope(env->isolate()); Local<Context> context = env->context(); AliasedBuffer<uint32_t, Uint32Array>& observers = env->performance_state()->observers; if (observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]) { - Local<Object> obj = entry->ToObject(); + Local<Object> obj; + if (!entry->ToObject().ToLocal(&obj)) return; PropertyAttribute attr = static_cast<PropertyAttribute>(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<Value>& args) { return; PerformanceEntry entry(env, *name, "function", start, end); - Local<Object> obj = entry.ToObject(); + Local<Object> 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 fe418ad441..56140bd62d 100644 --- a/src/node_perf.h +++ b/src/node_perf.h @@ -75,7 +75,7 @@ class PerformanceEntry { virtual ~PerformanceEntry() { } - virtual const Local<Object> ToObject() const; + virtual v8::MaybeLocal<Object> ToObject() const; Environment* env() const { return env_; } |