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

New Post: Scaling V8

$
0
0
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!

New Post: .Net Default Property Recognition

New Post: ActiveXObject implementation

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

New Post: ActiveXObject implementation

$
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!

New Post: validate js

$
0
0
how can i check if the given js is valid?

New Post: validate js

$
0
0
Hi furesoft,

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

Cheers!

New Post: vbs events

$
0
0
hi,
how can i use events in vbs?

New Post: vbs events

$
0
0
Hi furesoft,

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

Thanks!

New Post: vbs events

New Post: vbs events

$
0
0
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!

Commented Issue: [FIXED] 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

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.

New Post: Global window object

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

Commented Issue: [FIXED] 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

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!

New Post: Global window object

$
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!

New Post: Global window object

$
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

New Post: Global window object

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

New Post: Global window object

$
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;

New Post: validate js

$
0
0
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.

New Post: Global window object

$
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.

New Post: Global window object

$
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!
Viewing all 2297 articles
Browse latest View live




Latest Images