Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: for/in loop in JScript standards mode

It appears that the for/in loop is not working when JScript engine is initialized with WindowsScriptEngineFlags.EnableStandardsMode flag.

I tried adding PropertyBag and ExpandoObject as host objects.

I noticed that there is a ScriptEngineException when executing for/in loop on either of the two objects which has HResult of 0x800a0005 (Invalid procedure call or argument).

Without WindowsScriptEngineFlags.EnableStandardsMode flag everything works without exceptions.

I am developing on Windows 10 with ClearScript 5.4.3

Here is the sample program:
        static void Main(string[] args)
            var engine = new JScriptEngine(WindowsScriptEngineFlags.EnableStandardsMode);
            engine.AddHostType("Console", typeof(Console));

            dynamic expandoObj = new ExpandoObject();
            expandoObj.testProp = "expando testProp Text";
            engine.AddHostObject("expandoObj", expandoObj);

            var propertyBag = new PropertyBag();
            propertyBag["testProp"] = "property bag testProp Text";
            engine.AddHostObject("propertyBagObj", propertyBag);

            engine.Execute(@"Console.WriteLine('expandoObj.testProp=' + expandoObj.testProp);");
            engine.Execute(@"Console.WriteLine('propertyBagObj.testProp=' + propertyBagObj.testProp);");
            engine.Execute(@"for (var item in propertyBagObj) Console.WriteLine('propertyBagObj[' + item + ']=' + propertyBagObj[item]);");
            engine.Execute(@"for (var item in expandoObj) Console.WriteLine('expandoObj[' + item + ']=' + expandoObj[item]);");


Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles

Latest Images