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