@@ -20,6 +20,7 @@ using v8::HandleScope;
20
20
using v8::Integer;
21
21
using v8::Isolate;
22
22
using v8::Local;
23
+ using v8::MaybeLocal;
23
24
using v8::Name;
24
25
using v8::NewStringType;
25
26
using v8::Number;
@@ -102,10 +103,13 @@ inline void InitObject(const PerformanceEntry& entry, Local<Object> obj) {
102
103
}
103
104
104
105
// 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
+ }
109
113
InitObject (*this , obj);
110
114
return obj;
111
115
}
@@ -154,7 +158,8 @@ void Mark(const FunctionCallbackInfo<Value>& args) {
154
158
*name, now / 1000 );
155
159
156
160
PerformanceEntry entry (env, *name, " mark" , now, now);
157
- Local<Object> obj = entry.ToObject ();
161
+ Local<Object> obj;
162
+ if (!entry.ToObject ().ToLocal (&obj)) return ;
158
163
PerformanceEntry::Notify (env, entry.kind (), obj);
159
164
args.GetReturnValue ().Set (obj);
160
165
}
@@ -217,7 +222,8 @@ void Measure(const FunctionCallbackInfo<Value>& args) {
217
222
*name, *name, endTimestamp / 1000 );
218
223
219
224
PerformanceEntry entry (env, *name, " measure" , startTimestamp, endTimestamp);
220
- Local<Object> obj = entry.ToObject ();
225
+ Local<Object> obj;
226
+ if (!entry.ToObject ().ToLocal (&obj)) return ;
221
227
PerformanceEntry::Notify (env, entry.kind (), obj);
222
228
args.GetReturnValue ().Set (obj);
223
229
}
@@ -242,14 +248,16 @@ void SetupPerformanceObservers(const FunctionCallbackInfo<Value>& args) {
242
248
243
249
// Creates a GC Performance Entry and passes it to observers
244
250
void PerformanceGCCallback (Environment* env, void * ptr) {
245
- GCPerformanceEntry* entry = static_cast <GCPerformanceEntry*>(ptr);
251
+ std::unique_ptr<GCPerformanceEntry> entry{
252
+ static_cast <GCPerformanceEntry*>(ptr)};
246
253
HandleScope scope (env->isolate ());
247
254
Local<Context> context = env->context ();
248
255
249
256
AliasedBuffer<uint32_t , Uint32Array>& observers =
250
257
env->performance_state ()->observers ;
251
258
if (observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]) {
252
- Local<Object> obj = entry->ToObject ();
259
+ Local<Object> obj;
260
+ if (!entry->ToObject ().ToLocal (&obj)) return ;
253
261
PropertyAttribute attr =
254
262
static_cast <PropertyAttribute>(ReadOnly | DontDelete);
255
263
obj->DefineOwnProperty (context,
@@ -258,8 +266,6 @@ void PerformanceGCCallback(Environment* env, void* ptr) {
258
266
attr).FromJust ();
259
267
PerformanceEntry::Notify (env, entry->kind (), obj);
260
268
}
261
-
262
- delete entry;
263
269
}
264
270
265
271
// Marks the start of a GC cycle
@@ -359,7 +365,8 @@ void TimerFunctionCall(const FunctionCallbackInfo<Value>& args) {
359
365
return ;
360
366
361
367
PerformanceEntry entry (env, *name, " function" , start, end);
362
- Local<Object> obj = entry.ToObject ();
368
+ Local<Object> obj;
369
+ if (!entry.ToObject ().ToLocal (&obj)) return ;
363
370
for (idx = 0 ; idx < count; idx++)
364
371
obj->Set (context, idx, args[idx]).FromJust ();
365
372
PerformanceEntry::Notify (env, entry.kind (), obj);
0 commit comments