1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-19 23:57:59 +01:00

Use proxy of window for modules prototype. Closes issue #928.

This commit is contained in:
Kris Maglione
2014-03-15 14:32:58 -07:00
parent e1a6446fcf
commit 5d12a470bc
3 changed files with 35 additions and 14 deletions

10
common/bootstrap.js vendored
View File

@@ -172,7 +172,17 @@ let JSMLoader = {
let module = this.modules[name];
if (target)
for each (let symbol in module.EXPORTED_SYMBOLS)
try {
Object.defineProperty(target, symbol, {
configurable: true,
enumerable: true,
writable: true,
value: module[symbol]
});
}
catch (e) {
target[symbol] = module[symbol];
}
return module;
},

View File

@@ -6,8 +6,7 @@
var { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
if (typeof Proxy == "function")
var Cs = Proxy(Components.stack, {
var Cs = new Proxy(Components.stack, {
get: function Cs_get(target, prop) Components.stack.caller[prop]
});

View File

@@ -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) {