1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-05 23:34:10 +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

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