Search in sources :

Example 31 with Constructor

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

the class ArrayObject method ArraySpeciesCreate.

/**
 * 9.4.2.3 ArraySpeciesCreate(originalArray, length)
 *
 * @param cx
 *            the execution context
 * @param orginalArray
 *            the source array
 * @param length
 *            the array length
 * @return the new array object
 */
public static ScriptObject ArraySpeciesCreate(ExecutionContext cx, ScriptObject orginalArray, long length) {
    /* step 1 */
    assert length >= 0;
    /* steps 3-4 */
    if (!IsArray(cx, orginalArray)) {
        return ArrayCreate(cx, length);
    }
    /* step 5 */
    Object c = Get(cx, orginalArray, "constructor");
    /* step 6 */
    if (IsConstructor(c)) {
        Constructor constructor = (Constructor) c;
        /* step 6.a */
        Realm thisRealm = cx.getRealm();
        /* step 6.b */
        Realm realmC = GetFunctionRealm(cx, constructor);
        /* step 6.c */
        if (thisRealm != realmC && constructor == realmC.getIntrinsic(Intrinsics.Array)) {
            c = UNDEFINED;
        }
    }
    /* step 7 */
    if (Type.isObject(c)) {
        /* step 7.a.*/
        c = Get(cx, Type.objectValue(c), BuiltinSymbol.species.get());
        /* step 7.b */
        if (Type.isNull(c)) {
            c = UNDEFINED;
        }
    }
    /* step 8 */
    if (Type.isUndefined(c)) {
        return ArrayCreate(cx, length);
    }
    /* step 9 */
    if (!IsConstructor(c)) {
        throw newTypeError(cx, Messages.Key.NotConstructor);
    }
    /* step 10 */
    return ((Constructor) c).construct(cx, length);
}
Also used : Constructor(com.github.anba.es6draft.runtime.types.Constructor) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) TypedArrayObject(com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject) Realm(com.github.anba.es6draft.runtime.Realm)

Example 32 with Constructor

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

the class TypedArrayConstructor method TypedArraySpeciesCreate.

/**
     * TypedArraySpeciesCreate( exemplar, argumentList )
     * 
     * @param cx
     *            the execution context
     * @param exemplar
     *            the typed array object
     * @param length
     *            the new typed array length
     * @return the new typed array object
     */
public static TypedArrayObject TypedArraySpeciesCreate(ExecutionContext cx, TypedArrayObject exemplar, long length) {
    /* step 1 (implicit) */
    /* step 2 */
    Intrinsics defaultConstructor = exemplar.getElementType().getConstructor();
    /* step 3 */
    Constructor constructor = SpeciesConstructor(cx, exemplar, defaultConstructor);
    /* step 4 */
    return TypedArrayCreate(cx, constructor, length);
}
Also used : Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) Constructor(com.github.anba.es6draft.runtime.types.Constructor) BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor) SpeciesConstructor(com.github.anba.es6draft.runtime.AbstractOperations.SpeciesConstructor) ArrayBufferConstructor(com.github.anba.es6draft.runtime.objects.binary.ArrayBufferConstructor)

Example 33 with Constructor

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

the class TypedArrayConstructor method TypedArraySpeciesCreate.

/**
     * TypedArraySpeciesCreate( exemplar, argumentList )
     * 
     * @param cx
     *            the execution context
     * @param exemplar
     *            the typed array object
     * @param args
     *            the constructor function arguments
     * @return the new typed array object
     */
public static TypedArrayObject TypedArraySpeciesCreate(ExecutionContext cx, TypedArrayObject exemplar, Object... args) {
    /* step 1 (implicit) */
    /* step 2 */
    Intrinsics defaultConstructor = exemplar.getElementType().getConstructor();
    /* step 3 */
    Constructor constructor = SpeciesConstructor(cx, exemplar, defaultConstructor);
    /* step 4 */
    return TypedArrayCreate(cx, constructor, args);
}
Also used : Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) Constructor(com.github.anba.es6draft.runtime.types.Constructor) BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor) SpeciesConstructor(com.github.anba.es6draft.runtime.AbstractOperations.SpeciesConstructor) ArrayBufferConstructor(com.github.anba.es6draft.runtime.objects.binary.ArrayBufferConstructor)

Aggregations

Constructor (com.github.anba.es6draft.runtime.types.Constructor)33 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)21 OrdinaryCreateFromConstructor (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.OrdinaryCreateFromConstructor)11 Test (org.junit.Test)11 BuiltinConstructor (com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor)9 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)6 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)4 Intrinsics (com.github.anba.es6draft.runtime.types.Intrinsics)4 SpeciesConstructor (com.github.anba.es6draft.runtime.AbstractOperations.SpeciesConstructor)3 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)3 TryCatchLabel (com.github.anba.es6draft.compiler.assembler.TryCatchLabel)2 IsConstructor (com.github.anba.es6draft.runtime.AbstractOperations.IsConstructor)2 CheckConstructor (com.github.anba.es6draft.runtime.language.CallOperations.CheckConstructor)2 ModuleRecord (com.github.anba.es6draft.runtime.modules.ModuleRecord)2 ArrayBufferConstructor (com.github.anba.es6draft.runtime.objects.binary.ArrayBufferConstructor)2 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)2 MakeClassConstructor (com.github.anba.es6draft.runtime.types.builtins.FunctionObject.MakeClassConstructor)2 MakeConstructor (com.github.anba.es6draft.runtime.types.builtins.FunctionObject.MakeConstructor)2 LegacyConstructorFunction (com.github.anba.es6draft.runtime.types.builtins.LegacyConstructorFunction)2 MethodHandle (java.lang.invoke.MethodHandle)2