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

New Post: Connect ClearScript Debug Port through WebSockets

0
0
Hi,

I Am trying to connect v8debug port through websockets using WebSockets4Net, we are passing messages through websockets to engine (in/out).

Code is as follows
                var v8Engine = new V8ScriptEngine(V8ScriptEngineFlags.DisableGlobalMembers | V8ScriptEngineFlags.EnableDebugging, 9622)
                 {
                     AllowReflection = false,
                 };

                WebSocket webscoketClient;
                webscoketClient = new WebSocket("ws://localhost:9622");
                webscoketClient.Opened += WebSocket_Opened;
                webscoketClient.MessageReceived += WebSocket_MessageReceived;
                webscoketClient.Error += WebSocket_Error;
                webscoketClient.Closed += WebSocket_Closed;
                webscoketClient.DataReceived += WebSocket_DataReceived;

                webscoketClient.Open();
When websocket connects its throwing exception.

Error Message:Type:connect
StackTrace
   at ConsoleAppV8Engine.Program.WebSocket_Error(Object sender, ErrorEventArgs e) in e:\Data\CodeKata\ConsoleAppV8Engine\ConsoleAppV8Engine\Program.cs:line 115
   at WebSocket4Net.WebSocket.OnError(ErrorEventArgs e)
   at WebSocket4Net.WebSocket.OnError(Exception e)
   at WebSocket4Net.WebSocket.FireError(Exception error)
   at WebSocket4Net.Command.Handshake.ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
   at WebSocket4Net.WebSocket.ExecuteCommand(WebSocketCommandInfo commandInfo)
   at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
   at WebSocket4Net.WebSocket.client_DataReceived(Object sender, DataEventArgs e)
   at SuperSocket.ClientEngine.ClientSession.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
   at SuperSocket.ClientEngine.AsyncTcpSession.ProcessReceive(SocketAsyncEventArgs e)
   at SuperSocket.ClientEngine.AsyncTcpSession.SocketEventArgsCompleted(Object sender, SocketAsyncEventArgs e)
   at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
   at System.Net.Sockets.SocketAsyncEventArgs.ExecutionCallback(Object ignored)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
   at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
Let me know does v8 support websockets for debugging

Thank you,
Praveen

New Post: Connect ClearScript Debug Port through WebSockets

0
0
Hi Praveen,

Unfortunately ClearScript's V8 debug server does not support WebSocket.

Sorry!

New Post: HostTypeCollection

0
0
I receiving this error when add System.Drawing and System.Windows.Forms to HostTypeCollection

The program '[6516] WindowsFormsApplication2.vshost.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.

Its supported?

New Post: HostTypeCollection

0
0
Greetings!

We're not seeing any issues with adding those assemblies to HostTypeCollection instances, nor with exposing those collections to script engines. Do you have any additional information? A code sample or stack trace might provide a clue.

Thanks!

New Post: Meaning of "Fixed nested termination behavior on V8"

0
0
Dear ClearScript team,

we are currently running 5.4.3 on our server application - we have been noticing for a while that, on very rare occasions (and apparently at random) one of the threads using V8 through ClearScript hangs indefinitely.

We've observed this for different tasks (ranging from the computationally and memory intensive to the "short and clean") as well as different workloads of the system itself. Rather interestingly, this behavior is not coupled with high CPU usage (as one would expect from an infinite loop situation) - it's just like the engine is stalled indefinitely by something.

Now I was looking at the release notes of 5.4.4 and the "Fixed nested termination behavior on V8" got my attention - can this be related to an engine never returning control to the application?

Thanks!

New Post: Meaning of "Fixed nested termination behavior on V8"

0
0
Hi andrea_schirru,

The issue you're seeing doesn't seem likely to be affected by the nested termination fix, which has to do with ScriptEngine.Interrupt() behavior when multiple top-level script frames are on the stack.

Currently we're not aware of any hanging issues in ClearScript 5.4.3 or 5.4.4. Do you have a code sample or stack trace you could share?

Cheers!

New Post: Callbacks for some host objects are not executing

0
0
Hi again,

