Search in sources :

Example 51 with OrdinaryObject

use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.

the class DefaultCodeGenerator method ClassDefinitionEvaluation.

/**
     * 14.5.14 Runtime Semantics: ClassDefinitionEvaluation
     * 
     * @param def
     *            the class definition node
     * @param className
     *            the class name or {@code null} if not present
     * @param mv
     *            the code visitor
     */
protected final void ClassDefinitionEvaluation(ClassDefinition def, Name className, CodeVisitor mv) {
    mv.enterVariableScope();
    Variable<ArrayList<Callable>> classDecorators = null;
    boolean hasClassDecorators = !def.getDecorators().isEmpty();
    if (hasClassDecorators) {
        classDecorators = newDecoratorVariable("classDecorators", mv);
        evaluateDecorators(classDecorators, def.getDecorators(), mv);
    }
    mv.enterClassDefinition();
    // step 1 (not applicable)
    // steps 2-4
    BlockScope scope = def.getScope();
    assert (scope != null && scope.isPresent()) == (className != null);
    Variable<DeclarativeEnvironmentRecord> classScopeEnvRec = null;
    if (className != null) {
        // stack: [] -> [classScope]
        newDeclarativeEnvironment(scope, mv);
        classScopeEnvRec = mv.newVariable("classScopeEnvRec", DeclarativeEnvironmentRecord.class);
        getEnvRec(classScopeEnvRec, mv);
        // stack: [classScope] -> [classScope]
        Name innerName = scope.resolveName(className, false);
        BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(classScopeEnvRec, innerName);
        op.createImmutableBinding(classScopeEnvRec, innerName, true, mv);
        // stack: [classScope] -> []
        pushLexicalEnvironment(mv);
        mv.enterScope(def);
    }
    // steps 5-7
    // stack: [] -> [<constructorParent,proto>]
    Expression classHeritage = def.getHeritage();
    if (classHeritage == null) {
        mv.loadExecutionContext();
        mv.invoke(Methods.ScriptRuntime_getDefaultClassProto);
    } else if (classHeritage instanceof NullLiteral) {
        mv.loadExecutionContext();
        mv.invoke(Methods.ScriptRuntime_getClassProto_Null);
    } else {
        expressionBoxed(classHeritage, mv);
        mv.loadExecutionContext();
        mv.lineInfo(def);
        mv.invoke(Methods.ScriptRuntime_getClassProto);
    }
    // stack: [<constructorParent,proto>] -> [<constructorParent,proto>]
    Variable<OrdinaryObject> proto = mv.newVariable("proto", OrdinaryObject.class);
    mv.dup();
    mv.aload(1, Types.ScriptObject);
    mv.checkcast(Types.OrdinaryObject);
    mv.store(proto);
    // stack: [<constructorParent,proto>] -> [constructorParent, proto]
    mv.aload(0, Types.ScriptObject);
    mv.load(proto);
    // steps 8-9
    // stack: [constructorParent, proto] -> [constructorParent, proto, <rti>]
    MethodDefinition constructor = ConstructorMethod(def);
    assert constructor != null;
    MethodName method = codegen.compile(def);
    // Runtime Semantics: Evaluation -> MethodDefinition
    mv.invoke(method);
    // step 10 (not applicable)
    // steps 11-18
    // stack: [constructorParent, proto, <rti>] -> [F]
    mv.iconst(classHeritage != null);
    mv.loadExecutionContext();
    mv.lineInfo(def);
    mv.invoke(Methods.ScriptRuntime_EvaluateConstructorMethod);
    // stack: [F] -> []
    Variable<OrdinaryConstructorFunction> F = mv.newVariable("F", OrdinaryConstructorFunction.class);
    mv.store(F);
    Variable<ArrayList<Object>> methodDecorators = null;
    boolean hasMethodDecorators = HasDecorators(def);
    if (hasMethodDecorators) {
        methodDecorators = newDecoratorVariable("methodDecorators", mv);
    }
    if (!constructor.getDecorators().isEmpty()) {
        addDecoratorObject(methodDecorators, proto, mv);
        evaluateDecorators(methodDecorators, constructor.getDecorators(), mv);
        addDecoratorKey(methodDecorators, "constructor", mv);
    }
    // steps 19-21
    ClassPropertyEvaluation(codegen, def.getProperties(), F, proto, methodDecorators, mv);
    if (hasClassDecorators) {
        mv.load(F);
        mv.load(classDecorators);
        mv.loadExecutionContext();
        mv.lineInfo(def);
        mv.invoke(Methods.ScriptRuntime_EvaluateClassDecorators);
    }
    if (hasMethodDecorators) {
        mv.load(methodDecorators);
        mv.loadExecutionContext();
        mv.lineInfo(def);
        mv.invoke(Methods.ScriptRuntime_EvaluateClassMethodDecorators);
    }
    // steps 22-23 (moved)
    if (className != null) {
        // stack: [] -> []
        Name innerName = scope.resolveName(className, false);
        BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(classScopeEnvRec, innerName);
        op.initializeBinding(classScopeEnvRec, innerName, F, mv);
        mv.exitScope();
        popLexicalEnvironment(mv);
    }
    // stack: [] -> [F]
    mv.load(F);
    mv.exitVariableScope();
    // step 24 (return F)
    mv.exitClassDefinition();
}
Also used : ArrayList(java.util.ArrayList) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) Name(com.github.anba.es6draft.ast.scope.Name) FieldName(com.github.anba.es6draft.compiler.assembler.FieldName) OrdinaryConstructorFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction) BlockScope(com.github.anba.es6draft.ast.scope.BlockScope) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)

