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

Created Unassigned: Allow custom locations in V8Proxy.GetDirPaths [34]

$
0
0
I am bundling the ClearScript DLLs as embedded resources in my main application/dll. At runtime I extract ClearScriptV8-XX.dll and v8-xXX.dll to a temporary path (typically Temporary ASP.NET Files) so that they can be loaded from disk.

In order to support this I have added a simple static API which allows adding custom locations returned by V8Proxy.GetDirPaths. It would be ideal if some equivalent functionality were included in the library.

This issue is somewhat related to https://clearscript.codeplex.com/workitem/17

Edited Issue: [V8 bug] Issue with memory leaking scripts: 5.3.9 vs 5.3.10 [32]

$
0
0
Hi everybody,

I just noticed a behavior that differs between ClearScript v 5.3.9 and 5.3.10, and it's about limiting memory for a script execution. Consider following faulty script (it emulates a memory leak) being executed inside the 64 bit console application:
```
var sample_arr = [-1, 5, 7, 4, 0, 1, -5]
function My_Partition(container, first_index, last_index) {
var x = container[last_index];
var i = first_index - 1;

for (var elem = 0; elem < container.length-1; elem++) {
if (container[elem] <= x) {
i += 1;
var temp_1 = container[i];
container[i] = container[elem];
container[elem] = temp_1;
}
}
var temp_2 = container[i+1];
container[i+1] = container[last_index];
container[last_index] = temp_2;

return i+1;
}
function My_Quick_Sort(container, first_index, last_index) {
if (first_index < last_index) {
var mid = My_Partition(container, first_index, last_index);
My_Quick_Sort(container, first_index, mid-1);
My_Quick_Sort(container, mid+1, last_index);
}
}
My_Quick_Sort(sample_arr, 0, sample_arr.length-1);
console.WriteLine("Sorted Array:", sample_arr);
```
as well as following ClearScript's V8 engine configuration:
```
Using engine As New V8ScriptEngine("V8Engine", New V8RuntimeConstraints() With {.MaxOldSpaceSize = 209715200}, V8ScriptEngineFlags.EnableDebugging, 9222)
```
You'll notice that after running above code in 5.3.9 it gracefully ends up with an exception that indicates a memory limit being exceeded (see attachment). However, in 5.3.10 it doesn't result in exception and rather hard-crashes with a message in the console (see attachment). Could you test it on your end and provide some follow-up?

System used for testing: Window 7, 64 bit.

Thanks for your work,
Max

Commented Issue: [V8 bug] Issue with memory leaking scripts: 5.3.9 vs 5.3.10 [32]

$
0
0
Hi everybody,

I just noticed a behavior that differs between ClearScript v 5.3.9 and 5.3.10, and it's about limiting memory for a script execution. Consider following faulty script (it emulates a memory leak) being executed inside the 64 bit console application:
```
var sample_arr = [-1, 5, 7, 4, 0, 1, -5]
function My_Partition(container, first_index, last_index) {
var x = container[last_index];
var i = first_index - 1;

for (var elem = 0; elem < container.length-1; elem++) {
if (container[elem] <= x) {
i += 1;
var temp_1 = container[i];
container[i] = container[elem];
container[elem] = temp_1;
}
}
var temp_2 = container[i+1];
container[i+1] = container[last_index];
container[last_index] = temp_2;

return i+1;
}
function My_Quick_Sort(container, first_index, last_index) {
if (first_index < last_index) {
var mid = My_Partition(container, first_index, last_index);
My_Quick_Sort(container, first_index, mid-1);
My_Quick_Sort(container, mid+1, last_index);
}
}
My_Quick_Sort(sample_arr, 0, sample_arr.length-1);
console.WriteLine("Sorted Array:", sample_arr);
```
as well as following ClearScript's V8 engine configuration:
```
Using engine As New V8ScriptEngine("V8Engine", New V8RuntimeConstraints() With {.MaxOldSpaceSize = 209715200}, V8ScriptEngineFlags.EnableDebugging, 9222)
```
You'll notice that after running above code in 5.3.9 it gracefully ends up with an exception that indicates a memory limit being exceeded (see attachment). However, in 5.3.10 it doesn't result in exception and rather hard-crashes with a message in the console (see attachment). Could you test it on your end and provide some follow-up?

System used for testing: Window 7, 64 bit.

