Taritsyn / JavaScriptEngineSwitcher

JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines. This library allows you to quickly and easily switch to using of another JavaScript engine.
Apache License 2.0
440 stars 49 forks source link

Nil - can't locate function name #57

Closed deandob closed 6 years ago

deandob commented 6 years ago

Hi,

I'm trying to use JavaScriptEngineSwitcher for the NiL JS engine as it is the best fit for my use-case, however it seems there is an issue with being able to call functions, with the switcher reporting JavaScriptEngineSwitcher.Core.JsRuntimeException: 'The function with the name 'negate' does not exist.' yet when I run exactly the same code with Jint it works fine. Is the NiL wrapper not ready for use? The code is from your test cases, as below:

` JsEngineSwitcher engineSwitcher = (JsEngineSwitcher)JsEngineSwitcher.Current; engineSwitcher.EngineFactories .AddNiL(new NiLSettings { StrictMode = true }) //.AddJint() //.AddJurassic() //.AddMsie(new MsieSettings //{ // UseEcmaScript5Polyfill = true, // UseJson2Library = true //}) //.AddV8() ;

        engineSwitcher.DefaultEngineName = NiLJsEngine.EngineName;
        //engineSwitcher.DefaultEngineName = JintJsEngine.EngineName;

        const string functionCode = @"function negate(value) {
            return -1 * value;
        }";
        using (var engine = JsEngineSwitcher.Current.CreateDefaultEngine())
        {
            try
            {
                engine.Execute(functionCode);
                var result = engine.CallFunction("negate", 22);         //<=== Error here with NiL, function 'negate' not found, OK with Jint
            }
            catch (TimeoutException)
            {
                Console.WriteLine("Timed out!");
            }`
Taritsyn commented 6 years ago

Hello, Dean!

It seems, that this is some kind of error in the NiL.JS, because it occurs only in strict mode. I created a issue in repository of the original project - https://github.com/nilproject/NiL.JS/issues/146

deandob commented 6 years ago

Yep, that's it! Thanks for the quick response, and thanks for JSEngineSwitcher, very helpful.

Taritsyn commented 6 years ago

By the way, instead of the TimeoutException class you need to use the JsTimeoutException and timeouts occur only in the JavaScriptEngineSwitcher.Jint module.

deandob commented 6 years ago

OK. Thx. I'll close this now.

Taritsyn commented 6 years ago

Hello, Dean!

This error is fixed in version 3.0.0 Beta 9.