espruino / Espruino

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

Lack of Error Thrown when Using 'in' Operator on Non-Objects #2427

Open marccarigiet opened 11 months ago

marccarigiet commented 11 months ago

Description 'in' applied to non-objects do not throw an error.

Test case Test code to reproduce the behaviour:

'example' in true;
'example' in false;
'example' in undefined;
'example' in null;
'example' in this;

'example' in 'example';
'example' in 1;

Expected behaviour Going by other JavaScript engines including V8, SpiderMonkey and JavaScriptCore I'd expect a TypeError to be thrown.

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 11 months ago

Thanks! I'll look into it