Bug 1381853 - add defineLazyScriptGetter on XPCOMUtils.jsm, r=mconley.
authorFlorian Quèze <florian@queze.net>
Sun, 23 Jul 2017 00:17:54 +0200
changeset 419136 86169e904b4d3e5cc86c9802b73475ee702f902c
parent 419135 e323bc846da065850b8b755fcced8c6da9b3669e
child 419137 c31eeb2adfc4864219451e32b658b7083866d0cf
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1381853
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1381853 - add defineLazyScriptGetter on XPCOMUtils.jsm, r=mconley.
js/xpconnect/loader/XPCOMUtils.jsm
tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
--- a/js/xpconnect/loader/XPCOMUtils.jsm
+++ b/js/xpconnect/loader/XPCOMUtils.jsm
@@ -206,16 +206,41 @@ this.XPCOMUtils = {
         return value;
       },
       configurable: true,
       enumerable: true
     });
   },
 
   /**
+   * Defines a getter on a specified object for a script.  The script will not
+   * be loaded until first use.
+   *
+   * @param aObject
+   *        The object to define the lazy getter on.
+   * @param aName
+   *        The name of the getter to define on aObject for the script.
+   * @param aResource
+   *        The URL used to obtain the script.
+   */
+  defineLazyScriptGetter: function XPCU_defineLazyScriptGetter(aObject, aName,
+                                                               aResource)
+  {
+    Object.defineProperty(aObject, aName, {
+      get: function () {
+        delete aObject[aName];
+        Services.scriptloader.loadSubScript(aResource, aObject);
+        return aObject[aName];
+      },
+      configurable: true,
+      enumerable: true
+    });
+  },
+
+  /**
    * Defines a getter on a specified object for a service.  The service will not
    * be obtained until first use.
    *
    * @param aObject
    *        The object to define the lazy getter on.
    * @param aName
    *        The name of the getter to define on aObject for the service.
    * @param aContract
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
@@ -19,16 +19,17 @@ var directoryManifests = new Map();
 const callExpressionDefinitions = [
   /^loader\.lazyGetter\(this, "(\w+)"/,
   /^loader\.lazyImporter\(this, "(\w+)"/,
   /^loader\.lazyServiceGetter\(this, "(\w+)"/,
   /^loader\.lazyRequireGetter\(this, "(\w+)"/,
   /^XPCOMUtils\.defineLazyGetter\(this, "(\w+)"/,
   /^XPCOMUtils\.defineLazyModuleGetter\(this, "(\w+)"/,
   /^XPCOMUtils\.defineLazyPreferenceGetter\(this, "(\w+)"/,
+  /^XPCOMUtils\.defineLazyScriptGetter\(this, "(\w+)"/,
   /^XPCOMUtils\.defineLazyServiceGetter\(this, "(\w+)"/,
   /^XPCOMUtils\.defineConstant\(this, "(\w+)"/,
   /^DevToolsUtils\.defineLazyModuleGetter\(this, "(\w+)"/,
   /^DevToolsUtils\.defineLazyGetter\(this, "(\w+)"/,
   /^Object\.defineProperty\(this, "(\w+)"/,
   /^Reflect\.defineProperty\(this, "(\w+)"/,
   /^this\.__defineGetter__\("(\w+)"/
 ];