1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var fails = require('../internals/fails');
|
---|
4 | var ArrayBufferModule = require('../internals/array-buffer');
|
---|
5 | var anObject = require('../internals/an-object');
|
---|
6 | var toAbsoluteIndex = require('../internals/to-absolute-index');
|
---|
7 | var toLength = require('../internals/to-length');
|
---|
8 | var speciesConstructor = require('../internals/species-constructor');
|
---|
9 |
|
---|
10 | var ArrayBuffer = ArrayBufferModule.ArrayBuffer;
|
---|
11 | var DataView = ArrayBufferModule.DataView;
|
---|
12 | var nativeArrayBufferSlice = ArrayBuffer.prototype.slice;
|
---|
13 |
|
---|
14 | var INCORRECT_SLICE = fails(function () {
|
---|
15 | return !new ArrayBuffer(2).slice(1, undefined).byteLength;
|
---|
16 | });
|
---|
17 |
|
---|
18 | // `ArrayBuffer.prototype.slice` method
|
---|
19 | // https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice
|
---|
20 | $({ target: 'ArrayBuffer', proto: true, unsafe: true, forced: INCORRECT_SLICE }, {
|
---|
21 | slice: function slice(start, end) {
|
---|
22 | if (nativeArrayBufferSlice !== undefined && end === undefined) {
|
---|
23 | return nativeArrayBufferSlice.call(anObject(this), start); // FF fix
|
---|
24 | }
|
---|
25 | var length = anObject(this).byteLength;
|
---|
26 | var first = toAbsoluteIndex(start, length);
|
---|
27 | var fin = toAbsoluteIndex(end === undefined ? length : end, length);
|
---|
28 | var result = new (speciesConstructor(this, ArrayBuffer))(toLength(fin - first));
|
---|
29 | var viewSource = new DataView(this);
|
---|
30 | var viewTarget = new DataView(result);
|
---|
31 | var index = 0;
|
---|
32 | while (first < fin) {
|
---|
33 | viewTarget.setUint8(index++, viewSource.getUint8(first++));
|
---|
34 | } return result;
|
---|
35 | }
|
---|
36 | });
|
---|