Skip to content

Commit cc15a84

Browse files
Patrick SoquetMichael Kellner
Patrick Soquet
authored and
Michael Kellner
committed
XS: report unhandled rejection reason
1 parent 2f6728e commit cc15a84

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

xs/sources/xsPromise.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,14 @@ void fxNewPromiseCapabilityCallback(txMachine* the)
196196

197197
void fxAddUnhandledRejection(txMachine* the, txSlot* promise)
198198
{
199+
txSlot* reason = mxPromiseResult(promise);
199200
txSlot* list = &mxUnhandledPromises;
200201
txSlot** address = &list->value.reference->next;
201202
txSlot* slot;
202203
while ((slot = *address)) {
203204
if (slot->value.weakRef.target == promise)
204205
break;
206+
slot = slot->next;
205207
address = &slot->next;
206208
}
207209
if (!slot) {
@@ -211,26 +213,40 @@ void fxAddUnhandledRejection(txMachine* the, txSlot* promise)
211213
slot = *address = fxNewSlot(the);
212214
slot->kind = XS_WEAK_REF_KIND;
213215
slot->value.weakRef.target = promise;
216+
slot = slot->next = fxNewSlot(the);
217+
slot->kind = reason->kind;
218+
slot->value = reason->value;
214219
}
215220
}
216221

217222
void fxCheckUnhandledRejections(txMachine* the, txBoolean atExit)
218223
{
219224
txSlot* list = &mxUnhandledPromises;
220225
if (atExit) {
221-
if (list->value.reference->next)
226+
txSlot* slot = list->value.reference->next;
227+
while (slot) {
228+
slot = slot->next;
229+
mxException.value = slot->value;
230+
mxException.kind = slot->kind;
222231
fxAbort(the, XS_UNHANDLED_REJECTION_EXIT);
232+
slot = slot->next;
233+
}
223234
}
224235
else {
225236
txSlot** address = &list->value.reference->next;
226237
txSlot* slot;
227238
while ((slot = *address)) {
228239
if (slot->value.weakRef.target == C_NULL) {
240+
slot = slot->next;
229241
*address = slot->next;
242+
mxException.value = slot->value;
243+
mxException.kind = slot->kind;
230244
fxAbort(the, XS_UNHANDLED_REJECTION_EXIT);
231245
}
232-
else
246+
else {
247+
slot = slot->next;
233248
address = &slot->next;
249+
}
234250
}
235251
}
236252
}
@@ -1105,9 +1121,11 @@ void fxQueueJob(txMachine* the, txInteger count, txSlot* promise)
11051121
txSlot** address = &list->value.reference->next;
11061122
while ((slot = *address)) {
11071123
if (slot->value.weakRef.target == promise) {
1124+
slot = slot->next;
11081125
*address = slot->next;
11091126
break;
11101127
}
1128+
slot = slot->next;
11111129
address = &slot->next;
11121130
}
11131131
#ifdef mxPromisePrint

0 commit comments

Comments
 (0)