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

Function fxCombinePromises

xs/sources/xsPromise.c:278–401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276}
277
278void fxCombinePromises(txMachine* the, txInteger which)
279{
280 txSlot* stack = the->stack;
281 txSlot* resolveFunction;
282 txSlot* rejectFunction;
283 txSlot* promise;
284 txSlot* object;
285 txSlot* property;
286 txSlot* array;
287 txSlot* already;
288 txSlot* iterator;
289 txSlot* next;
290 txSlot* value;
291 txInteger index;
292
293 if (!mxIsReference(mxThis))
294 mxTypeError("this: not an object");
295 mxTemporary(resolveFunction);
296 mxTemporary(rejectFunction);
297 mxPushSlot(mxThis);
298 promise = fxNewPromiseCapability(the, resolveFunction, rejectFunction);
299 mxPullSlot(mxResult);
300 {
301 mxTry(the) {
302 txSlot* resolve = C_NULL;
303 if (which) {
304 object = fxNewInstance(the);
305 property = fxNextIntegerProperty(the, object, 0, XS_NO_ID, XS_NO_FLAG);
306 property = fxNextReferenceProperty(the, property, promise, XS_NO_ID, XS_NO_FLAG);
307 if (which == XS_PROMISE_COMBINE_REJECTED)
308 property = fxNextSlotProperty(the, property, rejectFunction, XS_NO_ID, XS_NO_FLAG);
309 else
310 property = fxNextSlotProperty(the, property, resolveFunction, XS_NO_ID, XS_NO_FLAG);
311 mxPush(mxArrayPrototype);
312 array = fxNewArrayInstance(the);
313 already = array->next;
314 property = fxNextReferenceProperty(the, property, array, XS_NO_ID, XS_NO_FLAG);
315 mxPop();
316 }
317 mxPushSlot(mxThis);
318 mxGetID(mxID(_resolve));
319 resolve = the->stack;
320 if (!fxIsCallable(the, resolve))
321 mxTypeError("resolve: not a function");
322 mxTemporary(iterator);
323 mxTemporary(next);
324 fxGetIterator(the, mxArgv(0), iterator, next, 0);
325 index = 0;
326 mxTemporary(value);
327 while (fxIteratorNext(the, iterator, next, value)) {
328 mxTry(the) {
329 mxPushSlot(mxThis);
330 mxPushSlot(resolve);
331 mxCall();
332 mxPushSlot(value);
333 mxRunCount(1);
334 mxDub();
335 mxGetID(mxID(_then));

Callers 4

fx_Promise_allFunction · 0.85
fx_Promise_allSettledFunction · 0.85
fx_Promise_anyFunction · 0.85
fx_Promise_raceFunction · 0.85

Calls 15

fxNewPromiseCapabilityFunction · 0.85
fxNewInstanceFunction · 0.85
fxNextIntegerPropertyFunction · 0.85
fxNextReferencePropertyFunction · 0.85
fxNextSlotPropertyFunction · 0.85
fxNewArrayInstanceFunction · 0.85
fxIsCallableFunction · 0.85
fxGetIteratorFunction · 0.85
fxIteratorNextFunction · 0.85
fxNewSlotFunction · 0.85
fxIteratorReturnFunction · 0.85

Tested by

no test coverage detected