Skip to content

Commit

Permalink
additional constructor validation in %TypedArray%.from
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Sep 18, 2021
1 parent 9beeaad commit 138a413
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/core-js/internals/typed-array-from.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var aConstructor = require('../internals/a-constructor');
var toObject = require('../internals/to-object');
var toLength = require('../internals/to-length');
var getIterator = require('../internals/get-iterator');
Expand All @@ -7,6 +8,7 @@ var bind = require('../internals/function-bind-context');
var aTypedArrayConstructor = require('../internals/array-buffer-view-core').aTypedArrayConstructor;

module.exports = function from(source /* , mapfn, thisArg */) {
var C = aConstructor(this);
var O = toObject(source);
var argumentsLength = arguments.length;
var mapfn = argumentsLength > 1 ? arguments[1] : undefined;
Expand All @@ -25,7 +27,7 @@ module.exports = function from(source /* , mapfn, thisArg */) {
mapfn = bind(mapfn, arguments[2], 2);
}
length = toLength(O.length);
result = new (aTypedArrayConstructor(this))(length);
result = new (aTypedArrayConstructor(C))(length);
for (i = 0; length > i; i++) {
result[i] = mapping ? mapfn(O[i], i) : O[i];
}
Expand Down

0 comments on commit 138a413

Please sign in to comment.