[Pkg-mozext-commits] [requestpolicy] 147/280: fix #564, fix #567. The Pref aliases did not work

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

    fix #564, fix #567. The Pref aliases did not work
---
 src/content/lib/prefs.jsm | 56 +++++++++++++++++++----------------------------
 1 file changed, 22 insertions(+), 34 deletions(-)

diff --git a/src/content/lib/prefs.jsm b/src/content/lib/prefs.jsm
index c9e6169..d839cf2 100644
--- a/src/content/lib/prefs.jsm
+++ b/src/content/lib/prefs.jsm
@@ -55,6 +55,12 @@ let Prefs = (function() {
   };
 
 
+  function getRPBoolPref(aPrefName) {
+    return rpPrefBranch.getBoolPref(aPrefName);
+  }
+  function setRPBoolPref(aPrefName, aValue) {
+    rpPrefBranch.setBoolPref(aPrefName, aValue);
+  }
   // not needed yet
   //function getInvertedRPBoolPref(aPrefName) {
   //  return !rpPrefBranch.getBoolPref(aPrefName);
@@ -68,16 +74,14 @@ let Prefs = (function() {
    * `Prefs.getter_function_name()` and `Prefs.setter_function_name()`.
    * Those functions will be added to `self` subsequently.
    */
-  let prefAliases = {
-    "defaultPolicy.allow": {
-      getter: {name: "isDefaultAllow", fn: rpPrefBranch.getBoolPref}
-    },
-    "defaultPolicy.allowSameDomain": {
-      getter: {name: "isDefaultAllowSameDomain", fn: rpPrefBranch.getBoolPref}
-    },
-    "startWithAllowAllEnabled": {
-      getter: {name: "isBlockingDisabled", fn: rpPrefBranch.getBoolPref},
-      setter: {name: "setBlockingDisabled", fn: rpPrefBranch.setBoolPref}
+  let rpPrefAliases = {
+    "bool": {
+      "defaultPolicy.allow": "DefaultAllow",
+      "defaultPolicy.allowSameDomain": "DefaultAllowSameDomain",
+
+      // As an example, this will become `isBlockingDisabled()` and
+      // `setBlockingDisabled()`:
+      "startWithAllowAllEnabled": "BlockingDisabled"
     }
   };
 
@@ -86,30 +90,14 @@ let Prefs = (function() {
    * `setBlockingDisabled`.
    */
   {
-    for (let prefID in prefAliases) {
-      let pref = prefAliases[prefID];
-
-      if (pref.hasOwnProperty("getter")) {
-        let getterName = pref.getter.name;
-        let getPref = pref.getter.fn;
-
-        // define the pref's getter function to `self`
-        self[getterName] = function() {
-          return getPref(prefID);
-        };
-      }
-
-      if (pref.hasOwnProperty("setter")) {
-        let setterName = pref.setter.name;
-        let setPref = pref.setter.fn;
-
-        // define the pref's getter function to `self`
-        self[setterName] = function(aValue) {
-          // set the pref and save it
-          setPref(prefID, aValue);
-          self.save();
-        };
-      }
+    for (let prefID in rpPrefAliases.bool) {
+      let prefName = rpPrefAliases.bool[prefID];
+
+      // define the pref's getter function to `self`
+      self["is"+prefName] = getRPBoolPref.bind(this, prefID);
+
+      // define the pref's getter function to `self`
+      self["set"+prefName] = setRPBoolPref.bind(this, prefID);
     }
   }
 

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