ChakraCore.NET icon indicating copy to clipboard operation
ChakraCore.NET copied to clipboard

Pass a big c# object to JS

Open DrEight opened this issue 7 years ago • 7 comments

I'm passing to JS a big c# object using RegisterProxyConverter. I've tried also to to use RegisterStructConverter, but the problem is always the same: the process is slow because, practically I have to describe the methods and properties to JS and it take time for large objects. Looking to the source code I notice that RegisterProxyConverter uses the API 'JSCreateExternalObject' with the first argument set to null. ( the object pointer ). Is any way to pass the c# object pointer using the API 'JSCreateExternalObject' and use it ? I've seen this example https://github.com/robertlong/ChakraLogExample/tree/master/ChakraLogExample where a class is passed to JS.

DrEight avatar Dec 04 '18 11:12 DrEight

Sorry for the late response, was a bit busy these days. the sample your provied is using a prototype "JSLogPrototype" (line 65) to describe the methods and properties for the object instance ( line 93-110 ) , which still need to be hardcoded. Currently there's no good solution for your problem, I think a code generator might be helpful. But I'm afraid I don't have enough bandwidth to do this these days :(

JohnMasen avatar Dec 12 '18 02:12 JohnMasen

Thank you for your answer. What do you mean for a 'code generator'? Currently I'm passing to js a json that generate the object in JS. Are we talking about the same approach ? The problem is that for a big object this approach is slow, so I was wonder if there a faster way.

DrEight avatar Dec 12 '18 10:12 DrEight

seems we're not talking the same thing, code generator means "reflect C# big class and generate the proxy registry code". from your latest post, my understanding is you're trying to pass a complex structure from C# to JS. to avoid hard code all the properties in C#, you're passing a json string to the js then restore it as an object in js.

you're doing the exactly what I'm doing in my other project. I'm thinking add a helper method may help, it serialize your POCO object ( to json) and restore it in JS. If you like this, please create a new issue to help me track this request.

JohnMasen avatar Dec 18 '18 07:12 JohnMasen

thank you for the confirmation. No I don't need an helper. I've already developed all the code. Since it is a very custom serializer/deserializer it does not make any sense that I share it

DrEight avatar Dec 27 '18 09:12 DrEight

no worry, please feel free to keep it to your own project. I'm considering create a new JS wrapper which target V8 engine as chakracore will no longer be actively developed.

JohnMasen avatar Dec 28 '18 02:12 JohnMasen

This is a very bad news. I'm coming from Edge.js and practically I have to redo everything again to return back to V8. How can I know if/when you start to write the new wrapper ?

DrEight avatar Dec 28 '18 12:12 DrEight

I will try my best to remain the high level api(context , hosting) remain same. Ideally I will start the new project at march.

JohnMasen avatar Dec 31 '18 04:12 JohnMasen