Bug 261815 - [JSC] Stress tests have bogus asserts due to incorrectly negating `instanceof` operator
Summary: [JSC] Stress tests have bogus asserts due to incorrectly negating `instanceof...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Alexey Shvayka
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-09-20 04:33 PDT by pablo.gobe
Modified: 2024-02-28 00:36 PST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description pablo.gobe 2023-09-20 04:33:52 PDT
`in` and `instanceof` expressions in JS
```js
a in obj;
a instanceof C;
```
can be negated by grouping them and applying the `!` operator, i.e.

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

Applying the `!` operator incorrectly (on the LHS operand) leads to bugs:
```js
!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 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#not_an_instanceof and the no-unsafe-negation recommended Eslint rule, https://eslint.org/docs/latest/rules/no-unsafe-negation.

I have found several potentially problematic instances of the above bugs in your codebase:

`in` bugs:
https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/WebKit/WebKit%24+lang:javascript+/%5C%21%5B%5B:alnum:%5D%5C%27%5C%22%5D%2B+in+%5B%5B:alnum:%5D%5D%2B/+-file:%5C.min%5C.js%24+count:all&patternType=standard&sm=1&groupBy=repo

`instanceof` bugs:
https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/WebKit/WebKit%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
Comment 1 Radar WebKit Bug Importer 2023-09-27 04:34:13 PDT
<rdar://problem/116114756>
Comment 2 Alexey Shvayka 2024-02-27 22:07:32 PST
Pull request: https://github.com/WebKit/WebKit/pull/25215
Comment 3 EWS 2024-02-28 00:36:01 PST
Committed 275433@main (d4af38db1147): <https://commits.webkit.org/275433@main>

Reviewed commits have been landed. Closing PR #25215 and removing active labels.