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

Function fxSetArrayBufferLength

xs/sources/xsDataView.c:152–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152void fxSetArrayBufferLength(txMachine* the, txSlot* slot, txInteger target)
153{
154 txSlot* instance = fxCheckArrayBufferInstance(the, slot);
155 txSlot* arrayBuffer = instance->next;
156 txSlot* bufferInfo = arrayBuffer->next;
157 txInteger length = bufferInfo->value.bufferInfo.length;
158 txByte* address = arrayBuffer->value.arrayBuffer.address;
159 if (bufferInfo->value.bufferInfo.maxLength < 0)
160 fxReport(the, "# Use xsArrayBufferResizable instead of xsArrayBuffer\n");
161 if (length != target) {
162 if (address)
163 address = (txByte*)fxRenewChunk(the, address, target);
164 if (address) {
165 if (length < target)
166 c_memset(address + length, 0, target - length);
167 }
168 else {
169 address = (txByte*)fxNewChunk(the, target);
170 if (length < target) {
171 c_memcpy(address, arrayBuffer->value.arrayBuffer.address, length);
172 c_memset(address + length, 0, target - length);
173 }
174 else
175 c_memcpy(address, arrayBuffer->value.arrayBuffer.address, target);
176 }
177 arrayBuffer->value.arrayBuffer.address = address;
178 bufferInfo->value.bufferInfo.length = target;
179 }
180}
181
182void* fxToArrayBuffer(txMachine* the, txSlot* slot)
183{

Callers 2

fxInsertDecompositionFunction · 0.85
fx_Uint8Array_fromBase64Function · 0.85

Calls 3

fxRenewChunkFunction · 0.85
fxNewChunkFunction · 0.85

Tested by

no test coverage detected