Debian Codegraph @

js/src/tests/test262/language/expressions/prefix-decrement/bigint.js

raw
1 // Copyright (C) 2017 Josh Wolfe. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 description: Prefix decrement for references to BigInt values
6 esid: sec-prefix-decrement-operator-runtime-semantics-evaluation
7 info: |
8 1. Let expr be the result of evaluating UnaryExpression.
9 2. Let oldValue be ? ToNumeric(? GetValue(expr)).
10 3. Let newValue be ? Type(oldvalue)::subtract(oldValue, Type(oldValue)::unit).
11 4. Perform ? PutValue(expr, newValue).
12 5. Return newValue.
13 features: [BigInt]
14 ---*/
15
16 var x = 1n;
17 assert.sameValue(--x, 0n, "var x = 1n; --x === 0n");
18 assert.sameValue(x, 0n, "var x = 1n; --x; x === 0n");
19
20 var x = 0n;
21 assert.sameValue(--x, -1n, "var x = 0n; --x === -1n");
22 assert.sameValue(x, -1n, "var x = 0n; --x; x === -1n");
23
24 var x = 123457n;
25 assert.sameValue(--x, 123456n, "var x = 123457n; --x === 123456n");
26 assert.sameValue(x, 123456n, "var x = 123457n; --x; x === 123456n");
27
28 var x = -123456n;
29 assert.sameValue(--x, -123457n, "var x = -123456n; --x === -123457n");
30 assert.sameValue(x, -123457n, "var x = -123456n; --x; x === -123457n");
31
32 var x = 0x1fffffffffffff01n;
33 assert.sameValue(--x, 0x1fffffffffffff00n, "var x = 0x1fffffffffffff01n; --x === 0x1fffffffffffff00n");
34 assert.sameValue(x, 0x1fffffffffffff00n, "var x = 0x1fffffffffffff01n; --x; x === 0x1fffffffffffff00n");
35
36 var x = -0x1fffffffffffff00n;
37 assert.sameValue(--x, -0x1fffffffffffff01n, "var x = -0x1fffffffffffff00n; --x === -0x1fffffffffffff01n");
38 assert.sameValue(x, -0x1fffffffffffff01n, "var x = -0x1fffffffffffff00n; --x; x === -0x1fffffffffffff01n");
39
40 var x = {y:1n};
41 assert.sameValue(--x.y, 0n, "var x = {y:1n}; --x.y === 0n");
42 assert.sameValue(x.y, 0n, "var x = {y:1n}; --x.y; x.y === 0n");
43
44 var x = {y:{z:1n}};
45 assert.sameValue(--x.y.z, 0n, "var x = {y:{z:1n}}; --x.y.z === 0n");
46 assert.sameValue(x.y.z, 0n, "var x = {y:{z:1n}}; --x.y.z; x.y.z === 0n");
47
48 var x = [1n];
49 assert.sameValue(--x[0], 0n, "var x = [1n]; --x[0] === 0n");
50 assert.sameValue(x[0], 0n, "var x = [1n]; --x[0]; x[0] === 0n");
51
52 var x = [null, [null, null, 1n]];
53 assert.sameValue(--x[1][2], 0n, "var x = [null, [null, null, 1n]]; --x[1][2] === 0n");
54 assert.sameValue(x[1][2], 0n, "var x = [null, [null, null, 1n]]; --x[1][2]; x[1][2] === 0n");
55
56 var x = {y:[1n]};
57 assert.sameValue(--x.y[0], 0n, "var x = {y:[1n]}; --x.y[0] === 0n");
58 assert.sameValue(x.y[0], 0n, "var x = {y:[1n]}; --x.y[0]; x.y[0] === 0n");
59
60 var x = [{z:1n}];
61 assert.sameValue(--x[0].z, 0n, "var x = [{z:1n}]; --x[0].z === 0n");
62 assert.sameValue(x[0].z, 0n, "var x = [{z:1n}]; --x[0].z; x[0].z === 0n");
63
64 reportCompare(0, 0);