Re: [whatwg] question about Web Storage setItem()'s behavior

2009-08-12 Thread Ian Hickson
On Sun, 2 Aug 2009, Jeremy Orlow wrote:
 On Sun, Aug 2, 2009 at 7:17 PM, 白石俊平 shumpei.shirai...@gmail.com wrote:
 
  I'm implementing the HTML5 Web Storage using Gears
  (http://code.google.com/p/gear5/), so I have several questions with
  the spec.
 
  -Storage.setItem(key, val)
  --is key allowed non-string type object?
 
 Yes, but...
 
 --and when pass non-string object to key/value, is it automatically
  converted to string?(I'm considering to convert to use String
  constructor - String(key) )
 
 Yes.

Correct.


  --when value is null, should `setItem(key, null)` behave as like as
  `removeItem(key)`? (localStorage.setItem(key, null);
  alert(localStorage.length); -- what is value displayed?)
 
 No, it's not the same as removeItem.  It'll be set to 'null'.

This changed recently; it'll now actually store the null value.

-- 
Ian Hickson   U+1047E)\._.,--,'``.fL
http://ln.hixie.ch/   U+263A/,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Re: [whatwg] question about Web Storage setItem()'s behavior

2009-08-12 Thread 白石俊平
Thanks, Ian.

  --when value is null, should `setItem(key, null)` behave as like as
  `removeItem(key)`? (localStorage.setItem(key, null);
  alert(localStorage.length); -- what is value displayed?)

 No, it's not the same as removeItem.  It'll be set to 'null'.

 This changed recently; it'll now actually store the null value.

OK, I see.

and, when passed value is undefined (e.g. `setItem(key)`), which
behavior will be correct?
On current implementation of browsers, I looked as follows.
- IE and Firefox raise error, (arguments number is incorrect)
- Webkit family persist it as string (undefined)


On Wed, Aug 12, 2009 at 4:10 PM, Ian Hicksoni...@hixie.ch wrote:
 On Sun, 2 Aug 2009, Jeremy Orlow wrote:
 On Sun, Aug 2, 2009 at 7:17 PM, 白石俊平 shumpei.shirai...@gmail.com wrote:
 
  I'm implementing the HTML5 Web Storage using Gears
  (http://code.google.com/p/gear5/), so I have several questions with
  the spec.
 
  -Storage.setItem(key, val)
  --is key allowed non-string type object?

 Yes, but...

 --and when pass non-string object to key/value, is it automatically
  converted to string?(I'm considering to convert to use String
  constructor - String(key) )

 Yes.

 Correct.


  --when value is null, should `setItem(key, null)` behave as like as
  `removeItem(key)`? (localStorage.setItem(key, null);
  alert(localStorage.length); -- what is value displayed?)

 No, it's not the same as removeItem.  It'll be set to 'null'.

 This changed recently; it'll now actually store the null value.

 --
 Ian Hickson               U+1047E                )\._.,--,'``.    fL
 http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
 Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


Re: [whatwg] question about Web Storage setItem()'s behavior

2009-08-12 Thread Ian Hickson
On Wed, 12 Aug 2009, �~Y��~_���~J平 wrote:
 
 and, when passed value is undefined (e.g. `setItem(key)`), which
 behavior will be correct?
 On current implementation of browsers, I looked as follows.
 - IE and Firefox raise error, (arguments number is incorrect)
 - Webkit family persist it as string (undefined)

I believe WebIDL says that a TypeError exception should be thrown, but it 
was not immediately obvious to me how to derive this from the spec.

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

-- 
Ian Hickson   U+1047E)\._.,--,'``.fL
http://ln.hixie.ch/   U+263A/,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Re: [whatwg] question about Web Storage setItem()'s behavior

2009-08-12 Thread 白石俊平
 I believe WebIDL says that a TypeError exception should be thrown, but it
 was not immediately obvious to me how to derive this from the spec.

Ok, I understood what behavior is correct (and that current webkit's
behavior is a bit wrong).

very thanks.

On Wed, Aug 12, 2009 at 5:34 PM, Ian Hicksoni...@hixie.ch wrote:
 On Wed, 12 Aug 2009, į~Y―į~_ģäŋ~Jåđģ wrote:

 and, when passed value is undefined (e.g. `setItem(key)`), which
 behavior will be correct?
 On current implementation of browsers, I looked as follows.
 - IE and Firefox raise error, (arguments number is incorrect)
 - Webkit family persist it as string (undefined)

 I believe WebIDL says that a TypeError exception should be thrown, but it
 was not immediately obvious to me how to derive this from the spec.

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

 --
 Ian Hickson               U+1047E                )\._.,--,'``.    fL
 http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
 Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


Re: [whatwg] question about Web Storage setItem()'s behavior

2009-08-12 Thread Jeremy Orlow
On Wed, Aug 12, 2009 at 1:34 AM, Ian Hickson i...@hixie.ch wrote:

 On Wed, 12 Aug 2009, į~Y―į~_ģäŋ~Jåđģ wrote:
 
  and, when passed value is undefined (e.g. `setItem(key)`), which
  behavior will be correct?
  On current implementation of browsers, I looked as follows.
  - IE and Firefox raise error, (arguments number is incorrect)
  - Webkit family persist it as string (undefined)

 I believe WebIDL says that a TypeError exception should be thrown, but it
 was not immediately obvious to me how to derive this from the spec.


