Skip to content

fix: correct ArrayQueue boundaries in takeWhile and takeFromEndWhile#301119

Open
Muszic wants to merge 1 commit intomicrosoft:mainfrom
Muszic:fix-arrayqueue-boundaries
Open

fix: correct ArrayQueue boundaries in takeWhile and takeFromEndWhile#301119
Muszic wants to merge 1 commit intomicrosoft:mainfrom
Muszic:fix-arrayqueue-boundaries

Conversation

@Muszic
Copy link

@Muszic Muszic commented Mar 12, 2026

This PR fixes two symmetrical boundary bugs in ArrayQueue where takeWhile and takeFromEndWhile would ignore the internal lastIdx and firstIdx pointers. If both methods were interleaved on the same queue instance, it would lead to out-of-bounds reading and queue state corruption.

Fixes:

  • takeWhile now correctly checks startIdx <= this.lastIdx (previously checked against this.items.length).
  • takeFromEndWhile now correctly checks endIdx >= this.firstIdx (previously checked >= 0).

Tests:
Added regression tests to arrays.test.ts to ensure that mixed calls to takeWhile and takeFromEndWhile safely respect the active boundaries of the queue. Also includes the updated monaco.d.ts generated by the watch task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants