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

View File

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

View File

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

View File

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