1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01:00

Do not use proxy for Function.prototype.toString

Fixes #685
This commit is contained in:
kkapsner 2024-03-29 16:37:07 +01:00
parent 1d8bf95926
commit 200f6b31f3
3 changed files with 19 additions and 10 deletions

View File

@ -144,20 +144,18 @@
const changedToStrings = new WeakMap();
scope.createProxyFunction = function createProxyFunction(window, original, replacement){
if (!changedToStrings.get(window)){
changedToStrings.set(window, true);
const functionPrototype = scope.getWrapped(window).Function.prototype;
const toString = functionPrototype.toString;
const originalToString = functionPrototype.toString;
changedToStrings.set(window, originalToString);
const alteredToString = scope.exportFunctionWithName(function toString(){
return proxies.get(this) || originalToString.call(this);
}, window, "toString");
proxies.set(alteredToString, originalToString.call(originalToString));
scope.changeProperty(window, "toString", {
object: functionPrototype,
name: "toString",
type: "value",
changed: scope.createProxyFunction(
window,
toString,
function(){
return proxies.get(this) || toString.call(this);
}
)
changed: alteredToString
});
}
const handler = scope.getWrapped(window).Object.create(null);
@ -177,7 +175,7 @@
}
}, window, "");
const proxy = new window.Proxy(original, handler);
proxies.set(proxy, original.toString());
proxies.set(proxy, changedToStrings.get(window).call(original));
return scope.getWrapped(proxy);
};

View File

@ -1,6 +1,7 @@
Version 1.10:
changes:
- added eBay and facebook.com to the convenience preset
- do not use proxy for Function.prototype.toString (causes weird problems sometimes)
new features:
- added setting showPresetsOnInstallation to be able to not show the presets page upon installation

View File

@ -181,6 +181,16 @@ addTest("toString modified", function(log){
configurable: true
},
log
) | checkPropertyDescriptor(
Function.prototype,
"toString",
{
value: function toString(){},
writable: true,
enumerable: false,
configurable: true
},
log
);
});
addTest("function name", function(log){