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:
12
common/bootstrap.js
vendored
12
common/bootstrap.js
vendored
@@ -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;
|
||||
},
|
||||
|
||||
@@ -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 = {};
|
||||
|
||||
@@ -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