mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 21:00:23 +01:00
Fix toString for proxies
This commit is contained in:
parent
aa3f9d878d
commit
a7d02efd09
@ -136,14 +136,40 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const proxies = new Map();
|
||||||
|
const changedToStrings = new WeakMap();
|
||||||
scope.createProxyFunction = function createProxyFunction(window, original, replacement){
|
scope.createProxyFunction = function createProxyFunction(window, original, replacement){
|
||||||
const wrappedWindow = scope.getWrapped(window);
|
if (!changedToStrings.get(window)){
|
||||||
const handler = wrappedWindow.Object.create(wrappedWindow.Object);
|
changedToStrings.set(window, true);
|
||||||
handler.apply = scope.exportFunctionWithName(function(target, thisArgs, args){
|
const functionPrototype = scope.getWrapped(window).Function.prototype;
|
||||||
// console.log(target, thisArgs, args);
|
const toString = functionPrototype.toString;
|
||||||
return replacement.apply(thisArgs, args);
|
scope.changeProperty(window, "toString", {
|
||||||
|
object: functionPrototype,
|
||||||
|
name: "toString",
|
||||||
|
type: "value",
|
||||||
|
changed: scope.createProxyFunction(
|
||||||
|
window,
|
||||||
|
toString,
|
||||||
|
function(){
|
||||||
|
return proxies.get(this) || toString.call(this);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const handler = scope.getWrapped(window).Object.create(null);
|
||||||
|
handler.apply = scope.exportFunctionWithName(function(_target, thisArgs, args){
|
||||||
|
try {
|
||||||
|
return args.length?
|
||||||
|
replacement.call(thisArgs, ...args):
|
||||||
|
replacement.call(thisArgs);
|
||||||
|
}
|
||||||
|
catch (error){
|
||||||
|
return original.apply(thisArgs, args);
|
||||||
|
}
|
||||||
}, window, "");
|
}, window, "");
|
||||||
return new wrappedWindow.Proxy(original, handler);
|
const proxy = new window.Proxy(original, handler);
|
||||||
|
proxies.set(proxy, original.toString());
|
||||||
|
return scope.getWrapped(proxy);
|
||||||
};
|
};
|
||||||
|
|
||||||
const changedPropertiesByWindow = new WeakMap();
|
const changedPropertiesByWindow = new WeakMap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user