This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 19540 - Firing WebStorage storage event
Summary: Firing WebStorage storage event
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: Web Storage (editor: Ian Hickson) (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-15 12:19 UTC by Janusz Majnert
Modified: 2016-02-05 06:16 UTC (History)
4 users (show)

See Also:


Attachments

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.
Comment 6 dewa 2016-02-05 06:16:13 UTC
(In reply to Ian 'Hixie' Hickson from comment #3)
> Yeah, that could have been clearer. How is it now? Please don't hesitate to
> reopen this bug if it's still not clear.

Sorry for respond such a old thread, but I have unclear point about storage event firing rule. If it makes sense, please response. The point is "Should this event occur in Window document that causes this result?" I know this event for "other" document in other window to recognize a Storage object change, but how about itself? The specification seems to be unclear this point. Nothing happens in the document makes changes. Correct?