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 string ExecuteHandler(IntPtr commandHandlerHandle, string json, string[] other = null) { IntPtr resultJsonPtr; IntPtr resultHandle = Js1.ExecuteCommandHandler( _script.GetHandle(), commandHandlerHandle, json, other, other != null ? other.Length : 0, out resultJsonPtr); if (resultHandle == IntPtr.Zero) { CompiledScript.CheckResult(_script.GetHandle(), disposeScriptOnException: false); } string resultJson = Marshal.PtrToStringUni(resultJsonPtr); Js1.FreeResult(resultHandle); return(resultJson); }
private string ExecuteHandler(IntPtr commandHandlerHandle, string json, string[] other = null) { _reverseCommandHandlerException = null; IntPtr resultJsonPtr; IntPtr resultHandle = Js1.ExecuteCommandHandler( _script.GetHandle(), commandHandlerHandle, json, other, other != null ? other.Length : 0, out resultJsonPtr); if (resultHandle == IntPtr.Zero) { CompiledScript.CheckResult(_script.GetHandle(), disposeScriptOnException: false); } //TODO: do we need to free resulktJsonPtr in case of exception thrown a line above string resultJson = Marshal.PtrToStringUni(resultJsonPtr); Js1.FreeResult(resultHandle); if (_reverseCommandHandlerException != null) { throw new ApplicationException( "An exception occurred while executing a reverse command handler. " + _reverseCommandHandlerException.Message, _reverseCommandHandlerException); } return(resultJson); }