| 647 | } |
| 648 | |
| 649 | void fxGroupBy(txMachine* the, txCallback aux) |
| 650 | { |
| 651 | txSlot *function, *iterable, *iterator, *next, *value, *slot; |
| 652 | txNumber k = 0; |
| 653 | if ((mxArgc < 1) || mxIsUndefined(mxArgv(0)) || mxIsUndefined(mxArgv(1))) |
| 654 | mxTypeError("items: not an object"); |
| 655 | if ((mxArgc < 2) || (!fxIsCallable(the, mxArgv(1)))) |
| 656 | mxTypeError("callback: not a function"); |
| 657 | function = mxArgv(1); |
| 658 | iterable = mxArgv(0); |
| 659 | mxTemporary(iterator); |
| 660 | mxTemporary(next); |
| 661 | fxGetIterator(the, iterable, iterator, next, 0); |
| 662 | mxTemporary(value); |
| 663 | while (fxIteratorNext(the, iterator, next, value)) { |
| 664 | mxTry(the) { |
| 665 | if (k > C_MAX_SAFE_INTEGER) |
| 666 | mxTypeError("unsafe integer"); |
| 667 | mxPushUndefined(); |
| 668 | mxPushSlot(function); |
| 669 | mxCall(); |
| 670 | mxPushSlot(value); |
| 671 | mxPushNumber(k); |
| 672 | mxRunCount(2); |
| 673 | aux(the); |
| 674 | slot = the->stack->value.reference->next; |
| 675 | slot->value.array.length++; |
| 676 | while (slot->next) |
| 677 | slot = slot->next; |
| 678 | slot->next = fxDuplicateSlot(the, value); |
| 679 | mxPop(); |
| 680 | mxPop(); |
| 681 | k++; |
| 682 | } |
| 683 | mxCatch(the) { |
| 684 | fxIteratorReturn(the, iterator, 1); |
| 685 | fxJump(the); |
| 686 | } |
| 687 | } |
| 688 | mxPop(); |
| 689 | mxPop(); |
| 690 | mxPop(); |
| 691 | } |
| 692 | |
| 693 | |
| 694 |
no test coverage detected