<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Can't you build the array on the Javascript side?</p>
<p>Value myArray = context.eval("[]");</p>
<p>and then copy to it from Java. It's probably likely to be faster
to use JS arrays in JS land anyway.<br>
</p>
<br>
<div class="moz-cite-prefix">On 24/07/19 04:25 AM, Carlos Aristu
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAEtqr35wiiYngGtnK=cuEBrpb3v0eVEr24ZkkZUsfZ9gSc1qZQ@mail.gmail.com">
<div dir="ltr">Hello all,
<div><br>
</div>
<div> I'm currently using GraalJS to execute some javascript
functions from my Java code. One of this javascript functions
receives an array as an argument and invokes the <i>sort()</i>
method.</div>
<div><br>
</div>
<div> To invoke this function from Java, I'm creating an
ArrayList and I send it to through a ProxyArray, something
similar to this code snippet:</div>
<div><br>
</div>
<div><i> Source sources = Source.newBuilder("js", jsCode,
"myCode").buildLiteral();</i></div>
<div><i> Source function = Source.create("js",
"myFunction");<br>
</i></div>
<div><i> List<String> myList = new
ArrayList<>();</i></div>
<div><i> try (Context context = Context.newBuilder()</i></div>
<i> .engine(Engine.create())<br>
.allowHostAccess(HostAccess.ALL)<br>
.build()) {<br>
context.eval(sources);<br>
Value res =
context.eval(function).execute(ProxyArray.fromList(myList));<br>
}</i>
<div><br>
</div>
<div> That code fails with the following error: "<i>org.graalvm.polyglot.PolyglotException:
TypeError: invokeMember on foreign object failed due to:
Message not supported.</i>"</div>
<div><br>
</div>
<div> To make it work, I need to enable the <i>js.experimental-foreign-object-prototype
</i>option[1] for the Context.</div>
<div><br>
</div>
<div> Being an experimental option and according to the docs,
it is not recommended to enable it for productive
environments. My questions are:</div>
<div><br>
</div>
<div> a) ¿Is there any plan to switch this option as
non-experimental?</div>
<div> b) ¿Do you know if there exists any alternative (or a
better way) to provide a JS array as an argument of a JS
function from Java?</div>
<div><br>
</div>
<div>Thank you in advance.</div>
<div><br>
</div>
<div>[1] <a
href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_graalvm_graaljs_issues_88-23issuecomment-2D453021299&d=DwMFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=SONxRA-cJWH4INLX-uDgL1Afx7XABorqPK3ite36VtA&s=Hw4Fpfxv8qQMK9XrdAcEW49J5nMi0ODhnsFdecPww3U&e="
moz-do-not-send="true">https://github.com/graalvm/graaljs/issues/88#issuecomment-453021299</a><br>
<div>-- <br>
<div dir="ltr" class="gmail_signature"
data-smartmail="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div dir="ltr">
<div><a
href="https://urldefense.proofpoint.com/v2/url?u=https-3A__www.openbravo.com&d=DwMFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=SONxRA-cJWH4INLX-uDgL1Afx7XABorqPK3ite36VtA&s=qLyjnBLTJ0nP65gCeCPRY2IqJC0l9sOfxepjQ0AnXfM&e="
target="_blank" moz-do-not-send="true"><img
moz-do-not-send="true" height="38px;"
width="170px;"></a></div>
<div><span>Carlos Aristu López</span> <br>
<span>Applications Engineer</span><br>
<br>
</div>
<p><i>This e-mail is confidential and contains
private information. Any reading, retention,
distribution or copying of this communication
by any person other than its intended
recipient is prohibited.</i></p>
<p><i>Your data is processed by Openbravo under
our <a
href="https://urldefense.proofpoint.com/v2/url?u=https-3A__www.openbravo.com_privacy-2Dpolicy_&d=DwMFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=SONxRA-cJWH4INLX-uDgL1Afx7XABorqPK3ite36VtA&s=S2N4L5FShXFXrm0d1AT3OyWLXYYH51PCWsdofw_twng&e="
target="_blank" moz-do-not-send="true">privacy
policy</a></i></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
GraalVM-Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:GraalVM-Users@oss.oracle.com">GraalVM-Users@oss.oracle.com</a>
<a class="moz-txt-link-freetext" href="https://oss.oracle.com/mailman/listinfo/graalvm-users">https://oss.oracle.com/mailman/listinfo/graalvm-users</a></pre>
</blockquote>
<br>
</body>
</html>