if (!shouldModify(scopename)) {
return input;
}
try {
AstRoot ast = null;
/* initialize JavaScript context */
Context cx = Context.enter();
/* create a new parser */
Parser rhinoParser = new Parser(new CompilerEnvirons(), cx.getErrorReporter());
/* parse some script and save it in AST */
ast = rhinoParser.parse(new String(input), scopename, 0);
modifier.setScopeName(scopename);
modifier.start();
/* recurse through AST */
ast.visit(modifier);
modifier.finish(ast);
/* clean up */
Context.exit();
return ast.toSource();
} catch (RhinoException re) {
System.err.println(re.getMessage()
+ "Unable to instrument. This might be a JSON response sent"
+ " with the wrong Content-Type or a syntax error.");