Bug 1458215 - Handle the optional service name in XPCOMUtils.defineLazyServiceGetters. r?kmag draft
authorMark Banner <standard8@mozilla.com>
Tue, 01 May 2018 13:51:53 +0100
changeset 790159 fc06b3d6def72d57ce408641e104febdc8fa75f9
parent 790006 7ef8450810693ab08e79ab0d4702de6f479e678c
push id108434
push userbmo:standard8@mozilla.com
push dateTue, 01 May 2018 14:58:37 +0000
reviewerskmag
bugs1458215
milestone61.0a1
Bug 1458215 - Handle the optional service name in XPCOMUtils.defineLazyServiceGetters. r?kmag MozReview-Commit-ID: 1Dp6lhQRbNU
js/xpconnect/loader/XPCOMUtils.jsm
--- a/js/xpconnect/loader/XPCOMUtils.jsm
+++ b/js/xpconnect/loader/XPCOMUtils.jsm
@@ -258,28 +258,28 @@ var XPCOMUtils = {
    * Defines a lazy service getter on a specified object for each
    * property in the given object.
    *
    * @param aObject
    *        The object to define the lazy getter on.
    * @param aServices
    *        An object with a property for each service to be
    *        imported, where the property name is the name of the
-   *        symbol to define, and the value is a 2-element array
-   *        containing the contract ID and the interface name of the
-   *        service, as passed to defineLazyServiceGetter.
+   *        symbol to define, and the value is a 1 or 2 element array
+   *        containing the contract ID and, optionally, the interface
+   *        name of the service, as passed to defineLazyServiceGetter.
    */
   defineLazyServiceGetters: function XPCU_defineLazyServiceGetters(
                                    aObject, aServices)
   {
     for (let [name, service] of Object.entries(aServices)) {
       // Note: This is hot code, and cross-compartment array wrappers
       // are not JIT-friendly to destructuring or spread operators, so
       // we need to use indexed access instead.
-      this.defineLazyServiceGetter(aObject, name, service[0], service[1]);
+      this.defineLazyServiceGetter(aObject, name, service[0], service[1] || null);
     }
   },
 
   /**
    * Defines a getter on a specified object for a module.  The module will not
    * be imported until first use. The getter allows to execute setup and
    * teardown code (e.g.  to register/unregister to services) and accepts
    * a proxy object which acts on behalf of the module until it is imported.