| 3035 | } |
| 3036 | |
| 3037 | inline MaybeOrValue<Promise> Promise::Catch(napi_value onRejected) const { |
| 3038 | EscapableHandleScope scope(_env); |
| 3039 | #ifdef NODE_ADDON_API_ENABLE_MAYBE |
| 3040 | Value catchMethod; |
| 3041 | if (!Get("catch").UnwrapTo(&catchMethod)) { |
| 3042 | return Nothing<Promise>(); |
| 3043 | } |
| 3044 | MaybeOrValue<Value> result = |
| 3045 | catchMethod.As<Function>().Call(*this, {onRejected}); |
| 3046 | if (result.IsJust()) { |
| 3047 | return Just(scope.Escape(result.Unwrap()).As<Promise>()); |
| 3048 | } |
| 3049 | return Nothing<Promise>(); |
| 3050 | #else |
| 3051 | Function catchMethod = Get("catch").As<Function>(); |
| 3052 | MaybeOrValue<Value> result = catchMethod.Call(*this, {onRejected}); |
| 3053 | if (scope.Env().IsExceptionPending()) { |
| 3054 | return Promise(); |
| 3055 | } |
| 3056 | return scope.Escape(result).As<Promise>(); |
| 3057 | #endif |
| 3058 | } |
| 3059 | |
| 3060 | inline MaybeOrValue<Promise> Promise::Then(const Function& onFulfilled) const { |
| 3061 | return Then(static_cast<napi_value>(onFulfilled)); |