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 | .... | 45 | 46 | (Page 47) | 48 | 49 | .... | 115 | newer

    0 0
  • 08/17/14--13:39: New Post: Scaling V8
  • Hi Shrainik,

    25000 Engines divided across 25 runtimes take up 11GB of memory.

    We've reproduced these numbers using a trivial native test program (no .NET, no ClearScript), so V8's implementation appears to be the cause.

    Since V8 runtimes don't support concurrent access, why keep a large number of engines (per runtime) in memory? If you're using them just to hold data, it might make sense to use regular data structures instead, moving data into a script engine only when necessary for script execution.

    Is there a way I can have multiple js contexts within a single engine (something like V8 isolates?)?

    ClearScript's V8 runtimes are based on V8 isolates, and they're quite expensive. A reasonable guideline for server applications is that you create one per pool thread, or roughly one per CPU core.

    In any case, if you're in control of the scripts you run and can ensure that they're well-behaved, you should be able to simulate multiple contexts by adopting simple rules about how data within the engine is organized and shared.

    Or what are other ways to reduce the memory usage?

    Holding fewer engines in memory is your best bet.

    Good luck!

    0 0

    Thank you as well.

    0 0

    hi,
    how can i implement an ActiveXObject class?
    i would add it as host-type

    0 0

    Hi furesoft,

    You could implement ActiveXObject as a dynamic object class (see DynamicObject and/or IDynamicMetaObjectProvider). That wouldn't be a trivial project, but it should be possible.

    We're working on something similar for the next ClearScript release (see here).

    Cheers!

    0 0
  • 08/28/14--00:58: New Post: validate js
  • how can i check if the given js is valid?

    0 0
  • 08/28/14--07:50: New Post: validate js
  • Hi furesoft,

    Consider using a JavaScript parsing library. Esprima is one that's written in JavaScript.

    Cheers!

    0 0
  • 08/29/14--12:55: New Post: vbs events
  • hi,
    how can i use events in vbs?

    0 0
  • 08/29/14--14:07: New Post: vbs events
  • Hi furesoft,

    Are you asking about handling .NET events in VBScript code running in ClearScript?

    Thanks!

    0 0
  • 08/30/14--02:08: New Post: vbs events
  • yes

    0 0
  • 08/30/14--07:22: New Post: vbs events
  • Hi again,

    Suppose you have a .NET class with an event:
    publicclass Foo {
        publicevent EventHandler SomethingHappened;
        publicvoid MakeSomethingHappen() {
            if (SomethingHappened != null)
                SomethingHappened(this, new EventArgs());
        }
    }
    Here's how you might handle the event in VBScript code:
    engine.AddHostObject("foo", new Foo());
    engine.AddHostType("Console", typeof(Console));
    engine.Execute(@"
        sub OnSomethingHappened(sender, args)
            Console.WriteLine(""Something just happened!"")
        end sub
        set connection = foo.SomethingHappened.connect(GetRef(""OnSomethingHappened""))
        foo.MakeSomethingHappen()
        connection.disconnect()
    ");
    Good luck!

    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: When I add ClearScriptV8-32.vcxproj or ClearScriptV8-64.vcxproj to my solution and try to build it, I get "cmd.exe" exited with code 1.

    0 0

    Is there a way to create a global "window" object. And has it been done already?

    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: Hello! Those project files assume the ClearScript solution directory structure and would require modification for standalone use or for inclusion in other solutions. Please see the ClearScript [ReadMe](https://clearscript.codeplex.com/SourceControl/latest#ReadMe.txt) for build instructions. Thanks!

    0 0

    Hi AndersBillLinden,

    ClearScript lets you expose any .NET object to the script engine. Do you already have an implementation for the object you require?

    Cheers!

    0 0

    Yes, I was exposing the window object like this:
    var engine = new V8ScriptEngine();
    engine.AddHostObject("window", new Window());
    Then I can have a class Window that looks like this:
    using System;
    
    namespace foo
    {
        public class Window
        {
            public void alert(string msg)
            {
                Console.WriteLine("alert: " + msg);
            }
        }
    }
    
    Now a script can use window.alert("foo") can it will come out on the console. What I need is to set the global object to window, so I can call just alert("foo"); from a script

    0 0

    Seems the forum translated my plus sign, however after I had written this comment, the plus sign was ok again

    0 0

    Not sure if it is possible in ClearScript but this is what i used

    var alert = window.alert;
    var prompt = window.prompt;
    var confirm = window.confirm;

    0 0
  • 09/01/14--17:50: New Post: validate js
  • Jint also has a .NET implementation of Esprima (I have written one myself too for an IDE). So you can also do the code validation in .NET.

    0 0

    Then I could of course just create some global functions and run the corresponding functions in the window object from them. But javascript has a global object, so if clearscript is a correct implementation, it should have one as well.

    0 0

    Hi AndersBillLinden,

    The global object is provided by the underlying script engine, and ClearScript does not allow you to replace it.

    However, ClearScript lets you expose a host object so that its members appear within the global namespace:
    engine.AddHostObject("window", HostItemFlags.GlobalMembers, new Window());
    engine.Execute("alert('hello')");
    Good luck!

older | 1 | .... | 45 | 46 | (Page 47) | 48 | 49 | .... | 115 | newer