Search in sources :

Example 31 with ArrayObject

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

the class ReflectParser method visit.

@Override
public Object visit(Script node, Void value) {
    ArrayObject body = createList(node.getStatements(), value);
    if (hasBuilder(Type.Program)) {
        return call(Type.Program, node, body);
    }
    OrdinaryObject program = createNode(node, Type.Program);
    addProperty(program, "body", body);
    addProperty(program, "sourceType", "script");
    return program;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)

Example 32 with ArrayObject

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

the class ReflectParser method visit.

@Override
public Object visit(LetExpression node, Void value) {
    ArrayObject head = createList(node.getBindings(), value);
    Object body = node.getExpression().accept(this, value);
    if (hasBuilder(Type.LetExpression)) {
        return call(Type.LetExpression, node, head, body);
    }
    OrdinaryObject expression = createExpression(node, Type.LetExpression);
    addProperty(expression, "head", head);
    addProperty(expression, "body", body);
    return expression;
}
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)

Example 33 with ArrayObject

use of com.github.anba.es6draft.runtime.types.builtins.ArrayObject 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 34 with ArrayObject

use of com.github.anba.es6draft.runtime.types.builtins.ArrayObject 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)

Example 35 with ArrayObject

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

the class ReflectParser method visit.

@Override
public Object visit(ObjectLiteral node, Void value) {
    ArrayObject properties = createList(node.getProperties(), value);
    if (hasBuilder(Type.ObjectExpression)) {
        return call(Type.ObjectExpression, node, properties);
    }
    OrdinaryObject expression = createExpression(node, Type.ObjectExpression);
    addProperty(expression, "properties", properties);
    return expression;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)

Aggregations

ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)50 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)43 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)32 RegExpObject (com.github.anba.es6draft.runtime.objects.text.RegExpObject)25 ArrayList (java.util.ArrayList)5 ImmutablePrototypeObject (com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject)3 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)2 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)1 MatchState (com.github.anba.es6draft.regexp.MatchState)1 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)1 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)1 DateObject (com.github.anba.es6draft.runtime.objects.date.DateObject)1 Callable (com.github.anba.es6draft.runtime.types.Callable)1 Property (com.github.anba.es6draft.runtime.types.Property)1 Symbol (com.github.anba.es6draft.runtime.types.Symbol)1 AbstractMap (java.util.AbstractMap)1 Date (java.util.Date)1 Map (java.util.Map)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1