jdk.nashorn.internal.ir.WithNode Java Examples

The following examples show how to use jdk.nashorn.internal.ir.WithNode. 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 openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
 public boolean enterWithNode(final WithNode withNode) {
     enterDefault(withNode);

     type("WithStatement");
     comma();

     property("object");
     withNode.getExpression().accept(this);
     comma();

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

     return leave();
}
 
Example #2
Source File: JSONWriter.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
 public boolean enterWithNode(final WithNode withNode) {
     enterDefault(withNode);

     type("WithStatement");
     comma();

     property("object");
     withNode.getExpression().accept(this);
     comma();

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

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

     type("WithStatement");
     comma();

     property("object");
     withNode.getExpression().accept(this);
     comma();

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

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

     type("WithStatement");
     comma();

     property("object");
     withNode.getExpression().accept(this);
     comma();

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

     return leave();
}
 
Example #5
Source File: JSONWriter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
 public boolean enterWithNode(final WithNode withNode) {
     enterDefault(withNode);

     type("WithStatement");
     comma();

     property("object");
     withNode.getExpression().accept(this);
     comma();

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

     return leave();
}
 
Example #6
Source File: JSONWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
 public boolean enterWithNode(final WithNode withNode) {
     enterDefault(withNode);

     type("WithStatement");
     comma();

     property("object");
     withNode.getExpression().accept(this);
     comma();

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

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

     type("WithStatement");
     comma();

     property("object");
     withNode.getExpression().accept(this);
     comma();

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

     return leave();
}
 
Example #8
Source File: Attr.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean symbolNeedsToBeScope(Symbol symbol) {
    if (symbol.isThis() || symbol.isInternal()) {
        return false;
    }
    boolean previousWasBlock = false;
    for (final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) {
        final LexicalContextNode node = it.next();
        if (node instanceof FunctionNode) {
            // We reached the function boundary without seeing a definition for the symbol - it needs to be in
            // scope.
            return true;
        } else if (node instanceof WithNode) {
            if (previousWasBlock) {
                // We reached a WithNode; the symbol must be scoped. Note that if the WithNode was not immediately
                // preceded by a block, this means we're currently processing its expression, not its body,
                // therefore it doesn't count.
                return true;
            }
            previousWasBlock = false;
        } else if (node instanceof Block) {
            if (((Block)node).getExistingSymbol(symbol.getName()) == symbol) {
                // We reached the block that defines the symbol without reaching either the function boundary, or a
                // WithNode. The symbol need not be scoped.
                return false;
            }
            previousWasBlock = true;
        } else {
            previousWasBlock = false;
        }
    }
    throw new AssertionError();
}
 
Example #9
Source File: PrintVisitor.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterWithNode(final WithNode withNode) {
    withNode.toString(sb);
    withNode.getBody().accept(this);

    return false;
}
 
Example #10
Source File: Parser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * WithStatement :
 *      with ( Expression ) Statement
 *
 * See 12.10
 *
 * Parse WITH statement.
 */
private void withStatement() {
    // Capture WITH token.
    final int  withLine  = line;
    final long withToken = token;
    // WITH tested in caller.
    next();

    // ECMA 12.10.1 strict mode restrictions
    if (isStrictMode) {
        throw error(AbstractParser.message("strict.no.with"), withToken);
    }

    // Get WITH expression.
    WithNode withNode = new WithNode(withLine, withToken, finish);

    try {
        lc.push(withNode);
        expect(LPAREN);
        withNode = withNode.setExpression(lc, expression());
        expect(RPAREN);
        withNode = withNode.setBody(lc, getStatement());
    } finally {
        lc.pop(withNode);
    }

    appendStatement(withNode);
}
 
Example #11
Source File: LocalVariableTypesCalculator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterWithNode(final WithNode withNode) {
    if (reachable) {
        visitExpression(withNode.getExpression());
        withNode.getBody().accept(this);
    }
    return false;
}
 
Example #12
Source File: CodeGeneratorLexicalContext.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private boolean isDynamicScopeBoundary(final LexicalContextNode node) {
    if (node instanceof Block) {
        // Block's immediate parent is a with node. Note we aren't testing for a WithNode, as that'd capture
        // processing of WithNode.expression too, but it should be unaffected.
        return !isEmpty() && peek() instanceof WithNode;
    } else if (node instanceof FunctionNode) {
        // Function has a direct eval in it (so a top-level "var ..." in the eval code can introduce a new
        // variable into the function's scope), and it isn't strict (as evals in strict functions get an
        // isolated scope).
        return isFunctionDynamicScope((FunctionNode)node);
    }
    return false;
}
 
Example #13
Source File: LocalVariableTypesCalculator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterWithNode(final WithNode withNode) {
    if (reachable) {
        visitExpression(withNode.getExpression());
        withNode.getBody().accept(this);
    }
    return false;
}
 
