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

Function fxGetArrayLimit

xs/sources/xsArray.c:584–624  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

582}
583
584txIndex fxGetArrayLimit(txMachine* the, txSlot* reference)
585{
586 txNumber length;
587 txSlot* instance = fxToInstance(the, reference);
588 txSlot* array = instance->next;
589 if (array && (array->kind == XS_ARRAY_KIND) && (array->ID == XS_ARRAY_BEHAVIOR)) {
590#if mxAliasInstance
591 if (instance->ID) {
592 txSlot* alias = the->aliasArray[instance->ID];
593 if (alias)
594 array = alias->next;
595 }
596#endif
597 return array->value.array.length;
598 }
599 if (array && (array->kind == XS_TYPED_ARRAY_KIND) && (array->ID == XS_TYPED_ARRAY_BEHAVIOR)) {
600 txSlot* view = array->next;
601 txSlot* buffer = view->next;
602 if (mxThis->value.reference != instance) { // iterator
603 if (fxIsDataViewOutOfBound(the, view, buffer))
604 mxTypeError("out of bound buffer");
605 }
606 return fxGetDataViewSize(the, view, buffer) >> array->value.typedArray.dispatch->shift;
607 }
608 mxPushReference(instance);
609 mxGetID(mxID(_length));
610 length = fxToLength(the, the->stack);
611 mxPop();
612 if (length > 0xFFFFFFFF) { // @@ practical limit for iterations
613 txSlot* result = instance->next;
614 length = 0;
615 while (result && (result->flag & XS_INTERNAL_FLAG)) {
616 if (result->kind == XS_ARRAY_KIND) {
617 length = result->value.array.length;
618 break;
619 }
620 result = result->next;
621 }
622 }
623 return (txIndex)length;
624}
625
626void fxIndexArray(txMachine* the, txSlot* array)
627{

Calls 4

fxToInstanceFunction · 0.85
fxIsDataViewOutOfBoundFunction · 0.85
fxGetDataViewSizeFunction · 0.85
fxToLengthFunction · 0.85

Tested by

no test coverage detected