summaryrefslogtreecommitdiffstats
path: root/docs/code-quality/lint/linters/eslint-plugin-mozilla/use-chromeutils-generateqi.rst
blob: 3da22e139af66ede30c49536a6deadd93f343375 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use-chromeutils-generateqi
==========================

Reject use of ``XPCOMUtils.generateQI`` and JS-implemented QueryInterface
methods in favor of ``ChromeUtils``.

Examples of incorrect code for this rule:
-----------------------------------------

.. code-block:: js

    X.prototype.QueryInterface = XPCOMUtils.generateQI(["nsIMeh"]);
    X.prototype = { QueryInterface: XPCOMUtils.generateQI(["nsIMeh"]) };
    X.prototype = { QueryInterface: function QueryInterface(iid) {
      if (
        iid.equals(Ci.nsISupports) ||
        iid.equals(Ci.nsIMeh) ||
        iid.equals(nsIFlug) ||
        iid.equals(Ci.amIFoo)
      ) {
        return this;
      }
      throw Components.Exception("", Cr.NS_ERROR_NO_INTERFACE);
    } };


Examples of correct code for this rule:
---------------------------------------

.. code-block:: js

    X.prototype.QueryInterface = ChromeUtils.generateQI(["nsIMeh"]);
    X.prototype = { QueryInterface: ChromeUtils.generateQI(["nsIMeh"]) }