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
JavaScript objects passed into function not "copy of reference" when using execute from Java #3247
Comments
Almost forgot the arguments to the function. myReflection is an ordinary polyglot Value (https://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/Value.html#as-java.lang.Class-) object |
For the time being, to work around this, I will be using function.protototype.apply similar to the following
This works for modifying members of passed in arguments,
Outputs "hi there" So I don't really need Value.execute, it is just a "nice to have". But I would like to know if this is a real bug or if there is some magic I need to perform to get Value.execute to work normally. |
Thank you for reporting this, I can take this to the Truffle team, but it would be much appreciated if we can have a smaller reproducer, would you mind providing a small java class with the Also, I'm wondering why you're using an old version of java11? |
Were you able to get a small reproducer for this issue? FYI I couldn't access the GitLab repo you provided. |
Closing for inactivity |
Describe GraalVM and your environment :
java -Xinternalversion
:Describe the issue
Normally JavaScript objects passed into functions are "copy of reference". That is to say that given this input
We would expect this output
Notice the 2nd object changed.
I have not yet found a way to get this to happen on my end. It is possible there is a pointer/reference method that I am not yet aware of, but everything I have tried (and I have tried a lot) will not allow me to update obj1.item inside of a function body when I call execute. I am using a single context.
Code snippet or code repository that reproduces the issue
The above contains a Value whose guest object is an empty JSOrdinaryObject
Function source
Executing function source
When this happens, exports is unchanged, no get function attached.
Be gentle, this is a work in progress, I am going to include the source where this occurred in this ticket.
Steps to reproduce the issue
Expected behavior
Observed Behavior
Note : To see an example of member functions being pulled successfully, observe when the JSON built-in is boxed and its members parse and stringify are extracted successfully
Additional context
Code examples CC-BY-SA from here https://stackoverflow.com/questions/518000/is-javascript-a-pass-by-reference-or-pass-by-value-language
The text was updated successfully, but these errors were encountered: