W3C home > Mailing lists > Public > whatwg@whatwg.org > May 2009

[whatwg] Overriding functions in DOM Storage

From: Jeremy Orlow <jorlow@google.com>
Date: Fri, 22 May 2009 17:51:29 -0700
Message-ID: <5dd9e5c50905221751h6c8b511el26cd0de85337e88e@mail.gmail.com>
On Fri, May 22, 2009 at 5:41 PM, Jeremy Orlow <jorlow at google.com> wrote:

> What is the behavior of the following supposed to be?
>
> window.sessionStorage.removeItem = function(x) { alert("Wait, this
> works?"); };
> window.sessionStorage.removeItem('blah');
> alert(typeof window.sessionStorage.removeItem);
>
> Safari shows 2 alerts, and the second one says 'function'.
> IE8 says "object doesn't support this property or method" if line 2 isn't
> commented out.  It returns type string when it is.
> Mozilla also won't run if line 2 is there, but it returns type object for
> line 3.
>
> It seems to me that if IE8's behavior is correct, those parameters should
> be marked as read-only since overriding them could only be used to shoot
> yourself in the foot.
>
> If Safari's implementation is correct (and it's good for the
> implementations to be overridable), then I believe there needs to be some
> safe way to make .clear() usable again.  (Otherwise, once you override
> removeItem() and clear(), there's not really any way to recover.)
>

Never mind.  "delete window.localStorage.clear;" should handle this use
case.

That said, IE8 doesn't support the delete operator in this fashion and
.clear() does not reset functions in Safari 4 (beta).


> The spec would also need to make it clear that removeItem, setItem, etc are
> special and should not be serialized to disk.
>
> Apologies if this is clear in the spec and I somehow missed it.  But, if
> not, I think a clarification might be necessary.
>
> J
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20090522/b1b0c49a/attachment.htm>
Received on Friday, 22 May 2009 17:51:29 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:49 UTC