source: imaps-frontend/node_modules/es-abstract/2024/ArrayBufferByteLength.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.6 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5// https://tc39.es/ecma262/#sec-arraybufferbytelength
6
7var IsDetachedBuffer = require('./IsDetachedBuffer');
8
9var isArrayBuffer = require('is-array-buffer');
10var isSharedArrayBuffer = require('is-shared-array-buffer');
11var arrayBufferByteLength = require('array-buffer-byte-length');
12
13var isGrowable = false; // TODO: support this
14
15module.exports = function ArrayBufferByteLength(arrayBuffer, order) {
16 var isSAB = isSharedArrayBuffer(arrayBuffer);
17 if (!isArrayBuffer(arrayBuffer) && !isSAB) {
18 throw new $TypeError('Assertion failed: `arrayBuffer` must be an ArrayBuffer or a SharedArrayBuffer');
19 }
20 if (order !== 'SEQ-CST' && order !== 'UNORDERED') {
21 throw new $TypeError('Assertion failed: `order` must be ~SEQ-CST~ or ~UNORDERED~');
22 }
23
24 // 1. If IsSharedArrayBuffer(arrayBuffer) is true and arrayBuffer has an [[ArrayBufferByteLengthData]] internal slot, then
25 // TODO: see if IsFixedLengthArrayBuffer can be used here in the spec instead
26 if (isSAB && isGrowable) { // step 1
27 // a. Let bufferByteLengthBlock be arrayBuffer.[[ArrayBufferByteLengthData]].
28 // b. Let rawLength be GetRawBytesFromSharedBlock(bufferByteLengthBlock, 0, BIGUINT64, true, order).
29 // c. Let isLittleEndian be the value of the [[LittleEndian]] field of the surrounding agent's Agent Record.
30 // d. Return ℝ(RawBytesToNumeric(BIGUINT64, rawLength, isLittleEndian)).
31 }
32
33 if (IsDetachedBuffer(arrayBuffer)) {
34 throw new $TypeError('Assertion failed: `arrayBuffer` must not be detached'); // step 2
35 }
36
37 return arrayBufferByteLength(arrayBuffer);
38};
Note: See TracBrowser for help on using the repository browser.