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
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var $TypeError = require('es-errors/type');
|
---|
4 |
|
---|
5 | var IsDetachedBuffer = require('./IsDetachedBuffer');
|
---|
6 |
|
---|
7 | var isDataViewWithBufferWitnessRecord = require('../helpers/records/data-view-with-buffer-witness-record');
|
---|
8 |
|
---|
9 | var dataViewBuffer = require('data-view-buffer');
|
---|
10 | var dataViewByteLength = require('data-view-byte-length');
|
---|
11 | var dataViewByteOffset = require('data-view-byte-offset');
|
---|
12 |
|
---|
13 | // https://262.ecma-international.org/15.0/#sec-isviewoutofbounds
|
---|
14 |
|
---|
15 | module.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.