Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Handle non-primitives in isNumber #12034

Merged
merged 1 commit into from
Feb 16, 2025

Conversation

joshkel
Copy link
Contributor

@joshkel joshkel commented Feb 15, 2025

While investigating chartjs/chartjs-plugin-zoom#928, I found that isNonPrimitive will throw TypeError on a Moment.js object after it's passed through Chart.js's options proxy, because the object has its Symbol.toPrimitive, toString, and valueOf all set to null.

(See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_coercion for background reading.)

Since isNumber appears to be a low-level function that can take any arbitrary input, it seems worth letting it handle this case.

While investigating chartjs/chartjs-plugin-zoom#928, I found that `isNonPrimitive` will throw TypeError on a Moment.js object after it's passed through Chart.js's options proxy, because the object has its `Symbol.toPrimitive`, `toString`, and `valueOf` all set to null.

(See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_coercion for background reading.)

Since isNumber appears to be a low-level function that can take any arbitrary input, it seems worth letting it handle this case.
@etimberg etimberg added this to the Version 4.4.8 milestone Feb 16, 2025
@etimberg etimberg merged commit 2f42529 into chartjs:master Feb 16, 2025
7 checks passed
@joshkel joshkel deleted the non-primitive-isNumber branch February 17, 2025 14:05
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