4

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?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Wayne Kao
  • 8,125
  • 5
  • 30
  • 25

3 Answers3

1

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.

Loki
  • 6,205
  • 4
  • 24
  • 36
  • The problem I've had with this (using JScript.NET) is that while it is possible to call functions & classes defined in JScript.NET from other languages, there does not appear to be a way to access variables and run code defined "at the top level". Further, if functions or methods try to access things initialized at global scope, these values are uninitialized. If you have a different experience, I'd love to hear about it! – James Hugard Jun 01 '09 at 22:55
1

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

Community
  • 1
  • 1
James Hugard
  • 3,232
  • 1
  • 25
  • 36
0

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
  • 61,017
  • 25
  • 133
  • 162