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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user