[Pkg-mozext-commits] [requestpolicy] 95/280: add some information about the bootstrap process

David Prévot taffit at moszumanska.debian.org
Sat May 2 20:30:05 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository requestpolicy.

commit 37b9716b2c99c2c991cb9f8c3f101a5e279a81da
Author: Martin Kimmerle <dev at 256k.de>
Date:   Thu Jan 1 11:30:47 2015 +0100

    add some information about the bootstrap process
---
 src/bootstrap.js                      | 26 ++++++++++++++++++--------
 src/content/lib/bootstrap-manager.jsm | 19 ++++++++++++++++---
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/src/bootstrap.js b/src/bootstrap.js
index 3289022..7fb9a7f 100644
--- a/src/bootstrap.js
+++ b/src/bootstrap.js
@@ -28,6 +28,14 @@ const Cu = Components.utils;
 const bootstrapManagerURI = "chrome://requestpolicy/content/lib/" +
     "bootstrap-manager.jsm";
 
+/**
+ * If any Exception gets into bootstrap.js, it will be a severe error.
+ * The Logger can't be used, as it might not be available.
+ */
+function logSevereError(msg, stack) {
+  dump("[RequestPolicy] [SEVERE] [ERROR] " + msg +
+       (stack ? ", stack was: " + stack : ""));
+}
 
 function startup(data, reason) {
   // if the Browser Toolbox is open when enabling RP, stop here.
@@ -36,12 +44,16 @@ function startup(data, reason) {
   //debugger;
 
   try {
+    // Import the BootstrapManager and call its startup() function, that's all
+    // what has to be done here.
+    // It is IMPORTANT that BootstrapManager is the FIRST module that is
+    // imported! The reason is that many modules call
+    // `BootstrapManager.registerStartupFunction()` at **load-time**, so
+    // BootstrapManager has to be available.
     Cu.import(bootstrapManagerURI);
     BootstrapManager.startup(data, reason);
   } catch(e) {
-    let msg = "startup() failed! " + e;
-    dump("[RequestPolicy] [SEVERE] [ERROR] " + msg +
-        (e.stack ? ", stack was: " + e.stack : ""));
+    logSevereError("startup() failed! " + e, e.stack);
   }
 }
 
@@ -54,16 +66,14 @@ function shutdown(data, reason) {
     BootstrapManager.shutdown(data, reason);
     Cu.unload(bootstrapManagerURI);
   } catch(e) {
-    let msg = "shutdown() failed! " + e;
-    dump("[RequestPolicy] [SEVERE] [ERROR] " + msg +
-        (e.stack ? ", stack was: " + e.stack : ""));
+    logSevereError("shutdown() failed! " + e, e.stack);
   }
 }
 
 function install(data, reason) {
-  // note: the addon might be not activated
+  // note: the addon might be not activated when this function gets called
 }
 
 function uninstall(data, reason) {
-  // note: the addon might be not activated
+  // note: the addon might be not activated when this function gets called
 }
diff --git a/src/content/lib/bootstrap-manager.jsm b/src/content/lib/bootstrap-manager.jsm
index c97d0b1..be70b37 100644
--- a/src/content/lib/bootstrap-manager.jsm
+++ b/src/content/lib/bootstrap-manager.jsm
@@ -87,10 +87,23 @@ let BootstrapManager = (function() {
    * called.
    */
   self.registerStartupFunction(function() {
-    // manually load the ScriptLoader
+    // Manually load the ScriptLoader. It has to be unloded manually as well!
     Cu.import(scriptLoaderURI, globalScope);
-    ScriptLoader.importModules(["logger", "requestpolicy-service",
-                                "window-manager", "about-uri"], globalScope);
+
+    // Next, import essential modules. Dependencies will be imported as well.
+    //
+    // It's IMPORTANT that those modules are imported in a startup-function
+    // and NOT when BootstrapManager itself gets loaded. The reason is that many
+    // modules call `BootstrapManager.registerStartupFunction()` at load-time,
+    // which wouldn't be available if BootstrapManager is *itself* still being
+    // loaded. This would be an "import()-loop".
+    {
+      // import the Logger first so that its startup-function will be called
+      // after this one
+      ScriptLoader.importModule("logger");
+      ScriptLoader.importModules(["requestpolicy-service", "window-manager",
+                                  "about-uri"], globalScope);
+    }
   });
 
   self.registerShutdownFunction(function() {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git



More information about the Pkg-mozext-commits mailing list