[whatwg] Accessing cookies from workers

2009/3/9 Jonas Sicking <jonas at sicking.cc>:
> On Mon, Mar 9, 2009 at 11:26 AM, Giovanni Campagna
> <scampa.giovanni at gmail.com> wrote:
>> 2009/3/9 Jonas Sicking <jonas at sicking.cc>:
>>> On Mon, Mar 9, 2009 at 11:01 AM, Giovanni Campagna
>>>> This can be even worse: how would you syncronize the code in the
>>>> callback with code right after the call? You don't have any of
>>>> semaphores or mutexes in ES and I don't expect them to be added soon.
>>>
>>> I'm not sure I understand the problem you are describing. Could you
>>> show an example using the APIs that exist in the spec today and with
>>> an async cookie API added?
>>
>> var x = 7;
>> function callback(cookies) {
>> x = 5;
>> }
>> getAllCookies(callback);
>> alert(x == 7);
>
> True. The callback can't happen in the middle of executing code.
> Javascript uses a run-to-completion model.

1) what does that mean?
The code in the callback is executed before reaching code outside
// doesn't seem very asyncronous
-or-
the code is executed after everything outside is already gone
// doesn't seem very useful, because code outside needs the result of
the cookie dependent routine
-or-
the code is executed in certain specific moments (when the thread is
waiting on a native call)
// doesn't seem very reliable, unless we specify what "native call" means

2) where is that specified?
I don't remember if the original Ecma262 has something about asyncronous calls

and most important
3) why it did actually happen in my code? (using an async XHR)

> / Jonas
>

Giovanni

@Drew:
If you don't want that workers set cookies in the middle of a JS block
in another browsing context, you just need to add a mutex at the
beginning of JS threads (timeout / intervals and event handlers), then
lock on that mutex in the setCookie.
This would make the call syncronous without problems for the JS developer.

Received on Monday, 9 March 2009 11:46:27 UTC