Skip to content

Commit 7e3a036

Browse files
feat: add default missing definition for constructor
1 parent c6dc19c commit 7e3a036

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

napi-inl.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,6 +2811,8 @@ inline void Promise::CheckCast(napi_env env, napi_value value) {
28112811
NAPI_CHECK(result, "Promise::CheckCast", "value is not promise");
28122812
}
28132813

2814+
inline Promise::Promise() : Object() {}
2815+
28142816
inline Promise::Promise(napi_env env, napi_value value) : Object(env, value) {}
28152817

28162818
inline MaybeOrValue<Promise> Promise::Then(napi_value onFulfilled) const {
@@ -2820,7 +2822,8 @@ inline MaybeOrValue<Promise> Promise::Then(napi_value onFulfilled) const {
28202822
if (!Get("then").UnwrapTo(&thenMethod)) {
28212823
return Nothing<Promise>();
28222824
}
2823-
MaybeOrValue<Value> result = thenMethod.As<Function>().Call(*this, {onFulfilled});
2825+
MaybeOrValue<Value> result =
2826+
thenMethod.As<Function>().Call(*this, {onFulfilled});
28242827
if (result.IsJust()) {
28252828
return Just(scope.Escape(result.Unwrap()).As<Promise>());
28262829
}
@@ -2835,21 +2838,24 @@ inline MaybeOrValue<Promise> Promise::Then(napi_value onFulfilled) const {
28352838
#endif
28362839
}
28372840

2838-
inline MaybeOrValue<Promise> Promise::Then(napi_value onFulfilled, napi_value onRejected) const {
2841+
inline MaybeOrValue<Promise> Promise::Then(napi_value onFulfilled,
2842+
napi_value onRejected) const {
28392843
EscapableHandleScope scope(_env);
28402844
#ifdef NODE_ADDON_API_ENABLE_MAYBE
28412845
Value thenMethod;
28422846
if (!Get("then").UnwrapTo(&thenMethod)) {
28432847
return Nothing<Promise>();
28442848
}
2845-
MaybeOrValue<Value> result = thenMethod.As<Function>().Call(*this, {onFulfilled, onRejected});
2849+
MaybeOrValue<Value> result =
2850+
thenMethod.As<Function>().Call(*this, {onFulfilled, onRejected});
28462851
if (result.IsJust()) {
28472852
return Just(scope.Escape(result.Unwrap()).As<Promise>());
28482853
}
28492854
return Nothing<Promise>();
28502855
#else
28512856
Function thenMethod = Get("then").As<Function>();
2852-
MaybeOrValue<Value> result = thenMethod.Call(*this, {onFulfilled, onRejected});
2857+
MaybeOrValue<Value> result =
2858+
thenMethod.Call(*this, {onFulfilled, onRejected});
28532859
if (scope.Env().IsExceptionPending()) {
28542860
return Promise();
28552861
}
@@ -2864,7 +2870,8 @@ inline MaybeOrValue<Promise> Promise::Catch(napi_value onRejected) const {
28642870
if (!Get("catch").UnwrapTo(&catchMethod)) {
28652871
return Nothing<Promise>();
28662872
}
2867-
MaybeOrValue<Value> result = catchMethod.As<Function>().Call(*this, {onRejected});
2873+
MaybeOrValue<Value> result =
2874+
catchMethod.As<Function>().Call(*this, {onRejected});
28682875
if (result.IsJust()) {
28692876
return Just(scope.Escape(result.Unwrap()).As<Promise>());
28702877
}
@@ -2883,8 +2890,10 @@ inline MaybeOrValue<Promise> Promise::Then(const Function& onFulfilled) const {
28832890
return Then(static_cast<napi_value>(onFulfilled));
28842891
}
28852892

2886-
inline MaybeOrValue<Promise> Promise::Then(const Function& onFulfilled, const Function& onRejected) const {
2887-
return Then(static_cast<napi_value>(onFulfilled), static_cast<napi_value>(onRejected));
2893+
inline MaybeOrValue<Promise> Promise::Then(const Function& onFulfilled,
2894+
const Function& onRejected) const {
2895+
return Then(static_cast<napi_value>(onFulfilled),
2896+
static_cast<napi_value>(onRejected));
28882897
}
28892898

28902899
inline MaybeOrValue<Promise> Promise::Catch(const Function& onRejected) const {

napi.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,11 +1578,13 @@ class Promise : public Object {
15781578
Promise(napi_env env, napi_value value);
15791579

15801580
MaybeOrValue<Promise> Then(napi_value onFulfilled) const;
1581-
MaybeOrValue<Promise> Then(napi_value onFulfilled, napi_value onRejected) const;
1581+
MaybeOrValue<Promise> Then(napi_value onFulfilled,
1582+
napi_value onRejected) const;
15821583
MaybeOrValue<Promise> Catch(napi_value onRejected) const;
15831584

15841585
MaybeOrValue<Promise> Then(const Function& onFulfilled) const;
1585-
MaybeOrValue<Promise> Then(const Function& onFulfilled, const Function& onRejected) const;
1586+
MaybeOrValue<Promise> Then(const Function& onFulfilled,
1587+
const Function& onRejected) const;
15861588
MaybeOrValue<Promise> Catch(const Function& onRejected) const;
15871589
};
15881590

test/promise.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Value ThenMethodOnFulfilled(const CallbackInfo& info) {
2828
auto deferred = Promise::Deferred::New(info.Env());
2929
Function onFulfilled = info[0].As<Function>();
3030

31-
Promise resultPromise = MaybeUnwrap(deferred.Promise().Then(onFulfilled));
31+
Promise resultPromise =
32+
MaybeUnwrap(deferred.Promise().Then(onFulfilled));
3233

3334
bool isPromise = resultPromise.IsPromise();
3435
deferred.Resolve(Number::New(info.Env(), 42));
@@ -45,7 +46,8 @@ Value ThenMethodOnFulfilledOnRejectedResolve(const CallbackInfo& info) {
4546
Function onFulfilled = info[0].As<Function>();
4647
Function onRejected = info[1].As<Function>();
4748

48-
Promise resultPromise = MaybeUnwrap(deferred.Promise().Then(onFulfilled, onRejected));
49+
Promise resultPromise =
50+
MaybeUnwrap(deferred.Promise().Then(onFulfilled, onRejected));
4951

5052
bool isPromise = resultPromise.IsPromise();
5153
deferred.Resolve(Number::New(info.Env(), 42));

0 commit comments

Comments
 (0)