feat: add list clear and insert primitives with capacity growth and index validation
Extract inline list growth logic into `ensureListCapacity` helper and add `validateIndex` function supporting negative indices. Implement `list_clear` primitive that resets count to zero without freeing memory, and `list_insert` primitive that shifts elements right and inserts at validated position. Add comprehensive test suites for both operations covering empty lists, normal/negative indices, and return values.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
var a = [1, 2, 3]
|
||||
a.clear
|
||||
io.write(a) // expect: []
|
||||
io.write(a.count) // expect: 0
|
||||
|
||||
// Returns null.
|
||||
io.write([1, 2].clear) // expect: null
|
||||
Reference in New Issue
Block a user