web runtimes should enforce int
types on bit operations
#45438
Labels
area-web-js
Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.
P3
A lower priority bug or feature request
web-dart2js
web-dev-compiler
The DDC and dart2js runtimes implement the bit operations like
&
and<<
on (JavaScript) Number rather than on Dartint
.They should be upgraded to enforce
int
receiver and argument types. The lack of enforcement is a hold-over from Dart 1, where the extra cost ofint
checks would be too expensive. The enforcement is now mostly static.The lack of enforcement does not affect statically typed code since the
int
interface enforces the receiver and argument types at compile time.Dynamic code fails to check both the receiver and argument for being
int
, allowing non-integer floating point numbers into the calculation (where they are truncated according to the JavaScriptToInt32
operation).The main benefit of better enforcement of the
int
types would be more uniform behaviour in testing, e.g. #45419.The main disadvantage is that there will be performance regressions on paths that do the extra checks, and these regressions would need to be fixed
DDC would need to go first, since the extra checks should not be a surprise in production.
The text was updated successfully, but these errors were encountered: