Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs in negated instanceof expressions #6950

Closed
gorosgobe opened this issue Sep 20, 2023 · 1 comment · Fixed by #6989
Closed

Bugs in negated instanceof expressions #6950

gorosgobe opened this issue Sep 20, 2023 · 1 comment · Fixed by #6989
Labels

Comments

@gorosgobe
Copy link

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 several potentially problematic instances of the above bugs in your codebase:
https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/chakra-core/ChakraCore%24+lang:javascript+/%5C%21%5B%5B:alnum:%5D%5D%2B+instanceof+%5B%5B:alnum:%5D%5D%2B/+-file:%5C.min%5C.js%24+count:all&patternType=standard&sm=1&groupBy=repo

@rhuanjl
Copy link
Collaborator

rhuanjl commented Apr 22, 2024

The Sourcegraph link shows errors in 3 of our test files where they will be failing to test what's intended:
test/Array/array_splice.js
test/es5/RegExpStrictDelete.js
test/Array/array_splice_double.js

We should fix these

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants