Bug 19540 - Firing WebStorage storage event
Firing WebStorage storage event
Status: RESOLVED FIXED
Product: WebAppsWG
Classification: Unclassified
Component: Web Storage (editor: Ian Hickson)
unspecified
PC Linux
: P2 normal
: ---
Assigned To: Ian 'Hixie' Hickson
public-webapps-bugzilla
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-10-15 12:19 UTC by Janusz Majnert
Modified: 2012-12-31 07:58 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Janusz Majnert 2012-10-15 12:19:16 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
(http://www.whatwg.org/specs/web-apps/current-work/multipage/webstorage.html#the-localstorage-attribute)
we have this sentence [1]:
"
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
described below.
"


"as described below" points to section 11.2.4, which reads [2]:
"
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 [1] says that storage events should be fired on affected
Document objects, except the one that originated the change.
Sentences in [2]  say that when a storage event is fired as described
in [1], 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?
Comment 1 contributor 2012-12-18 22:29:56 UTC
Checked in as WHATWG revision r7592.
Check-in comment: Try to clarify how 'storage' events are sent.
http://html5.org/tools/web-apps-tracker?from=7591&to=7592
Comment 2 Janusz Majnert 2012-12-19 07:46:11 UTC
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:

localStorage.setItem('key1','value1');
localStorage.setItem('key1','value1');

When running the above code, should UA generate one or two storage events?
Comment 3 Ian 'Hixie' Hickson 2012-12-30 19:44:16 UTC
Yeah, that could have been clearer. How is it now? Please don't hesitate to reopen this bug if it's still not clear.
Comment 4 contributor 2012-12-30 19:45:36 UTC
Checked in as WHATWG revision r7615.
Check-in comment: Try to clarify when 'storage' even fires.
http://html5.org/tools/web-apps-tracker?from=7614&to=7615
Comment 5 Janusz Majnert 2012-12-31 07:58:13 UTC
I think it's OK now. Thanks.