Skip to content

Instantly share code, notes, and snippets.

@shalithasuranga
Created January 7, 2019 06:51
Show Gist options
  • Save shalithasuranga/55e358e1275c8393a2f351db525b22e5 to your computer and use it in GitHub Desktop.
Save shalithasuranga/55e358e1275c8393a2f351db525b22e5 to your computer and use it in GitHub Desktop.
package com.mycompany.rhinojsexample;
import com.mycompany.rhinojsexample.hostobjects.ConsoleRunner;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
public class RhinoExample {
public static void main(String[] args) {
String code = "var a=[2,8,5]; a[1] + a[0];";
try {
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
Object ob = cx.evaluateString(scope, code, "rhinodemojs", 1, null);
System.out.println(Context.toObject(ob, scope));
}
catch(Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment