Quantcast
Channel: ClearScript
Viewing all 2297 articles
Browse latest View live

New Post: Enable Experimental JavaScript

$
0
0
Hello!

You'd have to make a small source code change and rebuild ClearScript.

For example, adding the following lines at the top of the V8IsolateImpl constructor should enable JavaScript proxies:
std::string flags("--harmony-proxies");
V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.length()));
Good luck!

New Post: Does ClearScript have memory leak?

$
0
0
Hi JerryBian,

We looked at your code and ran some tests; here's what we found.

  1. You're using an old ClearScript version. Several issues related to memory usage have been fixed recently.
  2. There doesn't appear to be a memory leak in the latest ClearScript code. That is, all host objects released by V8's garbage collector are eventually claimed by the CLR garbage collector.
  3. However, the current implementation of V8ScriptEngine.CollectGarbage(true) is not exhaustive. Contrary to its documentation, the underlying V8 API defers cleanup in many cases. This is a problem in general, but it's particularly devastating when the unclaimed V8 objects are actually proxies to very large host objects. This issue may account for what you're seeing in dotMemory.
We're close to releasing the next version of ClearScript, which includes a much more aggressive implementation of V8ScriptEngine.CollectGarbage(true).

Use global ScriptEngine instance or create one each time in our scenario?

Given the usage pattern you described, we recommend that you create and dispose engine instances as necessary. However, if the overhead of doing so impacts your server's scalability, you might consider a different strategy, such as engine instance pooling.

For example, if all the input scripts are same, ClearScript will cache the only one copy in memory to increase performance or cache every scripts? Do we need to cache it by ourselves?

If you're using a single V8ScriptEngine instance to execute a given script repeatedly, you could gain a significant performance boost by compiling the script via V8ScriptEngine.Compile(). Another possibility might be to invoke script functions that are already stored within the engine. The idea is to avoid the script parser if possible.

What's the next release plan, we don't want to compile source code by ourselves?

The next version should be out shortly, hopefully by the end of this week or early next week. However, we don't release binaries, so you'll have to build it or acquire binaries elsewhere.

Good luck!

New Post: How C#-Js binding is implemented?

$
0
0
Hello,

First of all let me tell you that it's a great project.

I'm playing now with the Chromium Embedded Framework to create an application that contains both C# and HTML+JS code. I want to implement some kind of dependency injection, so that I could replace JS code with C#.

