Debian Codegraph @

js/src/jit-test/tests/gc/finalizationRegistry-cleanupSome-recursive.js

raw
1 // Test trying to call cleanupSome recursively in callback.
2
3 // 0: Initial state.
4 // 1: Attempt recursive calls.
5 // 2: After recursive calls.
6 let state = 0;
7
8 let registry = new FinalizationRegistry(x => {
9 if (state === 0) {
10 state = 1;
11 try {
12 registry.cleanupSome();
13 } catch (e) {
14 // Pass the test if any error was thrown.
15 return;
16 } finally {
17 state = 2;
18 }
19 throw new Error("expected stack overflow error");
20 }
21
22 if (state === 1) {
23 registry.cleanupSome();
24 }
25 });
26
27 // Attempt to find the maximum supported stack depth.
28 var stackSize = 0;
29 function findStackSize(i) {
30 try {
31 stackSize = i;
32 findStackSize(i + 1);
33 } catch (e) {
34 return;
35 }
36 }
37 findStackSize(0);
38
39 // Multiply the calculated stack size by some factor just to be on the safe side.
40 const exceedStackDepthLimit = stackSize * 5;
41
42 let values = [];
43 for (let i = 0; i < exceedStackDepthLimit; ++i) {
44 let v = {};
45 registry.register(v, i);
46 values.push(v);
47 }
48 values.length = 0;
49
50 gc();
51 drainJobQueue();