-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to use JavaScript Array in Java method requiring a Collection #768
Comments
I am able to reproduce the missing conversion of JavaScript arrays to Java You are right that you can add the missing conversion through a custom target type mapping. Personally, I would use
I don't understand your troubles with errors. I don't see the relation to the mentioned target type mapping. Errors do not have array elements, so they should not be affected at all. I am afraid that I cannot help you without a reproducible test-case. |
Versions
Graal Scripting Engine Setup
To run each script file I used the following:
JS Code Example
See MockClass:
Issue
Calling the .addAll() method on a Java HashSet in JavaScript with a JavaScript array as the parameter (See above code example) throws the exception:
See Stack Trace for more information.
The code example at the top works on Nashorn, and it appears the problem is with Graal not mapping the JavaScript Array to a Collection, which Set.addAll() requires [1].
Nashorn Scripting Engine Setup:
(OpenJDK 11.0.19)
As before, I ran the same script in the same way:
In Graal, I could get around this issue by adding explicit type maps [2]
This explicit mapping solution came from another issue [2]. Using this type map caused other problems as the type mapping is too generic and caught other data types.
JS Error object no longer being passable to the logger:
The issue is caused by the JSErrorObject being passed into a Java logger class method which does not have a method that takes JSErrorObject. I have been unable to find a way to map JSErrorObject to anything else, as it seems to be indistinguishable from an object. From my research, it seems we can’t directly reference JSErrorObject from truffle. Is there a way to explicitly map JSErrorObject to something else?
Is there a proper way to use JavaScript Arrays in Java methods requiring Collections as their parameters?
Stack Trace
[1] https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Set.html#addAll(java.util.Collection)
[2] #3 (comment)
The text was updated successfully, but these errors were encountered: