On 26 oct, 18:16, Steve C <[email protected]> wrote:
> I have read numerous times that Hosted mode tests bytecode, while Web
> mode tests in actual JavaScript.   Wanting to delve into this deeper,
> I came up with the following, in which the JUnit tests succeed in both
> hosted and web modes.  I was expecting that because I used native JS
> features not available in Java, it would fail in hosted mode:
>
> package com.x.gwt.firsttest.client;
>
> public class StringProducer {
>           public native String getSomeText()/*-{
>               String.prototype.yo = function() {
>                   return "Hello there";
>           };
>           return "Yo".yo();
>           }-*/;

This is all JavaScript, why would it fail?

Even this one works:
public class StringProducer {
  public native String getSomeText(String yo) /*-{
    yo.constructor.prototype.yo = function() {
      return "Hello there";
    };
    return yo.yo();
  }-*/;
}
because the String is a marshaled as a "native JS String".

Now, try this:
public class Foo {
}
public class StringProducer {
  public native String getSomeText(Foo yo) /*-{
    yo.prototype.yo = function() {
      return "Hello there";
    };
    return yo.yo();
  }-*/;
}
with the test being:
public void testStringProducer() {
  assertEquals("Hello there", new StringProducer().getSomeText(new Foo
()));
}

Now, this will fail in hosted mode but pass in web mode, because when
Foo is passed in to the JS world, it is wrapped, contrary to String.
You can try "yo.prototype.yo = ..." and "yo.yo = ...", it'll fail with
a different error, but it'll fail anyway, and only in hosted mode.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to