Bugzilla – Bug 19540
Firing WebStorage storage event
Last modified: 2012-12-31 07:58:13 UTC
When trying to implement local storage I found it hard to understand the rules for firing the "storage" event.
In section 11.2.3
we have this sentence :
When the setItem(), removeItem(), and clear() methods are called on a
Storage object x that is associated with a local storage area, if the
methods did something, then in every Document object whose Window
object's localStorage attribute's Storage object is associated with
the same storage area, other than x, a storage event must be fired, as
"as described below" points to section 11.2.4, which reads :
The storage event is fired when a storage area changes, as described
in the previous two sections (for session storage, for local storage).
When this happens, the user agent must queue a task to fire an event
with the name storage, which does not bubble and is not cancelable,
and which uses the StorageEvent interface, at each Window object whose
Document object has a Storage object that is affected.
What I understood:
Sentence  says that storage events should be fired on affected
Document objects, except the one that originated the change.
Sentences in  say that when a storage event is fired as described
in , a task must be queued to fire storage events on all affected
Window objects. It also says that Document objects have Storage
objects, which I don't think is true.
Is my understanding correct? What am I missing?
Checked in as WHATWG revision r7592.
Check-in comment: Try to clarify how 'storage' events are sent.
Looks good to me now. Two things though:
1. Typo: "events are fired on the Window objecys".
2. I'm not sure how the condition "if the methods did something" evaluates for this code:
When running the above code, should UA generate one or two storage events?
Yeah, that could have been clearer. How is it now? Please don't hesitate to reopen this bug if it's still not clear.
Checked in as WHATWG revision r7615.
Check-in comment: Try to clarify when 'storage' even fires.
I think it's OK now. Thanks.