Explorar o código

Avoid using Array.from with Map/Iterator objects (fix #351)

Former-commit-id: 0ac805f4e8657d00221bd3050e8169d4b10a143e
Gildas %!s(int64=6) %!d(string=hai) anos
pai
achega
cf57ff9cf1

+ 1 - 1
extension/lib/single-file/fetch/content/content-fetch.js

@@ -42,7 +42,7 @@ this.singlefile.extension.lib.fetch.content.resources = this.singlefile.extensio
 			}
 			return {
 				status: response.status,
-				headers: Array.from(response.headers),
+				headers: [...response.headers],
 				array: Array.from(new Uint8Array(await response.arrayBuffer()))
 			};
 		} catch (error) {

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

@@ -140,7 +140,7 @@
 		dispatchEvent.call(window, new UIEvent("resize"));
 		dispatchEvent.call(window, new UIEvent("scroll"));
 		const docBoundingRect = scrollingElement.getBoundingClientRect();
-		Array.from(observers).forEach(([intersectionObserver, observer]) => {
+		[...observers].forEach(([intersectionObserver, observer]) => {
 			const rootBoundingRect = observer.options && observer.options.root && observer.options.root.getBoundingClientRect();
 			const targetElements = observedElements.get(intersectionObserver);
 			if (targetElements) {
@@ -155,7 +155,7 @@
 			}
 		});
 		if (pendingRequestAnimationFrameCalls.size) {
-			Array.from(pendingRequestAnimationFrameCalls).forEach(([id, callback]) => {
+			[...pendingRequestAnimationFrameCalls].forEach(([id, callback]) => {
 				cancelAnimationFrame(id);
 				callback();
 			});

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

@@ -57,7 +57,7 @@
 		let detail;
 		try {
 			const response = await fetch(url, { cache: "force-cache" });
-			detail = { url, response: await response.arrayBuffer(), headers: Array.from(response.headers), status: response.status };
+			detail = { url, response: await response.arrayBuffer(), headers: [...response.headers], status: response.status };
 		} catch (error) {
 			detail = { url, error: error.toString() };
 		}

+ 2 - 2
lib/single-file/single-file-core.js

@@ -1098,13 +1098,13 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 		}
 
 		async processStylesheets() {
-			await Promise.all(Array.from(this.stylesheets).map(([, stylesheetInfo]) =>
+			await Promise.all([...this.stylesheets].map(([, stylesheetInfo]) =>
 				ProcessorHelper.processStylesheet(stylesheetInfo.stylesheet.children, this.baseURI, this.options, this.cssVariables, this.batchRequest)
 			));
 		}
 
 		async processStyleAttributes() {
-			return Promise.all(Array.from(this.styles).map(([, declarationList]) =>
+			return Promise.all([...this.styles].map(([, declarationList]) =>
 				ProcessorHelper.processStyle(declarationList.children.toArray(), this.baseURI, this.options, this.cssVariables, this.batchRequest)
 			));
 		}