tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

use-isInstance.rst (1215B)


      1 use-isInstance
      2 ==============
      3 
      4 Prefer ``.isInstance()`` in chrome scripts over the standard ``instanceof``
      5 operator for DOM interfaces, since the latter will return false when the object
      6 is created from a different context.
      7 
      8 These files are covered:
      9 
     10 - ``*.sys.mjs``
     11 - ``*.xhtml`` with ``there.is.only.xul``
     12 - ``*.js`` with a heuristic
     13 
     14 Since there is no straightforward way to detect chrome scripts, currently the
     15 linter assumes that any script including the following words are chrome
     16 privileged. This of course may not be sufficient and is open for change:
     17 
     18 - ``ChromeUtils``, but not ``SpecialPowers.ChromeUtils``
     19 - ``BrowserTestUtils``, ``PlacesUtils``
     20 - ``document.createXULElement``
     21 - ``loader.lazyRequireGetter``
     22 - ``Services.foo``, but not ``SpecialPowers.Services.foo``
     23 
     24 Examples of incorrect code for this rule:
     25 -----------------------------------------
     26 
     27 .. code-block:: js
     28 
     29    node instanceof Node
     30    text instanceof win.Text
     31    target instanceof this.contentWindow.HTMLAudioElement
     32 
     33 Examples of correct code for this rule:
     34 ---------------------------------------
     35 
     36 .. code-block:: js
     37 
     38    Node.isInstance(node)
     39    win.Text.isInstance(text)
     40    this.contentWindow.HTMLAudioElement.isInstance(target)