chrome-privilieged scripts: `instanceof` operator against DOM interfaces will soon be strictly rejected

30 views
Skip to first unread message

Kagami Rosylight

unread,
Aug 24, 2022, 3:15:26 PM8/24/22
to dev-pl...@mozilla.org
Hi people,

If you are currently writing/maintaining chrome-privileged scripts then this post is for you. If not you can ignore this.

The mozilla/use-Instance ESLint rule will soon be improved to strictly reject any use of `instanceof` call against DOM interface within chrome scripts. This is because we traditionally used [Symbol.hasInstance] to allow cross-context instanceof and we want to unship it to make it standard-compliant. Unfortunately it is nontrivial to pick and replace the faulty instanceof uses, so we decided to replace all the uses with the equivalent chrome-only isInstance() function.

Non-privileged scripts e.g. mochitest files and general websites will not be affected.

Rejected: foo instanceof Node
Preferred: Node.isInstance(foo)

You can opt-out if you strictly need the context-strict standard instanceof with the following comment:

// eslint-disable-next-line mozilla/use-isInstance
foo instanceof Node

* the 2021 intent-to-unship: https://groups.google.com/g/mozilla.dev.platform/c/PSEPdL0MbvM/m/9Y_fOnt5AAAJ
Reply all
Reply to author
Forward
0 new messages