[Pkg-mozext-commits] [adblock-plus] 300/464: Moved hooks.js to buildtools

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 20:44:27 UTC 2014


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

taffit pushed a commit to branch master
in repository adblock-plus.

commit 67fc914f1f8e813da21c83234508f11ba0532d74
Author: Thomas Greiner <thomas at greinr.com>
Date:   Wed Oct 10 12:17:10 2012 +0200

    Moved hooks.js to buildtools
---
 lib/hooks.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/lib/hooks.js b/lib/hooks.js
new file mode 100644
index 0000000..e953831
--- /dev/null
+++ b/lib/hooks.js
@@ -0,0 +1,77 @@
+/*
+ * This Source Code is subject to the terms of the Mozilla Public License
+ * version 2.0 (the "License"). You can obtain a copy of the License at
+ * http://mozilla.org/MPL/2.0/.
+ */
+
+function hook(obj, name, func, cleanup)
+{
+  let orig = obj[name];
+  let origGet = obj.__lookupGetter__(name);
+  let origSet = obj.__lookupSetter__(name);
+  let dumbOverrideAttempt = false;
+
+  let newFunc = function()
+  {
+    let params = arguments;
+    try
+    {
+      let result = func.apply(this, params);
+      if (typeof result == "object")
+        params = result;
+    }
+    catch(e)
+    {
+      Cu.reportError(e);
+    }
+
+    try
+    {
+      return orig.apply(this, params);
+    }
+    finally
+    {
+      if (typeof cleanup == "function")
+        cleanup();
+    }
+  };
+  newFunc.toString = function()
+  {
+    dumbOverrideAttempt = true;
+    return orig.toString();
+  };
+
+  obj.__defineGetter__(name, function()
+  {
+    dumbOverrideAttempt = false;
+    return newFunc;
+  });
+
+  obj.__defineSetter__(name, function(value)
+  {
+    if (dumbOverrideAttempt)
+    {
+      orig = value;
+    }
+    else
+    {
+      delete obj[name];
+      obj[name] = value;
+    }
+  });
+
+  return function()
+  {
+    delete obj[name];
+    obj[name] = orig;
+    if (origGet)
+    {
+      obj.__defineGetter__(name, origGet);
+    }
+    if (origSet)
+    {
+      obj.__defineSetter__(name, origSet);
+    }
+  };
+}
+exports.hook = hook;

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



More information about the Pkg-mozext-commits mailing list