support passing native type arguments to functions either by reference or by value, which can be
specified in the function call. However, some target programming languages to which such code
is translated, e.g. JavaScript, only support passing arguments by value and do not support passing
arguments by reference. During conversion of code that includes function calls where arguments
are passed by reference to such a target language, function calls need to be suitably modified
using features supported by the target language.
DESCRIPTION
This disclosure describes techniques for replacement of function calls where arguments
are passed by reference with equivalent function calls where arguments are passed by value. The
techniques can be utilized, for example, during migration of code from one programming
language that supports the passing of arguments by reference to another programming language
that does not support the passing of arguments by reference. An automated tool can implement
the described techniques to convert code written in a particular language that supports the
passing of arguments by value or by reference, e.g., Visual Basic Applications (VBA), etc. to a
different programming language such as JavaScript that only supports the passing of arguments
by value for native types and passing by reference for objects/arrays.
When a pass by reference is encountered in the source program code, a wrapper object is
created by wrapping a native object with a pre-defined key. In the translated code in the target
language, the value of the object for the specified key is updated instead of being accessed as a
normal variable. Upon return of program control from the called function, the value assigned to
the object for the key is assigned back to the original variable. The variable now stores an
updated value, just as it would in a pass by reference scenario.
3
Defensive Publications Series, Art. 3777 [2020]
https://www.tdcommons.org/dpubs_series/3777