[graalvm-users] Question about js.experimental-foreign-object-prototype option

Steven Stewart-Gallus sstewartgallus at sstewartgallus.com
Thu Jul 25 16:06:46 PDT 2019


Can't you build the array on the Javascript side?

Value myArray = context.eval("[]");

and then copy to it from Java. It's probably likely to be faster to use 
JS arrays in JS land anyway.


On 24/07/19 04:25 AM, Carlos Aristu wrote:
> Hello all,
>
>   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 /sort()/ method.
>
>   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:
>
> /      Source sources = Source.newBuilder("js", jsCode, 
> "myCode").buildLiteral();/
> /      Source function = Source.create("js", "myFunction");
> /
> /      List<String> myList = new ArrayList<>();/
> /      try (Context context = Context.newBuilder()/
> /        .engine(Engine.create())
>         .allowHostAccess(HostAccess.ALL)
>         .build()) {
>           context.eval(sources);
>           Value res = 
> context.eval(function).execute(ProxyArray.fromList(myList));
>     }/
>
>   That code fails with the following error: 
> "/org.graalvm.polyglot.PolyglotException: TypeError: invokeMember on 
> foreign object failed due to: Message not supported./"
>
>   To make it work, I need to enable the 
> /js.experimental-foreign-object-prototype /option[1] for the Context.
>
>   Being an experimental option and according to the docs, it is not 
> recommended to enable it for productive environments. My questions are:
>
>   a) ¿Is there any plan to switch this option as non-experimental?
>   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?
>
> Thank you in advance.
>
> [1] 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_graalvm_graaljs_issues_88-23issuecomment-2D453021299&d=DwIDaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=tPvQjK_VVNTyIh2SJPrMm1pA3KSh5pS88cVuQwzJg2k&s=J1yDHwU44zY1bNUPFDZhrMm4Dl3BgdXejDkEs7GDOUE&e=  
> <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=>
> -- 
> <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=>
> Carlos Aristu López
> Applications Engineer
>
> /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./
>
> /Your data is processed by Openbravo under our privacy policy 
> <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=>/
>
>
>
> _______________________________________________
> GraalVM-Users mailing list
> GraalVM-Users at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/graalvm-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20190725/59ec7b21/attachment.html 


More information about the GraalVM-Users mailing list