Search in sources :

Example 16 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;
    /* step 2 (not applicable) */
    /* step 3 */
    Object c = UNDEFINED;
    /* steps 4-6 */
    if (IsArray(cx, orginalArray)) {
        /* steps 6.a-b */
        c = Get(cx, orginalArray, "constructor");
        /* step 6.c */
        if (IsConstructor(c)) {
            Constructor constructor = (Constructor) c;
            /* step 6.c.i */
            Realm thisRealm = cx.getRealm();
            /* steps 6.c.ii-iii */
            Realm realmC = GetFunctionRealm(cx, constructor);
            /* step 6.c.iv */
            if (thisRealm != realmC && constructor == realmC.getIntrinsic(Intrinsics.Array)) {
                c = UNDEFINED;
            }
        }
        /* step 6.d */
        if (Type.isObject(c)) {
            c = Get(cx, Type.objectValue(c), BuiltinSymbol.species.get());
            if (Type.isNull(c)) {
                c = UNDEFINED;
            }
        }
    }
    /* step 7 */
    if (Type.isUndefined(c)) {
        return ArrayCreate(cx, length);
    }
    /* step 8 */
    if (!IsConstructor(c)) {
        throw newTypeError(cx, Messages.Key.NotConstructor);
    }
    /* step 9 */
    return ((Constructor) c).construct(cx, (Constructor) c, 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 17 with Constructor

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

the class PropertiesTest method createEmptyClassAndConstruct.

@Test
public void createEmptyClassAndConstruct() {
    Constructor emptyClass = Properties.createClass(cx, "EmptyClass", EmptyClass.ConstructorProperties.class, EmptyClass.PrototypeProperties.class);
    ScriptObject object = emptyClass.construct(cx, emptyClass);
    assertNotNull(object);
    assertSame(emptyClass.get(cx, "prototype", emptyClass), object.getPrototypeOf(cx));
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Constructor(com.github.anba.es6draft.runtime.types.Constructor) OrdinaryCreateFromConstructor(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.OrdinaryCreateFromConstructor) Test(org.junit.Test)

Example 18 with Constructor

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

the class PropertiesTest method createEmptyClassAndCall.

@Test(expected = ScriptException.class)
public void createEmptyClassAndCall() {
    Constructor emptyClass = Properties.createClass(cx, "EmptyClass", EmptyClass.ConstructorProperties.class, EmptyClass.PrototypeProperties.class);
    emptyClass.call(cx, Null.NULL);
}
Also used : Constructor(com.github.anba.es6draft.runtime.types.Constructor) OrdinaryCreateFromConstructor(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.OrdinaryCreateFromConstructor) Test(org.junit.Test)

Example 19 with Constructor

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

the class PropertiesTest method createCustomClassWithObject.

@Test
public void createCustomClassWithObject() {
    Constructor customClass = Properties.createClass(cx, "CustomClassWithObject", CustomClassWithObject.ConstructorProperties.class, CustomClassWithObject.PrototypeProperties.class);
    ScriptObject object = customClass.construct(cx, customClass);
    assertNotNull(object);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Constructor(com.github.anba.es6draft.runtime.types.Constructor) OrdinaryCreateFromConstructor(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.OrdinaryCreateFromConstructor) Test(org.junit.Test)

Aggregations

Constructor (com.github.anba.es6draft.runtime.types.Constructor)19 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)11 OrdinaryCreateFromConstructor (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject.OrdinaryCreateFromConstructor)8 Test (org.junit.Test)8 BuiltinConstructor (com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor)7 SpeciesConstructor (com.github.anba.es6draft.runtime.AbstractOperations.SpeciesConstructor)4 ArrayBufferConstructor (com.github.anba.es6draft.runtime.objects.binary.ArrayBufferConstructor)3 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)3 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)2 CheckConstructor (com.github.anba.es6draft.runtime.internal.ScriptRuntime.CheckConstructor)2 Intrinsics (com.github.anba.es6draft.runtime.types.Intrinsics)2 MethodHandle (java.lang.invoke.MethodHandle)2 TryCatchLabel (com.github.anba.es6draft.compiler.assembler.TryCatchLabel)1 IsConstructor (com.github.anba.es6draft.runtime.AbstractOperations.IsConstructor)1 Realm (com.github.anba.es6draft.runtime.Realm)1 ModuleRecord (com.github.anba.es6draft.runtime.modules.ModuleRecord)1 TypedArrayObject (com.github.anba.es6draft.runtime.objects.binary.TypedArrayObject)1 LegacyConstructorFunction (com.github.anba.es6draft.runtime.types.builtins.LegacyConstructorFunction)1 NativeConstructor (com.github.anba.es6draft.runtime.types.builtins.NativeConstructor)1 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)1