I had originally tried on Safari 4.0.4 on OSX but just tried on Chrome (win)
and FF and got the same results.

So what you have is fine, the type returned on calling Boolean.apply(null,
[Object(true)] ) is indeed boolean.

The issue is that the value returned is incorrect when the original val is
false.

So try x = Object(false) and then echo the value of y. I'm getting a return
value of boolean 'true' instead of boolean 'false'



On Sun, Apr 11, 2010 at 4:03 PM, Ray Cromwell <cromwell...@gmail.com> wrote:

> Interesting, which browser? I just tried this in the Chrome console:
> x = Object(true)
> typeof(x) => "object"
> y = Boolean.apply(null, [x]);
> typeof(y) => "boolean"
>
> -Ray
>
>
> On Sun, Apr 11, 2010 at 6:32 AM, Sanjiv Jivan <sanjiv.ji...@gmail.com>
> wrote:
> > Thank's for the tip Ray. Unfortunately I'm not seeing the desired results
> > with Boolean, while Number works fine. However .valueOf() does return the
> > correct result.
> > Boolean.apply(null, [Object(false)])
> > true
> > Number.apply(null, [Object(5)])
> > 5
> > (Object(false)).valueOf()
> > false
> > (Object(true)).valueOf()
> > true
> > (Object(5)).valueOf()
> > 5
> > (Object("foobar")).valueOf()
> > "foobar"
> > Object("foobar")
> > String
> >
> > So I have altered the debox function to call valueOf() instead of
> apply(..)
> > and it appears to be working fine with my limited testing.
> > // no longer need to pass typeCast arg
> > $debox = function(val, typeCast) {
> >     return @com.google.gwt.core.client.GWT::isScript()() ? val :
> function()
> > {
> >     var v = val.apply(this, arguments);
> >     //return typeCast.apply(null, v == undefined ? [] : [v]);
> >     return v == null ? null : v.valueOf();
> > }};
> > I'll only be calling debox(..) for functions that have a Javascript
> > primitive return types including String type. The reason for applying it
> to
> > a String as well is because of this issue
> > : http://code.google.com/p/google-web-toolkit/issues/detail?id=4301
> > Let me know your thoughts..
> > Thanks,
> > Sanjiv
> >
> > On Sat, Apr 10, 2010 at 9:28 PM, Ray Cromwell <cromwell...@gmail.com>
> wrote:
> >>
> >> Bob's old proposal was to introduce an "Any" type which is the
> >> supertype of all types, including primitives. As a short term fix, you
> >> can do what I did in GWT Exporter and de-box these values. If you are
> >> trying to export JS functions, then you can have a function like:
> >>
> >> function debox(val, typeCast) {
> >>  return isScript ? val : typeCast.apply(null, arguments);
> >> }
> >>
> >> and then, debox($entry(...), Boolean) will return a 'boolean', and
> >> debox($entry(...), Number) will return a 'number'
> >>
> >> -Ray
> >>
> >> On Sat, Apr 10, 2010 at 6:24 PM, John Tamplin <j...@google.com> wrote:
> >> > On Sat, Apr 10, 2010 at 7:37 PM, Sanjiv Jivan <sanjiv.ji...@gmail.com
> >
> >> > wrote:
> >> >>
> >> >>   private static native Object apply(Object jsFunction, Object
> thisObj,
> >> >>       Object arguments) /*-{
> >> >>     if (@com.google.gwt.core.client.GWT::isScript()()) {
> >> >>       return jsFunction.apply(thisObj, arguments);
> >> >>     } else {
> >> >>       _ = jsFunction.apply(thisObj, arguments);
> >> >>       if (_ != null) {
> >> >>         // Wrap for hosted mode
> >> >>         _ = Object(_);
> >> >>       }
> >> >>       return _;
> >> >>     }
> >> >>   }-*/;
> >> >> What is the rationale for this wrapping as Object(..) in hosted mode?
> >> >> And
> >> >> can you suggest a workaround for this usecase?
> >> >
> >> > Notice the return type -- you can't return a JS primitive as an
> Object,
> >> > but
> >> > a JavaScriptObject can be returned as an Object.
> >> > I have cc'd BobV who wrote this -- perhaps he can suggest a
> workaround.
> >> > --
> >> > John A. Tamplin
> >> > Software Engineer (GWT), Google
> >> >
> >> > --
> >> > http://groups.google.com/group/Google-Web-Toolkit-Contributors
> >>
> >> --
> >> http://groups.google.com/group/Google-Web-Toolkit-Contributors
> >>
> >> To unsubscribe, reply using "remove me" as the subject.
> >
> > --
> > http://groups.google.com/group/Google-Web-Toolkit-Contributors
>
> --
> http://groups.google.com/group/Google-Web-Toolkit-Contributors
>

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to