/** * Given a filename, evaluate the file's contents as a JavaScript program. Return the value of the * program. If the test throws a Java exception or JavaScript runtime or compilation error, return * the string value of the error message. * * @param s full path to the file that will be exectued. * @return test result object. If the test is positive, result should be an instance of * Scriptable. if the test is negative, the result should be a String, whose value is the * message in the JavaScript error or Java exception. */ public Object executeTestFile(String s) { // this bit is stolen from Main.java FileReader in = null; try { in = new FileReader(s); } catch (FileNotFoundException ex) { driver.p("couldn't open file " + s); } Object result = null; try { // Here we evalute the entire contents of the file as // as script. Text is printed only if the print() function // is called. // cx.evaluateReader((Scriptable) global, in, args[i], 1, null); result = ((Scriptable) (((Context) cx).evaluateReader((Scriptable) global, (Reader) in, s, 1, null))); } catch (WrappedException we) { driver.p("Wrapped Exception: " + we.getWrappedException().toString()); result = we.getWrappedException().toString(); } catch (Exception jse) { driver.p("JavaScriptException: " + jse.getMessage()); result = jse.getMessage(); } return (result); }