use-isInstance¶
在 chrome 脚本中,建议使用 .isInstance() 而不是标准的 instanceof 运算符来检查 DOM 接口,因为后者在对象从不同上下文创建时将返回 false。
以下文件受此规则约束
*.sys.mjs*.jsm*.xhtml且包含there.is.only.xul*.js且符合启发式规则
由于没有直接的方法来检测 chrome 脚本,目前代码风格检查工具假设包含以下关键词的任何脚本都具有 chrome 权限。当然,这可能不够充分,并且可以进行更改
ChromeUtils,但不包括SpecialPowers.ChromeUtilsBrowserTestUtils、PlacesUtilsdocument.createXULElementloader.lazyRequireGetterServices.foo,但不包括SpecialPowers.Services.foo
此规则不符合代码示例:¶
node instanceof Node
text instanceof win.Text
target instanceof this.contentWindow.HTMLAudioElement
此规则符合代码示例:¶
Node.isInstance(node)
win.Text.isInstance(text)
this.contentWindow.HTMLAudioElement.isInstance(target)