Closed Bug 340072 Opened 18 years ago Closed 18 years ago

No increasing number value in session and persistent storage

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID
mozilla1.8.1beta1

People

(Reporter: channy, Unassigned)

References

()

Details

There is very simple sample code in http://www.whatwg.org/specs/web-apps/current-work/#introduction2. But it doesn't work a sample code of increasing page count in Bon Echo alpha 3. You can see this bug in http://channy.creation.net/work/firefox/domstorage/ too.
Blocks: 335540
I checked the code in the sample and found the sample code is somewhat misleading. Here is the problemtic code.

  if (!storage.pageLoadCount)
    storage.pageLoadCount = 0;
  storage.pageLoadCount += 1;
  document.getElementById('count').textContent = storage.pageLoadCount;

In the spec, storage item has string (DOMString) value. Thus, 0 is converted into "0" when saved into storage. And "0" + 1 in the next statement results "01" following javascript datat type conversion.

In short, the problem does not lie in the implementataion but in the sample code. It should be modified like below.

  -- storage.pageLoadCount += 1;
  ++ storage.pageLoadCount = parseInt(storage.pageLoadCount) + 1;
I had chat with Channy and learned that he notified this to WHATWG list. 

http://listserver.dreamhost.com/pipermail/whatwg-whatwg.org/2006-June/006515.html
Thanks. I followed up this to WHATWG mailing list to correct sample code.
But, I'm not sure to clode this bug. After a feedback from WHATWG, I'll decide it.
Spec has been fixed. Thanks for reporting it!
I believe Mozilla works per spec here (now that the spec has been fixed). Marking INVALID.
Status: NEW → RESOLVED
Closed: 18 years ago
OS: Windows 2000 → All
Hardware: PC → All
Resolution: --- → INVALID
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.