Files
ladybird/Tests/LibWeb/Text/input/indexeddb-gc-closes-unreachable-connection.html
Zaggy1024 61b9be47ce LibWeb: Open waiting IDB connections when the previous one is GCed
Without this, an open request could hang if a prior connection was not
explicitly close()d but instead allowed to go out of scope.

The spec says that the dangling connection should be closed when the
execution context it was opened in is destroyed, but no other browser
does so. Detecting the execution context being destroyed would likely
mean a lot of overhead in JS calls, so it's best to avoid that, despite
this being observable.
2026-04-08 03:03:38 +02:00

47 lines
1.2 KiB
HTML

<!DOCTYPE html>
<script src="include.js"></script>
<script>
asyncTest(done => {
const DB_NAME = "gc-closes-unreachable-connection";
indexedDB.deleteDatabase(DB_NAME);
function openAndForget() {
return new Promise((resolve) => {
let req = indexedDB.open(DB_NAME, 1);
req.onupgradeneeded = (e) => {
e.target.result.createObjectStore("store");
};
req.onsuccess = (e) => {
resolve();
};
});
}
function tryUpgrade() {
let req = indexedDB.open(DB_NAME, 2);
req.onblocked = () => {
println("FAIL: upgrade blocked, connection was not closed by GC");
done();
};
req.onupgradeneeded = () => {
println("PASS");
};
req.onsuccess = () => {
req.result.close();
indexedDB.deleteDatabase(DB_NAME);
done();
};
}
openAndForget().then(() => {
return internals.gcAsync()
}).then(() => {
tryUpgrade();
});
});
</script>