Fix unsafe `instanceof` negations

RESOLVED FIXED in Firefox 53

Status

()

defect
RESOLVED FIXED
3 years ago
3 years ago

People

(Reporter: lina, Assigned: lina)

Tracking

unspecified
mozilla53
Points:
---

Firefox Tracking Flags

(firefox53 fixed)

Details

Attachments

(2 attachments)

Some of our modules use the pattern `!value instanceof Class`, to check if `value` is not an instance of `Class`.

This isn't quite right: `!` binds tighter than `instanceof`, so that will evaluate to `false instanceof Class`...which will always be false (https://github.com/DavidBruant/ECMAScript-regrets/issues/27).

We need an extra set of parens to make this work: `!(value instanceof Class)`.
Comment hidden (mozreview-request)
Comment hidden (mozreview-request)

Comment 4

3 years ago
mozreview-review
Comment on attachment 8817932 [details]
Bug 1322954 - Fix incorrect `instanceof` negations.

https://reviewboard.mozilla.org/r/98100/#review98410

wow - it's scary how often we weren't checking what we thought we were checking!
Attachment #8817932 - Flags: review?(markh) → review+

Comment 5

3 years ago
mozreview-review
Comment on attachment 8817933 [details]
Bug 1322954 - Replace deprecated `no-negated-in-lhs` ESLint option with `no-unsafe-negation`.

https://reviewboard.mozilla.org/r/98102/#review98412

This looks great, but will require another try.
Attachment #8817933 - Flags: review?(markh) → review+
Comment hidden (mozreview-request)
Comment hidden (mozreview-request)

Comment 8

3 years ago
Pushed by kcambridge@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/4d6f11e28343
Fix incorrect `instanceof` negations. r=markh
https://hg.mozilla.org/integration/autoland/rev/2c1d9731a014
Replace deprecated `no-negated-in-lhs` ESLint option with `no-unsafe-negation`. r=markh

Comment 9

3 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/4d6f11e28343
https://hg.mozilla.org/mozilla-central/rev/2c1d9731a014
Status: ASSIGNED → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla53
You need to log in before you can comment on or make changes to this bug.