[whatwg] Sending MessagePorts after they have started

Aaron Boodman wrote:
> On Fri, Nov 14, 2008 at 4:33 PM, Jonas Sicking <jonas at sicking.cc> wrote:
>> Hmm.. this makes a lot of sense for importScripts, but for XHR you probably
>> want the baseURI to be that of the opening page, since it's quite likely
>> that the opening page gave you a URI to open and process.
> 
> My expectation was that the base URI would always be the URI of the
> worker. I think of opening a worker a lot like starting a new process,
> or opening a new window. I would expect that the new process has its
> own base URI which is the same URI as the script it is running.

Indeed, and that is what the spec says. However I think in many cases 
for XHR that is probably not what is the most useful. Consider for example:


example.html:

w = new Worker("http://docs.google.com/MSWordParser.js");
w.onmessage = function (e) {
   doneLoadingDoc(JSON.parse(e.data));
}
w.postMessage("/documents/report.doc");


MSWordParser.js:

onmessage = function(e) {
   xhr = new XMLHttpRequest();
   xhr.open("GET", e.data, false);
   xhr.send();
   res = mainParse(xhr.responseText);
   postMessage(JSON.stringify(res));
}


The above won't work since the URL is relative to the worker JS file, 
not relative to example.html. So an absolute URI always needs to be used 
which sort of sucks as is unintuitive from the point of view of most DOM 
APIs today.

I don't really have a good solution to propose though. We might need to 
add an API for resolving relative URIs and require that scripts use that 
manually.

/ Jonas

Received on Friday, 14 November 2008 17:26:50 UTC