Resolve an abstract implementation class at run-time in JS?

While abstracts don’t exist at runtime, their @:from and @:to functions still need to exist. I’m writing a library that needs to access those functions through reflection.

It seems that most targets can access an abstract’s implementation class at run-time by passing the appropriate string to Type.resolveClass(), like this:

var c = Type.resolveClass("com.example._MyAbstract.MyAbstract_Impl_");

This seems to work for most targets without any special flags or defines. I’ve tried in Neko, HashLink, and Flash so far with success. However, for JavaScript, it does not resolve. Looking at the generated code, it appears that the abstract implementation class is created, but it is never added to $hxClasses where Type.resolveClass() searches. I also tried -D js-es=6, but the generated ES6 code doesn’t make the class available to reflection either.

Is there another API that I can use instead of Type.resolveClass()? Or is there an optional define available that will enable Type.resolveClass() to work on the js target to find abstract implementation classes the same as it does other targets?

1 Like

Just following up on this to mention that I ended up creating a macro to generate a class with public static methods using a particular naming scheme that allow me to access the abstract’s methods at run-time. It feels a little hacky, but it works well enough. Since I’m already embedding a lot of RTTI data in my app, the size overhead of adding these extra methods doesn’t feel particularly heavy.

1 Like