I want to get inspired by going trough and understanding your code, how you have implemented the seamless binding you provide, e.g. host objets, ... (it'd be a great starting point for me because Chromium uses V8 under the hood just like you do)

If you could give me advice where to look at in the code, where can I find detailed documentation, that'd be appreciated.

Thanks in advance
Balazs

New Post: How C#-Js binding is implemented?

$
0
0
Hello Balazs,

Thanks for your kind words! Unfortunately there's no detailed documentation beyond the code itself.

ClearScript's V8 binding consists of several layers. The best way to understand it is to follow a code path from V8 to a target host object. Some tools you might find helpful are ClearScriptConsole, which provides a script command line with access to the core .NET class library, and the Visual Studio debugger, which lets you step through both native and managed code in the same process.

Here are some notes to get you started.

Interception is the key V8 mechanism that enables host object access from script code. A script talks to a host object through a native JavaScript proxy that invokes native ClearScript callbacks for all property access. You can find the callback methods in the V8ContextImpl class; e.g., GetHostObjectProperty(), SetHostObjectProperty(), etc.

If you set a breakpoint there, you can step through the code as it makes its way to the managed side and eventually ends up in HostItem, the managed wrapper for all exposed host resources. HostItem then fulfills the request using a variety of APIs such as reflection, the C# Runtime Binder, the .NET dynamic infrastructure, COM interop, etc. It has a lot of plumbing to handle a variety of binding scenarios.

Good luck, and please let us know if you have more questions!

New Post: How to use System.Linq.Expressions.Expression ...

$
0
0
How can I do something like this using clearscript ....
at runtime i only know what T will be ... not during compile time ...
public virtual List<T> FindBy(System.Linq.Expressions.Expression<Func<T, bool>> predicate)

New Post: How to use System.Linq.Expressions.Expression ...

$
0
0
Hello iwcoetzer,

Please clarify. What do you mean by "do something like this using ClearScript"?

Do you need to call this method from script code? If so, how are you defining the predicate?

Thanks!

New Post: Visual Studio 2013 cannot load assembly Microsoft.ClearScript.Windows.VBScriptEngine

$
0
0
Hello, I can't find any help for this error. I installed ClearScript from the NuGet Package Manager console using Install-Package ClearScript. I see messages informing me 'ClearScript 5.3.11.0' installed successfully.

I then tried to create a simple test project that instantiated the VBScriptEngine object using the following:
    public class ClearScriptEngine
    {
       private readonly VBScriptEngine _engine;

       public ClearScriptEngine()
       {
          _engine = new VBScriptEngine();
       }
    } 
When running, I receive this exception:
"Could not load type 'Microsoft.ClearScript.Windows.VBScriptEngine' from assembly 'ClearScript, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.":"Microsoft.ClearScript.Windows.VBScriptEngine"

Anyone know how to fix this? Is there a setting I'm missing? Again, the only setup I performed was installing from NuGet Package Manager.

I'm running Visual Studio Premium 2013. Version 12.0.30723.00 Update 3. .NET Framework Version 4.5.51641.

New Post: Visual Studio 2013 cannot load assembly Microsoft.ClearScript.Windows.VBScriptEngine

$
0
0
Greetings!

It looks like you're using this NuGet package. Generally, as we don't release ClearScript binaries, we recommend that NuGet package issues be reported to the package owners.

That said, we did run a quick test with this package, adding it to a command-line test application and successfully executing a few lines of VBScript code.

Can you give us any more details on the exception you're seeing? If you can share your test project, or the relevant portions of it, that could be very helpful as well.

Thanks!

New Post: Visual Studio 2013 cannot load assembly Microsoft.ClearScript.Windows.VBScriptEngine

$
0
0
Thanks for the quick reply!

I decided to delete everything and then use the zip download from here to build my ClearScript assembly using the Non-V8 solution. I'm still receiving the same exception:

{"Could not load type 'Microsoft.ClearScript.Windows.VBScriptEngine' from assembly 'ClearScript, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.":"Microsoft.ClearScript.Windows.VBScriptEngine"}

The issue occurs as soon as I try to instantiate my object wrapping the VBScriptEngine.

Here is a link to a zip file of my test solution. The solution is pretty straight forward. Two projects, one is a class assembly to wrap ClearScript interaction, the other is a XAML project. The class assembly has one class in it called ClearScriptEngine. When the XAML project tries to instantiate the ClearScriptEngine class, the exception above is thrown and XAML wraps it with a XAML parse exception.

ClearScript Test Solution

Thanks!

New Post: Visual Studio 2013 cannot load assembly Microsoft.ClearScript.Windows.VBScriptEngine

$
0
0
Hi again!

Thanks for sharing your solution.

The problem seems to be that your solution includes a class library project that generates "ClearScript.dll", which conflicts with the ClearScript assembly of the same name in the output directory.

Try changing the name of your assembly:
  1. Right-click your class library project and select "Properties".
  2. Change the assembly name from "ClearScript" to "ClearScriptLibrary" or something like that.
  3. Click "File" -> "Save All"
  4. Rebuild your solution.
Good luck!

New Post: Visual Studio 2013 cannot load assembly Microsoft.ClearScript.Windows.VBScriptEngine

$
0
0
I am so sorry to waste your time. That is such a rookie mistake, I almost feel shame :). It would help if .NET gave a more descript error. Sometimes you just need that extra perspective.

New Post: Using List and Linq withing javascript

$
0
0
Hello,

I am wondering if we are allowed to used linq functions like List.Exists within javascript.

Currently, I have this line
if (child.Name == "tr" && accountList.Exists(p => p == child.ChildNodes[1].InnerText)) 
{ }
But it's giving me a syntax error. accountList is passed in through
 engine.Script[key] = value; 
where key = "accountList" and the value is a List<string>

Is this something I can do, or do I have to do things the old fashioned way?

New Post: Build bug found for Visual Studio 2010

$
0
0
FYI- So far, there doesn't seem to be any issues.

New Post: Visual Studio 2013 cannot load assembly Microsoft.ClearScript.Windows.VBScriptEngine

