summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-wrapped-values.js
blob: ab18dcaf063476b0f6241c2581740f9dd28e4c1c (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (C) 2017 Josh Wolfe. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt.asUintN type coercion for bits parameter
esid: sec-bigint.asuintn
info: |
  BigInt.asUintN ( bits, bigint )

  1. Let bits be ? ToIndex(bits).
features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive]
---*/

assert.sameValue(BigInt.asUintN(Object(0), 1n), 0n, "ToPrimitive: unbox object with internal slot");
assert.sameValue(BigInt.asUintN({
  [Symbol.toPrimitive]: function() {
    return 0;
  }
}, 1n), 0n, "ToPrimitive: @@toPrimitive");
assert.sameValue(BigInt.asUintN({
  valueOf: function() {
    return 0;
  }
}, 1n), 0n, "ToPrimitive: valueOf");
assert.sameValue(BigInt.asUintN({
  toString: function() {
    return 0;
  }
}, 1n), 0n, "ToPrimitive: toString");
assert.sameValue(BigInt.asUintN(Object(NaN), 1n), 0n,
  "ToIndex: unbox object with internal slot => NaN => 0");
assert.sameValue(BigInt.asUintN({
  [Symbol.toPrimitive]: function() {
    return NaN;
  }
}, 1n), 0n, "ToIndex: @@toPrimitive => NaN => 0");
assert.sameValue(BigInt.asUintN({
  valueOf: function() {
    return NaN;
  }
}, 1n), 0n, "ToIndex: valueOf => NaN => 0");
assert.sameValue(BigInt.asUintN({
  toString: function() {
    return NaN;
  }
}, 1n), 0n, "ToIndex: toString => NaN => 0");
assert.sameValue(BigInt.asUintN({
  [Symbol.toPrimitive]: function() {
    return undefined;
  }
}, 1n), 0n, "ToIndex: @@toPrimitive => undefined => NaN => 0");
assert.sameValue(BigInt.asUintN({
  valueOf: function() {
    return undefined;
  }
}, 1n), 0n, "ToIndex: valueOf => undefined => NaN => 0");
assert.sameValue(BigInt.asUintN({
  toString: function() {
    return undefined;
  }
}, 1n), 0n, "ToIndex: toString => undefined => NaN => 0");
assert.sameValue(BigInt.asUintN({
  [Symbol.toPrimitive]: function() {
    return null;
  }
}, 1n), 0n, "ToIndex: @@toPrimitive => null => 0");
assert.sameValue(BigInt.asUintN({
  valueOf: function() {
    return null;
  }
}, 1n), 0n, "ToIndex: valueOf => null => 0");
assert.sameValue(BigInt.asUintN({
  toString: function() {
    return null;
  }
}, 1n), 0n, "ToIndex: toString => null => 0");
assert.sameValue(BigInt.asUintN(Object(true), 1n), 1n,
  "ToIndex: unbox object with internal slot => true => 1");
assert.sameValue(BigInt.asUintN({
  [Symbol.toPrimitive]: function() {
    return true;
  }
}, 1n), 1n, "ToIndex: @@toPrimitive => true => 1");
assert.sameValue(BigInt.asUintN({
  valueOf: function() {
    return true;
  }
}, 1n), 1n, "ToIndex: valueOf => true => 1");
assert.sameValue(BigInt.asUintN({
  toString: function() {
    return true;
  }
}, 1n), 1n, "ToIndex: toString => true => 1");
assert.sameValue(BigInt.asUintN(Object("1"), 1n), 1n,
  "ToIndex: unbox object with internal slot => parse Number");
assert.sameValue(BigInt.asUintN({
  [Symbol.toPrimitive]: function() {
    return "1";
  }
}, 1n), 1n, "ToIndex: @@toPrimitive => parse Number");
assert.sameValue(BigInt.asUintN({
  valueOf: function() {
    return "1";
  }
}, 1n), 1n, "ToIndex: valueOf => parse Number");
assert.sameValue(BigInt.asUintN({
  toString: function() {
    return "1";
  }
}, 1n), 1n, "ToIndex: toString => parse Number");

reportCompare(0, 0);