UNPKG

1.27 kBJavaScriptView Raw
1'use strict';
2var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
3var $fill = require('../internals/array-fill');
4var toBigInt = require('../internals/to-big-int');
5var classof = require('../internals/classof');
6var call = require('../internals/function-call');
7var uncurryThis = require('../internals/function-uncurry-this');
8var fails = require('../internals/fails');
9
10var aTypedArray = ArrayBufferViewCore.aTypedArray;
11var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
12var slice = uncurryThis(''.slice);
13
14// V8 ~ Chrome < 59, Safari < 14.1, FF < 55, Edge <=18
15var CONVERSION_BUG = fails(function () {
16 var count = 0;
17 // eslint-disable-next-line es/no-typed-arrays -- safe
18 new Int8Array(2).fill({ valueOf: function () { return count++; } });
19 return count !== 1;
20});
21
22// `%TypedArray%.prototype.fill` method
23// https://tc39.es/ecma262/#sec-%typedarray%.prototype.fill
24exportTypedArrayMethod('fill', function fill(value /* , start, end */) {
25 var length = arguments.length;
26 aTypedArray(this);
27 var actualValue = slice(classof(this), 0, 3) === 'Big' ? toBigInt(value) : +value;
28 return call($fill, this, actualValue, length > 1 ? arguments[1] : undefined, length > 2 ? arguments[2] : undefined);
29}, CONVERSION_BUG);