Example #14
Source File: Attr.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private boolean symbolNeedsToBeScope(Symbol symbol) {
    if (symbol.isThis() || symbol.isInternal()) {
        return false;
    }
    boolean previousWasBlock = false;
    for (final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) {
        final LexicalContextNode node = it.next();
        if (node instanceof FunctionNode) {
            // We reached the function boundary without seeing a definition for the symbol - it needs to be in
            // scope.
            return true;
        } else if (node instanceof WithNode) {
            if (previousWasBlock) {
                // We reached a WithNode; the symbol must be scoped. Note that if the WithNode was not immediately
                // preceded by a block, this means we're currently processing its expression, not its body,
                // therefore it doesn't count.
                return true;
            }
            previousWasBlock = false;
        } else if (node instanceof Block) {
            if (((Block)node).getExistingSymbol(symbol.getName()) == symbol) {
                // We reached the block that defines the symbol without reaching either the function boundary, or a
                // WithNode. The symbol need not be scoped.
                return false;
            }
            previousWasBlock = true;
        } else {
            previousWasBlock = false;
        }
    }
    throw new AssertionError();
}
 
Example #15
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * WithStatement :
 *      with ( Expression ) Statement
 *
 * See 12.10
 *
 * Parse WITH statement.
 */
private void withStatement() {
    // Capture WITH token.
    final int  withLine  = line;
    final long withToken = token;
    // WITH tested in caller.
    next();

    // ECMA 12.10.1 strict mode restrictions
    if (isStrictMode) {
        throw error(AbstractParser.message("strict.no.with"), withToken);
    }

    // Get WITH expression.
    WithNode withNode = new WithNode(withLine, withToken, finish);

    try {
        lc.push(withNode);
        expect(LPAREN);
        withNode = withNode.setExpression(lc, expression());
        expect(RPAREN);
        withNode = withNode.setBody(lc, getStatement());
    } finally {
        lc.pop(withNode);
    }

    appendStatement(withNode);
}
 
Example #16
Source File: AssignSymbols.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines if the symbol has to be a scope symbol. In general terms, it has to be a scope symbol if it can only
 * be reached from the current block by traversing a function node, a split node, or a with node.
 * @param symbol the symbol checked for needing to be a scope symbol
 * @return true if the symbol has to be a scope symbol.
 */
private boolean symbolNeedsToBeScope(final Symbol symbol) {
    if (symbol.isThis() || symbol.isInternal()) {
        return false;
    }

    final FunctionNode func = lc.getCurrentFunction();
    if ( func.allVarsInScope() || (!symbol.isBlockScoped() && func.isProgram())) {
        return true;
    }

    boolean previousWasBlock = false;
    for (final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) {
        final LexicalContextNode node = it.next();
        if (node instanceof FunctionNode || isSplitLiteral(node)) {
            // We reached the function boundary or a splitting boundary without seeing a definition for the symbol.
            // It needs to be in scope.
            return true;
        } else if (node instanceof WithNode) {
            if (previousWasBlock) {
                // We reached a WithNode; the symbol must be scoped. Note that if the WithNode was not immediately
                // preceded by a block, this means we're currently processing its expression, not its body,
                // therefore it doesn't count.
                return true;
            }
            previousWasBlock = false;
        } else if (node instanceof Block) {
            if (((Block)node).getExistingSymbol(symbol.getName()) == symbol) {
                // We reached the block that defines the symbol without reaching either the function boundary, or a
                // WithNode. The symbol need not be scoped.
                return false;
            }
            previousWasBlock = true;
        } else {
            previousWasBlock = false;
        }
    }
    throw new AssertionError();
}
 
Example #17
Source File: PrintVisitor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterWithNode(final WithNode withNode) {
    withNode.toString(sb, printTypes);
    withNode.getBody().accept(this);

    return false;
}
 
Example #18
Source File: AssignSymbols.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines if the symbol has to be a scope symbol. In general terms, it has to be a scope symbol if it can only
 * be reached from the current block by traversing a function node, a split node, or a with node.
 * @param symbol the symbol checked for needing to be a scope symbol
 * @return true if the symbol has to be a scope symbol.
 */