$
0
0
No worries! Actually, we really should adopt the common convention of using the base namespace name for the assembly name; e.g., "Microsoft.ClearScript.dll". That would have prevented your issue as well. Thanks again!

New Post: Using List and Linq withing javascript

$
0
0
Hello!

The method you're trying to call from script code is declared like this:
publicbool Exists(Predicate<T> match)
Because you're dealing with a string list, it requires an argument of type Predicate<string>, which is a delegate type.

The syntax p => p == child.ChildNodes[1].InnerText is C#-specific and not legal in JavaScript. Instead, you need to create the appropriate delegate around a script function.

To do that, first you need to expose the delegate type to the script engine:
engine.AddHostType("StrPred", typeof(Predicate<string>));
Now you can call the method from script code like this:
pred = function (p) { return p == child.ChildNodes[1].InnerText; };
exists = accountList.Exists(new StrPred(pred));
Good luck!

Updated Wiki: Announcements

$
0
0

10/22/2014: ClearScript 5.4 released.

View the release notes and download the source code here.

1/16/2014: Version 5.3.11 released.

View the release notes and download the source code here.

11/28/2013: Version 5.3.10 released.

View the release notes and download the source code here.

10/29/2013: Version 5.3.9 released.

View the release notes and download the source code here.

10/14/2013: Version 5.3.8 released.

View the release notes and download the source code here.

8/22/2013: Version 5.3.7 released.

View the release notes and download the source code here.

8/14/2013: Version 5.3.6 released.

View the release notes and download the source code here.

8/2/2013: Version 5.3.5 released.

View the release notes and download the source code here.

7/10/2013: Version 5.3.4 released.

View the release notes and download the source code here.

7/2/2013: Version 5.3.3 released.

View the release notes and download the source code here.

6/6/2013: Version 5.3.2 released.

View the release notes and download the source code here. Due to issues with several recent V8 trunk releases (build failures, breaking API changes, etc.), and because more breaking changes are coming soon, this release modifies V8Update so that it fetches a tested, known-good V8 revision by default. See the ClearScript ReadMe for more information.

5/31/2013: Version 5.3.1 released.

View the release notes and download the source code here.

5/21/2013: ClearScript 5.3 released.

View the release notes and download the source code here.

5/15/2013: Version 5.2.2 released.

View the release notes and download the source code here. This release addresses the build issue reported yesterday and can be used with the latest V8 version. Here's how to update your copy of V8:
C:\ClearScript> set V8REV=
C:\ClearScript> V8Update

5/14/2013: ClearScript build failure due to API deprecation in V8 3.19.1.

We are aware of a ClearScript build issue with the latest version of V8. Until this issue is resolved we recommend that you explicitly use V8 3.19.0:
C:\ClearScript> set V8REV=14604
C:\ClearScript> V8Update

5/2/2013: Version 5.2.1 released.

View the release notes and download the source code here.

4/18/2013: V8Update failure resolved by V8 3.18.1.

The V8Update issue reported yesterday has been fixed by a new version of V8 released today. Here's how to update to the latest V8 version:
C:\ClearScript> set V8REV=
C:\ClearScript> V8Update

4/17/2013: V8Update failure with V8 3.18.0.

We are aware of a V8Update issue with the latest version of V8. Until this issue is resolved we recommend that you explicitly use V8 3.17.16:
C:\ClearScript> set V8REV=14138
C:\ClearScript> V8Update

3/27/2013: ClearScript 5.2 released.

View the release notes and download the source code here.

3/8/2013: Version 5.1.3 released.

View the release notes and download the source code here.

3/4/2013: V8Update failure resolved by V8 3.17.7.

The V8Update issue reported earlier has been fixed by a new version of V8 released today. Here's how to update to the latest V8 version:
C:\ClearScript> set V8REV=
C:\ClearScript> V8Update

3/4/2013: V8Update failure with V8 3.17.6.

We are aware of a V8Update issue with the latest version of V8. The issue affects the "Building 64-bit V8" step. The V8 team appears to have already submitted a fix, but the fix has not yet been merged into the trunk. In the meantime, we recommend that you explicitly use V8 3.17.5:
C:\ClearScript> set V8REV=13745
C:\ClearScript> V8Update

