paulbartrum / jurassic

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

Return value of CompiledScript #203

Closed hamarb123 closed 3 years ago

hamarb123 commented 3 years ago

Hi, I was wondering how I can get the return value of the evaluation of a CompiledScript class. I noticed that it uses GlobalMethodGenerator, which supports a return value, but is internal, and its return value seems to just be discarded in the CompiledScript.Execute(ScriptEngine engine) method. I was wondering if you could update the library to include variants of Evaluate in CompiledScript like in the ScriptEngine class since it seems like it would require no internal changes and seems like a logical extension to me. The reason I want this is because I'm going to likely be evaluating the same script a lot of times in the same engine with possibly different global states, and want the return value, so rather than just calling ScriptEngine.Evaluate(string) every time, I'd like to cache the compilation. Thank you!

paulbartrum commented 3 years ago

Depending on how old your version of the code is, there should be a CompiledEval class too. It's essentially identical to CompiledScript except it returns a value.

hamarb123 commented 3 years ago

Thank you! I didn't see it since it doesn't have a method on ScriptEngine like CompiledScript does.

hamarb123 commented 3 years ago

Hi, @paulbartrum, I'm using the Nuget package, and it doesn't seem to have a CompiledEval class.

paulbartrum commented 3 years ago

You're right; I uploaded a new version to Nuget for you (version 3.2) :-)

hamarb123 commented 3 years ago

Thank you!