@@ -2816,9 +2816,11 @@ inline Promise::Promise(napi_env env, napi_value value) : Object(env, value) {}
28162816inline MaybeOrValue<Promise> Promise::Then (napi_value onFulfilled) const {
28172817 EscapableHandleScope scope (_env);
28182818#ifdef NODE_ADDON_API_ENABLE_MAYBE
2819- MaybeOrValue<Value> thenMethodMaybe = Get (" then" );
2820- Function thenMethod = thenMethodMaybe.Unwrap ().As <Function>();
2821- MaybeOrValue<Value> result = thenMethod.Call (*this , {onFulfilled});
2819+ Value thenMethod;
2820+ if (!Get (" then" ).UnwrapTo (&thenMethod)) {
2821+ return Nothing<Promise>();
2822+ }
2823+ MaybeOrValue<Value> result = thenMethod.As <Function>().Call (*this , {onFulfilled});
28222824 if (result.IsJust ()) {
28232825 return Just (scope.Escape (result.Unwrap ()).As <Promise>());
28242826 }
@@ -2836,9 +2838,11 @@ inline MaybeOrValue<Promise> Promise::Then(napi_value onFulfilled) const {
28362838inline MaybeOrValue<Promise> Promise::Then (napi_value onFulfilled, napi_value onRejected) const {
28372839 EscapableHandleScope scope (_env);
28382840#ifdef NODE_ADDON_API_ENABLE_MAYBE
2839- MaybeOrValue<Value> thenMethodMaybe = Get (" then" );
2840- Function thenMethod = thenMethodMaybe.Unwrap ().As <Function>();
2841- MaybeOrValue<Value> result = thenMethod.Call (*this , {onFulfilled, onRejected});
2841+ Value thenMethod;
2842+ if (!Get (" then" ).UnwrapTo (&thenMethod)) {
2843+ return Nothing<Promise>();
2844+ }
2845+ MaybeOrValue<Value> result = thenMethod.As <Function>().Call (*this , {onFulfilled, onRejected});
28422846 if (result.IsJust ()) {
28432847 return Just (scope.Escape (result.Unwrap ()).As <Promise>());
28442848 }
@@ -2856,9 +2860,11 @@ inline MaybeOrValue<Promise> Promise::Then(napi_value onFulfilled, napi_value on
28562860inline MaybeOrValue<Promise> Promise::Catch (napi_value onRejected) const {
28572861 EscapableHandleScope scope (_env);
28582862#ifdef NODE_ADDON_API_ENABLE_MAYBE
2859- MaybeOrValue<Value> catchMethodMaybe = Get (" catch" );
2860- Function catchMethod = catchMethodMaybe.Unwrap ().As <Function>();
2861- MaybeOrValue<Value> result = catchMethod.Call (*this , {onRejected});
2863+ Value catchMethod;
2864+ if (!Get (" catch" ).UnwrapTo (&catchMethod)) {
2865+ return Nothing<Promise>();
2866+ }
2867+ MaybeOrValue<Value> result = catchMethod.As <Function>().Call (*this , {onRejected});
28622868 if (result.IsJust ()) {
28632869 return Just (scope.Escape (result.Unwrap ()).As <Promise>());
28642870 }
0 commit comments