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