summaryrefslogtreecommitdiff
path: root/test/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset.js
blob: e43ab67de86fb3fedfd53fc286a972282a9203ea (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
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: ToIndex conversions on byteOffset
esid: sec-dataview.prototype.getbiguint64
features: [ArrayBuffer, BigInt, DataView, DataView.prototype.setUint8]
---*/

var buffer = new ArrayBuffer(12);
var sample = new DataView(buffer, 0);
sample.setUint8(0, 0x27);
sample.setUint8(1, 0x02);
sample.setUint8(2, 0x06);
sample.setUint8(3, 0x02);
sample.setUint8(4, 0x80);
sample.setUint8(5, 0x00);
sample.setUint8(6, 0x80);
sample.setUint8(7, 0x01);
sample.setUint8(8, 0x7f);
sample.setUint8(9, 0x00);
sample.setUint8(10, 0x01);
sample.setUint8(11, 0x02);

assert.sameValue(sample.getBigUint64(0), 0x2702060280008001 n);
assert.sameValue(sample.getBigUint64(1), 0x20602800080017f n);
assert.sameValue(sample.getBigUint64(-0.9), 0x2702060280008001 n, "ToIndex: truncate towards 0");
assert.sameValue(sample.getBigUint64(0.9), 0x2702060280008001 n, "ToIndex: truncate towards 0");
assert.sameValue(sample.getBigUint64(NaN), 0x2702060280008001 n, "ToIndex: NaN => 0");
assert.sameValue(sample.getBigUint64(undefined), 0x2702060280008001 n,
  "ToIndex: undefined => NaN => 0");
assert.sameValue(sample.getBigUint64(null), 0x2702060280008001 n, "ToIndex: null => 0");
assert.sameValue(sample.getBigUint64(false), 0x2702060280008001 n, "ToIndex: false => 0");
assert.sameValue(sample.getBigUint64(true), 0x20602800080017f n, "ToIndex: true => 1");
assert.sameValue(sample.getBigUint64("0"), 0x2702060280008001 n, "ToIndex: parse Number");
assert.sameValue(sample.getBigUint64("1"), 0x20602800080017f n, "ToIndex: parse Number");
assert.sameValue(sample.getBigUint64(""), 0x2702060280008001 n, "ToIndex: parse Number => NaN => 0");
assert.sameValue(sample.getBigUint64("foo"), 0x2702060280008001 n,
  "ToIndex: parse Number => NaN => 0");
assert.sameValue(sample.getBigUint64("true"), 0x2702060280008001 n,
  "ToIndex: parse Number => NaN => 0");
assert.sameValue(sample.getBigUint64(2), 0x602800080017F00 n);
assert.sameValue(sample.getBigUint64("2"), 0x602800080017F00 n, "toIndex: parse Number");
assert.sameValue(sample.getBigUint64(2.9), 0x602800080017F00 n, "toIndex: truncate towards 0");
assert.sameValue(sample.getBigUint64("2.9"), 0x602800080017F00 n,
  "toIndex: parse Number => truncate towards 0");
assert.sameValue(sample.getBigUint64(3), 0x2800080017F0001 n);
assert.sameValue(sample.getBigUint64("3"), 0x2800080017F0001 n, "toIndex: parse Number");
assert.sameValue(sample.getBigUint64(3.9), 0x2800080017F0001 n, "toIndex: truncate towards 0");
assert.sameValue(sample.getBigUint64("3.9"), 0x2800080017F0001 n,
  "toIndex: parse Number => truncate towards 0");
assert.sameValue(sample.getBigUint64([0]), 0x2702060280008001 n,
  'ToIndex: [0].toString() => "0" => 0');
assert.sameValue(sample.getBigUint64(["1"]), 0x20602800080017f n,
  'ToIndex: ["1"].toString() => "1" => 1');
assert.sameValue(sample.getBigUint64({}), 0x2702060280008001 n,
  'ToIndex: ({}).toString() => "[object Object]" => NaN => 0');
assert.sameValue(sample.getBigUint64([]), 0x2702060280008001 n,
  'ToIndex: [].toString() => "" => NaN => 0');