I believe this is the correct section of the spec to be looking at:
http://dev.w3.org/2006/webapi/WebIDL/#es-DOMString
If so, I think it's pretty clear that Safari's implementation is correct on
this issue.


Re: [whatwg] question about Web Storage setItem()'s behavior

2009-08-12 Thread Boris Zbarsky

Jeremy Orlow wrote:

  and, when passed value is undefined (e.g. `setItem(key)`), which
  behavior will be correct?

...

I believe this is the correct section of the spec to be looking 
at: http://dev.w3.org/2006/webapi/WebIDL/#es-DOMString


If so, I think it's pretty clear that Safari's implementation is correct 
on this issue.


Given the actual example code (and not its description, which doesn't 
match the code), the relevant section is 
http://dev.w3.org/2006/webapi/WebIDL/#es-operations steps 1 through 3 in 
the third bullet point.


It looks to me like per the current spec text that will throw a 
TypeError for the above call, unless the second argument to setItem is 
marked [optional].


-Boris


Re: [whatwg] question about Web Storage setItem()'s behavior

2009-08-12 Thread Cameron McCormack
Boris Zbarsky:
 Given the actual example code (and not its description, which
 doesn't match the code), the relevant section is
 http://dev.w3.org/2006/webapi/WebIDL/#es-operations steps 1 through
 3 in the third bullet point.
 
 It looks to me like per the current spec text that will throw a
 TypeError for the above call, unless the second argument to setItem
 is marked [optional].

Yeah I think that’s right.  I’ll just note though that behaviour when
passing too many or too few arguments is still an open issue (although
it’s more likely that the ‘too many’ case will change than the ‘too few’
case).

OTOH, passing in undefined explicitly as the second argument would have
it converted to the string undefined.

-- 
Cameron McCormack ≝ http://mcc.id.au/


Re: [whatwg] question about Web Storage setItem()'s behavior

2009-08-12 Thread Jeremy Orlow
On Wed, Aug 12, 2009 at 4:26 PM, Cameron McCormack c...@mcc.id.au wrote:

 Boris Zbarsky:
  Given the actual example code (and not its description, which
  doesn't match the code), the relevant section is
  http://dev.w3.org/2006/webapi/WebIDL/#es-operations steps 1 through
  3 in the third bullet point.
 
  It looks to me like per the current spec text that will throw a
  TypeError for the above call, unless the second argument to setItem
  is marked [optional].

 Yeah I think that’s right.  I’ll just note though that behaviour when
 passing too many or too few arguments is still an open issue (although
 it’s more likely that the ‘too many’ case will change than the ‘too few’
 case).

 OTOH, passing in undefined explicitly as the second argument would have
 it converted to the string undefined.


Thanks for the clarification.  I'll file a bug on WebKit.


Re: [whatwg] question about Web Storage setItem()'s behavior

2009-08-02 Thread Jeremy Orlow
On Sun, Aug 2, 2009 at 7:17 PM, 白石俊平 shumpei.shirai...@gmail.com wrote:

 Hi,

 I'm implementing the HTML5 Web Storage using Gears
 (http://code.google.com/p/gear5/), so I have several questions with
 the spec.

 -Storage.setItem(key, val)
 --is key allowed non-string type object?


Yes, but...

--and when pass non-string object to key/value, is it automatically
 converted to string?(I'm considering to convert to use String
 constructor - String(key) )


Yes.



 --when value is null, should `setItem(key, null)` behave as like as
 `removeItem(key)`? (localStorage.setItem(key, null);
 alert(localStorage.length); -- what is value displayed?)


No, it's not the same as removeItem.  It'll be set to 'null'.

Check out Safari 4's implementation if you'd like to see the correct
behavior for all of these cases.  I've been spending a lot of time with it,
and it matches the spec in every case I've tried.  (And I've tried a
lot...I'm working on it for Chromium.)  :-)

J


Re: [whatwg] question about Web Storage setItem()'s behavior

2009-08-02 Thread 白石俊平
Hi,

OK, I'll check the Safari4's implementation.

Very thanks, Jeremy.


On Mon, Aug 3, 2009 at 11:41 AM, Jeremy Orlowjor...@chromium.org wrote:
 On Sun, Aug 2, 2009 at 7:17 PM, 白石俊平 shumpei.shirai...@gmail.com wrote:

 Hi,

 I'm implementing the HTML5 Web Storage using Gears
 (http://code.google.com/p/gear5/), so I have several questions with
 the spec.

 -Storage.setItem(key, val)
 --is key allowed non-string type object?

 Yes, but...

 --and when pass non-string object to key/value, is it automatically
 converted to string?(I'm considering to convert to use String
 constructor - String(key) )

 Yes.


 --when value is null, should `setItem(key, null)` behave as like as
 `removeItem(key)`? (localStorage.setItem(key, null);
 alert(localStorage.length); -- what is value displayed?)

 No, it's not the same as removeItem.  It'll be set to 'null'.
 Check out Safari 4's implementation if you'd like to see the correct
 behavior for all of these cases.  I've been spending a lot of time with it,
 and it matches the spec in every case I've tried.  (And I've tried a
 lot...I'm working on it for Chromium.)  :-)
 J