views:

295

answers:

3

I have a set of core, complicated JavaScript data structures/classes that I'd like to be able to use both in the browser as JavaScript and run on the desktop with .NET 3.5. Is it possible to compile web-friendly JavaScript into assemblies that my C# code can access?

  • Managed JScript - Is there a compiler for this available that will produce something that can run on the desktop CLR? I've only seen released examples for the Silverlight runtime. It doesn't sound like it's officially available on the desktop but I'm willing to try something less blessed, like can I compile with the Silverlight tools and then run on the desktop CLR?
  • JScript .NET - Sounds like it's got enough custom language extensions where having the same code run in a browser would be really hard, but maybe there's a way...?

If neither of those work, I guess my options are to:

  • Have a C# version and a JavaScript version which I have to keep in sync (yuck).
  • Write a preprocessor of sorts that runs at compile time to turn my JavaScript into JScript .NET or something that I can compile into .NET assemblies.
  • Script#: Looks like this turns C# code into JavaScript code. Not awesome since I'd prefer to be able to heavily tune JavaScript code directly, but it could work.

Anyone have success with any of these options?

A: 

How about another option:

  • Host the javascript application inside your desktop app via winforms' WebBrowser control?

Is this possible?

You can also access the DOM from WebBrowser control but not everything you want is fully supported.

chakrit
+1  A: 

JScript.Net is actually mostly EMCAScript3 compliant. As long as you treat your code as a processing library (only have it do crunching, etc - use callbacks to interact with the program), you should be fine. I'm doing something similar, using javascript as my core parsing library, and then using it within python, dotnet, and php.

Lokkju
James Hugard
+1  A: 

Managed JavaScript (IronJScript) appears to have been killed. See this answer:

James Hugard