private boolean symbolNeedsToBeScope(final Symbol symbol) {
    if (symbol.isThis() || symbol.isInternal()) {
        return false;
    }

    final FunctionNode func = lc.getCurrentFunction();
    if ( func.allVarsInScope() || (!symbol.isBlockScoped() && func.isProgram())) {
        return true;
    }

    boolean previousWasBlock = false;
    for (final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) {
        final LexicalContextNode node = it.next();
        if (node instanceof FunctionNode || isSplitLiteral(node)) {
            // We reached the function boundary or a splitting boundary without seeing a definition for the symbol.
            // It needs to be in scope.
            return true;
        } else if (node instanceof WithNode) {
            if (previousWasBlock) {
                // We reached a WithNode; the symbol must be scoped. Note that if the WithNode was not immediately
                // preceded by a block, this means we're currently processing its expression, not its body,
                // therefore it doesn't count.
                return true;
            }
            previousWasBlock = false;
        } else if (node instanceof Block) {
            if (((Block)node).getExistingSymbol(symbol.getName()) == symbol) {
                // We reached the block that defines the symbol without reaching either the function boundary, or a
                // WithNode. The symbol need not be scoped.
                return false;
            }
            previousWasBlock = true;
        } else {
            previousWasBlock = false;
        }
    }
    throw new AssertionError();
}
 
Example #19
Source File: PrintVisitor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterWithNode(final WithNode withNode) {
    withNode.toString(sb, printTypes);
    withNode.getBody().accept(this);

    return false;
}
 
Example #20
Source File: Parser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * WithStatement :
 *      with ( Expression ) Statement
 *
 * See 12.10
 *
 * Parse WITH statement.
 */
private void withStatement() {
    // Capture WITH token.
    final int  withLine  = line;
    final long withToken = token;
    // WITH tested in caller.
    next();

    // ECMA 12.10.1 strict mode restrictions
    if (isStrictMode) {
        throw error(AbstractParser.message("strict.no.with"), withToken);
    }

    // Get WITH expression.
    WithNode withNode = new WithNode(withLine, withToken, finish);

    try {
        lc.push(withNode);
        expect(LPAREN);
        withNode = withNode.setExpression(lc, expression());
        expect(RPAREN);
        withNode = withNode.setBody(lc, getStatement());
    } finally {
        lc.pop(withNode);
    }

    appendStatement(withNode);
}
 
Example #21
Source File: AssignSymbols.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines if the symbol has to be a scope symbol. In general terms, it has to be a scope symbol if it can only
 * be reached from the current block by traversing a function node, a split node, or a with node.
 * @param symbol the symbol checked for needing to be a scope symbol
 * @return true if the symbol has to be a scope symbol.
 */
private boolean symbolNeedsToBeScope(final Symbol symbol) {
    if (symbol.isThis() || symbol.isInternal()) {
        return false;
    }

    final FunctionNode func = lc.getCurrentFunction();
    if ( func.allVarsInScope() || (!symbol.isBlockScoped() && func.isProgram())) {
        return true;
    }

    boolean previousWasBlock = false;
    for (final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) {
        final LexicalContextNode node = it.next();
        if (node instanceof FunctionNode || isSplitLiteral(node)) {
            // We reached the function boundary or a splitting boundary without seeing a definition for the symbol.
            // It needs to be in scope.
            return true;
        } else if (node instanceof WithNode) {
            if (previousWasBlock) {
                // We reached a WithNode; the symbol must be scoped. Note that if the WithNode was not immediately
                // preceded by a block, this means we're currently processing its expression, not its body,
                // therefore it doesn't count.
                return true;
            }
            previousWasBlock = false;
        } else if (node instanceof Block) {
            if (((Block)node).getExistingSymbol(symbol.getName()) == symbol) {
                // We reached the block that defines the symbol without reaching either the function boundary, or a
                // WithNode. The symbol need not be scoped.
                return false;
            }
            previousWasBlock = true;
        } else {
            previousWasBlock = false;
        }
    }
    throw new AssertionError();
}
 
Example #22
Source File: AssignSymbols.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines if the symbol has to be a scope symbol. In general terms, it has to be a scope symbol if it can only
 * be reached from the current block by traversing a function node, a split node, or a with node.
 * @param symbol the symbol checked for needing to be a scope symbol
 * @return true if the symbol has to be a scope symbol.
 */
private boolean symbolNeedsToBeScope(final Symbol symbol) {
    if (symbol.isThis() || symbol.isInternal()) {
        return false;
    }

    final FunctionNode func = lc.getCurrentFunction();
    if ( func.allVarsInScope() || (!symbol.isBlockScoped() && func.isProgram())) {
        return true;
    }

    boolean previousWasBlock = false;
    for (final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) {
        final LexicalContextNode node = it.next();
        if (node instanceof FunctionNode || isSplitLiteral(node)) {
            // We reached the function boundary or a splitting boundary without seeing a definition for the symbol.
            // It needs to be in scope.
            return true;
        } else if (node instanceof WithNode) {
            if (previousWasBlock) {
                // We reached a WithNode; the symbol must be scoped. Note that if the WithNode was not immediately
                // preceded by a block, this means we're currently processing its expression, not its body,
                // therefore it doesn't count.
                return true;
            }
            previousWasBlock = false;
        } else if (node instanceof Block) {
            if (((Block)node).getExistingSymbol(symbol.getName()) == symbol) {
                // We reached the block that defines the symbol without reaching either the function boundary, or a
                // WithNode. The symbol need not be scoped.
                return false;
            }
            previousWasBlock = true;
        } else {
            previousWasBlock = false;
        }
    }
    throw new AssertionError();
}
 
