espruino / Espruino

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

Division of certain Non-Numeral Operands Triggers Syntax Error on Linux #2424

Closed marccarigiet closed 8 months ago

marccarigiet commented 8 months ago

Description Certain divisions of non-numeral operands get interpreted as an unfinished Regex and trigger a Syntax Error.

Test case Test code to reproduce the behaviour:

true / false;

Backtrace

Uncaught SyntaxError: Got UNFINISHED REGEX expected EOF
 at line 1 col 6
true / false;

Expected behaviour I am not entirely sure what the expected behaviour should be. Going by other JavaScript Engines, NaN or Infinity would both be possible. But I definitely wouldn't have expected the present behavior.

Additional context This was found using comparative testing between multiple JavaScript engines. This could very much come down to a design choice. I just wanted to let you know in case it is not intentional

gfwilliams commented 8 months ago

Thanks - I've just put a fix in for this. JS Regex is nasty as it's not apparent to the poor lexer (without lookahead) exactly what makes a RegEx start and what makes a division.

Do you have any other examples of non-numerals beforehand that cause issues that work on other engines? I fixed true/false/undefined/null

I'd be particularly interested if there was everyday JS that had problems - I feel like dividing true by something is probably not something that would happen in non-buggy code :)

marccarigiet commented 8 months ago

Hi there,

The only other non-numerals that work on other engines and caused that issue were with this and uninitialized variables. Admittedly divisions involving theses are also not everyday JS 😅