Re: [gwt-contrib] $entry and wrapping result as Object in hosted mode
On Sun, Apr 11, 2010 at 9:36 PM, Ray Cromwell cromwell...@gmail.com wrote: 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. That is the primary reason DevMode doesn't unbox primites for you (we do for Strings, because in every way they are used in generated JS they behave the same, plus you have little control over when you get a string pimitive vs a String object). private native boolean getFlag() /*-{ return Boolean(false); }-*/; private native void useFlag(boolean flag) /*-{ window.alert(flag ? true : false); }-*/; private void showFlag() { useFlag(getFlag()); } will show false in web mode, and there really isn't anything we can do about it without adding code to potentially unbox all over the place. If we automatically handled boxing/unboxing in DevMode, this would show true. So instead, we let it fail in DevMode to alert you that there is a problem. -- John A. Tamplin Software Engineer (GWT), Google -- http://groups.google.com/group/Google-Web-Toolkit-Contributors To unsubscribe, reply using remove me as the subject.
Re: [gwt-contrib] $entry and wrapping result as Object in hosted mode
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
Re: [gwt-contrib] $entry and wrapping result as Object in hosted mode
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
Re: [gwt-contrib] $entry and wrapping result as Object in hosted mode
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
Re: [gwt-contrib] $entry and wrapping result as Object in hosted mode
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 sanjiv.ji...@gmail.com 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 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 -- http://groups.google.com/group/Google-Web-Toolkit-Contributors
[gwt-contrib] $entry and wrapping result as Object in hosted mode
I've run into an issue where I have a JSNI callback function wrapped within $entry so that exceptions raised by the GWT callback method are propagated correctly through the GWT exception handling mechanism. The issue I'm seeing is that in hosted mode when the function that $entry wraps is returns a boolean 'false' the apply method below gets called via $entry(..) and it wraps the boolean false value as Object(false). As a result when this value is passed to external JS is treated as true i,e. if( Object(false) ) { .. } evaluates as true. Impl.java:144 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? Thanks, Sanjiv -- http://groups.google.com/group/Google-Web-Toolkit-Contributors To unsubscribe, reply using remove me as the subject.
Re: [gwt-contrib] $entry and wrapping result as Object in hosted mode
On Sat, Apr 10, 2010 at 7:37 PM, Sanjiv Jivan sanjiv.ji...@gmail.comwrote: 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 To unsubscribe, reply using remove me as the subject.
Re: [gwt-contrib] $entry and wrapping result as Object in hosted mode
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.