Doh, you've right, boy do I love Javascript. "If you specify any object, including a Boolean object whose value is false, as the initial value of a Boolean object, the new Boolean object has a value of true."
-Ray On Sun, Apr 11, 2010 at 4:24 PM, Sanjiv Jivan <[email protected]> wrote: > 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 <[email protected]> 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 <[email protected]> >> 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 <[email protected]> >> > 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 <[email protected]> wrote: >> >> > On Sat, Apr 10, 2010 at 7:37 PM, Sanjiv Jivan >> >> > <[email protected]> >> >> > 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 -- http://groups.google.com/group/Google-Web-Toolkit-Contributors
