1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 20:46:39 +02:00

Get rid of eval.

This commit is contained in:
kkapsner 2019-12-12 00:09:53 +01:00
parent 32f9ea7447
commit 14a4d1cdc2
10 changed files with 96 additions and 50 deletions

View file

@ -13,6 +13,7 @@
}
const settings = require("./settings");
const extension = require("./extension");
const lists = require("./lists");
function isWhitelisted(url){
@ -129,40 +130,42 @@
protectionDefinition.methods.forEach(function(method){
const descriptor = Object.getOwnPropertyDescriptor(object, method);
const original = descriptor.value;
changeProperty(object, method, "value", exportFunction(eval(`(function ${method}(){
changeProperty(object, method, "value", extension.exportFunctionWithName(function method(){
const value = arguments.length?
original.apply(this, window.Array.from(arguments)):
original.call(this);
allCallback();
return value;
})`), window));
}, window, method));
});
protectionDefinition.getters.forEach(function(property){
const temp = eval(`({
get ${property}(){
const ret = this.${property};
const descriptor = Object.getOwnPropertyDescriptor(object, property);
const temp = {
get [property](){
const ret = this[property];
allCallback();
return ret;
}
})`);
changeProperty(object, property, "get", exportFunction(
};
changeProperty(object, property, "get", extension.exportFunctionWithName(
Object.getOwnPropertyDescriptor(temp, property).get,
window
window,
descriptor.get
));
});
protectionDefinition.setters.forEach(function(property){
const descriptor = Object.getOwnPropertyDescriptor(object, property);
const setter = descriptor.set;
const temp = eval(`({
set ${property}(value){
const temp = {
set [property](value){
const ret = setter.call(this, value);
// const ret = this.${property} = value;
allCallback();
return ret;
}
})`);
changeProperty(object, property, "set", exportFunction(
Object.getOwnPropertyDescriptor(temp, property).set, window
};
changeProperty(object, property, "set", extension.exportFunctionWithName(
Object.getOwnPropertyDescriptor(temp, property).set, window, setter.name
));
});
});