Dynamic .NET objects

Nov 11, 2015 at 2:47 PM
I have a need to generate objects in Jurassic with methods and properties that will be dynamically handled and dispatched from .Net.

What is the best way to go about doing this? A lot of the internals of ObjectInstance seem to rely on scanning the Type for JSFunction attributes, and generating dispatchers for these. I've half solved my problem by generating Dynamic Proxies with those attributes magically inserted that inherit from ObjectInstance and invoke PopulateFunctions on themselves. That actually worked, for some cases.

But now I have a case where I have an unbounded set of potential object signatures. And I can't just start generating proxies for each and every combination. So I need some other method to do this.

I thought about manually populating an object full of FunctionInstance classes. But there's a number of internal things that I don't seem to have access to.

Nov 11, 2015 at 9:21 PM
Include the Jurassic source code in your project -- all internal methods become callable like magic! ;-)

But seriously, this is a known area of weakness. I was never very happy with the attribute scanning stuff and the infrastructure behind it, which is why a lot of it is marked internal (I wanted to be able to rewrite it and not break people). Jurassic can accommodate simple scenarios without calling any internal methods, but more advanced scenarios like supporting .NET method overloads with a single JS function is impossible IIRC.

Luckily it's open source so if you don't like any of my decisions, you can override them :-)
Nov 11, 2015 at 9:46 PM
If I were to start a project of coming up with something to solve this, maybe something like a DynamicObjectInstance, that just sat on top of ObjectInstance, but replaced all the functionality, would you have an issue with it?

I want to make sure any approach I take will be acceptable upstream, since I really dislike maintaining forks. :)
Nov 11, 2015 at 9:49 PM
I'm wondering about the required visibility of method groups to JS, for instance. Say I just configure a callable method name for a given method group, and have it support a params array, then do the method discovery back in the FunctionInstance, sending it to the appropriate .NET implementation.

If you have some vision on how you want this to be, don't be shy!