Skip to content

Instantly share code, notes, and snippets.

@pingw33n
Created July 18, 2011 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pingw33n/1089306 to your computer and use it in GitHub Desktop.
Save pingw33n/1089306 to your computer and use it in GitHub Desktop.
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) {
msg += " Function";
}
System.out.println(msg);
}
obj=[object Object] org.mozilla.javascript.NativeObject Scriptable
arr=org.mozilla.javascript.NativeArray@2d189c org.mozilla.javascript.NativeArray Scriptable
i=1.0 java.lang.Double
d=1.2345 java.lang.Double
b=true java.lang.Boolean
s=string java.lang.String
n=null null
un=org.mozilla.javascript.Undefined@716cb7 org.mozilla.javascript.Undefined
re=/.*/ org.mozilla.javascript.regexp.NativeRegExp Scriptable Function
f=org.mozilla.javascript.gen.c1@987a33 org.mozilla.javascript.gen.c1 Scriptable Function
dt=org.mozilla.javascript.NativeDate@7eb6e2 org.mozilla.javascript.NativeDate Scriptable
nan=NaN java.lang.Double
pinf=Infinity java.lang.Double
ninf=-Infinity java.lang.Double
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment