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

Function fxNewHostFunction

xs/sources/xsAPI.c:591–636  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

589}
590
591txSlot* fxNewHostFunction(txMachine* the, txCallback theCallback, txInteger theLength, txInteger name, txInteger profileID)
592{
593 txSlot* instance;
594 txSlot* property;
595
596 mxPushUndefined();
597 instance = fxNewSlot(the);
598 instance->flag |= XS_CAN_CALL_FLAG;
599 instance->kind = XS_INSTANCE_KIND;
600 instance->value.instance.garbage = C_NULL;
601 instance->value.instance.prototype = mxFunctionPrototype.value.reference;
602 the->stack->value.reference = instance;
603 the->stack->kind = XS_REFERENCE_KIND;
604
605 /* CALLBACK */
606 property = instance->next = fxNewSlot(the);
607 property->flag = XS_INTERNAL_FLAG;
608 property->kind = XS_CALLBACK_KIND;
609 property->value.callback.address = theCallback;
610 property->value.callback.closures = C_NULL;
611
612 /* HOME */
613 property = property->next = fxNewSlot(the);
614 if (profileID != XS_NO_ID)
615 property->ID = profileID;
616 else
617 property->ID = fxGenerateProfileID(the);
618 property->flag = XS_INTERNAL_FLAG;
619 property->kind = XS_HOME_KIND;
620 property->value.home.object = C_NULL;
621 if (the->frame && (mxFunction->kind == XS_REFERENCE_KIND) && (mxIsFunction(mxFunction->value.reference))) {
622 txSlot* slot = mxFunctionInstanceHome(mxFunction->value.reference);
623 property->value.home.module = slot->value.home.module;
624 }
625 else
626 property->value.home.module = C_NULL;
627
628 /* LENGTH */
629 if (gxDefaults.newFunctionLength)
630 gxDefaults.newFunctionLength(the, instance, theLength);
631
632 /* NAME */
633 fxRenameFunction(the, instance, name, 0, XS_NO_ID, C_NULL);
634
635 return instance;
636}
637
638txSlot* fxNewHostInstance(txMachine* the)
639{

Callers 15

_xsbug_import_Function · 0.85
fxBuildHostFunctionFunction · 0.85
fxRunModuleFileFunction · 0.85
fxBuildModuleFunction · 0.85
fxExecuteModulesFunction · 0.85
fxLoadModulesPromiseFunction · 0.85

Calls 3

fxNewSlotFunction · 0.85
fxRenameFunctionFunction · 0.85
fxGenerateProfileIDFunction · 0.70

Tested by

no test coverage detected