Updated Wiki: Home

$
0
0
InfoIcon.jpgClearScript 5.4 released. More...

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.

Features

  • Simple usage; create a script engine, add your objects and/or types, run scripts
  • Support for several script engines: Google's V8, Microsoft's JScript and VBScript
  • Exposed resources require no modification, decoration, or special coding of any kind
  • Scripts get simple access to most of the features of exposed objects and types:
    • Methods, properties, fields, events
    • (Objects) Indexers, extension methods, conversion operators, explicitly implemented interfaces
    • (Types) Constructors, nested types
  • Full support for generic types and methods, including C#-like type inference and explicit type arguments
  • Scripts can invoke methods with output parameters, optional parameters, and parameter arrays
  • Script delegates enable callbacks into script code
  • Support for exposing all the types defined in one or more assemblies in one step
  • Optional support for importing types and assemblies from script code
  • The host can invoke script functions and access script objects directly
  • Full support for script debugging

Examples

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

// create a script engineusing (var engine = new V8ScriptEngine())
{
    // expose a host type
    engine.AddHostType("Console", typeof(Console));
    engine.Execute("Console.WriteLine('{0} is an interesting number.', Math.PI)");

    // expose a host object
    engine.AddHostObject("random", new Random());
    engine.Execute("Console.WriteLine(random.NextDouble())");

    // expose entire assemblies
    engine.AddHostObject("lib", new HostTypeCollection("mscorlib", "System.Core"));
    engine.Execute("Console.WriteLine(lib.System.DateTime.Now)");

    // create a host object from script
    engine.Execute(@"
        birthday = new lib.System.DateTime(2007, 5, 22);
        Console.WriteLine(birthday.ToLongDateString());
    ");

    // use a generic class from script
    engine.Execute(@"
        Dictionary = lib.System.Collections.Generic.Dictionary;
        dict = new Dictionary(lib.System.String, lib.System.Int32);
        dict.Add('foo', 123);
    ");

    // call a host method with an output parameter
    engine.AddHostObject("host", new HostFunctions());
    engine.Execute(@"
        intVar = host.newVar(lib.System.Int32);
        found = dict.TryGetValue('foo', intVar.out);
        Console.WriteLine('{0} {1}', found, intVar);
    ");

    // create and populate a host array
    engine.Execute(@"
        numbers = host.newArr(lib.System.Int32, 20);
        for (var i = 0; i < numbers.Length; i++) { numbers[i] = i; }
        Console.WriteLine(lib.System.String.Join(', ', numbers));
    ");

    // create a script delegate
    engine.Execute(@"
        Filter = lib.System.Func(lib.System.Int32, lib.System.Boolean);
        oddFilter = new Filter(function(value) {
            return (value & 1) ? true : false;
        });
    ");

    // use LINQ from script
    engine.Execute(@"
        oddNumbers = numbers.Where(oddFilter);
        Console.WriteLine(lib.System.String.Join(', ', oddNumbers));
    ");

    // use a dynamic host object
    engine.Execute(@"
        expando = new lib.System.Dynamic.ExpandoObject();
        expando.foo = 123;
        expando.bar = 'qux';
        delete expando.foo;
    ");

    // call a script function
    engine.Execute("function print(x) { Console.WriteLine(x); }");
    engine.Script.print(DateTime.Now.DayOfWeek);

    // examine a script object
    engine.Execute("person = { name: 'Fred', age: 5 }");
    Console.WriteLine(engine.Script.person.name);
}

Edited Feature: COM object projection [38]

$
0
0
Script code currently cannot invoke COM interface methods on exposed RCWs. This is an issue because the OS includes many useful COM objects. Besides, if it implements IDispatch, it should be scriptable, period.

Commented Feature: COM object projection [38]

$
0
0
Script code currently cannot invoke COM interface methods on exposed RCWs. This is an issue because the OS includes many useful COM objects. Besides, if it implements IDispatch, it should be scriptable, period.
Comments: Fixed in [ClearScript 5.4](https://clearscript.codeplex.com/releases/view/135637).

Edited Issue: Fatal error in heap setup, Allocation failed - process out of memory [44]

$
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

Viewing all 2297 articles
Browse latest View live




Latest Images