[Pkg-mozext-commits] [adblock-plus] 450/464: Issue 653 - Object.defineProperty instead of defineGetter / defineSetter

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 20:44:43 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 384cb64c6d3c2aa698b5f15c9d8aaefd22c889aa
Author: Tom Schuster <tschuster at adblockplus.org>
Date:   Wed Jul 9 19:08:29 2014 +0200

    Issue 653 - Object.defineProperty instead of defineGetter / defineSetter
---
 chrome/content/ui/filters-subscriptionactions.js |  2 +-
 chrome/content/ui/progressBar.js                 | 14 ++++++++++----
 chrome/content/ui/sidebar.js                     |  2 +-
 lib/filterClasses.js                             | 13 ++++++-------
 lib/filterStorage.js                             |  5 +++--
 lib/io.js                                        |  5 ++---
 lib/utils.js                                     | 10 +++++-----
 7 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/chrome/content/ui/filters-subscriptionactions.js b/chrome/content/ui/filters-subscriptionactions.js
index 222a4a6..7cedc27 100644
--- a/chrome/content/ui/filters-subscriptionactions.js
+++ b/chrome/content/ui/filters-subscriptionactions.js
@@ -236,7 +236,7 @@ var SubscriptionActions =
       else if (accelKey == Ci.nsIDOMKeyEvent.DOM_VK_ALT)
         result = this._altMask;
     } catch(e) {}
-    this.__defineGetter__("_accelMask", function() result);
+    Object.defineProperty(this, "_accelMask", {value: result});
     return result;
   },
 
diff --git a/chrome/content/ui/progressBar.js b/chrome/content/ui/progressBar.js
index 659acdd..a506c97 100644
--- a/chrome/content/ui/progressBar.js
+++ b/chrome/content/ui/progressBar.js
@@ -32,10 +32,16 @@
       canvas.parentNode.appendChild(headers[i]);
 
     // Expose properties
-    progressBar.__defineGetter__("activeItem", getActiveItem);
-    progressBar.__defineSetter__("activeItem", setActiveItem);
-    progressBar.__defineGetter__("activeItemComplete", getActiveItemComplete);
-    progressBar.__defineSetter__("activeItemComplete", setActiveItemComplete);
+    Object.defineProperty(progressBar, "activeItem",
+    {
+      get: getActiveItem,
+      set: setActiveItem
+    });
+    Object.defineProperty(progressBar, "activeItemComplete",
+    {
+      get: getActiveItemComplete,
+      set: setActiveItemComplete
+    });
 
     isRTL = (window.getComputedStyle(document.documentElement).direction == "rtl");
 
diff --git a/chrome/content/ui/sidebar.js b/chrome/content/ui/sidebar.js
index 92e82ef..7694797 100644
--- a/chrome/content/ui/sidebar.js
+++ b/chrome/content/ui/sidebar.js
@@ -85,7 +85,7 @@ function init() {
   }
 
   let {getBrowser, addBrowserLocationListener} = require("appSupport");
-  window.__defineGetter__("content", function() {return getBrowser(mainWin).contentWindow;});
+  Object.defineProperty(window, "content", { get: () => getBrowser(mainWin).contentWindow });
 
   // Initialize matcher for disabled filters
   reloadDisabledFilters();
diff --git a/lib/filterClasses.js b/lib/filterClasses.js
index 4572946..2df8781 100644
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -473,7 +473,7 @@ function RegExpFilter(text, regexpSource, contentType, matchCase, domains, third
   {
     // The filter is a regular expression - convert it immediately to catch syntax errors
     let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), this.matchCase ? "" : "i");
-    this.__defineGetter__("regexp", () => regexp);
+    Object.defineProperty(this, "regexp", {value: regexp});
   }
   else
   {
@@ -529,10 +529,8 @@ RegExpFilter.prototype =
       .replace(/(\.\*)$/, "");     // remove trailing wildcards
 
     let regexp = new RegExp(source, this.matchCase ? "" : "i");
-
-    delete this.regexpSource;
-    this.__defineGetter__("regexp", () => regexp);
-    return this.regexp;
+    Object.defineProperty(this, "regexp", {value: regexp});
+    return regexp;
   },
   /**
    * Content types the filter applies to, combination of values from RegExpFilter.typeMap
@@ -572,9 +570,10 @@ RegExpFilter.prototype =
   }
 };
 
-RegExpFilter.prototype.__defineGetter__("0", function()
+// Required to optimize Matcher, see also RegExpFilter.prototype.length
+Object.defineProperty(RegExpFilter.prototype, "0",
 {
-  return this;
+  get: function() { return this; }
 });
 
 /**
diff --git a/lib/filterStorage.js b/lib/filterStorage.js
index f263a68..7028ec9 100644
--- a/lib/filterStorage.js
+++ b/lib/filterStorage.js
@@ -85,8 +85,9 @@ let FilterStorage = exports.FilterStorage =
     if (!file)
       Cu.reportError("Adblock Plus: Failed to resolve filter file location from extensions.adblockplus.patternsfile preference");
 
-    this.__defineGetter__("sourceFile", () => file);
-    return this.sourceFile;
+    // Property is configurable because of the test suite.
+    Object.defineProperty(this, "sourceFile", {value: file, configurable: true});
+    return file;
   },
 
   /**
diff --git a/lib/io.js b/lib/io.js
index ea362b7..915b5c1 100644
--- a/lib/io.js
+++ b/lib/io.js
@@ -39,9 +39,8 @@ let IO = exports.IO =
   get lineBreak()
   {
     let lineBreak = (Services.appinfo.OS == "WINNT" ? "\r\n" : "\n");
-    delete IO.lineBreak;
-    IO.__defineGetter__("lineBreak", () => lineBreak);
-    return IO.lineBreak;
+    Object.defineProperty(this, "lineBreak", {value: lineBreak});
+    return lineBreak;
   },
 
   /**
diff --git a/lib/utils.js b/lib/utils.js
index b827f90..20e613c 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -55,7 +55,7 @@ let Utils = exports.Utils =
   {
     let {application} = require("info");
     let result = (application == "fennec" || application == "fennec2");
-    Utils.__defineGetter__("isFennec", () => result);
+    Object.defineProperty(this, "isFennec", {value: result});
     return result;
   },
 
@@ -73,8 +73,8 @@ let Utils = exports.Utils =
     {
       Cu.reportError(e);
     }
-    Utils.__defineGetter__("appLocale", () => locale);
-    return Utils.appLocale;
+    Object.defineProperty(this, "appLocale", {value: locale});
+    return locale;
   },
 
   /**
@@ -83,8 +83,8 @@ let Utils = exports.Utils =
   get platformVersion()
   {
     let platformVersion = Services.appinfo.platformVersion;
-    Utils.__defineGetter__("platformVersion", () => platformVersion);
-    return Utils.platformVersion;
+    Object.defineProperty(this, "platformVersion", {value: platformVersion});
+    return platformVersion;
   },
 
   /**

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