Search in sources :

Example 1 with ObjectEnvironmentRecord

use of com.github.anba.es6draft.runtime.ObjectEnvironmentRecord in project es6draft by anba.

the class ScriptRuntime method canDeclareVarBinding.

/**
     * 18.2.1.2 Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict)
     * 
     * @param varEnv
     *            the variable environment
     * @param lexEnv
     *            the lexical environment
     * @param name
     *            the function name
     * @param catchVar
     *            {@code true} if variable redeclarations are allowed in catch clauses
     * @return {@code true} if the name can be declared
     */
public static boolean canDeclareVarBinding(LexicalEnvironment<?> varEnv, LexicalEnvironment<DeclarativeEnvironmentRecord> lexEnv, String name, boolean catchVar) {
    for (LexicalEnvironment<?> thisEnv = lexEnv; thisEnv != varEnv; thisEnv = thisEnv.getOuter()) {
        EnvironmentRecord thisEnvRec = thisEnv.getEnvRec();
        if (thisEnvRec instanceof ObjectEnvironmentRecord) {
            continue;
        }
        DeclarativeEnvironmentRecord declEnvRec = (DeclarativeEnvironmentRecord) thisEnvRec;
        if (declEnvRec.hasBinding(name) && !(catchVar && declEnvRec.isCatchEnvironment())) {
            return false;
        }
    }
    return true;
}
Also used : ObjectEnvironmentRecord(com.github.anba.es6draft.runtime.ObjectEnvironmentRecord) ModuleEnvironmentRecord(com.github.anba.es6draft.runtime.ModuleEnvironmentRecord) FunctionEnvironmentRecord(com.github.anba.es6draft.runtime.FunctionEnvironmentRecord) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord) EnvironmentRecord(com.github.anba.es6draft.runtime.EnvironmentRecord) GlobalEnvironmentRecord(com.github.anba.es6draft.runtime.GlobalEnvironmentRecord) ObjectEnvironmentRecord(com.github.anba.es6draft.runtime.ObjectEnvironmentRecord) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)

Example 2 with ObjectEnvironmentRecord

use of com.github.anba.es6draft.runtime.ObjectEnvironmentRecord in project es6draft by anba.

the class DeclarationOperations method canDeclareVarBinding.

/**
 * 18.2.1.2 Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict)
 *
 * @param varEnv
 *            the variable environment
 * @param lexEnv
 *            the lexical environment
 * @param name
 *            the function name
 * @param catchVar
 *            {@code true} if variable redeclarations are allowed in catch clauses
 * @return {@code true} if the name can be declared
 */
public static boolean canDeclareVarBinding(LexicalEnvironment<?> varEnv, LexicalEnvironment<DeclarativeEnvironmentRecord> lexEnv, String name, boolean catchVar) {
    for (LexicalEnvironment<?> thisEnv = lexEnv; thisEnv != varEnv; thisEnv = thisEnv.getOuter()) {
        EnvironmentRecord thisEnvRec = thisEnv.getEnvRec();
        if (thisEnvRec instanceof ObjectEnvironmentRecord) {
            continue;
        }
        DeclarativeEnvironmentRecord declEnvRec = (DeclarativeEnvironmentRecord) thisEnvRec;
        if (declEnvRec.hasBinding(name) && !(catchVar && declEnvRec.isCatchEnvironment())) {
            return false;
        }
    }
    return true;
}
Also used : ObjectEnvironmentRecord(com.github.anba.es6draft.runtime.ObjectEnvironmentRecord) EnvironmentRecord(com.github.anba.es6draft.runtime.EnvironmentRecord) GlobalEnvironmentRecord(com.github.anba.es6draft.runtime.GlobalEnvironmentRecord) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord) ObjectEnvironmentRecord(com.github.anba.es6draft.runtime.ObjectEnvironmentRecord) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)

Aggregations

DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)2 EnvironmentRecord (com.github.anba.es6draft.runtime.EnvironmentRecord)2 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)2 ObjectEnvironmentRecord (com.github.anba.es6draft.runtime.ObjectEnvironmentRecord)2 FunctionEnvironmentRecord (com.github.anba.es6draft.runtime.FunctionEnvironmentRecord)1 ModuleEnvironmentRecord (com.github.anba.es6draft.runtime.ModuleEnvironmentRecord)1