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 | .... | 54 | 55 | (Page 56) | 57 | 58 | .... | 115 | newer

    0 0

    I initialize my engine with the following lines:

    ```
    Dim engine As JScriptEngine
    engine = New JScriptEngine(WindowsScriptEngineFlags.EnableDebugging)
    engine.AddHostType("Console", GetType(Console))

    ```

    I add the following script to the engine:

    ```
    function Test(param) {
    Console.WriteLine("Called Test with param: " + param);
    }
    ```

    When I call

    ```
    engine.Script.Test(20)
    ```

    It prints: "Called Test with param: undefined"

    Does JScriptEngine not support calling internal functions with parameters?

    0 0

    I initialize my engine with the following lines:

    ```
    Dim engine As JScriptEngine
    engine = New JScriptEngine(WindowsScriptEngineFlags.EnableDebugging)
    engine.AddHostType("Console", GetType(Console))

    ```

    I add the following script to the engine:

    ```
    function Test(param) {
    Console.WriteLine("Called Test with param: " + param);
    }
    ```

    When I call

    ```
    engine.Script.Test(20)
    ```

    It prints: "Called Test with param: undefined"

    Does JScriptEngine not support calling internal functions with parameters?
    Comments: We cannot reproduce this issue in ClearScript 5.4, and there has been no response from ahmetuzun in 10 days. Marking as resolved.

    0 0

    Hi Julien,

    In the test code above, the initial toString() call does not involve ClearScript at all. The "[object Undefined]" result makes sense; the script engine finds the built-in function on the global object's prototype chain, and invokes it with an undefined this binding. Note that the result is different if you bind this to the global object via this.toString().

    The result of the second call is also expected; V8 invokes the user-defined function that now hangs off the global object.

    The result of the third call is due to a ClearScript bug. The GlobalMembers feature incorrectly exposes the proxy's built-in toString() method as a global member that overrides the user-defined function. We're testing a fix and will post it very soon.

    Thanks bringing another ClearScript issue to our attention!

    0 0

    Hello Julien,

    We cannot reproduce the V8 crash with the test code above. The correct exception is delivered to the caller with or without a second GlobalMembers object added before the MissingSetter instance.

    One difference is that we're not using NUnit. Could you try replacing the Assert.Throws() call with a try..catch statement?

    Thanks!

    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


    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

    Greetings!

    By-reference arguments to VBScript functions are not currently supported. We'll use the work item you created to track this issue. Thanks for reporting it!

    In the meantime, you can create a wrapper in VBScript that calls the target function and returns its output to the host without by-reference parameters. For example:
    publicclass Holder<T> {
        public T Value;
    }
    And then:
    engine.Execute(@"
        sub TestSubWrapper(holder)
            dim value
            value = holder.Value
            call TestSub(value)
            holder.Value = value
        end sub
    ");
    
    var holder = new Holder<double> { Value = 10.0 };
    engine.Script.TestSubWrapper(holder);
    Console.WriteLine(holder.Value);
    Thanks again, and good luck!

    0 0

    Same behaviour with the try/catch block. It crashes before the catch statement in my code.

    it still crashes in the same place (api.cc, line 2905), just after the ScriptException was thrown in the V8ContextImpl::SetHostObjectProperty() method
    and here is the call stack
    Image

    0 0

    Hi Julien,

    We've now reproduced the issue, and we'll post a fix shortly.

    You've helped us find some very tricky bugs. Thank you!

    EDIT: We couldn't reproduce the crash earlier because it's the result of a failing debug-only assertion in V8. You're using a debug build of V8, right?

    0 0

    Yes the assert/check is only produced in debug.
    I mixed-up my first test somehow, I thought I was using release V8/ClearScript but it was the debug version.

    0 0

    Fix posted here.

    0 0

    Fix posted here.

    0 0

    Hi,

    I am exposing existing .NET objects to my script now following .NET conventions I am using PascalCase for my names, is there any nice way that these can become camel cased once exposed to js?

    I don't want to have to pollute my objects with methods of both cases or move to camel casing, it would be nice if there was an attribute I could put on methods or some sort of global flag to say treat eveyrthing as camel case.


    Ideas?


    Thanks
    Stefan

    0 0

    Hi,

    I am exposing existing .NET objects to my script now following .NET conventions I am using PascalCase for my names, is there any nice way that these can become camel cased once exposed to js?

    I don't want to have to pollute my objects with methods of both cases or move to camel casing, it would be nice if there was an attribute I could put on methods or some sort of global flag to say treat eveyrthing as camel case.


    Ideas?


    Thanks
    Stefan
    Comments: Sorry ignore this I see it is supported abd just not documented! Thanks

    0 0

    Hi,

    I am exposing existing .NET objects to my script now following .NET conventions I am using PascalCase for my names, is there any nice way that these can become camel cased once exposed to js?

    I don't want to have to pollute my objects with methods of both cases or move to camel casing, it would be nice if there was an attribute I could put on methods or some sort of global flag to say treat eveyrthing as camel case.


    Ideas?


    Thanks
    Stefan
    Comments: Sorry I don't mean not documented just not in front of me.

    0 0

    Hi,

    I am exposing existing .NET objects to my script now following .NET conventions I am using PascalCase for my names, is there any nice way that these can become camel cased once exposed to js?

    I don't want to have to pollute my objects with methods of both cases or move to camel casing, it would be nice if there was an attribute I could put on methods or some sort of global flag to say treat eveyrthing as camel case.

    It would be nice if this could be conventional so I could support it on existing libraries that I cannot add the attribute to!


    Ideas?


    Thanks
    Stefan

    0 0

    Hi,

    I am exposing existing .NET objects to my script now following .NET conventions I am using PascalCase for my names, is there any nice way that these can become camel cased once exposed to js?

    I don't want to have to pollute my objects with methods of both cases or move to camel casing, it would be nice if there was an attribute I could put on methods or some sort of global flag to say treat eveyrthing as camel case.

    It would be nice if this could be conventional so I could support it on existing libraries that I cannot add the attribute to!


    Ideas?


    Thanks
    Stefan

    0 0

    Hi,

    I am exposing existing .NET objects to my script now following .NET conventions I am using PascalCase for my names, is there any nice way that these can become camel cased once exposed to js?

    I don't want to have to pollute my objects with methods of both cases or move to camel casing, it would be nice if there was an attribute I could put on methods or some sort of global flag to say treat eveyrthing as camel case.

    It would be nice if this could be conventional so I could support it on existing libraries that I cannot add the attribute to!


    Ideas?


    Thanks
    Stefan
    Comments: Hi Stefan, It looks like you found `ScriptMemberAttribute`. Unfortunately ClearScript doesn't provide global control over exposed member names. Good luck!

    0 0

    I initialize my engine with the following lines:

    ```
    Dim engine As JScriptEngine
    engine = New JScriptEngine(WindowsScriptEngineFlags.EnableDebugging)
    engine.AddHostType("Console", GetType(Console))

    ```

    I add the following script to the engine:

    ```
    function Test(param) {
    Console.WriteLine("Called Test with param: " + param);
    }
    ```

    When I call

    ```
    engine.Script.Test(20)
    ```

    It prints: "Called Test with param: undefined"

    Does JScriptEngine not support calling internal functions with parameters?

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

    ```

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