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

Closed Unassigned: Exception when creating Dates in V8ScriptEngine [113]

$
0
0
Hello,

I'm trying to create/parse date from a JS evaluate and return them as strings back into c# code as such:

```
using (var engine = new V8ScriptEngine())
{
resultEval = engine.Evaluate(expression);
}
```

where my `expression` is

`new Date()`

and it return an "Microsoft.ClearScript.V8.V8ScriptItem" object with an "UnderlyingSystemType" saying:

'((Microsoft.ClearScript.ScriptItem)resultEval).UnderlyingSystemType' threw an exception of type 'System.NotImplementedException'

Now, I feel like this *should* work, but it's not. Any ideas? I don't think anything went wrong during the build/reference process. Other JS libraries such as Math work flawlessly.

Also, this is only an issue when trying to create a `new` date. Calling `Date()` works, but it only displays today's date.

Edited Issue: Exception when creating Dates in V8ScriptEngine [113]

$
0
0
Hello,

I'm trying to create/parse date from a JS evaluate and return them as strings back into c# code as such:

```
using (var engine = new V8ScriptEngine())
{
resultEval = engine.Evaluate(expression);
}
```

where my `expression` is

`new Date()`

and it return an "Microsoft.ClearScript.V8.V8ScriptItem" object with an "UnderlyingSystemType" saying:

'((Microsoft.ClearScript.ScriptItem)resultEval).UnderlyingSystemType' threw an exception of type 'System.NotImplementedException'

Now, I feel like this *should* work, but it's not. Any ideas? I don't think anything went wrong during the build/reference process. Other JS libraries such as Math work flawlessly.

Also, this is only an issue when trying to create a `new` date. Calling `Date()` works, but it only displays today's date.

New Post: Debugging hangs if an event handler for a UI element is set and event handler gets executed (V8)

$
0
0
For the sake of completeness, I want to share the final version of my helper functions which can be used to connect and disconnect to any kind of event on an object.
       private static Delegate CreateDelegate(Type delegateType, Action<object[]> target)
        {
            var sourceParameters = delegateType.GetMethod("Invoke").GetParameters();
            var parameters = sourceParameters.Select(p => Expression.Parameter(p.ParameterType, p.Name)).ToArray();
            var castParameters = parameters.Select(p => Expression.TypeAs(p, typeof(object))).ToArray();
            var createArray = Expression.NewArrayInit(typeof(object), castParameters);
            var invokeTarget = Expression.Invoke(Expression.Constant(target), createArray);
            var lambdaExpression = Expression.Lambda(delegateType, invokeTarget, parameters);
            return lambdaExpression.Compile();
        }

        private static Type delegateFactory = typeof(V8ScriptEngine).Assembly.GetType("Microsoft.ClearScript.DelegateFactory");
        private static MethodInfo createDelegateX = delegateFactory.GetMethod("CreateDelegate", new[] { typeof(ScriptEngine), typeof(object), typeof(Type) });

        public Delegate AddEventHandler(object obj, string eventName, object callback) {
            var eventInfo = obj.GetType().GetEvent(eventName);
            if (eventInfo != null)
            {
                // Create a delegate from the JavaScript callback function
                Delegate scriptHandler = (Delegate)createDelegateX.Invoke(null, new object[] { engine, callback, eventInfo.EventHandlerType });

                var handler = CreateDelegate(eventInfo.EventHandlerType, (object[] args) =>
                {
                    Debug.WriteLine("Event triggered: " + eventInfo.Name);
                    new Thread(() =>
                    {
                        scriptHandler.DynamicInvoke(args);
                    }).Start();
                });

                try
                {
                    eventInfo.AddEventHandler(obj, handler);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("AddEventHandler could not add event handler:" + ex.Message);
                    return null;
                }

                return handler;
            }
            return null;
        }

        public bool RemoveEventHandler(object obj, string eventName, Delegate handler)
        {
            var eventInfo = obj.GetType().GetEvent(eventName);
            if (eventInfo != null)
            {
                eventInfo.RemoveEventHandler(obj, handler);
                return true;
            }
            return false;
        }

New Post: Is it possible to send messages to debugger console?

$
0
0
ClearScript does not have a built-in console object to log messages.
console.log("Hello world");
If I implement one myself, how can direct messages to the debugger console?

The debugger can be either the Eclipse debugger or custom V8-compatible debugger.

New Post: Is it possible to send messages to debugger console?

$
0
0
Hi ahmetuzun,

