From b6235a8d23aa8b3b322d2609e9a035748ec518ec Mon Sep 17 00:00:00 2001 From: josdejong Date: Tue, 23 Jun 2020 21:22:21 +0200 Subject: [PATCH] Fix #1027: create IE11 Array polyfills `find` and `findIndex` in such a way that they are not iterable --- HISTORY.md | 2 ++ src/js/polyfills.js | 32 ++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index d567753..5cb6800 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -7,6 +7,8 @@ https://github.com/josdejong/jsoneditor - Fixed broken link to the Ace editor website (https://ace.c9.io/). Thanks @p3x-robot. +- Fix #1027: create IE11 Array polyfills `find` and `findIndex` in such a way + that they are not iterable. ## 2020-05-24, version 9.0.0 diff --git a/src/js/polyfills.js b/src/js/polyfills.js index 0c59ac2..8c42bd1 100644 --- a/src/js/polyfills.js +++ b/src/js/polyfills.js @@ -25,24 +25,32 @@ if (typeof Element !== 'undefined') { // simple polyfill for Array.findIndex if (!Array.prototype.findIndex) { // eslint-disable-next-line no-extend-native - Array.prototype.findIndex = function (predicate) { - for (let i = 0; i < this.length; i++) { - const element = this[i] - if (predicate.call(this, element, i, this)) { - return i + Object.defineProperty(Array.prototype, 'findIndex', { + value: function (predicate) { + for (let i = 0; i < this.length; i++) { + const element = this[i] + if (predicate.call(this, element, i, this)) { + return i + } } - } - return -1 - } + return -1 + }, + configurable: true, + writable: true + }) } // Polyfill for Array.find if (!Array.prototype.find) { // eslint-disable-next-line no-extend-native - Array.prototype.find = function (predicate) { - const i = this.findIndex(predicate) - return this[i] - } + Object.defineProperty(Array.prototype, 'find', { + value: function (predicate) { + const i = this.findIndex(predicate) + return this[i] + }, + configurable: true, + writable: true + }) } // Polyfill for String.trim