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: The purpose was to both 1) run a script as if it belonged to a particular class 2) maintain a global context (which has not the same lifespan). If you think of some sort of workaround for this case, I would be glad to accept your clues on this.

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images