Always use exportFunctionWithName

This commit is contained in:
kkapsner 2019-12-13 17:34:14 +01:00
parent af1dfe755c
commit 6fb7622fec
4 changed files with 44 additions and 47 deletions

View File

@ -169,7 +169,7 @@
const matchMediaDescriptor = Object.getOwnPropertyDescriptor(wrappedWindow, "matchMedia"); const matchMediaDescriptor = Object.getOwnPropertyDescriptor(wrappedWindow, "matchMedia");
const originalMatchMedia = matchMediaDescriptor.value; const originalMatchMedia = matchMediaDescriptor.value;
matchMediaDescriptor.value = exportFunction(function matchMedia(query){ matchMediaDescriptor.value = extension.exportFunctionWithName(function matchMedia(query){
if (query === extensionSecret[0]){ if (query === extensionSecret[0]){
return extensionSecret[1]; return extensionSecret[1];
} }
@ -178,7 +178,7 @@
originalMatchMedia.apply(this, wrappedWindow.Array.from(arguments)): originalMatchMedia.apply(this, wrappedWindow.Array.from(arguments)):
originalMatchMedia.call(this, query); originalMatchMedia.call(this, query);
} }
}, window); }, window, originalMatchMedia.name);
Object.defineProperty(wrappedWindow, "matchMedia", matchMediaDescriptor); Object.defineProperty(wrappedWindow, "matchMedia", matchMediaDescriptor);
interceptedWindows.set(wrappedWindow, true); interceptedWindows.set(wrappedWindow, true);

View File

