*/
private JsFunction parseJsBlock(int startLineNumber, String script)
throws UnableToCompleteException {
script = "function() { " + script + "}";
StringReader r = new StringReader(script);
JsStatements stmts;
try {
stmts = jsParser.parse(jsPgm.getScope(), r, startLineNumber);
} catch (IOException e) {
logger.log(TreeLogger.ERROR, "Error reading script source", e);
throw new UnableToCompleteException();
} catch (JsParserException e) {
SourceDetail dtl = e.getSourceDetail();
if (dtl != null) {
StringBuffer sb = new StringBuffer();
sb.append(moduleURL.toExternalForm());
sb.append("(");
sb.append(dtl.getLine());
sb.append(", ");
sb.append(dtl.getLineOffset());
sb.append("): ");
sb.append(e.getMessage());
logger.log(TreeLogger.ERROR, sb.toString(), e);
} else {
logger.log(TreeLogger.ERROR, "Error parsing JavaScript source", e);
}
throw new UnableToCompleteException();
}
// Rip the body out of the parsed function and attach the JavaScript
// AST to the method.
//
JsFunction fn = (JsFunction) ((JsExprStmt) stmts.get(0)).getExpression();
return fn;
}