source: imaps-frontend/node_modules/core-js/internals/array-buffer-transfer.js

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.3 KB
Line 
1'use strict';
2var globalThis = require('../internals/global-this');
3var uncurryThis = require('../internals/function-uncurry-this');
4var uncurryThisAccessor = require('../internals/function-uncurry-this-accessor');
5var toIndex = require('../internals/to-index');
6var notDetached = require('../internals/array-buffer-not-detached');
7var arrayBufferByteLength = require('../internals/array-buffer-byte-length');
8var detachTransferable = require('../internals/detach-transferable');
9var PROPER_STRUCTURED_CLONE_TRANSFER = require('../internals/structured-clone-proper-transfer');
10
11var structuredClone = globalThis.structuredClone;
12var ArrayBuffer = globalThis.ArrayBuffer;
13var DataView = globalThis.DataView;
14var min = Math.min;
15var ArrayBufferPrototype = ArrayBuffer.prototype;
16var DataViewPrototype = DataView.prototype;
17var slice = uncurryThis(ArrayBufferPrototype.slice);
18var isResizable = uncurryThisAccessor(ArrayBufferPrototype, 'resizable', 'get');
19var maxByteLength = uncurryThisAccessor(ArrayBufferPrototype, 'maxByteLength', 'get');
20var getInt8 = uncurryThis(DataViewPrototype.getInt8);
21var setInt8 = uncurryThis(DataViewPrototype.setInt8);
22
23module.exports = (PROPER_STRUCTURED_CLONE_TRANSFER || detachTransferable) && function (arrayBuffer, newLength, preserveResizability) {
24 var byteLength = arrayBufferByteLength(arrayBuffer);
25 var newByteLength = newLength === undefined ? byteLength : toIndex(newLength);
26 var fixedLength = !isResizable || !isResizable(arrayBuffer);
27 var newBuffer;
28 notDetached(arrayBuffer);
29 if (PROPER_STRUCTURED_CLONE_TRANSFER) {
30 arrayBuffer = structuredClone(arrayBuffer, { transfer: [arrayBuffer] });
31 if (byteLength === newByteLength && (preserveResizability || fixedLength)) return arrayBuffer;
32 }
33 if (byteLength >= newByteLength && (!preserveResizability || fixedLength)) {
34 newBuffer = slice(arrayBuffer, 0, newByteLength);
35 } else {
36 var options = preserveResizability && !fixedLength && maxByteLength ? { maxByteLength: maxByteLength(arrayBuffer) } : undefined;
37 newBuffer = new ArrayBuffer(newByteLength, options);
38 var a = new DataView(arrayBuffer);
39 var b = new DataView(newBuffer);
40 var copyLength = min(newByteLength, byteLength);
41 for (var i = 0; i < copyLength; i++) setInt8(b, i, getInt8(a, i));
42 }
43 if (!PROPER_STRUCTURED_CLONE_TRANSFER) detachTransferable(arrayBuffer);
44 return newBuffer;
45};
Note: See TracBrowser for help on using the repository browser.