Search in sources :

Example 21 with ArrayObject

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

the class IntlAbstractOperations method SupportedLocales.

/**
     * 9.2.9 SupportedLocales (availableLocales, requestedLocales, options)
     * 
     * @param cx
     *            the execution context
     * @param availableLocales
     *            the set of available locales
     * @param requestedLocales
     *            the set of requested locales
     * @param options
     *            the options object
     * @return the supported locales array
     */
public static ScriptObject SupportedLocales(ExecutionContext cx, Set<String> availableLocales, Set<String> requestedLocales, Object options) {
    /* step 1 */
    String matcher = null;
    if (!Type.isUndefined(options)) {
        matcher = GetStringOption(cx, ToObject(cx, options), "localeMatcher", set("lookup", "best fit"), "best fit");
    }
    /* steps 2-5 */
    List<String> supportedLocales;
    if (matcher == null || "best fit".equals(matcher)) {
        supportedLocales = BestFitSupportedLocales(availableLocales, requestedLocales);
    } else {
        supportedLocales = LookupSupportedLocales(availableLocales, requestedLocales);
    }
    /* steps 6-8 */
    ArrayObject subset = ArrayCreate(cx, supportedLocales.size());
    int index = 0;
    for (Object value : supportedLocales) {
        subset.defineOwnProperty(cx, index++, new PropertyDescriptor(value, false, true, false));
    }
    PropertyDescriptor nonConfigurableWritable = new PropertyDescriptor();
    nonConfigurableWritable.setConfigurable(false);
    nonConfigurableWritable.setWritable(false);
    subset.defineOwnProperty(cx, "length", nonConfigurableWritable);
    /* step 9 */
    return subset;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 22 with ArrayObject

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

the class ExpressionGenerator method visit.

/**
     * 12.2.4.1.3 Runtime Semantics: Evaluation<br>
     * 12.2.4.1.2 Runtime Semantics: Array Accumulation
     */
@Override
public ValType visit(SpreadElementMethod node, CodeVisitor mv) {
    MethodName method = codegen.compile(node, mv);
    boolean hasResume = node.hasResumePoint();
    mv.enterVariableScope();
    Variable<ArrayObject> array = mv.newVariable("array", ArrayObject.class);
    Variable<Integer> nextIndex = mv.newVariable("nextIndex", int.class);
    // stack: [array, nextIndex] -> [array]
    mv.store(nextIndex);
    mv.dup();
    mv.store(array);
    // stack: [array] -> [array, nextIndex']
    // 0 = hint for stacktraces to omit this frame
    mv.lineInfo(0);
    if (hasResume) {
        mv.callWithSuspend(method, array, nextIndex);
    } else {
        mv.call(method, array, nextIndex);
    }
    mv.exitVariableScope();
    return ValType.Any;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 23 with ArrayObject

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

the class Interpreter method visit.

@Override
public Object visit(ArrayLiteral node, ExecutionContext cx) {
    ArrayObject array = ArrayCreate(cx, 0);
    int nextIndex = 0;
    for (Expression element : node.getElements()) {
        if (element instanceof Elision) {
        // Elision
        } else {
            Object value = GetValue(element.accept(this, cx), cx);
            ScriptRuntime.defineProperty(array, nextIndex, value);
        }
        nextIndex += 1;
    }
    Set(cx, array, "length", nextIndex, false);
    return array;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) 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 24 with ArrayObject

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

the class JSONParser method jsonArray.

/**
     * <pre>
     * JSONArray :
     *      [ ]
     *      [ JSONElementList ]
     * JSONElementList :
     *      JSONValue
     *      JSONElementList , JSONValue
     * </pre>
     * 
     * @return the script object represented by the JSON array
     */
private ArrayObject jsonArray() {
    ArrayObject array = ArrayCreate(cx, 0);
    consume(Token.LB);
    if (token() != Token.RB) {
        for (long index = 0; ; ) {
            Object value = jsonValue();
            array.defineOwnProperty(cx, index++, new PropertyDescriptor(value, true, true, true));
            if (token() == Token.RB) {
                break;
            }
            consume(Token.COMMA);
        }
    }
    consume(Token.RB);
    return array;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 25 with ArrayObject

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

the class ObjectConstructor method EnumerableOwnProperties.

/**
     * EnumerableOwnProperties (O)
     * 
     * @param cx
     *            the execution context
     * @param object
     *            the script object
     * @param kind
     *            the property kind
     * @return <var>object</var>'s own enumerable properties
     */
static List<Object> EnumerableOwnProperties(ExecutionContext cx, ScriptObject object, PropertyKind kind) {
    /* step 1 (not applicable) */
    /* steps 2-3 */
    List<?> ownKeys = object.ownPropertyKeys(cx);
    /* step 4 */
    int initialSize = Math.min(16, ownKeys.size());
    ArrayList<Object> properties = new ArrayList<>(initialSize);
    /* step 5 */
    for (Object key : ownKeys) {
        if (key instanceof String) {
            String skey = (String) key;
            Property desc = object.getOwnProperty(cx, skey);
            if (desc != null && desc.isEnumerable()) {
                if (kind == PropertyKind.Key) {
                    properties.add(skey);
                } else {
                    Object value = Get(cx, object, skey);
                    if (kind == PropertyKind.Value) {
                        properties.add(value);
                    } else {
                        ArrayObject entry = CreateArrayFromList(cx, key, value);
                        properties.add(entry);
                    }
                }
            }
        }
    }
    /* step 7 */
    return properties;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) 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) Property(com.github.anba.es6draft.runtime.types.Property)

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