summaryrefslogtreecommitdiff
path: root/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-offset-tointeger.js
blob: e5d504634831685b0d0c789bd70c4a082843f3cf (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-%typedarray%.prototype.set-array-offset
description: >
  ToInteger(offset) operations
info: |
  22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] )

  1. Assert: array is any ECMAScript language value other than an Object with a
  [[TypedArrayName]] internal slot. If it is such an Object, the definition in
  22.2.3.23.2 applies.
  ...
  6. Let targetOffset be ? ToInteger(offset).
  7. If targetOffset < 0, throw a RangeError exception.
  ...
includes: [testBigIntTypedArray.js, compareArray.js]
features: [BigInt, TypedArray]
---*/

testWithBigIntTypedArrayConstructors(function(TA) {
  var sample;

  sample = new TA([1n, 2n]);
  sample.set([42n], "");
  assert(compareArray(sample, [42n, 2n]), "the empty string");

  sample = new TA([1n, 2n]);
  sample.set([42n], "0");
  assert(compareArray(sample, [42n, 2n]), "'0'");

  sample = new TA([1n, 2n]);
  sample.set([42n], false);
  assert(compareArray(sample, [42n, 2n]), "false");

  sample = new TA([1n, 2n]);
  sample.set([42n], 0.1);
  assert(compareArray(sample, [42n, 2n]), "0.1");

  sample = new TA([1n, 2n]);
  sample.set([42n], 0.9);
  assert(compareArray(sample, [42n, 2n]), "0.9");

  sample = new TA([1n, 2n]);
  sample.set([42n], -0.5);
  assert(compareArray(sample, [42n, 2n]), "-0.5");

  sample = new TA([1n, 2n]);
  sample.set([42n], 1.1);
  assert(compareArray(sample, [1n, 42n]), "1.1");

  sample = new TA([1n, 2n]);
  sample.set([42n], NaN);
  assert(compareArray(sample, [42n, 2n]), "NaN");

  sample = new TA([1n, 2n]);
  sample.set([42n], null);
  assert(compareArray(sample, [42n, 2n]), "null");

  sample = new TA([1n, 2n]);
  sample.set([42n], undefined);
  assert(compareArray(sample, [42n, 2n]), "undefined");

  sample = new TA([1n, 2n]);
  sample.set([42n], {});
  assert(compareArray(sample, [42n, 2n]), "{}");

  sample = new TA([1n, 2n]);
  sample.set([42n], []);
  assert(compareArray(sample, [42n, 2n]), "[]");

  sample = new TA([1n, 2n]);
  sample.set([42n], [0]);
  assert(compareArray(sample, [42n, 2n]), "[0]");

  sample = new TA([1n, 2n]);
  sample.set([42n], true);
  assert(compareArray(sample, [1n, 42n]), "true");

  sample = new TA([1n, 2n]);
  sample.set([42n], "1");
  assert(compareArray(sample, [1n, 42n]), "'1'");

  sample = new TA([1n, 2n]);
  sample.set([42n], [1]);
  assert(compareArray(sample, [1n, 42n]), "[1]");

  sample = new TA([1n, 2n]);
  sample.set([42n], { valueOf: function() {return 1;} });
  assert(compareArray(sample, [1n, 42n]), "valueOf");

  sample = new TA([1n, 2n]);
  sample.set([42n], { toString: function() {return 1;} });
  assert(compareArray(sample, [1n, 42n]), "toString");
});