diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-11-01 21:55:13 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-11-01 21:55:13 +0100 |
commit | ff881bdb6795e0f307b93919f98f454bedde4bb6 (patch) | |
tree | 53934cce4459a0c2c3e0d9ace5f7645c60d96a7d /application/palemoon | |
parent | 24027f0df9d23304709a80c22c6bfdbd27a95046 (diff) | |
download | UXP-ff881bdb6795e0f307b93919f98f454bedde4bb6.tar UXP-ff881bdb6795e0f307b93919f98f454bedde4bb6.tar.gz UXP-ff881bdb6795e0f307b93919f98f454bedde4bb6.tar.lz UXP-ff881bdb6795e0f307b93919f98f454bedde4bb6.tar.xz UXP-ff881bdb6795e0f307b93919f98f454bedde4bb6.zip |
#1261 - Update status bar component for the removal of Object.(un)watch
This fixes the regression from #1257 by adding in an
Object.prototype.watch() shim, based on Eli Grey's polyfill.
This resolves #1261.
Diffstat (limited to 'application/palemoon')
-rw-r--r-- | application/palemoon/components/statusbar/Status.jsm | 66 |
1 files changed, 51 insertions, 15 deletions
diff --git a/application/palemoon/components/statusbar/Status.jsm b/application/palemoon/components/statusbar/Status.jsm index 19e12ddfd..dbdd1fc49 100644 --- a/application/palemoon/components/statusbar/Status.jsm +++ b/application/palemoon/components/statusbar/Status.jsm @@ -120,6 +120,57 @@ S4EStatusService.prototype = }, buildBinding: function() { + + // Object.prototype.watch() shim, based on Eli Grey's polyfill + // object.watch + if (!this._window.XULBrowserWindow.watch) { + Object.defineProperty(this._window.XULBrowserWindow, "watch", { + enumerable: false, + configurable: true, + writable: false, + value: function (prop, handler) { + var oldval = this[prop], + newval = oldval, + getter = function () { + return newval; + }, + setter = function (val) { + oldval = newval; + return newval = handler.call(this, prop, oldval, val); + } + ; + + try { + if (delete this[prop]) { // can't watch constants + Object.defineProperty(this, prop, { + get: getter, + set: setter, + enumerable: true, + configurable: true + }); + } + } catch(e) { + // This fails fatally on non-configurable props, so just + // ignore errors if it does. + } + } + }); + } + + // object.unwatch + if (!this._window.XULBrowserWindow.unwatch) { + Object.defineProperty(this._window.XULBrowserWindow, "unwatch", { + enumerable: false, + configurable: true, + writable: false, + value: function (prop) { + var val = this[prop]; + delete this[prop]; // remove accessors + this[prop] = val; + } + }); + } + let XULBWPropHandler = function(prop, oldval, newval) { CU.reportError("Attempt to modify XULBrowserWindow." + prop); return oldval; @@ -139,21 +190,6 @@ S4EStatusService.prototype = this._window.XULBrowserWindow[prop] = this[prop].bind(this); this._window.XULBrowserWindow.watch(prop, XULBWPropHandler); }, this); - - let XULBWHandler = function(prop, oldval, newval) { - if(!newval) - { - return newval; - } - CU.reportError("XULBrowserWindow changed. Updating S4E bindings."); - this._window.setTimeout(function(self) - { - self.buildBinding(); - }, 0, this); - return newval; - }; - - this._window.watch("XULBrowserWindow", XULBWHandler); }, destroy: function() |