| function makeWeakRef() { return new WeakRef({foo: 1 }); } |
| // Turns out the test times out if we turn the event loop 10000 times... |
| let loopCount = globalThis.window ? 300 : 10000; |
| function turnEventLoop() { |
| return new Promise(function(resolve, reject) { |
| window.setTimeout(() => { |
| let weak = makeWeakRef(); |
| if (weak.deref().foo !== 1) |
| throw new Error("Weak ref was collected too early"); |
| for (let i = 0; i < loopCount; i++) { |
| for await (value of foo()) { } |
| if (weakRefs.find((weak) => weak.deref() === undefined) === undefined) |
| throw new Error("No weak ref value was collected"); |
| test().catch(e => debug(e)); |