use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode 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();
}
Aggregations