Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Attempt to describe a self-hosted version of WindowProxy
// Reusing parts of https://gist.github.com/4279162
function WindowProxyHandler(target){
this.target = target;
}
WindowProxyHandler.prototype = {
get: function (_, name) {
return this.target[name];
},
set: function (_, name, value) {
return this.target[name] = value;
},
getOwnPropertyDescriptor: function (_, name) {
return Object.getOwnPropertyDescriptor(this.target, name);
},
defineProperty: function(_, name, desc){
if(desc.configurable === false)
throw new TypeError('Nope');
else
return Object.defineProperty(this.target, name, desc);
},
isExtensible: function () {
return true;
},
isSealed: function () {
return false;
},
isFrozen: function () {
return false;
},
preventExtensions: function(){
throw new TypeError('Nope');
},
freeze: function(){
throw new TypeError('Nope');
},
seal: function(){
throw new TypeError('Nope');
}
};
function retargetableProxy(target, dummyTarget) {
var handler = new WindowProxyHandler(target);
return {
proxy: new Proxy(dummyTarget, handler),
setTarget: function(newTarget){
handler.target = newTarget;
}
};
}
function Window(){/* create window instances */}
var dummyWindowProxyTarget = {
get location(){},
set location(url){},
get document(){}
// ...
};
function WindowProxy(){
var {proxy, setTarget} = retargetableProxy(new Window(), dummyWindowProxyTarget);
return proxy;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.