Skip to content
Snippets Groups Projects
Commit a7ceebeb authored by Michael J. Ryan's avatar Michael J. Ryan
Browse files

Update array.js formatting

Autoformatted via prettier with settings below, this is so additional polyfill matches can be used to match formatting in future PRs for polyfills, as well as full formatting tooling for .js files.

```yaml
tabWidth: 4
useTabs: true
singleQuote: true
trailingComma: "es5"
```
parent 8eaa996b
No related branches found
No related tags found
2 merge requests!463MRC mods by Codefenix (2024-10-20),!120Update array.js formatting
......@@ -7,12 +7,14 @@
* load('array.js');
*/
if (!Array.from) {
Array.from = (function () {
var toStr = Object.prototype.toString;
var isCallable = function (fn) {
return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
return (
typeof fn === 'function' ||
toStr.call(fn) === '[object Function]'
);
};
var toInteger = function (value) {
var number = Number(value);
......@@ -36,7 +38,9 @@ if (!Array.from) {
// 3. ReturnIfAbrupt(items).
if (arrayLike == null) {
throw new TypeError('Array.from requires an array-like object - not null or undefined');
throw new TypeError(
'Array.from requires an array-like object - not null or undefined'
);
}
// 4. If mapfn is undefined, then let mapping be false.
......@@ -46,7 +50,9 @@ if (!Array.from) {
// 5. else
// 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
if (!isCallable(mapFn)) {
throw new TypeError('Array.from: when provided, the second argument must be a function');
throw new TypeError(
'Array.from: when provided, the second argument must be a function'
);
}
// 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
......@@ -70,7 +76,10 @@ if (!Array.from) {
while (k < len) {
kValue = items[k];
if (mapFn) {
A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
A[k] =
typeof T === 'undefined'
? mapFn(kValue, k)
: mapFn.call(T, kValue, k);
} else {
A[k] = kValue;
}
......@@ -81,7 +90,7 @@ if (!Array.from) {
// 20. Return A.
return A;
};
}());
})();
}
if (!Array.of) {
......@@ -106,24 +115,27 @@ if (!Array.prototype.copyWithin) {
// Steps 6-8.
var relativeTarget = target >> 0;
var to = relativeTarget < 0 ?
Math.max(len + relativeTarget, 0) :
Math.min(relativeTarget, len);
var to =
relativeTarget < 0
? Math.max(len + relativeTarget, 0)
: Math.min(relativeTarget, len);
// Steps 9-11.
var relativeStart = start >> 0;
var from = relativeStart < 0 ?
Math.max(len + relativeStart, 0) :
Math.min(relativeStart, len);
var from =
relativeStart < 0
? Math.max(len + relativeStart, 0)
: Math.min(relativeStart, len);
// Steps 12-14.
var end = arguments[2];
var relativeEnd = end === undefined ? len : end >> 0;
var final = relativeEnd < 0 ?
Math.max(len + relativeEnd, 0) :
Math.min(relativeEnd, len);
var final =
relativeEnd < 0
? Math.max(len + relativeEnd, 0)
: Math.min(relativeEnd, len);
// Step 15.
var count = Math.min(final - from, len - to);
......@@ -131,7 +143,7 @@ if (!Array.prototype.copyWithin) {
// Steps 16-17.
var direction = 1;
if (from < to && to < (from + count)) {
if (from < to && to < from + count) {
direction = -1;
from += count - 1;
to += count - 1;
......@@ -153,7 +165,7 @@ if (!Array.prototype.copyWithin) {
return O;
},
configurable: true,
writable: true
writable: true,
});
}
......@@ -161,7 +173,8 @@ if (!Array.prototype.fill) {
Object.defineProperty(Array.prototype, 'fill', {
value: function (value) {
// Steps 1-2.
if (this == null) throw new TypeError('this is null or not defined');
if (this == null)
throw new TypeError('this is null or not defined');
var O = Object(this);
......@@ -173,19 +186,20 @@ if (!Array.prototype.fill) {
var relativeStart = start >> 0;
// Step 8.
var k = relativeStart < 0 ?
Math.max(len + relativeStart, 0) :
Math.min(relativeStart, len);
var k =
relativeStart < 0
? Math.max(len + relativeStart, 0)
: Math.min(relativeStart, len);
// Steps 9-10.
var end = arguments[2];
var relativeEnd = end === undefined ?
len : end >> 0;
var relativeEnd = end === undefined ? len : end >> 0;
// Step 11.
var final = relativeEnd < 0 ?
Math.max(len + relativeEnd, 0) :
Math.min(relativeEnd, len);
var final =
relativeEnd < 0
? Math.max(len + relativeEnd, 0)
: Math.min(relativeEnd, len);
// Step 12.
while (k < final) {
......@@ -195,7 +209,7 @@ if (!Array.prototype.fill) {
// Step 13.
return O;
}
},
});
}
......@@ -240,7 +254,7 @@ if (!Array.prototype.find) {
return undefined;
},
configurable: true,
writable: true
writable: true,
});
}
......@@ -285,7 +299,7 @@ if (!Array.prototype.findIndex) {
return -1;
},
configurable: true,
writable: true
writable: true,
});
}
......@@ -294,7 +308,8 @@ if (!Array.prototype.includes) {
Object.defineProperty(Array.prototype, 'includes', {
value: function (searchElement, fromIndex) {
// 1. Let O be ? ToObject(this value).
if (this == null) throw new TypeError('"this" is null or not defined');
if (this == null)
throw new TypeError('"this" is null or not defined');
var o = Object(this);
......@@ -316,7 +331,13 @@ if (!Array.prototype.includes) {
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
function sameValueZero(x, y) {
return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
return (
x === y ||
(typeof x === 'number' &&
typeof y === 'number' &&
isNaN(x) &&
isNaN(y))
);
}
// 7. Repeat, while k < len
......@@ -330,6 +351,6 @@ if (!Array.prototype.includes) {
// 8. Return false
return false;
}
},
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment