source: imaps-frontend/node_modules/es-abstract/2024/GetViewByteLength.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.5 KB
RevLine 
[d565449]1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var IsFixedLengthArrayBuffer = require('./IsFixedLengthArrayBuffer');
6var IsViewOutOfBounds = require('./IsViewOutOfBounds');
7
8var isDataViewWithBufferWitnessRecord = require('../helpers/records/data-view-with-buffer-witness-record');
9
10var dataViewBuffer = require('data-view-buffer');
11var dataViewByteLength = require('data-view-byte-length');
12var dataViewByteOffset = require('data-view-byte-offset');
13
14// https://262.ecma-international.org/15.0/#sec-getviewbytelength
15
16module.exports = function GetViewByteLength(viewRecord) {
17 if (!isDataViewWithBufferWitnessRecord(viewRecord)) {
18 throw new $TypeError('Assertion failed: `viewRecord` must be a DataView with Buffer Witness Record');
19 }
20
21 if (IsViewOutOfBounds(viewRecord)) {
22 throw new $TypeError('Assertion failed: `viewRecord` is out of bounds'); // step 1
23 }
24
25 var view = viewRecord['[[Object]]']; // step 2
26
27 var viewByteLength = dataViewByteLength(view); // view.[[ByteLength]]
28 if (viewByteLength !== 'AUTO') {
29 return viewByteLength; // step 3
30 }
31
32 if (IsFixedLengthArrayBuffer(dataViewBuffer(view))) {
33 throw new $TypeError('Assertion failed: DataView’s ArrayBuffer is not fixed length'); // step 4
34 }
35
36 var byteOffset = dataViewByteOffset(view); // step 5
37
38 var byteLength = viewRecord['[[CachedBufferByteLength]]']; // step 6
39
40 if (byteLength === 'DETACHED') {
41 throw new $TypeError('Assertion failed: DataView’s ArrayBuffer is detached'); // step 7
42 }
43
44 return byteLength - byteOffset; // step 8
45};
Note: See TracBrowser for help on using the repository browser.