Skip to content

Commit

Permalink
Do not use proxy for Function.prototype.toString
Browse files Browse the repository at this point in the history
Fixes #685
  • Loading branch information
kkapsner committed Mar 29, 2024
1 parent 1d8bf95 commit 200f6b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
};

Expand Down
1 change: 1 addition & 0 deletions releaseNotes.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/detectionTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down

0 comments on commit 200f6b3

Please sign in to comment.