Have you considered using Mono.Cecil?

Dec 30, 2010 at 5:56 PM

I have not looked at a feature by feature comparison to verify that it would in fact work in place of Reflection.Emit for the IL generation, but I believe it would and it would allow Jurassic to work under Mono and potentially on Windows Phone 7.

Coordinator
Dec 31, 2010 at 8:15 AM

Have you confirmed that Jurassic doesn't work under Mono and WP7?  Because I haven't... and it's a little pointless switching codegen frameworks to fix a problem when the problem may not even exist.

I'm definately interested in improving compatibility though - I'll put it on my list of things to do.

Dec 31, 2010 at 2:57 PM

Sorry was in more of a rush than I should have been when I wrote that.  Yes, Jurassic does not work on mono on the mac - the method DynamicMethod.GetDynamicILInfo() has not been implemented and I have not been able to get beyond that.  

As for Win Phone 7 - I have not tried it myself but reports are that the System.Reflection.Emit namespace is not present on SL for Win Phone 7 

   http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/2de27723-749f-4438-8a1e-7086e9468abc

* http://michaelsync.net/2010/04/20/try-mono-cecil-if-you-need-system-reflection-emit-in-windows-phone-7

Also,  What is the time to complete all the tests in the TestSuiteRunner?  I ran them yesterday on my Win 7 box and it was > 5 hours to finish the suite.  Is that typical?

 

Coordinator
Dec 31, 2010 at 11:06 PM

Bypassing GetDynamicILInfo() should not be hard - I already do that for the silverlight version (it's not supported in silverlight either).  I don't have a mac but I'll try to get it working on the win32 version of mono (I assume it's identical across platforms).

No Reflection.Emit is definately a problem with respect to WP7 compatibility.  If Cecil works that might be a reason to switch - however when I last looked it was focused on saving and loading assemblies to disk.  I need to be able to run dynamically generated code without transiting to and from the file system.  I'll have another look though, in case I am wrong about that.

It takes approx. 10 minutes to complete all ~5000 tests on my machine (Intel Core i7 Q720 1.6GHz, 4GB RAM) with the default settings.  What sort of machine are you running the tests on?

Jan 5, 2011 at 11:53 AM

Dear Paul!

It's seems to be a very nice JS engine You have created!

I would very much like to use it for windows phone application, but there is this issue with System.Reflection.Emit, when I try to compile the source. I'm quite new to C# in general though... Do you think there is an easy workaround for this?

Another thing, but this must be probably asked in another thread, anyway.. Is it possible with Your engine by calling from Javascript structures like "var obj = document.getElementById('id')" or "element.setAttribute('id', 'theid')" to make it trigger the C# code? I'm planning to use it for SVGDOM manipulation.

Thank you!

Kind regards,

Yevgeny

Jan 5, 2011 at 1:26 PM
ogryzok wrote:

Another thing, but this must be probably asked in another thread, anyway.. Is it possible with Your engine by calling from Javascript structures like "var obj = document.getElementById('id')" or "element.setAttribute('id', 'theid')" to make it trigger the C# code? I'm planning to use it for SVGDOM manipulation.

 

RTFM :-))) It's here http://jurassic.codeplex.com/wikipage?title=Exposing%20a%20.NET%20class%20to%20JavaScript&referringTitle=Documentation

Then this Engine seems to be what I need. Just that it could nice to have on wp.

Oct 10, 2011 at 10:58 AM

Hi Paul :)

I recently tried out SassAndCoffee and CoffeeSharp that both rely on Jurassic for CoffeeScript compilation. I mainly use Mono on Unix and when I tried to use one of those earlier mentioned libs I get not implemented exceptions on methods under System.Reflection namespace due to incomplete implementation in Mono (have tried 2.10.5 and latest from github, 2.11). Bummer :/

Have you reconsidered using Cecil?

Coordinator
Oct 10, 2011 at 9:52 PM
Edited Oct 10, 2011 at 9:53 PM

I haven't had a chance to look at Mono - is it just GetDynamicILInfo() that is failing?  'cause if so a few #ifdefs should make it work.

I looked at Cecil a while and it didn't seem to fit what I needed.  Also, I'd rather not add any dependencies if I can help it (currently System.dll is the only dependency).

Oct 11, 2011 at 2:51 PM
Edited Oct 11, 2011 at 2:54 PM

