use-chromeutils-generateqi.rst (980B)
1 use-chromeutils-generateqi 2 ========================== 3 4 Reject use of ``XPCOMUtils.generateQI`` and JS-implemented QueryInterface 5 methods in favor of ``ChromeUtils``. 6 7 Examples of incorrect code for this rule: 8 ----------------------------------------- 9 10 .. code-block:: js 11 12 X.prototype.QueryInterface = XPCOMUtils.generateQI(["nsIMeh"]); 13 X.prototype = { QueryInterface: XPCOMUtils.generateQI(["nsIMeh"]) }; 14 X.prototype = { QueryInterface: function QueryInterface(iid) { 15 if ( 16 iid.equals(Ci.nsISupports) || 17 iid.equals(Ci.nsIMeh) || 18 iid.equals(nsIFlug) || 19 iid.equals(Ci.amIFoo) 20 ) { 21 return this; 22 } 23 throw Components.Exception("", Cr.NS_ERROR_NO_INTERFACE); 24 } }; 25 26 27 Examples of correct code for this rule: 28 --------------------------------------- 29 30 .. code-block:: js 31 32 X.prototype.QueryInterface = ChromeUtils.generateQI(["nsIMeh"]); 33 X.prototype = { QueryInterface: ChromeUtils.generateQI(["nsIMeh"]) }