From 4601dd25aff492cfaeb6478fb2f76d1b69a70803 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Sun, 29 Dec 2019 23:40:39 +0100 Subject: [PATCH] Allow cross origin arguments and remove apply(..., Array.from) Fixes #415 --- lib/extension.js | 3 ++- lib/frame.js | 2 +- lib/iframeProtection.js | 4 ++-- lib/modifiedAPIFunctions.js | 2 +- lib/modifiedAudioAPI.js | 14 +++++++------- lib/modifiedCanvasAPI.js | 26 +++++++++++++------------- lib/modifiedDOMRectAPI.js | 6 +++--- lib/modifiedHistoryAPI.js | 2 +- lib/modifiedNavigatorAPI.js | 4 ++-- lib/modifiedScreenAPI.js | 4 ++-- lib/modifiedWindowAPI.js | 8 ++++---- 11 files changed, 38 insertions(+), 37 deletions(-) diff --git a/lib/extension.js b/lib/extension.js index d9570e8..b023bd4 100644 --- a/lib/extension.js +++ b/lib/extension.js @@ -49,13 +49,14 @@ }; scope.exportFunctionWithName = function exportFunctionWithName(func, context, name){ - const exportedTry = exportFunction(func, context); + const exportedTry = exportFunction(func, context, {allowCrossOriginArguments: true}); if (exportedTry.name === name){ return exportedTry; } else { const wrappedContext = scope.getWrapped(context); const options = { + allowCrossOriginArguments: true, defineAs: name }; const oldDescriptor = Object.getOwnPropertyDescriptor(wrappedContext, name); diff --git a/lib/frame.js b/lib/frame.js index f4b6443..b7ccb72 100644 --- a/lib/frame.js +++ b/lib/frame.js @@ -174,7 +174,7 @@ } else { return arguments.length > 1? - originalMatchMedia.apply(this, wrappedWindow.Array.from(arguments)): + originalMatchMedia.call(this, ...arguments): originalMatchMedia.call(this, query); } }, window, originalMatchMedia.name); diff --git a/lib/iframeProtection.js b/lib/iframeProtection.js index eb20215..10d98d9 100644 --- a/lib/iframeProtection.js +++ b/lib/iframeProtection.js @@ -133,7 +133,7 @@ const original = descriptor.value; changeProperty(object, method, "value", function method(){ const value = arguments.length? - original.apply(this, window.Array.from(arguments)): + original.call(this, ...arguments): original.call(this); allCallback(); return value; @@ -272,7 +272,7 @@ wrappedWindow, "open", "value", function open(){ const newWindow = arguments.length? - windowOpen.apply(this, window.Array.from(arguments)): + windowOpen.call(this, ...arguments): windowOpen.call(this); if (newWindow){ // if we use windowOpen from the normal window we see some SOP errors diff --git a/lib/modifiedAPIFunctions.js b/lib/modifiedAPIFunctions.js index 7940c75..3565440 100644 --- a/lib/modifiedAPIFunctions.js +++ b/lib/modifiedAPIFunctions.js @@ -17,7 +17,7 @@ if (check.allow){ if (check.allow === true){ return args.length? - check.original.apply(object, check.window.Array.from(args)): + check.original.call(object, ...args): check.original.call(object); } return callback.call(object, args, check); diff --git a/lib/modifiedAudioAPI.js b/lib/modifiedAudioAPI.js index 21ebea7..1652f46 100644 --- a/lib/modifiedAudioAPI.js +++ b/lib/modifiedAudioAPI.js @@ -166,7 +166,7 @@ return checkerWrapper(checker, this, arguments, function(args, check){ const {prefs, notify, window, original} = check; notify("fakedAudioReadout"); - const ret = original.apply(this, window.Array.from(args)); + const ret = original.call(this, ...args); fakeFloat32Array(array, window, prefs); return ret; }); @@ -180,7 +180,7 @@ return checkerWrapper(checker, this, arguments, function(args, check){ const {prefs, notify, window, original} = check; notify("fakedAudioReadout"); - const ret = original.apply(this, window.Array.from(args)); + const ret = original.call(this, ...args); fakeUint8Array(array, window, prefs); return ret; }); @@ -194,7 +194,7 @@ return checkerWrapper(checker, this, arguments, function(args, check){ const {prefs, notify, window, original} = check; notify("fakedAudioReadout"); - const ret = original.apply(this, window.Array.from(args)); + const ret = original.call(this, ...args); fakeFloat32Array(array, window, prefs); return ret; }); @@ -208,7 +208,7 @@ return checkerWrapper(checker, this, arguments, function(args, check){ const {prefs, notify, window, original} = check; notify("fakedAudioReadout"); - const ret = original.apply(this, window.Array.from(args)); + const ret = original.call(this, ...args); fakeUint8Array(array, window, prefs); return ret; }); @@ -221,7 +221,7 @@ return function getChannelData(channel){ return checkerWrapper(checker, this, arguments, function(args, 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)){ notify("fakedAudioReadout"); fakeFloat32Array(ret, window, prefs); @@ -244,7 +244,7 @@ fakeFloat32Array(channelData, window, prefs); getChannelDataAlreadyFakedArrays.set(channelData, true); } - const ret = original.apply(this, window.Array.from(args)); + const ret = original.call(this, ...args); return ret; }); }; @@ -257,7 +257,7 @@ return checkerWrapper(checker, this, arguments, function(args, check){ const {prefs, notify, window, original} = check; notify("fakedAudioReadout"); - const ret = original.apply(this, window.Array.from(args)); + const ret = original.call(this, ...args); fakeFloat32Array(magResponseOutput, window, prefs); fakeFloat32Array(phaseResponseOutput, window, prefs); return ret; diff --git a/lib/modifiedCanvasAPI.js b/lib/modifiedCanvasAPI.js index 252f8fc..b8c59e2 100644 --- a/lib/modifiedCanvasAPI.js +++ b/lib/modifiedCanvasAPI.js @@ -214,10 +214,10 @@ if (fakeCanvas !== this){ notify("fakedReadout"); } - return original.apply(fakeCanvas, window.Array.from(args)); + return original.call(fakeCanvas, ...args); } else { - return original.apply(this, window.Array.from(args)); + return original.call(this, ...args); } } @@ -234,13 +234,13 @@ // nothing to do here } // 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; this.putImageData(randomMixImageData(window, oldImageData, newImageData), 0, 0); return ret; } else { - return original.apply(this, window.Array.from(args)); + return original.call(this, ...args); } } @@ -273,9 +273,9 @@ fakeGenerator: function(checker){ return function(context, contextAttributes){ return checkerWrapper(checker, this, arguments, function(args, check){ - const {window, original} = check; + const {original} = check; canvasContextType.set(this, context); - return original.apply(this, window.Array.from(args)); + return original.call(this, ...args); }); }; } @@ -332,10 +332,10 @@ "2d" ); } - return original.apply(context, window.Array.from(args)); + return original.call(context, ...args); } 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){ const {notify, window, original} = check; 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"){ notify("fakedReadout"); const index = x + this.width * y; @@ -372,7 +372,7 @@ return checkerWrapper(checker, this, arguments, function(args, check){ const {notify, window, original} = check; 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"){ notify("fakedReadout"); if (x instanceof window.Path2D){ @@ -431,10 +431,10 @@ fakeCanvas, this instanceof window.WebGLRenderingContext? "webgl": "webgl2" ); - return original.apply(context, window.Array.from(args)); + return original.call(context, ...args); } else { - return original.apply(this, window.Array.from(args)); + return original.call(this, ...args); } }); }; @@ -449,7 +449,7 @@ return function getParameter(pname){ return checkerWrapper(checker, this, arguments, function(args, 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]){ const definition = webgl.parameterChangeDefinition[pname]; const {value, faked} = definition.fake(originalValue, window, prefs); diff --git a/lib/modifiedDOMRectAPI.js b/lib/modifiedDOMRectAPI.js index 4e929a6..44601a4 100644 --- a/lib/modifiedDOMRectAPI.js +++ b/lib/modifiedDOMRectAPI.js @@ -91,7 +91,7 @@ function registerCallback(args, check){ const {prefs, notify, window, original} = check; const originalValue = args.length? - original.apply(this, window.Array.from(args)): + original.call(this, ...args): original.call(this); registerDOMRect(originalValue, notify, window, prefs); return originalValue; @@ -104,7 +104,7 @@ return function getClientRects(){ return checkerWrapper(checker, this, arguments, function(args, 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){ registerDOMRect(ret[i], notify, window, prefs); } @@ -195,7 +195,7 @@ }); } else { - original.apply(this, window.Array.from(arguments)); + original.call(this, ...arguments); } } }; diff --git a/lib/modifiedHistoryAPI.js b/lib/modifiedHistoryAPI.js index 0ab34b9..9b4edef 100644 --- a/lib/modifiedHistoryAPI.js +++ b/lib/modifiedHistoryAPI.js @@ -23,7 +23,7 @@ get length(){ return checkerWrapper(checker, this, arguments, function(args, 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); if (originalLength > threshold){ notify("fakedHistoryReadout"); diff --git a/lib/modifiedNavigatorAPI.js b/lib/modifiedNavigatorAPI.js index f35e5cc..c395b51 100644 --- a/lib/modifiedNavigatorAPI.js +++ b/lib/modifiedNavigatorAPI.js @@ -23,8 +23,8 @@ const temp = { get [property](){ return checkerWrapper(checker, this, arguments, function(args, check){ - const {notify, window, original} = check; - const originalValue = original.apply(this, window.Array.from(args)); + const {notify, original} = check; + const originalValue = original.call(this, ...args); const returnValue = navigator.getNavigatorValue(property); if (originalValue !== returnValue){ notify("fakedNavigatorReadout"); diff --git a/lib/modifiedScreenAPI.js b/lib/modifiedScreenAPI.js index 19e924c..5ea6349 100644 --- a/lib/modifiedScreenAPI.js +++ b/lib/modifiedScreenAPI.js @@ -92,7 +92,7 @@ function getFaker(dimension){ return function fake(args, 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"? dimension(window): dimension? @@ -254,7 +254,7 @@ get matches(){ return checkerWrapper(checker, this, arguments, function(args, 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); if ( ( diff --git a/lib/modifiedWindowAPI.js b/lib/modifiedWindowAPI.js index 532abbd..95eeec0 100644 --- a/lib/modifiedWindowAPI.js +++ b/lib/modifiedWindowAPI.js @@ -23,8 +23,8 @@ const temp = { get opener(){ return checkerWrapper(checker, this, arguments, function(args, check){ - const {notify, window, original} = check; - const originalOpener = original.apply(this, window.Array.from(args)); + const {notify, original} = check; + const originalOpener = original.call(this, ...args); if (originalOpener !== null){ notify("fakedWindowReadout"); } @@ -49,7 +49,7 @@ get name(){ return checkerWrapper(checker, this, arguments, function(args, 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) || ""; if (originalName !== returnedName){ notify("fakedWindowReadout"); @@ -63,7 +63,7 @@ setterGenerator: function(window, original){ const temp = { set name(name){ - original.apply(this, window.Array.from(arguments)); + original.call(this, ...arguments); windowNames.set(window, name); } };