[whatwg] Accessing cookies from workers

Drew Wilson atwilson at google.com
Mon Mar 9 12:43:15 PDT 2009


Following up on this. I created two pages, one that tests cookies in a loop,
and one that sets cookies in a loop, and ran them in separate windows in
Firefox 3, IE7, and Chrome.

Chrome and IE7 currently allow concurrent modification of document.cookies
(i.e. the test loop throws up an alert). Firefox does not.

My two pages are below - do you see any problems with my test? If not, I'd
like to propose that browsers do not currently impose any guarantees as to
the immutability of document.cookies, so there's no reason not to support
synchronous access to cookies from workers.

-atw

<html>
<head>
</head>
<body>
  Testing cookies: <span id="log">0</span>
  <a href="#" onclick="cookieTest()">Start</a>
  <script>
    var count = 1;
    function cookieTest() {
      var a = document.cookie;
      for (var i = 0 ; i < 10000 ; i++) {
        var b = document.cookie;
        if (a != b) {
          alert("a: " + a + "\nb:" + b);
        }
      }
      setTimeout(cookieTest, 0);
      document.getElementById('log').innerHTML = count++;
    };
  </script>

</body>
</html>


<html>
<head>
</head>
<body>
  setCookies: <span id="log">0</span>
  <a href="#" onclick="cookieSet()">Start</a>
  <script>
    var count = 1;
    function cookieSet() {
      for (var i = 0 ; i < 10000 ; i++) {
        document.cookie = ("cookieSetVal=" + i);
      }
      setTimeout(cookieSet, 0);
      document.getElementById('log').innerHTML = count++;
    };
  </script>
</body>
</html>


On Mon, Mar 9, 2009 at 11:38 AM, Drew Wilson <atwilson at google.com> wrote:

>
>
> On Mon, Mar 9, 2009 at 10:23 AM, Jonas Sicking <jonas at sicking.cc> wrote:
>
>>
>> The problem is that people are likely to write code like:
>>
>> if (self.getAllCookies() != "magic value") {
>>  a = self.getAllCookies();
>>  ...do stuff...
>> }
>>
>> at that point it's entirely possible for 'a' to have the value "magic
>> value" which is likely to cause the script to break.
>
>
> Here we are making assumptions about how people will use routines that
> don't actually exist yet. If you were to substitute "new Date().getTime()"
> for "self.getAllCookies()" in the code above, I think we'd all agree that
> the user expectation is faulty - is it not feasible to state that, just like
> Date().getTime(),. getAllCookies() returns a snapshot of a mutable value?
>
> I'm OK with making setCookie() asynchronous, because I think there may be a
> valid point that you don't want new worker code to suddenly break existing
> JS code that expects document.cookies to remain immutable across a single
> block of execution. But I don't see that argument extending to
> getAllCookies().
>
>
>>
>> Indeed. It does seem like you would be able to ask ;)
>>
>
> I'm looking into this now, actually :) - I'll let you know what I find out.
>
> -atw
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20090309/027f7c0a/attachment-0002.htm>


More information about the whatwg mailing list