Skip to content

Commit

Permalink
minor Array.from fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Sep 18, 2021
1 parent 7377472 commit 9beeaad
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/core-js/internals/array-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ var getIteratorMethod = require('../internals/get-iterator-method');
// https://tc39.es/ecma262/#sec-array.from
module.exports = function from(arrayLike /* , mapfn = undefined, thisArg = undefined */) {
var O = toObject(arrayLike);
var C = isConstructor(this) ? this : Array;
var IS_CONSTRUCTOR = isConstructor(this);
var argumentsLength = arguments.length;
var mapfn = argumentsLength > 1 ? arguments[1] : undefined;
var mapping = mapfn !== undefined;
if (mapping) mapfn = bind(mapfn, argumentsLength > 2 ? arguments[2] : undefined, 2);
var iteratorMethod = getIteratorMethod(O);
var index = 0;
var length, result, step, iterator, next, value;
if (mapping) mapfn = bind(mapfn, argumentsLength > 2 ? arguments[2] : undefined, 2);
// if the target is not iterable or it's an array with the default iterator - use a simple case
if (iteratorMethod && !(C == Array && isArrayIteratorMethod(iteratorMethod))) {
if (iteratorMethod && !(this == Array && isArrayIteratorMethod(iteratorMethod))) {
iterator = getIterator(O, iteratorMethod);
next = iterator.next;
result = new C();
result = IS_CONSTRUCTOR ? new this() : [];
for (;!(step = next.call(iterator)).done; index++) {
value = mapping ? callWithSafeIterationClosing(iterator, mapfn, [step.value, index], true) : step.value;
createProperty(result, index, value);
}
} else {
length = toLength(O.length);
result = new C(length);
result = IS_CONSTRUCTOR ? new this(length) : Array(length);
for (;length > index; index++) {
value = mapping ? mapfn(O[index], index) : O[index];
createProperty(result, index, value);
Expand Down

0 comments on commit 9beeaad

Please sign in to comment.