Java Code Examples for jdk.nashorn.internal.ir.CatchNode#getExceptionCondition()

The following examples show how to use jdk.nashorn.internal.ir.CatchNode#getExceptionCondition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCatchNode(final CatchNode catchNode) {
    enterDefault(catchNode);

    type("CatchClause");
    comma();

    property("param");
    catchNode.getException().accept(this);
    comma();

    final Node guard = catchNode.getExceptionCondition();
    if (guard != null) {
        property("guard");
        guard.accept(this);
        comma();
    }

    property("body");
    catchNode.getBody().accept(this);

    return leave();
}
 
Example 2
Source File: JSONWriter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCatchNode(final CatchNode catchNode) {
    enterDefault(catchNode);

    type("CatchClause");
    comma();

    property("param");
    catchNode.getException().accept(this);
    comma();

    final Node guard = catchNode.getExceptionCondition();
    if (guard != null) {
        property("guard");
        guard.accept(this);
        comma();
    }

    property("body");
    catchNode.getBody().accept(this);

    return leave();
}
 
Example 3
Source File: JSONWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCatchNode(final CatchNode catchNode) {
    enterDefault(catchNode);

    type("CatchClause");
    comma();

    property("param");
    catchNode.getException().accept(this);
    comma();

    final Node guard = catchNode.getExceptionCondition();
    if (guard != null) {
        property("guard");
        guard.accept(this);
        comma();
    }

    property("body");
    catchNode.getBody().accept(this);

    return leave();
}
 
Example 4
Source File: JSONWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCatchNode(final CatchNode catchNode) {
    enterDefault(catchNode);

    type("CatchClause");
    comma();

    property("param");
    catchNode.getException().accept(this);
    comma();

    final Node guard = catchNode.getExceptionCondition();
    if (guard != null) {
        property("guard");
        guard.accept(this);
        comma();
    }

    property("body");
    catchNode.getBody().accept(this);

    return leave();
}
 
Example 5
Source File: JSONWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCatchNode(final CatchNode catchNode) {
    enterDefault(catchNode);

    type("CatchClause");
    comma();

    property("param");
    catchNode.getException().accept(this);
    comma();

    final Node guard = catchNode.getExceptionCondition();
    if (guard != null) {
        property("guard");
        guard.accept(this);
        comma();
    }

    property("body");
    catchNode.getBody().accept(this);

    return leave();
}
 
Example 6
Source File: JSONWriter.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCatchNode(final CatchNode catchNode) {
    enterDefault(catchNode);

    type("CatchClause");
    comma();

    property("param");
    catchNode.getException().accept(this);
    comma();

    final Node guard = catchNode.getExceptionCondition();
    if (guard != null) {
        property("guard");
        guard.accept(this);
        comma();
    }

    property("body");
    catchNode.getBody().accept(this);

    return leave();
}
 
Example 7
Source File: JSONWriter.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCatchNode(final CatchNode catchNode) {
    enterDefault(catchNode);

    type("CatchClause");
    comma();

    property("param");
    catchNode.getException().accept(this);
    comma();

    final Node guard = catchNode.getExceptionCondition();
    if (guard != null) {
        property("guard");
        guard.accept(this);
        comma();
    }

    property("body");
    catchNode.getBody().accept(this);

    return leave();
}
 
Example 8
Source File: JSONWriter.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCatchNode(final CatchNode catchNode) {
    enterDefault(catchNode);

    type("CatchClause");
    comma();

    property("param");
    catchNode.getException().accept(this);
    comma();

    final Node guard = catchNode.getExceptionCondition();
    if (guard != null) {
        property("guard");
        guard.accept(this);
        comma();
    }

    property("body");
    catchNode.getBody().accept(this);

    return leave();
}
 
Example 9
Source File: JSONWriter.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCatchNode(final CatchNode catchNode) {
    enterDefault(catchNode);

    type("CatchClause");
    comma();

    property("param");
    catchNode.getException().accept(this);
    comma();

    final Node guard = catchNode.getExceptionCondition();
    if (guard != null) {
        property("guard");
        guard.accept(this);
        comma();
    }

    property("body");
    catchNode.getBody().accept(this);

    return leave();
}
 
Example 10
Source File: JSONWriter.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterCatchNode(final CatchNode catchNode) {
    enterDefault(catchNode);

    type("CatchClause");
    comma();

    property("param");
    catchNode.getException().accept(this);
    comma();

    final Node guard = catchNode.getExceptionCondition();
    if (guard != null) {
        property("guard");
        guard.accept(this);
        comma();
    }

    property("body");
    catchNode.getBody().accept(this);

    return leave();
}
 
