From 5d6c2d9a4742136198f6dbc0ae22fcd81c7339ac Mon Sep 17 00:00:00 2001 From: kkapsner Date: Thu, 7 Nov 2019 17:38:54 +0100 Subject: [PATCH] Added ability to use objectGetters on faked functions. --- lib/intercept.js | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/lib/intercept.js b/lib/intercept.js index 2455410..abf6c51 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -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); } } });