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

Edited Issue: GlobalMember property not found (regression) [57]

$
0
0
when upgrading from 5.3.10 to 5.4, my unit tests fail when trying to find a globalmember property, in a particular case. Some unit tests are better than a long speech so here are the tests (only the NOK fails, with error : __ReferenceError: A is not defined__) :

```
class host1
{
public string H { get; set; }
public PropertyBag A { get; set; }
public host1() { A = new PropertyBag(); A.Add("FOUR", 4); }
}

class host2
{
public string W { get; set; }
public PropertyBag B { get; set; }
public host2() { B = new PropertyBag(); B.Add("EIGHT", 8); }
}

[Test]
public void Test_engine_global_objects_NOK()
{
var engine = new V8ScriptEngine("xscript");

engine.AddHostObject("", HostItemFlags.GlobalMembers, new host1());
engine.AddHostObject("", HostItemFlags.GlobalMembers, new host2());

Assert.AreEqual(4, engine.Evaluate("A.FOUR"));
Assert.AreEqual(8, engine.Evaluate("B.EIGHT"));
}

[Test]
public void Test_engine_global_objects_A()
{
var engine = new V8ScriptEngine("xscript");
engine.AddHostObject("", HostItemFlags.GlobalMembers, new host1());
Assert.AreEqual(4, engine.Evaluate("A.FOUR"));
}
[Test]
public void Test_engine_global_objects_B()
{
var engine = new V8ScriptEngine("xscript");
engine.AddHostObject("", HostItemFlags.GlobalMembers, new host2());
Assert.AreEqual(8, engine.Evaluate("B.EIGHT"));
}

[Test]
public void Test_engine_normal_objects()
{
var engine = new V8ScriptEngine("xscript");

engine.AddHostObject("f", new host1().A);
engine.AddHostObject("e", new host2().B);
Assert.AreEqual(4, engine.Evaluate("f.FOUR"));
Assert.AreEqual(8, engine.Evaluate("e.EIGHT"));
}

[Test]
public void Test_engine_simple_global_objects()
{
var engine = new V8ScriptEngine("xscript");

engine.AddHostObject("", HostItemFlags.GlobalMembers, new host1());
engine.AddHostObject("", HostItemFlags.GlobalMembers, new host2());

engine.Execute("H = 'hello'");
engine.Execute("W = 'world'");
Assert.AreEqual("hello", engine.Evaluate("H"));
Assert.AreEqual("world", engine.Evaluate("W"));
}

```

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>