@ -24,6 +24,9 @@
function changeProperty(object, name, type, changed){ function changeProperty(object, name, type, changed){
const descriptor = Object.getOwnPropertyDescriptor(object, name); const descriptor = Object.getOwnPropertyDescriptor(object, name);
const original = descriptor[type]; const original = descriptor[type];
if ((typeof changed) === "function"){
changed = extension.exportFunctionWithName(changed, window, original.name);
}
descriptor[type] = changed; descriptor[type] = changed;
Object.defineProperty(object, name, descriptor); Object.defineProperty(object, name, descriptor);
registerChangedProperty(object, name, descriptor, type, original); registerChangedProperty(object, name, descriptor, type, original);
@ -71,10 +74,9 @@
return window; return window;
} }
}; };
changeProperty(wrappedConstructor.prototype, "contentWindow", "get", exportFunction( changeProperty(wrappedConstructor.prototype, "contentWindow", "get",
Object.getOwnPropertyDescriptor(contentWindowTemp, "contentWindow").get, Object.getOwnPropertyDescriptor(contentWindowTemp, "contentWindow").get
window );
));
const contentDocumentDescriptor = Object.getOwnPropertyDescriptor( const contentDocumentDescriptor = Object.getOwnPropertyDescriptor(
constructor.prototype, constructor.prototype,
@ -90,10 +92,9 @@
return document; return document;
} }
}; };
changeProperty(wrappedConstructor.prototype, "contentDocument", "get", exportFunction( changeProperty(wrappedConstructor.prototype, "contentDocument", "get",
Object.getOwnPropertyDescriptor(contentDocumentTemp, "contentDocument").get, Object.getOwnPropertyDescriptor(contentDocumentTemp, "contentDocument").get
window );
));
}); });
} }
@ -130,16 +131,15 @@
protectionDefinition.methods.forEach(function(method){ protectionDefinition.methods.forEach(function(method){
const descriptor = Object.getOwnPropertyDescriptor(object, method); const descriptor = Object.getOwnPropertyDescriptor(object, method);
const original = descriptor.value; const original = descriptor.value;
changeProperty(object, method, "value", extension.exportFunctionWithName(function method(){ changeProperty(object, method, "value", function method(){
const value = arguments.length? const value = arguments.length?
original.apply(this, window.Array.from(arguments)): original.apply(this, window.Array.from(arguments)):
original.call(this); original.call(this);
allCallback(); allCallback();
return value; return value;
}, window, method)); });
}); });
protectionDefinition.getters.forEach(function(property){ protectionDefinition.getters.forEach(function(property){
const descriptor = Object.getOwnPropertyDescriptor(object, property);
const temp = { const temp = {
get [property](){ get [property](){
const ret = this[property]; const ret = this[property];
@ -147,11 +147,9 @@
return ret; return ret;
} }
}; };
changeProperty(object, property, "get", extension.exportFunctionWithName( changeProperty(object, property, "get",
Object.getOwnPropertyDescriptor(temp, property).get, Object.getOwnPropertyDescriptor(temp, property).get
window, );
descriptor.get
));
}); });
protectionDefinition.setters.forEach(function(property){ protectionDefinition.setters.forEach(function(property){
const descriptor = Object.getOwnPropertyDescriptor(object, property); const descriptor = Object.getOwnPropertyDescriptor(object, property);
@ -164,9 +162,9 @@
return ret; return ret;
} }
}; };
changeProperty(object, property, "set", extension.exportFunctionWithName( changeProperty(object, property, "set",
Object.getOwnPropertyDescriptor(temp, property).set, window, setter.name Object.getOwnPropertyDescriptor(temp, property).set
)); );
}); });
}); });
} }
@ -207,8 +205,7 @@
documentWriteDescriptorOnHTMLDocument? documentWriteDescriptorOnHTMLDocument?
wrappedWindow.HTMLDocument.prototype: wrappedWindow.HTMLDocument.prototype:
wrappedWindow.Document.prototype, wrappedWindow.Document.prototype,
// eslint-disable-next-line no-unused-vars "write", "value", function write(markup){
"write", "value", exportFunction(function write(markup){
for (let i = 0, l = arguments.length; i < l; i += 1){ for (let i = 0, l = arguments.length; i < l; i += 1){
const str = "" + arguments[i]; const str = "" + arguments[i];
// weird problem with waterfox and google docs // weird problem with waterfox and google docs
@ -226,7 +223,7 @@
} }
} }
} }
}, window) }
); );
const documentWritelnDescriptorOnHTMLDocument = Object.getOwnPropertyDescriptor( const documentWritelnDescriptorOnHTMLDocument = Object.getOwnPropertyDescriptor(
@ -242,26 +239,22 @@
documentWritelnDescriptorOnHTMLDocument? documentWritelnDescriptorOnHTMLDocument?
wrappedWindow.HTMLDocument.prototype: wrappedWindow.HTMLDocument.prototype:
wrappedWindow.Document.prototype, wrappedWindow.Document.prototype,
"writeln", "value", exportFunction( "writeln", "value", function writeln(markup){
// eslint-disable-next-line no-unused-vars for (let i = 0, l = arguments.length; i < l; i += 1){
function writeln(markup){ const str = "" + arguments[i];
for (let i = 0, l = arguments.length; i < l; i += 1){ const parts = str.split(/(?=<)/);
const str = "" + arguments[i]; const length = parts.length;
const parts = str.split(/(?=<)/); const scripts = window.document.getElementsByTagName("script");
const length = parts.length; for (let i = 0; i < length; i += 1){
const scripts = window.document.getElementsByTagName("script"); documentWrite.call(this, parts[i]);
for (let i = 0; i < length; i += 1){ allCallback();
documentWrite.call(this, parts[i]); if (scripts.length && scripts[scripts.length - 1].src){
allCallback(); observe();
if (scripts.length && scripts[scripts.length - 1].src){
observe();
}
} }
} }
documentWriteln.call(this, ""); }
}, documentWriteln.call(this, "");
window }
)
); );
} }
@ -277,7 +270,7 @@
).get; ).get;
changeProperty( changeProperty(
wrappedWindow, wrappedWindow,
"open", "value", exportFunction(function open(){ "open", "value", function open(){
const newWindow = arguments.length? const newWindow = arguments.length?
windowOpen.apply(this, window.Array.from(arguments)): windowOpen.apply(this, window.Array.from(arguments)):
windowOpen.call(this); windowOpen.call(this);
@ -287,7 +280,7 @@
singleCallback(getDocument.call(newWindow).defaultView); singleCallback(getDocument.call(newWindow).defaultView);
} }
return newWindow; return newWindow;
}, window) }
); );
} }

View File

@ -149,7 +149,7 @@
{ {
enumerable: true, enumerable: true,
configurable: true, configurable: true,
get: exportFunction(function(){ get: extension.exportFunctionWithName(function(){
if (forceLoad){ if (forceLoad){
logging.warning("force load the settings. Calling stack:", (new Error()).stack); logging.warning("force load the settings. Calling stack:", (new Error()).stack);
undoPreIntercept(); undoPreIntercept();
@ -175,8 +175,8 @@
}); });
return undef; return undef;
} }
}, windowToProcess), }, windowToProcess, `get ${name}`),
set: exportFunction(function(){}, windowToProcess) set: extension.exportFunctionWithName(function(){}, windowToProcess, `set ${name}`)
} }
); );
}); });

View File

@ -203,6 +203,10 @@ addTest("function name", function(log){
func: HTMLIFrameElement.prototype.__lookupGetter__("contentDocument"), func: HTMLIFrameElement.prototype.__lookupGetter__("contentDocument"),
expectedName: "get contentDocument" expectedName: "get contentDocument"
}, },
{
func: HTMLIFrameElement.prototype.__lookupGetter__("contentWindow"),
expectedName: "get contentWindow"
},
].map(checkName).some(function(b){return b;}); ].map(checkName).some(function(b){return b;});
}); });
addTest("exposed getters or setters", function(log){ addTest("exposed getters or setters", function(log){