Search in sources :

Example 1 with PropertyEvaluation

use of com.github.anba.es6draft.compiler.PropertyGenerator.PropertyEvaluation in project es6draft by anba.

the class ExpressionGenerator method visit.

/**
 * 12.2.6 Object Initializer
 * <p>
 * 12.2.6.8 Runtime Semantics: Evaluation
 */
@Override
public ValType visit(ObjectLiteral node, CodeVisitor mv) {
    List<MethodDefinition> decoratedMethods = DecoratedMethods(node.getProperties());
    if (decoratedMethods.isEmpty()) {
        /* step 1 */
        mv.loadExecutionContext();
        mv.get(Fields.Intrinsics_ObjectPrototype);
        mv.invoke(Methods.OrdinaryObject_ObjectCreate);
        /* steps 2-3 */
        PropertyEvaluation(codegen, node.getProperties(), mv);
        /* step 4 */
        return ValType.Object;
    }
    mv.enterVariableScope();
    /* step 1 */
    Variable<OrdinaryObject> object = mv.newVariable("object", OrdinaryObject.class);
    mv.loadExecutionContext();
    mv.get(Fields.Intrinsics_ObjectPrototype);
    mv.invoke(Methods.OrdinaryObject_ObjectCreate);
    mv.store(object);
    int decoratorsCount = decoratedMethods.stream().mapToInt(m -> m.getDecorators().size()).sum();
    int decoratorsLength = decoratorsCount + decoratedMethods.size();
    StoreToArray<Object> methodDecorators = StoreToArray.create("methodDecorators", decoratorsLength, Object[].class, mv);
    /* steps 2-3 */
    PropertyEvaluation(codegen, node.getProperties(), object, methodDecorators, mv);
    MethodName decoratorsMethod = mv.compile(node, this::objectMethodDecorators);
    // 0 = hint for stacktraces to omit this frame
    mv.lineInfo(0);
    mv.invoke(decoratorsMethod, mv.executionContext(), object, methodDecorators.array);
    mv.load(object);
    mv.exitVariableScope();
    /* step 4 */
    return ValType.Object;
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ListIterator(java.util.ListIterator) MutableValue(com.github.anba.es6draft.compiler.assembler.MutableValue) SIMDType(com.github.anba.es6draft.runtime.objects.simd.SIMDType) EvaluateArrayComprehension(com.github.anba.es6draft.compiler.ArrayComprehensionGenerator.EvaluateArrayComprehension) ArrayList(java.util.ArrayList) Variable(com.github.anba.es6draft.compiler.assembler.Variable) Type(com.github.anba.es6draft.compiler.assembler.Type) Completion(com.github.anba.es6draft.compiler.StatementGenerator.Completion) WithScope(com.github.anba.es6draft.ast.scope.WithScope) ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType) Scope(com.github.anba.es6draft.ast.scope.Scope) OutlinedCall(com.github.anba.es6draft.compiler.CodeVisitor.OutlinedCall) BigInteger(java.math.BigInteger) MethodTypeDescriptor(com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) AbstractOperations(com.github.anba.es6draft.runtime.AbstractOperations) CompatibilityOption(com.github.anba.es6draft.runtime.internal.CompatibilityOption) Parser(com.github.anba.es6draft.parser.Parser) EvalFlags(com.github.anba.es6draft.runtime.objects.Eval.EvalFlags) StaticSemantics(com.github.anba.es6draft.semantics.StaticSemantics) Jump(com.github.anba.es6draft.compiler.assembler.Jump) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) SpreadElementMethod(com.github.anba.es6draft.ast.synthetic.SpreadElementMethod) Objects(java.util.Objects) com.github.anba.es6draft.ast(com.github.anba.es6draft.ast) BlockScope(com.github.anba.es6draft.ast.scope.BlockScope) TopLevelScope(com.github.anba.es6draft.ast.scope.TopLevelScope) CompletionValueVisitor(com.github.anba.es6draft.compiler.completion.CompletionValueVisitor) List(java.util.List) Name(com.github.anba.es6draft.ast.scope.Name) PropertyEvaluation(com.github.anba.es6draft.compiler.PropertyGenerator.PropertyEvaluation) FieldName(com.github.anba.es6draft.compiler.assembler.FieldName) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Value(com.github.anba.es6draft.compiler.assembler.Value) NativeCalls(com.github.anba.es6draft.runtime.internal.NativeCalls) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) ExpressionMethod(com.github.anba.es6draft.ast.synthetic.ExpressionMethod) Bootstrap(com.github.anba.es6draft.runtime.internal.Bootstrap) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Aggregations

com.github.anba.es6draft.ast (com.github.anba.es6draft.ast)1 BlockScope (com.github.anba.es6draft.ast.scope.BlockScope)1 Name (com.github.anba.es6draft.ast.scope.Name)1 Scope (com.github.anba.es6draft.ast.scope.Scope)1 TopLevelScope (com.github.anba.es6draft.ast.scope.TopLevelScope)1 WithScope (com.github.anba.es6draft.ast.scope.WithScope)1 ExpressionMethod (com.github.anba.es6draft.ast.synthetic.ExpressionMethod)1 SpreadElementMethod (com.github.anba.es6draft.ast.synthetic.SpreadElementMethod)1 EvaluateArrayComprehension (com.github.anba.es6draft.compiler.ArrayComprehensionGenerator.EvaluateArrayComprehension)1 OutlinedCall (com.github.anba.es6draft.compiler.CodeVisitor.OutlinedCall)1 ValType (com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType)1 PropertyEvaluation (com.github.anba.es6draft.compiler.PropertyGenerator.PropertyEvaluation)1 Completion (com.github.anba.es6draft.compiler.StatementGenerator.Completion)1 MethodCode (com.github.anba.es6draft.compiler.assembler.Code.MethodCode)1 FieldName (com.github.anba.es6draft.compiler.assembler.FieldName)1 Jump (com.github.anba.es6draft.compiler.assembler.Jump)1 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)1 MethodTypeDescriptor (com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor)1 MutableValue (com.github.anba.es6draft.compiler.assembler.MutableValue)1 Type (com.github.anba.es6draft.compiler.assembler.Type)1