Skip to content

Nil - can't locate function name #57

Description

@deandob

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!");
            }`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions