The example isn't doing instanceof though, it is just making that the
return type for the method (albeit through the use of generics). Does
this suggest that we should stop using arrays to refer to raw JS data,
or at least expect that generics may fail in interesting ways around
them (and at runtime of all places)?
elemental2.Array is full of cases where [] or ... are used as arguments,
though this includes generic arrays (as opposed to generics _of_
arrays). If I understand you correctly, valid Java code that is passed a
String[] or Double[] (or for example Element[]) may fail in exciting
ways if passed one of these 'arrays'.
In case those are correctly handled, and it is important only to tell
JsInterop about an array of generics  instead of generic representing an
array, perhaps Vassilis should have another AccessorFunction which
handles arrays instead? (Actually maye need 3 more, <T, V[]>, <T[], V>,
<T[], V[]>, so I don't think this is a serious suggestion).
Otherwise your email seems to suggest that we need a type in
jsinterop.base  for all JS arrays instead of our current situation of
pretending that java arrays and js arrays are compatible.
--
  Colin Alworth
  co...@colinalworth.com



On Mon, Jun 26, 2017, at 12:09 PM, 'Roberto Lublinerman' via GWT Contributors 
wrote:> The short answer is that this is also not a bug.
> 
> Java arrays are typed, JS arrays are not. So none of the examples you
> have will fully work.> 
> E.g. If you do array instanceof Date[] on an array built in JS filled
>      with Dates it will fail.> 
> A native array is best modeled as SomeNativeJsType[] where there are
> not expectations on the contents of the array from the Java
> perspective.> 
> We would have loved to have a more seamless array JsInterop.
> 
> 
> 
> On Mon, Jun 26, 2017 at 1:31 AM, Vassilis Virvilis
> <vasv...@gmail.com> wrote:>> Originally posted in gwt-users.
>> The question here is the same with the previous one.
>> 
>> Is this considered a bug? Should I report it as an issue? and if
>> so where?>> 
>>  Thanks.
>> 
>> 
>> ---------- Forwarded message ----------
>> From: *Vassilis Virvilis* <vasv...@gmail.com>
>> Date: Fri, Feb 24, 2017 at 2:44 PM
>> Subject: jsinterop woes: Part 2: return Double[]
>> To: google-web-tool...@googlegroups.com
>> 
>> 
>> Hi,
>> 
>> I am not sure if it is a bug but it kills my beautiful jsinterop
>> mappings.>> Let's say that I have a native js function (d3.extent) that 
>> returns
>> an array of something. It may be dates it may be doubles..>> 
>> This is mapped nicely with 
>> 
>>>     public static native <T, V> V[] extent(T[] data,
>>>             AccessorFunction<T, V> accessor);
>> 
>> Where AccessorFunction is 
>> 
>>>     @JsFunction
>>>     public static interface AccessorFunction<T, V> {
>>>         public V get(T d);
>>>     }
>> 
>> The above scheme works for Date and other objects but it fails with
>> Double. If I specify another variant of d3.extent that returns
>> double[] it works>> Here is the javascript exception
>> 
>>> Uncaught Error: java.lang.ClassCastException
>>>     at java_lang_ClassCastException_ClassCastException__V.java_lang-
>>>     _Throwable_createError__Ljava_lang_String_2Ljava_lang_Object_2
>>>     [as package_private$java_lang$createError__Ljava_lang_String_2L-
>>>     java_lang_Object_2] (dashboard-0.js:7245)>>>     at 
>>> java_lang_ClassCastException_ClassCastException__V.java_lang-
>>>     _Throwable_initializeBackingError__V [as
>>>     private$java_lang_Throwable$initializeBackingError__V] (dashboard-
>>>     0.js:7300)>>>     at 
>>> java_lang_ClassCastException_ClassCastException__V.java_lang-
>>>     _Throwable_Throwable__V (dashboard-0.js:7133)>>>     at 
>>> java_lang_ClassCastException_ClassCastException__V.java_lang-
>>>     _Exception_Exception__V (dashboard-0.js:7381)>>>     at 
>>> java_lang_ClassCastException_ClassCastException__V.java_lang-
>>>     _RuntimeException_RuntimeException__V (dashboard-0.js:29760)>>>     at 
>>> java_lang_ClassCastException_ClassCastException__V (dashboard-
>>>     0.js:57310)>>>     at 
>>> javaemul_internal_InternalPreconditions_checkCriticalType__ZV
>>>     (dashboard-0.js:72171)>>>     at 
>>> javaemul_internal_InternalPreconditions_checkType__ZV (dashboard-
>>>     0.js:72378)>>>     at 
>>> com_google_gwt_lang_Cast_castTo__Ljava_lang_Object_2Lcom_goo-
>>>     gle_gwt_core_client_JavaScriptObject_2Ljava_lang_Object_2 (dashboard-
>>>     0.js:647)>> 
>> It goes here
>>> function com_google_gwt_lang_Cast_castTo__Ljava_lang_Object_2Lcom_g-
>>> oogle_gwt_core_client_JavaScriptObject_2Ljava_lang_Object_2(src_0,
>>> dstId){>>>   com_google_gwt_lang_Cast_$clinit__V();
>>>   javaemul_internal_InternalPreconditions_checkType__ZV(com_google_-
>>>   gwt_lang_Cast_jsEquals__Ljava_lang_Object_2Ljava_lang_Object_2Z(s-
>>>   rc_0, null) || com_google_gwt_lang_Cast_canCast__Ljava_lang_Objec-
>>>   t_2Lcom_google_gwt_core_client_JavaScriptObject_2Z(src_0, dstId));>>>   
>>> return src_0;
>>> }
>> 
>> Arguments:
>>  * src_0:
>>    * evaluated: js array of numbers as it should be
>>  * dstId:
>>    * evaluated: 2396>> and then it goes to
>> 
>>> function com_google_gwt_lang_Cast_canCast__Ljava_lang_Object_2Lcom_-
>>> google_gwt_core_client_JavaScriptObject_2Z(src_0, dstId){>>>   
>>> com_google_gwt_lang_Cast_$clinit__V();
>>>   if (com_google_gwt_lang_Cast_instanceOfString__Ljava_lang_Object_-
>>>   2Z(src_0)) {>>>     return 
>>> !!com_google_gwt_lang_Cast_stringCastMap[dstId];
>>>   }
>>>    else if (src_0.java_lang_Object_castableTypeMap) {
>>>     return !!src_0.java_lang_Object_castableTypeMap[dstId];
>>>   }
>>>    else if (com_google_gwt_lang_Cast_instanceOfDouble__Ljava_lang_O-
>>>    bject_2Z(src_0)) {>>>     return 
>>> !!com_google_gwt_lang_Cast_doubleCastMap[dstId];
>>>   }
>>>    else if (com_google_gwt_lang_Cast_instanceOfBoolean__Ljava_lang_-
>>>    Object_2Z(src_0)) {>>>     return 
>>> !!com_google_gwt_lang_Cast_booleanCastMap[dstId];
>>>   }
>>>   return false;
>>> }
>> 
>> where it fails.
>> Would it be possible to handle transparently also Double[] (and
>> possibly String[])? as double[]?>>    Thank you for reading that far...
>> 
>> Vassilis
>> 
>> 
>> 
>> 
>> 
>> -- 
>> Vassilis Virvilis
>> 
>> 
>> 
>> 
>> 
>> 
>> -- 
>> Vassilis Virvilis
>> 
>> 
>> 


>> --
>>  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+unsubscr...@googlegroups.com. To view this discussion
>>  on the web visit
>>  
>> https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAKbOjEzUf3LAK90Gnq%2B8B5Yzq7akyZPC%3DJ9ch1DFieqoOCJJVA%40mail.gmail.com[1].
>>  For more options, visit https://groups.google.com/d/optout.> 
> 


> --
>  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+unsubscr...@googlegroups.com.>  To view this discussion on the 
> web visit
>  
> https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAC7T7gnF1A8-xQs%3DORiyp1Ofmp%3D%2B4Hj9JJ%2B2KGsfbT%2B_1JVeTA%40mail.gmail.com[2].>
>   For more options, visit https://groups.google.com/d/optout.


Links:

  1. 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAKbOjEzUf3LAK90Gnq%2B8B5Yzq7akyZPC%3DJ9ch1DFieqoOCJJVA%40mail.gmail.com?utm_medium=email&utm_source=footer
  2. 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAC7T7gnF1A8-xQs%3DORiyp1Ofmp%3D%2B4Hj9JJ%2B2KGsfbT%2B_1JVeTA%40mail.gmail.com?utm_medium=email&utm_source=footer

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/1498497405.2496615.1021798000.4D20C26E%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to