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

Function fxSetIndexSize

xs/sources/xsProperty.c:421–466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

419}
420
421void fxSetIndexSize(txMachine* the, txSlot* array, txIndex target, txBoolean growable)
422{
423 txSlot* address = array->value.array.address;
424 txSlot* chunk = C_NULL;
425 txIndex current = (address) ? (((txChunk*)(((txByte*)address) - sizeof(txChunk)))->size) / sizeof(txSlot) : 0;
426 txSize size;
427 if (current != target) {
428 if (array->flag & XS_DONT_SET_FLAG)
429 mxTypeError("set length: not writable");
430 size = fxMultiplyChunkSizes(the, target, sizeof(txSlot));
431 if (address) {
432 if (target) {
433 chunk = (txSlot*)fxRenewChunk(the, address, size);
434 if (!chunk) {
435 #ifndef mxNoArrayOverallocation
436 if (growable) {
437 txSize capacity = fxSizeToCapacity(the, size);
438 chunk = (txSlot*)fxNewGrowableChunk(the, size, capacity);
439 }
440 else
441 #endif
442 chunk = (txSlot*)fxNewChunk(the, size);
443 address = array->value.array.address;
444 if (current < target)
445 c_memcpy(chunk, address, current * sizeof(txSlot));
446 else
447 c_memcpy(chunk, address, size);
448 }
449 }
450 }
451 else {
452 #ifndef mxNoArrayOverallocation
453 if (growable) {
454 txSize capacity = fxSizeToCapacity(the, size);
455 chunk = (txSlot*)fxNewGrowableChunk(the, size, capacity);
456 }
457 else
458 #endif
459 chunk = (txSlot*)fxNewChunk(the, size);
460 }
461 if (current < target)
462 c_memset(chunk + current, 0, (target - current) * sizeof(txSlot));
463 array->value.array.length = target;
464 array->value.array.address = chunk;
465 }
466}
467
468txBoolean fxDefinePrivateProperty(txMachine* the, txSlot* instance, txSlot* check, txID id, txSlot* slot, txFlag mask)
469{

Callers 15

fxRunArgumentsFunction · 0.85
fxRunProxyFunction · 0.85
fxNewArrayFunction · 0.85
fxConstructArrayEntryFunction · 0.85
fx_ArrayFunction · 0.85
fx_Array_ofFunction · 0.85
fx_Array_prototype_fillFunction · 0.85
fx_Array_prototype_mapFunction · 0.85

Calls 4

fxRenewChunkFunction · 0.85
fxSizeToCapacityFunction · 0.85
fxNewGrowableChunkFunction · 0.85
fxNewChunkFunction · 0.85

Tested by

no test coverage detected