Well, this has turned into quite an investigation. Our findings:

  1. The MSHTML/JScript window object requires that callbacks be recognizable as JScript functions, not simply IDispatchEx instances. Contrary to earlier findings, legacy JScript and pre-Edge Chakra have identical requirements in this area, although they don't seem to recognize each other's functions. Interestingly, functions belonging to other instances of the same script engine are apparently permitted.
  2. Your change in HostItem.cs assumes that window (actually any COM object) can be treated as a script object belonging to the current script engine. This enables your callback scenario by tricking ClearScript into giving windowdirect access to the callback. That is, when your script issues a call such as window.setTimeout(callback), ClearScript observes that window and callback are script objects belonging to the same script engine and concludes that no proxy is required. The resulting proxy-free (direct) access allows window to recognize callback as a JScript function.
  3. While it enables your scenario, your change in HostItem.cs is generally incorrect. Most COM objects are not script objects; in fact, most script engines don't support COM at all. In this particular case, windowis a COM object, and it is natively compatible with your script engine (Chakra), but there's no way for ClearScript to detect that or to determine that direct access is actually desirable. Only the application has that knowledge.
Given all this, we've decided to add HostItemFlags.DirectAccess (commit). Here's how you might use it in your BHO:
engine.AddHostObject("window", HostItemFlags.GlobalMembers | HostItemFlags.DirectAccess, window);
This exposes window for script access that bypasses ClearScript completely. It should yield better performance, and all callbacks should work. Give it a try. You'll still need your other modifications that enable Chakra support within ClearScript.

Good luck!

New Post: Callbacks for some host objects are not executing

0
0
This fix appears to work. Thanks.

New Post: I can override methods with whatever value on 5.4.4

0
0
The following anomaly executes on version 5.4.4. Is this change intentional? If so, is there a way to disable it? Properties are still restricted to their types, only methods not.

public class Calculator
{
    public int Add(int a, int b)
    {
        return a + b;
    }

    public int Sub(int a, int b)
    {
        return Add(a, -b);
    }
}

class Program
{
    static void Main(string[] args)
    {
        using (var engine = new V8ScriptEngine())
        {
            engine.AddHostObject("calc", new Calculator());

            int result = (int)engine.Evaluate("calc.Add(2, 3)");
            // Prints 5
            Console.WriteLine(result);

            // Override the method...
            engine.Execute("calc.Add = 'add is now a string'");
            string newResult = (string)engine.Evaluate("calc.Add");
            // Prints "add is now a string"
            Console.WriteLine(newResult);

            // calc.Sub still works though
            result = (int)engine.Evaluate("calc.Sub(10, 20)");
            // Prints -10
            Console.WriteLine(result);

            // Does not work anymore (throws "Add is not a function")
            result = (int)engine.Evaluate("calc.Add(7, 8)");
        }
    }
}

Source code checked in, #0970b09f989042047519d2ee62d6dda526547bb0

0
0
Fixed host method clobbering on V8.

New Post: I can override methods with whatever value on 5.4.4

0
0
Hello!

This is a bug, and a fix is available (commit).

Thanks for reporting this issue!

New Post: Clearscript V8 engine hang while debugging

0
0
Hi,

I am running Clearscript v8 script engine in debug mode to control script execution(Play,Pause,Stop). Clearscript V8 engine executing all scripts perfectly. I we put execution in a loop, after few script execution v8 will not write any response to newtork stream, it just hang.
//Clearscript  V8 script engine.
            var debuggingPort =2015;

            m_scriptEngine = new V8ScriptEngine(V8ScriptEngineFlags.DisableGlobalMembers | V8ScriptEngineFlags.EnableDebugging, debuggingPort)
            {
                AllowReflection = false,
            };
            Uri portUri = new Uri("tcp://127.0.0.1:"+debuggingPort);
            m_tcpClient = new TcpClient(portUri.Host, portUri.Port);
