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