Bug 1894428 - Set depended on bit from AutoStableStringChars r=sfink
[gecko.git] / js / src / tests / test262 / built-ins / DataView / prototype / getFloat16 / index-is-out-of-range.js
blob7781bde8105a64abafa893ec915936e37ec2ba5d
1 // |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options
2 // Copyright (C) 2024 Kevin Gibbons. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
5 /*---
6 esid: sec-dataview.prototype.getfloat16
7 description: >
8   Throws a RangeError if getIndex + elementSize > viewSize
9 features: [Float16Array]
10 ---*/
12 var sample;
13 var buffer = new ArrayBuffer(12);
15 sample = new DataView(buffer, 0);
17 assert.throws(RangeError, function() {
18   sample.getFloat16(Infinity);
19 }, "getIndex == Infinity");
21 assert.throws(RangeError, function() {
22   sample.getFloat16(13);
23 }, "13 + 2 > 12");
25 assert.throws(RangeError, function() {
26   sample.getFloat16(12);
27 }, "12 + 2 > 12");
29 assert.throws(RangeError, function() {
30   sample.getFloat16(11);
31 }, "11 + 2 > 12");
33 sample = new DataView(buffer, 10);
34 assert.throws(RangeError, function() {
35   sample.getFloat16(1);
36 }, "1 + 2 > 2 (offset)");
38 sample = new DataView(buffer, 11);
39 assert.throws(RangeError, function() {
40   sample.getFloat16(0);
41 }, "0 + 2 > 1 (offset)");
43 sample = new DataView(buffer, 0, 2);
44 assert.throws(RangeError, function() {
45   sample.getFloat16(1);
46 }, "1 + 2 > 2 (length)");
48 sample = new DataView(buffer, 0, 1);
49 assert.throws(RangeError, function() {
50   sample.getFloat16(0);
51 }, "0 + 2 > 1 (length)");
53 sample = new DataView(buffer, 4, 2);
54 assert.throws(RangeError, function() {
55   sample.getFloat16(1);
56 }, "1 + 2 > 2 (offset+length)");
58 sample = new DataView(buffer, 4, 1);
59 assert.throws(RangeError, function() {
60   sample.getFloat16(0);
61 }, "0 + 2 > 1 (offset+length)");
63 reportCompare(0, 0);