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

Function fx_Map

xs/sources/xsMapSet.c:275–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

273}
274
275void fx_Map(txMachine* the)
276{
277 txSlot *function, *iterable, *iterator, *next, *value;
278 if (!mxHasTarget)
279 mxTypeError("call: Map");
280 mxPushSlot(mxTarget);
281 fxGetPrototypeFromConstructor(the, &mxMapPrototype);
282 fxNewMapInstance(the);
283 mxPullSlot(mxResult);
284 if (mxArgc < 1)
285 return;
286 iterable = mxArgv(0);
287 if ((iterable->kind == XS_UNDEFINED_KIND) || (iterable->kind == XS_NULL_KIND))
288 return;
289 mxPushSlot(mxResult);
290 mxGetID(mxID(_set));
291 function = the->stack;
292 if (!fxIsCallable(the, function))
293 mxTypeError("result.set: not a function");
294 mxTemporary(iterator);
295 mxTemporary(next);
296 fxGetIterator(the, iterable, iterator, next, 0);
297 mxTemporary(value);
298 while (fxIteratorNext(the, iterator, next, value)) {
299 mxTry(the) {
300 if (value->kind != XS_REFERENCE_KIND)
301 mxTypeError("item: not an object");
302 mxPushSlot(mxResult);
303 mxPushSlot(function);
304 mxCall();
305 mxPushSlot(value);
306 mxGetIndex(0);
307 mxPushSlot(value);
308 mxGetIndex(1);
309 mxRunCount(2);
310 mxPop();
311 }
312 mxCatch(the) {
313 fxIteratorReturn(the, iterator, 1);
314 fxJump(the);
315 }
316 }
317}
318
319static void fx_Map_groupByAux(txMachine* the)
320{

Callers

nothing calls this directly

Calls 7

fxNewMapInstanceFunction · 0.85
fxIsCallableFunction · 0.85
fxGetIteratorFunction · 0.85
fxIteratorNextFunction · 0.85
fxIteratorReturnFunction · 0.85
fxJumpFunction · 0.85

Tested by

no test coverage detected