Created
January 7, 2019 06:51
-
-
Save shalithasuranga/55e358e1275c8393a2f351db525b22e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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