Search in sources :

Example 1 with BuiltinSymbol

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

the class SourceBuilder method symbolDescription.

private static String symbolDescription(ExecutionContext cx, Symbol symbol) {
    for (BuiltinSymbol builtin : BuiltinSymbol.values()) {
        if (builtin != BuiltinSymbol.NONE && builtin.get() == symbol) {
            return symbol.getDescription();
        }
    }
    String registered = cx.getRealm().getSymbolRegistry().getKey(symbol);
    if (registered != null) {
        return String.format("Symbol.for(%s)", Strings.quote(registered));
    }
    String description = symbol.getDescription();
    if (description != null) {
        return String.format("Symbol(%s)", Strings.quote(description));
    }
    return "Symbol()";
}
Also used : BuiltinSymbol(com.github.anba.es6draft.runtime.types.BuiltinSymbol) ToFlatString(com.github.anba.es6draft.runtime.AbstractOperations.ToFlatString)

Example 2 with BuiltinSymbol

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

the class Properties method createExternalAccessors.

private static <OWNER> void createExternalAccessors(ExecutionContext cx, ScriptObject target, OWNER owner, ObjectLayout layout, Converter converter) {
    LinkedHashMap<String, PropertyDescriptor> stringProps = new LinkedHashMap<>();
    EnumMap<BuiltinSymbol, PropertyDescriptor> symbolProps = new EnumMap<>(BuiltinSymbol.class);
    for (Entry<Accessor, MethodHandle> entry : layout.accessors.entrySet()) {
        MethodHandle handle = getInstanceMethodHandle(cx, converter, entry.getValue(), owner);
        createExternalAccessor(cx, entry.getKey(), handle, stringProps, symbolProps);
    }
    defineProperties(cx, target, stringProps, symbolProps);
}
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) EnumMap(java.util.EnumMap) LinkedHashMap(java.util.LinkedHashMap) MethodHandle(java.lang.invoke.MethodHandle)

Example 3 with BuiltinSymbol

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

the class Properties method createExternalAccessor.

private static void createExternalAccessor(ExecutionContext cx, Accessor accessor, MethodHandle mh, 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, mh);
    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 4 with BuiltinSymbol

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

the class Properties method createExternalAccessors.

private static void createExternalAccessors(ExecutionContext cx, OrdinaryObject target, ObjectLayout layout, Converter converter) {
    LinkedHashMap<String, PropertyDescriptor> stringProps = new LinkedHashMap<>();
    EnumMap<BuiltinSymbol, PropertyDescriptor> symbolProps = new EnumMap<>(BuiltinSymbol.class);
    for (Entry<Accessor, MethodHandle> entry : layout.accessors.entrySet()) {
        MethodHandle handle = getStaticMethodHandle(cx, converter, entry.getValue());
        createExternalAccessor(cx, entry.getKey(), handle, stringProps, symbolProps);
    }
    defineProperties(cx, target, stringProps, symbolProps);
}
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) EnumMap(java.util.EnumMap) LinkedHashMap(java.util.LinkedHashMap) MethodHandle(java.lang.invoke.MethodHandle)

Example 5 with BuiltinSymbol

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

the class Properties method createAliasFunction.

private static void createAliasFunction(Realm realm, OrdinaryObject target, AliasFunctionLayout layout) {
    Object propertyKey = layout.propertyKey;
    Property fun;
    if (propertyKey instanceof String) {
        fun = target.lookupOwnProperty((String) propertyKey);
    } else {
        fun = target.lookupOwnProperty(((BuiltinSymbol) propertyKey).get());
    }
    assert fun != null : "property not found: " + propertyKey;
    defineProperty(target, layout, valueProperty(layout, fun.getValue()));
}
Also used : BuiltinSymbol(com.github.anba.es6draft.runtime.types.BuiltinSymbol) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Property(com.github.anba.es6draft.runtime.types.Property)

Aggregations

BuiltinSymbol (com.github.anba.es6draft.runtime.types.BuiltinSymbol)5 PropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor)3 AccessorPropertyDescriptor (com.github.anba.es6draft.runtime.types.PropertyDescriptor.AccessorPropertyDescriptor)3 MethodHandle (java.lang.invoke.MethodHandle)2 EnumMap (java.util.EnumMap)2 LinkedHashMap (java.util.LinkedHashMap)2 ToFlatString (com.github.anba.es6draft.runtime.AbstractOperations.ToFlatString)1 Property (com.github.anba.es6draft.runtime.types.Property)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1 NativeFunction (com.github.anba.es6draft.runtime.types.builtins.NativeFunction)1 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)1