1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01:00

Allow cross origin arguments and remove apply(..., Array.from)

Fixes #415
This commit is contained in:
kkapsner 2019-12-29 23:40:39 +01:00
parent 8506757c62
commit 4601dd25af
11 changed files with 38 additions and 37 deletions

View File

@ -49,13 +49,14 @@
}; };
scope.exportFunctionWithName = function exportFunctionWithName(func, context, name){ scope.exportFunctionWithName = function exportFunctionWithName(func, context, name){
const exportedTry = exportFunction(func, context); const exportedTry = exportFunction(func, context, {allowCrossOriginArguments: true});
if (exportedTry.name === name){ if (exportedTry.name === name){
return exportedTry; return exportedTry;
} }
else { else {
const wrappedContext = scope.getWrapped(context); const wrappedContext = scope.getWrapped(context);
const options = { const options = {
allowCrossOriginArguments: true,
defineAs: name defineAs: name
}; };
const oldDescriptor = Object.getOwnPropertyDescriptor(wrappedContext, name); const oldDescriptor = Object.getOwnPropertyDescriptor(wrappedContext, name);

View File

@ -174,7 +174,7 @@
} }
else { else {
return arguments.length > 1? return arguments.length > 1?
originalMatchMedia.apply(this, wrappedWindow.Array.from(arguments)): originalMatchMedia.call(this, ...arguments):
originalMatchMedia.call(this, query); originalMatchMedia.call(this, query);
} }
}, window, originalMatchMedia.name); }, window, originalMatchMedia.name);

View File

@ -133,7 +133,7 @@
const original = descriptor.value; const original = descriptor.value;
changeProperty(object, method, "value", function method(){ changeProperty(object, method, "value", function method(){
const value = arguments.length? const value = arguments.length?
original.apply(this, window.Array.from(arguments)): original.call(this, ...arguments):
original.call(this); original.call(this);
allCallback(); allCallback();
return value; return value;
@ -272,7 +272,7 @@
wrappedWindow, wrappedWindow,
"open", "value", function open(){ "open", "value", function open(){
const newWindow = arguments.length? const newWindow = arguments.length?
windowOpen.apply(this, window.Array.from(arguments)): windowOpen.call(this, ...arguments):
windowOpen.call(this); windowOpen.call(this);
if (newWindow){ if (newWindow){
// if we use windowOpen from the normal window we see some SOP errors // if we use windowOpen from the normal window we see some SOP errors

View File

@ -17,7 +17,7 @@
if (check.allow){ if (check.allow){
if (check.allow === true){ if (check.allow === true){
return args.length? return args.length?
check.original.apply(object, check.window.Array.from(args)): check.original.call(object, ...args):
check.original.call(object); check.original.call(object);
} }
return callback.call(object, args, check); return callback.call(object, args, check);

View File

@ -166,7 +166,7 @@
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
notify("fakedAudioReadout"); notify("fakedAudioReadout");
const ret = original.apply(this, window.Array.from(args)); const ret = original.call(this, ...args);
fakeFloat32Array(array, window, prefs); fakeFloat32Array(array, window, prefs);
return ret; return ret;
}); });
@ -180,7 +180,7 @@
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
notify("fakedAudioReadout"); notify("fakedAudioReadout");
const ret = original.apply(this, window.Array.from(args)); const ret = original.call(this, ...args);
fakeUint8Array(array, window, prefs); fakeUint8Array(array, window, prefs);
return ret; return ret;
}); });
@ -194,7 +194,7 @@
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
notify("fakedAudioReadout"); notify("fakedAudioReadout");
const ret = original.apply(this, window.Array.from(args)); const ret = original.call(this, ...args);
fakeFloat32Array(array, window, prefs); fakeFloat32Array(array, window, prefs);
return ret; return ret;
}); });
@ -208,7 +208,7 @@
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
notify("fakedAudioReadout"); notify("fakedAudioReadout");
const ret = original.apply(this, window.Array.from(args)); const ret = original.call(this, ...args);
fakeUint8Array(array, window, prefs); fakeUint8Array(array, window, prefs);
return ret; return ret;
}); });
@ -221,7 +221,7 @@
return function getChannelData(channel){ return function getChannelData(channel){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
const ret = original.apply(this, window.Array.from(args)); const ret = original.call(this, ...args);
if (!getChannelDataAlreadyFakedArrays.get(ret)){ if (!getChannelDataAlreadyFakedArrays.get(ret)){
notify("fakedAudioReadout"); notify("fakedAudioReadout");
fakeFloat32Array(ret, window, prefs); fakeFloat32Array(ret, window, prefs);
@ -244,7 +244,7 @@
fakeFloat32Array(channelData, window, prefs); fakeFloat32Array(channelData, window, prefs);
getChannelDataAlreadyFakedArrays.set(channelData, true); getChannelDataAlreadyFakedArrays.set(channelData, true);
} }
const ret = original.apply(this, window.Array.from(args)); const ret = original.call(this, ...args);
return ret; return ret;
}); });
}; };
@ -257,7 +257,7 @@
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
notify("fakedAudioReadout"); notify("fakedAudioReadout");
const ret = original.apply(this, window.Array.from(args)); const ret = original.call(this, ...args);
fakeFloat32Array(magResponseOutput, window, prefs); fakeFloat32Array(magResponseOutput, window, prefs);
fakeFloat32Array(phaseResponseOutput, window, prefs); fakeFloat32Array(phaseResponseOutput, window, prefs);
return ret; return ret;

