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 | .... | 30 | 31 | (Page 32) | 33 | 34 | .... | 115 | newer

    0 0

    I installed the nuget package and then removed it. Seems to have left behind the post build event command lines. Booo :(

    0 0

    ClearScript apparently can't find a function added dynamically to the window object.

    In a regular html file, I can call "var passwordAnalysis = zxcvbn($(this).val(), penalties);" just fine.

    However, I am trying to execute https://raw.github.com/lowe/zxcvbn/master/zxcvbn.js inside a C# project.

    I always get the exception:

    ScriptEngineException: TypeError: Method or property not found.

    I suspect it is because the zxcvbn method is added dynamically.

    C# Code is as follows:

    using Microsoft.ClearScript;
    using Microsoft.ClearScript.V8;

    public class RunScripts
    {
    public void GetPasswordStrength(string password, string[] penalties)
    {
    using (var engine = new V8ScriptEngine())
    {
    engine.Execute(ZxcvbnScript);

    var result = engine.Script.zxcvbn(password, penalties);
    //or
    var result = engine.Script.zxcvbn(password);
    //or
    var result = engine.Script.zxcvbn(password);
    }
    }
    }

    0 0

    Passing a variable (Class) to a sub and using the passed variable to make changes results in the calling routine having its copy adjusted suggesting that BYVAL is not being used for Class objects.

    Example Code

    ```
    Class Switch
    Public Name
    Public IP
    End Class

    sub Test(byval lsw)
    lsw.Name = "From Sub"
    end sub

    set LSwitch = new Switch
    LSwitch.Name = "Outside"
    writeline("Name : " & LSwitch.Name)
    Test LSwitch
    writeline("Name : " & LSwitch.Name)
    ```
    Resulting Output :
    ```
    Name : Outside
    Name : From Sub
    ```

    0 0

    When an class have overloaded indexed property,
    overload resolution with the property does not work.

    class definition (C#)
    ```
    public class MyDictionary
    {
    public Object this[Int32 index]
    {
    get { return this.GetItemByIndex(index); }
    }
    public String this[String name]
    {
    get { return this.GetItemByName(name); }
    }
    // ...
    }
    ```

    Code execution
    ```
    var engine = new V8ScriptEngine();
    var dic = new MyDictionary();
    engine.AddHostObject("dic", dic);

    engine.Execute("dic.Item.get(0);"); // works
    engine.Execute("dic.Item.get('name');"); // throws ScriptEngineException
    ```

    0 0

    Hello ClearScript,

    Two question about object design and purpose:

    1.) What the property AccessContext of the V8ScriptEngine is for? It looks promising but I can't see any usage of this at the moment.

    2.) Why the V8ScriptEngine Type has got a constructor with name? I can't see that I can use it anytime.

    With best regards,
    Torsten

    0 0

    Hi ClearScript,

    when I execute JavaScript code I have to add objects, types etc. before I call execute. The JavaScript code itself has not influence which objects or types are available.

    But what I want is that the JavaScript Code itself has got an option to define what objects / types etc. it needs an the runtime has the option to add it, like following pseudocode

    1st. the bootstrap

    ```
    using (var engine = new V8ScriptEngine())
    {
    engine.AddHostObject("using", MyApp.PackageManager);
    ... ' something what is additionally need
    engine.Execute(myscript);
    }
    ```

    2nd, the JavaScript

    ```
    using.AddType("System.Environment");

    var username = Enviroment.UserName;
    ```

    3rd, the "MyApp.PackageManager"

    ```
    static void AddType(string name)
    {
    _ V8ScriptEngine.Current.AddHostType(name);_
    }
    ```

    I know, there is no option like V8ScriptEngine.Current at the moment. But is there another way to do this?

    Best regards,
    Torsten

    0 0

    can this work inside a winRT "metro" C# application?

    0 0

    Add the nuget package for Clearscript V8 to a solution, build solution this completes with no errors.
    Remove folder packages\ClearScript.V8.5.3.10.0, build solution this restores and completes with no errors.

    remove V8 and replace with Clearscript without V8 dependancies.
    Remove the folder packages\ClearScript.5.3.8, now the build solution fails because package restores fails:

    Unable to find version '5.3.8' of package 'ClearScript'

    0 0

    can this work inside a winRT "metro" C# application?

    0 0

    Hi ClearScript,

    when I execute JavaScript code I have to add objects, types etc. before I call execute. The JavaScript code itself has not influence which objects or types are available.

    But what I want is that the JavaScript Code itself has got an option to define what objects / types etc. it needs an the runtime has the option to add it, like following pseudocode

    1st. the bootstrap

    ```
    using (var engine = new V8ScriptEngine())
    {
    engine.AddHostObject("using", MyApp.PackageManager);
    ... ' something what is additionally need
    engine.Execute(myscript);
    }
    ```

    2nd, the JavaScript

    ```
    using.AddType("System.Environment");

    var username = Enviroment.UserName;
    ```

    3rd, the "MyApp.PackageManager"

    ```
    static void AddType(string name)
    {
    _ V8ScriptEngine.Current.AddHostType(name);_
    }
    ```

    I know, there is no option like V8ScriptEngine.Current at the moment. But is there another way to do this?

    Best regards,
    Torsten

    0 0

    Hello ClearScript,

    Two question about object design and purpose:

    1.) What the property AccessContext of the V8ScriptEngine is for? It looks promising but I can't see any usage of this at the moment.

    2.) Why the V8ScriptEngine Type has got a constructor with name? I can't see that I can use it anytime.

    With best regards,
    Torsten

    0 0

    Add the nuget package for Clearscript V8 to a solution, build solution this completes with no errors.
    Remove folder packages\ClearScript.V8.5.3.10.0, build solution this restores and completes with no errors.

    remove V8 and replace with Clearscript without V8 dependancies.
    Remove the folder packages\ClearScript.5.3.8, now the build solution fails because package restores fails:

    Unable to find version '5.3.8' of package 'ClearScript'

    0 0

    Overhauled ClearScriptV8 string usage to fix Issue #42 and improve performance.

    0 0

    Ron,

    The fix is now available.

    Thanks again!

    0 0

    Hi, sorry for taking so long to come back to this - I had to spend a couple of weeks on something else and didn't get back to this office. It looks like that has cured the problem. Will test further and update.

    thanks very much
    Simon

    0 0

    Thanks for following up, Simon! Please let us know if you run into further issues.

    0 0

    Hi,

    While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:

    ```
    #
    # Fatal error in heap setup
    # Allocation failed - process out of memory
    #
    ```

    ```
    class Program
    {
    static void Main(string[] args)
    {
    for (int i = 0; i < 1000; i++)
    {
    using (V8ScriptEngine engine = new V8ScriptEngine())
    {
    Console.WriteLine("Created engine #{0}", i);
    engine.Execute("function zz(){}");
    var tmp = engine.Evaluate("zz");
    }
    }
    }
    }
    ```


    Strangely, the memory usage doesn't seem high when it terminates.

    I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.

    Any help will be greatly appreciated.
    Thanks in advance again,
    Ron


    0 0

    Hi,

    While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:

    ```
    #
    # Fatal error in heap setup
    # Allocation failed - process out of memory
    #
    ```

    ```
    class Program
    {
    static void Main(string[] args)
    {
    for (int i = 0; i < 1000; i++)
    {
    using (V8ScriptEngine engine = new V8ScriptEngine())
    {
    Console.WriteLine("Created engine #{0}", i);
    engine.Execute("function zz(){}");
    var tmp = engine.Evaluate("zz");
    }
    }
    }
    }
    ```


    Strangely, the memory usage doesn't seem high when it terminates.

    I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.

    Any help will be greatly appreciated.
    Thanks in advance again,
    Ron

    Comments: Hi Ron, ``` C# var tmp = engine.Evaluate("zz"); ``` This statement acquires a script object, and even though the script engine is disposed immediately thereafter, the corresponding unmanaged V8 runtime cannot be destroyed until the script object is also disposed or finalized. In most cases this is no big deal; the garbage collector eventually finalizes the script object and the V8 runtime is destroyed. The problem here is that the code creates additional V8 runtimes in a tight loop. V8 reserves a large block of address space for each one and quickly fills up your 32-bit process before the garbage collector can do its job. The result is a process that cannot allocate memory even though relatively little is actually in use. The solution is to dispose all managed references to the V8 runtime explicitly. Consider coding your loop body as follows: ``` C# using (V8ScriptEngine engine = new V8ScriptEngine()) { Console.WriteLine("Created engine #{0}", i); engine.Execute("function zz(){}"); var tmp = engine.Evaluate("zz"); using (tmp as IDisposable) { // do something with tmp } } ``` Please let us know if this resolves your issue. Thank you!

    0 0

    Hi,

    While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:

    ```
    #
    # Fatal error in heap setup
    # Allocation failed - process out of memory
    #
    ```

    ```
    class Program
    {
    static void Main(string[] args)
    {
    for (int i = 0; i < 1000; i++)
    {
    using (V8ScriptEngine engine = new V8ScriptEngine())
    {
    Console.WriteLine("Created engine #{0}", i);
    engine.Execute("function zz(){}");
    var tmp = engine.Evaluate("zz");
    }
    }
    }
    }
    ```


    Strangely, the memory usage doesn't seem high when it terminates.

    I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.

    Any help will be greatly appreciated.
    Thanks in advance again,
    Ron

    Comments: Hi, Thanks, your dispose addition resolves this problem! However, I think that in a realistic scenario it would not always be possible to dispose the script object at that time. Why isn't the script item disposed automatically when its engine/runtime is disposed? Surely it can't be used after that time. I also don't fully understand the problem. You wrote that "V8 reserves a large block of address space __for each one"__ but I'm creating a new engine each time. Does V8 keep a global block for all instances? I verified that I can create more than 50 script items per engine, so where exactly is this ~50 limit? I think it would be great if ClearScript would automatically take care of disposing all engine resources once the engine is disposed, especially for server scenarios where new engines may be created frequently. Thanks again, Ron

    0 0

    Hi,

    While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:

    ```
    #
    # Fatal error in heap setup
    # Allocation failed - process out of memory
    #
    ```

    ```
    class Program
    {
    static void Main(string[] args)
    {
    for (int i = 0; i < 1000; i++)
    {
    using (V8ScriptEngine engine = new V8ScriptEngine())
    {
    Console.WriteLine("Created engine #{0}", i);
    engine.Execute("function zz(){}");
    var tmp = engine.Evaluate("zz");
    }
    }
    }
    }
    ```


    Strangely, the memory usage doesn't seem high when it terminates.

    I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.

    Any help will be greatly appreciated.
    Thanks in advance again,
    Ron


older | 1 | .... | 30 | 31 | (Page 32) | 33 | 34 | .... | 115 | newer