[Pkg-mozext-commits] [requestpolicy] 164/280: [refact] "processSequence" --> "iterateLevels"

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 95d942d8bc8f4c690b69c78f347a530d8c6f1781
Author: Martin Kimmerle <dev at 256k.de>
Date:   Tue Jan 20 16:15:47 2015 +0100

    [refact] "processSequence" --> "iterateLevels"
    
    Environment.iterateStartupLevels(fn)
    Environment.iterateShutdownLevels(fn)
---
 src/content/lib/environment.jsm          | 75 ++++++++++++++++----------------
 src/content/main/environment-manager.jsm | 22 +++++-----
 2 files changed, 48 insertions(+), 49 deletions(-)

diff --git a/src/content/lib/environment.jsm b/src/content/lib/environment.jsm
index 28a6884..3c56fc5 100644
--- a/src/content/lib/environment.jsm
+++ b/src/content/lib/environment.jsm
@@ -135,18 +135,36 @@ function generateLevelObjects() {
   return obj;
 }
 
-Environment.startupSequence = [
-  LEVELS.ESSENTIAL,
-  LEVELS.BACKEND,
-  LEVELS.INTERFACE,
-  LEVELS.UI
-];
-Environment.shutdownSequence = [
-  LEVELS.UI,
-  LEVELS.INTERFACE,
-  LEVELS.BACKEND,
-  LEVELS.ESSENTIAL
-];
+(function addLevelIterators(Environment) {
+  let startupSequence = [
+    LEVELS.ESSENTIAL,
+    LEVELS.BACKEND,
+    LEVELS.INTERFACE,
+    LEVELS.UI
+  ];
+  let shutdownSequence = [
+    LEVELS.UI,
+    LEVELS.INTERFACE,
+    LEVELS.BACKEND,
+    LEVELS.ESSENTIAL
+  ];
+  function iterateLevels(aSequence, aFn) {
+    for (let i = 0, len = aSequence.length; i < len; ++i) {
+      // Note: It's necessary to use for(;;) instead of  for(..of..)
+      //       because the order/sequence must be exactly the same as in the
+      //       array.  for(..of..) doesn't guarantee that the elements are
+      //       called in order.
+
+      let level = aSequence[i];
+      aFn(level);
+    }
+  };
+
+  Environment.iterateStartupLevels = iterateLevels.bind(null, startupSequence);
+  Environment.iterateShutdownLevels = iterateLevels.bind(null, shutdownSequence);
+})(Environment);
+
+
 
 
 /**
@@ -228,19 +246,6 @@ Environment.prototype.callShutdownFunctions = function(aLevel, fnArgsToApply) {
 };
 
 
-Environment.processSequence = function(aSequence, aCallback) {
-  for (let i = 0, len = aSequence.length; i < len; ++i) {
-    // Note: It's necessary to use for(;;) instead of  for(..of..)
-    //       because the order/sequence must be exactly the same as in the
-    //       array.  for(..of..) doesn't guarantee that the elements are
-    //       called in order.
-
-    let level = aSequence[i];
-    aCallback(level);
-  }
-};
-
-
 
 
 Environment.prototype.startup = function() {
@@ -251,12 +256,10 @@ Environment.prototype.startup = function() {
     //console.log('[RPC] starting up Environment "'+self.name+'"...');
     self.envState = ENV_STATES.STARTING_UP;
 
-    Environment.processSequence(
-        Environment.startupSequence,
-        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;
   }
@@ -272,12 +275,10 @@ Environment.prototype.shutdown = function() {
 
     EnvironmentManager.unregisterEnvironment(self);
 
-    Environment.processSequence(
-        Environment.shutdownSequence,
-        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;
   }
diff --git a/src/content/main/environment-manager.jsm b/src/content/main/environment-manager.jsm
index 2429928..04cbd74 100644
--- a/src/content/main/environment-manager.jsm
+++ b/src/content/main/environment-manager.jsm
@@ -100,23 +100,21 @@ let EnvironmentManager = (function(self) {
     let fnArgsToApply = [data, reason];
 
     // prepare shutdown
-    for (let env of self.environments) {
+    self.environments.forEach(function(env) {
       env.envState = Environment.SHUTTING_DOWN;
-    }
+    });
     // shut down
-    Environment.processSequence(
-        Environment.shutdownSequence,
-        function (level) {
-          //console.debug("[RPC] reaching level "+level+" ...");
-          for (let env of self.environments) {
-            env.callShutdownFunctions(level, fnArgsToApply);
-          }
-        });
+    Environment.iterateShutdownLevels(function (level) {
+      //console.debug("[RPC] reaching level "+level+" ...");
+      self.environments.forEach(function(env) {
+        env.callShutdownFunctions(level, fnArgsToApply);
+      });
+    });
     // finishing tasks
-    for (let env of self.environments) {
+    self.environments.forEach(function(env) {
       env.envState = Environment.SHUT_DOWN;
       self.unregisterEnvironment(env);
-    }
+    });
 
     // final tasks
     //console.debug("[RPC] reaching level 0 ...");

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