Permalink
Browse files

java 6 based rhino runner example, still has problems with array errors

  • Loading branch information...
1 parent 0bfdd78 commit 52ee08532407295aa8f58758ec7a2d3f2fe289fa @benjaminplee committed Nov 29, 2010
Showing with 35 additions and 0 deletions.
  1. +35 −0 rhino/Java6RhinoRunner.java
View
35 rhino/Java6RhinoRunner.java
@@ -0,0 +1,35 @@
+/************
+ *
+ * Java 6 Embedded Rhino Test Suite Runner
+ *
+ * Java 6 comes with Rhino bundled with the JDK. This example test runner will execute the suit.js test suite in the same directory.
+ *
+ ************/
+
+import javax.script.*;
+import java.io.*;
+
+public class Java6RhinoRunner {
+ public static void main(String[] args) throws ScriptException {
+ new Java6RhinoRunner().load(args[0]);
+ }
+
+ private final ScriptEngine engine;
+
+ public Java6RhinoRunner() throws ScriptException {
+ ScriptEngineManager factory = new ScriptEngineManager();
+ this.engine = factory.getEngineByName("JavaScript");
+
+ this.engine.put("Java6RhinoRunner", this);
+ this.engine.eval("function load(filename) { Java6RhinoRunner.load(filename); }");
+ }
+
+ public void load(String filename) throws ScriptException {
+ try {
+ this.engine.eval(new FileReader(filename));
+ }
+ catch(FileNotFoundException e) {
+ throw new RuntimeException("Error loading javascript file: " + filename, e);
+ }
+ }
+}

0 comments on commit 52ee085

Please sign in to comment.