Eric --
I see what you're saying.  I created a quick test here:
http://lisbakken.com/gears/hello_world/workerpool_converts_instance/

It seems like if I run this in the html file:
new String('aa') instanceof String
I get true.

If I pass new String('aa') into the worker and have the worker do
message.body instanceof String then the result is false.

This doesn't seem like expected behavior, so I've contacted Aaron about this
to see if he can help you out.  I've added him to the thread.

-Ben


On Thu, Oct 9, 2008 at 8:47 AM, Eric Ayers <[EMAIL PROTECTED]> wrote:

>
> (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/
>

Reply via email to