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

[whatwg] Overriding functions in DOM Storage

From: Ian Hickson <ian@hixie.ch>
Date: Fri, 10 Jul 2009 01:21:12 +0000 (UTC)
Message-ID: <Pine.LNX.4.62.0907100110360.23663@hixie.dreamhostps.com>
On Thu, 11 Jun 2009, Jeremy Orlow wrote:
> On Thu, Jun 11, 2009 at 12:36 PM, Jeremy Orlow <jorlow at google.com> wrote:
> > On Thu, Jun 11, 2009 at 11:52 AM, Ian Hickson <ian at hixie.ch> wrote:
> >> On Fri, 22 May 2009, Jeremy Orlow 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);
> >>
> >> The behaviour of these things are defined in WebIDL:
> >>
> >>   http://dev.w3.org/2006/webapi/WebIDL/
> >>
> >> ...which, as defined today, consists of setting 'removeItem' to a 
> >> function value that doesn't persist.
> 
> Also, does this mean that setting removeItem to null is ok?  What about 
> other (non-function) objects?
>
> What specific portion of WebIDL talks about this?  I'm having trouble 
> finding it.

http://dev.w3.org/2006/webapi/WebIDL/#put


On Thu, 11 Jun 2009, Jeremy Orlow wrote:
> 
> Sorry, but one more question (that I'm sure the spec answers, but I can't
> find that answer via searching):
> 
> What takes precedent when you do the following?
> 
> window.localStorage.setItem("removeItem", "blah");
> window.localStorage.removeItem = function (x) { // do something };
> alert(window.localStorage.removeItem);

First follow this algorithm for the setting of removeItem:

   http://dev.w3.org/2006/webapi/WebIDL/#put

...then follow this one for the getting of removeItem on the next line:

   http://dev.w3.org/2006/webapi/WebIDL/#get



> In Safari 4, the alert will show "blah".  Is this correct?

Not as far as I can tell. After calling setItem(), setting removeItem 
should work the same way as calling setItem() directly, since it's now on 
the list of named properties. So the third line takes the value set in the 
second.


> Also, what's the intended behavior when doing a "delete 
> window.localStorage.removeItem" after all of this?  Should it delete 
> both entries, just the function, or just the local storage map entry?  
> If it's one of the latter, should a subsequent delete call delete the 
> other?

http://dev.w3.org/2006/webapi/WebIDL/#delete


> I assume from what you said that a "window.localStorage.clear()" after 
> "window.localStorage.setItem("removeItem", "blah"); 
> window.localStorage.removeItem = function (x) { // do something };" 
> should leave just the function override?

No, because there is no function override in that case.


> Does the complexity of these corner cases worry anyone else?  :-)

Not really. :-)

It seems pretty simple to me.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Thursday, 9 July 2009 18:21:12 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:14 UTC