A possible JsInterop issue in GWT 2.8 RC2

505 views
Skip to first unread message

Boris Brudnoy

unread,
Aug 19, 2016, 11:14:46 AM8/19/16
to GWT Contributors
Hello all, 

I was tripped yesterday by a discrepancy in JsType field treatment between beta1 and rc2 releases, so I made a small Maven project reproducing it: https://github.com/bbrudnoy/jsinterop-test.

The problem is as follows: given a simple JsType-annotated class, HelloWorld:

@JsType(namespace = JsPackage.GLOBAL)
public class HelloWorld {

  public String hello = "Hello";
  public String world = "World";
}

passing an instance of it to a JavaScript function from GWT, as I do in App.java, the field names are preserved and usable in JavaScript, if I use beta1. Chrome Dev tools show this:



however, for the same code, if I change GWT version to 2.8.0-rc2, the fields become obfuscated and are no longer usable in JavaScript which worked previously:

 
Is this a JsInterop issue, or am I missing something in the way JsInterop has officially changed in RC2?

Jens

unread,
Aug 19, 2016, 3:38:32 PM8/19/16
to GWT Contributors
@JsType with isNative = false (the default) are probably treated as normal classes now if you do not use -generateJsInteropExports as compiler parameter. I guess it works again if you use the compiler parameter?

-- J.

Boris Brudnoy

unread,
Aug 21, 2016, 8:42:20 PM8/21/16
to GWT Contributors
Yes, field names return to being named in JavaScript as declared in Java after the addition of the -generateJsInteropExports compiler parameter. Why isn't this the default compiler behavior, though? After all, I followed the JsInterop spec, which, in @JsType section, states:

"The contract says that any instance behind this interface must have methods or properties with the original name in JavaScript (i.e not renamed, not pruned)."
"As the class is annotated with @JsType, it will preserve its original names for all of its public API. This makes the class easily accessible from JavaScript"


On Fri, Aug 19, 2016 at 3:38 PM Jens <jens.ne...@gmail.com> wrote:
@JsType with isNative = false (the default) are probably treated as normal classes now if you do not use -generateJsInteropExports as compiler parameter. I guess it works again if you use the compiler parameter?

-- J.

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/3f124c9c-f38b-413b-91c9-ab1c0c741e24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
BORIS BRUDNOY
Web Application Developer, Java/GWT Enthusiast (LinkedIn)

Jens

unread,
Aug 22, 2016, 6:21:29 AM8/22/16
to GWT Contributors
Because all these non native JsTypes are considered entry points to your application when they are exported and thus all code referenced by them can not be pruned and maybe some other optimization a can't be applied to it as well.

Now consider GWT libraries that use non native JsTypes to export their API to JavaScript so they can be used by an Angular UI or similar. If it would be the default then lots of apps would miss optimization opportunities just because they use the libraries and might not use any pure js at all.

This is especially harmful as the flag is an all or nothing flag. So you have to explicitly decide to export to JS. in the future you should also be able to define a regex which tells the compiler which classes to export. This will be helpful if you depend on multiple such libraries but your app only needs to export one if them as well.

-- J.

Thomas Broyer

unread,
Aug 22, 2016, 6:56:18 AM8/22/16
to GWT Contributors

Daniel Kurka

unread,
Aug 22, 2016, 6:57:20 AM8/22/16
to GWT Contributors
Jens is spot on. We want people to explicitly use -generateJsInteropExports if they rely on exporting since it has a hit on code size.

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.

Jens

unread,
Aug 22, 2016, 8:04:50 AM8/22/16
to GWT Contributors

Jens is spot on. We want people to explicitly use -generateJsInteropExports if they rely on exporting since it has a hit on code size.

Maybe the mention of the parameter should be added to the JsType JavaDoc for a final 2.8 release.

-- J.

Boris Brudnoy

unread,
Aug 22, 2016, 10:17:53 AM8/22/16
to google-web-tool...@googlegroups.com
Thanks guys. A note on this should certainly make it into the public JsInterop doc, somewhere close to the definition of the JsType/JsMethod/JsProperty contract.

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Goktug Gokdogan

unread,
Aug 25, 2016, 5:07:00 PM8/25/16
to google-web-toolkit-contributors
Document includes a comment about it in the examples and the section that describes the migration from 2.7 has an instruction to add the flag.

On Mon, Aug 22, 2016 at 7:17 AM, Boris Brudnoy <boris.brudnoy@healthometry.com> wrote:
Thanks guys. A note on this should certainly make it into the public JsInterop doc, somewhere close to the definition of the JsType/JsMethod/JsProperty contract.
On Mon, Aug 22, 2016 at 8:04 AM Jens <jens.ne...@gmail.com> wrote:

Jens is spot on. We want people to explicitly use -generateJsInteropExports if they rely on exporting since it has a hit on code size.

Maybe the mention of the parameter should be added to the JsType JavaDoc for a final 2.8 release.

-- J.

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-contributors+unsu...@googlegroups.com.
--
BORIS BRUDNOY
Web Application Developer, Java/GWT Enthusiast (LinkedIn)

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.

Daniel Gerson

unread,
Apr 9, 2017, 1:38:56 PM4/9/17
to GWT Contributors
This tripped me up as well. I second adding a note to the Javadoc as Boris suggested.
Reply all
Reply to author
Forward
0 new messages