That seems fine, you're just mirroring the bad API design of Gears,
silently swallowing types it doesn't understand :).

- a

On Mon, Oct 13, 2008 at 12:31 PM, Eric Ayers <[EMAIL PROTECTED]> wrote:
>
> I have no problem with not using Boxed types, but I am not the one
> writing the worker code here.  I'm just providing bindings from
> JavaScript to Java to read messages, so I have to create an method in
> Java for each type to return.  If boxed types aren't supported, that's
> fine, I'll just note it as such in the javadoc.
>
> Thanks for the response,
> -Eric.
>
> On Mon, Oct 13, 2008 at 3:26 PM, Aaron Boodman <[EMAIL PROTECTED]> wrote:
>>
>> I'm sorry for the long delay, I missed this message in my inbox.
>>
>> This is an interesting question. The answer is that boxed primitive
>> types are not supported, nor are any other types other than exactly:
>>
>> boolean, number, null, undefined, string, Blob
>>
>> What happens when you try to send a boxed primitive through is that
>> Gears recognizes it as an Object and tries to clone its properties to
>> the worker. In the case of boxed primitives, there often are no
>> properties. Even if there are, on the other side it is created as
>> Object, not whatever the original constructor was.
>>
>> Can you just use primitives?
>>
>> - a
>>
>> On Thu, Oct 9, 2008 at 8:47 AM, Eric Ayers <[EMAIL PROTECTED]> wrote:
>>> 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/
>>>
>>
>
>
>
> --
> Eric Z. Ayers - GWT Team - Atlanta, GA USA
> http://code.google.com/webtoolkit/
>

Reply via email to