Skip to content

Commit f064e90

Browse files
refactor: simplify Then and Catch method
1 parent 88ad5b9 commit f064e90

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

napi-inl.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,16 +2818,14 @@ inline MaybeOrValue<Promise> Promise::Then(napi_value onFulfilled) const {
28182818
#ifdef NODE_ADDON_API_ENABLE_MAYBE
28192819
MaybeOrValue<Value> thenMethodMaybe = Get("then");
28202820
Function thenMethod = thenMethodMaybe.Unwrap().As<Function>();
2821-
#else
2822-
Function thenMethod = Get("then").As<Function>();
2823-
#endif
28242821
MaybeOrValue<Value> result = thenMethod.Call(*this, {onFulfilled});
2825-
#ifdef NODE_ADDON_API_ENABLE_MAYBE
28262822
if (result.IsJust()) {
28272823
return Just(scope.Escape(result.Unwrap()).As<Promise>());
28282824
}
28292825
return Nothing<Promise>();
28302826
#else
2827+
Function thenMethod = Get("then").As<Function>();
2828+
MaybeOrValue<Value> result = thenMethod.Call(*this, {onFulfilled});
28312829
if (scope.Env().IsExceptionPending()) {
28322830
return Promise();
28332831
}
@@ -2840,16 +2838,14 @@ inline MaybeOrValue<Promise> Promise::Then(napi_value onFulfilled, napi_value on
28402838
#ifdef NODE_ADDON_API_ENABLE_MAYBE
28412839
MaybeOrValue<Value> thenMethodMaybe = Get("then");
28422840
Function thenMethod = thenMethodMaybe.Unwrap().As<Function>();
2843-
#else
2844-
Function thenMethod = Get("then").As<Function>();
2845-
#endif
28462841
MaybeOrValue<Value> result = thenMethod.Call(*this, {onFulfilled, onRejected});
2847-
#ifdef NODE_ADDON_API_ENABLE_MAYBE
28482842
if (result.IsJust()) {
28492843
return Just(scope.Escape(result.Unwrap()).As<Promise>());
28502844
}
28512845
return Nothing<Promise>();
28522846
#else
2847+
Function thenMethod = Get("then").As<Function>();
2848+
MaybeOrValue<Value> result = thenMethod.Call(*this, {onFulfilled, onRejected});
28532849
if (scope.Env().IsExceptionPending()) {
28542850
return Promise();
28552851
}
@@ -2862,16 +2858,14 @@ inline MaybeOrValue<Promise> Promise::Catch(napi_value onRejected) const {
28622858
#ifdef NODE_ADDON_API_ENABLE_MAYBE
28632859
MaybeOrValue<Value> catchMethodMaybe = Get("catch");
28642860
Function catchMethod = catchMethodMaybe.Unwrap().As<Function>();
2865-
#else
2866-
Function catchMethod = Get("catch").As<Function>();
2867-
#endif
28682861
MaybeOrValue<Value> result = catchMethod.Call(*this, {onRejected});
2869-
#ifdef NODE_ADDON_API_ENABLE_MAYBE
28702862
if (result.IsJust()) {
28712863
return Just(scope.Escape(result.Unwrap()).As<Promise>());
28722864
}
28732865
return Nothing<Promise>();
28742866
#else
2867+
Function catchMethod = Get("catch").As<Function>();
2868+
MaybeOrValue<Value> result = catchMethod.Call(*this, {onRejected});
28752869
if (scope.Env().IsExceptionPending()) {
28762870
return Promise();
28772871
}

0 commit comments

Comments
 (0)