<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi Carlos,</p>
<p>thank you for your question.</p>
<p>The JavaScript language is very lenient towards what it accepts
as array. If an object has a "length" property, it behaves like an
array. What you provide fulfils that requirement, and can thus be
sorted (and searched, filtered, etc.).</p>
<p>However, what you provide does not have `Array.prototype`
assigned as its prototype. You are basically calling
`({}).sort();`, resulting in a TypeError in plain JS (or the
"Message not supported" in Interop). From JS language semantics,
the right thing to do would be
`Array.prototype.sort.call(myInteropObj);`. That, however,
requires a change in your source code and potentially libraries
that you use.</p>
<p>To mitigate that, we have the <i>js.experimental-foreign-object-prototype
</i>option that you found already. This forces the Array.prototype
on array-like object; however, this option might also break other
code, which is why we don't use that behavior by default.</p>
<p><br>
</p>
<p>The option is experimental as we are not sure yet whether this is
the right way to go for a longer time, or whether we can support
that in a better way in the future. In this case, `experimental`
really means: there is no guarantee that exactly this option, with
exactly this behavior, will exist in future releases. We are aware
of the usecase though and will see to support it in reasonable
fashion in any case.<br>
</p>
<p>Your feedback that you are using this option is helpful to us:
the more we know about "experimental" features being used in
practice, the more we will see to have them as stable features.<br>
</p>
<p>Best,<br>
Christian<br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">Am 24.07.2019 um 13:25 schrieb Carlos
Aristu:<br>
</div>
<blockquote type="cite"
cite="mid:CAEtqr35wiiYngGtnK=cuEBrpb3v0eVEr24ZkkZUsfZ9gSc1qZQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<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
style="color:rgb(0,0,0);font-family:"Times
New
Roman";font-size:medium;float:left;margin-right:15px"><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
src="https://www.openbravo.com/wp-content/uploads/2018/08/logoOB_OBI.png"
moz-do-not-send="true" width="170px;"
height="38px;"></a></div>
<div><span
style="color:rgb(102,102,102);font-family:"Century
Gothic",Verdana;font-size:12px;font-weight:bold">Carlos Aristu
López</span><font size="3" face="Times New
Roman" color="#000000"> </font><br>
<font face="Century Gothic, Verdana"
color="#6eb43f"><span style="font-size:12px">Applications
Engineer</span></font><br>
<br>
</div>
<p style="font-size:11px;font-family:"Century
Gothic",Verdana;color:rgb(153,153,153)"><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 style="font-size:11px;font-family:"Century
Gothic",Verdana;color:rgb(153,153,153)"><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="
style="color:rgb(110,180,63)"
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>
<pre class="moz-quote-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>
</body>
</html>