Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Question about passing generic List.

$
0
0
I am trying to convert an C# application that used VSA JScript engine to use ClearScript with V8 engine. I have a question about how ClearScript handles generic list. I have the follow sample code:
    public class Item { public int Value; }
    public IList<Item> MyList = new List<Item>() { new Item(), new Item(), new Item() };

    void ClearScriptTest(object sender, EventArgs e) {
        using (var engine = new V8ScriptEngine()) {
            engine.AddHostObject("Me", this);
            engine.Execute("Me.MyList[0].Value = 123;");
            MessageBox.Show(MyList[0].Value.ToString());
        }
    }
When I run this code, an exception "TypeError: Cannot set property 'Value' of undefined"
will be thrown. However when I change the declaration type of MyList from IList<int> to List<int>, then the code works. It looks like that engine.Execute() uses the static declaration type instead of the actual type of the object Me.MyList. Is this a defect ? The old VSA JScript engine behaviors differently. Is there a way to configure ClearScript to fix this problem?

Viewing all articles
Browse latest Browse all 2297

Trending Articles