| //@ requireOptions("--useWeakRefs=true") |
| function makeWeakRef() { return new WeakRef({foo: 1 }); } |
| function turnEventLoop() { |
| return new Promise(function(resolve, reject) { |
| // Turns out the test times out if we turn the event loop 10000 times... |
| window.setTimeout(() => { |
| let weak = makeWeakRef(); |
| let object = weak.deref(); |
| if (weak.deref() !== object) |
| throw new Error("Object appears to have been collected incorrectly"); |
| yield await turnEventLoop(); |
| for (let i = 0; i < loopCount; i++) { |
| for await (value of foo()) { } |
| if (weakRefs.find((weak) => weak.deref() === null) === undefined) |
| throw new Error("No weak ref value was collected"); |
| test().catch(e => debug(e)); |