source: imaps-frontend/node_modules/core-js/modules/es.array-buffer.slice.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.6 KB
Line 
1'use strict';
2var $ = require('../internals/export');
3var uncurryThis = require('../internals/function-uncurry-this-clause');
4var fails = require('../internals/fails');
5var ArrayBufferModule = require('../internals/array-buffer');
6var anObject = require('../internals/an-object');
7var toAbsoluteIndex = require('../internals/to-absolute-index');
8var toLength = require('../internals/to-length');
9
10var ArrayBuffer = ArrayBufferModule.ArrayBuffer;
11var DataView = ArrayBufferModule.DataView;
12var DataViewPrototype = DataView.prototype;
13var nativeArrayBufferSlice = uncurryThis(ArrayBuffer.prototype.slice);
14var getUint8 = uncurryThis(DataViewPrototype.getUint8);
15var setUint8 = uncurryThis(DataViewPrototype.setUint8);
16
17var 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});
Note: See TracBrowser for help on using the repository browser.