Skip to content

Commit

Permalink
src: pass along errors from perf obj instantiation
Browse files Browse the repository at this point in the history
PR-URL: #25734
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
  • Loading branch information
addaleax committed Jan 29, 2019
1 parent 95571ac commit 77fa310
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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));
}

Expand Down
29 changes: 18 additions & 11 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/node_perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }

Expand Down

0 comments on commit 77fa310

Please sign in to comment.