Quantcast
Are you the publisher? Claim or contact us about this channel


Embed this content in your HTML

Search

Report adult content:

click to rate:

Account: (login)

More Channels


Showcase


Channel Catalog



Channel Description:

ClearScript is a library that makes it easy to add scripting to your .NET applications. It currently supports JavaScript (via V8 and JScript) and VBScript.

older | 1 | .... | 53 | 54 | (Page 55) | 56 | 57 | .... | 115 | newer

    0 0
  • 11/17/14--01:11: New Post: javascript blob
  • Hi ,

    How can we give input from user for the expression .

    Thank you.

    0 0
  • 11/17/14--07:22: New Post: javascript blob
  • Please elaborate. How are you gathering user input? How is it represented? How would you like to use it from script code?

    0 0
  • 11/18/14--02:04: New Post: javascript blob
  • Hi,

    I have records with single field stored in list in a class i.e., name of person . Now i need to give the input expression to evaluate , and this input expression need to check for the records in list.

    example :

    Name is : siva
    Name is : kumar

    these are present in list, now we will give input expression name='siva' .

    WriteLine("Enter input");
    var input = ReadLine();

    var result = engine.Evaluate(input = list.ToString());

    WriteLine(result);

    Thank you .

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

    ```

    0 0
  • 11/18/14--04:40: New Post: javascript blob
  • Hi,

    Sorry, still not clear:

    var input = ReadLine();

    var result = engine.Evaluate(input = list.ToString());

    Are you expecting the user to enter the script to be executed? Or is the user typing in some data for the script to process?

    Thanks!

    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!

    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: Oooouch.. I really didn't expected that. (BTW when reading the clearscript code I thought using same names was specifically supported). The intent behind such code was to run specific scripts with particular scopes. We have a global scope, and specific scopes depending on the scripts being run. Imagine this example : ``` C# engine.AddHostObject("", HostItemFlags.GlobalMembers, new global_context()); engine.AddHostObject("", HostItemFlags.GlobalMembers, new kitchen_context()); ``` I can run the following js code (kitchen_context has a Shutter and Oven property, global_context has a Sensor property) : ``` js Oven.Start(); if (Sensor.GetHumidity() > 0.70) { Shutter.Open(0.5); } ``` And with another scope we can achieve this : (bathroom_context has a HVAC property) ``` C# otherengine.AddHostObject("", HostItemFlags.GlobalMembers, new global_context()); otherengine.AddHostObject("", HostItemFlags.GlobalMembers, new bathroom_context()); ``` I can run the following js code : ``` js if (Sensor.GetHumidity() > 0.70) { HVAC.Blow(); } ``` I guess we are stuck with 5.3.10 now... (or maybe some sort of proxy object could merge the two globalmembers contexts ? or maybe you could still support this :-p)

    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.

    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: Hi again, Unless we're missing something, you can absolutely do what you need without relying on the bug. Consider something like this: ``` C# engine.AddHostObject("residence", HostItemFlags.GlobalMembers, new global_context()); engine.AddHostObject("room", HostItemFlags.GlobalMembers, new kitchen_context()); engine.Execute(kitchen_script); ``` And later: ``` C# engine.AddHostObject("room", HostItemFlags.GlobalMembers, new bathroom_context()); engine.Execute(bathroom_script); ``` The `AddHostObject("room", ...)` call removes the kitchen properties and adds the bathroom properties. The "residence" properties are available for both scripts. With the bug, `AddHostObject("room", ...)` would fail to remove the kitchen properties. Worse, the underlying host object would leak. Cheers!

    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 ! Explained like that, it really makes sense. I guess I was confused about the "name". Good job, thanks ! Julien.

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

    ```

    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: No problem. Thank you!

    0 0
  • 11/19/14--01:39: New Post: javascript blob
  • Hi,
    user is typing in some data for the script to process.
            using (var engine = new V8ScriptEngine())
            {
                WriteLine("Enter input");
                var input = ReadLine(); 
    
                foreach (PersonList person in list)
                {
                 var output= engine.Evaluate((input) = (person.name));
                 WriteLine(output);
                 }
    
    input is typing by user some data for the script to process i.e., name="siva"

    Thanks!

    0 0
  • 11/19/14--05:40: New Post: javascript blob
  • OK, it looks like you're trying to pass input and person.name to a script function or expression.

    If that's correct, there are many ways to do that. Several were already demonstrated (see the myFunction samples above).

    Another possibility, if all the arguments are strings, is to insert the arguments into the script code itself:
    engine.Evaluate(string.Format("myFunction('{0}', '{1}')", input, person.name));
    Good luck!

    0 0
  • 11/19/14--22:51: New Post: javascript blob
  • Hi,

    Yes we are not also passing the input and person.name but also comparing the them i.e., comparing the input to the list(person.name) .

    Thanks.

    0 0
  • 11/20/14--07:06: New Post: javascript blob
  • Hi nsivakumarreddy,

    No matter what kind of data you need to pass to your script, you should be able to use one of the patterns above.

    Please let us know if you have other questions.

    Thank you!

    0 0

    One of my users created a toString() function which miserably failed, always returning [object Undefined].

    I created a test, and the unexpected behaviour seems to be triggered by using GlobalMembers.

    I do not know exactly what behaviour to expect in the context of clearscript, but the function toString cannot be redefined once the global host object is added.
    Is it a bug, is it a design feature ?

    Here is the test code :
    class foo
            {
                publicstring A { get; set; }
            }
    
            [Test]
            publicvirtualvoid Test_ToString_v8_base()
            {
                using(var run = new V8ScriptEngine())
                {
                    var tsBefore = run.Evaluate("toString()");
                    Assert.AreEqual("[object Undefined]", tsBefore);// is it ok ?
    
                    run.Execute(@"function toString(){return 'AAA';}");
                    var tsBefore2 = run.Evaluate("toString()");
                    Assert.AreEqual("AAA", tsBefore2);
    
                    var foo = new foo();
                    run.AddHostObject("foo", HostItemFlags.GlobalMembers, foo);
    
                    var tsAfter = run.Evaluate("toString()");
    
                    run.Execute(@"function toString(){return 'BBB';}");
    
                    var tsAfter2 = run.Evaluate("toString()");
                    Assert.AreEqual("BBB", tsAfter2);// NOK: it is still [object Undefined]
                    Assert.AreEqual("AAA", tsAfter); // don't know what to expect here..
                }
            }

    0 0


    Great Library, really helpful!

    I ran into one situation where we have some existing VBScripts, the have subroutines and functions that take ByRef scalar types such as ints, double and the values are being changed in the function.


    Here is the code I tested:

    VBScriptEngine scriptEngine = new VBScriptEngine(WindowsScriptEngineFlags.EnableDebugging);
    double byRefValue = 10.0;
    scriptEngine.Execute(@"sub TestSub(ByRef MyParam) : MyParam=20.0 : end sub");
    scriptEngine.Script.TestSub(ref byRefValue);


    Basically what I was trying to accomplish , was the double values should end up being set to 20.0 , but it always remains at 10.0

    I tried changing the double to an object and dynamic and it didn't make a difference.

    Any thoughts on how to support this scenario.

    Thanks!


    0 0

    Hello !
    I'm using Clearscript 5.4 with default V8.

    It crashes when trying to write to a property without setter.. but only if I add another global object first, as illustrated with the test below (the fact that it is a PropertyBag does not seems to be relevant). Otherwise it behaves as expected, throwing an exception.

    Any idea of what might be happening here ?
    #
    # Fatal error in ..\..\src\api.cc, line 2905
    # CHECK(!(isolate)->external_caught_exception()) failed
    #
    Exception de première chance à 0x00000000 dans nunit.exe : 0xC0000005: Violation d'accès à l'emplacement 0x0000000000000000.
    Exception non gérée à 0x00000000 dans nunit.exe : 0xC0000005: Violation d'accès à l'emplacement 0x0000000000000000.
    class MissingSetter
            {
                privatestring _back_title;
                public MissingSetter(string title)
                {
                    _back_title = title;
                }
                publicstring title
                {
                    get
                    {
                        return _back_title;
                    }
                }
            }
    
            [Test]
            publicvirtualvoid Test_InterfaceAndScriptAccess_basic([Values(false, true)] bool withPropertyBag)
            {
                using (var run0 = new V8ScriptEngine())
                {
                    if (withPropertyBag)
                        run0.AddHostObject("bag", HostItemFlags.GlobalMembers, new PropertyBag());
                    run0.AddHostObject("__other_page", HostItemFlags.GlobalMembers, new MissingSetter("BBB"));
                    Assert.AreEqual("BBB", run0.Evaluate("title"));
                    Assert.Throws<Microsoft.ClearScript.ScriptEngineException>(delegate
                    {
                        run0.Execute("title = 'AAA'");
                    });
                    Assert.AreEqual("BBB", run0.Evaluate("title"));
                }
            }

    0 0

    Sorry I added a item to the issues, but probably should have been posted here instead..

    Great Library, really helpful!

    I ran into one situation where we have some existing VBScripts, the have subroutines and functions that take ByRef scalar types such as ints, double and the values are being changed in the function.


    Here is the code I tested:
        VBScriptEngine scriptEngine = new VBScriptEngine(WindowsScriptEngineFlags.EnableDebugging);
        double byRefValue = 10.0;
        scriptEngine.Execute(@"sub TestSub(ByRef MyParam) : MyParam=20.0 : end sub");
        scriptEngine.Script.TestSub(ref byRefValue);
    
    
    Basically what I was trying to accomplish , was the double values should end up being set to 20.0 , but it always remains at 10.0

    I tried changing the double to an object and dynamic and it didn't make a difference.

    Any thoughts on how to support this scenario.

    Thanks!

older | 1 | .... | 53 | 54 | (Page 55) | 56 | 57 | .... | 115 | newer