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

Function fxStepAsync

xs/sources/xsFunction.c:663–724  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

661}
662
663void fxStepAsync(txMachine* the, txSlot* instance, txFlag status)
664{
665 txSlot* state = instance->next->next;
666 txSlot* promise = state->next;
667 txSlot* resolveFunction = promise->next;
668 txSlot* rejectFunction = resolveFunction->next;
669 txSlot* resolveAwaitFunction = rejectFunction->next;
670 txSlot* rejectAwaitFunction = resolveAwaitFunction->next;
671 txSlot* value;
672 mxTry(the) {
673 the->status = status;
674 state->value.integer = XS_NO_CODE;
675 fxRunID(the, instance, XS_NO_ID);
676 value = the->stack;
677 if (state->value.integer == XS_NO_CODE) {
678 /* THIS */
679 mxPushUndefined();
680 /* FUNCTION */
681 mxPushSlot(resolveFunction);
682 mxCall();
683 /* ARGUMENTS */
684 mxPushSlot(value);
685 mxRunCount(1);
686 mxPop();
687 }
688 else {
689 if (mxIsReference(value) && mxIsPromise(value->value.reference)) {
690 mxDub();
691 mxGetID(mxID(_constructor));
692 if (fxIsSameValue(the, &mxPromiseConstructor, the->stack, 0)) {
693 mxPop();
694 fxPromiseThen(the, value->value.reference, resolveAwaitFunction, rejectAwaitFunction, C_NULL, C_NULL);
695 goto exit;
696 }
697 mxPop();
698 }
699 mxTemporary(resolveFunction);
700 mxTemporary(rejectFunction);
701 mxPush(mxPromiseConstructor);
702 fxNewPromiseCapability(the, resolveFunction, rejectFunction);
703#ifdef mxPromisePrint
704 fprintf(stderr, "fxStepAsync %d\n", the->stack->value.reference->next->ID);
705#endif
706 fxPromiseThen(the, the->stack->value.reference, resolveAwaitFunction, rejectAwaitFunction, C_NULL, C_NULL);
707 /* THIS */
708 mxPushUndefined();
709 /* FUNCTION */
710 mxPushSlot(resolveFunction);
711 mxCall();
712 /* ARGUMENTS */
713 mxPushSlot(value);
714 /* COUNT */
715 mxRunCount(1);
716 mxPop();
717 }
718exit:
719 mxPop();
720 }

Callers 3

fxResolveAwaitFunction · 0.85
fxRejectAwaitFunction · 0.85
fxRunAsyncFunction · 0.85

Calls 5

fxRunIDFunction · 0.85
fxIsSameValueFunction · 0.85
fxPromiseThenFunction · 0.85
fxNewPromiseCapabilityFunction · 0.85
fxRejectExceptionFunction · 0.85

Tested by

no test coverage detected