/** * 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); }
public void reportException(RhinoException ex) { if (ex instanceof WrappedException) { WrappedException we = (WrappedException) ex; we.printStackTrace(err); } else { String lineSeparator = SecurityUtilities.getSystemProperty("line.separator"); String msg = getExceptionMessage(ex) + lineSeparator + ex.getScriptStackTrace(); reportErrorMessage( msg, ex.sourceName(), ex.lineNumber(), ex.lineSource(), ex.columnNumber(), false); } }
protected T coerce(T newValue) { try { return (T) converter.apply1(newValue); } catch (Throwable ex) { throw WrappedException.rethrow(ex); } }
public static URL toURL(String str) { try { if (!Path.uriSchemeSpecified(str)) { Path cur = currentPath(); Path path = cur.resolve(str); if (path.isAbsolute()) return path.toURL(); str = path.toString(); } return new URL(str); } catch (Throwable ex) { throw WrappedException.wrapIfNeeded(ex); } }