Quellcode durchsuchen

remove .call usage

Gildas vor 5 Jahren
Ursprung
Commit
4be877ca1e

+ 2 - 3
extension/lib/single-file/fetch/content/content-fetch.js

@@ -21,7 +21,7 @@
  *   Source.
  */
 
-/* global browser, window, CustomEvent */
+/* global browser, window, CustomEvent, setTimeout */
 
 this.singlefile.extension.lib.fetch.content.resources = this.singlefile.extension.lib.fetch.content.resources || (() => {
 
@@ -32,7 +32,6 @@ this.singlefile.extension.lib.fetch.content.resources = this.singlefile.extensio
 	const dispatchEvent = event => window.dispatchEvent(event);
 	const removeEventListener = (type, listener, options) => window.removeEventListener(type, listener, options);
 	const fetch = window.fetch;
-	const setTimeout = window.setTimeout;
 
 	browser.runtime.onMessage.addListener(message => {
 		if (message.method == "singlefile.fetchFrame" && window.frameId && window.frameId == message.frameId) {
@@ -47,7 +46,7 @@ this.singlefile.extension.lib.fetch.content.resources = this.singlefile.extensio
 				response = await Promise.race(
 					[
 						hostFetch(message.url),
-						new Promise((resolve, reject) => setTimeout.call(window, () => reject(), HOST_FETCH_MAX_DELAY))
+						new Promise((resolve, reject) => setTimeout(() => reject(), HOST_FETCH_MAX_DELAY))
 					]);
 			}
 			return {

+ 1 - 1
extension/lib/woleet/woleet.js

@@ -26,7 +26,7 @@
 this.woleet = this.woleet || (() => {
 
 	const urlService = "https://api.woleet.io/v1/anchor";
-	const apiKey = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhYzZmZTMzMi0wODNjLTRjZmMtYmYxNC0xNWU5MTJmMWY4OWIiLCJpYXQiOjE1NzYxNzQzNDV9.n31j9ctJj7R1Vjwyc5yd1d6Cmg0NDnpwSaLWsqtZJQA";
+	const apiKey = "__WOLEET_API_KEY__";
 
 	return {
 		anchor

+ 2 - 3
lib/single-file/modules/css-fonts-alt-minifier.js

@@ -21,14 +21,13 @@
  *   Source.
  */
 
-/* global window */
+/* global window, setTimeout */
 
 this.singlefile.lib.modules.fontsAltMinifier = this.singlefile.lib.modules.fontsAltMinifier || (() => {
 
 	const singlefile = this.singlefile;
 
 	const FontFace = window.FontFace;
-	const setTimeout = window.setTimeout;
 
 	const REGEXP_URL_SIMPLE_QUOTES_FN = /url\s*\(\s*'(.*?)'\s*\)/i;
 	const REGEXP_URL_DOUBLE_QUOTES_FN = /url\s*\(\s*"(.*?)"\s*\)/i;
@@ -231,7 +230,7 @@ this.singlefile.lib.modules.fontsAltMinifier = this.singlefile.lib.modules.fonts
 										await Promise.race(
 											[
 												fontFace.load().then(() => fontFace.loaded).then(() => source.valid = true),
-												new Promise(resolve => setTimeout.call(window, () => { source.valid = true; resolve(); }, FONT_MAX_LOAD_DELAY))
+												new Promise(resolve => setTimeout(() => { source.valid = true; resolve(); }, FONT_MAX_LOAD_DELAY))
 											]);
 									} catch (error) {
 										// ignored

+ 2 - 4
lib/single-file/modules/css-fonts-minifier.js

@@ -27,8 +27,6 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
 
 	const singlefile = this.singlefile;
 
-	const getComputedStyle = window.getComputedStyle;
-
 	const REGEXP_COMMA = /\s*,\s*/;
 	const REGEXP_DASH = /-/;
 	const REGEXP_QUESTION_MARK = /\?/g;
@@ -59,11 +57,11 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
 			});
 			workStyleElement.remove();
 			docContent += doc.body.innerText;
-			if (getComputedStyle && options.doc) {
+			if (window.getComputedStyle && options.doc) {
 				fontsInfo.used = fontsInfo.used.map(fontNames => fontNames.map(familyName => {
 					const matchedVar = familyName.match(/^var\((--.*)\)$/);
 					if (matchedVar && matchedVar[1]) {
-						const computedFamilyName = getComputedStyle.call(window, options.doc.body).getPropertyValue(matchedVar[1]);
+						const computedFamilyName = window.getComputedStyle(options.doc.body).getPropertyValue(matchedVar[1]);
 						return (computedFamilyName && computedFamilyName.split(",").map(name => singlefile.lib.helper.normalizeFontFamily(name))) || familyName;
 					}
 					return familyName;

+ 4 - 6
lib/single-file/processors/frame-tree/content/content-frame-tree.js

@@ -21,7 +21,7 @@
  *   Source.
  */
 
-/* global window */
+/* global window, setTimeout, clearTimeout */
 
 this.singlefile.lib.processors.frameTree.content.frames = this.singlefile.lib.processors.frameTree.content.frames || (() => {
 
@@ -46,8 +46,6 @@ this.singlefile.lib.processors.frameTree.content.frames = this.singlefile.lib.pr
 	const top = window.top;
 	const MessageChannel = window.MessageChannel;
 	const document = window.document;
-	const setTimeout = window.setTimeout;
-	const clearTimeout = window.clearTimeout;
 
 	const sessions = new Map();
 	let windowId;
@@ -235,7 +233,7 @@ this.singlefile.lib.processors.frameTree.content.frames = this.singlefile.lib.pr
 			} catch (error) {
 				// ignored
 			}
-			requestTimeouts[windowId] = setTimeout.call(window, () => sendInitResponse({ frames: [{ windowId, processed: true }], sessionId }), TIMEOUT_INIT_REQUEST_MESSAGE);
+			requestTimeouts[windowId] = setTimeout(() => sendInitResponse({ frames: [{ windowId, processed: true }], sessionId }), TIMEOUT_INIT_REQUEST_MESSAGE);
 		});
 		delete doc.documentElement.dataset.requestedFrameId;
 	}
@@ -271,7 +269,7 @@ this.singlefile.lib.processors.frameTree.content.frames = this.singlefile.lib.pr
 		if (session && session[type]) {
 			const timeout = session[type][windowId];
 			if (timeout) {
-				clearTimeout.call(window, timeout);
+				clearTimeout(timeout);
 				delete session[type][windowId];
 			}
 		}
@@ -280,7 +278,7 @@ this.singlefile.lib.processors.frameTree.content.frames = this.singlefile.lib.pr
 	function createFrameResponseTimeout(sessionId, windowId) {
 		const session = sessions.get(sessionId);
 		if (session && session.responseTimeouts) {
-			session.responseTimeouts[windowId] = setTimeout.call(window, () => sendInitResponse({ frames: [{ windowId: windowId, processed: true }], sessionId: sessionId }), TIMEOUT_INIT_RESPONSE_MESSAGE);
+			session.responseTimeouts[windowId] = setTimeout(() => sendInitResponse({ frames: [{ windowId: windowId, processed: true }], sessionId: sessionId }), TIMEOUT_INIT_RESPONSE_MESSAGE);
 		}
 	}
 

+ 3 - 3
lib/single-file/processors/hooks/content/content-hooks-frames-web.js

@@ -58,7 +58,7 @@
 	const FileReader = window.FileReader;
 	const Blob = window.Blob;
 	const console = window.console;
-	const warn = (console && console.warn) || (() => { });
+	const warn = (console && console.warn && ((...args) => console.warn(...args))) || (() => { });
 
 	const observers = new Map();
 	const observedElements = new Map();
@@ -269,7 +269,7 @@
 		let warningFontFaceDisplayed;
 		window.FontFace = function () {
 			if (!warningFontFaceDisplayed) {
-				warn.call(console, "SingleFile is hooking the FontFace constructor to get font URLs."); // eslint-disable-line no-console
+				warn("SingleFile is hooking the FontFace constructor to get font URLs."); // eslint-disable-line no-console
 				warningFontFaceDisplayed = true;
 			}
 			const detail = {};
@@ -303,7 +303,7 @@
 		let warningIntersectionObserverDisplayed;
 		window.IntersectionObserver = function () {
 			if (!warningIntersectionObserverDisplayed) {
-				warn.call(console, "SingleFile is hooking the IntersectionObserver API to detect and load deferred images."); // eslint-disable-line no-console
+				warn("SingleFile is hooking the IntersectionObserver API to detect and load deferred images."); // eslint-disable-line no-console
 				warningIntersectionObserverDisplayed = true;
 			}
 			const intersectionObserver = new IntersectionObserver(...arguments);

+ 2 - 2
lib/single-file/processors/hooks/content/content-hooks-frames.js

@@ -106,7 +106,7 @@ this.singlefile.lib.processors.hooks.content.frames = this.singlefile.lib.proces
 
 	function injectedScript() {
 		const console = window.console;
-		const warn = (console && console.warn) || (() => { });
+		const warn = (console && console.warn && ((...args) => console.warn(...args))) || (() => { });
 		const NEW_FONT_FACE_EVENT = "single-file-new-font-face";
 		const FONT_STYLE_PROPERTIES = {
 			family: "font-family",
@@ -123,7 +123,7 @@ this.singlefile.lib.processors.hooks.content.frames = this.singlefile.lib.proces
 			let warningFontFaceDisplayed;
 			window.FontFace = function () {
 				if (!warningFontFaceDisplayed) {
-					warn.call(console, "SingleFile is hooking the FontFace constructor to get font URLs."); // eslint-disable-line no-console
+					warn("SingleFile is hooking the FontFace constructor to get font URLs."); // eslint-disable-line no-console
 					warningFontFaceDisplayed = true;
 				}
 				const detail = {};

+ 3 - 5
lib/single-file/processors/lazy/content/content-lazy-loader.js

@@ -21,7 +21,7 @@
  *   Source.
  */
 
-/* global window */
+/* global window, setTimeout, clearTimeout */
 
 this.singlefile.lib.processors.lazy.content.loader = this.singlefile.lib.processors.lazy.content.loader || (() => {
 
@@ -32,8 +32,6 @@ this.singlefile.lib.processors.lazy.content.loader = this.singlefile.lib.process
 	const browser = this.browser;
 	const document = window.document;
 	const MutationObserver = window.MutationObserver;
-	const setTimeout = window.setTimeout;
-	const clearTimeout = window.clearTimeout;
 	const addEventListener = (type, listener, options) => window.addEventListener(type, listener, options);
 	const removeEventListener = (type, listener, options) => window.removeEventListener(type, listener, options);
 
@@ -163,7 +161,7 @@ this.singlefile.lib.processors.lazy.content.loader = this.singlefile.lib.process
 			browser.runtime.onMessage.addListener(timeoutCallback);
 			return timeoutId;
 		} else {
-			return setTimeout.call(window, callback, delay);
+			return setTimeout(callback, delay);
 		}
 	}
 
@@ -171,7 +169,7 @@ this.singlefile.lib.processors.lazy.content.loader = this.singlefile.lib.process
 		if (browser && browser.runtime && browser.runtime.sendMessage) {
 			await browser.runtime.sendMessage({ method: "singlefile.lazyTimeout.clearTimeout", id: timeoutId });
 		} else {
-			return clearTimeout.call(window, timeoutId);
+			return clearTimeout(timeoutId);
 		}
 	}