1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:37:36 +00:00

LibJS: Add the WeakRef.prototype.deref method

This is the only exposed method of the WeakRef built-in.
This commit is contained in:
Idan Horowitz 2021-06-12 17:40:33 +03:00 committed by Linus Groh
parent 7eba63a8a3
commit b9d4dd6850
3 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,21 @@
test("length is 0", () => {
expect(WeakRef.prototype.deref).toHaveLength(0);
});
test("basic functionality", () => {
var original = { a: 1 };
var weakRef = new WeakRef(original);
expect(weakRef.deref()).toBe(original);
});
test("kept alive for current synchronous execution sequence", () => {
var weakRef;
{
weakRef = new WeakRef({ a: 1 });
}
weakRef.deref();
gc();
// This is fine 🔥
expect(weakRef.deref()).not.toBe(undefined);
});