summaryrefslogtreecommitdiff
path: root/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-offset-tointeger.js
blob: 9d5b2478fee1e0c87fc9748f3ce1ec78af2024ab (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
// 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-typedarray-offset
description: >
  ToInteger(offset) operations
info: |
  22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] )

  1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not,
  the definition in 22.2.3.23.1 applies.
  ...
  6. Let targetOffset be ? ToInteger(offset).
includes: [testBigIntTypedArray.js, compareArray.js]
features: [BigInt, TypedArray]
---*/

testWithBigIntTypedArrayConstructors(function(TA) {
  var sample;
  var src = new TA(convertToBigInt([42]));

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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