mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 09:45:06 +02:00
Storage objects are created lazily when window.localStorage or window.sessionStorage is first accessed. Previously, broadcast() iterated over already-created Storage objects, so windows that had never accessed these properties would not receive storage events. Fix this by iterating over all active windows and initializing Storage objects as part of the broadcast loop so all eligible windows receive the event regardless of whether they had previously accessed their storage property.
31 lines
1.1 KiB
HTML
31 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<script src="../include.js"></script>
|
|
<script>
|
|
// Verify that a storage event is fired to a window that has not yet accessed
|
|
// sessionStorage - i.e. its Storage object has not yet been lazily created.
|
|
// See: https://github.com/whatwg/html/issues/10135
|
|
asyncTest(async (done) => {
|
|
const key = 'my-key';
|
|
|
|
const eventReceived = Promise.withResolvers();
|
|
window.onStorageEventReceived = eventReceived.resolve;
|
|
|
|
const iframe = document.createElement('iframe');
|
|
iframe.src = '../../data/session-storage-event-iframe.html';
|
|
const iframeLoaded = new Promise(resolve => { iframe.onload = resolve; });
|
|
document.body.appendChild(iframe);
|
|
await iframeLoaded;
|
|
|
|
sessionStorage.setItem(key, 'hello');
|
|
|
|
const e = await eventReceived.promise;
|
|
println(`key: ${key}`);
|
|
println(`oldValue: ${e.oldValue}`);
|
|
println(`newValue: ${e.newValue}`);
|
|
println(`storageArea: ${e.storageAreaString}`);
|
|
|
|
sessionStorage.removeItem(key);
|
|
done();
|
|
});
|
|
</script>
|