[whatwg] Overriding functions in DOM Storage
Ian Hickson
ian at hixie.ch
Thu Jun 11 11:52:23 PDT 2009
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.
> Safari shows 2 alerts, and the second one says 'function'.
This appears to be correct according to WebIDL today.
> 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.
On Fri, 22 May 2009, Jeremy Orlow wrote:
>
> Never mind. "delete window.localStorage.clear;" should handle this use
> case.
Right.
On Fri, 22 May 2009, Jeremy Orlow wrote:
>
> The spec would also need to make it clear that removeItem, setItem, etc
> are special and should not be serialized to disk.
They are serialised to disk if you ever call the actual setter with those
names; it's just that in this case you never call that setter.
> That said, IE8 doesn't support the delete operator in this fashion and
> .clear() does not reset functions in Safari 4 (beta).
.clear() indeed would not affect the functions.
On Fri, 22 May 2009, Maciej Stachowiak wrote:
>
> DOM methods are normally overridable. That would make the Safari
> behavior correct. If we want the behavior to be different in this case,
> then the spec should spell that out. Perhaps part of the issue here is
> that the definition of the [NameSetter] extended attribute in Web IDL
> doesn't make clear whether or not name setter behavior takes precedence
> over setting existing predefined attributes or methods.
It seems clear to me.
On Tue, 26 May 2009, Jeremy Orlow wrote:
>
> What's special here is that everything set with the implicit
> getters/setters is supposed to be turned into a string. So yes this
> does seem somewhat unique.
The special setters aren't invoked in this particular case according to
WebIDL.
> I think it's important to decide which behavior makes the most sense and
> standardize on it. The way things are now is pretty useless to eveyone.
Implementors need to make sure they read WedIDL. :-)
On Tue, 26 May 2009, Jeremy Orlow wrote:
>
> Oh yeah, it's also a bit odd because values persist. Which doesn't
> really make sense if we allow functions to be overridden by functions,
> but does make sense if we're overriding them with strings.
They only persist if the custom setter is invoked.
--
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg
mailing list