(I apologize if this is a repeat post, apparently I was not subscribed
to the group before)
I am working on bindings for the Gears API for the Google Web Toolkit.
The WorkerPool API supports sending messages to another worker
including primitive types, Arrays, or Objects.
I'm running into trouble when I try to send a boxed type from the child.
Here's my test case worker string:
function workerInit() {
google.gears.workerPool.onmessage = function(a, b, message) {
var returnMessage = 'error';
if (message.body == 'boolean') {
returnMessage = true;
} else if (message.body == 'Boolean') {
returnMessage = new Boolean(true);
} else if (message.body == 'string') {
returnMessage = 'string';
} else if (message.body == 'String') {
returnMessage = new String('stringValue');
} else if (message.body == 'double') {
returnMessage = 1.0;
} else if (message.body == 'Double') {
returnMessage = new Number(1.0);
} else if (message.body == 'object') {
returnMessage = new Object(); returnMessage.foo = 1;
}
google.gears.workerPool.sendMessage(returnMessage, message.sender);
};
}
workerInit();
The primitve types work fine. I can detect them with 'typeof()'. The
boxed types all come out as 'object' when tested with 'typeof' as
expected. However, in the onmessage callback, The 'instanceof'
operator never returns true when I test messageObject.body.
messageObject.body instanceof Boolean
messageObject.body instanceof Number
messageObject.body instanceof String
Converting the Boolean(true) to a string seems to work, but converting
Number(1.0) and String('stringValue') to a primitive string gives me
results like: [object Object]
For the instanceof failing, I imagine this might have to do with the
'window' object not being available in the worker thread and therefore
the constructors not matching.
I'm trying to wrap up this issue ASAP for a release of the bindings.
Any suggestions for what to do in these cases? I don't necessarily
need a code solution - I could just tell users to avoid these
scenarios.
My development environment is:
FF3.0.3, MacOS X 10.5.5, Gears 0.4.20.0
--
Eric Z. Ayers - GWT Team - Atlanta, GA USA
http://code.google.com/webtoolkit/