By Sibers CTO Andrey Gavrilov
Whatever they do, scripting languages all have a big flaw, namely interaction with the parent objects system. It so fell out, I am now scripting a Java application on JavaScript. If you don’t know, Mozilla Rhino is perhaps the strongest realization of script languages under Java. Full concordance to the ECMA standards, stability, optimizations etc. All you need.
As you understand, scripting language (also called an extension language) is used not alone by itself but to control some parent application. It means that it accesses Java classes. And that’s where rock-n-roll begins – some classes exist both in JavaScript and in Java. Like String. And these Strings are very very different Strings.
What comes next? Many methods of these classes match each other. For example there exists a method replace in both “Javas”. But again – these are very very different replaces.
And you know what? The script generates no errors – it just uses the Java’s replace because somewhere before it had used the wrong String. That’s it.
It’s all spiced with the fact that some allotted in API classes are accessed only by JavaScript and use classes of Rhino.
A workaround? Explicit definition of types – everywhere! It helps although it does annoy.