Search in sources :

Example 1 with NativeFunction

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

the class Properties method createExternalAccessor.

private static void createExternalAccessor(ExecutionContext cx, Accessor accessor, MethodHandle handle, LinkedHashMap<String, PropertyDescriptor> stringProps, EnumMap<BuiltinSymbol, PropertyDescriptor> symbolProps) {
    Accessor.Type type = accessor.type();
    String name = accessor.name();
    BuiltinSymbol symbol = accessor.symbol();
    Attributes attributes = accessor.attributes();
    String functionName = accessorName(type, name, symbol);
    int arity = accessorArity(type);
    NativeFunction fun = new NativeFunction(cx.getRealm(), functionName, arity, handle);
    PropertyDescriptor existing;
    if (symbol == BuiltinSymbol.NONE) {
        existing = stringProps.get(name);
    } else {
        existing = symbolProps.get(symbol);
    }
    PropertyDescriptor desc;
    if (existing != null) {
        if (attributes.enumerable() != existing.isEnumerable() || attributes.configurable() != existing.isConfigurable()) {
            throw new IllegalArgumentException();
        }
        if (type == Accessor.Type.Getter ? existing.getGetter() != null : existing.getSetter() != null) {
            throw new IllegalArgumentException();
        }
        desc = existing;
    } else {
        desc = propertyDescriptor(null, null, attributes);
    }
    if (type == Accessor.Type.Getter) {
        desc.setGetter(fun);
    } else {
        desc.setSetter(fun);
    }
    if (symbol == BuiltinSymbol.NONE) {
        stringProps.put(name, desc);
    } else {
        symbolProps.put(symbol, desc);
    }
}
Also used : BuiltinSymbol(com.github.anba.es6draft.runtime.types.BuiltinSymbol) PropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor) AccessorPropertyDescriptor(com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor) NativeFunction(com.github.anba.es6draft.runtime.types.builtins.NativeFunction)

Example 2 with NativeFunction

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

the class Properties method createExternalFunction.

private static <OWNER> NativeFunction createExternalFunction(ExecutionContext cx, OWNER owner, Class<OWNER> holder) {
    ObjectLayout layout = externalLayouts.get(holder);
    if (layout.functions == null || layout.functions.size() != 1) {
        throw new IllegalArgumentException();
    }
    Converter converter = new Converter(cx);
    Entry<Function, MethodHandle> entry = layout.functions.entrySet().iterator().next();
    Function function = entry.getKey();
    MethodHandle handle = getInstanceMethodHandle(converter, entry.getValue(), owner);
    return new NativeFunction(cx.getRealm(), function.name(), function.arity(), handle);
}
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) NativeFunction(com.github.anba.es6draft.runtime.types.builtins.NativeFunction) MethodHandle(java.lang.invoke.MethodHandle)

Example 3 with NativeFunction

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

the class Properties method createExternalFunction.

private static void createExternalFunction(ExecutionContext cx, ScriptObject target, Function function, MethodHandle handle) {
    String name = function.name();
    NativeFunction fun = new NativeFunction(cx.getRealm(), name, function.arity(), handle);
    defineProperty(cx, target, name, function.symbol(), function.attributes(), fun);
}
Also used : NativeFunction(com.github.anba.es6draft.runtime.types.builtins.NativeFunction)

Example 4 with NativeFunction

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

the class Properties method createFunction.

private static void createFunction(Realm realm, OrdinaryObject target, FunctionLayout layout) {
    BuiltinFunction fun;
    if (layout.isTailCall()) {
        fun = new NativeTailCallFunction(realm, layout.name, layout.arity, layout.methodHandle);
    } else {
        fun = new NativeFunction(realm, layout.name, layout.arity, layout.nativeId, layout.methodHandle);
    }
    defineProperty(target, layout, valueProperty(layout, fun));
}
Also used : BuiltinFunction(com.github.anba.es6draft.runtime.types.builtins.BuiltinFunction) NativeFunction(com.github.anba.es6draft.runtime.types.builtins.NativeFunction) NativeTailCallFunction(com.github.anba.es6draft.runtime.types.builtins.NativeTailCallFunction)

Example 5 with NativeFunction

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

the class Properties method createAccessor.

private static void createAccessor(Realm realm, OrdinaryObject target, AccessorLayout layout) {
    int arity = accessorArity(layout.type);
    NativeFunction fun = new NativeFunction(realm, layout.accessorName, arity, layout.nativeId, layout.methodHandle);
    Property accessorProperty = lookupOwnProperty(target, layout);
    if (accessorProperty == null) {
        defineProperty(target, layout, accessorProperty(layout, fun));
    } else {
        assert accessorProperty.isAccessorDescriptor();
        assert accessorProperty.isConfigurable() == layout.configurable();
        assert accessorProperty.isEnumerable() == layout.enumerable();
        assert (layout.type == Accessor.Type.Getter ? accessorProperty.getGetter() : accessorProperty.getSetter()) == null;
        accessorProperty.apply(accessorPropertyDescriptor(layout, fun));
    }
}
Also used : NativeFunction(com.github.anba.es6draft.runtime.types.builtins.NativeFunction) Property(com.github.anba.es6draft.runtime.types.Property)

Aggregations

NativeFunction (com.github.anba.es6draft.runtime.types.builtins.NativeFunction)5 BuiltinFunction (com.github.anba.es6draft.runtime.types.builtins.BuiltinFunction)2 NativeTailCallFunction (com.github.anba.es6draft.runtime.types.builtins.NativeTailCallFunction)2 BuiltinSymbol (com.github.anba.es6draft.runtime.types.BuiltinSymbol)1 Property (com.github.anba.es6draft.runtime.types.Property)1 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)1 AccessorPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor)1 OrdinaryConstructorFunction (com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction)1 MethodHandle (java.lang.invoke.MethodHandle)1