Polyfill for Arrays should be declared with Object.defineProperty

To not be enumerable
This commit is contained in:
Ilya Goncharov
2020-05-29 16:58:41 +03:00
committed by Ilya Goncharov
parent 83e17cbf09
commit 9431fc4693
+38 -33
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -251,45 +251,48 @@ if (typeof ArrayBuffer.isView === "undefined") {
if (typeof Array.prototype.fill === "undefined") { if (typeof Array.prototype.fill === "undefined") {
// Polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill#Polyfill // Polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill#Polyfill
Array.prototype.fill = function() { Object.defineProperty(Array.prototype, 'fill', {
// Steps 1-2. value: function (value) {
if (this == null) {
throw new TypeError('this is null or not defined');
}
var O = Object(this); // Steps 1-2.
if (this == null) {
throw new TypeError('this is null or not defined');
}
// Steps 3-5. var O = Object(this);
var len = O.length >>> 0;
// Steps 6-7. // Steps 3-5.
var start = arguments[1]; var len = O.length >>> 0;
var relativeStart = start >> 0;
// Step 8. // Steps 6-7.
var k = relativeStart < 0 ? var start = arguments[1];
Math.max(len + relativeStart, 0) : var relativeStart = start >> 0;
Math.min(relativeStart, len);
// Steps 9-10. // Step 8.
var end = arguments[2]; var k = relativeStart < 0 ?
var relativeEnd = end === undefined ? Math.max(len + relativeStart, 0) :
len : end >> 0; Math.min(relativeStart, len);
// Step 11. // Steps 9-10.
var final = relativeEnd < 0 ? var end = arguments[2];
Math.max(len + relativeEnd, 0) : var relativeEnd = end === undefined ?
Math.min(relativeEnd, len); len : end >> 0;
// Step 12. // Step 11.
while (k < final) { var finalValue = relativeEnd < 0 ?
O[k] = value; Math.max(len + relativeEnd, 0) :
k++; Math.min(relativeEnd, len);
}
// Step 13. // Step 12.
return O; while (k < finalValue) {
}; O[k] = value;
k++;
}
// Step 13.
return O;
}
});
} }
(function() { (function() {
@@ -310,7 +313,9 @@ if (typeof Array.prototype.fill === "undefined") {
for (var i = 0; i < arrays.length; ++i) { for (var i = 0; i < arrays.length; ++i) {
var TypedArray = arrays[i]; var TypedArray = arrays[i];
if (typeof TypedArray.prototype.fill === "undefined") { if (typeof TypedArray.prototype.fill === "undefined") {
TypedArray.prototype.fill = Array.prototype.fill; Object.defineProperty(TypedArray.prototype, 'fill', {
value: Array.prototype.fill
});
} }
if (typeof TypedArray.prototype.slice === "undefined") { if (typeof TypedArray.prototype.slice === "undefined") {
Object.defineProperty(TypedArray.prototype, 'slice', { Object.defineProperty(TypedArray.prototype, 'slice', {