JavascriptNet / Javascript.Net

.Net bindings to the V8 JavaScript engine
BSD 2-Clause "Simplified" License
829 stars 150 forks source link

Explain how to manipulate C# (CLR) objects from js and vice versa #93

Closed MappingSteve closed 3 years ago

MappingSteve commented 3 years ago

I can’t determine from the limited documentation what interchange of information is possible between CLR objects and js objects.

Where does this project sit, along a spectrum of “no coupling”: two independent domains, using json (or whatever) to communicate back and forth, to “fully coupled”: where js and c# can directly manipulate objects from the other domain?

  1. Can js hold a handle to a C# (CLR) object?
  2. Can js use .net reflection to discover properties and functions useable on a c# object? And read/write properties, invoke functions with parameters?

And similar questions in the other direction, where c# manipulates js objects.

FWIW: Investigating whether this project would be any help towards a larger goal: A super-strict subset of typescript, removing (hiding) some of js loose-typing functionality, with 1:1 translation between it and c#, calling .net 5 libraries. Then a static analyzer that determines all possible data flow in the CLR representation, for better debugging. Then all needed code is (optionally) translated back into ts/js, so there is an option to run in js without WASM compilation of c#. Just in case / or as in interim solution. Assuming WASM ultimately becomes capable of doing everything js can, without performance issues, this also becomes a path for moving super-strictly-typed ts/js code forward into a pure C#/WASM implementation.

—————————————

UPDATE:

I just discovered Jurassic which is more suitable for my purpose. Compiles js into .NET bytecodes (CIL). Nevertheless, answers to questions above might be useful to add to your read me page.

oliverbock commented 3 years ago

Added a How it works paragraph to the README.