Debian Codegraph @

js/src/jit-test/tests/basic/dumpValue.js

raw
1 // |jit-test| skip-if: typeof dumpValue !== 'function'
2
3 // Try the dumpValue and dumpValueToString shell functions on various types of
4 // values, and make sure theyit don't crash, and the result is valid JSON.
5
6 function testDump(v) {
7 dumpValue(v);
8
9 const s = dumpValueToString(v);
10
11 const result = JSON.parse(s);
12 assertEq(typeof result, "object");
13 assertEq(typeof result.type, "string");
14 }
15
16
17 testDump(1);
18 testDump(1.1);
19 testDump(-0.1);
20
21 testDump(100n);
22
23 testDump(true);
24 testDump(false);
25
26 testDump(null);
27
28 testDump(undefined);
29
30 // dumpStringRepresentation.js covers more strings.
31 testDump("foo");
32
33 testDump(/foo/ig);
34
35 testDump(Symbol.iterator);
36 testDump(Symbol("hello"));
37 testDump(Symbol.for("hello"));
38
39 testDump({});
40 testDump({ prop1: 10, prop2: 20 });
41
42 testDump([]);
43 testDump([1, , 3, 4]);
44
45 testDump(function f() {});
46 testDump(function* f() {});
47 testDump(async function f() {});
48 testDump(async function* f() {});
49
50 testDump(Promise.withResolvers());
51
52 var p1 = new Promise(() => {}); p1.then(() => {});
53 testDump(p1);
54 var p2 = new Promise(() => {}); p2.then(() => {}); p2.then(() => {});
55 testDump(p2);
56 var p3 = Promise.reject(10).catch(() => {});
57 testDump(p3);
58
59 testDump(new ArrayBuffer([1, 2, 3]));
60 testDump(new Int8Array([1, 2, 3]));
61 testDump(new Int8Array(new Int8Array([1, 2, 3]).buffer, 1));
62 testDump(new Int32Array([1, 2, 3]));
63 testDump(new Int32Array(new Int32Array([1, 2, 3]).buffer, 4));
64 testDump(new Float64Array([1, 2, 3]));
65
66 testDump(new Date());
67 testDump(new Map([[1, 2]]));
68 testDump(new Set([1, 2]));
69 testDump(new WeakMap([ [{}, 10], [{}, 20] ]));
70 testDump(new WeakSet([{}, {}]));
71 testDump(new Proxy({}, {}));
72
73 testDump(Array);
74 testDump(Array.prototype);
75 testDump(this);
76
77 testDump([
78 1,
79 1.1,
80 -0.1,
81
82 100n,
83
84 true,
85 false,
86
87 null,
88
89 undefined,
90
91 "foo",
92
93 /foo/ig,
94
95 Symbol.iterator,
96 Symbol("hello"),
97 Symbol.for("hello"),
98
99 {},
100 { prop1: 10, prop2: 20 },
101
102 [],
103 [1, , 3, 4],
104
105 function f() {},
106 function* f() {},
107 async function f() {},
108 async function* f() {},
109
110 Promise.withResolvers(),
111 p1,
112 p2,
113 p3,
114
115 new ArrayBuffer([1, 2, 3]),
116 new Int8Array([1, 2, 3]),
117 new Int8Array(new Int8Array([1, 2, 3]).buffer, 1),
118 new Int32Array([1, 2, 3]),
119 new Int32Array(new Int32Array([1, 2, 3]).buffer, 4),
120 new Float64Array([1, 2, 3]),
121 new Float64Array([1, 2, 3]),
122
123 new Map([[1, 2]]),
124 new Set([1, 2]),
125 new WeakMap([ [{}, 10], [{}, 20] ]),
126 new WeakSet([{}, {}]),
127 new Proxy({}, {}),
128
129 Array,
130 Array.prototype,
131 this,
132 ]);