use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.
the class PropertiesTest method createEmptyClassAndCall.
@Test(expected = ScriptException.class)
public void createEmptyClassAndCall() {
Constructor emptyClass = Properties.createClass(cx, "EmptyClass", EmptyClass.ConstructorProperties.class, EmptyClass.PrototypeProperties.class);
emptyClass.call(cx, Null.NULL);
}
use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.
the class ClassOperations method GetSuperConstructor.
/**
* 12.3.5 The super Keyword
* <p>
* 12.3.5.2 Runtime Semantics: GetSuperConstructor ( )
*
* @param cx
* the execution context
* @return the super reference
*/
public static Constructor GetSuperConstructor(ExecutionContext cx) {
/* step 1 */
EnvironmentRecord envRec = cx.getThisEnvironment();
/* step 2 */
assert envRec instanceof FunctionEnvironmentRecord;
FunctionEnvironmentRecord fEnvRec = (FunctionEnvironmentRecord) envRec;
/* step 3 */
FunctionObject activeFunction = fEnvRec.getFunctionObject();
/* step 4 */
ScriptObject superConstructor = activeFunction.getPrototypeOf(cx);
/* step 5 */
if (!IsConstructor(superConstructor)) {
throw newTypeError(cx, Messages.Key.NotConstructor);
}
/* step 6 */
return (Constructor) superConstructor;
}
use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.
the class Bootstrap method constructSetup.
private static MethodHandle constructSetup(MutableCallSite callsite, Object constructor, ExecutionContext cx, Object[] arguments) {
MethodHandle target, test;
if (constructor instanceof FunctionObject && constructor instanceof Constructor) {
FunctionObject fn = (FunctionObject) constructor;
test = MethodHandles.insertArguments(testFunctionObjectMH, 1, fn.getMethodInfo());
target = fn.getConstructMethod();
} else if (constructor instanceof BuiltinConstructor) {
BuiltinConstructor fn = (BuiltinConstructor) constructor;
test = MethodHandles.insertArguments(testBuiltinFunctionMH, 1, fn.getMethodInfo());
target = fn.getConstructMethod();
} else {
target = test = null;
}
if (target != null) {
// Insert constructor as newTarget argument.
target = target.asType(target.type().changeParameterType(2, constructor.getClass()));
target = MethodHandles.permuteArguments(target, target.type().dropParameterTypes(2, 3), 0, 1, 0, 2);
}
return setCallSiteTarget(callsite, target, test, constructGenericMH);
}
use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.
the class Bootstrap method superSetup.
private static MethodHandle superSetup(MutableCallSite callsite, Constructor constructor, ExecutionContext cx, Constructor newTarget, Object[] arguments) {
MethodHandle target, test;
if (constructor instanceof FunctionObject && constructor instanceof Constructor) {
FunctionObject fn = (FunctionObject) constructor;
test = MethodHandles.insertArguments(testFunctionObjectMH, 1, fn.getMethodInfo());
target = fn.getConstructMethod();
} else if (constructor instanceof BuiltinConstructor) {
BuiltinConstructor fn = (BuiltinConstructor) constructor;
test = MethodHandles.insertArguments(testBuiltinFunctionMH, 1, fn.getMethodInfo());
target = fn.getConstructMethod();
} else {
target = test = null;
}
if (test != null) {
test = test.asType(test.type().changeParameterType(0, Constructor.class));
}
return setCallSiteTarget(callsite, target, test, superGenericMH);
}
use of com.github.anba.es6draft.runtime.types.Constructor in project es6draft by anba.
the class Properties method createExternalClass.
private static Constructor createExternalClass(ExecutionContext cx, String className, Class<?> constructorProperties, Class<?> prototypeProperties) {
ObjectLayout ctorLayout = externalClassLayouts.get(constructorProperties);
ObjectLayout protoLayout = externalClassLayouts.get(prototypeProperties);
Converter converter = new Converter(cx);
ScriptObject[] objects = ClassOperations.getDefaultClassProto(cx);
ScriptObject protoParent = objects[0];
OrdinaryObject proto = ClassOperations.createProto(protoParent, cx);
ScriptObject constructorParent = objects[1];
assert constructorParent == cx.getIntrinsic(Intrinsics.FunctionPrototype);
OrdinaryObject constructor = createConstructor(cx, className, proto, converter, protoLayout);
assert constructor instanceof Constructor;
if (ctorLayout.functions != null) {
createExternalFunctions(cx, constructor, ctorLayout, converter);
}
if (ctorLayout.accessors != null) {
createExternalAccessors(cx, constructor, ctorLayout, converter);
}
if (protoLayout.functions != null) {
createExternalFunctions(cx, proto, protoLayout, converter);
}
if (protoLayout.accessors != null) {
createExternalAccessors(cx, proto, protoLayout, converter);
}
return (Constructor) constructor;
}
Aggregations