@@ -299,6 +299,8 @@ txSlot* fxCheckArray(txMachine* the, txSlot* slot, txBoolean mutable)
299299txSlot * fxCheckArrayItems (txMachine * the , txSlot * array , txIndex from , txIndex to )
300300{
301301 txSlot * address = array -> value .array .address ;
302+ if (!address )
303+ return C_NULL ;
302304 address += from ;
303305 while (from < to ) {
304306 if (address -> flag )
@@ -438,7 +440,6 @@ txSlot* fxCreateArraySpecies(txMachine* the, txNumber length)
438440{
439441 txSlot * instance = fxToInstance (the , mxThis );
440442 txFlag flag = 1 ;
441- txSlot * array = C_NULL ;
442443 if (fxIsArray (the , instance )) {
443444 mxPushSlot (mxThis );
444445 mxGetID (mxID (_constructor ));
@@ -464,11 +465,7 @@ txSlot* fxCreateArraySpecies(txMachine* the, txNumber length)
464465 mxPushNumber (length );
465466 mxRunCount (1 );
466467 mxPullSlot (mxResult );
467- if (flag ) {
468- array = mxResult -> value .reference -> next ;
469- fxSetIndexSize (the , array , (txIndex )length , XS_CHUNK );
470- }
471- return array ;
468+ return (flag ) ? mxResult -> value .reference -> next : C_NULL ;
472469}
473470
474471void fxFindThisItem (txMachine * the , txSlot * function , txIndex index , txSlot * item )
@@ -1752,6 +1749,7 @@ void fx_Array_prototype_map(txMachine* the)
17521749 txIndex index = 0 ;
17531750 if (resultArray ) {
17541751 txIndex resultLength = 0 ;
1752+ fxSetIndexSize (the , resultArray , length , XS_CHUNK );
17551753 while (index < length ) {
17561754 if (fxCallThisItem (the , function , index , C_NULL )) {
17571755 txSlot * slot = resultArray -> value .array .address + resultLength ;
@@ -2066,12 +2064,13 @@ void fx_Array_prototype_slice(txMachine* the)
20662064 txNumber COUNT = (END > START ) ? END - START : 0 ;
20672065 txSlot * array = fxCheckArray (the , mxThis , XS_IMMUTABLE );
20682066 txSlot * resultArray = fxCreateArraySpecies (the , COUNT );
2069- if (array && resultArray )
2067+ if (array )
20702068 array = fxCheckArrayItems (the , array , (txIndex )START , (txIndex )(START + COUNT ));
20712069 if (array && resultArray ) {
20722070 txIndex start = (txIndex )START ;
20732071 txIndex count = (txIndex )COUNT ;
20742072 if (count ) {
2073+ fxSetIndexSize (the , resultArray , count , XS_CHUNK );
20752074 c_memcpy (resultArray -> value .array .address , array -> value .array .address + start , count * sizeof (txSlot ));
20762075 fxIndexArray (the , resultArray );
20772076 mxMeterSome (count * 10 );
@@ -2341,6 +2340,7 @@ void fx_Array_prototype_splice(txMachine* the)
23412340 txIndex index ;
23422341 if (LENGTH + INSERTIONS - DELETIONS > 0xFFFFFFFF )
23432342 mxTypeError ("array overflow" );
2343+ fxSetIndexSize (the , resultArray , deletions , XS_CHUNK );
23442344 c_memcpy (resultArray -> value .array .address , array -> value .array .address + start , deletions * sizeof (txSlot ));
23452345 fxIndexArray (the , resultArray );
23462346 mxMeterSome (deletions * 10 );
0 commit comments