| 578 | } |
| 579 | |
| 580 | void fxPromiseThen(txMachine* the, txSlot* promise, txSlot* onFullfilled, txSlot* onRejected, txSlot* resolveFunction, txSlot* rejectFunction) |
| 581 | { |
| 582 | txSlot* reaction; |
| 583 | txSlot* slot; |
| 584 | txSlot* status; |
| 585 | |
| 586 | reaction = fxNewInstance(the); |
| 587 | slot = reaction->next = fxNewSlot(the); |
| 588 | slot->flag = XS_INTERNAL_FLAG; |
| 589 | if (resolveFunction) { |
| 590 | slot->kind = resolveFunction->kind; |
| 591 | slot->value = resolveFunction->value; |
| 592 | } |
| 593 | slot = slot->next = fxNewSlot(the); |
| 594 | slot->flag = XS_INTERNAL_FLAG; |
| 595 | if (rejectFunction) { |
| 596 | slot->kind = rejectFunction->kind; |
| 597 | slot->value = rejectFunction->value; |
| 598 | } |
| 599 | slot = slot->next = fxNewSlot(the); |
| 600 | slot->ID = mxID(__onFullfilled_); |
| 601 | if (onFullfilled) { |
| 602 | slot->kind = onFullfilled->kind; |
| 603 | slot->value = onFullfilled->value; |
| 604 | } |
| 605 | slot = slot->next = fxNewSlot(the); |
| 606 | slot->ID = mxID(__onRejected_); |
| 607 | if (onRejected) { |
| 608 | slot->kind = onRejected->kind; |
| 609 | slot->value = onRejected->value; |
| 610 | } |
| 611 | if (resolveFunction) { |
| 612 | slot = slot->next = fxNewSlot(the); |
| 613 | slot->ID = mxID(__result_); |
| 614 | slot->kind = mxResult->kind; |
| 615 | slot->value = mxResult->value; |
| 616 | } |
| 617 | |
| 618 | status = mxPromiseStatus(promise); |
| 619 | if (status->value.integer == mxPendingStatus) { |
| 620 | txSlot** address = &(mxPromiseThens(promise)->value.reference->next); |
| 621 | while ((slot = *address)) |
| 622 | address = &(slot->next); |
| 623 | slot = *address = fxNewSlot(the); |
| 624 | slot->kind = XS_REFERENCE_KIND; |
| 625 | slot->value.reference = reaction; |
| 626 | } |
| 627 | else { |
| 628 | mxPushReference(reaction); |
| 629 | if (status->value.integer == mxFulfilledStatus) |
| 630 | mxPush(mxOnResolvedPromiseFunction); |
| 631 | else |
| 632 | mxPush(mxOnRejectedPromiseFunction); |
| 633 | mxCall(); |
| 634 | slot = mxPromiseResult(promise); |
| 635 | mxPushSlot(slot); |
| 636 | fxQueueJob(the, 1, promise); |
| 637 | } |
no test coverage detected