YuzuJS/setImmediate

there is no "window" inside WebWorker

Yaffle opened this issue · 16 comments

there is no "window" inside WebWorker

I cannot see how the title you have given this (empty) issue applies at all to our setImmediate implementation. Please explain and I will reopen if it makes sense.

index.html:

var x = new Worker('webworker.js');

webworker.js:

setImmediate(....); -> window is undefined....

OK, I think I have a working implementation of setImmediate for web worker use; it works inside the latest stable Chrome and Firefox. Can you test my fork at https://github.com/DomenicDenicola/setImmediate and see if it's working as expected? If so I will pull it back into the NobleJS repository.

it works good
Opera 11 and Chrome 14 tested

see my test files here:
https://gist.github.com/1235275

Also, It seems, Firefox 6 hasn't minimum delay for setTimeout, so setTimeout(..., 0) works as setImmediate
in Workers

but some problems with setImmediate undef IE8 ...

According to http://caniuse.com/#webworkers IE doesn't support web workers until IE10.

i know, i test outside worker, on single page,
IE 8 standart mode

I believe the problem here is that postMessage doesn't work properly with local files in IE8. Are you testing locally, or with a web server?

http://localhost

it will be good to create some tests in repo

Darn, OK. Do you know if the NobleJS setImmediate (i.e. not the one in my fork) works in IE8 on localhost? I'm trying to figure out if the changes in the fork broke it, or if it's never worked there.

i can't test it now, i'll try later

changes in fork doesn't broke it!

in master repo (and fork too)
there are 3 mistakes:

window.attachEvent("message", handleMessage);

should be
window.attachEvent("onmessage", handleMessage);

  1. in IE event.source !== window
    is "event.source === window" usefull ?

3);
IE8 postMessage is synchronous
so it can't be used to emulate setImmediate
http://www.google.ru/search?client=opera&rls=ru&q=IE8+postMessage+is+synchronous&sourceid=opera&ie=utf-8&oe=utf-8&channel=suggest

Seems,

you meen "Doen setImmediate is syncronouse/asyncronouse" in use test/test.js:

"Does setImmediate yield to subsequent code before executing its callback"

var syncronouse = false;
function atest() {
syncronouse = true;
};
window.onmessage = atest;
window.postMessage('', '*');
window.onmessage = null;
if (synconouse) {
can't use postMessage for setImmediate
}

Thanks Yaffle! I did a major refactor incorporating your fixes; IE8 now falls back to setTimeout(..., 0) and has been tested to work. I'll look at your pull request later to hopefully incorporate some of those tests into the repository as well.