Added ability to use objectGetters on faked functions.

This commit is contained in:
kkapsner 2019-11-07 17:38:54 +01:00
parent 73657852d3
commit 5d6c2d9a47
1 changed files with 34 additions and 8 deletions

View File

@ -79,10 +79,23 @@
Array.isArray(changedFunction.object)?
changedFunction.object:
[changedFunction.object]
).map(function(name){
if (name){
const constructor = getWrapped(window)[name];
if (constructor){
return constructor.prototype;
}
}
return false;
}).concat(
changedFunction.objectGetters?
changedFunction.objectGetters.map(function(objectGetter){
return objectGetter(getWrapped(window));
}):
[]
).forEach(function(object){
const constructor = getWrapped(window)[object];
if (constructor){
callback({name, object: constructor.prototype});
if (object){
callback({name, object: object});
}
});
});
@ -295,12 +308,25 @@
Array.isArray(changedFunction.object)?
changedFunction.object:
[changedFunction.object]
).map(function(name){
if (name){
const constructor = getWrapped(window)[name];
if (constructor){
return constructor.prototype;
}
}
return false;
}).concat(
changedFunction.objectGetters?
changedFunction.objectGetters.map(function(objectGetter){
return objectGetter(getWrapped(window));
}):
[]
).forEach(function(object){
const constructor = getWrapped(window)[object];
if (constructor){
const original = constructor.prototype[name];
if (object){
const original = object[name];
const checker = generateChecker(name, changedFunction, siteStatus, original);
const descriptor = Object.getOwnPropertyDescriptor(constructor.prototype, name);
const descriptor = Object.getOwnPropertyDescriptor(object, name);
if (descriptor){
if (descriptor.hasOwnProperty("value")){
if (changedFunction.fakeGenerator){
@ -321,7 +347,7 @@
);
}, window);
}
Object.defineProperty(constructor.prototype, name, descriptor);
Object.defineProperty(object, name, descriptor);
}
}
});