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

Cannot create object with accented characters (following ECMA 5.1 compliance) #36

Closed imsmart-tech closed 7 years ago

imsmart-tech commented 7 years ago

This is using jint, but I suspect it's the same with other engines. For example, this works:

script._engine.Execute("var À_la_maison = 5;");

but this does not work:

int test= 5;
engine.EmbedHostObject("À_la_maison", test);

it returns error:

"The script item name 'À_la_maison' has incorrect format."

Of course, without accent it works well.

imsmart-tech commented 7 years ago

This works fine, using jint directly without JavascriptEngineSwitcher:

            var p = new Person
            {
                Name = "Mickey Mouse"
            };

            var engine = new Engine()
                .SetValue("À_la_maison", p)
                .Execute("À_la_maison.Name === 'Mickey Mouse'")
                ;
Taritsyn commented 7 years ago

Hello, Paul!

This error fixed in version 2.4.9.

When you deal with primitive types, then you should use the SetVariableValue method instead of the EmbedHostObject method:

int test= 5;
engine.SetVariableValue("À_la_maison", test);