Last Comment Bug 510234 - `localStorage.clear()` doesn't actually delete its properties
: `localStorage.clear()` doesn't actually delete its properties
Status: RESOLVED FIXED
: html5, testcase
Product: Core
Classification: Components
Component: DOM (show other bugs)
: Trunk
: All All
: P2 normal with 1 vote (vote)
: mozilla1.9.2
Assigned To: Honza Bambas (:mayhemer)
:
Mentors:
javascript:void((function() {localSto...
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-08-13 09:45 PDT by Juriy "kangax" Zaytsev
Modified: 2013-04-04 13:53 PDT (History)
3 users (show)
jst: blocking1.9.2+
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---
beta4-fixed


Attachments
v1 [Checkin comment 6] (3.04 KB, patch)
2009-11-02 05:22 PST, Honza Bambas (:mayhemer)
jst: review+
jst: superreview+
Details | Diff | Review
as landed on 1.9.2 [Checking comment 8] (3.24 KB, patch)
2009-11-16 08:42 PST, Honza Bambas (:mayhemer)
no flags Details | Diff | Review

Description Juriy "kangax" Zaytsev 2009-08-13 09:45:46 PDT
User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2
Build Identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2

`localStorage` supports short accessor notation (as an alternative to `getItem`/`setItem`): 

localStorage.foo = 'bar';
localStorage.foo; // 'bar'

It also supports `clear()` method, which as per current "Web Storage" specs draft (http://www.w3.org/TR/webstorage/):

"... must atomically cause the list associated with the object to be emptied of all key/value pairs, if there are any. If there are none, then the method must do nothing."

What looks like a bug is that even after `clear()`, keys are still "present" in `localStorage`:

localStorage.foo = 'bar';
localStorage.clear();
'foo' in localStorage; // true

Is this an expected behavior? 

Note that the last statement returns `false` in at least WebKit and IE8 (and allows to check for presence of a value without resorting to a more verbose - `getItem(key) !== null`).

Thank you.

Reproducible: Always
Comment 1 Nickolay_Ponomarev 2009-09-19 11:00:12 PDT
The spec also says "The names of the supported named properties on a Storage  object are the keys of each key/value pair currently present in the list associated with the object.", so this looks like a bug.

See the URL field for testcase.

Confirmed in Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.3a1pre) Gecko/20090919 Minefield/3.7a1pre
Comment 2 Honza Bambas (:mayhemer) 2009-10-14 11:27:00 PDT
From jst on IRC: "I think that'd be a matter of finding the XPConnect wrapper for the localStorage object when calling clear, and calling JS_ClearScope() on its JSObject"
Comment 3 Johnny Stenback (:jst, jst@mozilla.com) 2009-10-14 11:52:01 PDT
I think we should block on this web compatibility bug for 1.9.2.
Comment 4 Honza Bambas (:mayhemer) 2009-11-02 05:22:23 PST
Created attachment 409678 [details] [diff] [review]
v1 [Checkin comment 6]
Comment 5 Johnny Stenback (:jst, jst@mozilla.com) 2009-11-03 14:36:21 PST
Comment on attachment 409678 [details] [diff] [review]
v1 [Checkin comment 6]

r+sr=jst
Comment 6 Honza Bambas (:mayhemer) 2009-11-11 12:42:11 PST
Comment on attachment 409678 [details] [diff] [review]
v1 [Checkin comment 6]

http://hg.mozilla.org/mozilla-central/rev/5df9f71b9e98
Comment 7 Mike Beltzner [:beltzner, not reading bugmail] 2009-11-12 07:33:00 PST
Comment on attachment 409678 [details] [diff] [review]
v1 [Checkin comment 6]

(this is a blocker, doesn't need explicit approval, please land ASAP)
Comment 8 Honza Bambas (:mayhemer) 2009-11-16 08:42:40 PST
Created attachment 412613 [details] [diff] [review]
as landed on 1.9.2 [Checking comment 8]

http://hg.mozilla.org/releases/mozilla-1.9.2/rev/247cda75bc87

Note You need to log in before you can comment on or make changes to this bug.