@@ -20,6 +20,7 @@ using v8::HandleScope;
2020using v8::Integer;
2121using v8::Isolate;
2222using v8::Local;
23+ using v8::MaybeLocal;
2324using v8::Name;
2425using v8::NewStringType;
2526using 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
244250void 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);
0 commit comments