Search in sources :

Example 6 with Constructor

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

the class PropertiesTest method createEmptyClass.

@Test
public void createEmptyClass() {
    Constructor emptyClass = Properties.createClass(cx, "EmptyClass", EmptyClass.ConstructorProperties.class, EmptyClass.PrototypeProperties.class);
    assertNotNull(emptyClass);
    assertNotNull(emptyClass.getOwnProperty(cx, "prototype"));
}
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 7 with Constructor

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

the class PropertiesTest method createCustomClassNoArgs.

@Test
public void createCustomClassNoArgs() {
    Constructor customClass = Properties.createClass(cx, "CustomClassNoArgs", CustomClassNoArgs.ConstructorProperties.class, CustomClassNoArgs.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)

Example 8 with Constructor

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

the class PropertiesTest method createCustomClassWithSubclass.

@Test
public void createCustomClassWithSubclass() {
    Constructor customClass = Properties.createClass(cx, "CustomClassWithSubclass", CustomClassWithSubclass.ConstructorProperties.class, CustomClassWithSubclass.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)

Example 9 with Constructor

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

the class Bootstrap method superSetup.

@SuppressWarnings("unused")
private static MethodHandle superSetup(MutableCallSite callsite, Constructor constructor, ExecutionContext cx, Constructor newTarget, Object[] arguments) {
    MethodHandle target, test;
    if (constructor instanceof FunctionObject && constructor instanceof Constructor) {
        FunctionObject fn = (FunctionObject) constructor;
        test = MethodHandles.insertArguments(testFunctionObjectMH, 1, fn.getMethodInfo());
        target = fn.getConstructMethod();
    } else if (constructor instanceof BuiltinConstructor) {
        BuiltinConstructor fn = (BuiltinConstructor) constructor;
        test = MethodHandles.insertArguments(testBuiltinFunctionMH, 1, fn.getMethodInfo());
        target = fn.getConstructMethod();
    } else {
        target = test = null;
    }
    if (test != null) {
        test = test.asType(test.type().changeParameterType(0, Constructor.class));
    }
    return setCallSiteTarget(callsite, target, test, superGenericMH);
}
Also used : BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor) Constructor(com.github.anba.es6draft.runtime.types.Constructor) BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor) CheckConstructor(com.github.anba.es6draft.runtime.internal.ScriptRuntime.CheckConstructor) FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) MethodHandle(java.lang.invoke.MethodHandle)

Example 10 with Constructor

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

the class Bootstrap method constructSetup.

@SuppressWarnings("unused")
private static MethodHandle constructSetup(MutableCallSite callsite, Object constructor, ExecutionContext cx, Object[] arguments) {
    MethodHandle target, test;
    if (constructor instanceof FunctionObject && constructor instanceof Constructor) {
        FunctionObject fn = (FunctionObject) constructor;
        test = MethodHandles.insertArguments(testFunctionObjectMH, 1, fn.getMethodInfo());
        target = fn.getConstructMethod();
    } else if (constructor instanceof BuiltinConstructor) {
        BuiltinConstructor fn = (BuiltinConstructor) constructor;
        test = MethodHandles.insertArguments(testBuiltinFunctionMH, 1, fn.getMethodInfo());
        target = fn.getConstructMethod();
    } else {
        target = test = null;
    }
    if (target != null) {
        // Insert constructor as newTarget argument.
        target = target.asType(target.type().changeParameterType(2, constructor.getClass()));
        target = MethodHandles.permuteArguments(target, target.type().dropParameterTypes(2, 3), 0, 1, 0, 2);
    }
    return setCallSiteTarget(callsite, target, test, constructGenericMH);
}
Also used : BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor) Constructor(com.github.anba.es6draft.runtime.types.Constructor) BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor) CheckConstructor(com.github.anba.es6draft.runtime.internal.ScriptRuntime.CheckConstructor) FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) MethodHandle(java.lang.invoke.MethodHandle)

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