Skip to content

Instantly share code, notes, and snippets.

Scriptable scope = cx.initStandardObjects();
Object result = cx.evaluateString(scope, "obj = {a:1, b:['x','y']}; arr = [1,2,3]; i = 1; d = 1.2345; b = true; s = 'string'; re=/.*/; f = function() { }; dt = new Date(); n=null; un=undefined; nan=Number.NaN; pinf=Infinity; ninf=-Infinity;", "MySource", 1, null);
for (String name: new String[]{"obj", "arr", "i", "d", "b", "s", "n", "un", "re", "f", "dt", "nan", "pinf", "ninf"}) {
Object o = scope.get(name, scope);
String msg = name + "=" + String.valueOf(o) + " " + (o != null ? o.getClass().getName() : "null");
if (o instanceof Scriptable) {
msg += " Scriptable";
}
if (o instanceof Function) {