summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/DataView/prototype/setFloat16/to-boolean-littleendian.js
blob: 1840009be6a2830a28379ce216f97fd4f56ecf01 (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
// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.setfloat16
description: >
  Boolean littleEndian argument coerced in ToBoolean
features: [Float16Array, Symbol]
---*/

var buffer = new ArrayBuffer(2);
var sample = new DataView(buffer, 0);

// False
sample.setFloat16(0, 1);
assert.sameValue(sample.getFloat16(0), 1, "no arg");
sample.setFloat16(0, 2, undefined);
assert.sameValue(sample.getFloat16(0), 2, "undefined");
sample.setFloat16(0, 3, null);
assert.sameValue(sample.getFloat16(0), 3, "null");
sample.setFloat16(0, 4, 0);
assert.sameValue(sample.getFloat16(0), 4, "0");
sample.setFloat16(0, 5, "");
assert.sameValue(sample.getFloat16(0), 5, "the empty string");

// True
sample.setFloat16(0, 6, {}); // 01000110 00000000
assert.sameValue(sample.getFloat16(0), 0.000004172325134277344, "{}"); // 00000000 01000110
sample.setFloat16(0, 7, Symbol("1")); // 01000111 00000000
assert.sameValue(sample.getFloat16(0), 0.000004231929779052734, "symbol"); // 00000000 01000111
sample.setFloat16(0, 8, 1); // 01001000 00000000
assert.sameValue(sample.getFloat16(0), 0.000004291534423828125, "1"); // 00000000 01001000
sample.setFloat16(0, 9, "string"); // 01001000 10000000
assert.sameValue(sample.getFloat16(0), -0.000004291534423828125, "string"); // 10000000 01001000

reportCompare(0, 0);