V8 and ClearScript neither support nor impede the implementation of any particular user interface, including a console window. If your application or debugger has a console window and provides an API for sending output to it, then that API should be easy to expose via ClearScript. It would probably be similar to the way the sample code on ClearScript's home page exposes System.Console.

Good luck!

New Post: Is it possible to send messages to debugger console?

$
0
0
Ok, let me rephrase it like this:

node.js also uses the V8 engine. It has a built in console object which directs messages to the debugger console if the debugger is attached.

When I execute "console.log("Hello")" with node.js, I can see the "Hello" message both in my console and the debugger console.

Sİnce you create a bridge between the V8 engine and the .NET world, do you know how to tell V8 send text messages to the debugger console?

New Post: Is it possible to send messages to debugger console?

$
0
0
We're not aware of any facility within V8's main API, debug API or debug protocol that supports console output. There appear to be some console-related features defined here, but ClearScript doesn't consume this newer API and we haven't investigated it. Sorry!

New Post: Is it possible to send messages to debugger console?

$
0
0
I also could not find any console-related requests in the debug protocol.

I think node-inspector and other node.js debuggers implement something special to achieve this.

I will look deeper and share anything I can find here.

Thank you very much.

New Post: how to call webservice method & read the response

$
0
0
Hi,
we are using clearscript 5.4.7 version and trying the below
  1. Call a webservice (.svc) method by passing few parameters
  2. Get the response returned by webservice - success response
  3. Get the response returned by webservice - failure response - e.g. timeout happened
    Unable to read the response what the webservice return.
    we are trying with the below sample code in 5.4.7. Based on this working we need use the same script in 5.3.10 version. Will it work or we need to upgrade to latest ver of 5.4.7?

sample-code-snippet:

public class Console
{
    public void Log(string msg)
    {
        Console.WriteLine(msg);
    }
}
-----------
public class MyObject
{
    public string _url;
    public string data1;
    public string data2;
}
------------
    static void Main(string[] args)
    {
        using (var _eng = new V8ScriptEngine())
        {
            Console _log = new Console();

            _eng.AddHostType("Console", typeof(Console));

            MyObject _obj = new MyObject();
            _obj._url = "http://1.2.3.4/myWebService/myService1.svc/Process?param1=value1&param2=value";
            _obj.data1 = "some test data-1";
            _obj.data2 = "some test data-2";

            _eng.AddHostType("WebClient", typeof(WebClient));
            _eng.AddHostObject("jsObject", _obj);
            _eng.AddHostObject("Console", _log);

            //--.js
            _eng.Execute(@"
            var client = new WebClient();
            var ret = client.DownloadString(jsObject._url);
            Console.Log('URL return string :' + ret);
            ");

            _log.Log(" WS return val:" + engine.Script.html);

        }
    }
any help?

Thanks & Regards

New Post: how to call webservice method & read the response

$
0
0
Hi omnamasivaya,

If you're wondering how to handle .NET exceptions in script code, here's one way:
engine.AddHostType(typeof(WebClient));
engine.AddHostType(typeof(Console));
engine.Execute(@"
    client = new WebClient();
    try {
        ret = client.DownloadString('http://example.com');
    }
    catch (ex) {
        if (ex.hostException) {
            Console.WriteLine(ex.hostException.GetBaseException().Message);
        }
    }
");
Note that this works only in V8ScriptEngine. An alternative that works with other script engines is HostFunctions.tryCatch; you can download the latest API reference here.

Both features are new in ClearScript 5.4, but if you're stuck with an older version, it should be fairly easy to code up your own version of tryCatch. You can see ClearScript's implementation here.

Good luck!

Created Unassigned: Access Violation Exception in v8-x64.dll [115]

$
0
0
Hi!
We launched a new site last week that uses ClearScript to server render a React application. After launch, we get around 2-3 crashes on Access Violation Exception in w3wp.exe a day per web server. The site has around 200 concurrent users on average, with peaks up over a thousand. We use the latest version of ClearScript (5.4.7).

We see that the crash is an Access Violation Exception in v8-x64.dll and we have a few dump files from such crashes, but since we don't have any debugging symbols the stack traces doesn't give us much.

Would you be interested in looking at the crash dumps to help us figure this out? Or if you can help us with debug symbols so we can get more information out of the dumps.

Some information about how we use ClearScript:
1. We create multiple V8Runtime and V8ScriptEngine and keep them in a queue. When a request comes in, we dequeue an engine, run JS and return it back to the queue.
2. Since we don't store any JS globals we reuse the same V8 context for different visitors. But we run CollectGarbage(true) for every 30 execution. We have deployed a change this morning where we call CollectGarbage(false) instead but twice as often. Not because we think it will solve it, but see if the behavior changes.

Any help or pointers are appreciated!

Edited Unassigned: Access Violation Exception in v8-x64.dll [115]

$
0
0
Hi!
We launched a new site last week that uses ClearScript to server render a React application. After launch, we get around 2-3 crashes on Access Violation Exception in w3wp.exe a day per web server. The site has around 200 concurrent users on average, with peaks up over a thousand. We use the latest version of ClearScript (5.4.7).

We see that the crash is an Access Violation Exception in v8-x64.dll and we have a few dump files from such crashes, but since we don't have any debugging symbols the stack traces doesn't give us much.

Would you be interested in looking at the crash dumps to help us figure this out? Or if you can help us with debug symbols so we can get more information out of the dumps.

Some information about how we use ClearScript:
1. We create multiple V8Runtime and V8ScriptEngine and keep them in a queue. When a request comes in, we dequeue an engine, run JS and return it back to the queue.
2. Since we don't store any JS globals we reuse the same V8 context for different visitors. But we run CollectGarbage(true) for every 30 execution. We have deployed a change this morning where we call CollectGarbage(false) instead but twice as often. Not because we think it will solve it, but see if the behavior changes.
3. We don't pass any CLR references to V8. The only thing we do is call Engine.Execute with strings of JS code. When we pass data to V8 we do that by either calling Engine.Execute or Engine.Evaluate with strings of JSON.

Any help or pointers are appreciated!

Edited Unassigned: Access Violation Exception in v8-x64.dll [115]

$
0
0
Hi!
We launched a new site last week that uses ClearScript to server render a React application. After launch, we get around 2-3 crashes on Access Violation Exception in w3wp.exe a day per web server. The site has around 200 concurrent users on average, with peaks up over a thousand. We use the latest version of ClearScript (5.4.7).

We see that the crash is an Access Violation Exception in v8-x64.dll and we have a few dump files from such crashes, but since we don't have any debugging symbols the stack traces doesn't give us much.

Would you be interested in looking at the crash dumps to help us figure this out? Or if you can help us with debug symbols so we can get more information out of the dumps.

Some information about how we use ClearScript:
1. We create multiple V8Runtime and V8ScriptEngine and keep them in a queue. When a request comes in, we dequeue an engine, run JS and return it back to the queue.
2. Since we don't store any JS globals we reuse the same V8 context for different visitors. But we run CollectGarbage(true) for every 30 execution. We have deployed a change this morning where we call CollectGarbage(false) instead but twice as often. Not because we think it will solve it, but see if the behavior changes.
3. We don't pass any CLR references to V8. The only thing we do is call Engine.Execute with strings of JS code. When we pass data to V8 we do that by either calling Engine.Execute or Engine.Evaluate with strings of JSON.

Any help or pointers are appreciated! We'd be happy to share code with you if you need it.

Commented Unassigned: Access Violation Exception in v8-x64.dll [115]

$
0
0
Hi!
We launched a new site last week that uses ClearScript to server render a React application. After launch, we get around 2-3 crashes on Access Violation Exception in w3wp.exe a day per web server. The site has around 200 concurrent users on average, with peaks up over a thousand. We use the latest version of ClearScript (5.4.7).

We see that the crash is an Access Violation Exception in v8-x64.dll and we have a few dump files from such crashes, but since we don't have any debugging symbols the stack traces doesn't give us much.

Would you be interested in looking at the crash dumps to help us figure this out? Or if you can help us with debug symbols so we can get more information out of the dumps.

Some information about how we use ClearScript:
1. We create multiple V8Runtime and V8ScriptEngine and keep them in a queue. When a request comes in, we dequeue an engine, run JS and return it back to the queue.
2. Since we don't store any JS globals we reuse the same V8 context for different visitors. But we run CollectGarbage(true) for every 30 execution. We have deployed a change this morning where we call CollectGarbage(false) instead but twice as often. Not because we think it will solve it, but see if the behavior changes.
3. We don't pass any CLR references to V8. The only thing we do is call Engine.Execute with strings of JS code. When we pass data to V8 we do that by either calling Engine.Execute or Engine.Evaluate with strings of JSON.

Any help or pointers are appreciated! We'd be happy to share code with you if you need it.
Comments: Hello! We'll be happy to have a look at a crash dump (or even just a crash stack), although, as you point out, we'll be limited without debug symbols. In such situations we always recommend that you obtain symbols, either by contacting the party that built your ClearScript binaries, or by building ClearScript yourself as outlined [here](https://clearscript.codeplex.com/SourceControl/latest#ReadMe.txt). In the meantime, can you say more about your engine/runtime provisioning? Do you enforce a limit on the number of simultaneously active runtimes? Do you know how many, approximately, are active when the crashes occur? When do you dispose engines/runtimes? Thanks!

Commented Unassigned: Access Violation Exception in v8-x64.dll [115]

$
0
0
Hi!
We launched a new site last week that uses ClearScript to server render a React application. After launch, we get around 2-3 crashes on Access Violation Exception in w3wp.exe a day per web server. The site has around 200 concurrent users on average, with peaks up over a thousand. We use the latest version of ClearScript (5.4.7).

We see that the crash is an Access Violation Exception in v8-x64.dll and we have a few dump files from such crashes, but since we don't have any debugging symbols the stack traces doesn't give us much.

Would you be interested in looking at the crash dumps to help us figure this out? Or if you can help us with debug symbols so we can get more information out of the dumps.

Some information about how we use ClearScript:
1. We create multiple V8Runtime and V8ScriptEngine and keep them in a queue. When a request comes in, we dequeue an engine, run JS and return it back to the queue.
2. Since we don't store any JS globals we reuse the same V8 context for different visitors. But we run CollectGarbage(true) for every 30 execution. We have deployed a change this morning where we call CollectGarbage(false) instead but twice as often. Not because we think it will solve it, but see if the behavior changes.
3. We don't pass any CLR references to V8. The only thing we do is call Engine.Execute with strings of JS code. When we pass data to V8 we do that by either calling Engine.Execute or Engine.Evaluate with strings of JSON.

Any help or pointers are appreciated! We'd be happy to share code with you if you need it.
Comments: Hi! We'll try go get symbols deployed to get a better error description. We have a queue of max 20 runner instances where a runner is one script engine instance and one runtime instance. We never dispose them, we only run GC on them. When a request comes in for a runner but all 20 instances are busy the caller is put in a waiting state until a runner is free. There seems to be some correlation between crashes and used memory. It seems that the crashes occurs most frequently when memory usage levels out at around 60-80%. After a restart we see that memory usage raises (as expected) as caches etc are getting filled. Then memory levels out as cache eviction etc starts to kick in. And that's when we see most of our crashes.

New Post: Serializing a compiled script

Commented Unassigned: Access Violation Exception in v8-x64.dll [115]

$
0
0
Hi!
We launched a new site last week that uses ClearScript to server render a React application. After launch, we get around 2-3 crashes on Access Violation Exception in w3wp.exe a day per web server. The site has around 200 concurrent users on average, with peaks up over a thousand. We use the latest version of ClearScript (5.4.7).

We see that the crash is an Access Violation Exception in v8-x64.dll and we have a few dump files from such crashes, but since we don't have any debugging symbols the stack traces doesn't give us much.

Would you be interested in looking at the crash dumps to help us figure this out? Or if you can help us with debug symbols so we can get more information out of the dumps.

Some information about how we use ClearScript:
1. We create multiple V8Runtime and V8ScriptEngine and keep them in a queue. When a request comes in, we dequeue an engine, run JS and return it back to the queue.
2. Since we don't store any JS globals we reuse the same V8 context for different visitors. But we run CollectGarbage(true) for every 30 execution. We have deployed a change this morning where we call CollectGarbage(false) instead but twice as often. Not because we think it will solve it, but see if the behavior changes.
3. We don't pass any CLR references to V8. The only thing we do is call Engine.Execute with strings of JS code. When we pass data to V8 we do that by either calling Engine.Execute or Engine.Evaluate with strings of JSON.

Any help or pointers are appreciated! We'd be happy to share code with you if you need it.
Comments: Some more info: we tried calling CollectGarbage(false) instead of CollectGarbage(true) but doing it twice as often. This seemed to make the crashes less frequent but it also made it eat memory like nothing else. This morning we deployed a new version where we dispose both engines and runtimes when we've used them 300 times. This has made a drastic improvement in memory use for us. Memory use went from 15% to 60% of 32GB RAM in a couple of hours. But since this morning it has gone from 15% to 20-25% in ten hours. Is this normal? Why do we need to dispose engines and runtimes on a regular basis instead of just running GC?

New Post: Serializing a compiled script

$
0
0
It's still on the backlog. You're only the second person to express interest in this feature :)

Commented Unassigned: Access Violation Exception in v8-x64.dll [115]

$
0
0
Hi!
We launched a new site last week that uses ClearScript to server render a React application. After launch, we get around 2-3 crashes on Access Violation Exception in w3wp.exe a day per web server. The site has around 200 concurrent users on average, with peaks up over a thousand. We use the latest version of ClearScript (5.4.7).

We see that the crash is an Access Violation Exception in v8-x64.dll and we have a few dump files from such crashes, but since we don't have any debugging symbols the stack traces doesn't give us much.

Would you be interested in looking at the crash dumps to help us figure this out? Or if you can help us with debug symbols so we can get more information out of the dumps.

Some information about how we use ClearScript:
1. We create multiple V8Runtime and V8ScriptEngine and keep them in a queue. When a request comes in, we dequeue an engine, run JS and return it back to the queue.
2. Since we don't store any JS globals we reuse the same V8 context for different visitors. But we run CollectGarbage(true) for every 30 execution. We have deployed a change this morning where we call CollectGarbage(false) instead but twice as often. Not because we think it will solve it, but see if the behavior changes.
3. We don't pass any CLR references to V8. The only thing we do is call Engine.Execute with strings of JS code. When we pass data to V8 we do that by either calling Engine.Execute or Engine.Evaluate with strings of JSON.

Any help or pointers are appreciated! We'd be happy to share code with you if you need it.
Comments: >This morning we deployed a new version where we dispose both engines and runtimes when we've used them 300 times. This has made a drastic improvement in memory use for us. ​ Excellent! Any change in the frequency of crashes? Any impact on your site's performance? ​ >Is this normal? Why do we need to dispose engines and runtimes on a regular basis instead of just running GC? ​ Is it possible that the scripts you run leave artifacts that are reachable from the global object and therefore cannot be collected? Do they return script objects that the host keeps around? Normally we'd suspect ClearScript's V8 interop code, from which we've shaken out quite a few leaks and other issues over the years, but as you said, you're doing next to zero interop. The only other thing that comes to mind is that V8 seems to have small memory leaks in its parser, possibly related to heap fragmentation. This in addition to performance is why we always recommend reusing parsed script code if possible. You mentioned that your application invokes script code exclusively via `ScriptEngine.Execute` and similar methods, all of which involve the parser. That could be a factor.

Commented Unassigned: Access Violation Exception in v8-x64.dll [115]

$
0
0
Hi!
We launched a new site last week that uses ClearScript to server render a React application. After launch, we get around 2-3 crashes on Access Violation Exception in w3wp.exe a day per web server. The site has around 200 concurrent users on average, with peaks up over a thousand. We use the latest version of ClearScript (5.4.7).

We see that the crash is an Access Violation Exception in v8-x64.dll and we have a few dump files from such crashes, but since we don't have any debugging symbols the stack traces doesn't give us much.

Would you be interested in looking at the crash dumps to help us figure this out? Or if you can help us with debug symbols so we can get more information out of the dumps.

Some information about how we use ClearScript:
1. We create multiple V8Runtime and V8ScriptEngine and keep them in a queue. When a request comes in, we dequeue an engine, run JS and return it back to the queue.
2. Since we don't store any JS globals we reuse the same V8 context for different visitors. But we run CollectGarbage(true) for every 30 execution. We have deployed a change this morning where we call CollectGarbage(false) instead but twice as often. Not because we think it will solve it, but see if the behavior changes.
3. We don't pass any CLR references to V8. The only thing we do is call Engine.Execute with strings of JS code. When we pass data to V8 we do that by either calling Engine.Execute or Engine.Evaluate with strings of JSON.

Any help or pointers are appreciated! We'd be happy to share code with you if you need it.
Comments: Thanks for replying! After reading my own comment I see that I was a bit unclear. At first we had ~20 engines and runtimes that we never disposed, we just called CollectGarbage(true) on them for every 30 execution. This gave a slow buildup of memory. About one GB an hour. This gave us Access Violation crashes every 2-6 hours. Then we changed to run CollectGarbage(false) but for every 15 execution. This seemed to reduce the number of crashes but it made the memory usage increase a lot and we had to manually restart one server as the memory grew to 100%. After that we changed to dispose both the engine and the runtime after 300 executions. This has removed the crashes entirely, and the servers now use ~30% memory without it growing. We only use ScriptEngine.Execute and ScriptEngine.Evaluate when we pass in JSON. For the main chunk of code we precompile at startup. Our code does not leave artifacts behind that grows and it does not add global variables. I wouldn't call it pure (as in no side effects) but the process is "pass in a big JSON structure, get HTML back". The big JSON object passed in is stored in a local variable which no parts of the code references when the HTML is returned.
Viewing all 2297 articles
Browse latest View live




Latest Images