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

Function fx_Compartment

xs/sources/xsModule.c:2866–3152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2864}
2865
2866void fx_Compartment(txMachine* the)
2867{
2868 txSlot* module = mxFunctionInstanceHome(mxFunction->value.reference)->value.home.module;
2869 txSlot* program = C_NULL;
2870 txSlot* parent;
2871 txSlot* realm;
2872 txSlot* global = C_NULL;
2873 txSlot* closures = C_NULL;
2874 txSlot* slot;
2875 txSlot* target;
2876 txSlot* own;
2877 txInteger id;
2878
2879 if (!module) module = mxProgram.value.reference;
2880 mxTry(the) {
2881 if (!mxHasTarget)
2882 mxTypeError("call: Compartment");
2883
2884 mxPushSlot(mxTarget);
2885 fxGetPrototypeFromConstructor(the, &mxCompartmentPrototype);
2886 program = fxNewProgramInstance(the);
2887 mxPullSlot(mxResult);
2888
2889 // PARENT
2890 parent = mxModuleInstanceInternal(module)->value.module.realm;
2891 mxPushReference(parent);
2892
2893 // GLOBALS
2894 if (the->sharedMachine == C_NULL) {
2895 txSlot* instance;
2896 txSlot* property;
2897 txSlot* callback;
2898 mxPush(mxObjectPrototype);
2899 #ifdef mxLink
2900 global = fxNewObjectInstance(the);
2901 #else
2902 global = fxNewGlobalInstance(the);
2903 #endif
2904 slot = fxLastProperty(the, global);
2905 if (mxCompartmentGlobal.kind == XS_UNDEFINED_KIND) {
2906 for (id = XS_SYMBOL_ID_COUNT; id < _Infinity; id++)
2907 slot = fxNextSlotProperty(the, slot, &the->stackIntrinsics[-1 - id], mxID(id), XS_DONT_ENUM_FLAG);
2908 for (; id < _Compartment; id++)
2909 slot = fxNextSlotProperty(the, slot, &the->stackIntrinsics[-1 - id], mxID(id), XS_GET_ONLY);
2910 }
2911 else {
2912 txSlot* item = mxCompartmentGlobal.value.reference->next;
2913 for (id = XS_SYMBOL_ID_COUNT; id < _Infinity; id++) {
2914 mxPushSlot(item->value.array.address + id);
2915 slot = fxNextSlotProperty(the, slot, the->stack, mxID(id), XS_DONT_ENUM_FLAG);
2916 mxPop();
2917 }
2918 for (; id < _Compartment; id++) {
2919 mxPushSlot(item->value.array.address + id);
2920 slot = fxNextSlotProperty(the, slot, the->stack, mxID(id), XS_GET_ONLY);
2921 mxPop();
2922 }
2923 }

Callers

nothing calls this directly

Calls 15

fxNewProgramInstanceFunction · 0.85
fxNewObjectInstanceFunction · 0.85
fxNewGlobalInstanceFunction · 0.85
fxLastPropertyFunction · 0.85
fxNextSlotPropertyFunction · 0.85
fxBuildHostFunctionFunction · 0.85
fxDuplicateInstanceFunction · 0.85
fxIDFunction · 0.85
fxNewInstanceFunction · 0.85
fxNewEnvironmentInstanceFunction · 0.85

Tested by

no test coverage detected