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

Embed this content in your HTML


Report adult content:

click to rate:

Account: (login)

More Channels


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

    0 0
  • 08/06/14--06:36: New Post: Performance...
  • Thanks for posting that, UweKeim! Just to clarify, ClearScript's JScriptEngine class defaults to the JScript 5.7 feature set. Specifying WindowsScriptEngineFlags.EnableStandardsMode selects the JScript 5.8 feature set, which includes the JSON object.

    0 0

    Perhaps something like this:
    engine.AddHostObject("$", new DollarSignFunc((arg1, arg2) => {
        var name = arg1 asstring;
        if (name == null)
            new Window(f).AddEventHandler("Load", arg1);
        elseif (arg2 != null)
            new Window(f).AddEventHandler(name, arg2);
        else {
            // add code here
    As long as the calling pattern can be inferred from the arguments, you can support as many as you need.


    0 0
  • 08/06/14--07:03: New Post: Performance...
  • UweKeim/ClearScript -

    Thank you for the detailed information. This will really help!


    0 0

    thanks it works

    0 0
  • 08/06/14--10:19: New Post: get js of function
  • is it possible to get the source of an js function via js?

    0 0

    how is it possible to implement an uneval function?

    0 0
  • 08/06/14--12:43: New Post: get js of function
  • Sure, take a look at Function.prototype.toString().

    0 0

    Perhaps you could start with JSON.stringify() and incorporate Function.prototype.toString()?

    0 0

    i would like to implement it in c# as a function for js

    0 0

    Hi furesoft,

    You can use DynamicObject.GetDynamicMemberNames() to enumerate the properties of a script object.

    However, you'll have to invoke script functions to retrieve various information such as function source code, whether an object is a function, whether one object is the same as another (for cycle detection), etc. A full uneval() implementation without the script engine's help may not be possible.

    Consider also that script invocations are expensive, whereas uneval() can be implemented fully in JavaScript without any hops across the host-script boundary.

    Good luck!

    0 0
  • 08/07/14--11:41: New Post: ecmascript 6
  • when is it possible to use ecmascript 6 implementation?

    0 0
  • 08/07/14--12:36: New Post: ecmascript 6
  • Hi furesoft,

    We have no plan to explicitly enable Harmony support while it's in development. Presumably the V8 team will enable Harmony features by default sometime after the standard is finalized and V8's implementation of the standard is complete.

    Thanks for your question!

    0 0

    Is it possible to serialize a compiled script? For instance do something like:
    byte[] result = null;
    using (var clearscriptV8 = new V8Runtime())
    using (var stream = new MemoryStream())
        var compiled = clearscriptV8.Compile(jsCode);
        var formatter = new BinaryFormatter();
        formatter.Serialize(stream, compiled);
        stream.Position = 0;
        result = stream.ToArray();
    and then at some point later on deserialize it and call a function within the script?
    V8Script compiledScript;
    using (var stream = new MemoryStream(serializedScript))
        var formatter = new BinaryFormatter();
        stream.Seek(0, SeekOrigin.Begin);
        compiledScript = formatter.Deserialize(stream) as V8Script;
    using (var engine = new V8ScriptEngine(V8ScriptEngineFlags.DisableGlobalMembers))
        return engine.Script.MyMethod(new { Something=true }) as IEnumerable<Result>;

    0 0


    Unfortunately V8Script instances are not serializable. More information here.


    0 0

    Is this something that can be changed in ClearScript or is it a limitation of V8?

    0 0

    its a limitation of .net

    0 0

    Hi again,

    V8 doesn't support serialization of compiled scripts, but it does have a somewhat similar feature that ClearScript currently doesn't leverage.

    In V8, script compilation optionally produces a binary artifact that supports offline storage and can be used to speed up the recompilation of the same script. This data could be combined with the original script code to produce a single object that supports standard .NET serialization and can reconstitute the compiled script faster than normal compilation.

    Support for this feature is on our long-term to-do list.


    0 0


    i have a memory problem and i don't know if it is due to a wrong usage or a problem in the engine.
    When I use the V8 engine a long time with many JS-calls from C#:
    using (var compiledFunction = m_Engine.Compile(function))
        var result = m_Engine.Evaluate(compiledFunction);
        Log.Debug("Result of function '" + function + "': " + result);
    (also tried: engine.Execute(function);)
    and many calls from JS to C# through an object I attached to engine.Script
    engine.Script["nameOfObject"] = theObject;
    (also tried: engine.AddHostObject("nameOfObject", theObject);)
    the memory usage is increasing constantly.
    I used DebugDiag2 to see what could cause that problem. Most of the memory is allocated by v8_x64.dll
    Module Name   v8_x64 
    Allocation Count   466 allocation(s) 
    Allocation Size   1.02 GBytes 
    Function details
    Function   v8_x64!v8::Testing::DeoptimizeAll+109ccd 
    Source Line    
    Allocation type   Virtual memory allocation(s) 
    Allocation Count   460 allocation(s) 
    Allocation Size   530.3 MBytes 
    Leak Probability   84% 
    and here is a call stack sample
    Call stack sample 3
    Address   0x00000000`22000000 
    Allocation Time   14:43:09 since tracking started 
    Allocation Size   8.02 MBytes 
    Do you see something what I am doing wrong or do you have some hints what else I can try?

    0 0

    Hello querdenker,

    It doesn't look like you're doing anything wrong. Can you say any more about the sort of work your scripts are doing?

    Some general suggestions:‚Äč
    • Make sure you're using the latest version of ClearScript. A number of memory leaks have been fixed since the last point release.
    • Is it possible that your scripts are generating increasing amounts of data that is reachable from the global/root object?
    • Try to avoid script compilation as much as possible. Consider using compiled scripts or direct invocation of script functions to re-execute script code.
    • We've found that when it comes to garbage collection, V8 is lazy to an extent that can get it in trouble. Consider invoking the garbage collector explicitly via ScriptEngine.CollectGarbage(true). Use a schedule that makes sense for your application - periodically or based on idle state, maximum invocation count, etc.
    • If all else fails, consider disposing the script engine and spinning up a fresh instance once in a while - again, using a schedule that makes sense for you.
    Good luck!

    0 0

    Is there any support for parallelism or web workers in clearscript? I would like to do parallel processing within my javascript code instead of having .net facilitate it because of the overhead of creating the engine in each thread.

    Do you have a roadmap you can share? If this isn't on it will you consider adding it?

older | 1 | .... | 43 | 44 | (Page 45) | 46 | 47 | .... | 115 | newer