use of com.github.anba.es6draft.runtime.ExecutionContext 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.ExecutionContext in project es6draft by anba.
the class Properties method getStaticMethodHandle.
private static MethodHandle getStaticMethodHandle(Lookup lookup, Method method) throws IllegalAccessException {
MethodHandle handle = lookup.unreflect(method);
MethodType type = handle.type();
Class<?>[] params = type.parameterArray();
int p = 0, pcount = type.parameterCount();
boolean callerContext = false;
// First three parameters are (ExecutionContext, ExecutionContext?, Object=ThisValue)
if (!(p < pcount && ExecutionContext.class.equals(params[p++]))) {
throw new IllegalArgumentException(type.toString());
}
if (p < pcount && ExecutionContext.class.equals(params[p])) {
callerContext = true;
p++;
}
if (!(p < pcount && Object.class.equals(params[p++]))) {
throw new IllegalArgumentException(type.toString());
}
// Always required to return Object (for now at least)
if (!Object.class.equals(type.returnType())) {
throw new IllegalArgumentException(type.toString());
}
// Collect remaining arguments into Object[]
if (!(p + 1 == pcount && Object[].class.equals(params[p]))) {
final int fixedArguments = callerContext ? 3 : 2;
final boolean varargs = handle.isVarargsCollector();
// Otherwise all trailing arguments need to be of type Object or Object[]
for (; p < pcount; ++p) {
if (Object.class.equals(params[p])) {
continue;
}
if (p + 1 == pcount && Object[].class.equals(params[p]) && varargs) {
continue;
}
throw new IllegalArgumentException(type.toString());
}
// Trailing Object[] arguments are no longer spread in var-args methods (jdk8u40, jdk9).
if (varargs) {
handle = handle.asFixedArity();
}
// Convert to (ExecutionContext, Object, ...) -> Object handle
handle = toCanonical(handle, fixedArguments, varargs, method);
}
if (!callerContext) {
handle = MethodHandles.dropArguments(handle, 1, ExecutionContext.class);
}
return handle;
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class CollatorConstructor method construct.
/**
* 10.1.2 Intl.Collator([ locales [, options]])
*/
@Override
public CollatorObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object locales = argument(args, 0);
Object options = argument(args, 1);
/* step 1 (not applicable) */
/* steps 2-5 */
CollatorObject collator = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.Intl_CollatorPrototype, CollatorObject::new);
/* step 6 */
InitializeCollator(calleeContext, collator, locales, options);
return collator;
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class DateTimeFormatConstructor method construct.
/**
* 12.2.1 Intl.DateTimeFormat([ locales [, options ]])
*/
@Override
public DateTimeFormatObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object locales = argument(args, 0);
Object options = argument(args, 1);
/* step 1 (not applicable) */
/* step 2 */
DateTimeFormatObject obj = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.Intl_DateTimeFormatPrototype, DateTimeFormatObject::new);
/* step 3 */
InitializeDateTimeFormat(calleeContext, obj, locales, options);
/* step 6 */
return obj;
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class ListFormatConstructor method construct.
/**
* Intl.ListFormat ([ locales [ , options ]])
*/
@Override
public ListFormatObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object locales = argument(args, 0);
Object options = argument(args, 1);
/* step 1 (not applicable) */
/* step 2 */
ListFormatObject listFormat = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.Intl_ListFormatPrototype, ListFormatObject::new);
/* step 3 */
InitializeListFormat(calleeContext, listFormat, locales, options);
return listFormat;
}
Aggregations