Permalink
Browse files

src: pass along errors from perf obj instantiation

PR-URL: #25734
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
  • Loading branch information...
addaleax authored and targos committed Jan 27, 2019
1 parent 5add2b5 commit ced4e7150468481825eb9e7f306cbf31f756a79c
Showing with 23 additions and 14 deletions.
  1. +4 −2 src/node_http2.cc
  2. +18 −11 src/node_perf.cc
  3. +1 −1 src/node_perf.h
@@ -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));
}

@@ -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);
@@ -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_; }

0 comments on commit ced4e71

Please sign in to comment.