Example 11
Source File: FinalizeTypes.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveCatchNode(final CatchNode catchNode) {
    final Expression exceptionCondition = catchNode.getExceptionCondition();
    if (exceptionCondition != null) {
        return catchNode.setExceptionCondition(convert(exceptionCondition, Type.BOOLEAN));
    }
    return catchNode;
}
 
Example 12
Source File: CodeGenerator.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterTryNode(final TryNode tryNode) {
    lineNumber(tryNode);

    final Block       body        = tryNode.getBody();
    final List<Block> catchBlocks = tryNode.getCatchBlocks();
    final Symbol      symbol      = tryNode.getException();
    final Label       entry       = new Label("try");
    final Label       recovery    = new Label("catch");
    final Label       exit        = tryNode.getExit();
    final Label       skip        = new Label("skip");

    method.label(entry);

    body.accept(this);

    if (!body.hasTerminalFlags()) {
        method._goto(skip);
    }

    method.label(exit);

    method._catch(recovery);
    method.store(symbol);

    for (int i = 0; i < catchBlocks.size(); i++) {
        final Block catchBlock = catchBlocks.get(i);

        //TODO this is very ugly - try not to call enter/leave methods directly
        //better to use the implicit lexical context scoping given by the visitor's
        //accept method.
        lc.push(catchBlock);
        enterBlock(catchBlock);

        final CatchNode  catchNode          = (CatchNode)catchBlocks.get(i).getStatements().get(0);
        final IdentNode  exception          = catchNode.getException();
        final Expression exceptionCondition = catchNode.getExceptionCondition();
        final Block      catchBody          = catchNode.getBody();

        new Store<IdentNode>(exception) {
            @Override
            protected void storeNonDiscard() {
                return;
            }

            @Override
            protected void evaluate() {
                if (catchNode.isSyntheticRethrow()) {
                    method.load(symbol);
                    return;
                }
                /*
                 * If caught object is an instance of ECMAException, then
                 * bind obj.thrown to the script catch var. Or else bind the
                 * caught object itself to the script catch var.
                 */
                final Label notEcmaException = new Label("no_ecma_exception");
                method.load(symbol).dup()._instanceof(ECMAException.class).ifeq(notEcmaException);
                method.checkcast(ECMAException.class); //TODO is this necessary?
                method.getField(ECMAException.THROWN);
                method.label(notEcmaException);
            }
        }.store();

        final Label next;

        if (exceptionCondition != null) {
            next = new Label("next");
            load(exceptionCondition, Type.BOOLEAN).ifeq(next);
        } else {
            next = null;
        }

        catchBody.accept(this);

        if (i + 1 != catchBlocks.size() && !catchBody.hasTerminalFlags()) {
            method._goto(skip);
        }

        if (next != null) {
            if (i + 1 == catchBlocks.size()) {
                // no next catch block - rethrow if condition failed
                method._goto(skip);
                method.label(next);
                method.load(symbol).athrow();
            } else {
                method.label(next);
            }
        }

        leaveBlock(catchBlock);
        lc.pop(catchBlock);
    }

    method.label(skip);
    method._try(entry, exit, recovery, Throwable.class);

    // Finally body is always inlined elsewhere so it doesn't need to be emitted

    return false;
}
 
