private string ExecuteHandler( IntPtr commandHandlerHandle, string json, string[] other, out string newSharedState) { _reverseCommandHandlerException = null; _prelude.ScheduleTerminateExecution(); IntPtr resultJsonPtr; IntPtr result2JsonPtr; IntPtr memoryHandle; bool success = Js1.ExecuteCommandHandler( _script.GetHandle(), commandHandlerHandle, json, other, other != null ? other.Length : 0, out resultJsonPtr, out result2JsonPtr, out memoryHandle); var terminated = _prelude.CancelTerminateExecution(); if (!success) { CompiledScript.CheckResult(_script.GetHandle(), terminated, disposeScriptOnException: false); } string resultJson = Marshal.PtrToStringUni(resultJsonPtr); string result2Json = Marshal.PtrToStringUni(result2JsonPtr); Js1.FreeResult(memoryHandle); if (_reverseCommandHandlerException != null) { throw new ApplicationException( "An exception occurred while executing a reverse command handler. " + _reverseCommandHandlerException.Message, _reverseCommandHandlerException); } newSharedState = result2Json; return(resultJson); }
private CompiledScript CompileScript(PreludeScript prelude, string script, string fileName) { prelude.ScheduleTerminateExecution(); IntPtr query = Js1.CompileQuery( prelude.GetHandle(), script, fileName, _commandHandlerRegisteredCallback, _reverseCommandHandlerDelegate); var terminated = prelude.CancelTerminateExecution(); CompiledScript.CheckResult(query, terminated, disposeScriptOnException: true); return new CompiledScript(query); }
private CompiledScript CompileScript(PreludeScript prelude, string script, string fileName) { prelude.ScheduleTerminateExecution(); IntPtr query = Js1.CompileQuery( prelude.GetHandle(), script, fileName, _commandHandlerRegisteredCallback, _reverseCommandHandlerDelegate); var terminated = prelude.CancelTerminateExecution(); CompiledScript.CheckResult(query, terminated, disposeScriptOnException: true); return(new CompiledScript(query, fileName)); }
public void long_execution_of_non_v8_code_does_not_crash() { _cancelCallbackFactory = (timeout, action) => ThreadPool.QueueUserWorkItem(state => { Console.WriteLine("Calling a callback in " + timeout + "ms"); Thread.Sleep(timeout); action(); }); Action<string> logger = Console.WriteLine; Func<string, Tuple<string, string>> getModuleSource = name => { var fullScriptFileName = Path.GetFullPath(Path.Combine(_jsPath, name + ".js")); var scriptSource = File.ReadAllText(fullScriptFileName, Helper.UTF8NoBom); return Tuple.Create(scriptSource, fullScriptFileName); }; var preludeSource = getModuleSource("1Prelude"); var prelude = new PreludeScript(preludeSource.Item1, preludeSource.Item2, getModuleSource, _cancelCallbackFactory, logger); try { //var cancelToken = 123; prelude.ScheduleTerminateExecution(); Thread.Sleep(500); _commandHandlerRegisteredCallback = (name, handle) => { }; _reverseCommandHandlerDelegate = (name, body) => { }; Js1.CompileQuery( prelude.GetHandle(), "log(1);", "fn", _commandHandlerRegisteredCallback, _reverseCommandHandlerDelegate); prelude.CancelTerminateExecution(); } catch { prelude.Dispose(); // clean up unmanaged resources if failed to create throw; } }