espruino / Espruino

The Espruino JavaScript interpreter - Official Repo
http://www.espruino.com/
Other
2.76k stars 741 forks source link

Modulus with infinity returns unexpected value #2542

Open theauk opened 3 weeks ago

theauk commented 3 weeks ago

https://github.com/espruino/Espruino/commit/ff487e008472deff8113a32ebd3217dbd606405c

Test case The original test case I ran:

>var a = [1]; var b = [1]; console.log((b[0] % (a.push(1) / (a[0] ^ b.length))));
=0

It can be simplified to:

>1 % (1 / 0)
=0

or

>1%Infinity
=0

Expected behavior I would expect it to return 1 (from 1 % Infinity). Running the test case on other JavaScript engines (Node, Hermes, and QuickJS), I get the expected 1.

gfwilliams commented 2 weeks ago

Thanks for these reports! I'll take a look at them when I get a bit of free time.

In the mean time if you or anyone else wants to contribute fixes that'd be awesome!