@@ -2816,9 +2816,11 @@ inline Promise::Promise(napi_env env, napi_value value) : Object(env, value) {}
2816
2816
inline MaybeOrValue<Promise> Promise::Then (napi_value onFulfilled) const {
2817
2817
EscapableHandleScope scope (_env);
2818
2818
#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});
2822
2824
if (result.IsJust ()) {
2823
2825
return Just (scope.Escape (result.Unwrap ()).As <Promise>());
2824
2826
}
@@ -2836,9 +2838,11 @@ inline MaybeOrValue<Promise> Promise::Then(napi_value onFulfilled) const {
2836
2838
inline MaybeOrValue<Promise> Promise::Then (napi_value onFulfilled, napi_value onRejected) const {
2837
2839
EscapableHandleScope scope (_env);
2838
2840
#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});
2842
2846
if (result.IsJust ()) {
2843
2847
return Just (scope.Escape (result.Unwrap ()).As <Promise>());
2844
2848
}
@@ -2856,9 +2860,11 @@ inline MaybeOrValue<Promise> Promise::Then(napi_value onFulfilled, napi_value on
2856
2860
inline MaybeOrValue<Promise> Promise::Catch (napi_value onRejected) const {
2857
2861
EscapableHandleScope scope (_env);
2858
2862
#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});
2862
2868
if (result.IsJust ()) {
2863
2869
return Just (scope.Escape (result.Unwrap ()).As <Promise>());
2864
2870
}
0 commit comments