Monday, October 26, 2015

Re: JsInterop: Casting native javascript objects in gwt

jsinterop.annotations

Truly,
If one day I'll find the man who continue using non standard packages in GWT, I'll take all his keyboards and "hack" so that each key will output "org.gwtproject" as a prefix to any key stroke!

:-D

Il giorno lun 26 ott 2015 alle ore 13:30 Brian Pedersen <brian.pedersen@gmail.com> ha scritto:
I didn't get that quite right, the generated function seem to fail doing the lookup in the castableTypeMap, which must be it's way of assuring that the types are actually castable to the target type.

Den mandag den 26. oktober 2015 kl. 13.16.21 UTC+1 skrev Brian Pedersen:
It seems the generated function com_google_gwt_lang_Cast_canCast__Ljava_lang_Object_2Lcom_google_gwt_core_client_JavaScriptObject_2Z only supports strings, maps, numbers and booleans.

function com_google_gwt_lang_Cast_canCast__Ljava_lang_Object_2Lcom_google_gwt_core_client_JavaScriptObject_2Z(src_0, dstId){
  return typeof src_0 === 'string' && !!com_google_gwt_lang_Cast_stringCastMap[dstId]
      || src_0.java_lang_Object_castableTypeMap && !!src_0.java_lang_Object_castableTypeMap[dstId]
      || typeof src_0 === 'number' && !!com_google_gwt_lang_Cast_doubleCastMap[dstId]
      || typeof src_0 === 'boolean' && !!com_google_gwt_lang_Cast_booleanCastMap[dstId];
}

/Brian

Den mandag den 26. oktober 2015 kl. 13.01.40 UTC+1 skrev Brian Pedersen:
Thank's for pointing that out. So i switched to the new annotations in jsinterop.annotations and activated the new mode with -jsInteropMode JS_RC.

The cast still doesn't work though :(

Instead of a java.lang.ClassCastException, I now get a  Uncaught [object Object] during the cast.
Once again, everything works if I use the concrete type and remove the cast.


/Brian

Den mandag den 26. oktober 2015 kl. 12.29.21 UTC+1 skrev Jens:

I am using GWT 2.8.0-SNAPSHOT, but the new annotations does not work for me.

I tried using @JsType(namespace = "acme", name = "MyJavaScriptObject"), as described in the new version of the JsInterop document, but apparently the namespace and name attributes are not there in the jar file.
Same thing with the @JsExport and @JsNamespace, I currently have to use them or things stop working.

The new annotations have a different package: jsinterop.annotations. Also @JsExport does not exist anymore in the new JsInterop version, you just use @JsType.

To activate the new annotations you also have to change the JsInterop mode via -jsInteropMode JS_RC


-- J.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment