Re: [gwt-contrib] Digest for google-web-toolkit-contributors@googlegroups.com - 5 updates in 2 topics

94 views
Skip to first unread message

Arnaud TOURNIER

unread,
May 31, 2017, 8:28:36 AM5/31/17
to Digest recipients

About the iframe instanceof problem, I think this is due to the fact that JavaScript prototypes do not cross frame boundaries (for security and privacy reasons). So even in JavaScript, the instanceof operator would not work.

You can try this example :


<html>
<head></head>
<body>
<iframe id="frame" src="frame.html" frameborder="0"></iframe>

<script>
let frame = document.querySelector("#frame");
let doc = frame.contentDocument;

let a = doc instanceof HTMLDocument;

console.log(`reality check : ${a}`);
</script>
</body>
</html>


If the HTMLDocument class would have @JsType( isNative=true, namespace=JsPackage.GLOBAL, name="Object" ) annotation, the above snippet would have worked as expected.

The suggested work around (jsni method) might work, the idea is to bypass the GWT compiler generated cast checks.

Thanks

Arnaud



Le mer. 31 mai 2017 à 12:47, <google-web-tool...@googlegroups.com> a écrit :
Daniel Harezlak <dhar...@gmail.com>: May 30 11:23PM -0700

Hi, I have the following code using elemental2-dom:
 
HTMLIFrameElement frame = (HTMLIFrameElement) DomGlobal.document.
createElement("iframe");
HTMLDocument doc = (HTMLDocument) frame.contentDocument; //throws
java.lang.ClassCastException
 
The second line throws an exception although I am quite sure that the
returned element is an HTMLDocument because when I log it in the JS console
I get "[object HTMLDocument]". The first line works fine. What is strange
the exception is only thrown in Chrome both in SDM and production modes. In
Firefox it works just fine. Any thoughts?
Daniel Harezlak <dhar...@gmail.com>: May 31 12:25AM -0700

The way to work around it is to use a native method:
 
private static native HTMLDocument getHtmlDocument(HTMLIFrameElement frame)
/*-{
return frame.contentDocument;
}-*/;
 
Is this required?
 
On Wednesday, May 31, 2017 at 8:23:20 AM UTC+2, Daniel Harezlak wrote:
gwtt...@gmail.com: May 31 02:19AM -0700

How about using jsinterop.base.Js.cast() for the casing instead? - see:
https://groups.google.com/forum/#!topic/Google-Web-Toolkit/0XGv7EhDFmc
 
On Wednesday, May 31, 2017 at 7:23:20 AM UTC+1, Daniel Harezlak wrote:
Daniel Harezlak <dhar...@gmail.com>: May 30 11:04PM -0700

Hi, it looks like issues are disabled for the
https://github.com/google/elemental2 project.
 
On Saturday, May 20, 2017 at 12:34:09 AM UTC+2, Julien Dramaix wrote:
 
Julien Dramaix <julien....@gmail.com>: May 31 06:40AM

I've enabled the issue tab.
 
On Tue, May 30, 2017 at 11:04 PM Daniel Harezlak <dhar...@gmail.com>
wrote:
 
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to google-web-toolkit-co...@googlegroups.com.

Daniel Harezlak

unread,
May 31, 2017, 1:35:53 PM5/31/17
to GWT Contributors
OK, it looks like the frame boundaries can be crossed in Firefox which yields reality check : true whereas Chrome produces reality check : false. Thanks for the explanation. Beside the JSNI workaround one can also use jsinterop.base.Js.uncheckedCast() for such cases.
Reply all
Reply to author
Forward
0 new messages