@@ -40,6 +40,40 @@ Value ThenMethodOnFulfilled(const CallbackInfo& info) {
40
40
return result;
41
41
}
42
42
43
+ Value ThenMethodOnFulfilledOnRejectedResolve (const CallbackInfo& info) {
44
+ auto deferred = Promise::Deferred::New (info.Env ());
45
+ Function onFulfilled = info[0 ].As <Function>();
46
+ Function onRejected = info[1 ].As <Function>();
47
+
48
+ Promise resultPromise = MaybeUnwrap (deferred.Promise ().Then (onFulfilled, onRejected));
49
+
50
+ bool isPromise = resultPromise.IsPromise ();
51
+ deferred.Resolve (Number::New (info.Env (), 42 ));
52
+
53
+ Object result = Object::New (info.Env ());
54
+ result[" isPromise" ] = Boolean::New (info.Env (), isPromise);
55
+ result[" promise" ] = resultPromise;
56
+
57
+ return result;
58
+ }
59
+
60
+ Value ThenMethodOnFulfilledOnRejectedReject (const CallbackInfo& info) {
61
+ auto deferred = Promise::Deferred::New (info.Env ());
62
+ Function onFulfilled = info[0 ].As <Function>();
63
+ Function onRejected = info[1 ].As <Function>();
64
+
65
+ Promise resultPromise = MaybeUnwrap (deferred.Promise ().Then (onFulfilled, onRejected));
66
+
67
+ bool isPromise = resultPromise.IsPromise ();
68
+ deferred.Reject (String::New (info.Env (), " Rejected" ));
69
+
70
+ Object result = Object::New (info.Env ());
71
+ result[" isPromise" ] = Boolean::New (info.Env (), isPromise);
72
+ result[" promise" ] = resultPromise;
73
+
74
+ return result;
75
+ }
76
+
43
77
Object InitPromise (Env env) {
44
78
Object exports = Object::New (env);
45
79
@@ -48,7 +82,11 @@ Object InitPromise(Env env) {
48
82
exports[" rejectPromise" ] = Function::New (env, RejectPromise);
49
83
exports[" promiseReturnsCorrectEnv" ] =
50
84
Function::New (env, PromiseReturnsCorrectEnv);
51
- exports[" ThenMethodOnFulfilled" ] = Function::New (env, ThenMethodOnFulfilled);
85
+ exports[" thenMethodOnFulfilled" ] = Function::New (env, ThenMethodOnFulfilled);
86
+ exports[" thenMethodOnFulfilledOnRejectedResolve" ] =
87
+ Function::New (env, ThenMethodOnFulfilledOnRejectedResolve);
88
+ exports[" thenMethodOnFulfilledOnRejectedReject" ] =
89
+ Function::New (env, ThenMethodOnFulfilledOnRejectedReject);
52
90
53
91
return exports;
54
92
}
0 commit comments