summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/DataView/byteOffset-validated-against-initial-buffer-length.js
blob: 51b030b66bcd15b7eb6b6a1cf4d7d8965c9c0b24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (C) 2024 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview-buffer-byteoffset-bytelength
description: >
  The byteOffset argument is validated against the initial buffer length.
info: |
  DataView ( buffer [ , byteOffset [ , byteLength ] ] )

  ...
  3. Let offset be ? ToIndex(byteOffset).
  ...
  5. Let bufferByteLength be ArrayBufferByteLength(buffer, seq-cst).
  6. If offset > bufferByteLength, throw a RangeError exception.
  ...
  10. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataView.prototype%",
      « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »).
  ...

  OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )

  ...
  2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
  ...

features: [Reflect.construct]
---*/

let newTarget = Object.defineProperty(function(){}.bind(), "prototype", {
  get() {
    throw new Test262Error("GetPrototypeFromConstructor not executed");
  }
});

// Zero length buffer.
let ab = new ArrayBuffer(0);

// Byte offset is larger than the buffer length, which is zero.
let byteOffset = 10;

assert.throws(RangeError, () => {
  Reflect.construct(DataView, [ab, byteOffset], newTarget);
});

reportCompare(0, 0);