Skip to content

fix: handle splice with single argument - #12194

Open
veeceey wants to merge 2 commits into
chartjs:masterfrom
veeceey:fix/issue-12191-splice-single-arg
Open

veeceey wants to merge 2 commits into
chartjs:masterfrom
veeceey:fix/issue-12191-splice-single-arg

Conversation

@veeceey

@veeceey veeceey commented Feb 14, 2026

Copy link
Copy Markdown

Fixes #12191

When Array.prototype.splice is called with only the start argument (e.g. .splice(0) to clear an array), the second argument (deleteCount) is omitted. In _onDataSplice, this caused arguments.length - 2 to evaluate to -1, which is truthy and led to _insertElements being called with a negative count, throwing:

RangeError: Invalid array length

The fix changes the condition from if (newCount) to if (newCount > 0) so that negative values from omitted arguments are properly ignored.

Added a test that verifies data.splice(0) works without throwing.

When Array.splice is called with only the start argument (e.g.
splice(0)), the deleteCount parameter is omitted. This caused
arguments.length - 2 to evaluate to -1, which was truthy and
led to _insertElements being called with a negative count,
throwing a RangeError: Invalid array length.

Fix by checking newCount > 0 instead of just truthy.

Fixes chartjs#12191
@veeceey

veeceey commented Mar 10, 2026

Copy link
Copy Markdown
Author

hey, just circling back — is this something that could get reviewed soon?

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.

Splice on data with a single argument throws an error.

3 participants