Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ced4e71

Browse filesBrowse files
addaleaxtargos
authored andcommitted
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>
1 parent 5add2b5 commit ced4e71
Copy full SHA for ced4e71

File tree

Expand file treeCollapse file tree

3 files changed

+23
-14
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+23
-14
lines changed
Open diff view settings
Collapse file

‎src/node_http2.cc‎

Copy file name to clipboardExpand all lines: src/node_http2.cc
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,8 @@ void Http2Stream::EmitStatistics() {
697697
}
698698
buffer[IDX_STREAM_STATS_SENTBYTES] = entry->sent_bytes();
699699
buffer[IDX_STREAM_STATS_RECEIVEDBYTES] = entry->received_bytes();
700-
entry->Notify(entry->ToObject());
700+
Local<Object> obj;
701+
if (entry->ToObject().ToLocal(&obj)) entry->Notify(obj);
701702
}, static_cast<void*>(entry));
702703
}
703704

@@ -726,7 +727,8 @@ void Http2Session::EmitStatistics() {
726727
buffer[IDX_SESSION_STATS_DATA_RECEIVED] = entry->data_received();
727728
buffer[IDX_SESSION_STATS_MAX_CONCURRENT_STREAMS] =
728729
entry->max_concurrent_streams();
729-
entry->Notify(entry->ToObject());
730+
Local<Object> obj;
731+
if (entry->ToObject().ToLocal(&obj)) entry->Notify(obj);
730732
}, static_cast<void*>(entry));
731733
}
732734

Collapse file

‎src/node_perf.cc‎

Copy file name to clipboardExpand all lines: src/node_perf.cc
+18-11Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using v8::HandleScope;
2020
using v8::Integer;
2121
using v8::Isolate;
2222
using v8::Local;
23+
using v8::MaybeLocal;
2324
using v8::Name;
2425
using v8::NewStringType;
2526
using v8::Number;
@@ -102,10 +103,13 @@ inline void InitObject(const PerformanceEntry& entry, Local<Object> obj) {
102103
}
103104

104105
// Create a new PerformanceEntry object
105-
const Local<Object> PerformanceEntry::ToObject() const {
106-
Local<Object> obj =
107-
env_->performance_entry_template()
108-
->NewInstance(env_->context()).ToLocalChecked();
106+
MaybeLocal<Object> PerformanceEntry::ToObject() const {
107+
Local<Object> obj;
108+
if (!env_->performance_entry_template()
109+
->NewInstance(env_->context())
110+
.ToLocal(&obj)) {
111+
return MaybeLocal<Object>();
112+
}
109113
InitObject(*this, obj);
110114
return obj;
111115
}
@@ -154,7 +158,8 @@ void Mark(const FunctionCallbackInfo<Value>& args) {
154158
*name, now / 1000);
155159

156160
PerformanceEntry entry(env, *name, "mark", now, now);
157-
Local<Object> obj = entry.ToObject();
161+
Local<Object> obj;
162+
if (!entry.ToObject().ToLocal(&obj)) return;
158163
PerformanceEntry::Notify(env, entry.kind(), obj);
159164
args.GetReturnValue().Set(obj);
160165
}
@@ -217,7 +222,8 @@ void Measure(const FunctionCallbackInfo<Value>& args) {
217222
*name, *name, endTimestamp / 1000);
218223

219224
PerformanceEntry entry(env, *name, "measure", startTimestamp, endTimestamp);
220-
Local<Object> obj = entry.ToObject();
225+
Local<Object> obj;
226+
if (!entry.ToObject().ToLocal(&obj)) return;
221227
PerformanceEntry::Notify(env, entry.kind(), obj);
222228
args.GetReturnValue().Set(obj);
223229
}
@@ -242,14 +248,16 @@ void SetupPerformanceObservers(const FunctionCallbackInfo<Value>& args) {
242248

243249
// Creates a GC Performance Entry and passes it to observers
244250
void PerformanceGCCallback(Environment* env, void* ptr) {
245-
GCPerformanceEntry* entry = static_cast<GCPerformanceEntry*>(ptr);
251+
std::unique_ptr<GCPerformanceEntry> entry{
252+
static_cast<GCPerformanceEntry*>(ptr)};
246253
HandleScope scope(env->isolate());
247254
Local<Context> context = env->context();
248255

249256
AliasedBuffer<uint32_t, Uint32Array>& observers =
250257
env->performance_state()->observers;
251258
if (observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]) {
252-
Local<Object> obj = entry->ToObject();
259+
Local<Object> obj;
260+
if (!entry->ToObject().ToLocal(&obj)) return;
253261
PropertyAttribute attr =
254262
static_cast<PropertyAttribute>(ReadOnly | DontDelete);
255263
obj->DefineOwnProperty(context,
@@ -258,8 +266,6 @@ void PerformanceGCCallback(Environment* env, void* ptr) {
258266
attr).FromJust();
259267
PerformanceEntry::Notify(env, entry->kind(), obj);
260268
}
261-
262-
delete entry;
263269
}
264270

265271
// Marks the start of a GC cycle
@@ -359,7 +365,8 @@ void TimerFunctionCall(const FunctionCallbackInfo<Value>& args) {
359365
return;
360366

361367
PerformanceEntry entry(env, *name, "function", start, end);
362-
Local<Object> obj = entry.ToObject();
368+
Local<Object> obj;
369+
if (!entry.ToObject().ToLocal(&obj)) return;
363370
for (idx = 0; idx < count; idx++)
364371
obj->Set(context, idx, args[idx]).FromJust();
365372
PerformanceEntry::Notify(env, entry.kind(), obj);
Collapse file

‎src/node_perf.h‎

Copy file name to clipboardExpand all lines: src/node_perf.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class PerformanceEntry {
7575

7676
virtual ~PerformanceEntry() { }
7777

78-
virtual const Local<Object> ToObject() const;
78+
virtual v8::MaybeLocal<Object> ToObject() const;
7979

8080
Environment* env() const { return env_; }
8181

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.