debian-mirror-gitlab/core-js/modules/es.typed-array.subarray.js
2019-09-25 13:30:05 +05:30

21 lines
838 B
JavaScript

'use strict';
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
var toLength = require('../internals/to-length');
var toAbsoluteIndex = require('../internals/to-absolute-index');
var speciesConstructor = require('../internals/species-constructor');
var aTypedArray = ArrayBufferViewCore.aTypedArray;
// `%TypedArray%.prototype.subarray` method
// https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.subarray
ArrayBufferViewCore.exportProto('subarray', function subarray(begin, end) {
var O = aTypedArray(this);
var length = O.length;
var beginIndex = toAbsoluteIndex(begin, length);
return new (speciesConstructor(O, O.constructor))(
O.buffer,
O.byteOffset + beginIndex * O.BYTES_PER_ELEMENT,
toLength((end === undefined ? length : toAbsoluteIndex(end, length)) - beginIndex)
);
});