Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/DataView/negative-bytelength-throws.js

raw
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-dataview-buffer-byteoffset-bytelength
6 description: >
7 Throws a RangeError if ToInteger(byteLength) < 0
8 info: |
9 24.2.2.1 DataView (buffer, byteOffset, byteLength )
10
11 ...
12 8. If byteLength is either not present or undefined, then
13 a. Let viewByteLength be bufferByteLength - offset.
14 9. Else,
15 a. Let viewByteLength be ? ToIndex(byteLength).
16 ...
17
18 ToIndex ( value )
19
20 1. If value is undefined, then
21 a. Let index be 0.
22 2. Else,
23 a. Let integerIndex be ? ToInteger(value).
24 b. If integerIndex < 0, throw a RangeError exception.
25 ...
26 ---*/
27
28 var buffer = new ArrayBuffer(2);
29
30 assert.throws(RangeError, function() {
31 new DataView(buffer, 0, -1);
32 }, "new DataView(buffer, 0, -1);");
33
34 assert.throws(RangeError, function() {
35 new DataView(buffer, 0, -Infinity);
36 }, "new DataView(buffer, 0, -Infinity);");
37
38 assert.throws(RangeError, function() {
39 new DataView(buffer, 1, -1);
40 }, "new DataView(buffer, 1, -1);");
41
42 assert.throws(RangeError, function() {
43 new DataView(buffer, 2, -Infinity);
44 }, "new DataView(buffer, 2, -Infinity);");