Search in sources :

Example 31 with Name

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

the class Parser method checkFormalParameterDuplicationStrict.

private void checkFormalParameterDuplicationStrict(FunctionNode node, List<Name> boundNames, NameSet names) {
    boolean hasDuplicates = (boundNames.size() != names.size());
    if (hasDuplicates) {
        Name duplicate = findDuplicate(names, boundNames);
        BindingIdentifier parameter = FindParameter.find(node, duplicate);
        reportStrictModeSyntaxError(parameter, Messages.Key.DuplicateFormalParameter, duplicate);
    }
}
Also used : Name(com.github.anba.es6draft.ast.scope.Name)

Example 32 with Name

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

the class Parser method hasEnclosingLexicalDeclaration.

private boolean hasEnclosingLexicalDeclaration(FunctionDeclaration function, ScopeContext topScope) {
    Name name = function.getIdentifier().getName();
    ScopeContext enclosingScope = (ScopeContext) function.getScope().getEnclosingScope();
    // Top-level function declarations are not applicable for legacy semantics.
    assert enclosingScope != topScope : "top-level function declaration";
    assert enclosingScope.isDeclared(name) : "undeclared block scoped function: " + name;
    for (ScopeContext scope = enclosingScope; (scope = scope.parent) != topScope; ) {
        // See 13.12.1 Static Semantics: Early Errors
        if (scope.isDeclared(name)) {
            // Found a block scoped, lexical declaration - cannot declare function as var.
            if (scope instanceof CatchContext) {
                // Unless "B.3.5 VariableStatements in Catch blocks" applies.
                continue;
            }
            return true;
        }
    }
    return false;
}
Also used : Name(com.github.anba.es6draft.ast.scope.Name)

Example 33 with Name

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

the class Parser method addVarDeclaredName.

private void addVarDeclaredName(BindingIdentifier bindingIdentifier) {
    Name name = BoundName(bindingIdentifier);
    addVarDeclaredName(bindingIdentifier, name, Parser::redeclarationNode);
}
Also used : Name(com.github.anba.es6draft.ast.scope.Name) RegExpParser(com.github.anba.es6draft.regexp.RegExpParser)

Example 34 with Name

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

the class RuntimeInfoGenerator method hasMappedOrLegacyArguments.

private boolean hasMappedOrLegacyArguments(FunctionNode node) {
    // Strict or arrow functions never have mapped arguments.
    if (IsStrict(node) || node.getThisMode() == FunctionNode.ThisMode.Lexical) {
        return false;
    }
    // Functions with non-simple parameters (or no parameters at all) also never have mapped arguments.
    FormalParameterList formals = node.getParameters();
    if (formals.getFormals().isEmpty() || !IsSimpleParameterList(formals)) {
        return false;
    }
    // Legacy functions always need the argument name mapping.
    if (hasLegacyArguments(node)) {
        return true;
    }
    // No mapping needed when 'arguments' is never accessed.
    boolean argumentsObjectNeeded = node.getScope().needsArguments();
    Name arguments = node.getScope().arguments();
    if (!argumentsObjectNeeded || arguments == null) {
        return false;
    }
    // Or a parameter named 'arguments' is present.
    if (BoundNames(formals).contains(arguments)) {
        return false;
    }
    // Or a lexical variable named 'arguments' is present.
    if (LexicallyDeclaredNames(node).contains(arguments)) {
        return false;
    }
    // Or a function named 'arguments' is present.
    for (StatementListItem item : VarScopedDeclarations(node)) {
        if (item instanceof HoistableDeclaration) {
            HoistableDeclaration d = (HoistableDeclaration) item;
            if (arguments.equals(BoundName(d))) {
                return false;
            }
        }
    }
    return true;
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) Name(com.github.anba.es6draft.ast.scope.Name)

Example 35 with Name

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

the class StatementGenerator method BindingClassDeclarationEvaluation.

/**
 * 14.5.15 Runtime Semantics: BindingClassDeclarationEvaluation
 *
 * @param node
 *            the class declaration node
 * @param mv
 *            the code visitor
 */
private void BindingClassDeclarationEvaluation(ClassDeclaration node, CodeVisitor mv) {
    if (node.getIdentifier() != null) {
        /* step 1 */
        Name className = node.getIdentifier().getName();
        /* steps 2-3 */
        ClassDefinitionEvaluation(node, className, mv);
        /* steps 4-6 */
        SetFunctionName(node, className, mv);
        /* steps 7-9 */
        // stack: [value] -> []
        InitializeBoundNameWithValue(className, FunctionObject.class, mv);
    /* step 10 (return) */
    } else {
        // stack: [] -> [value]
        ClassDefinitionEvaluation(node, null, mv);
    }
}
Also used : InitializeBoundName(com.github.anba.es6draft.compiler.BindingInitializationGenerator.InitializeBoundName) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) Name(com.github.anba.es6draft.ast.scope.Name)

Aggregations

Name (com.github.anba.es6draft.ast.scope.Name)49 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)31 DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)24 LexicalEnvironment (com.github.anba.es6draft.runtime.LexicalEnvironment)16 HoistableDeclaration (com.github.anba.es6draft.ast.HoistableDeclaration)13 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)13 StatementListItem (com.github.anba.es6draft.ast.StatementListItem)12 Declaration (com.github.anba.es6draft.ast.Declaration)11 Jump (com.github.anba.es6draft.compiler.assembler.Jump)11 HashSet (java.util.HashSet)11 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)10 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)10 BlockScope (com.github.anba.es6draft.ast.scope.BlockScope)9 InitializeBoundName (com.github.anba.es6draft.compiler.BindingInitializationGenerator.InitializeBoundName)9 FunctionDeclaration (com.github.anba.es6draft.ast.FunctionDeclaration)8 VariableStatement (com.github.anba.es6draft.ast.VariableStatement)8 ArrayDeque (java.util.ArrayDeque)8 IdentifierName (com.github.anba.es6draft.ast.IdentifierName)7 VariableDeclaration (com.github.anba.es6draft.ast.VariableDeclaration)6 EnvironmentRecord (com.github.anba.es6draft.runtime.EnvironmentRecord)6