Search in sources :

Example 1 with ComputedPropertyName

use of com.github.anba.es6draft.ast.ComputedPropertyName in project es6draft by anba.

the class PropertyGenerator method visit.

/**
     * 12.2.5.8 Runtime Semantics: PropertyDefinitionEvaluation
     * <p>
     * PropertyDefinition : PropertyName : AssignmentExpression
     */
@Override
public ValType visit(PropertyValueDefinition node, CodeVisitor mv) {
    Expression propertyValue = node.getPropertyValue();
    PropertyName propertyName = node.getPropertyName();
    String propName = PropName(propertyName);
    long propIndex = propName != null ? IndexedMap.toIndex(propName) : -1;
    // stack: [<object>] -> []
    if (propName == null) {
        assert propertyName instanceof ComputedPropertyName;
        ValType type = propertyName.accept(this, mv);
        expressionBoxed(propertyValue, mv);
        if (IsAnonymousFunctionDefinition(propertyValue)) {
            SetFunctionName(propertyValue, type, mv);
        }
        mv.loadExecutionContext();
        mv.lineInfo(node);
        mv.invoke(Methods.ScriptRuntime_defineProperty);
    } else if ("__proto__".equals(propName) && codegen.isEnabled(CompatibilityOption.ProtoInitializer)) {
        expressionBoxed(propertyValue, mv);
        mv.loadExecutionContext();
        mv.lineInfo(node);
        mv.invoke(Methods.ScriptRuntime_defineProtoProperty);
    } else if (IndexedMap.isIndex(propIndex)) {
        mv.lconst(propIndex);
        expressionBoxed(propertyValue, mv);
        if (IsAnonymousFunctionDefinition(propertyValue)) {
            SetFunctionName(propertyValue, propName, mv);
        }
        mv.loadExecutionContext();
        mv.lineInfo(node);
        mv.invoke(Methods.ScriptRuntime_defineProperty_long);
    } else {
        mv.aconst(propName);
        expressionBoxed(propertyValue, mv);
        if (IsAnonymousFunctionDefinition(propertyValue)) {
            SetFunctionName(propertyValue, propName, mv);
        }
        mv.loadExecutionContext();
        mv.lineInfo(node);
        mv.invoke(Methods.ScriptRuntime_defineProperty_String);
    }
    return null;
}
Also used : PropertyName(com.github.anba.es6draft.ast.PropertyName) ComputedPropertyName(com.github.anba.es6draft.ast.ComputedPropertyName) Expression(com.github.anba.es6draft.ast.Expression) ComputedPropertyName(com.github.anba.es6draft.ast.ComputedPropertyName)

Example 2 with ComputedPropertyName

use of com.github.anba.es6draft.ast.ComputedPropertyName in project es6draft by anba.

the class PropertyGenerator method visit.

/**
     * 14.3.9 Runtime Semantics: PropertyDefinitionEvaluation<br>
     * 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation
     */
@Override
public ValType visit(MethodDefinition node, CodeVisitor mv) {
    MethodName method = codegen.compile(node);
    boolean hasDecorators = !node.getDecorators().isEmpty();
    if (hasDecorators) {
        evaluateDecorators(decorators, node.getDecorators(), mv);
    }
    // stack: [<object>] -> []
    String propName = PropName(node);
    if (propName == null) {
        assert node.getPropertyName() instanceof ComputedPropertyName;
        ValType propKey = node.getPropertyName().accept(this, mv);
        if (hasDecorators) {
            addDecoratorKey(decorators, propKey, mv);
        }
        mv.iconst(node.getAllocation() == MethodDefinition.MethodAllocation.Object);
        mv.invoke(method);
        mv.loadExecutionContext();
        mv.lineInfo(node);
        switch(node.getType()) {
            case AsyncFunction:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionAsync);
                break;
            case AsyncGenerator:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionAsyncGenerator);
                break;
            case Function:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinition);
                break;
            case ConstructorGenerator:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionConstructorGenerator);
                break;
            case Generator:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionGenerator);
                break;
            case Getter:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionGetter);
                break;
            case Setter:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionSetter);
                break;
            case BaseConstructor:
            case DerivedConstructor:
            case CallConstructor:
            default:
                throw new AssertionError("invalid method type");
        }
    } else {
        if (hasDecorators) {
            addDecoratorKey(decorators, propName, mv);
        }
        mv.aconst(propName);
        mv.iconst(node.getAllocation() == MethodDefinition.MethodAllocation.Object);
        mv.invoke(method);
        mv.loadExecutionContext();
        mv.lineInfo(node);
        switch(node.getType()) {
            case AsyncFunction:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionAsync_String);
                break;
            case AsyncGenerator:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionAsyncGenerator_String);
                break;
            case Function:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinition_String);
                break;
            case ConstructorGenerator:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionConstructorGenerator_String);
                break;
            case Generator:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionGenerator_String);
                break;
            case Getter:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionGetter_String);
                break;
            case Setter:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionSetter_String);
                break;
            case BaseConstructor:
            case DerivedConstructor:
            case CallConstructor:
            default:
                throw new AssertionError("invalid method type");
        }
    }
    return null;
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) ComputedPropertyName(com.github.anba.es6draft.ast.ComputedPropertyName)

Aggregations

ComputedPropertyName (com.github.anba.es6draft.ast.ComputedPropertyName)2 Expression (com.github.anba.es6draft.ast.Expression)1 PropertyName (com.github.anba.es6draft.ast.PropertyName)1 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)1