-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgc.js
More file actions
26 lines (23 loc) · 688 Bytes
/
gc.js
File metadata and controls
26 lines (23 loc) · 688 Bytes
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
// Capture the engine-provided gc (Node exposes it under --expose-gc) before
// we overwrite globalThis.gc with the harness wrapper below.
const engineGc = globalThis.gc;
if (typeof engineGc !== "function") {
throw new Error(
"Node harness expects globalThis.gc to be available (run with --expose-gc)",
);
}
const gc = () => {
engineGc();
};
const gcUntil = async (name, condition) => {
let count = 0;
while (!condition()) {
await new Promise((resolve) => setImmediate(resolve));
if (++count < 10) {
engineGc();
} else {
throw new Error(`GC test "${name}" failed after ${count} attempts`);
}
}
};
Object.assign(globalThis, { gc, gcUntil });