Example 13
Source File: CodeGenerator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterTryNode(final TryNode tryNode) {
    lineNumber(tryNode);

    final Block       body        = tryNode.getBody();
    final List<Block> catchBlocks = tryNode.getCatchBlocks();
    final Symbol      symbol      = tryNode.getException();
    final Label       entry       = new Label("try");
    final Label       recovery    = new Label("catch");
    final Label       exit        = tryNode.getExit();
    final Label       skip        = new Label("skip");

    method.label(entry);

    body.accept(this);

    if (!body.hasTerminalFlags()) {
        method._goto(skip);
    }

    method.label(exit);

    method._catch(recovery);
    method.store(symbol);

    for (int i = 0; i < catchBlocks.size(); i++) {
        final Block catchBlock = catchBlocks.get(i);

        //TODO this is very ugly - try not to call enter/leave methods directly
        //better to use the implicit lexical context scoping given by the visitor's
        //accept method.
        lc.push(catchBlock);
        enterBlock(catchBlock);

        final CatchNode  catchNode          = (CatchNode)catchBlocks.get(i).getStatements().get(0);
        final IdentNode  exception          = catchNode.getException();
        final Expression exceptionCondition = catchNode.getExceptionCondition();
        final Block      catchBody          = catchNode.getBody();

        new Store<IdentNode>(exception) {
            @Override
            protected void storeNonDiscard() {
                return;
            }

            @Override
            protected void evaluate() {
                if (catchNode.isSyntheticRethrow()) {
                    method.load(symbol);
                    return;
                }
                /*
                 * If caught object is an instance of ECMAException, then
                 * bind obj.thrown to the script catch var. Or else bind the
                 * caught object itself to the script catch var.
                 */
                final Label notEcmaException = new Label("no_ecma_exception");
                method.load(symbol).dup()._instanceof(ECMAException.class).ifeq(notEcmaException);
                method.checkcast(ECMAException.class); //TODO is this necessary?
                method.getField(ECMAException.THROWN);
                method.label(notEcmaException);
            }
        }.store();

        final Label next;

        if (exceptionCondition != null) {
            next = new Label("next");
            load(exceptionCondition, Type.BOOLEAN).ifeq(next);
        } else {
            next = null;
        }

        catchBody.accept(this);

        if (i + 1 != catchBlocks.size() && !catchBody.hasTerminalFlags()) {
            method._goto(skip);
        }

        if (next != null) {
            if (i + 1 == catchBlocks.size()) {
                // no next catch block - rethrow if condition failed
                method._goto(skip);
                method.label(next);
                method.load(symbol).athrow();
            } else {
                method.label(next);
            }
        }

        leaveBlock(catchBlock);
        lc.pop(catchBlock);
    }

    method.label(skip);
    method._try(entry, exit, recovery, Throwable.class);

    // Finally body is always inlined elsewhere so it doesn't need to be emitted

    return false;
}
 
Example 14
Source File: CodeGenerator.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterTryNode(final TryNode tryNode) {
    lineNumber(tryNode);

    final Block       body        = tryNode.getBody();
    final List<Block> catchBlocks = tryNode.getCatchBlocks();
    final Symbol      symbol      = tryNode.getException();
    final Label       entry       = new Label("try");
    final Label       recovery    = new Label("catch");
    final Label       exit        = tryNode.getExit();
    final Label       skip        = new Label("skip");

    method.label(entry);

    body.accept(this);

    if (!body.hasTerminalFlags()) {
        method._goto(skip);
    }

    method.label(exit);

    method._catch(recovery);
    method.store(symbol);

    for (int i = 0; i < catchBlocks.size(); i++) {
        final Block catchBlock = catchBlocks.get(i);

        //TODO this is very ugly - try not to call enter/leave methods directly
        //better to use the implicit lexical context scoping given by the visitor's
        //accept method.
        lc.push(catchBlock);
        enterBlock(catchBlock);

        final CatchNode  catchNode          = (CatchNode)catchBlocks.get(i).getStatements().get(0);
        final IdentNode  exception          = catchNode.getException();
        final Expression exceptionCondition = catchNode.getExceptionCondition();
        final Block      catchBody          = catchNode.getBody();

        new Store<IdentNode>(exception) {
            @Override
            protected void storeNonDiscard() {
                return;
            }

            @Override
            protected void evaluate() {
                if (catchNode.isSyntheticRethrow()) {
                    method.load(symbol);
                    return;
                }
                /*
                 * If caught object is an instance of ECMAException, then
                 * bind obj.thrown to the script catch var. Or else bind the
                 * caught object itself to the script catch var.
                 */
                final Label notEcmaException = new Label("no_ecma_exception");
                method.load(symbol).dup()._instanceof(ECMAException.class).ifeq(notEcmaException);
                method.checkcast(ECMAException.class); //TODO is this necessary?
                method.getField(ECMAException.THROWN);
                method.label(notEcmaException);
            }
        }.store();

        final Label next;

        if (exceptionCondition != null) {
            next = new Label("next");
            load(exceptionCondition).convert(Type.BOOLEAN).ifeq(next);
        } else {
            next = null;
        }

        catchBody.accept(this);

        if (i + 1 != catchBlocks.size() && !catchBody.hasTerminalFlags()) {
            method._goto(skip);
        }

        if (next != null) {
            if (i + 1 == catchBlocks.size()) {
                // no next catch block - rethrow if condition failed
                method._goto(skip);
                method.label(next);
                method.load(symbol).athrow();
            } else {
                method.label(next);
            }
        }

        leaveBlock(catchBlock);
        lc.pop(catchBlock);
    }

    method.label(skip);
    method._try(entry, exit, recovery, Throwable.class);

    // Finally body is always inlined elsewhere so it doesn't need to be emitted

    return false;
}