示例#1
0
 /**
  * Executes an arbitrary expression.<br>
  * It fails if the expression throws a JsAssertException.<br>
  * It fails if the expression throws a RhinoException.<br>
  * Code from JsTester (http://jstester.sf.net/)
  */
 public Object eval(String expr) {
   Object value = null;
   try {
     value = context.evaluateString(globalScope, expr, "", 1, null);
   } catch (JavaScriptException jse) {
     Scriptable jsAssertException = (Scriptable) globalScope.get("currentException", globalScope);
     jse.printStackTrace();
     String message = (String) jsAssertException.get("message", jsAssertException);
     if (message != null) {
       fail(message);
     }
   } catch (RhinoException re) {
     fail(re.getMessage());
   }
   return value;
 }