@@ -425,33 +425,31 @@ void WallProfiler::Dispose(Isolate* isolate) {
425425 }
426426}
427427
428+ template <typename T>
429+ decltype (auto ) ToLocalValue(Local<Value> v) {
430+ return Nan::MaybeLocal<T>(v.template As <T>()).ToLocalChecked ()->Value ();
431+ }
432+
428433NAN_METHOD (WallProfiler::New) {
429434 if (info.Length () != 4 ) {
430435 return Nan::ThrowTypeError (" WallProfiler must have four arguments." );
431436 }
432437 if (!info[0 ]->IsNumber ()) {
433438 return Nan::ThrowTypeError (" Sample rate must be a number." );
434439 }
435-
436440 if (!info[1 ]->IsNumber ()) {
437441 return Nan::ThrowTypeError (" Duration must be a number." );
438442 }
439-
440443 if (!info[2 ]->IsBoolean ()) {
441444 return Nan::ThrowTypeError (" includeLines must be a boolean." );
442445 }
443-
444446 if (!info[3 ]->IsBoolean ()) {
445447 return Nan::ThrowTypeError (" withLabels must be a boolean." );
446448 }
447449
448450 if (info.IsConstructCall ()) {
449- int interval = Nan::MaybeLocal<Integer>(info[0 ].As <Integer>())
450- .ToLocalChecked ()
451- ->Value ();
452- int duration = Nan::MaybeLocal<Integer>(info[1 ].As <Integer>())
453- .ToLocalChecked ()
454- ->Value ();
451+ int interval = ToLocalValue<Integer>(info[0 ]);
452+ int duration = ToLocalValue<Integer>(info[1 ]);
455453
456454 if (interval <= 0 ) {
457455 return Nan::ThrowTypeError (" Sample rate must be positive." );
@@ -463,13 +461,8 @@ NAN_METHOD(WallProfiler::New) {
463461 return Nan::ThrowTypeError (" Duration must not be less than sample rate." );
464462 }
465463
466- bool includeLines = Nan::MaybeLocal<Boolean>(info[2 ].As <Boolean>())
467- .ToLocalChecked ()
468- ->Value ();
469-
470- bool withLabels = Nan::MaybeLocal<Boolean>(info[3 ].As <Boolean>())
471- .ToLocalChecked ()
472- ->Value ();
464+ bool includeLines = ToLocalValue<Boolean>(info[2 ]);
465+ bool withLabels = ToLocalValue<Boolean>(info[3 ]);
473466
474467 WallProfiler* obj =
475468 new WallProfiler (interval, duration, includeLines, withLabels);
@@ -503,8 +496,7 @@ NAN_METHOD(WallProfiler::Stop) {
503496 if (!info[0 ]->IsBoolean ()) {
504497 return Nan::ThrowTypeError (" restart must be a boolean." );
505498 }
506- bool restart =
507- Nan::MaybeLocal<Boolean>(info[0 ].As <Boolean>()).ToLocalChecked ()->Value ();
499+ bool restart = ToLocalValue<Boolean>(info[0 ]);
508500
509501 WallProfiler* wallProfiler =
510502 Nan::ObjectWrap::Unwrap<WallProfiler>(info.Holder ());
0 commit comments