Java Code Examples for jdk.nashorn.internal.ir.Symbol#isBlockScoped()

The following examples show how to use jdk.nashorn.internal.ir.Symbol#isBlockScoped() . 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: AssignSymbols.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveIdentNode(final IdentNode identNode) {
    if (identNode.isPropertyName()) {
        return identNode;
    }

    final Symbol symbol = nameIsUsed(identNode.getName(), identNode);

    if (!identNode.isInitializedHere()) {
        symbol.increaseUseCount();
    }

    IdentNode newIdentNode = identNode.setSymbol(symbol);

    // If a block-scoped var is used before its declaration mark it as dead.
    // We can only statically detect this for local vars, cross-function symbols require runtime checks.
    if (symbol.isBlockScoped() && !symbol.hasBeenDeclared() && !identNode.isDeclaredHere() && isLocal(lc.getCurrentFunction(), symbol)) {
        newIdentNode = newIdentNode.markDead();
    }

    return end(newIdentNode);
}
 
Example 2
Source File: AssignSymbols.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveIdentNode(final IdentNode identNode) {
    if (identNode.isPropertyName()) {
        return identNode;
    }

    final Symbol symbol = nameIsUsed(identNode.getName(), identNode);

    if (!identNode.isInitializedHere()) {
        symbol.increaseUseCount();
    }

    IdentNode newIdentNode = identNode.setSymbol(symbol);

    // If a block-scoped var is used before its declaration mark it as dead.
    // We can only statically detect this for local vars, cross-function symbols require runtime checks.
    if (symbol.isBlockScoped() && !symbol.hasBeenDeclared() && !identNode.isDeclaredHere() && isLocal(lc.getCurrentFunction(), symbol)) {
        newIdentNode = newIdentNode.markDead();
    }

    return end(newIdentNode);
}
 
Example 3
Source File: AssignSymbols.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveIdentNode(final IdentNode identNode) {
    if (identNode.isPropertyName()) {
        return identNode;
    }

    final Symbol symbol = nameIsUsed(identNode.getName(), identNode);

    if (!identNode.isInitializedHere()) {
        symbol.increaseUseCount();
    }

    IdentNode newIdentNode = identNode.setSymbol(symbol);

    // If a block-scoped var is used before its declaration mark it as dead.
    // We can only statically detect this for local vars, cross-function symbols require runtime checks.
    if (symbol.isBlockScoped() && !symbol.hasBeenDeclared() && !identNode.isDeclaredHere() && isLocal(lc.getCurrentFunction(), symbol)) {
        newIdentNode = newIdentNode.markDead();
    }

    return end(newIdentNode);
}
 
Example 4
Source File: AssignSymbols.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveIdentNode(final IdentNode identNode) {
    if (identNode.isPropertyName()) {
        return identNode;
    }

    final Symbol symbol = nameIsUsed(identNode.getName(), identNode);

    if (!identNode.isInitializedHere()) {
        symbol.increaseUseCount();
    }

    IdentNode newIdentNode = identNode.setSymbol(symbol);

    // If a block-scoped var is used before its declaration mark it as dead.
    // We can only statically detect this for local vars, cross-function symbols require runtime checks.
    if (symbol.isBlockScoped() && !symbol.hasBeenDeclared() && !identNode.isDeclaredHere() && isLocal(lc.getCurrentFunction(), symbol)) {
        newIdentNode = newIdentNode.markDead();
    }

    return end(newIdentNode);
}
 
Example 5
Source File: AssignSymbols.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveIdentNode(final IdentNode identNode) {
    if (identNode.isPropertyName()) {
        return identNode;
    }

    final Symbol symbol = nameIsUsed(identNode.getName(), identNode);

    if (!identNode.isInitializedHere()) {
        symbol.increaseUseCount();
    }

    IdentNode newIdentNode = identNode.setSymbol(symbol);

    // If a block-scoped var is used before its declaration mark it as dead.
    // We can only statically detect this for local vars, cross-function symbols require runtime checks.
    if (symbol.isBlockScoped() && !symbol.hasBeenDeclared() && !identNode.isDeclaredHere() && isLocal(lc.getCurrentFunction(), symbol)) {
        newIdentNode = newIdentNode.markDead();
    }

    return end(newIdentNode);
}
 
