neurojs icon indicating copy to clipboard operation
neurojs copied to clipboard

Bugs in negated `instanceof` expressions

Open gorosgobe opened this issue 2 years ago • 0 comments

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/janhuenermann/neurojs/blob/9a19adc2c3d56a4276affa06fb61524dca5bbbd9/src/storage.js#L36

gorosgobe avatar Sep 20 '23 13:09 gorosgobe