forked from Mirrors/gomuks
web/polyfill: make toArray work on map iterators
This commit is contained in:
parent
277732efd9
commit
5fae264802
1 changed files with 7 additions and 2 deletions
|
@ -15,7 +15,8 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
if (!window.Iterator?.prototype.map) {
|
if (!window.Iterator?.prototype.map) {
|
||||||
;(new Map([])).keys().__proto__.map = function(callbackFn) {
|
const iterProto = (new Map([])).keys().__proto__
|
||||||
|
iterProto.map = function(callbackFn) {
|
||||||
const output = []
|
const output = []
|
||||||
let i = 0
|
let i = 0
|
||||||
for (const item of this) {
|
for (const item of this) {
|
||||||
|
@ -24,7 +25,7 @@ if (!window.Iterator?.prototype.map) {
|
||||||
}
|
}
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
;(new Map([])).keys().__proto__.filter = function(callbackFn) {
|
iterProto.filter = function(callbackFn) {
|
||||||
const output = []
|
const output = []
|
||||||
let i = 0
|
let i = 0
|
||||||
for (const item of this) {
|
for (const item of this) {
|
||||||
|
@ -35,6 +36,10 @@ if (!window.Iterator?.prototype.map) {
|
||||||
}
|
}
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
const identity = x => x
|
||||||
|
iterProto.toArray = function() {
|
||||||
|
return this.map(identity)
|
||||||
|
}
|
||||||
Array.prototype.toArray = function() {
|
Array.prototype.toArray = function() {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue