Skip to content

Commit

Permalink
XS: report unhandled rejection reason
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Soquet authored and Michael Kellner committed Mar 11, 2022
1 parent 2f6728e commit cc15a84
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions xs/sources/xsPromise.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,14 @@ void fxNewPromiseCapabilityCallback(txMachine* the)

void fxAddUnhandledRejection(txMachine* the, txSlot* promise)
{
txSlot* reason = mxPromiseResult(promise);
txSlot* list = &mxUnhandledPromises;
txSlot** address = &list->value.reference->next;
txSlot* slot;
while ((slot = *address)) {
if (slot->value.weakRef.target == promise)
break;
slot = slot->next;
address = &slot->next;
}
if (!slot) {
Expand All @@ -211,26 +213,40 @@ void fxAddUnhandledRejection(txMachine* the, txSlot* promise)
slot = *address = fxNewSlot(the);
slot->kind = XS_WEAK_REF_KIND;
slot->value.weakRef.target = promise;
slot = slot->next = fxNewSlot(the);
slot->kind = reason->kind;
slot->value = reason->value;
}
}

void fxCheckUnhandledRejections(txMachine* the, txBoolean atExit)
{
txSlot* list = &mxUnhandledPromises;
if (atExit) {
if (list->value.reference->next)
txSlot* slot = list->value.reference->next;
while (slot) {
slot = slot->next;
mxException.value = slot->value;
mxException.kind = slot->kind;
fxAbort(the, XS_UNHANDLED_REJECTION_EXIT);
slot = slot->next;
}
}
else {
txSlot** address = &list->value.reference->next;
txSlot* slot;
while ((slot = *address)) {
if (slot->value.weakRef.target == C_NULL) {
slot = slot->next;
*address = slot->next;
mxException.value = slot->value;
mxException.kind = slot->kind;
fxAbort(the, XS_UNHANDLED_REJECTION_EXIT);
}
else
else {
slot = slot->next;
address = &slot->next;
}
}
}
}
Expand Down Expand Up @@ -1105,9 +1121,11 @@ void fxQueueJob(txMachine* the, txInteger count, txSlot* promise)
txSlot** address = &list->value.reference->next;
while ((slot = *address)) {
if (slot->value.weakRef.target == promise) {
slot = slot->next;
*address = slot->next;
break;
}
slot = slot->next;
address = &slot->next;
}
#ifdef mxPromisePrint
Expand Down

0 comments on commit cc15a84

Please sign in to comment.