drawcall / Proton

Javascript particle animation library
https://drawcall.github.io/Proton/
MIT License
2.42k stars 275 forks source link

Bugs in negated `in` expressions #101

Open gorosgobe opened 1 year ago

gorosgobe commented 1 year ago

in and instanceof expressions in JS

a in obj;
a instanceof C;

can be negated by grouping them and applying the ! operator, i.e.

!(a in obj);
!(a instanceof C);

Applying the ! operator incorrectly (on the LHS operand) leads to bugs:

!a in obj; // will evaluate to false, unless obj has a "true" or "false" key
!a instanceof C; // will evaluate to false, unless C overrides instanceof with a @@hasInstance method

For more information, please see these MDN docs and the no-unsafe-negation recommended Eslint rule.

I have found a potentially problematic instance of the above bugs in your codebase: https://github.com/drawcall/Proton/blob/83c3caa8203c4e60c7363fb3fffbfd69c9d7ba0e/example/game/crafty/js/crafty.js#L4306

igurisandhu commented 1 month ago

Hi @drawcall ,

Thank you for merging my pull request! 🙏 I really appreciate your prompt review and support.

Thanks again! 😊