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

Carlos Aristu carlos.aristu at openbravo.com
Wed Jul 24 04:25:41 PDT 2019


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=DwIFaQ&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=DwIFaQ&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=DwIFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=SONxRA-cJWH4INLX-uDgL1Afx7XABorqPK3ite36VtA&s=S2N4L5FShXFXrm0d1AT3OyWLXYYH51PCWsdofw_twng&e= >*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20190724/c999b181/attachment.html 


More information about the GraalVM-Users mailing list