From 3ea3dcb3dbc9a0f1fa27bf77eb11bc94d82f0acf Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 16 Mar 2014 21:43:36 -0700 Subject: [PATCH] Make things not be broken on FF<29. --- common/modules/main.jsm | 64 +++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/common/modules/main.jsm b/common/modules/main.jsm index cfb9ff91..80e64a79 100644 --- a/common/modules/main.jsm +++ b/common/modules/main.jsm @@ -111,24 +111,58 @@ var Modules = function Modules(window) { const BASES = [BASE, "resource://dactyl-local-content/"]; let proxyCache = {}; - let proxy = new Proxy(window, { - get: function window_get(target, prop) { - // `in`, not `hasOwnProperty`, because we want to return - // unbound methods in `Object.prototype` - if (prop in proxyCache) - return proxyCache[prop]; + if (config.haveGecko(29)) + var proxy = new Proxy(window, { + get: function window_get(target, prop) { + // `in`, not `hasOwnProperty`, because we want to return + // unbound methods in `Object.prototype` + if (prop in proxyCache) + return proxyCache[prop]; - let p = target[prop]; - if (callable(p)) - return proxyCache[prop] = p.bind(target); + let p = target[prop]; + if (callable(p)) + return proxyCache[prop] = p.bind(target); - return p; - }, + return p; + }, - set: function window_set(target, prop, val) { - return target[prop] = val; - } - }); + set: function window_set(target, prop, val) { + return target[prop] = val; + } + }); + else { + // Bug 814892 + let o = {}; + // Oh, the brokenness... See bug 793210 + Object.preventExtensions(o); + proxy = new Proxy(o, { + get: function window_get(target, prop) { + // `in`, not `hasOwnProperty`, because we want to return + // unbound methods in `Object.prototype` + if (prop in proxyCache) + return proxyCache[prop]; + + let p = window[prop]; + if (callable(p)) + return proxyCache[prop] = p.bind(window); + + return p; + }, + + set: function window_set(target, prop, val) { + return window[prop] = val; + }, + + getOwnPropertyDescriptor: function (target, prop) Object.getOwnPropertyDescriptor(window, prop), + getOwnPropertyNames: function (target, prop) Object.getOwnPropertyNames(window), + defineProperty: function (target, prop, desc) Object.defineProperty(window, prop, desc), + deleteProperty: function (target, prop) { delete window[prop]; }, + has: function (target, prop) prop in window, + hasOwn: function (target, prop) hasOwnProperty(window, prop), + enumerate: function (target) (p for (p in window)), + iterate: function (target) (p for (p of window)) + }); + } var jsmodules = newContext(proxy, false, "Dactyl `jsmodules`"); jsmodules.NAME = "jsmodules";