Thanks for your work,
Max

Comments: V8 bug [here](https://code.google.com/p/v8/issues/detail?id=3060).

Edited Feature: Allow custom locations in V8Proxy.GetDirPaths [34]

$
0
0
I am bundling the ClearScript DLLs as embedded resources in my main application/dll. At runtime I extract ClearScriptV8-XX.dll and v8-xXX.dll to a temporary path (typically Temporary ASP.NET Files) so that they can be loaded from disk.

In order to support this I have added a simple static API which allows adding custom locations returned by V8Proxy.GetDirPaths. It would be ideal if some equivalent functionality were included in the library.

This issue is somewhat related to https://clearscript.codeplex.com/workitem/17

Commented Feature: Allow custom locations in V8Proxy.GetDirPaths [34]

$
0
0
I am bundling the ClearScript DLLs as embedded resources in my main application/dll. At runtime I extract ClearScriptV8-XX.dll and v8-xXX.dll to a temporary path (typically Temporary ASP.NET Files) so that they can be loaded from disk.

In order to support this I have added a simple static API which allows adding custom locations returned by V8Proxy.GetDirPaths. It would be ideal if some equivalent functionality were included in the library.

This issue is somewhat related to https://clearscript.codeplex.com/workitem/17
Comments: Hi jbrantly, When you get a chance, please take a look at the latter part of [this thread](https://clearscript.codeplex.com/discussions/471622). Do you think the proposed assembly resolver hook will suffice in your scenario?

Commented Feature: Allow custom locations in V8Proxy.GetDirPaths [34]

$
0
0
I am bundling the ClearScript DLLs as embedded resources in my main application/dll. At runtime I extract ClearScriptV8-XX.dll and v8-xXX.dll to a temporary path (typically Temporary ASP.NET Files) so that they can be loaded from disk.

In order to support this I have added a simple static API which allows adding custom locations returned by V8Proxy.GetDirPaths. It would be ideal if some equivalent functionality were included in the library.

This issue is somewhat related to https://clearscript.codeplex.com/workitem/17
Comments: If the proposed hook is added prior to the LoadNativeLibrary() call then I believe that would work (and I'll just do my own LoadLibrary for v8). The point just being that the proposed hook specifically addresses loading the mixed-mode assembly but not necessarily the v8 native library.

Commented Feature: Allow custom locations in V8Proxy.GetDirPaths [34]

$
0
0
I am bundling the ClearScript DLLs as embedded resources in my main application/dll. At runtime I extract ClearScriptV8-XX.dll and v8-xXX.dll to a temporary path (typically Temporary ASP.NET Files) so that they can be loaded from disk.

In order to support this I have added a simple static API which allows adding custom locations returned by V8Proxy.GetDirPaths. It would be ideal if some equivalent functionality were included in the library.

This issue is somewhat related to https://clearscript.codeplex.com/workitem/17
Comments: Yes, the hook would be invoked before the current loading process takes place. Also, the V8 DLL is a dependency of the mixed-mode assembly, so unless you're extracting them to different directories, loading the mixed-mode assembly should automatically bring in the native DLL.

Commented Feature: Allow custom locations in V8Proxy.GetDirPaths [34]

$
0
0
I am bundling the ClearScript DLLs as embedded resources in my main application/dll. At runtime I extract ClearScriptV8-XX.dll and v8-xXX.dll to a temporary path (typically Temporary ASP.NET Files) so that they can be loaded from disk.

In order to support this I have added a simple static API which allows adding custom locations returned by V8Proxy.GetDirPaths. It would be ideal if some equivalent functionality were included in the library.

This issue is somewhat related to https://clearscript.codeplex.com/workitem/17
Comments: I may be missing something, but V8Proxy specifically invokes LoadLibraryW to bring in the V8 DLL (using paths given by GetDirPaths). Are you saying that is not needed? Keep in mind that in my case GetDirPaths would *not* return a valid path to the v8 DLL. To be clear, in my case: ClearScript.dll - Loaded from memory using Assembly.Load(byte[]) ClearScriptV8-64.dll - Loaded from disk in a temporary folder v8-x64.dll - Loaded from disk in a temporary folder GetDirPaths does return the location of the ClearScript.dll but in my case that is not valid since I'm loading from memory.

Commented Feature: Allow custom locations in V8Proxy.GetDirPaths [34]

$
0
0
I am bundling the ClearScript DLLs as embedded resources in my main application/dll. At runtime I extract ClearScriptV8-XX.dll and v8-xXX.dll to a temporary path (typically Temporary ASP.NET Files) so that they can be loaded from disk.

In order to support this I have added a simple static API which allows adding custom locations returned by V8Proxy.GetDirPaths. It would be ideal if some equivalent functionality were included in the library.

This issue is somewhat related to https://clearscript.codeplex.com/workitem/17
Comments: >V8Proxy specifically invokes LoadLibraryW to bring in the V8 DLL (using paths given by GetDirPaths). Are you saying that is not needed? ​ That's correct; in most cases it isn't needed because the two files are in the same place. V8Proxy does what it does to provide optional support for separate placement, which is very unusual. In your case, if you extract both files into the same temporary folder, your assembly resolution handler will just have to load ClearScriptV8-64.dll. The system will automatically bring in the native V8 DLL and its dependencies, and ClearScript's default loading procedure will be skipped.

Commented Feature: Allow custom locations in V8Proxy.GetDirPaths [34]

$
0
0
I am bundling the ClearScript DLLs as embedded resources in my main application/dll. At runtime I extract ClearScriptV8-XX.dll and v8-xXX.dll to a temporary path (typically Temporary ASP.NET Files) so that they can be loaded from disk.

In order to support this I have added a simple static API which allows adding custom locations returned by V8Proxy.GetDirPaths. It would be ideal if some equivalent functionality were included in the library.

This issue is somewhat related to https://clearscript.codeplex.com/workitem/17
Comments: Gotcha. I didn't realize that was the case. That route sounds good to me! Also, as a side note, thanks for ClearScript and your excellent dev relations. I follow the project somewhat and your response times and willingness to help are second to none.

Commented Feature: Allow custom locations in V8Proxy.GetDirPaths [34]

$
0
0
I am bundling the ClearScript DLLs as embedded resources in my main application/dll. At runtime I extract ClearScriptV8-XX.dll and v8-xXX.dll to a temporary path (typically Temporary ASP.NET Files) so that they can be loaded from disk.

In order to support this I have added a simple static API which allows adding custom locations returned by V8Proxy.GetDirPaths. It would be ideal if some equivalent functionality were included in the library.

This issue is somewhat related to https://clearscript.codeplex.com/workitem/17
Comments: Thank you very much! Being able to interact productively with individual developers is one of the nice things about maintaining a small project like this.

Commented Feature: Allow custom locations in V8Proxy.GetDirPaths [34]

$
0
0
I am bundling the ClearScript DLLs as embedded resources in my main application/dll. At runtime I extract ClearScriptV8-XX.dll and v8-xXX.dll to a temporary path (typically Temporary ASP.NET Files) so that they can be loaded from disk.

In order to support this I have added a simple static API which allows adding custom locations returned by V8Proxy.GetDirPaths. It would be ideal if some equivalent functionality were included in the library.

This issue is somewhat related to https://clearscript.codeplex.com/workitem/17
Comments: I was able to test this today. I modified V8Proxy.LoadAssembly(): private static void LoadAssembly() { try { assembly = Assembly.Load("ClearScriptV8"); return; } catch (FileNotFoundException) { } if (LoadNativeLibrary()) ..... Using AssemblyResolve I was able to load ClearScriptV8 and, as you said, it automatically loaded the v8 native DLL and the test passed. Good stuff.

New Post: Passing javascript objects to c# native code

$
0
0
I am currently trying to pass a js array to a C# method.


Engine.AddHostObject("plotUtility", plotUtility);

Engine.Evaluate("myData = [ [1,2], [3,4],[5,8] ]" );
....
Engine.Evaluate("plotUtility.plot( myData )");

Where plotUtility is a c# object with method plot.

What would be the proper method for converting myData to a C# array? It comes in as a Microsoft.ClearScript.V8.V8ScriptItem which is protected, meaning i can't use it it my PlotUtlity.Plot signature. (e.g. Public void Plot(V8ScriptItem scriptItem) does not work.)

I can do the following:

Engine.Evaluate("plotUtility.plot( JSON.stringify(myData ) )");

and use a c# signature: Public void Plot(string scriptItem), but that seems a bit superfluous.

Is there a better way to do this where i can preserve the syntax:

Engine.Evaluate("plotUtility.plot( myData )");

New Post: Passing javascript objects to c# native code

$
0
0
Greetings!

ClearScript was designed to provide direct access to script objects, without data conversion. For example, you could write your C# class as follows:
publicclass ConsolePlotUtility {
    publicvoid plot(dynamic data) {
        for (var i = 0; i < data.length; i++)
            Console.WriteLine("({0},{1})", data[i][0], data[i][1]);
    }
}
and then use it like this:
engine.AddHostObject("plotUtility", new ConsolePlotUtility());
engine.Evaluate("plotUtility.plot([[1,2], [3,4], [5,8]])");
Keep in mind, however, that host-to-script and script-to-host calls are relatively expensive. Data conversion can actually yield better performance in many cases. With JSON, for example, you can package your data and move it across the boundary in one step, but of course you have to weigh that against the costs of JSON serialization and parsing.

Good luck, and thanks for your question!

Commented Feature: Allow custom locations in V8Proxy.GetDirPaths [34]

$
0
0
I am bundling the ClearScript DLLs as embedded resources in my main application/dll. At runtime I extract ClearScriptV8-XX.dll and v8-xXX.dll to a temporary path (typically Temporary ASP.NET Files) so that they can be loaded from disk.

In order to support this I have added a simple static API which allows adding custom locations returned by V8Proxy.GetDirPaths. It would be ideal if some equivalent functionality were included in the library.

This issue is somewhat related to https://clearscript.codeplex.com/workitem/17
Comments: Excellent, thank you! We'll incorporate this change into the next ClearScript release.

New Post: Re-using script object

$
0
0
Hi,

I'm using a library (CSG.js) and I need to call it from .Net. I instantiate a few objects and do operation on them. The information on what object and how I combine them comes from .Net. I'm having problem figuring how to do this.

I'm getting this error: 'Microsoft.ClearScript.Undefined' does not contain a definition for 'DoStuff'

Here's a simplified sample of what I'm doing.
        V8ScriptEngine engine;

        engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging);

        engine.Execute(@"MyClass = function() {
                                this.First = [];
                                this.Second = 2;
                            };

                            MyClass.prototype = {
                                DoStuff: function(someInt) {
                                    var mc = new MyClass();
                                    mc.Second = this.Second + mc.Second;
                                }
                            };
                            ");

        dynamic v1 = engine.Evaluate("new MyClass();");

        dynamic v2 = engine.Evaluate("new MyClass();");

        dynamic res = engine.Script.v1.DoStuff(2);

        Console.WriteLine((int)res);
Thanks

New Post: Re-using script object

$
0
0
Hi ssylvain,

First, you probably need to add a return statement to DoStuff; otherwise it returns undefined.

Next, you're getting the error because v1 is a .NET variable, but engine.Script.v1 tries to retrieve a nonexistent global value named v1 from the script engine.

You probably either want to do something like this:
dynamic v1 = engine.Evaluate("new MyClass()");
var res1 = (int)v1.DoStuff(2);
Console.WriteLine(res1);
or something like this:
engine.Evaluate("v2 = new MyClass()");
var res2 = Convert.ToInt32(engine.Evaluate("v2.DoStuff(2)"));
Console.WriteLine(res2);
Cheers!

New Post: Strong Name

$
0
0
Hi,

Is it possible to get a strong named version of ClearScript? I want to use it in a Visual Studio extension, which requires the assembly (and hence all its dependencies) to be signed. I'm currently using Chakra (IE's engine) via Active Scripting but I'd rather use V8 (especially with all the nice features ClearScript provides).

Thanks!

New Post: Strong Name

$
0
0
Hi Dan15,

We'll take a look at strong naming for the next release. Originally we weren't sure about the value of strong naming in an open-source project, since we'd be distributing the private key. However, it appears that strong naming is a requirement in a number of deployment scenarios, so it may be useful even without its security guarantees, as long as the user understands that.

Happy holidays!

New Post: Async/Await during script execution

$
0
0
I am exposing numerous C# objects to ClearScript using the async/await keywords because they are performing I/O. Will ClearScript properly handle asynchronous methods by returning the thread to the pool properly? Basically I do not want to encounter thread pool starvation due to numerous v8 engines performing I/O at the same time. Thanks!
Viewing all 2297 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>