[Pkg-mozext-commits] [requestpolicy] 165/280: [refact] Environment: wrap startup and shutdown

David Prévot taffit at moszumanska.debian.org
Sat May 2 20:30:17 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 546aa45c508f02b53a6607512242383188060cc3
Author: Martin Kimmerle <dev at 256k.de>
Date:   Tue Jan 20 16:21:05 2015 +0100

    [refact] Environment: wrap startup and shutdown
---
 src/content/lib/environment.jsm | 112 ++++++++++++++++++++--------------------
 1 file changed, 57 insertions(+), 55 deletions(-)

diff --git a/src/content/lib/environment.jsm b/src/content/lib/environment.jsm
index 3c56fc5..537d192 100644
--- a/src/content/lib/environment.jsm
+++ b/src/content/lib/environment.jsm
@@ -213,76 +213,78 @@ Environment.prototype.addShutdownFunction = function(aLevel, f) {
 
 
 
-/**
- * This function calls all functions of a function queue.
- */
-function callFunctions(fnArray, fnArgsToApply) {
-  // process the Array as long as it contains elements
-  while (fnArray.length > 0) {
-    // The following is either `fnArray.pop()` or `fnArray.shift()`
-    // depending on `sequence`.
-    let f = fnArray.pop();
-
-    // call the function
-    f.apply(null, fnArgsToApply);
-  }
-};
+(function addStartupAndShutdown(Environment) {
+  /**
+   * This function calls all functions of a function queue.
+   */
+  function callFunctions(fnArray, fnArgsToApply) {
+    // process the Array as long as it contains elements
+    while (fnArray.length > 0) {
+      // The following is either `fnArray.pop()` or `fnArray.shift()`
+      // depending on `sequence`.
+      let f = fnArray.pop();
+
+      // call the function
+      f.apply(null, fnArgsToApply);
+    }
+  };
 
-function processLevel(aLevelObj, fnArgsToApply) {
-  aLevelObj.levelState = LEVEL_STATES.PROCESSING;
-  callFunctions(aLevelObj.functions, fnArgsToApply);
-  aLevelObj.levelState = LEVEL_STATES.FINISHED_PROCESSING;
-}
+  function processLevel(aLevelObj, fnArgsToApply) {
+    aLevelObj.levelState = LEVEL_STATES.PROCESSING;
+    callFunctions(aLevelObj.functions, fnArgsToApply);
+    aLevelObj.levelState = LEVEL_STATES.FINISHED_PROCESSING;
+  }
 
-// not used for now
-//Environment.prototype.callStartupFunctions = function(aLevel, fnArgsToApply) {
-//  let self = this;
-//  processLevel(self.startupLevels[aLevel], fnArgsToApply);
-//};
+  // not used for now
+  //Environment.prototype.callStartupFunctions = function(aLevel, fnArgsToApply) {
+  //  let self = this;
+  //  processLevel(self.startupLevels[aLevel], fnArgsToApply);
+  //};
 
-Environment.prototype.callShutdownFunctions = function(aLevel, fnArgsToApply) {
-  let self = this;
-  processLevel(self.shutdownLevels[aLevel], fnArgsToApply);
-};
+  Environment.prototype.callShutdownFunctions = function(aLevel, fnArgsToApply) {
+    let self = this;
+    processLevel(self.shutdownLevels[aLevel], fnArgsToApply);
+  };
 
 
 
 
-Environment.prototype.startup = function() {
-  let self = this;
-  let fnArgsToApply = arguments;
+  Environment.prototype.startup = function() {
+    let self = this;
+    let fnArgsToApply = arguments;
 
-  if (self.envState == ENV_STATES.NOT_STARTED) {
-    //console.log('[RPC] starting up Environment "'+self.name+'"...');
-    self.envState = ENV_STATES.STARTING_UP;
+    if (self.envState == ENV_STATES.NOT_STARTED) {
+      //console.log('[RPC] starting up Environment "'+self.name+'"...');
+      self.envState = ENV_STATES.STARTING_UP;
 
-    Environment.iterateStartupLevels(function (level) {
-      let levelObj = self.startupLevels[level];
-      processLevel(levelObj, fnArgsToApply);
-    });
+      Environment.iterateStartupLevels(function (level) {
+        let levelObj = self.startupLevels[level];
+        processLevel(levelObj, fnArgsToApply);
+      });
 
-    self.envState = ENV_STATES.STARTUP_DONE;
-  }
-};
+      self.envState = ENV_STATES.STARTUP_DONE;
+    }
+  };
 
-Environment.prototype.shutdown = function() {
-  let self = this;
-  let fnArgsToApply = arguments;
+  Environment.prototype.shutdown = function() {
+    let self = this;
+    let fnArgsToApply = arguments;
 
-  if (self.envState === ENV_STATES.STARTUP_DONE) {
-    //console.log('[RPC] shutting down Environment "'+self.name+'"...');
-    self.envState = ENV_STATES.SHUTTING_DOWN;
+    if (self.envState === ENV_STATES.STARTUP_DONE) {
+      //console.log('[RPC] shutting down Environment "'+self.name+'"...');
+      self.envState = ENV_STATES.SHUTTING_DOWN;
 
-    EnvironmentManager.unregisterEnvironment(self);
+      EnvironmentManager.unregisterEnvironment(self);
 
-    Environment.iterateShutdownLevels(function (level) {
-      let levelObj = self.shutdownLevels[level];
-      processLevel(levelObj, fnArgsToApply);
-    });
+      Environment.iterateShutdownLevels(function (level) {
+        let levelObj = self.shutdownLevels[level];
+        processLevel(levelObj, fnArgsToApply);
+      });
 
-    self.envState = ENV_STATES.SHUT_DOWN;
-  }
-};
+      self.envState = ENV_STATES.SHUT_DOWN;
+    }
+  };
+})(Environment);
 
 /**
  * Helper function: shuts down the environment when an EventTarget's "unload"

-- 
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