Does Server-side Javascript pass by reference when invoking a C3 action implemented in java or javascript?

#1

If we write javascript that runs on the server (e.g. method declared with js server annotation), and it makes a call to another C3 action also running on the server (implemented in java or javascript), does it pass the arguments to the C3 action by value or by reference?

I ask this because I’m wondering when it’s necessary to deep clone() an object before invoking a C3 action, if I want to make sure that the original object is not modified. I know that a copy is made when we go from js client to c3 server, or from an external action engine to/from c3 server, but I’ve heard that server-side Javascript can run natively within the C3 server, in the same JVM. I suspect that the arguments to a C3 action are not serialized/de-serialized when going from server-side Javascript to c3 server, and therefore may not be copied.

I’ve heard that C3 actions should not modify the input arguments, but I want to know this for defensive programming, when I’m the one invoking another C3 action that I did not implement.

#2

Most actions are isolated so the equivalent of serialization happens between calls.

The only exception to this is if the method is marked as inline and the implementation is in the same language. In that case only, the argument values passed to the action call are received by the implementation.

2 Likes