mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +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){
|
||||
const wrappedWindow = scope.getWrapped(window);
|
||||
const handler = wrappedWindow.Object.create(wrappedWindow.Object);
|
||||
handler.apply = scope.exportFunctionWithName(function(target, thisArgs, args){
|
||||
// console.log(target, thisArgs, args);
|
||||
return replacement.apply(thisArgs, args);
|
||||
if (!changedToStrings.get(window)){
|
||||
changedToStrings.set(window, true);
|
||||
const functionPrototype = scope.getWrapped(window).Function.prototype;
|
||||
const toString = functionPrototype.toString;
|
||||
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, "");
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user