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;
}
Aggregations