1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:37:35 +00:00

Revert "LibJS: Remove "uprooting" mechanism from garbage collector"

This reverts commit 6232ad3a0d.

Unfortunately this introduced some flakiness on CI, so it wasn't
quite this simple.
This commit is contained in:
Andreas Kling 2023-07-22 06:53:22 +02:00
parent a2955501d3
commit 1768d70823
6 changed files with 65 additions and 28 deletions

View file

@ -1,9 +1,3 @@
function registerInDifferentScope(registry) {
const target = {};
registry.register(target, {});
eval("");
}
test("basic functionality", () => {
expect(WeakMap.prototype.set).toHaveLength(2);
@ -27,26 +21,25 @@ test("invalid values", () => {
});
});
function setObjectKey(weakMap) {
expect(weakMap.set({ e: 3 }, 1)).toBe(weakMap);
}
function setSymbolKey(weakMap) {
expect(weakMap.set(Symbol("foo"), "bar")).toBe(weakMap);
}
test("automatic removal of garbage-collected values", () => {
const weakMap = new WeakMap();
const objectKey = { e: 3 };
setObjectKey(weakMap);
expect(weakMap.set(objectKey, 1)).toBe(weakMap);
expect(getWeakMapSize(weakMap)).toBe(1);
markAsGarbage("objectKey");
gc();
expect(getWeakMapSize(weakMap)).toBe(0);
setSymbolKey(weakMap);
const symbolKey = Symbol("foo");
expect(weakMap.set(symbolKey, "bar")).toBe(weakMap);
expect(getWeakMapSize(weakMap)).toBe(1);
markAsGarbage("symbolKey");
gc();
expect(getWeakMapSize(weakMap)).toBe(0);
});