Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/DataView/toindex-bytelength-sab.js

raw
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // Copyright (C) 2017 Mozilla Corporation. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-dataview-buffer-byteoffset-bytelength
7 description: >
8 ToIndex conversions on byteLength
9 info: |
10 24.2.2.1 DataView ( buffer, byteOffset, byteLength )
11
12 ...
13 8. If byteLength is either not present or undefined, then
14 a. Let viewByteLength be bufferByteLength - offset.
15 9. Else,
16 a. Let viewByteLength be ? ToIndex(byteLength).
17 b. If offset + viewByteLength > bufferByteLength, throw a RangeError
18 exception.
19 ...
20
21 ToIndex( value )
22
23 1. If value is undefined, then
24 a. Let index be 0.
25 2. Else,
26 a. Let integerIndex be ? ToInteger(value).
27 b. If integerIndex < 0, throw a RangeError exception.
28 c. Let index be ! ToLength(integerIndex).
29 d. If SameValueZero(integerIndex, index) is false, throw a RangeError exception.
30 3. Return index.
31 features: [SharedArrayBuffer]
32 ---*/
33
34 var obj1 = {
35 valueOf: function() {
36 return 3;
37 }
38 };
39
40 var obj2 = {
41 toString: function() {
42 return 4;
43 }
44 };
45
46 var sample;
47 var ab = new SharedArrayBuffer(42);
48
49 sample = new DataView(ab, 0, -0);
50 assert.sameValue(sample.byteLength, 0, "-0");
51
52 sample = new DataView(ab, 0, obj1);
53 assert.sameValue(sample.byteLength, 3, "object's valueOf");
54
55 sample = new DataView(ab, 0, obj2);
56 assert.sameValue(sample.byteLength, 4, "object's toString");
57
58 sample = new DataView(ab, 0, "");
59 assert.sameValue(sample.byteLength, 0, "the Empty string");
60
61 sample = new DataView(ab, 0, "0");
62 assert.sameValue(sample.byteLength, 0, "string '0'");
63
64 sample = new DataView(ab, 0, "1");
65 assert.sameValue(sample.byteLength, 1, "string '1'");
66
67 sample = new DataView(ab, 0, true);
68 assert.sameValue(sample.byteLength, 1, "true");
69
70 sample = new DataView(ab, 0, false);
71 assert.sameValue(sample.byteLength, 0, "false");
72
73 sample = new DataView(ab, 0, NaN);
74 assert.sameValue(sample.byteLength, 0, "NaN");
75
76 sample = new DataView(ab, 0, null);
77 assert.sameValue(sample.byteLength, 0, "null");
78
79 sample = new DataView(ab, 0, 0.1);
80 assert.sameValue(sample.byteLength, 0, "0.1");
81
82 sample = new DataView(ab, 0, 0.9);
83 assert.sameValue(sample.byteLength, 0, "0.9");
84
85 sample = new DataView(ab, 0, 1.1);
86 assert.sameValue(sample.byteLength, 1, "1.1");
87
88 sample = new DataView(ab, 0, 1.9);
89 assert.sameValue(sample.byteLength, 1, "1.9");
90
91 sample = new DataView(ab, 0, -0.1);
92 assert.sameValue(sample.byteLength, 0, "-0.1");
93
94 sample = new DataView(ab, 0, -0.99999);
95 assert.sameValue(sample.byteLength, 0, "-0.99999");