Search in sources :

Example 1 with NativeConstructor

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

the class Properties method createConstructor.

private static OrdinaryObject createConstructor(ExecutionContext cx, String className, OrdinaryObject proto, Converter converter, ObjectLayout layout) {
    Entry<Function, MethodHandle> constructorEntry = findConstructor(layout);
    if (constructorEntry != null) {
        // User supplied method, perform manual ClassDefinitionEvaluation for constructors
        Function function = constructorEntry.getKey();
        MethodHandle unreflect = constructorEntry.getValue();
        MethodHandle callMethod = getStaticMethodHandle(converter, unreflect, MethodKind.Call);
        MethodHandle constructMethod = getStaticMethodHandle(converter, unreflect, MethodKind.Construct);
        NativeConstructor constructor = new NativeConstructor(cx.getRealm(), className, function.arity(), callMethod, constructMethod);
        constructor.defineOwnProperty(cx, "prototype", new PropertyDescriptor(proto, false, false, false));
        proto.defineOwnProperty(cx, "constructor", new PropertyDescriptor(constructor, true, false, true));
        return constructor;
    }
    // Create default constructor
    String sourceText = String.format("(class %s { })", sanitizeName(className));
    Object constructor = ScriptLoading.eval(cx.getRealm(), "<Constructor>", sourceText);
    assert constructor instanceof OrdinaryConstructorFunction : constructor.getClass();
    return (OrdinaryConstructorFunction) constructor;
}
Also used : NativeFunction(com.github.anba.es6draft.runtime.types.builtins.NativeFunction) OrdinaryConstructorFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction) BuiltinFunction(com.github.anba.es6draft.runtime.types.builtins.BuiltinFunction) NativeTailCallFunction(com.github.anba.es6draft.runtime.types.builtins.NativeTailCallFunction) NativeConstructor(com.github.anba.es6draft.runtime.types.builtins.NativeConstructor) OrdinaryConstructorFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) AccessorPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)1 AccessorPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1 BuiltinFunction (com.github.anba.es6draft.runtime.types.builtins.BuiltinFunction)1 NativeConstructor (com.github.anba.es6draft.runtime.types.builtins.NativeConstructor)1 NativeFunction (com.github.anba.es6draft.runtime.types.builtins.NativeFunction)1 NativeTailCallFunction (com.github.anba.es6draft.runtime.types.builtins.NativeTailCallFunction)1 OrdinaryConstructorFunction (com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction)1 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)1 MethodHandle (java.lang.invoke.MethodHandle)1