// detect lambda method
Class lambdaClass = convert(handle.getOwner());
String lambdaMethodName = '"' + Javascript.computeMethodName(lambdaClass, handle.getName(), handle.getDesc()) + '"';
// build parameter from local environment
StringJoiner parameters = new StringJoiner(",", "[", "]");
for (int i = parameterDiff - 1; 0 <= i; i--) {
parameters.add(current.remove(i).toString());
}
// detect context
Object context = useContext ? current.remove(0) : "null";
// decide lambda context
Object holder = null;
switch (handle.getTag()) {
case H_INVOKESTATIC:
holder = Javascript.computeClassName(lambdaClass);
break;
case H_INVOKESPECIAL:
case H_INVOKEVIRTUAL:
holder = context;
break;
case H_INVOKEINTERFACE:
holder = context;
break;
case H_NEWINVOKESPECIAL:
holder = Javascript.computeClassName(lambdaClass) + ".prototype";
break;
default:
// If this exception will be thrown, it is bug of this program. So we must rethrow the
// wrapped error in here.
throw new Error();
}
// create lambda proxy class
current
.addOperand(Javascript
.writeMethodCode(Proxy.class, "newLambdaInstance", Class.class, interfaceClassName, NativeObject.class, holder, String.class, lambdaMethodName, Object.class, context, Object[].class, parameters
.toString()));
}