summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/dumpValue.js
blob: b97c9e89d86227d4fd2137e36423bd4e76446c8f (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// |jit-test| skip-if: typeof dumpValue !== 'function'

// Try the dumpValue and dumpValueToString shell functions on various types of
// values, and make sure theyit don't crash, and the result is valid JSON.

function testDump(v) {
  dumpValue(v);

  const s = dumpValueToString(v);

  const result = JSON.parse(s);
  assertEq(typeof result, "object");
  assertEq(typeof result.type, "string");
}


testDump(1);
testDump(1.1);
testDump(-0.1);

testDump(100n);

testDump(true);
testDump(false);

testDump(null);

testDump(undefined);

// dumpStringRepresentation.js covers more strings.
testDump("foo");

testDump(/foo/ig);

testDump(Symbol.iterator);
testDump(Symbol("hello"));
testDump(Symbol.for("hello"));

testDump({});
testDump({ prop1: 10, prop2: 20 });

testDump([]);
testDump([1, , 3, 4]);

testDump(function f() {});
testDump(function* f() {});
testDump(async function f() {});
testDump(async function* f() {});

testDump(Promise.withResolvers());

var p1 = new Promise(() => {}); p1.then(() => {});
testDump(p1);
var p2 = new Promise(() => {}); p2.then(() => {}); p2.then(() => {});
testDump(p2);
var p3 = Promise.reject(10).catch(() => {});
testDump(p3);

testDump(new ArrayBuffer([1, 2, 3]));
testDump(new Int8Array([1, 2, 3]));
testDump(new Int8Array(new Int8Array([1, 2, 3]).buffer, 1));
testDump(new Int32Array([1, 2, 3]));
testDump(new Int32Array(new Int32Array([1, 2, 3]).buffer, 4));
testDump(new Float64Array([1, 2, 3]));

testDump(new Date());
testDump(new Map([[1, 2]]));
testDump(new Set([1, 2]));
testDump(new WeakMap([ [{}, 10], [{}, 20] ]));
testDump(new WeakSet([{}, {}]));
testDump(new Proxy({}, {}));

testDump(Array);
testDump(Array.prototype);
testDump(this);

testDump([
  1,
  1.1,
  -0.1,

  100n,

  true,
  false,

  null,

  undefined,

  "foo",

  /foo/ig,

  Symbol.iterator,
  Symbol("hello"),
  Symbol.for("hello"),

  {},
  { prop1: 10, prop2: 20 },

  [],
  [1, , 3, 4],

  function f() {},
  function* f() {},
  async function f() {},
  async function* f() {},

  Promise.withResolvers(),
  p1,
  p2,
  p3,

  new ArrayBuffer([1, 2, 3]),
  new Int8Array([1, 2, 3]),
  new Int8Array(new Int8Array([1, 2, 3]).buffer, 1),
  new Int32Array([1, 2, 3]),
  new Int32Array(new Int32Array([1, 2, 3]).buffer, 4),
  new Float64Array([1, 2, 3]),
  new Float64Array([1, 2, 3]),

  new Map([[1, 2]]),
  new Set([1, 2]),
  new WeakMap([ [{}, 10], [{}, 20] ]),
  new WeakSet([{}, {}]),
  new Proxy({}, {}),

  Array,
  Array.prototype,
  this,
]);