Example #23
Source File: PrintVisitor.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterWithNode(final WithNode withNode) {
    withNode.toString(sb, printTypes);
    withNode.getBody().accept(this);

    return false;
}
 
Example #24
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterWithNode(final WithNode withNode) {
    if (reachable) {
        visitExpression(withNode.getExpression());
        withNode.getBody().accept(this);
    }
    return false;
}
 
Example #25
Source File: AssignSymbols.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines if the symbol has to be a scope symbol. In general terms, it has to be a scope symbol if it can only
 * be reached from the current block by traversing a function node, a split node, or a with node.
 * @param symbol the symbol checked for needing to be a scope symbol
 * @return true if the symbol has to be a scope symbol.
 */
private boolean symbolNeedsToBeScope(final Symbol symbol) {
    if (symbol.isThis() || symbol.isInternal()) {
        return false;
    }

    final FunctionNode func = lc.getCurrentFunction();
    if ( func.allVarsInScope() || (!symbol.isBlockScoped() && func.isProgram())) {
        return true;
    }

    boolean previousWasBlock = false;
    for (final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) {
        final LexicalContextNode node = it.next();
        if (node instanceof FunctionNode || isSplitLiteral(node)) {
            // We reached the function boundary or a splitting boundary without seeing a definition for the symbol.
            // It needs to be in scope.
            return true;
        } else if (node instanceof WithNode) {
            if (previousWasBlock) {
                // We reached a WithNode; the symbol must be scoped. Note that if the WithNode was not immediately
                // preceded by a block, this means we're currently processing its expression, not its body,
                // therefore it doesn't count.
                return true;
            }
            previousWasBlock = false;
        } else if (node instanceof Block) {
            if (((Block)node).getExistingSymbol(symbol.getName()) == symbol) {
                // We reached the block that defines the symbol without reaching either the function boundary, or a
                // WithNode. The symbol need not be scoped.
                return false;
            }
            previousWasBlock = true;
        } else {
            previousWasBlock = false;
        }
    }
    throw new AssertionError();
}
 
Example #26
Source File: Parser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * WithStatement :
 *      with ( Expression ) Statement
 *
 * See 12.10
 *
 * Parse WITH statement.
 */
private void withStatement() {
    // Capture WITH token.
    final int  withLine  = line;
    final long withToken = token;
    // WITH tested in caller.
    next();

    // ECMA 12.10.1 strict mode restrictions
    if (isStrictMode) {
        throw error(AbstractParser.message("strict.no.with"), withToken);
    }

    // Get WITH expression.
    WithNode withNode = new WithNode(withLine, withToken, finish);

    try {
        lc.push(withNode);
        expect(LPAREN);
        withNode = withNode.setExpression(lc, expression());
        expect(RPAREN);
        withNode = withNode.setBody(lc, getStatement());
    } finally {
        lc.pop(withNode);
    }

    appendStatement(withNode);
}
 
Example #27
Source File: Parser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * WithStatement :
 *      with ( Expression ) Statement
 *
 * See 12.10
 *
 * Parse WITH statement.
 */
private void withStatement() {
    // Capture WITH token.
    final int  withLine  = line;
    final long withToken = token;
    // WITH tested in caller.
    next();

    // ECMA 12.10.1 strict mode restrictions
    if (isStrictMode) {
        throw error(AbstractParser.message("strict.no.with"), withToken);
    }

    // Get WITH expression.
    WithNode withNode = new WithNode(withLine, withToken, finish);

    try {
        lc.push(withNode);
        expect(LPAREN);
        withNode = withNode.setExpression(lc, expression());
        expect(RPAREN);
        withNode = withNode.setBody(lc, getStatement());
    } finally {
        lc.pop(withNode);
    }

    appendStatement(withNode);
}
 
Example #28
Source File: PrintVisitor.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterWithNode(final WithNode withNode) {
    withNode.toString(sb, printTypes);
    withNode.getBody().accept(this);

    return false;
}
 
Example #29
Source File: LocalVariableTypesCalculator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterWithNode(final WithNode withNode) {
    if (reachable) {
        visitExpression(withNode.getExpression());
        withNode.getBody().accept(this);
    }
    return false;
}
 
Example #30
Source File: LocalVariableTypesCalculator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean enterWithNode(final WithNode withNode) {
    if (reachable) {
        visitExpression(withNode.getExpression());
        withNode.getBody().accept(this);
    }
    return false;
}