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()";
}
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);
}
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);
}
}
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);
}
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()));
}
Aggregations