summaryrefslogtreecommitdiff
path: root/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-offset-tointeger.js
blob: b47dc9de6037f91698c74c503f8f50dc706c588e (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(convertToBigInt([1, 2]));
  sample.set([convertToBigInt(42)], "");
  assert(compareArray(sample, convertToBigInt([42, 2])), "the empty string");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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