On Fri, Sep 26, 2008 at 11:37 AM, Eric Ayers <[EMAIL PROTECTED]> wrote:

> I am running into a problem in hosted mode that is kind of tricky to work
> around.
>
> gwt-google-apis issue 180:
>
>   http://code.google.com/p/gwt-google-apis/issues/detail?id=180
>
> Basically, I have a JS API that is calling back into a method defined in
> Java:
>
>      [EMAIL PROTECTED]
> ::fromPixelToLatLng(Lcom/google/gwt/maps/client/geom/Point;IZ)(
>           arg0 || null,
>           arg1,
>           arg2);
>
> were 'arg2' is a boolean value.
>
> Sometimes, the Maps API is passing 'undefined' as the 3rd argument.
> I could fix this by writing all my argument passing in the form of:
>
> (arg2 == null ? false : arg2)
>
> but this would just be a workaround for hosted mode - web mode wouldn't
> care about the difference.  Besides that, it would bloat up the code.  So, I
> propose that in JsGlue that we just assume a null or undefined value is
> "false" when passed into java.
>
> M      user/test/com/google/gwt/dev/jjs/test/HostedTest.java
> M      dev/core/src/com/google/gwt/dev/shell/JsValueGlue.java
>

For this to be reasonable, you have to be certain that everywhere a boolean
can be used the behavior of a null is exactly the same -- otherwise you will
be masking web-mode problems.  One example where this would cause a problem
would be

public native String getBool(boolean v) /*-{
  return "" + v;
}-*/;

If a JS undefined or null were allowed to be passed into Java code as a
boolean, then the result of this function would be different in web mode vs.
hosted mode.

I think anytime we are getting values from JS, it is safer to ensure they
match the declared type at that point.  If you do it often, write a small
function to do the mapping.

Examples where we *have* relaxed the JS types that can be used are String
(vs primitive string) and null/undef equivalence (by changing the generated
code in the few cases that care).

-- 
John A. Tamplin
Software Engineer (GWT), Google

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

Reply via email to