Example 6
Source File: AssignSymbols.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveIdentNode(final IdentNode identNode) {
    if (identNode.isPropertyName()) {
        return identNode;
    }

    final Symbol symbol = nameIsUsed(identNode.getName(), identNode);

    if (!identNode.isInitializedHere()) {
        symbol.increaseUseCount();
    }

    IdentNode newIdentNode = identNode.setSymbol(symbol);

    // If a block-scoped var is used before its declaration mark it as dead.
    // We can only statically detect this for local vars, cross-function symbols require runtime checks.
    if (symbol.isBlockScoped() && !symbol.hasBeenDeclared() && !identNode.isDeclaredHere() && isLocal(lc.getCurrentFunction(), symbol)) {
        newIdentNode = newIdentNode.markDead();
    }

    return end(newIdentNode);
}
 
Example 7
Source File: AssignSymbols.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveIdentNode(final IdentNode identNode) {
    if (identNode.isPropertyName()) {
        return identNode;
    }

    final Symbol symbol = nameIsUsed(identNode.getName(), identNode);

    if (!identNode.isInitializedHere()) {
        symbol.increaseUseCount();
    }

    IdentNode newIdentNode = identNode.setSymbol(symbol);

    // If a block-scoped var is used before its declaration mark it as dead.
    // We can only statically detect this for local vars, cross-function symbols require runtime checks.
    if (symbol.isBlockScoped() && !symbol.hasBeenDeclared() && !identNode.isDeclaredHere() && isLocal(lc.getCurrentFunction(), symbol)) {
        newIdentNode = newIdentNode.markDead();
    }

    return end(newIdentNode);
}
 