Example 52 with OrdinaryObject

use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.

the class CodeGenerator method compile.

MethodName compile(PropertyDefinitionsMethod node, boolean hasDecorators, CodeVisitor mv) {
    if (!isCompiled(node)) {
        MethodCode method = newMethod(node);
        PropertyDefinitionsCodeVisitor body = new PropertyDefinitionsCodeVisitor(node, method, mv);
        body.lineInfo(node);
        body.begin();
        Variable<OrdinaryObject> object = body.getObjectParameter();
        Variable<ArrayList<Object>> decorators = hasDecorators ? body.getDecoratorsParameter() : null;
        PropertyGenerator propgen = propertyGenerator(decorators);
        for (PropertyDefinition property : node.getProperties()) {
            body.load(object);
            property.accept(propgen, body);
        }
        body._return();
        body.end();
    }
    return methodDesc(node);
}
Also used : OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayList(java.util.ArrayList) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 53 with OrdinaryObject

use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.

the class CodeGenerator method compile.

MethodName compile(MethodDefinitionsMethod node, boolean hasDecorators, CodeVisitor mv) {
    if (!isCompiled(node)) {
        MethodCode method = newMethod(node);
        MethodDefinitionsCodeVisitor body = new MethodDefinitionsCodeVisitor(node, method, mv);
        body.lineInfo(node);
        body.begin();
        Variable<OrdinaryConstructorFunction> function = body.getFunctionParameter();
        Variable<OrdinaryObject> proto = body.getPrototypeParameter();
        Variable<ArrayList<Object>> decorators = hasDecorators ? body.getDecoratorsParameter() : null;
        ClassPropertyEvaluation(this, node.getProperties(), function, proto, decorators, body);
        body._return();
        body.end();
    }
    return methodDesc(node);
}
Also used : OrdinaryConstructorFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayList(java.util.ArrayList) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 54 with OrdinaryObject

use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.

the class Interpreter method visit.

@Override
public Object visit(ObjectLiteral node, ExecutionContext cx) {
    OrdinaryObject obj = ObjectCreate(cx, Intrinsics.ObjectPrototype);
    for (PropertyDefinition propertyDefinition : node.getProperties()) {
        assert propertyDefinition instanceof PropertyValueDefinition;
        PropertyValueDefinition propValDef = (PropertyValueDefinition) propertyDefinition;
        PropertyName propertyName = propValDef.getPropertyName();
        Expression propertyValue = propValDef.getPropertyValue();
        String propName = PropName(propertyName);
        long propIndex = propName != null ? IndexedMap.toIndex(propName) : -1;
        assert propName != null && !(propertyName instanceof ComputedPropertyName);
        Object value = GetValue(propertyValue.accept(this, cx), cx);
        if ("__proto__".equals(propName) && cx.getRealm().isEnabled(CompatibilityOption.ProtoInitializer)) {
            ScriptRuntime.defineProtoProperty(obj, value, cx);
        } else if (IndexedMap.isIndex(propIndex)) {
            ScriptRuntime.defineProperty(obj, propIndex, value, cx);
        } else {
            ScriptRuntime.defineProperty(obj, propName, value, cx);
        }
    }
    return obj;
}
Also used : OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 55 with OrdinaryObject

use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.

the class Properties method createPrototype.

private static void createPrototype(Realm realm, OrdinaryObject target, Object rawValue) {
    Object value = resolveValue(realm, rawValue);
    assert value == null || value instanceof ScriptObject;
    target.infallibleSetPrototype((ScriptObject) value);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)

Aggregations

OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)141 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)102 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)98 RegExpObject (com.github.anba.es6draft.runtime.objects.text.RegExpObject)84 Intrinsics (com.github.anba.es6draft.runtime.types.Intrinsics)14 Property (com.github.anba.es6draft.runtime.types.Property)5 CompilationException (com.github.anba.es6draft.compiler.CompilationException)3 ParserException (com.github.anba.es6draft.parser.ParserException)3 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)3 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)3 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)3 Source (com.github.anba.es6draft.runtime.internal.Source)3 FunctionConstructor.functionSource (com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource)3 AsyncGeneratorFunctionConstructor (com.github.anba.es6draft.runtime.objects.async.iteration.AsyncGeneratorFunctionConstructor)3 AsyncGeneratorFunctionPrototype (com.github.anba.es6draft.runtime.objects.async.iteration.AsyncGeneratorFunctionPrototype)3 AtomicsObject (com.github.anba.es6draft.runtime.objects.atomics.AtomicsObject)3 IntlObject (com.github.anba.es6draft.runtime.objects.intl.IntlObject)3 ArrayList (java.util.ArrayList)3 MethodCode (com.github.anba.es6draft.compiler.assembler.Code.MethodCode)2 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)2