Bug: wrong parameter names for native functions in nested class

28 views
Skip to first unread message

Udo

unread,
Apr 1, 2014, 5:44:17 AM4/1/14
to java2...@googlegroups.com
We have 

public class AbstractHtmlComponent … {
     
      public class HtmlComponent {
       /**
 * @j2sNative this.css(propertyName, value); return this;
 */
public native HtmlComponent css(String propertyName, String value);

      …
      }
}

Calling the css function results in a “ ReferenceError: propertyName is not defined”. This is because J2S generated the following code


Clazz.defineMethod (c$, "css"
function (a, b) {
this.css(propertyName, value); return this;
}, "~S,~S");



instead of 


Clazz.defineMethod (c$, "css"
function (propertyName, value) {
this.css(propertyName, value); return this;
}, "~S,~S");



Moving HtmlComponent to an extra file (after making it static) would solve the issue.


Udo

Zhou Renjian

unread,
Apr 2, 2014, 2:08:15 AM4/2/14
to Java2Script
Hi,

It seems that you are in release mode compiling for inner class.

Use both @j2sNativeSrc and @j2sNative should fix this problem.

      public class HtmlComponent {
       /**
 * @j2sNativeSrc this.css(propertyName, value); return this;
 * @j2sNative this.css(a, b); return this;
 */
public native HtmlComponent css(String propertyName, String value);

      …
      }

@j2sNativeSrc is for normal mode compiling. @j2sNative is for release mode compiling or for normal compiling if @j2sNativeSrc is missing.

Regards,
Zhou Renjian


--
You received this message because you are subscribed to the Google Groups "Java2Script" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java2script...@googlegroups.com.
To post to this group, send email to java2...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/java2script/57e8e143-ef98-454b-b2ff-61d1087e58c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Udo

unread,
Apr 2, 2014, 6:47:45 AM4/2/14
to java2...@googlegroups.com
Hi,

thanks for your answer.

Can you explain a little what you mean with "release mode compiling" vs. "normal compiling"? I wasn't aware those modes exist.

Also: how does one switch the modes, or what does influence the mode a class is compiled in? As all other code seems to be compiled in "normal" mode there seems to be something special about the nested class?!


Udo

Zhou Renjian

unread,
Apr 2, 2014, 7:29:05 AM4/2/14
to Java2Script
It seems there is a bug in compiling nested classes not using the same mode of root classes. 

To enable release mode, modify .j2s file in the project root, add/modify a line:
j2s.compiler.mode=release

And here are some other compiler options used in net.sf.j2s.java.core project:

j2s.compiler.mode=debug

j2s.compiler.whitespace=false

j2s.compiler.linebreak=\r\n

You may get a smaller file in release mode. But it will be hard to read/debug those scripts later. Modern HTTP servers always serve *.js files in g-zip encoding, which result in a much smaller files. So release mode is not a must, in my opinion.


Regards,
Zhou Renjian


Reply all
Reply to author
Forward
0 new messages