use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction in project es6draft by anba.
the class ClassPropertyGenerator method methodDefinitions.
private OutlinedCall methodDefinitions(MethodDefinitionsMethod node, CodeVisitor mv) {
MethodTypeDescriptor methodDescriptor = MethodDefinitionsCodeVisitor.methodDescriptor(mv);
MethodCode method = codegen.method(mv, "mdef", methodDescriptor);
return outlined(new MethodDefinitionsCodeVisitor(node, method, mv), body -> {
Variable<OrdinaryConstructorFunction> function = body.getFunctionParameter();
Variable<OrdinaryObject> proto = body.getPrototypeParameter();
StoreToArray<Object> staticFields = this.staticFields.from(body.getStaticFieldsParameter());
StoreToArray<Object> instanceFields = this.instanceFields.from(body.getInstanceFieldsParameter());
StoreToArray<InstanceMethod> instanceMethods = this.instanceMethods.from(body.getInstanceMethodsParameter());
StoreToArray<Object> decorators = this.decorators.from(body.getDecoratorsParameter());
ClassPropertyEvaluation(codegen, classDefinition, node.getProperties(), function, proto, staticFields, instanceFields, instanceMethods, decorators, body);
return Completion.Normal;
});
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction in project es6draft by anba.
the class DefaultCodeGenerator method classMethodDecorators.
private MethodName classMethodDecorators(ClassDefinition node, CodeVisitor parent) {
MethodTypeDescriptor descriptor = ClassMethodDecoratorsVisitor.methodDescriptor();
MethodCode method = codegen.method(parent, "classdecorators", descriptor);
ClassMethodDecoratorsVisitor mv = new ClassMethodDecoratorsVisitor(method);
mv.begin();
Variable<ExecutionContext> cx = mv.getExecutionContext();
Variable<OrdinaryConstructorFunction> constructor = mv.getConstructor();
Variable<OrdinaryObject> prototype = mv.getPrototype();
// List of <1..n callable, property key>.
Variable<Object[]> decorators = mv.getDecorators();
Variable<Object> propertyKey = mv.newVariable("propertyKey", Object.class);
Variable<Object> propertyDesc = mv.newVariable("propertyDesc", Object.class);
Variable<Object> result = mv.newVariable("result", Object.class);
int index = 0;
for (MethodDefinition methodDef : DecoratedMethods(node.getMethods())) {
List<Expression> decoratorsList = methodDef.getDecorators();
assert !decoratorsList.isEmpty();
assert !methodDef.isCallConstructor();
Variable<? extends OrdinaryObject> object;
if (methodDef.isStatic()) {
object = constructor;
} else {
object = prototype;
}
mv.store(propertyKey, mv.arrayElement(decorators, index + decoratorsList.size(), Object.class));
mv.lineInfo(methodDef);
mv.invoke(Methods.DecoratorOperations_propertyDescriptor, object, propertyKey, cx);
mv.store(propertyDesc);
for (Expression decoratorExpr : decoratorsList) {
Value<Object> decorator = mv.arrayElement(decorators, index++, Object.class);
invokeDynamicCall(mv, decoratorExpr, decorator, cx, mv.undefinedValue(), object, propertyKey, propertyDesc);
mv.store(result);
Jump isObject = new Jump();
mv.invoke(Methods.Type_isObject, result);
mv.ifeq(isObject);
{
mv.store(propertyDesc, result);
}
mv.mark(isObject);
}
Jump isObject = new Jump();
mv.invoke(Methods.Type_isObject, propertyDesc);
mv.ifeq(isObject);
{
mv.lineInfo(methodDef);
mv.invoke(Methods.DecoratorOperations_defineProperty, object, propertyKey, propertyDesc, cx);
}
mv.mark(isObject);
// Skip over property key element.
index += 1;
}
mv._return();
mv.end();
return method.name();
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction 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;
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction in project es6draft by anba.
the class ClassOperations method InitializeInstanceFields.
public static void InitializeInstanceFields(ScriptObject thisValue, ExecutionContext cx) {
EnvironmentRecord envRec = cx.getThisEnvironment();
assert envRec instanceof FunctionEnvironmentRecord;
FunctionEnvironmentRecord fEnvRec = (FunctionEnvironmentRecord) envRec;
FunctionObject activeFunction = fEnvRec.getFunctionObject();
assert activeFunction instanceof OrdinaryConstructorFunction;
OrdinaryConstructorFunction constructor = (OrdinaryConstructorFunction) activeFunction;
InitializeInstanceFields(thisValue, constructor, cx);
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction in project es6draft by anba.
the class FunctionOperations method EvaluateFunctionExpression.
/**
* 14.1 Function Definitions
* <p>
* 14.1.21 Runtime Semantics: Evaluation
* <ul>
* <li>FunctionExpression : function ( FormalParameters ) { FunctionBody }
* <li>FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody }
* </ul>
*
* @param fd
* the function runtime info object
* @param cx
* the execution context
* @return the new function instance
*/
public static OrdinaryConstructorFunction EvaluateFunctionExpression(RuntimeInfo.Function fd, ExecutionContext cx) {
OrdinaryConstructorFunction closure;
if (!fd.is(RuntimeInfo.FunctionFlags.ScopedName)) {
/* step 1 (not applicable) */
/* step 2 */
LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
/* step 3 */
closure = ConstructorFunctionCreate(cx, FunctionKind.Normal, fd, scope);
/* step 4 */
MakeConstructor(cx, closure);
} else {
/* step 1 (not applicable) */
/* step 2 */
LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
/* step 3 */
LexicalEnvironment<DeclarativeEnvironmentRecord> funcEnv = newDeclarativeEnvironment(scope);
/* step 4 */
DeclarativeEnvironmentRecord envRec = funcEnv.getEnvRec();
/* step 5 */
String name = fd.functionName();
/* step 6 */
envRec.createImmutableBinding(name, false);
/* step 7 */
closure = ConstructorFunctionCreate(cx, FunctionKind.Normal, fd, funcEnv);
/* step 8 */
MakeConstructor(cx, closure);
/* step 9 */
SetFunctionName(closure, name);
/* step 10 */
envRec.initializeBinding(name, closure);
}
/* step 5/11 */
return closure;
}
Aggregations