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

Function fx_Array

xs/sources/xsArray.c:1115–1173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1113}
1114
1115void fx_Array(txMachine* the)
1116{
1117 txSlot* instance;
1118 txSlot* array;
1119 txSlot* argument;
1120 txIndex count = (txIndex)mxArgc;
1121 txBoolean flag = 0;
1122 txIndex index = 0;
1123 txSlot* slot;
1124
1125 if (!mxHasTarget)
1126 mxPushSlot(mxFunction);
1127 else
1128 mxPushSlot(mxTarget);
1129 fxGetPrototypeFromConstructor(the, &mxArrayPrototype);
1130 instance = fxNewArrayInstance(the);
1131 mxPullSlot(mxResult);
1132 array = instance->next;
1133
1134 if (count == 1) {
1135 argument = mxArgv(0);
1136 if ((argument->kind == XS_INTEGER_KIND) || (argument->kind == XS_NUMBER_KIND)) {
1137 count = fxCheckArrayLength(the, mxArgv(0));
1138 flag = 1;
1139 }
1140 }
1141 if (array) {
1142 if (flag)
1143 fxSetArrayLength(the, array, count);
1144 else {
1145 fxSetIndexSize(the, array, count, XS_CHUNK);
1146 slot = array->value.array.address;
1147 while (index < count) {
1148 argument = mxArgv(index);
1149 *((txIndex*)slot) = index;
1150 slot->ID = XS_NO_ID;
1151 slot->kind = argument->kind;
1152 slot->value = argument->value;
1153 slot++;
1154 index++;
1155 }
1156 }
1157 }
1158 else {
1159 mxPushNumber(count);
1160 mxPushSlot(mxThis);
1161 mxSetID(mxID(_length));
1162 mxPop();
1163 if (!flag) {
1164 while (index < count) {
1165 mxPushSlot(mxArgv(index));
1166 mxPushSlot(mxThis);
1167 mxDefineIndex(index, 0, XS_GET_ONLY);
1168 mxPop();
1169 index++;
1170 }
1171 }
1172 }

Callers

nothing calls this directly

Calls 5

fxNewArrayInstanceFunction · 0.85
fxCheckArrayLengthFunction · 0.85
fxSetArrayLengthFunction · 0.85
fxSetIndexSizeFunction · 0.85

Tested by

no test coverage detected