Skip to content

Commit

Permalink
use toObject at the first place for the expected errors order
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Dec 26, 2023
1 parent da53d6d commit 8d46fe0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/core-js/internals/collection-from.js
Expand Up @@ -2,17 +2,19 @@
// https://tc39.github.io/proposal-setmap-offrom/
var bind = require('../internals/function-bind-context');
var anObject = require('../internals/an-object');
var toObject = require('../internals/to-object');
var iterate = require('../internals/iterate');

module.exports = function (C, adder, ENTRY) {
return function from(source /* , mapFn, thisArg */) {
var O = toObject(source);
var length = arguments.length;
var mapFn = length > 1 ? arguments[1] : undefined;
var mapping = mapFn !== undefined;
var boundFunction = mapping ? bind(mapFn, length > 2 ? arguments[2] : undefined) : undefined;
var result = new C();
var n = 0;
iterate(source, function (nextItem) {
iterate(O, function (nextItem) {
var entry = mapping ? boundFunction(nextItem, n++) : nextItem;
if (ENTRY) adder(result, anObject(entry)[0], entry[1]);
else adder(result, entry);
Expand Down

0 comments on commit 8d46fe0

Please sign in to comment.