MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxResolvePromise

Function fxResolvePromise

xs/sources/xsPromise.c:720–801  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

718}
719
720void fxResolvePromise(txMachine* the)
721{
722 txSlot* slot;
723 txSlot* promise;
724 txSlot* argument;
725 txSlot* result;
726 slot = mxFunctionInstanceHome(mxFunction->value.reference)->value.home.object->next;
727 if (slot->value.boolean)
728 return;
729 slot->value.boolean = 1;
730 mxPushSlot(slot->next);
731 promise = the->stack->value.reference;
732 slot->next = C_NULL;
733 if (mxArgc > 0)
734 mxPushSlot(mxArgv(0));
735 else
736 mxPushUndefined();
737 argument = the->stack;
738#ifdef mxPromisePrint
739 fprintf(stderr, "fxResolvePromise %d\n", promise->next->ID);
740#endif
741 mxTry(the) {
742 if (mxIsReference(argument)) {
743 if (argument->value.reference == promise)
744 mxTypeError("promise resolves itself");
745 mxPushSlot(argument);
746 mxGetID(mxID(_then));
747 slot = the->stack;
748 if (fxIsCallable(the, slot)) {
749#ifdef mxPromisePrint
750 fprintf(stderr, "fxResolvePromise then %d\n", promise->next->ID);
751#endif
752 mxPushSlot(argument);
753 mxPush(mxOnThenableFunction);
754 mxCall();
755 fxPushPromiseFunctions(the, promise);
756 mxPushSlot(slot);
757 fxQueueJob(the, 3, promise);
758 goto bail;
759 }
760 mxPop();
761 }
762 result = mxPromiseResult(promise);
763 result->kind = argument->kind;
764 result->value = argument->value;
765 slot = mxPromiseThens(promise)->value.reference->next;
766 while (slot) {
767 mxPushReference(slot->value.reference);
768 mxPush(mxOnResolvedPromiseFunction);
769 mxCall();
770 mxPushSlot(result);
771 fxQueueJob(the, 1, promise);
772 slot = slot->next;
773 }
774 mxPromiseThens(promise)->value.reference->next = C_NULL;
775 slot = mxPromiseStatus(promise);
776 slot->value.integer = mxFulfilledStatus;
777 }

Callers

nothing calls this directly

Calls 4

fxIsCallableFunction · 0.85
fxPushPromiseFunctionsFunction · 0.85
fxQueueJobFunction · 0.85
fxAddUnhandledRejectionFunction · 0.85

Tested by

no test coverage detected