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

Function fx_GeneratorFunction

xs/sources/xsGenerator.c:1397–1432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1395}
1396
1397void fx_GeneratorFunction(txMachine* the)
1398{
1399 txInteger c, i;
1400 txStringStream stream;
1401 txSlot* module = mxFunctionInstanceHome(mxFunction->value.reference)->value.home.module;
1402 if (!module) module = mxProgram.value.reference;
1403
1404 c = mxArgc;
1405 i = 0;
1406 mxPushStringX("(function* anonymous(");
1407 while (c > 1) {
1408 fxToString(the, mxArgv(i));
1409 fxConcatString(the, the->stack, mxArgv(i));
1410 if (c > 2)
1411 fxConcatStringC(the, the->stack, ", ");
1412 c--;
1413 i++;
1414 }
1415 fxConcatStringC(the, the->stack, "\n){");
1416 if (c > 0) {
1417 fxToString(the, mxArgv(i));
1418 fxConcatString(the, the->stack, mxArgv(i));
1419 }
1420 fxConcatStringC(the, the->stack, "\n})");
1421 stream.slot = the->stack;
1422 stream.offset = 0;
1423 stream.size = mxStringLength(the->stack->value.string);
1424 fxRunScript(the, fxParseScript(the, &stream, fxStringGetter, mxProgramFlag | mxGeneratorFlag), C_NULL, C_NULL, C_NULL, C_NULL, module);
1425 mxPullSlot(mxResult);
1426 if (mxHasTarget && !fxIsSameSlot(the, mxTarget, mxFunction)) {
1427 mxPushSlot(mxTarget);
1428 fxGetPrototypeFromConstructor(the, &mxGeneratorFunctionPrototype);
1429 mxResult->value.reference->value.instance.prototype = the->stack->value.reference;
1430 mxPop();
1431 }
1432}
1433
1434void fx_Enumerator(txMachine* the)
1435{

Callers

nothing calls this directly

Calls 7

fxToStringFunction · 0.85
fxConcatStringFunction · 0.85
fxConcatStringCFunction · 0.85
fxRunScriptFunction · 0.85
fxIsSameSlotFunction · 0.85
fxParseScriptFunction · 0.70

Tested by

no test coverage detected