View File

@ -214,10 +214,10 @@
if (fakeCanvas !== this){ if (fakeCanvas !== this){
notify("fakedReadout"); notify("fakedReadout");
} }
return original.apply(fakeCanvas, window.Array.from(args)); return original.call(fakeCanvas, ...args);
} }
else { else {
return original.apply(this, window.Array.from(args)); return original.call(this, ...args);
} }
} }
@ -234,13 +234,13 @@
// nothing to do here // nothing to do here
} }
// if "this" is not a correct context the next line will throw an error // if "this" is not a correct context the next line will throw an error
const ret = original.apply(this, window.Array.from(args)); const ret = original.call(this, ...args);
const newImageData = getImageData(window, this).imageData; const newImageData = getImageData(window, this).imageData;
this.putImageData(randomMixImageData(window, oldImageData, newImageData), 0, 0); this.putImageData(randomMixImageData(window, oldImageData, newImageData), 0, 0);
return ret; return ret;
} }
else { else {
return original.apply(this, window.Array.from(args)); return original.call(this, ...args);
} }
} }
@ -273,9 +273,9 @@
fakeGenerator: function(checker){ fakeGenerator: function(checker){
return function(context, contextAttributes){ return function(context, contextAttributes){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {window, original} = check; const {original} = check;
canvasContextType.set(this, context); canvasContextType.set(this, context);
return original.apply(this, window.Array.from(args)); return original.call(this, ...args);
}); });
}; };
} }
@ -332,10 +332,10 @@
"2d" "2d"
); );
} }
return original.apply(context, window.Array.from(args)); return original.call(context, ...args);
} }
else { else {
return original.apply(this, window.Array.from(args)); return original.call(this, ...args);
} }
}); });
}; };
@ -350,7 +350,7 @@
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {notify, window, original} = check; const {notify, window, original} = check;
const rng = randomSupply.getValueRng(1, window); const rng = randomSupply.getValueRng(1, window);
const originalValue = original.apply(this, window.Array.from(args)); const originalValue = original.call(this, ...args);
if ((typeof originalValue) === "boolean"){ if ((typeof originalValue) === "boolean"){
notify("fakedReadout"); notify("fakedReadout");
const index = x + this.width * y; const index = x + this.width * y;
@ -372,7 +372,7 @@
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {notify, window, original} = check; const {notify, window, original} = check;
const rng = randomSupply.getValueRng(1, window); const rng = randomSupply.getValueRng(1, window);
const originalValue = original.apply(this, window.Array.from(args)); const originalValue = original.call(this, ...args);
if ((typeof originalValue) === "boolean"){ if ((typeof originalValue) === "boolean"){
notify("fakedReadout"); notify("fakedReadout");
if (x instanceof window.Path2D){ if (x instanceof window.Path2D){
@ -431,10 +431,10 @@
fakeCanvas, fakeCanvas,
this instanceof window.WebGLRenderingContext? "webgl": "webgl2" this instanceof window.WebGLRenderingContext? "webgl": "webgl2"
); );
return original.apply(context, window.Array.from(args)); return original.call(context, ...args);
} }
else { else {
return original.apply(this, window.Array.from(args)); return original.call(this, ...args);
} }
}); });
}; };
@ -449,7 +449,7 @@
return function getParameter(pname){ return function getParameter(pname){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
const originalValue = original.apply(this, window.Array.from(args)); const originalValue = original.call(this, ...args);
if (webgl.parameterChangeDefinition[pname]){ if (webgl.parameterChangeDefinition[pname]){
const definition = webgl.parameterChangeDefinition[pname]; const definition = webgl.parameterChangeDefinition[pname];
const {value, faked} = definition.fake(originalValue, window, prefs); const {value, faked} = definition.fake(originalValue, window, prefs);

View File

@ -91,7 +91,7 @@
function registerCallback(args, check){ function registerCallback(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
const originalValue = args.length? const originalValue = args.length?
original.apply(this, window.Array.from(args)): original.call(this, ...args):
original.call(this); original.call(this);
registerDOMRect(originalValue, notify, window, prefs); registerDOMRect(originalValue, notify, window, prefs);
return originalValue; return originalValue;
@ -104,7 +104,7 @@
return function getClientRects(){ return function getClientRects(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
const ret = args.length? original.apply(this, window.Array.from(args)): original.call(this); const ret = args.length? original.call(this, ...args): original.call(this);
for (let i = 0; i < ret.length; i += 1){ for (let i = 0; i < ret.length; i += 1){
registerDOMRect(ret[i], notify, window, prefs); registerDOMRect(ret[i], notify, window, prefs);
} }
@ -195,7 +195,7 @@
}); });
} }
else { else {
original.apply(this, window.Array.from(arguments)); original.call(this, ...arguments);
} }
} }
}; };

