private JsTry mapTryStatement(Node tryNode) throws JsParserException {
JsTry toTry = new JsTry(makeSourceInfo(tryNode));
// Map the "try" body.
//
Node fromTryBody = tryNode.getFirstChild();
toTry.setTryBlock(mapBlock(fromTryBody));
// Map zero or more catch blocks.
//
Node fromCatchNodes = fromTryBody.getNext();
Node fromCatchNode = fromCatchNodes.getFirstChild();
while (fromCatchNode != null) {
assert (fromCatchNode.getType() == TokenStream.CATCH);
// Map the catch variable.
//
Node fromCatchVarName = fromCatchNode.getFirstChild();
JsCatch catchBlock = new JsCatch(makeSourceInfo(fromCatchNode),
getScope(), fromCatchVarName.getString());
// Pre-advance to the next catch block, if any.
// We do this here to decide whether or not this is the last one.
//
fromCatchNode = fromCatchNode.getNext();
// Map the condition, with a little fixup based on whether or not
// this is the last catch block.
//
Node fromCondition = fromCatchVarName.getNext();
JsExpression toCondition = mapExpression(fromCondition);
catchBlock.setCondition(toCondition);
if (fromCatchNode == null) {
if (toCondition instanceof JsBooleanLiteral) {
if (((JsBooleanLiteral) toCondition).getValue()) {
// Actually, this is an unconditional catch block.
// Indicate that by nulling the condition.
//
catchBlock.setCondition(null);
}
}
}
// Map the catch body.
//
Node fromCatchBody = fromCondition.getNext();
pushScope(catchBlock.getScope(), catchBlock.getSourceInfo());
catchBlock.setBody(mapBlock(fromCatchBody));
popScope();
// Attach it.
//
toTry.getCatches().add(catchBlock);
}
Node fromFinallyNode = fromCatchNodes.getNext();
if (fromFinallyNode != null) {
toTry.setFinallyBlock(mapBlock(fromFinallyNode));
}
return toTry;