Search in sources :

Example 16 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(TryStatement node, Void value) {
    Object block = node.getTryBlock().accept(this, value);
    Object handler = acceptOrNull(node.getCatchNode(), value);
    ArrayObject guardedHandlers = createList(node.getGuardedCatchNodes(), value);
    Object finalizer = acceptOrNull(node.getFinallyBlock(), value);
    if (hasBuilder(Type.TryStatement)) {
        return call(Type.TryStatement, node, block, guardedHandlers, handler, finalizer);
    }
    OrdinaryObject statement = createStatement(node, Type.TryStatement);
    addProperty(statement, "block", block);
    addProperty(statement, "handler", handler);
    addProperty(statement, "guardedHandlers", guardedHandlers);
    addProperty(statement, "finalizer", finalizer);
    return statement;
}
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 17 with ArrayObject

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

the class SourceBuilder method source.

private String source(ExecutionContext cx, HashSet<ScriptObject> stack, Object value) {
    switch(Type.of(value)) {
        case Null:
            return "null";
        case Boolean:
            return Type.booleanValue(value) ? "true" : "false";
        case String:
            return Strings.quote(Type.stringValue(value).toString());
        case Symbol:
            return Type.symbolValue(value).toString();
        case Number:
            return ToFlatString(cx, value);
        case SIMD:
            return Type.simdValue(value).toString();
        case Object:
            ScriptObject objValue = Type.objectValue(value);
            if (IsCallable(objValue)) {
                return ((Callable) objValue).toSource(cx);
            }
            if (stack.contains(objValue) || stack.size() > maxStackDepth) {
                return "« ... »";
            }
            stack.add(objValue);
            try {
                if (objValue instanceof DateObject) {
                    return DatePrototype.Properties.toString(cx, value).toString();
                } else if (objValue instanceof RegExpObject) {
                    return RegExpPrototype.Properties.toString(cx, value).toString();
                } else if (objValue instanceof ArrayObject) {
                    return arrayToSource(cx, stack, objValue);
                } else {
                    return objectToSource(cx, stack, objValue);
                }
            } finally {
                stack.remove(objValue);
            }
        case Undefined:
        default:
            return "(void 0)";
    }
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) RegExpObject(com.github.anba.es6draft.runtime.objects.text.RegExpObject) IsCallable(com.github.anba.es6draft.runtime.AbstractOperations.IsCallable) Callable(com.github.anba.es6draft.runtime.types.Callable) DateObject(com.github.anba.es6draft.runtime.objects.date.DateObject)

Example 18 with ArrayObject

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

the class ObjectConstructor method GetOwnPropertyNames.

/**
     * 19.1.2.8.1 Runtime Semantics: GetOwnPropertyKeys ( O, Type ), with Type = String
     * 
     * @param cx
     *            the execution context
     * @param o
     *            the script object
     * @return the own string-valued property keys of <var>o</var>
     */
public static ArrayObject GetOwnPropertyNames(ExecutionContext cx, Object o) {
    /* steps 1-2 */
    ScriptObject obj = ToObject(cx, o);
    /* steps 3-4 */
    List<?> keys = obj.ownPropertyKeys(cx);
    /* step 5 */
    int initialSize = Math.min(32, keys.size());
    ArrayList<String> nameList = new ArrayList<>(initialSize);
    /* step 6 */
    for (Object key : keys) {
        if (key instanceof String) {
            nameList.add((String) key);
        }
    }
    /* step 7 */
    return CreateArrayFromList(cx, nameList);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ArrayList(java.util.ArrayList) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ImmutablePrototypeObject(com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 19 with ArrayObject

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

the class DateTimeFormatConstructor method FormatToPartDateTime.

/**
     * FormatToPartDateTime(dateTimeFormat, x)
     * 
     * @param cx
     *            the execution context
     * @param dateTimeFormat
     *            the date format object
     * @param x
     *            the number value
     * @return the formatted date-time object
     */
public static ArrayObject FormatToPartDateTime(ExecutionContext cx, DateTimeFormatObject dateTimeFormat, double x) {
    if (Double.isInfinite(x) || Double.isNaN(x)) {
        throw newRangeError(cx, Messages.Key.InvalidDateValue);
    }
    /* step 1 */
    List<Map.Entry<String, String>> parts = CreateDateTimeParts(dateTimeFormat, new Date((long) x));
    /* step 2 */
    ArrayObject result = ArrayCreate(cx, 0);
    /* step 3 */
    int n = 0;
    /* step 4 */
    for (Map.Entry<String, String> part : parts) {
        /* step 4.a */
        OrdinaryObject o = ObjectCreate(cx, Intrinsics.ObjectPrototype);
        /* steps 4.b-c */
        CreateDataProperty(cx, o, "type", part.getKey());
        /* steps 4.d-e */
        CreateDataProperty(cx, o, "value", part.getValue());
        /* steps 4.f-g */
        CreateDataProperty(cx, result, n++, o);
    }
    /* step 5 */
    return result;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Map(java.util.Map) AbstractMap(java.util.AbstractMap) Date(java.util.Date)

Example 20 with ArrayObject

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

the class ArrayConstructor method construct.

/**
     * 22.1.1.1 Array ( )<br>
     * 22.1.1.2 Array (len)<br>
     * 22.1.1.3 Array (...items )
     */
@Override
public ArrayObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    /* step 1 */
    int numberOfArgs = args.length;
    /* steps 2-3 (not applicable) */
    /* steps 4-5 */
    ScriptObject proto = GetPrototypeFromConstructor(calleeContext, newTarget, Intrinsics.ArrayPrototype);
    if (numberOfArgs == 0) {
        /* step 6 */
        return ArrayCreate(calleeContext, 0, proto);
    } else if (numberOfArgs == 1) {
        // [22.1.1.2]
        Object len = args[0];
        /* steps 6-11 */
        if (!Type.isNumber(len)) {
            return DenseArrayCreate(calleeContext, proto, len);
        } else {
            double llen = Type.numberValue(len);
            long intLen = ToUint32(llen);
            if (intLen != llen) {
                throw newRangeError(calleeContext, Messages.Key.InvalidArrayLength);
            }
            return ArrayCreate(calleeContext, intLen, proto);
        }
    } else {
        /* steps 6-12 */
        return DenseArrayCreate(calleeContext, proto, args);
    }
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

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