diff --git a/common/bootstrap.js b/common/bootstrap.js index 0e1d864a..91a97c1c 100755 --- a/common/bootstrap.js +++ b/common/bootstrap.js @@ -172,7 +172,17 @@ let JSMLoader = { let module = this.modules[name]; if (target) for each (let symbol in module.EXPORTED_SYMBOLS) - target[symbol] = module[symbol]; + try { + Object.defineProperty(target, symbol, { + configurable: true, + enumerable: true, + writable: true, + value: module[symbol] + }); + } + catch (e) { + target[symbol] = module[symbol]; + } return module; }, diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 3389dee9..093d6c95 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -6,10 +6,9 @@ var { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; -if (typeof Proxy == "function") - var Cs = Proxy(Components.stack, { - get: function Cs_get(target, prop) Components.stack.caller[prop] - }); +var Cs = new Proxy(Components.stack, { + get: function Cs_get(target, prop) Components.stack.caller[prop] +}); function module(url) { let obj = {}; diff --git a/common/modules/main.jsm b/common/modules/main.jsm index 31df62fd..cfb9ff91 100644 --- a/common/modules/main.jsm +++ b/common/modules/main.jsm @@ -110,7 +110,27 @@ var Modules = function Modules(window) { const BASES = [BASE, "resource://dactyl-local-content/"]; - var jsmodules = newContext(window, false, "Dactyl `jsmodules`"); + 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]; + + let p = target[prop]; + if (callable(p)) + return proxyCache[prop] = p.bind(target); + + return p; + }, + + set: function window_set(target, prop, val) { + return target[prop] = val; + } + }); + + var jsmodules = newContext(proxy, false, "Dactyl `jsmodules`"); jsmodules.NAME = "jsmodules"; const create = bind("create", jsmodules.Object); @@ -120,14 +140,6 @@ var Modules = function Modules(window) { jsmodules: jsmodules, - get content() this.config.browser.contentWindow || window.content, - - get document() window.document, - - get navigator() window.navigator, - - window: window, - Module: Module, load: function load(script) {