Debian Codegraph @

js/src/tests/test262/language/expressions/addition/bigint-and-number.js

raw
1 // Copyright (C) 2018 Igalia, S.L. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-addition-operator-plus-runtime-semantics-evaluation
5 description: Mixing BigInt and Number produces a TypeError for addition operator
6 features: [BigInt]
7 info: |
8 Let lprim be ? ToPrimitive(lval).
9 Let rprim be ? ToPrimitive(rval).
10 ...
11 Let lnum be ? ToNumeric(lprim)
12 Let rnum be ? ToNumeric(rprim)
13 If Type(lnum) does not equal Type(rnum), throw a TypeError exception.
14 ---*/
15 assert.throws(TypeError, function() {
16 1n + 1;
17 }, '1n + 1 throws TypeError');
18
19 assert.throws(TypeError, function() {
20 1 + 1n;
21 }, '1 + 1n throws TypeError');
22
23 assert.throws(TypeError, function() {
24 Object(1n) + 1;
25 }, 'Object(1n) + 1 throws TypeError');
26
27 assert.throws(TypeError, function() {
28 1 + Object(1n);
29 }, '1 + Object(1n) throws TypeError');
30
31 assert.throws(TypeError, function() {
32 1n + Object(1);
33 }, '1n + Object(1) throws TypeError');
34
35 assert.throws(TypeError, function() {
36 Object(1) + 1n;
37 }, 'Object(1) + 1n throws TypeError');
38
39 assert.throws(TypeError, function() {
40 Object(1n) + Object(1);
41 }, 'Object(1n) + Object(1) throws TypeError');
42
43 assert.throws(TypeError, function() {
44 Object(1) + Object(1n);
45 }, 'Object(1) + Object(1n) throws TypeError');
46
47 assert.throws(TypeError, function() {
48 1n + NaN;
49 }, '1n + NaN throws TypeError');
50
51 assert.throws(TypeError, function() {
52 NaN + 1n;
53 }, 'NaN + 1n throws TypeError');
54
55 assert.throws(TypeError, function() {
56 1n + Infinity;
57 }, '1n + Infinity throws TypeError');
58
59 assert.throws(TypeError, function() {
60 Infinity + 1n;
61 }, 'Infinity + 1n throws TypeError');
62
63 assert.throws(TypeError, function() {
64 1n + true;
65 }, '1n + true throws TypeError');
66
67 assert.throws(TypeError, function() {
68 true + 1n;
69 }, 'true + 1n throws TypeError');
70
71 assert.throws(TypeError, function() {
72 1n + null;
73 }, '1n + null throws TypeError');
74
75 assert.throws(TypeError, function() {
76 null + 1n;
77 }, 'null + 1n throws TypeError');
78
79 assert.throws(TypeError, function() {
80 1n + undefined;
81 }, '1n + undefined throws TypeError');
82
83 assert.throws(TypeError, function() {
84 undefined + 1n;
85 }, 'undefined + 1n throws TypeError');
86
87 reportCompare(0, 0);