summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/builtins/WeakSet
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-06-09 20:10:47 +0300
committerLinus Groh <mail@linusgroh.de>2021-06-09 21:52:25 +0100
commita00d154522eeed0b2976827be5dd91500e5a45cf (patch)
tree08f3fdc376dda75c9a83a4a082e8b31f769472c5 /Userland/Libraries/LibJS/Tests/builtins/WeakSet
parentfb63aeae4d7c2b18833837cc54509f6627792af9 (diff)
downloadserenity-a00d154522eeed0b2976827be5dd91500e5a45cf.zip
LibJS: Notify WeakSets when heap cells are sweeped
This is an implementation of the following optional optimization: https://tc39.es/ecma262/#sec-weakref-execution
Diffstat (limited to 'Userland/Libraries/LibJS/Tests/builtins/WeakSet')
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/WeakSet/WeakSet.prototype.add.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/WeakSet/WeakSet.prototype.add.js b/Userland/Libraries/LibJS/Tests/builtins/WeakSet/WeakSet.prototype.add.js
index 0f77e94fe6..d9dd1eee2e 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/WeakSet/WeakSet.prototype.add.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/WeakSet/WeakSet.prototype.add.js
@@ -14,3 +14,13 @@ test("invalid values", () => {
}).toThrowWithMessage(TypeError, "is not an object");
});
});
+
+test("automatic removal of garbage-collected values", () => {
+ const weakSet = new WeakSet();
+ {
+ expect(weakSet.add({ a: 1 })).toBe(weakSet);
+ expect(getWeakSetSize(weakSet)).toBe(1);
+ }
+ gc();
+ expect(getWeakSetSize(weakSet)).toBe(0);
+});