Interoperability in a Scripted World: Putting Inheritance & Prototypes Together
Kathryn E. Gray · 2010
Scripting languages are used to quickly and easily develop or extend programs. Frequently, these scripted programs are combined with libraries and other programs from conventional languages to build more complex applications. Bridging the gap between different languages requires manual data conversions and dynamic checks which can introduce subtle errors. Language and compiler support for interoperability can simplify the task of writing programs with multiple languages. Our previous compilation techniques allow any given value to pass from one language to another and be used as a native value for languages with similar runtime semantics. In this paper, we support interoperability between languages with different runtime semantics while still allowing a free exchange of values and maintaining type-safety. We consider interoperation between two object-oriented languages with different means of extension and different treatment of object-members—Java, with class-based inheritance, separation of fields and methods, and statically fixed object structure, versus JavaScript, with prototype-based extension, uniform members, and fully mutable object structure. To allow a Java object to pass to JavaScript, we supply a transformation that causes the JavaScript program to treat the value as a JavaScript object, and vice-versa. We mingle class-based and prototype-based inheritance to combine the different representations of objects and object extension without losing the flexibility or guarantees of either.