Search in sources :

Example 31 with ScriptObject

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

the class TypedArrayConstructorPrototype method construct.

/**
     * 22.2.1.1 %TypedArray% ( )
     */
@Override
public ScriptObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    /* step 3 */
    if (newTarget == this) {
        throw newTypeError(calleeContext, Messages.Key.TypedArrayCreate);
    }
    /* step 4 */
    ScriptObject super_ = getPrototypeOf(calleeContext);
    /* step 5 */
    if (!IsConstructor(super_)) {
        throw newTypeError(calleeContext, Messages.Key.NotConstructor);
    }
    /* steps 6-7 */
    return ((Constructor) super_).construct(calleeContext, newTarget, args);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) Constructor(com.github.anba.es6draft.runtime.types.Constructor) BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor)

Example 32 with ScriptObject

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

the class MapConstructor method construct.

/**
     * 23.1.1.1 Map ([ iterable ])
     */
@Override
public MapObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object iterable = argument(args, 0);
    /* step 1 (not applicable) */
    /* steps 2-4 */
    MapObject map = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.MapPrototype, MapObject::new);
    /* steps 5-6, 8 */
    if (Type.isUndefinedOrNull(iterable)) {
        return map;
    }
    /* step 7 */
    Object _adder = Get(calleeContext, map, "set");
    if (!IsCallable(_adder)) {
        throw newTypeError(calleeContext, Messages.Key.PropertyNotCallable, "set");
    }
    Callable adder = (Callable) _adder;
    boolean isBuiltin = MapPrototype.isBuiltinSet(_adder);
    if (isBuiltin && iterable instanceof MapObject) {
        MapObject other = (MapObject) iterable;
        if (ScriptIterators.isBuiltinIterator(calleeContext, other)) {
            map.getMapData().setAll(other.getMapData());
            return map;
        }
    }
    ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
    /* step 9 */
    try {
        while (iter.hasNext()) {
            Object nextItem = iter.next();
            if (!Type.isObject(nextItem)) {
                throw newTypeError(calleeContext, Messages.Key.MapPairNotObject);
            }
            ScriptObject item = Type.objectValue(nextItem);
            Object k = Get(calleeContext, item, 0);
            Object v = Get(calleeContext, item, 1);
            if (isBuiltin) {
                map.getMapData().set(k, v);
            } else {
                adder.call(calleeContext, map, k, v);
            }
        }
        return map;
    } catch (ScriptException e) {
        iter.close(e);
        throw e;
    }
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) IsCallable(com.github.anba.es6draft.runtime.AbstractOperations.IsCallable) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 33 with ScriptObject

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

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

the class WeakMapConstructor method construct.

/**
     * 23.3.1.1 WeakMap ([ iterable ])
     */
@Override
public WeakMapObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object iterable = argument(args, 0);
    /* step 1 (not applicable) */
    /* steps 2-4 */
    WeakMapObject map = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.WeakMapPrototype, WeakMapObject::new);
    /* steps 5-6, 8 */
    if (Type.isUndefinedOrNull(iterable)) {
        return map;
    }
    /* step 7 */
    Object _adder = Get(calleeContext, map, "set");
    if (!IsCallable(_adder)) {
        throw newTypeError(calleeContext, Messages.Key.PropertyNotCallable, "set");
    }
    Callable adder = (Callable) _adder;
    ScriptIterator<?> iter = GetScriptIterator(calleeContext, iterable);
    /* step 9 */
    try {
        while (iter.hasNext()) {
            Object nextItem = iter.next();
            if (!Type.isObject(nextItem)) {
                throw newTypeError(calleeContext, Messages.Key.WeakMapPairNotObject);
            }
            ScriptObject item = Type.objectValue(nextItem);
            Object k = Get(calleeContext, item, 0);
            Object v = Get(calleeContext, item, 1);
            adder.call(calleeContext, map, k, v);
        }
        return map;
    } catch (ScriptException e) {
        iter.close(e);
        throw e;
    }
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) IsCallable(com.github.anba.es6draft.runtime.AbstractOperations.IsCallable) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 35 with ScriptObject

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

the class SharedArrayBufferConstructor method AllocateSharedArrayBuffer.

/**
     * AllocateSharedArrayBuffer( constructor, byteLength )
     * 
     * @param cx
     *            the execution context
     * @param constructor
     *            the constructor function
     * @param byteLength
     *            the buffer byte length
     * @return the new shared array buffer object
     */
public static SharedArrayBufferObject AllocateSharedArrayBuffer(ExecutionContext cx, Constructor constructor, long byteLength) {
    /* steps 1-2 */
    ScriptObject proto = GetPrototypeFromConstructor(cx, constructor, Intrinsics.SharedArrayBufferPrototype);
    /* step 3 */
    assert byteLength >= 0;
    /* steps 4-5 */
    ByteBuffer block = CreateSharedByteDataBlock(cx, byteLength);
    /* steps 1-2, 6-8 */
    return new SharedArrayBufferObject(cx.getRealm(), block, byteLength, proto);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)129 Callable (com.github.anba.es6draft.runtime.types.Callable)43 Property (com.github.anba.es6draft.runtime.types.Property)32 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)26 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)21 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)16 Constructor (com.github.anba.es6draft.runtime.types.Constructor)11 Realm (com.github.anba.es6draft.runtime.Realm)9 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)9 ParserException (com.github.anba.es6draft.parser.ParserException)8 CompilationException (com.github.anba.es6draft.compiler.CompilationException)7 Source (com.github.anba.es6draft.runtime.internal.Source)7 ArrayList (java.util.ArrayList)7 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)6 ImmutablePrototypeObject (com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject)6 OrdinaryCreateFromConstructor (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.OrdinaryCreateFromConstructor)6 Test (org.junit.Test)6 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)5 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)4 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)4