paulbartrum / jurassic

A .NET library to parse and execute JavaScript code.
MIT License
873 stars 122 forks source link

Linux compability ? #223

Open bsjaramillo opened 1 year ago

paulbartrum commented 1 year ago

It should work on Linux (there's no platform-specific stuff), but I haven't tried it, so I can't say for sure.

bsjaramillo commented 1 year ago

I understand, I asked because I'm migrating a Windows Project to Linux, this project use Jurassic lib, then when I execute It (still in Windows console) I'm having problems with methods not finded and this problem raise in Jurassic lib.

image

The problem gets here in Core.ScriptEngine, in the method: public object Evaluate(ScriptSource source) { var methodGen = new EvalMethodGenerator( ObjectScope.CreateGlobalScope(this.Global), // The variable scope. source, // The source code. CreateOptions(), // The compiler options. this.Global); // The value of the "this" keyword.

        try
        {
            // Parse
            this.ParsingStarted?.Invoke(this, EventArgs.Empty);
            methodGen.Parse();

            // Optimize
            this.OptimizationStarted?.Invoke(this, EventArgs.Empty);
            methodGen.Optimize();

            // Generate code
            this.CodeGenerationStarted?.Invoke(this, EventArgs.Empty);
            **methodGen.GenerateCode();**
            VerifyGeneratedCode();
        }
        catch (SyntaxErrorException ex)
        {
            throw new JavaScriptException(this, ErrorType.SyntaxError, ex.Message, ex.LineNumber, ex.SourcePath);
        }

        // Execute
        this.ExecutionStarted?.Invoke(this, EventArgs.Empty);
        var result = methodGen.Execute(this);

        // Normalize the result (convert null to Undefined, double to int, etc).
        return TypeUtilities.NormalizeValue(result);
    }

Maybe any idea about this problem ? :/

paulbartrum commented 1 year ago

That error looks like it's related to PDB generation, but I got rid of that code a while back (.NET core dropped support for it). What version of Jurassic are you using?

Edit: old versions of Jurassic had a EnableDebugging property on the ScriptEngine class. I think in order to get the error you are seeing your code must be setting that property to true. Try setting it to false instead (or just remove that line, that property is false by default).

bsjaramillo commented 1 year ago

Well, I've updated Jurassic to last version, I think It was using Jurassic 3.0.0, I had to change many things in the project and I dont know if It will works rigth hahaha. A last question, with the last version, I had to delete decorators [JSObject(Name="lalala")] and others, is it not necesary already ? and the project was using a field UserData from ScriptEngine, but It doesnt appears in the last version, what is this field ? Thanks for you support.