Hi Paul - Yep totally understand you. I really hope to get this working on Mono such that I can use one of those libs mentioned in the original post.

Unhandled Exception: System.NotImplementedException: The requested feature is not implemented.  at Jurassic.Compiler.DynamicILGenerator..ctor (System.Reflection.Emit.DynamicMethod dynamicMethod) [0x00000] in <filename unknown>:0   at Jurassic.Compiler.MethodGenerator.GenerateCode () [0x00000] in <filename unknown>:0   at Jurassic.ScriptEngine.Execute (Jurassic.ScriptSource source) [0x00000] in <filename unknown>:0   at Jurassic.ScriptEngine.Execute (System.String code) [0x00000] in <filename unknown>:0   at CoffeeSharp.CoffeeScriptEngine..ctor () [0x00000] in <filename unknown>:0   at FubuMVC.Coffee.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.NotImplementedException: The requested feature is not implemented.  at Jurassic.Compiler.DynamicILGenerator..ctor (System.Reflection.Emit.DynamicMethod dynamicMethod) [0x00000] in <filename unknown>:0   at Jurassic.Compiler.MethodGenerator.GenerateCode () [0x00000] in <filename unknown>:0   at Jurassic.ScriptEngine.Execute (Jurassic.ScriptSource source) [0x00000] in <filename unknown>:0   at Jurassic.ScriptEngine.Execute (System.String code) [0x00000] in <filename unknown>:0   at CoffeeSharp.CoffeeScriptEngine..ctor () [0x00000] in <filename unknown>:0   at FubuMVC.Coffee.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 


Running a simple little console program that uses CoffeeSharp:

var cse = new CoffeeScriptEngine();
var smoke = cse.Compile("smoke = (x) -> x * x"); 
Console.WriteLine(smoke);

I think you would be able to encounter same issues using Mono for Windows.

Oct 11, 2011 at 7:33 PM

What about WP7, do Cecil work on those?

Oct 19, 2011 at 12:29 AM

Hi Paul :) just a follow up - Have you tried out Jurassic on Mono?

Coordinator
Oct 19, 2011 at 6:15 AM

Not yet, sorry.  It should be easy to get the basics working - but getting the unit test runner working will take a decent amount of effort (it's WPF) and I need the tests to pass to be able to say it works properly.

Nov 8, 2011 at 8:11 AM

Can't you just ommit the graphical unit-test and run it from command line? If I recall correctly you use xUnit or nUnit or something along those lines? I think both of those should work well in mono, simply just run the command line runner instead of a GUI one you've written. That way you can also automate it on build etc., and you could probably even set up a build-server if you wanted to.

Coordinator
Nov 8, 2011 at 9:42 AM

The tests are all written in JavaScript, I can't change them, and the list of tests is not static.  So no, I can't use xUnit or nUnit.

Nov 8, 2011 at 10:12 AM
Ah, sorry, I must have mixed projects :). Anyways, writing a console app that runs the tests instead of a WPF app shouldn't be that hard, right? You can probably copy paste most of the code, and just output the result as a XML-file or something along those lines.
Coordinator
Nov 8, 2011 at 11:53 PM

My plan is to refactor the back-end test runner code into a separate DLL and have multiple "shells" (Console, WPF, WP7).  I also want to update the tests to the latest version (from here: http://test262.ecmascript.org/).  Unfortunately work is keeping me busy and I don't have a lot of motivation to do more programming when I get home...

Nov 9, 2011 at 8:11 AM
I hear you. I'll look at it if I got time.
Jan 21, 2012 at 10:18 AM

I have tested it with Mono, and as far as I can tell this is the only change required.
I haven't run any unit tests with it, so there may be other problems, however it runs fine with my code.

(Located in ScriptEngine class)

internal static bool LowPrivilegeEnvironment
{
    get
    {
        lock (lowPrivilegeEnvironmentLock)
        {
            if (lowPrivilegeEnvironmentTested == false)
            {
                if(Type.GetType("Mono.Runtime") != null)
                {
                    lowPrivilegeEnvironment = true;
                    lowPrivilegeEnvironmentTested = true;
                }
                else
                {
                    var permission = new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode);
                    lowPrivilegeEnvironment = !System.Security.SecurityManager.IsGranted(permission);
                    lowPrivilegeEnvironmentTested = true;
                }
            }
        }
        return lowPrivilegeEnvironment;
    }
}
Essentially if it is in mono it defaults to a low privilege environment.