FIX: adds values/entries/NodeList.forEach/before polyfills for iOS 9.3 (#9401)

FIX: adds values/entries/NodeList.forEach/before polyfills for iOS 9.3 (#9401)

diff --git a/app/assets/javascripts/polyfills.js b/app/assets/javascripts/polyfills.js
index 0129823..358a213 100644
--- a/app/assets/javascripts/polyfills.js
+++ b/app/assets/javascripts/polyfills.js
@@ -49,4 +49,69 @@ if (!String.prototype.padEnd) {
   };
 }
 
+// Needed for iOS 9.3
+// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
+if (!Object.entries) {
+  Object.entries = function(obj) {
+    var ownProps = Object.keys(obj),
+      i = ownProps.length,
+      resArray = new Array(i); // preallocate the Array
+    while (i--) resArray[i] = [ownProps[i], obj[ownProps[i]]];
+
+    return resArray;
+  };
+}
+
+// Needed for iOS 9.3
+// adapted from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
+if (!Object.values) {
+  Object.values = function(obj) {
+    var ownProps = Object.keys(obj),
+      i = ownProps.length,
+      resArray = new Array(i); // preallocate the Array
+    while (i--) resArray[i] = obj[ownProps[i]];
+
+    return resArray;
+  };
+}
+
+// Needed for iOS 9.3
+// https://developer.mozilla.org/fr/docs/Web/API/NodeList/forEach
+if (window.NodeList && !NodeList.prototype.forEach) {
+  NodeList.prototype.forEach = function(callback, thisArg) {
+    thisArg = thisArg || window;
+    for (var i = 0; i < this.length; i++) {
+      callback.call(thisArg, this[i], i, this);
+    }
+  };
+}
+
+// Needed for iOS 9.3
+// from: https://github.com/jserz/js_piece/blob/master/DOM/ChildNode/before()/before().md
+(function(arr) {
+  arr.forEach(function(item) {
+    if (item.hasOwnProperty("before")) {
+      return;
+    }
+    Object.defineProperty(item, "before", {
+      configurable: true,
+      enumerable: true,
+      writable: true,
+      value: function before() {
+        var argArr = Array.prototype.slice.call(arguments),
+          docFrag = document.createDocumentFragment();
+
+        argArr.forEach(function(argItem) {
+          var isNode = argItem instanceof Node;
+          docFrag.appendChild(
+            isNode ? argItem : document.createTextNode(String(argItem))
+          );
+        });
+
+        this.parentNode.insertBefore(docFrag, this);
+      }
+    });
+  });
+})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);
+
 /* eslint-enable */

GitHub sha: 3e10d413

This commit appears in #9401 which was merged by jjaffeux.