Search in sources :

Example 21 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 22 with Constructor

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

the class ClassOperations method GetSuperConstructor.

/**
 * 12.3.5 The super Keyword
 * <p>
 * 12.3.5.2 Runtime Semantics: GetSuperConstructor ( )
 *
 * @param cx
 *            the execution context
 * @return the super reference
 */
public static Constructor GetSuperConstructor(ExecutionContext cx) {
    /* step 1 */
    EnvironmentRecord envRec = cx.getThisEnvironment();
    /* step 2 */
    assert envRec instanceof FunctionEnvironmentRecord;
    FunctionEnvironmentRecord fEnvRec = (FunctionEnvironmentRecord) envRec;
    /* step 3 */
    FunctionObject activeFunction = fEnvRec.getFunctionObject();
    /* step 4 */
    ScriptObject superConstructor = activeFunction.getPrototypeOf(cx);
    /* step 5 */
    if (!IsConstructor(superConstructor)) {
        throw newTypeError(cx, Messages.Key.NotConstructor);
    }
    /* step 6 */
    return (Constructor) superConstructor;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Constructor(com.github.anba.es6draft.runtime.types.Constructor) MakeClassConstructor(com.github.anba.es6draft.runtime.types.builtins.FunctionObject.MakeClassConstructor) MakeConstructor(com.github.anba.es6draft.runtime.types.builtins.FunctionObject.MakeConstructor) FunctionEnvironmentRecord(com.github.anba.es6draft.runtime.FunctionEnvironmentRecord) FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) FunctionEnvironmentRecord(com.github.anba.es6draft.runtime.FunctionEnvironmentRecord) EnvironmentRecord(com.github.anba.es6draft.runtime.EnvironmentRecord)

Example 23 with Constructor

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

the class Bootstrap method constructSetup.

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) CheckConstructor(com.github.anba.es6draft.runtime.language.CallOperations.CheckConstructor) BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor) Constructor(com.github.anba.es6draft.runtime.types.Constructor) FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) MethodHandle(java.lang.invoke.MethodHandle)

Example 24 with Constructor

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

the class Bootstrap method superSetup.

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) CheckConstructor(com.github.anba.es6draft.runtime.language.CallOperations.CheckConstructor) BuiltinConstructor(com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor) Constructor(com.github.anba.es6draft.runtime.types.Constructor) FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) MethodHandle(java.lang.invoke.MethodHandle)

Example 25 with Constructor

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

the class Properties method createExternalClass.

private static Constructor createExternalClass(ExecutionContext cx, String className, Class<?> constructorProperties, Class<?> prototypeProperties) {
    ObjectLayout ctorLayout = externalClassLayouts.get(constructorProperties);
    ObjectLayout protoLayout = externalClassLayouts.get(prototypeProperties);
    Converter converter = new Converter(cx);
    ScriptObject[] objects = ClassOperations.getDefaultClassProto(cx);
    ScriptObject protoParent = objects[0];
    OrdinaryObject proto = ClassOperations.createProto(protoParent, cx);
    ScriptObject constructorParent = objects[1];
    assert constructorParent == cx.getIntrinsic(Intrinsics.FunctionPrototype);
    OrdinaryObject constructor = createConstructor(cx, className, proto, converter, protoLayout);
    assert constructor instanceof Constructor;
    if (ctorLayout.functions != null) {
        createExternalFunctions(cx, constructor, ctorLayout, converter);
    }
    if (ctorLayout.accessors != null) {
        createExternalAccessors(cx, constructor, ctorLayout, converter);
    }
    if (protoLayout.functions != null) {
        createExternalFunctions(cx, proto, protoLayout, converter);
    }
    if (protoLayout.accessors != null) {
        createExternalAccessors(cx, proto, protoLayout, converter);
    }
    return (Constructor) constructor;
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Constructor(com.github.anba.es6draft.runtime.types.Constructor) NativeConstructor(com.github.anba.es6draft.runtime.types.builtins.NativeConstructor) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)

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