source: imaps-frontend/node_modules/es-abstract/2024/IsViewOutOfBounds.js

main
Last change on this file 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 IsDetachedBuffer = require('./IsDetachedBuffer');
6
7var isDataViewWithBufferWitnessRecord = require('../helpers/records/data-view-with-buffer-witness-record');
8
9var dataViewBuffer = require('data-view-buffer');
10var dataViewByteLength = require('data-view-byte-length');
11var dataViewByteOffset = require('data-view-byte-offset');
12
13// https://262.ecma-international.org/15.0/#sec-isviewoutofbounds
14
15module.exports = function IsViewOutOfBounds(viewRecord) {
16 if (!isDataViewWithBufferWitnessRecord(viewRecord)) {
17 throw new $TypeError('Assertion failed: `viewRecord` must be a DataView With Buffer Witness Record');
18 }
19
20 var view = viewRecord['[[Object]]']; // step 1
21
22 var bufferByteLength = viewRecord['[[CachedBufferByteLength]]']; // step 2
23
24 if (IsDetachedBuffer(dataViewBuffer(view)) !== (bufferByteLength === 'DETACHED')) {
25 // step 3
26 throw new $TypeError('Assertion failed: `IsDetachedBuffer(dataViewBuffer(view))` must be true if and only if `bufferByteLength === ~DETACHED~');
27 }
28
29 if (bufferByteLength === 'DETACHED') {
30 return true; // step 4
31 }
32
33 var byteOffsetStart = dataViewByteOffset(view); // step 5
34
35 var dvByteLength = dataViewByteLength(view);
36 var byteOffsetEnd = dvByteLength === 'AUTO' ? bufferByteLength : byteOffsetStart + dvByteLength; // steps 6 - 7
37
38 if (byteOffsetStart > bufferByteLength || byteOffsetEnd > bufferByteLength) {
39 return true; // step 8
40 }
41
42 // 9. NOTE: 0-length DataViews are not considered out-of-bounds.
43
44 return false; // step 10
45};
Note: See TracBrowser for help on using the repository browser.