Debian Codegraph @

js/src/tests/test262/language/expressions/left-shift/bigint-non-primitive.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 description: Left shift for non-primitive BigInt values
5 esid: sec-left-shift-operator-runtime-semantics-evaluation
6 info: |
7 ShiftExpression : ShiftExpression << AdditiveExpression
8
9 1. Let lref be the result of evaluating ShiftExpression.
10 2. Let lval be ? GetValue(lref).
11 3. Let rref be the result of evaluating AdditiveExpression.
12 4. Let rval be ? GetValue(rref).
13 5. Let lnum be ? ToNumeric(lval).
14 6. Let rnum be ? ToNumeric(rval).
15 7. If Type(lnum) does not equal Type(rnum), throw a TypeError exception.
16 8. Let T be Type(lnum).
17 9. Return T::leftShift(lnum, rnum).
18
19 features: [BigInt, Symbol.toPrimitive]
20 ---*/
21 assert.sameValue(Object(0b101n) << 1n, 0b1010n, 'The result of (Object(0b101n) << 1n) is 0b1010n');
22
23 assert.sameValue(
24 Object(0b101n) << Object(1n),
25 0b1010n,
26 'The result of (Object(0b101n) << Object(1n)) is 0b1010n'
27 );
28
29 function err() {
30 throw new Test262Error();
31 }
32
33 assert.sameValue({
34 [Symbol.toPrimitive]: function() {
35 return 0b101n;
36 },
37
38 valueOf: err,
39 toString: err
40 } << 1n, 0b1010n, 'The result of (({[Symbol.toPrimitive]: function() {return 0b101n;}, valueOf: err, toString: err}) << 1n) is 0b1010n');
41
42 assert.sameValue({
43 valueOf: function() {
44 return 0b101n;
45 },
46
47 toString: err
48 } << 1n, 0b1010n, 'The result of (({valueOf: function() {return 0b101n;}, toString: err}) << 1n) is 0b1010n');
49
50 assert.sameValue({
51 toString: function() {
52 return 0b101n;
53 }
54 } << 1n, 0b1010n, 'The result of (({toString: function() {return 0b101n;}}) << 1n) is 0b1010n');
55
56 assert.sameValue(0b101n << {
57 [Symbol.toPrimitive]: function() {
58 return 1n;
59 },
60
61 valueOf: err,
62 toString: err
63 }, 0b1010n, 'The result of (0b101n << {[Symbol.toPrimitive]: function() {return 1n;}, valueOf: err, toString: err}) is 0b1010n');
64
65 assert.sameValue(0b101n << {
66 valueOf: function() {
67 return 1n;
68 },
69
70 toString: err
71 }, 0b1010n, 'The result of (0b101n << {valueOf: function() {return 1n;}, toString: err}) is 0b1010n');
72
73 assert.sameValue(0b101n << {
74 toString: function() {
75 return 1n;
76 }
77 }, 0b1010n, 'The result of (0b101n << {toString: function() {return 1n;}}) is 0b1010n');
78
79 assert.sameValue({
80 valueOf: function() {
81 return 0b101n;
82 }
83 } << {
84 valueOf: function() {
85 return 1n;
86 }
87 }, 0b1010n, 'The result of (({valueOf: function() {return 0b101n;}}) << {valueOf: function() {return 1n;}}) is 0b1010n');
88
89 reportCompare(0, 0);