Search in sources :

Example 1 with Scope

use of com.github.anba.es6draft.ast.scope.Scope in project es6draft by anba.

the class ExpressionGenerator method isGlobalThis.

private static boolean isGlobalThis(Scope currentScope) {
    for (Scope scope = currentScope; ; ) {
        TopLevelScope top = scope.getTop();
        TopLevelNode<?> node = top.getNode();
        if (node instanceof Script) {
            return ((Script) node).isGlobalThis();
        }
        if (node instanceof Module) {
            return true;
        }
        assert node instanceof FunctionNode : "class=" + node.getClass();
        if (((FunctionNode) node).getThisMode() != FunctionNode.ThisMode.Lexical) {
            return false;
        }
        scope = top.getEnclosingScope();
    }
}
Also used : WithScope(com.github.anba.es6draft.ast.scope.WithScope) Scope(com.github.anba.es6draft.ast.scope.Scope) BlockScope(com.github.anba.es6draft.ast.scope.BlockScope) TopLevelScope(com.github.anba.es6draft.ast.scope.TopLevelScope) TopLevelScope(com.github.anba.es6draft.ast.scope.TopLevelScope)

Example 2 with Scope

use of com.github.anba.es6draft.ast.scope.Scope in project es6draft by anba.

the class ExpressionGenerator method isEnclosedByLexicalDeclaration.

private boolean isEnclosedByLexicalDeclaration(Scope currentScope) {
    final boolean catchVar = codegen.isEnabled(CompatibilityOption.CatchVarStatement);
    final boolean catchPattern = codegen.isEnabled(CompatibilityOption.CatchVarPattern);
    TopLevelScope top = currentScope.getTop();
    for (Scope scope : currentScope) {
        if (scope instanceof BlockScope) {
            if (catchVar) {
                ScopedNode node = scope.getNode();
                if (node instanceof CatchClause) {
                    if (!catchPattern || ((CatchClause) node).getCatchParameter() instanceof BindingIdentifier) {
                        continue;
                    }
                }
            }
            if (!((BlockScope) scope).lexicallyDeclaredNames().isEmpty()) {
                return true;
            }
        } else if (scope == top) {
            break;
        }
    }
    if (!top.lexicallyDeclaredNames().isEmpty()) {
        TopLevelNode<?> topNode = top.getNode();
        if (topNode instanceof Script) {
            return ((Script) topNode).isEvalScript();
        }
        return true;
    }
    return codegen.isEnabled(Parser.Option.EnclosedByLexicalDeclaration);
}
Also used : WithScope(com.github.anba.es6draft.ast.scope.WithScope) Scope(com.github.anba.es6draft.ast.scope.Scope) BlockScope(com.github.anba.es6draft.ast.scope.BlockScope) TopLevelScope(com.github.anba.es6draft.ast.scope.TopLevelScope) BlockScope(com.github.anba.es6draft.ast.scope.BlockScope) TopLevelScope(com.github.anba.es6draft.ast.scope.TopLevelScope)

Aggregations

BlockScope (com.github.anba.es6draft.ast.scope.BlockScope)2 Scope (com.github.anba.es6draft.ast.scope.Scope)2 TopLevelScope (com.github.anba.es6draft.ast.scope.TopLevelScope)2 WithScope (com.github.anba.es6draft.ast.scope.WithScope)2