View File

@ -23,7 +23,7 @@
get length(){ get length(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
const originalLength = original.apply(this, window.Array.from(args)); const originalLength = original.call(this, ...args);
const threshold = prefs("historyLengthThreshold", window.location); const threshold = prefs("historyLengthThreshold", window.location);
if (originalLength > threshold){ if (originalLength > threshold){
notify("fakedHistoryReadout"); notify("fakedHistoryReadout");

View File

@ -23,8 +23,8 @@
const temp = { const temp = {
get [property](){ get [property](){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {notify, window, original} = check; const {notify, original} = check;
const originalValue = original.apply(this, window.Array.from(args)); const originalValue = original.call(this, ...args);
const returnValue = navigator.getNavigatorValue(property); const returnValue = navigator.getNavigatorValue(property);
if (originalValue !== returnValue){ if (originalValue !== returnValue){
notify("fakedNavigatorReadout"); notify("fakedNavigatorReadout");

View File

@ -92,7 +92,7 @@
function getFaker(dimension){ function getFaker(dimension){
return function fake(args, check){ return function fake(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
const originalValue = original.apply(this, window.Array.from(args)); const originalValue = original.call(this, ...args);
const returnValue = (typeof dimension) === "function"? const returnValue = (typeof dimension) === "function"?
dimension(window): dimension(window):
dimension? dimension?
@ -254,7 +254,7 @@
get matches(){ get matches(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
const originalValue = original.apply(this, window.Array.from(args)); const originalValue = original.call(this, ...args);
const screenSize = prefs("screenSize", window.location); const screenSize = prefs("screenSize", window.location);
if ( if (
( (

View File

@ -23,8 +23,8 @@
const temp = { const temp = {
get opener(){ get opener(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {notify, window, original} = check; const {notify, original} = check;
const originalOpener = original.apply(this, window.Array.from(args)); const originalOpener = original.call(this, ...args);
if (originalOpener !== null){ if (originalOpener !== null){
notify("fakedWindowReadout"); notify("fakedWindowReadout");
} }
@ -49,7 +49,7 @@
get name(){ get name(){
return checkerWrapper(checker, this, arguments, function(args, check){ return checkerWrapper(checker, this, arguments, function(args, check){
const {notify, window, original} = check; const {notify, window, original} = check;
const originalName = original.apply(this, window.Array.from(args)); const originalName = original.call(this, ...args);
const returnedName = windowNames.get(window) || ""; const returnedName = windowNames.get(window) || "";
if (originalName !== returnedName){ if (originalName !== returnedName){
notify("fakedWindowReadout"); notify("fakedWindowReadout");
@ -63,7 +63,7 @@
setterGenerator: function(window, original){ setterGenerator: function(window, original){
const temp = { const temp = {
set name(name){ set name(name){
original.apply(this, window.Array.from(arguments)); original.call(this, ...arguments);
windowNames.set(window, name); windowNames.set(window, name);
} }
}; };