Example 8
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 9
Source File: AssignSymbols.java    From jdk8u_nashorn 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 10
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 11
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 12
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 13
Source File: AssignSymbols.java    From jdk8u60 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 || isSplitArray(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 14
Source File: MapCreator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute property flags given local state of a field. May be overridden and extended,
 *
 * @param symbol       symbol to check
 * @param hasArguments does the created object have an "arguments" property
 *
 * @return flags to use for fields
 */
static int getPropertyFlags(final Symbol symbol, final boolean hasArguments, final boolean evalCode, final boolean dualFields) {
    int flags = 0;

    if (symbol.isParam()) {
        flags |= Property.IS_PARAMETER;
    }

    if (hasArguments) {
        flags |= Property.HAS_ARGUMENTS;
    }

    // See ECMA 5.1 10.5 Declaration Binding Instantiation.
    // Step 2  If code is eval code, then let configurableBindings
    // be true else let configurableBindings be false.
    // We have to make vars, functions declared in 'eval' code
    // configurable. But vars, functions from any other code is
    // not configurable.
    if (symbol.isScope() && !evalCode) {
        flags |= Property.NOT_CONFIGURABLE;
    }

    if (symbol.isFunctionDeclaration()) {
        flags |= Property.IS_FUNCTION_DECLARATION;
    }

    if (symbol.isConst()) {
        flags |= Property.NOT_WRITABLE;
    }

    if (symbol.isBlockScoped()) {
        flags |= Property.IS_LEXICAL_BINDING;
    }

    // Mark symbol as needing declaration. Access before declaration will throw a ReferenceError.
    if (symbol.isBlockScoped() && symbol.isScope()) {
        flags |= Property.NEEDS_DECLARATION;
    }

    if (dualFields) {
        flags |= Property.DUAL_FIELDS;
    }

    return flags;
}
 
Example 15
Source File: MapCreator.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute property flags given local state of a field. May be overridden and extended,
 *
 * @param symbol       symbol to check
 * @param hasArguments does the created object have an "arguments" property
 *
 * @return flags to use for fields
 */
static int getPropertyFlags(final Symbol symbol, final boolean hasArguments, final boolean evalCode, final boolean dualFields) {
    int flags = 0;

    if (symbol.isParam()) {
        flags |= Property.IS_PARAMETER;
    }

    if (hasArguments) {
        flags |= Property.HAS_ARGUMENTS;
    }

    // See ECMA 5.1 10.5 Declaration Binding Instantiation.
    // Step 2  If code is eval code, then let configurableBindings
    // be true else let configurableBindings be false.
    // We have to make vars, functions declared in 'eval' code
    // configurable. But vars, functions from any other code is
    // not configurable.
    if (symbol.isScope() && !evalCode) {
        flags |= Property.NOT_CONFIGURABLE;
    }

    if (symbol.isFunctionDeclaration()) {
        flags |= Property.IS_FUNCTION_DECLARATION;
    }

    if (symbol.isConst()) {
        flags |= Property.NOT_WRITABLE;
    }

    if (symbol.isBlockScoped()) {
        flags |= Property.IS_LEXICAL_BINDING;
    }

    // Mark symbol as needing declaration. Access before declaration will throw a ReferenceError.
    if (symbol.isBlockScoped() && symbol.isScope()) {
        flags |= Property.NEEDS_DECLARATION;
    }

    if (dualFields) {
        flags |= Property.DUAL_FIELDS;
    }

    return flags;
}
 
Example 16
Source File: MapCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute property flags given local state of a field. May be overridden and extended,
 *
 * @param symbol       symbol to check
 * @param hasArguments does the created object have an "arguments" property
 *
 * @return flags to use for fields
 */
static int getPropertyFlags(final Symbol symbol, final boolean hasArguments, final boolean evalCode, final boolean dualFields) {
    int flags = 0;

    if (symbol.isParam()) {
        flags |= Property.IS_PARAMETER;
    }

    if (hasArguments) {
        flags |= Property.HAS_ARGUMENTS;
    }

    // See ECMA 5.1 10.5 Declaration Binding Instantiation.
    // Step 2  If code is eval code, then let configurableBindings
    // be true else let configurableBindings be false.
    // We have to make vars, functions declared in 'eval' code
    // configurable. But vars, functions from any other code is
    // not configurable.
    if (symbol.isScope() && !evalCode) {
        flags |= Property.NOT_CONFIGURABLE;
    }

    if (symbol.isFunctionDeclaration()) {
        flags |= Property.IS_FUNCTION_DECLARATION;
    }

    if (symbol.isConst()) {
        flags |= Property.NOT_WRITABLE;
    }

    if (symbol.isBlockScoped()) {
        flags |= Property.IS_LEXICAL_BINDING;
    }

    // Mark symbol as needing declaration. Access before declaration will throw a ReferenceError.
    if (symbol.isBlockScoped() && symbol.isScope()) {
        flags |= Property.NEEDS_DECLARATION;
    }

    if (dualFields) {
        flags |= Property.DUAL_FIELDS;
    }

    return flags;
}
 
Example 17
Source File: MapCreator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute property flags given local state of a field. May be overridden and extended,
 *
 * @param symbol       symbol to check
 * @param hasArguments does the created object have an "arguments" property
 *
 * @return flags to use for fields
 */
static int getPropertyFlags(final Symbol symbol, final boolean hasArguments, final boolean evalCode, final boolean dualFields) {
    int flags = 0;

    if (symbol.isParam()) {
        flags |= Property.IS_PARAMETER;
    }

    if (hasArguments) {
        flags |= Property.HAS_ARGUMENTS;
    }

    // See ECMA 5.1 10.5 Declaration Binding Instantiation.
    // Step 2  If code is eval code, then let configurableBindings
    // be true else let configurableBindings be false.
    // We have to make vars, functions declared in 'eval' code
    // configurable. But vars, functions from any other code is
    // not configurable.
    if (symbol.isScope() && !evalCode) {
        flags |= Property.NOT_CONFIGURABLE;
    }

    if (symbol.isFunctionDeclaration()) {
        flags |= Property.IS_FUNCTION_DECLARATION;
    }

    if (symbol.isConst()) {
        flags |= Property.NOT_WRITABLE;
    }

    if (symbol.isBlockScoped()) {
        flags |= Property.IS_LEXICAL_BINDING;
    }

    // Mark symbol as needing declaration. Access before declaration will throw a ReferenceError.
    if (symbol.isBlockScoped() && symbol.isScope()) {
        flags |= Property.NEEDS_DECLARATION;
    }

    if (dualFields) {
        flags |= Property.DUAL_FIELDS;
    }

    return flags;
}
 
Example 18
Source File: MapCreator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute property flags given local state of a field. May be overridden and extended,
 *
 * @param symbol       symbol to check
 * @param hasArguments does the created object have an "arguments" property
 *
 * @return flags to use for fields
 */
static int getPropertyFlags(final Symbol symbol, final boolean hasArguments, final boolean evalCode, final boolean dualFields) {
    int flags = 0;

    if (symbol.isParam()) {
        flags |= Property.IS_PARAMETER;
    }

    if (hasArguments) {
        flags |= Property.HAS_ARGUMENTS;
    }

    // See ECMA 5.1 10.5 Declaration Binding Instantiation.
    // Step 2  If code is eval code, then let configurableBindings
    // be true else let configurableBindings be false.
    // We have to make vars, functions declared in 'eval' code
    // configurable. But vars, functions from any other code is
    // not configurable.
    if (symbol.isScope() && !evalCode) {
        flags |= Property.NOT_CONFIGURABLE;
    }

    if (symbol.isFunctionDeclaration()) {
        flags |= Property.IS_FUNCTION_DECLARATION;
    }

    if (symbol.isConst()) {
        flags |= Property.NOT_WRITABLE;
    }

    if (symbol.isBlockScoped()) {
        flags |= Property.IS_LEXICAL_BINDING;
    }

    // Mark symbol as needing declaration. Access before declaration will throw a ReferenceError.
    if (symbol.isBlockScoped() && symbol.isScope()) {
        flags |= Property.NEEDS_DECLARATION;
    }

    if (dualFields) {
        flags |= Property.DUAL_FIELDS;
    }

    return flags;
}
 
Example 19
Source File: MapCreator.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute property flags given local state of a field. May be overridden and extended,
 *
 * @param symbol       symbol to check
 * @param hasArguments does the created object have an "arguments" property
 *
 * @return flags to use for fields
 */
static int getPropertyFlags(final Symbol symbol, final boolean hasArguments, final boolean evalCode, final boolean dualFields) {
    int flags = 0;

    if (symbol.isParam()) {
        flags |= Property.IS_PARAMETER;
    }

    if (hasArguments) {
        flags |= Property.HAS_ARGUMENTS;
    }

    // See ECMA 5.1 10.5 Declaration Binding Instantiation.
    // Step 2  If code is eval code, then let configurableBindings
    // be true else let configurableBindings be false.
    // We have to make vars, functions declared in 'eval' code
    // configurable. But vars, functions from any other code is
    // not configurable.
    if (symbol.isScope() && !evalCode) {
        flags |= Property.NOT_CONFIGURABLE;
    }

    if (symbol.isFunctionDeclaration()) {
        flags |= Property.IS_FUNCTION_DECLARATION;
    }

    if (symbol.isConst()) {
        flags |= Property.NOT_WRITABLE;
    }

    if (symbol.isBlockScoped()) {
        flags |= Property.IS_LEXICAL_BINDING;
    }

    // Mark symbol as needing declaration. Access before declaration will throw a ReferenceError.
    if (symbol.isBlockScoped() && symbol.isScope()) {
        flags |= Property.NEEDS_DECLARATION;
    }

    if (dualFields) {
        flags |= Property.DUAL_FIELDS;
    }

    return flags;
}
 
Example 20
Source File: MapCreator.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute property flags given local state of a field. May be overridden and extended,
 *
 * @param symbol       symbol to check
 * @param hasArguments does the created object have an "arguments" property
 *
 * @return flags to use for fields
 */
static int getPropertyFlags(final Symbol symbol, final boolean hasArguments, final boolean evalCode, final boolean dualFields) {
    int flags = 0;

    if (symbol.isParam()) {
        flags |= Property.IS_PARAMETER;
    }

    if (hasArguments) {
        flags |= Property.HAS_ARGUMENTS;
    }

    // See ECMA 5.1 10.5 Declaration Binding Instantiation.
    // Step 2  If code is eval code, then let configurableBindings
    // be true else let configurableBindings be false.
    // We have to make vars, functions declared in 'eval' code
    // configurable. But vars, functions from any other code is
    // not configurable.
    if (symbol.isScope() && !evalCode) {
        flags |= Property.NOT_CONFIGURABLE;
    }

    if (symbol.isFunctionDeclaration()) {
        flags |= Property.IS_FUNCTION_DECLARATION;
    }

    if (symbol.isConst()) {
        flags |= Property.NOT_WRITABLE;
    }

    if (symbol.isBlockScoped()) {
        flags |= Property.IS_LEXICAL_BINDING;
    }

    // Mark symbol as needing declaration. Access before declaration will throw a ReferenceError.
    if (symbol.isBlockScoped() && symbol.isScope()) {
        flags |= Property.NEEDS_DECLARATION;
    }

    if (dualFields) {
        flags |= Property.DUAL_FIELDS;
    }

    return flags;
}