source: frontend/node_modules/es-abstract/2025/ArrayBufferByteLength.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.7 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5// https://262.ecma-international.org/15.0/#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 callBound = require('call-bound');
14var $sabByteLength = callBound('SharedArrayBuffer.prototype.byteLength', true);
15
16var isGrowable = false; // TODO: support this
17
18module.exports = function ArrayBufferByteLength(arrayBuffer, order) {
19 var isSAB = isSharedArrayBuffer(arrayBuffer);
20 if (!isArrayBuffer(arrayBuffer) && !isSAB) {
21 throw new $TypeError('Assertion failed: `arrayBuffer` must be an ArrayBuffer or a SharedArrayBuffer');
22 }
23 if (order !== 'SEQ-CST' && order !== 'UNORDERED') {
24 throw new $TypeError('Assertion failed: `order` must be ~SEQ-CST~ or ~UNORDERED~');
25 }
26
27 // 1. If IsSharedArrayBuffer(arrayBuffer) is true and arrayBuffer has an [[ArrayBufferByteLengthData]] internal slot, then
28 // TODO: see if IsFixedLengthArrayBuffer can be used here in the spec instead
29 if (isSAB && isGrowable) { // step 1
30 // a. Let bufferByteLengthBlock be arrayBuffer.[[ArrayBufferByteLengthData]].
31 // b. Let rawLength be GetRawBytesFromSharedBlock(bufferByteLengthBlock, 0, BIGUINT64, true, order).
32 // c. Let isLittleEndian be the value of the [[LittleEndian]] field of the surrounding agent's Agent Record.
33 // d. Return ℝ(RawBytesToNumeric(BIGUINT64, rawLength, isLittleEndian)).
34 }
35
36 if (IsDetachedBuffer(arrayBuffer)) {
37 throw new $TypeError('Assertion failed: `arrayBuffer` must not be detached'); // step 2
38 }
39
40 return isSAB ? $sabByteLength(arrayBuffer) : arrayBufferByteLength(arrayBuffer);
41};
Note: See TracBrowser for help on using the repository browser.