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

Function fx_DataView

xs/sources/xsDataView.c:930–984  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

928}
929
930void fx_DataView(txMachine* the)
931{
932 txSlot* slot;
933 txBoolean flag = 0;
934 txInteger offset, size;
935 txSlot* info;
936 txSlot* instance;
937 txSlot* view;
938 txSlot* buffer;
939 if (!mxHasTarget)
940 mxTypeError("call: DataView");
941 if ((mxArgc > 0) && (mxArgv(0)->kind == XS_REFERENCE_KIND)) {
942 slot = mxArgv(0)->value.reference->next;
943 if (slot && ((slot->kind == XS_ARRAY_BUFFER_KIND) || (slot->kind == XS_HOST_KIND))) {
944 flag = 1;
945 }
946 }
947 if (!flag)
948 mxTypeError("buffer: not an ArrayBuffer instance");
949
950 offset = fxArgToByteLength(the, 1, 0);
951 info = fxGetBufferInfo(the, mxArgv(0));
952 if (info->value.bufferInfo.length < offset)
953 mxRangeError("invalid byteOffset %ld", offset);
954 size = fxArgToByteLength(the, 2, -1);
955 if (size >= 0) {
956 txInteger end = offset + size;
957 if ((info->value.bufferInfo.length < end) || (end < offset))
958 mxRangeError("invalid byteLength %ld", size);
959 }
960 else {
961 if (info->value.bufferInfo.maxLength < 0)
962 size = info->value.bufferInfo.length - offset;
963 }
964 mxPushSlot(mxTarget);
965 fxGetPrototypeFromConstructor(the, &mxDataViewPrototype);
966 instance = fxNewDataViewInstance(the);
967 mxPullSlot(mxResult);
968 view = instance->next;
969 buffer = view->next;
970 buffer->kind = XS_REFERENCE_KIND;
971 buffer->value.reference = mxArgv(0)->value.reference;
972 info = fxGetBufferInfo(the, buffer);
973 if (info->value.bufferInfo.maxLength >= 0) {
974 if (info->value.bufferInfo.length < offset)
975 mxRangeError("invalid byteOffset %ld", offset);
976 else if (size >= 0) {
977 txInteger end = offset + size;
978 if ((info->value.bufferInfo.length < end) || (end < offset))
979 mxRangeError("invalid byteLength %ld", size);
980 }
981 }
982 view->value.dataView.offset = offset;
983 view->value.dataView.size = size;
984}
985
986void fx_DataView_prototype_buffer_get(txMachine* the)
987{

Callers

nothing calls this directly

Calls 4

fxArgToByteLengthFunction · 0.85
fxGetBufferInfoFunction · 0.85
fxNewDataViewInstanceFunction · 0.85

Tested by

no test coverage detected