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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(data): avoid crashing with BigInt values #19847

Merged
merged 1 commit into from Apr 29, 2024
Merged

Conversation

zettca
Copy link
Contributor

@zettca zettca commented Apr 18, 2024

Brief Information

This pull request is in the type of:

  • bug fixing

What does this PR do?

  • Replaces global isFinite with Number.isFinite and unary (+) with Number() conversion so that a simple chart doesn't blow up when passing in a BigInt

Fixed Related issues

Details

Before: What was the problem?

When passing a BigInt data column to a chart, the chart blows up.

image

Uncaught TypeError: Cannot convert a BigInt value to a number
    at isFinite (<anonymous>)
    at detectValue (chunk-TNIQ5HHQ.js?v=9ea597be:5513:25)
    at doGuessOrdinal (chunk-TNIQ5HHQ.js?v=9ea597be:5494:21)
    at guessOrdinal (chunk-TNIQ5HHQ.js?v=9ea597be:5434:10)
    at new SourceImpl2 (chunk-TNIQ5HHQ.js?v=9ea597be:5538:17)
    at createSource (chunk-TNIQ5HHQ.js?v=9ea597be:5555:16)

馃憞

This is happens because of the way isFinite, isNaN, and + (unary operator) coerces the values. isFinite and isNaN implicitly converts the values in a way that's incompatible with BigInt.

The Number.isFinite() and Number.isNaN() methods work in a more predictable way by not casting non-numeric values implicitly - We can do that explicitly using Number() which can be more more performant) and does work with BigInt

The unary + operator conversion will likely never be supported for BigInt for compatibility reasons with ASM, while Number() does (with possible loss of precision)

After: How does it behave after the fixing?

Chart is rendered without crashing 馃殌

Document Info

One of the following should be checked.

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Misc

ZRender Changes

  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

N.A.

Others

Merging options

  • Please squash the commits into a single one when merging.

Other information

Please let me know if you'd like me to address some of the conversion issues in other places of the codebase too. That would require quite a few changes though; I've kept this PR small to increase its chances of being merged 馃憖

Thank you 馃檹

Copy link

echarts-bot bot commented Apr 18, 2024

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

Copy link
Contributor

The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-19847@e23a407

@zettca
Copy link
Contributor Author

zettca commented Apr 22, 2024

The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-19847@e23a407

-data: [150, 230, 224, 218, 135, 147, 260],
+data: [150, 230, 224, 218, 135, 147, 260].map(BigInt),

Copy link
Contributor

@Ovilia Ovilia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your valuable contribution!

@Ovilia Ovilia merged commit bdc5d4f into apache:master Apr 29, 2024
2 checks passed
Copy link

echarts-bot bot commented Apr 29, 2024

Congratulations! Your PR has been merged. Thanks for your contribution! 馃憤

@plainheart plainheart added this to the 5.5.1 milestone May 6, 2024
@plainheart plainheart changed the title fix: detectValue & parseDataValue not crashing with BigInt fix(data): avoid crashing with BigInt values May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants