<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">Hi Christian,<div class=""><br class=""></div><div class="">I’m trying now to wire that into my code but I’m not sure how to put that resulting “Context” into the right place to take effect.</div><div class=""><br class=""></div><div class="">This is my code to start the scripting engine (currently Nashorn based):</div><div class=""><br class=""></div><div class=""><img apple-inline="yes" id="2EA70A5A-8E48-4A6E-B32E-D042D9C479EE" src="cid:7FD16C3C-5790-48FD-9BD9-B82E8B007A74@fritz.box" class=""></div><div class=""><br class=""></div><div class="">Can you tell me where to set the context here?</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Andreas</div><div class=""><br class=""><div class="">--&nbsp;<br class="">Andreas Mueller<br class="">IIT Software GmbH<br class=""><a href="https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!Pgc0pm15UXxeRsrjCp2Xr2PzWFlWlnyxs0yYGR3h2FFp0DeE7cwmwVMxz11rRpBB7KJA3g$" class="">http://www.swiftmq.com</a><br class=""><br class=""><span><img apple-inline="yes" id="F1E1A8A4-A827-478A-8F85-95F78B1EBB9E" src="cid:A0309C4C-D818-48E8-A9CE-B43C74051926@multi.box" class=""></span><br class=""></div><br class=""><blockquote type="cite" class="">On 30. Oct 2019, at 18:08, Christian Wirth &lt;<a href="mailto:christian.wirth@oracle.com" class="">christian.wirth@oracle.com</a>&gt; wrote:<br class=""><br class="">Hi Andreas,<br class=""><br class="">there is now a solution to your problem. You can use "Target type&nbsp;mapping" [1] to specify you want that custom conversion in your&nbsp;code.&nbsp;<br class=""><br class="">Find below some pseudo-code how to do that. You will want to&nbsp;fine-tune that to your usecase (not use allowAllAccess; not use&nbsp;HostAccess.ALL; maybe include additional types). A&nbsp;more lengthy&nbsp;discussion you will find in&nbsp;<a href="https://urldefense.com/v3/__https://github.com/graalvm/graaljs/issues/94__;!!GqivPVa7Brio!Pgc0pm15UXxeRsrjCp2Xr2PzWFlWlnyxs0yYGR3h2FFp0DeE7cwmwVMxz11rRpA5KcK6TQ$" class="">https://github.com/graalvm/graaljs/issues/94</a>.&nbsp;I'll also add an example of this to our FAQ in&nbsp;<a href="https://urldefense.com/v3/__https://github.com/graalvm/graaljs/blob/master/docs/user/FAQ.md**Aand/or__;wqA!!GqivPVa7Brio!Pgc0pm15UXxeRsrjCp2Xr2PzWFlWlnyxs0yYGR3h2FFp0DeE7cwmwVMxz11rRpCCei6ELw$">https://github.com/graalvm/graaljs/blob/master/docs/user/FAQ.md&nbsp;and/or</a> our NashornMigrationGuide.md.<br class=""><br class="">Best,<br class="">Christian<br class=""><br class="">[1]&nbsp;<a href="https://urldefense.com/v3/__https://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/HostAccess.Builder.html*targetTypeMapping-java.lang.Class-java.lang.Class-java.util.function.Predicate-java.util.function.Function-__;Iw!!GqivPVa7Brio!Pgc0pm15UXxeRsrjCp2Xr2PzWFlWlnyxs0yYGR3h2FFp0DeE7cwmwVMxz11rRpB5UJ5vyw$">https://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/HostAccess.Builder.html#targetTypeMapping-java.lang.Class-java.lang.Class-java.util.function.Predicate-java.util.function.Function-</a><br class=""><br class=""><br class="">Context context =&nbsp;Context.newBuilder("js").allowAllAccess(true).allowHostAccess(getHostAccess()).build();<br class=""><br class="">&nbsp; &nbsp; private HostAccess getHostAccess() {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; HostAccess.Builder builder =&nbsp;HostAccess.newBuilder(HostAccess.ALL);<br class="">&nbsp; &nbsp; &nbsp; &nbsp; builder.targetTypeMapping(String.class, Integer.class,&nbsp;null, (v) -&gt; parseInt(v));<br class="">&nbsp; &nbsp; &nbsp; &nbsp; return builder.build();<br class="">&nbsp; &nbsp; }<br class=""><br class="">&nbsp; &nbsp; private int parseInt(String input) {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; try {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Integer.parseInt(input);<br class="">&nbsp; &nbsp; &nbsp; &nbsp; } catch (Exception ex) {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0; //TODO should not fail silently<br class="">&nbsp; &nbsp; &nbsp; &nbsp; }<br class="">&nbsp; &nbsp; }<br class=""><br class=""><br class=""><br class=""><br class=""><br class="">Am 29.10.2019 um 13:13 schrieb Andreas&nbsp;Mueller:<br class=""><blockquote type="cite" cite="mid:B448A6EB-A390-4BFA-8F9C-B8A28DFF6505@iit.de" class="">Hi,<br class=""><br class="">I just wanted to ask if there was any change&nbsp;meanwhile?&nbsp;<br class=""><br class="">I understand your arguments but it is a real pain to&nbsp;convert a huge number of JS scripts to cast it to the&nbsp;corresponding Java type. This prevents us to switch to GraalVM.&nbsp;<br class=""><br class="">Thanks,<br class="">Andreas<br class=""><br class="">--&nbsp;<br class="">Andreas Mueller<br class="">IIT Software GmbH<br class=""><a href="https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!Pgc0pm15UXxeRsrjCp2Xr2PzWFlWlnyxs0yYGR3h2FFp0DeE7cwmwVMxz11rRpBB7KJA3g$">http://www.swiftmq.com</a><br class=""><br class=""><span id="cid:part5.E256DAD2.5A819D01@oracle.com">&lt;swiftmq_logo_positiv.png&gt;</span><br class=""><br class=""><blockquote type="cite" class="">On 6. Sep 2018, at 18:29,&nbsp;Andreas Mueller &lt;am@iit.de&gt; wrote:<br class=""><br class="">Hi Christian,<br class=""><br class="">thanks for the explanation.<br class=""><br class="">Look here (last section):<br class=""><br class="">https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/prog_guide/javascript.html<br class=""><br class="">Regards&nbsp;<br class="">Andreas&nbsp;<br class=""><br class="">Am 06.09.2018 um 15:47 schrieb Christian Wirth&nbsp;&lt;christian.wirth@oracle.com&gt;:<br class=""><br class=""><blockquote type="cite" class="">Hi Andreas,<br class=""><br class="">thanks for keeping persistent on that matter.<br class=""><br class="">&gt; Actually I don’t need this graaljs “feature” at all.&nbsp;;-)<br class=""><br class="">In fact you would; you need a new Graal.js/Truffle feature&nbsp;that converts the value for you. From a Java perspective,&nbsp;you are providing a wrong data type according to the method&nbsp;signature. You trust JavaScript to convert correctly,&nbsp;according to some defined (?) semantics of selecting the&nbsp;right method and right conversion.<br class=""><br class="">The reason why we don't have this by default is two fold:&nbsp;first, we try to provide something that works across more&nbsp;languages, not just JS between Java; and secondly, we think&nbsp;such a feature can cause way more trouble than it solves,&nbsp;especially if you go as far as String =&gt; int conversions.<br class=""><br class="">But yes, I acknowledge that this feature could simplify&nbsp;the migration from Nashorn to Graal.js, especially if you&nbsp;don't have an API on either side that does that already and&nbsp;you&nbsp;cannot introduce such API.<br class=""><br class="">&gt; can’t you just act like Nashorn<br class=""><br class="">Are you aware of any documentation (outside source code)&nbsp;that describes Nashorn's semantics on this, that your code&nbsp;depends on? In what order (of target data types) do you&nbsp;expect we try to convert to, if ambiguous - especially when&nbsp;methods with more than one arguments are involved? We have&nbsp;seen behavior that is dependent on the ordering of&nbsp;method&nbsp;definitions in the Java class file; that is something we&nbsp;cannot easily support. We have seen errors arise from JS&nbsp;code trusting its numeric data is int, while it was double&nbsp;(or the other way round) unexpectedly; that's not something&nbsp;we can solve automatically in the engine.&nbsp;<br class=""><br class="">We are still working on providing better compatibility. One&nbsp;of the next improvements will be to explicitly select&nbsp;which method+signature you want to call&nbsp;(<a href="https://urldefense.com/v3/__https://github.com/graalvm/graaljs/issues/37).**AThis__;wqA!!GqivPVa7Brio!Pgc0pm15UXxeRsrjCp2Xr2PzWFlWlnyxs0yYGR3h2FFp0DeE7cwmwVMxz11rRpDZRL7AcQ$">https://github.com/graalvm/graaljs/issues/37).&nbsp;This</a> won't solve the problem of conversion, but allows to&nbsp;mitigate the issue of seemingly random selection of methods&nbsp;that are&nbsp;called. Feel free to file any issues you come&nbsp;across in our Github Issue tracker; we can prioritize issues&nbsp;of high interest.<br class=""><br class="">Note that the Nashorn Compatibility Mode is not something&nbsp;we would encourage you to use on the long run. It helps you&nbsp;to migrate more easily now, but with it enabled, you&nbsp;might&nbsp;miss newer features of Graal.js/GraalVM, or run into&nbsp;compatibility issues in your JS code (JSAdapter has been&nbsp;superseded by ES6's Proxy, that JS Strings are in&nbsp;fact&nbsp;java.lang.Strings is an implementation detail that&nbsp;might not be correct forever, etc.).<br class=""><br class="">Best,<br class="">Christian<br class=""><br class=""><br class=""><br class=""><br class=""><br class=""><br class="">Am 06.09.2018 um 14:20 schrieb Andreas Mueller:<br class=""><blockquote type="cite" cite="mid:A0CA4089-1A8A-4994-BD7F-4EFF5501FC5F@iit.de" class="">Hi,<br class=""><br class="">I’ve tested the latest graalvm release and I’m&nbsp;still getting an exception due to lossy conversion.<br class=""><br class="">Actually I have a JS var that contains a String but is an&nbsp;int and the Java method call is int. I know that&nbsp;graaljs is restrictive here but can’t you just act like&nbsp;Nashorn when in&nbsp;Nashorn compatibility mode?<br class=""><br class="">I mean I know that I pass a String containing an int so I&nbsp;am responsible for that. Actually I don’t need this&nbsp;graaljs “feature” at all. ;-)<br class=""><br class="">Thanks,<br class="">Andreas<br class=""><br class="">--&nbsp;<br class="">Andreas Mueller<br class="">IIT Software GmbH<br class=""><a href="https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!Pgc0pm15UXxeRsrjCp2Xr2PzWFlWlnyxs0yYGR3h2FFp0DeE7cwmwVMxz11rRpBB7KJA3g$">http://www.swiftmq.com</a><br class=""><br class="">&lt;swiftmq_logo_positiv.png&gt;<br class=""><br class=""><br class=""><blockquote type="cite" class="">On 22 Jun 2018, at&nbsp;20:34, Andreas Mueller&nbsp;&lt;am@iit.de&gt;&nbsp;wrote:<br class=""><br class="">Hi Christian,<br class=""><br class=""><blockquote type="cite" class="">Did you try if it&nbsp;worked if you annotated it? Or is your code (or&nbsp;relevant parts of it) open-source so we can run it&nbsp;ourselves?<br class=""></blockquote><br class="">I didn’t test it yet. It’s not open source either (the&nbsp;scripts are under Apache 2 but the SwiftMQ is not).&nbsp;<br class=""><br class="">The scripts are using a SwiftMQ Stream Interface (the&nbsp;Java part provided by SwiftMQ). The intention is to use&nbsp;any JSR 223 available scripting engine so that scripts&nbsp;(SwiftMQ&nbsp;Steeams) can be written in JS, Groovy, Scala,&nbsp;Python etc. We have only tested (and implemented it) in&nbsp;JS. So I can add annotattions but would rather&nbsp;appreciated if you don’t&nbsp;require them at all.<br class=""><br class="">Javadoc of the Stream Interface, FYI (sometimes we just&nbsp;use a Runnable as the callback interface):<br class=""><br class=""><a href="https://urldefense.com/v3/__http://www.swiftmq.com/products/router/swiftlets/sys_streams/si/javadoc/index.html__;!!GqivPVa7Brio!Pgc0pm15UXxeRsrjCp2Xr2PzWFlWlnyxs0yYGR3h2FFp0DeE7cwmwVMxz11rRpAl762DAg$">http://www.swiftmq.com/products/router/swiftlets/sys_streams/si/javadoc/index.html</a><br class=""><br class=""><br class=""><blockquote type="cite" class="">&gt; What we need is in&nbsp;fact a Nashorn replacement as a scripting engine as&nbsp;part of the JDK<br class="">&gt; or as a plugin into the JDK by adding it to&nbsp;the classpath.<br class=""><br class="">Executing Graal JavaScript on a stock JDK is&nbsp;possible already (without Graal as optimizing&nbsp;compiler), and we are working on a fully-performant&nbsp;solution for JDK 11 (with&nbsp;Graal). Graal JavaScript&nbsp;tries to be closely compatible to Nashorn, but it is&nbsp;unrealistic that it ever provides 100% compatibility.&nbsp;Feedback like yours helps us understand what&nbsp;users&nbsp;care about most.<br class=""></blockquote><br class="">We have a lot of scripts we can test again GraalVM,&nbsp;no problem. Just post it when you have a new release and&nbsp;I’ll give it a try.<br class=""><br class=""><blockquote type="cite" class=""><br class="">&gt; Nashorn’s performance is ok for us but an&nbsp;increase would be much<br class="">&gt; appreciated. Are there plans to provide that?<br class=""><br class="">Graal JavaScript is significantly faster than Nashorn&nbsp;on most peak performance benchmarks (often orders of&nbsp;magnitude faster). But please note the difference:&nbsp;Nashorn&nbsp;always compiles the JavaScript code it&nbsp;executes to bytecode. Graal JavaScript requires Graal&nbsp;as optimizing compiler to achive good performance. The&nbsp;setup you are testing&nbsp;right now does not include&nbsp;Graal, so in your case, JavaScript is only&nbsp;interpreted, thus you will experience a&nbsp;performance impact.<br class=""></blockquote><br class="">Interpreted is not an option for us.<br class=""><br class="">Thanks,<br class="">Andreas<br class="">--&nbsp;<br class="">Andreas Mueller<br class="">IIT Software GmbH<br class=""><a href="https://urldefense.com/v3/__http://www.swiftmq.com__;!!GqivPVa7Brio!Pgc0pm15UXxeRsrjCp2Xr2PzWFlWlnyxs0yYGR3h2FFp0DeE7cwmwVMxz11rRpBB7KJA3g$">http://www.swiftmq.com</a><br class=""><br class="">&lt;swiftmq_logo_positiv.png&gt;<br class=""><br class=""><br class=""><br class="">IIT Software GmbH<br class="">Falkenhorst 11, 48155 Münster, Germany<br class="">Phone: +49 (0)251 39 72 99 00<br class="">Managing Director: Andreas Müller<br class="">District Court: Amtsgericht Münster, HRB 16294<br class="">VAT-No: DE199945912<br class=""><br class="">This e-mail may contain confidential and/or&nbsp;privileged information. If you are not the intended&nbsp;recipient (or have received this e-mail in error) please&nbsp;notify the sender&nbsp;immediately and destroy this e-mail.&nbsp;Any unauthorized copying, disclosure or distribution of&nbsp;the material in this e-mail is strictly forbidden.<br class="">_______________________________________________<br class="">GraalVM-Users mailing list<br class="">GraalVM-Users@oss.oracle.com<br class="">https://oss.oracle.com/mailman/listinfo/graalvm-users<br class=""></blockquote><br class=""><br class=""><br class=""><br class="">IIT Software GmbH<br class="">Falkenhorst 11, 48155 Münster, Germany<br class="">Phone: +49 (0)251 39 72 99 00<br class="">Managing Director: Andreas Müller<br class="">District Court: Amtsgericht Münster, HRB 16294<br class="">VAT-No: DE199945912<br class=""><br class="">This e-mail may contain confidential and/or privileged&nbsp;information. If you are not the intended recipient (or&nbsp;have received this e-mail in error) please notify the&nbsp;sender&nbsp;immediately and destroy this e-mail. Any&nbsp;unauthorized copying, disclosure or distribution of the&nbsp;material in this e-mail is strictly forbidden.<br class=""></blockquote><br class=""></blockquote><br class=""><br class="">IIT Software GmbH<br class="">Falkenhorst 11, 48155 Münster, Germany<br class="">Phone: +49 (0)251 39 72 99 00<br class="">Managing Director: Andreas Müller<br class="">District Court: Amtsgericht Münster, HRB 16294<br class="">VAT-No: DE199945912<br class=""><br class="">This e-mail may contain confidential and/or privileged&nbsp;information. If you are not the intended recipient (or have&nbsp;received this e-mail in error) please notify the&nbsp;sender&nbsp;immediately and destroy this e-mail. Any unauthorized&nbsp;copying, disclosure or distribution of the material in this&nbsp;e-mail is strictly forbidden.<br class="">_______________________________________________<br class="">GraalVM-Users mailing list<br class="">GraalVM-Users@oss.oracle.com<br class="">https://oss.oracle.com/mailman/listinfo/graalvm-users<br class=""></blockquote><br class=""><br class=""><br class="">IIT Software GmbH<br class="">Falkenhorst 11, 48155 Münster, Germany<br class="">Phone: +49 (0)251 39 72 99 00<br class="">Managing Director: Andreas Müller<br class="">District Court: Amtsgericht Münster, HRB 16294<br class="">VAT-No: DE199945912<br class=""><br class="">This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately&nbsp;and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.<br class=""></blockquote></blockquote><br class=""></div></body></html>