Callback from JavaScript to Java with an int[] was: DEW works!

16 views
Skip to first unread message

Jaroslav Tulach

unread,
Dec 2, 2017, 12:37:57 AM12/2/17
to Wooguil Pak, bck2...@googlegroups.com, DukeScript
Hello Wooguil,
thanks for experimenting with DEW and thanks for such a great question! I think you found a bug: I've reported it as https://issues.apache.org/jira/browse/NETBEANS-193
In addition to that please find the answer below:

2017-11-29 12:49 GMT+01:00 Wooguil Pak <woogu...@gmail.com>:
Hello, Jaroslav Tulach,

I'm currently testing DEW and it seems that it does not support
parameters like integer array.
When I try
  @JavaScriptBody(args = { "id", "r" },
    javacall = true, body =
    "var array = new Array();\n" +
    "array[0]=1; array[1]=2;\n" +
    "r.@dew.demo.lowlevel.Java2JsAndBack::test([I)(array);\n"
  )
  public static native void test(String id, Java2JsAndBack r);

compiler complaints

Callback to dew.demo.lowlevel.Java2JsAndBack.test with wrong
parameters: ([I). Only known parameters are ([L)
(Ljava/lang/String;Ldew/demo/lowlevel/Java2JsAndBack;)

If it is true, is there no way to pass integer array to Java as a parameter?

There is a note in the [HTML/Java documentation](http://bits.netbeans.org/html+java/1.5.1/net/java/html/js/package-summary.html) about arrays - they are passed by copy. However you are right, there is no note about primitive arrays.

However there are no primitive arrays in JavaScript. Arrays always contain objects. As such java.lang.Object[] is usually used to refer to JavaScript Array from Java. E.g. if you change your method to:

public int test(Object[] arr) {
   int a0 = (Integer)arr[0];
   int a1 = (Integer)arr[1];
   return a0 + a1;
}

then your sample shall compile and run. Sorry for the inconvenience and thanks a lot for testing! I'll see what I can do with the #193 bugreport.
-jt


 

Best Regards,

Wooguil.


2017-10-31 13:49 GMT+09:00 Jaroslav Tulach <jarosla...@gmail.com>:
> Hello Wooguil,
> if you find some problems with Bck2Brwsr compatibility then the best way to
> report a problem is to write a unit test using the DukeScript archetype as
> Toni Epple recently documented:
> https://dukescript.com/best/practices/2017/10/23/TestingTranspiledJava.html
>
> Happy transipling!
> -jt
>
>
> 2017-10-23 14:47 GMT+02:00 Wooguil Pak <woogu...@gmail.com>:
>>
>> Dear Jaroslav Tulach,
>>
>> It's great news!!!.
>> I will test it more specifically.
>> Anyway, until now, I have tested DEW using my own testing code.
>> I found that some codes work strange although I'm not sure it is a bug or
>> not.
>> After testing a bit more, I will send the code if I determine it can be a
>> bug.
>>
>> Best Regards,
>>
>> Wooguil
>>
>>
>>
>>
>> 2017-10-22 15:07 GMT+09:00 Jaroslav Tulach <jarosla...@gmail.com>:
>> > Hi.
>> > Now I believe the new DEW works for all examples.
>> >
>> > 2017-09-10 13:23 GMT+02:00 Jaroslav Tulach <jarosla...@gmail.com>:
>> >>
>> >> Hello Wooguil,
>> >> Currently some examples do not work such as
>> >>>
>> >>> - Renders analog clock -- does not update clock image.
>> >>
>> >>
>> >> This works for me, from time to time, but when it doesn't there is a
>> >> following error in the console:
>> >>
>> >> java.lang.ClassNotFoundException: java.util.Timer
>> >> c.warn__VLjava_lang_String_2 @ vm.js:122403
>> >>
>> >> when this happens, the vm.java_util_Timer functions (which represents
>> >> the
>> >> class) is set to:
>> >>
>> >> $ vm.java_util_Timer
>> >> ƒ () {
>> >>   var instance = arguments.length == 0 || arguments[0] === true;
>> >>   return lazy.load__Ljava_lang_Object_2Ljava_lang_String_2Z(dot,
>> >> instance);
>> >> }
>> >>
>> >> which is strange, this class should have already be in the VM, no need
>> >> to
>> >> load it lazily.
>> >
>> >
>> > I solved this problem by pre-initializing certain API classes before
>> > loading
>> > the dynamic code:
>> >
>> > https://github.com/jtulach/dew/commit/2dafa5052d7733084a681c2b82f17887fe2e0179
>> >
>> > If no more errors if found, it is time to replace the previous version
>> > of
>> > DEW with the new. Thanks in advance for a bit more testing. The new
>> > version
>> > is now staged at
>> >
>> > http://hudson.apidesign.org/job/dew/lastSuccessfulBuild/artifact/static-dew/target/static-dew-0.1-SNAPSHOT-bck2brwsr/public_html/index.html
>> >
>> > -jt
>> >
>> >
>>
>>
>>
>> --
>> =========================================================
>> Wooguil Pak, Ph.D, Assistant Professor
>> Security and Wireless Network Lab. Dept. of Computer Engineering,
>> Shindang-Dong, Dalseo-Gu, Daegu, Keimyung Univ. 704-701, Korea
>> Office:+82-53-580-5229, Cell phone: +82-10-2753-1027
>> Fax: +82-53-580-6275, Email: woogu...@kmu.ac.kr
>> =========================================================
>
>



--
=========================================================
Wooguil Pak, Ph.D, Assistant Professor
Security and Wireless Network Lab. Dept. of Computer Engineering,
Shindang-Dong, Dalseo-Gu, Daegu, Keimyung Univ. 704-701, Korea
Office:+82-53-580-5229, Cell phone: +82-10-2753-1027
Fax: +82-53-580-6275, Email: woogu...@kmu.ac.kr
=========================================================

Reply all
Reply to author
Forward
0 new messages