From 5fae26480217e50a13bdbad67beaf574395fa591 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 23 Dec 2024 11:35:23 +0200 Subject: [PATCH] web/polyfill: make toArray work on map iterators --- web/src/util/polyfill.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/web/src/util/polyfill.js b/web/src/util/polyfill.js index c98c5d9..d123cde 100644 --- a/web/src/util/polyfill.js +++ b/web/src/util/polyfill.js @@ -15,7 +15,8 @@ // along with this program. If not, see . if (!window.Iterator?.prototype.map) { - ;(new Map([])).keys().__proto__.map = function(callbackFn) { + const iterProto = (new Map([])).keys().__proto__ + iterProto.map = function(callbackFn) { const output = [] let i = 0 for (const item of this) { @@ -24,7 +25,7 @@ if (!window.Iterator?.prototype.map) { } return output } - ;(new Map([])).keys().__proto__.filter = function(callbackFn) { + iterProto.filter = function(callbackFn) { const output = [] let i = 0 for (const item of this) { @@ -35,6 +36,10 @@ if (!window.Iterator?.prototype.map) { } return output } + const identity = x => x + iterProto.toArray = function() { + return this.map(identity) + } Array.prototype.toArray = function() { return this }