Send request to V8 Debug engine
      private Task<Response> SendRequestAsync(Request request, CancellationToken cancellationToken = new CancellationToken()) 
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (request.Sequence.HasValue == false)
                request.Sequence = m_currentSequence++;
            else
                m_currentSequence = request.Sequence.Value + 1;

             var requestResetEvent = new ManualResetEvent(false);
             _requestWaitHandles.AddOrUpdate(request.Sequence.Value, requestResetEvent, (id, r) => requestResetEvent);

             var serializedRequest = JsonConvert.SerializeObject(request);  
    //ex:- serializedRequest ={"seq":1,"type":"request","command":"setbreakpoint","arguments":{"type":"script","target":"1fa9ab33-fea8-41f5-91a4-d891e361a52f_IdeFfeVoLb.js [temp]","line":0}}

             return Task.Run(() => {

                 SendMessage(serializedRequest);

                 requestResetEvent.WaitOne();

                 Response response = null;
                 _responses.TryRemove(request.Sequence.Value, out response);

                 _requestWaitHandles.TryRemove(request.Sequence.Value, out requestResetEvent);

                 return response;
             });             
        }

        private async void SendMessage(string message) 
        {
            try
            {
               
                TcpClient networkClient;
                lock (m_networkClientLock)
                {
                    networkClient = m_tcpClient;
                }

                var networkStream = m_tcpClient.GetStream();

                var streamWriter = new StreamWriter(networkStream);
                
                int byteCount = Encoding.UTF8.GetByteCount(message);
                string request = string.Format("Content-Length: {0}{1}{1}{2}", byteCount, Environment.NewLine, message);

                if(Connected)
                {
                    await streamWriter.WriteAsync(request).ConfigureAwait(false);                    
                    await streamWriter.FlushAsync().ConfigureAwait(false);
                                       
                    WriteToLogFile("Written to stream. Message:" + request);                    
                }                
            }
            catch (Exception e)
            {
                WriteToLogFile("Exception writing to stream. Err Mesg:" + e.Message + Environment.NewLine);                    
                Debug.Write("Exception writing to stream. Err Mesg:" + e.Message+Environment.NewLine);
            }
Reading response from engine using while loop.
var networkStream=networkClient.GetStream();
                //networkStream.ReadTimeout = 2000;

                using (var streamReader = new StreamReader(networkStream, Encoding.Default))                              
                {                    
                   while (Connected) 
                   {
                       //if (networkStream.DataAvailable)
                       {
                           try
                           {
                               WriteToLogFile("Before Response: ");

                               var result = await streamReader.ReadLineAsync().ConfigureAwait(false);
                               //var result = streamReader.ReadLine();

                               WriteToLogFile("Response from engine. Response: " + result);

                               if (result == null)
                               {
                                   continue;
                               }

                               // Check whether result is content length header
                               var match = m_contentLength.Match(result);

                               if (!match.Success)
                               {
                                   //DebugWriteLine(string.Format("Debugger info: {0}", result));
                                   continue;
                               }

                               await streamReader.ReadLineAsync().ConfigureAwait(false);

                               // Retrieve content length
                               var length = int.Parse(match.Groups[1].Value);
                               if (length == 0)
                               {
                                   continue;
                               }

                               // Read content
                               string message = await streamReader.ReadLineBlockAsync(length).ConfigureAwait(false);

                               WriteToLogFile("Response from engine. Response: " + message);

                               HandleOutput(message);
                           }
                           catch (Exception exx)
                           {
                               WriteToLogFile("Exception reading from stream. Err Mesg:" + exx.Message + Environment.NewLine);
                           }
                       }
                    }
                }
Script hanging at line
var result = await streamReader.ReadLineAsync().ConfigureAwait(false);
No response from Clearscript V8 engine. step in request sent to engine on breakpoint event. Is there any other technique to control script execution.

Thanks and Regards
Praveen Kumar

New Post: Clearscript V8 engine hang while debugging

0
0
Hi Praveen,

It's difficult for us to diagnose this kind of issue armed only with partial code from your application and without detailed information about its overall design, its process/thread architecture, the scripts being executed, etc.

One suggestion would be to try to reproduce the issue using Eclipse instead of your custom debugger (see the ClearScript ReadMe for more information). That might help you determine whether the problem is within ClearScript. Would that be possible?

Also, please make sure you're using ClearScript 5.4.3 or later.

Thanks!

Commented Feature: [FEATURE] Expose Chakra [29]

0
0
It would be great to get access to the IE9+ Chakra engine as a lightweight (in terms of file size), ES5 compatible alternative to V8.
Comments: ChakraCore was just released in open source: https://github.com/Microsoft/ChakraCore

New Post: Clearscript V8 engine hang while debugging


New Post: Clearscript V8 engine hang while debugging

0
0
Thanks Praveen.

Eclipse is our test environment for ClearScript's V8 debug server, and currently we're not aware of any issues. Please let us know if you can reproduce your issue in Eclipse. Or, if you can provide a complete sample that reproduces it, we'll be happy to take a look.

Thanks!

New Post: Clearscript V8 engine hang while debugging

0
0
Hi,

I have included test project in github((https://github.com/NKumarPraveen/ClearScriptV8Debugger)). issue with stream reading from engine.
                if(Connected)
                {
                    //await streamWriter.WriteAsync(request).ConfigureAwait(false);                    
                    //await streamWriter.FlushAsync().ConfigureAwait(false);
                    WriteToLogFile("Writting to stream. Message:" + request);  

                    streamWriter.Write(request);
                    streamWriter.Flush();
                                       
                    WriteToLogFile("Written to stream. Message:" + request);                    
                }   
and
            {
                TcpClient networkClient;
                
                lock (m_networkClientLock)
                {
                    networkClient = m_tcpClient;
                }

                var networkStream=networkClient.GetStream();
                //networkStream.ReadTimeout = 2000;

                using (var streamReader = new StreamReader(networkStream, Encoding.Default))                              
                {                    
                   while (Connected) 
                   {
                       //if (networkStream.DataAvailable)
                       {
                           try
                           {
                               WriteToLogFile("Before Response: ");

                               var result = await streamReader.ReadLineAsync().ConfigureAwait(false);
                               //var result = streamReader.ReadLine();

                               WriteToLogFile("Response from engine. Response: " + result);

                               if (result == null)
                               {
                                   continue;
                               }

                               // Check whether result is content length header
                               var match = m_contentLength.Match(result);

                               if (!match.Success)
                               {
                                   //DebugWriteLine(string.Format("Debugger info: {0}", result));
                                   continue;
                               }

                               await streamReader.ReadLineAsync().ConfigureAwait(false);

                               // Retrieve content length
                               var length = int.Parse(match.Groups[1].Value);
                               if (length == 0)
                               {
                                   continue;
                               }

                               // Read content
                               string message = await streamReader.ReadLineBlockAsync(length).ConfigureAwait(false);

                               WriteToLogFile("Response from engine. Response: " + message);

                               HandleOutput(message);
                           }
                           catch (Exception exx)
                           {
                               WriteToLogFile("Exception reading from stream. Err Mesg:" + exx.Message + Environment.NewLine);
                           }
                       }
                    }
                }
            }
Also logging to text file in temp folder(V8Enginelog.log).

Thanks and Regards
Praveen

New Post: Clearscript V8 engine hang while debugging

0
0
Hi Praveen,

Thanks for posting your test project, but we're not seeing any issues. The test program appears to run to completion every time, even with several loops running simultaneously.

Image

Any thoughts?

New Post: Clearscript V8 engine hang while debugging

0
0
Hi,

This issue cannot reproducible all the time. I have executed on different windows OS 32 & 64 bit, can be producible on following.

Windows 7 64 bit => Recreated issue
Windows 8 64 bit => Recreated issue

Windows 7 32 bit => Working
Windows 8 32 bit => Working
Windows 8.1 32 bit => Working
Windows 8.1 64 bit => Working

This frequently recreated on Windows 7 64 bit & Windows 8 64 bit.

Thanks
Praveen.

Created Unassigned: Can no longer use object method "toString()" in 5.4.4 [98]

0
0
Hi,

We currently use ClearScript v5.4.2 and wanted to upgrade to v5.4.4. This is because the method "toString()" no longer binds to the method on the managed instance of the HostObject - this means that it always returns "[object HostObject]".

I also tried using extension methods and interface methods, but all of them return the same string: "[object HostObject]". The problem is that we can't upgrade to ClearScript v5.4.4 because of this issue. If it turns out to be a v8 issue that can't be fixed in ClearScript, do you know what version of v8 made it stop working?

I attached an additional test fixture that you can just add to the ClearScriptTest project so you can see experience the problem.

Thank you.
Viewing all 2297 articles
Browse latest View live




Latest Images