| 1253 | } |
| 1254 | |
| 1255 | void fx_Array_fromAsync(txMachine* the) |
| 1256 | { |
| 1257 | txSlot* stack = the->stack; |
| 1258 | txSlot* iterator; |
| 1259 | txSlot* resolveFunction; |
| 1260 | txSlot* rejectFunction; |
| 1261 | txSlot* promise; |
| 1262 | txSlot* instance; |
| 1263 | txSlot* property; |
| 1264 | txSlot* home; |
| 1265 | |
| 1266 | mxTemporary(iterator); |
| 1267 | mxTemporary(resolveFunction); |
| 1268 | mxTemporary(rejectFunction); |
| 1269 | mxTemporary(promise); |
| 1270 | mxPush(mxPromiseConstructor); |
| 1271 | fxNewPromiseCapability(the, resolveFunction, rejectFunction); |
| 1272 | mxPullSlot(promise); |
| 1273 | { |
| 1274 | mxTry(the) { |
| 1275 | txSlot* function = (mxArgc > 1) && !mxIsUndefined(mxArgv(1)) ? fxArgToCallback(the, 1) : C_NULL; |
| 1276 | txNumber length = 0; |
| 1277 | |
| 1278 | if (mxArgc == 0) |
| 1279 | mxTypeError("no items"); |
| 1280 | |
| 1281 | mxPushSlot(mxArgv(0)); |
| 1282 | mxDub(); |
| 1283 | mxGetID(mxID(_Symbol_asyncIterator)); |
| 1284 | if (mxIsUndefined(the->stack) || mxIsNull(the->stack)) { |
| 1285 | mxPop(); |
| 1286 | mxDub(); |
| 1287 | mxGetID(mxID(_Symbol_iterator)); |
| 1288 | if (mxIsUndefined(the->stack) || mxIsNull(the->stack)) { |
| 1289 | mxPop(); |
| 1290 | mxDub(); |
| 1291 | mxGetID(mxID(_length)); |
| 1292 | length = fxToLength(the, the->stack); |
| 1293 | mxPop(); |
| 1294 | if (length > 0x7FFFFFFF) |
| 1295 | mxRangeError("array overflow"); |
| 1296 | mxPush(mxIteratorPrototype); |
| 1297 | property = fxLastProperty(the, fxNewIteratorInstance(the, mxArgv(0), mxID(_Array))); |
| 1298 | property = fxNextIntegerProperty(the, property, (txInteger)length, XS_NO_ID, XS_INTERNAL_FLAG); |
| 1299 | property = fxNextHostFunctionProperty(the, property, mxCallback(fx_Array_fromAsync_items_next), 0, mxID(_next), XS_DONT_ENUM_FLAG); |
| 1300 | fxNewAsyncFromSyncIteratorInstance(the); |
| 1301 | mxPullSlot(iterator); |
| 1302 | fxCreateArray(the, 1, (txIndex)length); |
| 1303 | } |
| 1304 | else { |
| 1305 | mxCall(); |
| 1306 | mxRunCount(0); |
| 1307 | fxNewAsyncFromSyncIteratorInstance(the); |
| 1308 | mxPullSlot(iterator); |
| 1309 | fxCreateArray(the, 0, 0); |
| 1310 | } |
| 1311 | } |
| 1312 | else { |
nothing calls this directly
no test coverage detected