ekibun / flutter_qjs

A quickjs engine for flutter.
https://pub.dev/packages/flutter_qjs
MIT License
146 stars 28 forks source link

Evaluate returns double instead int #16

Open fiFoFy opened 3 years ago

fiFoFy commented 3 years ago

When the number greater then 2147483647 in Dart I get double value.

Example:

2147483647 (JS) -> 2147483647 (Dart)
2147483648 (JS) -> 2147483648.0 (Dart)
ekibun commented 3 years ago

In quickjs, integer larger than 2147483647 is stored in double please see https://262.ecma-international.org/5.1/#sec-8.5 and https://bellard.org/quickjs/quickjs.html#Numbers

fiFoFy commented 3 years ago

It may make sense to somehow change this behavior, because it is logical that the int in Javascript is compatible with int in Dart? It turns out that depending on the size of the number, we have to interpret the result differently.

For example: If the user is using the package built_value then this behavior creates problems _(I know how to solve it with builtvalue, but it is unexpected behavior).

ekibun commented 3 years ago

I do not know what behavior you want. Is there any problem that using num type in package built_value?

Currently type wrapper cannot tell whether the passed js float point value is integer or not.