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

Commented Unassigned: 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"));
}

```
Comments: Hello! It looks like your test code relies on an earlier bug that is now fixed. Take a look at this code from your test method: ``` C# engine.AddHostObject("", HostItemFlags.GlobalMembers, new host1()); engine.AddHostObject("", HostItemFlags.GlobalMembers, new host2()); ``` `GlobalMembers` or not, what `AddHostObject()` does is set a property on the global object, and because you're using the same property name for both calls (the empty string), the second line _overwrites_ the property value assigned by the first. Simply changing one of those names should make the test pass again. Sorry about the earlier bug. Please let us know if you have further questions or concerns. Thanks!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images