Search in sources :

Example 1 with BuiltinConstructor

use of com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor 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 2 with BuiltinConstructor

use of com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor 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)

Aggregations

CheckConstructor (com.github.anba.es6draft.runtime.language.CallOperations.CheckConstructor)2 Constructor (com.github.anba.es6draft.runtime.types.Constructor)2 BuiltinConstructor (com.github.anba.es6draft.runtime.types.builtins.BuiltinConstructor)2 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)2 MethodHandle (java.lang.invoke.MethodHandle)2