Search in sources :

Example 1 with ClassFieldScope

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

the class StatementGenerator method visit.

@Override
public Completion visit(ClassFieldInitializer node, CodeVisitor mv) {
    ClassFieldDefinition field = node.getField();
    // stack: [] -> [fieldName]
    ValType type = expressionBoxed(node.getFieldName(), mv);
    // stack: [fieldName] -> [fieldName, value]
    Expression initializer = field.getInitializer();
    ClassFieldScope scope = node.getScope();
    assert (initializer != null) == (scope != null);
    if (initializer != null) {
        mv.enterScope(node);
        if (!scope.isPresent()) {
            expressionBoxed(initializer, mv);
        } else {
            Variable<LexicalEnvironment<?>> env = saveEnvironment(mv);
            newClassFieldInitializerEnvironment(env, mv);
            if (!scope.varDeclaredNames().isEmpty()) {
                Variable<DeclarativeEnvironmentRecord> classFieldEnvRec = mv.newVariable("classFieldEnvRec", DeclarativeEnvironmentRecord.class);
                getVariableEnvironmentRecord(classFieldEnvRec, mv);
                for (Name varName : scope.varDeclaredNames()) {
                    BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(classFieldEnvRec, varName);
                    op.createMutableBinding(classFieldEnvRec, varName, false, mv);
                    op.initializeBinding(classFieldEnvRec, varName, mv.undefinedValue(), mv);
                }
            }
            expressionBoxed(initializer, mv);
            setVariableAndLexicalEnvironment(env, mv);
        }
        mv.exitScope();
        if (IsAnonymousFunctionDefinition(initializer)) {
            SetFunctionName(initializer, type, mv);
        }
    } else {
        mv.loadUndefined();
    }
    mv.loadExecutionContext();
    mv.lineInfo(node);
    mv.invoke(Methods.ClassOperations_DefineField);
    return Completion.Normal;
}
Also used : ClassFieldScope(com.github.anba.es6draft.ast.scope.ClassFieldScope) LexicalEnvironment(com.github.anba.es6draft.runtime.LexicalEnvironment) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord) 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

ClassFieldScope (com.github.anba.es6draft.ast.scope.ClassFieldScope)1 Name (com.github.anba.es6draft.ast.scope.Name)1 InitializeBoundName (com.github.anba.es6draft.compiler.BindingInitializationGenerator.InitializeBoundName)1 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)1 DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)1 LexicalEnvironment (com.github.anba.es6draft.runtime.LexicalEnvironment)1