Search in sources :

Example 96 with OrdinaryObject

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

the class ReflectParser method visit.

@Override
public Object visit(PropertyValueDefinition node, Void value) {
    String propertyName = node.getPropertyName().getName();
    if ("__proto__".equals(propertyName)) {
        Object _value = node.getPropertyValue().accept(this, value);
        if (hasBuilder(Type.PrototypeMutation)) {
            return call(Type.PrototypeMutation, node, _value);
        }
        OrdinaryObject property = createNode(node, Type.PrototypeMutation);
        addProperty(property, "value", _value);
        return property;
    }
    Object key = node.getPropertyName().accept(this, value);
    Object _value = node.getPropertyValue().accept(this, value);
    String kind = "init";
    boolean method = false;
    boolean shorthand = false;
    boolean computed = node.getPropertyName() instanceof ComputedPropertyName;
    if (hasBuilder(Type.Property)) {
        return call(Type.Property, node, kind, key, _value);
    }
    OrdinaryObject property = createNode(node, Type.Property);
    addProperty(property, "key", key);
    addProperty(property, "value", _value);
    addProperty(property, "kind", kind);
    addProperty(property, "method", method);
    addProperty(property, "shorthand", shorthand);
    addProperty(property, "computed", computed);
    return property;
}
Also used : OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) RegExpObject(com.github.anba.es6draft.runtime.objects.text.RegExpObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 97 with OrdinaryObject

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

the class ReflectParser method visit.

@Override
public Object visit(ForEachStatement node, Void value) {
    Object forEachStatement;
    Object left = node.getHead().accept(this, value);
    Object right = node.getExpression().accept(this, value);
    Object body = node.getStatement().accept(this, value);
    boolean each = true;
    if (hasBuilder(Type.ForInStatement)) {
        forEachStatement = call(Type.ForInStatement, node, left, right, body, each);
    } else {
        OrdinaryObject statement = createStatement(node, Type.ForInStatement);
        addProperty(statement, "left", left);
        addProperty(statement, "right", right);
        addProperty(statement, "body", body);
        addProperty(statement, "each", each);
        forEachStatement = statement;
    }
    return createLabelledStatement(node, forEachStatement);
}
Also used : OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) RegExpObject(com.github.anba.es6draft.runtime.objects.text.RegExpObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 98 with OrdinaryObject

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

the class ReflectParser method visit.

@Override
public Object visit(TemplateLiteral node, Void value) {
    if (!node.isTagged()) {
        ArrayList<Object> list = new ArrayList<>();
        for (Expression element : node.getElements()) {
            if (element instanceof TemplateCharacters) {
                list.add(createLiteral((TemplateCharacters) element));
            } else {
                list.add(element.accept(this, value));
            }
        }
        if (list.size() == 1) {
            return list.get(0);
        }
        ArrayObject elements = createListFromValues(list);
        if (hasBuilder(Type.TemplateLiteral)) {
            return call(Type.TemplateLiteral, node, elements);
        }
        OrdinaryObject expression = createExpression(node, Type.TemplateLiteral);
        addProperty(expression, "elements", elements);
        return expression;
    } else {
        ArrayList<String> rawList = new ArrayList<>(), cookedList = new ArrayList<>();
        for (TemplateCharacters chars : TemplateStrings(node)) {
            rawList.add(chars.getRawValue());
            cookedList.add(chars.getValue());
        }
        Object callSiteObject;
        ArrayObject raw = createListFromValues(rawList);
        ArrayObject cooked = createListFromValues(cookedList);
        if (hasBuilder(Type.CallSiteObject)) {
            callSiteObject = call(Type.CallSiteObject, node, raw, cooked);
        } else {
            OrdinaryObject callSiteObj = createExpression(node, Type.CallSiteObject);
            addProperty(callSiteObj, "raw", raw);
            addProperty(callSiteObj, "cooked", cooked);
            callSiteObject = callSiteObj;
        }
        ArrayList<Object> arguments = new ArrayList<>();
        arguments.add(callSiteObject);
        for (Expression subst : Substitutions(node)) {
            arguments.add(subst.accept(this, value));
        }
        return createListFromValues(arguments);
    }
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayList(java.util.ArrayList) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) RegExpObject(com.github.anba.es6draft.runtime.objects.text.RegExpObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 99 with OrdinaryObject

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

the class ReflectParser method visit.

@Override
public Object visit(DoExpression node, Void value) {
    OrdinaryObject expression = createExpression(node, Type.DoExpression);
    addProperty(expression, "statement", node.getStatement().accept(this, value));
    return expression;
}
Also used : OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)

Example 100 with OrdinaryObject

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

the class ReflectParser method visit.

@Override
public Object visit(GeneratorDeclaration node, Void value) {
    Object id = acceptOrNull(node.getIdentifier(), value);
    ArrayObject params = createList(getParameterBindings(node.getParameters()), value);
    ArrayObject defaults = createListWithNull(getParameterDefaults(node.getParameters()), value);
    Object rest = acceptOrNull(getRestParameter(node.getParameters()), value);
    Object body = createFunctionBody(node, value);
    boolean generator = true;
    boolean expression = false;
    if (hasBuilder(Type.FunctionDeclaration)) {
        return call(Type.FunctionDeclaration, node, id, params, body, generator, expression);
    }
    GeneratorStyle style = node instanceof LegacyGeneratorDeclaration ? GeneratorStyle.Legacy : GeneratorStyle.ES6;
    OrdinaryObject function = createFunction(node, Type.FunctionDeclaration);
    addProperty(function, "id", id);
    addProperty(function, "params", params);
    addProperty(function, "defaults", defaults);
    addProperty(function, "body", body);
    addProperty(function, "rest", rest);
    addProperty(function, "generator", generator);
    addProperty(function, "style", style.name);
    addProperty(function, "expression", expression);
    return function;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) RegExpObject(com.github.anba.es6draft.runtime.objects.text.RegExpObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

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