Discussion:
Arrays and JSNI in J2CL
Kirill Prazdnikov
2018-07-13 12:57:10 UTC
Permalink
Hi, I've heard that mysterious J2CL does not support JSNI, good.

But how then the Float32Array is implemented ?
As far as I know, there is no JSIndexer-like (hello TeaVM) annotation in
JsInterop ?

Currently everyone is using JSNI llike

public static native float getF(Float32Array data, int i) /*-{
return data[i];
}-*/;
Thanks
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+***@googlegroups.com.
To post to this group, send email to google-web-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
Thomas Broyer
2018-07-13 13:54:47 UTC
Permalink
Post by Kirill Prazdnikov
Hi, I've heard that mysterious J2CL does not support JSNI, good.
But how then the Float32Array is implemented ?
As far as I know, there is no JSIndexer-like (hello TeaVM) annotation in
JsInterop ?
Currently everyone is using JSNI llike
public static native float getF(Float32Array data, int i) /*-{
return data[i];
}-*/;
Thanks
Don't worry, there's an alternative to JSNI. Its usage is meant to be much
smaller and exceptional than JSNI though.

Basically, you declare a method 'native' and give it a known name using
JsInterop (i.e. annotate it with @JsMethod), and then in a JS file you can
implement it, in "standard Closure way" (the class has the same name in JS
as in Java, so you assign a function to MyClass.prototype.getF).
That said, for this specific case, you'd probably better extend
JsArrayLike<Double> from jsinterop-base (this is what
elemental2.core.Float32Array does; knowing that java.lang.Double is
interchangeable with double as a representation of JS Number type, without
any overhead); or implement the method by casting to JsArrayLike<Double>:
public static float getF(Float32Array data, int i) {
return Js.asArrayLike(this).getAnyAt(i).asFloat();
}
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+***@googlegroups.com.
To post to this group, send email to google-web-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
Loading...