Bug 1091706 - Ensure spawning only one devtools loader instances. r=jryans
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 17 Nov 2014 12:47:35 -0800
changeset 240421 1cdf743b10cb2ca5438acbb04e5667a8555a8ca3
parent 240420 885334253d3a435994151a4c276a08b13da3455a
child 240422 cc48ff0ed5092319d1953dc15fc595c7ea0cbbbf
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1091706
milestone36.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 1091706 - Ensure spawning only one devtools loader instances. r=jryans
toolkit/devtools/Loader.jsm
toolkit/devtools/tests/unit/test_require.js
toolkit/devtools/tests/unit/xpcshell.ini
--- a/toolkit/devtools/Loader.jsm
+++ b/toolkit/devtools/Loader.jsm
@@ -264,17 +264,19 @@ DevToolsLoader.prototype = {
   _provider: null,
 
   /**
    * A dummy version of require, in case a provider hasn't been chosen yet when
    * this is first called.  This will then be replaced by the real version.
    * @see setProvider
    */
   require: function() {
-    this._chooseProvider();
+    if (!this._provider) {
+      this._chooseProvider();
+    }
     return this.require.apply(this, arguments);
   },
 
   /**
    * Define a getter property on the given object that requires the given
    * module. This enables delaying importing modules until the module is
    * actually used.
    *
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/tests/unit/test_require.js
@@ -0,0 +1,20 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Test devtools.require
+
+// Ensure that DevtoolsLoader.require doesn't spawn multiple
+// loader/modules when early cached
+function testBug1091706() {
+  let loader = new DevToolsLoader();
+  let require = loader.require;
+
+  let color1 = require("devtools/css-color");
+  let color2 = require("devtools/css-color");
+
+  do_check_true(color1 === color2);
+}
+
+function run_test() {
+  testBug1091706();
+}
--- a/toolkit/devtools/tests/unit/xpcshell.ini
+++ b/toolkit/devtools/tests/unit/xpcshell.ini
@@ -7,8 +7,9 @@ support-files =
 
 [test_independent_loaders.js]
 [test_invisible_loader.js]
 [test_safeErrorString.js]
 [test_defineLazyPrototypeGetter.js]
 [test_async-utils.js]
 [test_consoleID.js]
 [test_require_lazy.js]
+[test_require.js]