public static void Call <TThis>(IntPtr info, Func <TThis, NSJSFunctionCallbackInfo, NSJSValue, NSJSValue> doo) { if (doo == null) { throw new ArgumentNullException("doo"); } NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); TThis self = NSJSKeyValueCollection.Get <TThis>(arguments.This); if (self == null) { Throwable.ObjectDisposedException(arguments.VirtualMachine); } else { try { NSJSValue solt0 = arguments.Length > 0 ? arguments[0] : null; doo(self, arguments, solt0); } catch (Exception exception) { Throwable.Exception(arguments.VirtualMachine, exception); } } }
private static void Flush(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); BaseStream stream = NSJSKeyValueCollection.Get <BaseStream>(arguments.This); if (stream == null) { Throwable.ObjectDisposedException(arguments.VirtualMachine); } else { Exception exception = null; bool success = false; try { stream.Flush(); } catch (Exception e) { exception = e; } if (exception != null) { Throwable.Exception(arguments.VirtualMachine, exception); } else { arguments.SetReturnValue(success); } } }
public static NSJSObject New(NSJSVirtualMachine machine, BaseStream stream) { if (machine == null || stream == null) { return(null); } NSJSObject o = NSJSObject.New(machine); o.Set("CanWrite", stream.CanWrite); o.Set("CanSeek", stream.CanSeek); o.Set("CanRead", stream.CanRead); o.DefineProperty("Length", m_LengthProc, (NSJSFunctionCallback)null); o.DefineProperty("Position", m_PositionProc, m_PositionProc); o.Set("Seek", m_SeekProc); o.Set("CopyTo", m_CopyToProc); o.Set("Read", m_ReadProc); o.Set("Write", m_WriteProc); o.Set("Flush", m_FlushProc); o.Set("ReadBytes", m_ReadBytesProc); o.Set("Close", m_DisposeProc); o.Set("Dispose", m_DisposeProc); NSJSKeyValueCollection.Set(o, stream); return(o); }
public static NSJSObject New(NSJSVirtualMachine machine, NSJSObject context, HTTPResponse response) { if (machine == null || context == null || response == null) { return(null); } NSJSObject objective = NSJSObject.New(machine); objective.Set("CurrentContext", context); objective.DefineProperty("ContentEncoding", g_ContentEncodingProc, g_ContentEncodingProc); objective.DefineProperty("ContentType", g_ContentTypeProc, g_ContentTypeProc); objective.DefineProperty("StatusDescription", g_StatusDescriptionProc, g_StatusDescriptionProc); objective.DefineProperty("StatusCode", g_StatusCodeProc, g_StatusCodeProc); objective.DefineProperty("KeepAlive", g_KeepAliveProc, g_KeepAliveProc); objective.DefineProperty("ProtocolVersion", g_ProtocolVersionProc, g_ProtocolVersionProc); objective.DefineProperty("RedirectLocation", g_RedirectLocationProc, g_RedirectLocationProc); objective.DefineProperty("SendChunked", g_SendChunkedProc, g_SendChunkedProc); objective.DefineProperty("Headers", g_HeadersProc, g_HeadersProc); objective.DefineProperty("Cookies", g_CookiesProc, g_CookiesProc); objective.Set("Redirect", g_RedirectProc); objective.Set("End", g_EndProc); objective.Set("Abort", g_AbortProc); objective.Set("SetCookie", g_SetCookieProc); objective.Set("AppendCookie", g_SetCookieProc); objective.Set("AddHeader", g_AddHeaderProc); objective.Set("AppendHeader", g_AddHeaderProc); objective.Set("Write", g_WriteProc); objective.Set("WriteFile", g_WriteFileProc); objective.Set("BinaryWrite", g_BinaryWriteProc); NSJSKeyValueCollection.Set(objective, response); return(objective); }
private static NSJSObject New(NSJSVirtualMachine machine, WebSocketListener server) { if (machine == null || server == null) { return(null); } NSJSObject objective = NSJSObject.New(machine); objective.Set("Port", server.Port); objective.Set("GetBindPort", g_GetBindPortProc); objective.Set("Stop", g_StopProc); objective.Set("Start", g_StartProc); objective.Set("Close", g_CloseProc); objective.Set("Dispose", g_CloseProc); server.UserToken = objective; objective.CrossThreading = true; server.OnMessage += (websocket, e) => ProcessEvent(objective, websocket, "OnMessage", e); server.OnOpen += (websocket, e) => ProcessEvent(objective, websocket, "OnOpen", e, true); server.OnError += (websocket, e) => ProcessEvent(objective, websocket, "OnError", e); server.OnClose += (websocket, e) => ProcessEvent(objective, websocket, "OnClose", e); NSJSKeyValueCollection.Set(objective, server); return(objective); }
private static void CopyTo(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); BaseStream stream = NSJSKeyValueCollection.Get <BaseStream>(arguments.This); if (stream == null) { Throwable.ObjectDisposedException(arguments.VirtualMachine); } else { BaseStream destination = NSJSKeyValueCollection.Get <BaseStream>(arguments.Length > 0 ? arguments[0] as NSJSObject : null); if (destination == null) { Throwable.ArgumentNullException(arguments.VirtualMachine); } else { try { stream.CopyTo(destination); } catch (Exception e) { Throwable.Exception(arguments.VirtualMachine, e); } } } }
public static NSJSObject NewContextObject(NSJSVirtualMachine machine, NSJSObject application, HTTPContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (application == null) { throw new ArgumentNullException("application"); } if (machine == null) { throw new ArgumentNullException("machine"); } NSJSObject objective = NSJSObject.New(machine); // ctx objective.Set("Application", application); objective.Set("Close", m_CloseProc); objective.Set("Dispose", m_CloseProc); objective.Set("Request", HttpRequest.New(machine, objective, context.Request)); objective.Set("Response", HttpResponse.New(machine, objective, context.Response)); objective.DefineProperty("Asynchronous", m_AsynchronousProc, m_AsynchronousProc); NSJSKeyValueCollection.Set(objective, context); return(objective); }
public static NSJSObject New(NSJSVirtualMachine machine, HTTPApplication application) { if (machine == null || application == null) { return(null); } NSJSObject objective = NSJSObject.New(machine); objective.DefineProperty("Name", g_NameProc, g_NameProc); objective.DefineProperty("Root", g_RootProc, g_RootProc); objective.Set("Start", g_StartProc); objective.Set("Stop", g_StopProc); objective.Set("Close", g_CloseProc); objective.Set("Dispose", g_CloseProc); application.Tag = objective; objective.CrossThreading = true; application.Handler = new HttpHandler(objective, application); application.EndProcessRequest += g_EndProcessRequestProc; application.BeginProcessRequest += g_BeginProcessRequestProc; NSJSKeyValueCollection.Set(objective, application); return(objective); }
private static void Dispose(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); RC4CSP provider; NSJSKeyValueCollection.Release(arguments.This, out provider); }
private static void Position(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); BaseStream stream = NSJSKeyValueCollection.Get <BaseStream>(arguments.This); if (stream == null) { Throwable.ObjectDisposedException(arguments.VirtualMachine); } else if (arguments.Length <= 0) { arguments.SetReturnValue(unchecked ((int)stream.Position)); } else { NSJSInt32 value = arguments[0] as NSJSInt32; if (value == null) { arguments.SetReturnValue(false); } else { try { stream.Position = value.Value; arguments.SetReturnValue(true); } catch (Exception e) { Throwable.Exception(arguments.VirtualMachine, e); } } } }
public static NSJSObject New(NSJSVirtualMachine machine, ENCODING encoding) { lock (g_Locker) { if (machine == null || encoding == null) { return(null); } IDictionary <IntPtr, NSJSObject> dVirtualTables; if (!g_EncodingInstanceTable.TryGetValue(encoding.CodePage, out dVirtualTables)) { dVirtualTables = new Dictionary <IntPtr, NSJSObject>(); g_EncodingInstanceTable.Add(encoding.CodePage, dVirtualTables); } NSJSObject o; if (dVirtualTables.TryGetValue(machine.Isolate, out o)) { return(o); } if (!g_UninitializedEncoding) { g_UninitializedEncoding = true; g_GetBytesProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(GetBytes); g_GetStringProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(GetString); } o = NSJSObject.New(machine); o.CrossThreading = true; o.Set("GetBytes", g_GetBytesProc); o.Set("GetString", g_GetStringProc); dVirtualTables.Add(machine.Isolate, o); NSJSKeyValueCollection.Set(o, encoding); return(o); } }
private void EncryptOrDecrypt(IntPtr info, bool decrypt) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); RijndaelCryptoServiceProvider provider = NSJSKeyValueCollection.Get <RijndaelCryptoServiceProvider>(arguments.This); if (provider == null) { Throwable.ObjectDisposedException(arguments.VirtualMachine); } else { byte[] result = null; Exception exception = null; if (arguments.Length > 0) { byte[] buffer = (arguments[0] as NSJSUInt8Array)?.Buffer; if (buffer != null) { int ofs = 0; if (arguments.Length > 1) { ofs = ((arguments[1] as NSJSInt32)?.Value).GetValueOrDefault(); } int count = buffer.Length; if (arguments.Length > 2) { count = ((arguments[2] as NSJSInt32)?.Value).GetValueOrDefault(); } try { if (decrypt) { result = provider.Decrypt(buffer, ofs, count); } else { result = provider.Encrypt(buffer, ofs, count); } } catch (Exception e) { exception = e; } } } if (exception != null) { Throwable.Exception(arguments.VirtualMachine, exception); } else if (result != null) { arguments.SetReturnValue(result); } else { Throwable.ArgumentNullException(arguments.VirtualMachine, exception); } } }
public static ENCODING GetEncoding(NSJSObject value) { if (value == null) { return(DefaultEncoding); } return(NSJSKeyValueCollection.Get <ENCODING>(value)); }
public static HTTPApplication GetApplication(NSJSObject application) { if (application == null) { return(null); } return(NSJSKeyValueCollection.Get <HTTPApplication>(application)); }
public static HTTPResponse GetResponse(NSJSObject response) { if (response == null) { return(null); } return(NSJSKeyValueCollection.Get <HTTPResponse>(response)); }
private static void GetString(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); ENCODING encoding = NSJSKeyValueCollection.Get <ENCODING>(arguments.This); if (encoding == null) { Throwable.ObjectDisposedException(arguments.VirtualMachine); } else { string s = null; if (arguments.Length > 0) { NSJSUInt8Array chars = arguments[0] as NSJSUInt8Array; if (chars != null) { byte[] buffer = chars.Buffer; if (buffer != null) { NSJSInt32 index = null; NSJSInt32 len = null; switch (arguments.Length) { case 2: len = arguments[1] as NSJSInt32; break; case 3: index = arguments[1] as NSJSInt32; len = arguments[2] as NSJSInt32; break; } int ofs = index != null ? index.Value : 0; int count = len != null ? len.Value : buffer.Length; if (count < 0) { count = 0; } if (ofs < 0) { ofs = 0; } s = encoding.GetString(buffer, ofs, count); } } } if (s != null) { arguments.SetReturnValue(s); } else { arguments.SetReturnValue(NSJSValue.Undefined(arguments.VirtualMachine)); } } }
private static NSJSObject New(NSJSVirtualMachine machine, RC4CSP provider) { NSJSObject o = NSJSObject.New(machine); o.Set("Encrypt", m_EncryptProc); o.Set("Decrypt", m_DecryptProc); o.Set("Dispose", m_DisposeProc); NSJSKeyValueCollection.Set(o, provider); return(o); }
private NSJSObject New(NSJSVirtualMachine machine, RijndaelCryptoServiceProvider provider) { NSJSObject o = NSJSObject.New(machine); o.Set("Encrypt", this.m_EncryptProc); o.Set("Decrypt", this.m_DecryptProc); o.Set("Dispose", this.m_DisposeProc); NSJSKeyValueCollection.Set(o, provider); return(o); }
public static bool RemoveInKeyValueCollection(NSJSObject value) { if (value == null) { return(false); } object result; return(NSJSKeyValueCollection.Release(value, out result)); }
private void Dispose(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); RijndaelCryptoServiceProvider provider; NSJSKeyValueCollection.Release <RijndaelCryptoServiceProvider>(arguments.This, out provider); if (provider != null) { provider.Dispose(); } }
private static void Dispose(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); BaseStream stream; NSJSKeyValueCollection.Release(arguments.This, out stream); if (stream != null) { stream.Dispose(); } }
private static void Length(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); BaseStream stream = NSJSKeyValueCollection.Get <BaseStream>(arguments.This); if (stream == null) { Throwable.ObjectDisposedException(arguments.VirtualMachine); } else { arguments.SetReturnValue(unchecked ((int)stream.Length)); } }
public static NSJSObject New(NSJSVirtualMachine machine, MailClient smtp) { if (machine == null || smtp == null) { return(null); } NSJSObject o = NSJSObject.New(machine); o.Set("Send", g_SendProc); o.Set("SendAsync", m_SendAsyncProc); o.Set("Close", g_CloseProc); o.Set("Dispose", g_CloseProc); NSJSKeyValueCollection.Set(o, smtp); return(o); }
public static NSJSObject New(NSJSVirtualMachine machine, IDbTransaction transaction) { if (machine == null || transaction == null) { return(null); } NSJSObject o = NSJSObject.New(machine); o.Set("Commit", g_CommitProc); o.Set("Rollback", g_RollbackProc); o.Set("Close", g_CloseProc); o.Set("Dispose", g_CloseProc); NSJSKeyValueCollection.Set(o, transaction); return(o); }
public static NSJSObject New(NSJSVirtualMachine machine, DATATableGateway gateway) { if (machine == null || gateway == null) { return(null); } NSJSObject o = NSJSObject.New(machine); o.Set("Select", g_SelectProc); o.Set("Close", g_CloseProc); o.Set("Dispose", g_CloseProc); o.Set("ExecuteNonQuery", g_ExecuteNonQueryProc); o.Set("DeriveParameters", g_DeriveParametersProc); o.Set("BeginTransaction", g_BeginTransactionProc); NSJSKeyValueCollection.Set(o, gateway); return(o); }
public static void Close(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); IDbTransaction transaction; NSJSKeyValueCollection.Release(arguments.This, out transaction); if (transaction != null) { try { transaction.Dispose(); } catch (Exception exception) { Throwable.Exception(arguments.VirtualMachine, exception); } } }
private static void Seek(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); BaseStream stream = NSJSKeyValueCollection.Get <BaseStream>(arguments.This); if (stream == null) { Throwable.ObjectDisposedException(arguments.VirtualMachine); } else { Exception exception = null; int offset = 0; int? result = null; if (stream != null) { SeekOrigin origin = SeekOrigin.Begin; if (arguments.Length > 0) { offset = ((arguments[0] as NSJSInt32)?.Value).GetValueOrDefault(); } if (arguments.Length > 1) { origin = (SeekOrigin)((arguments[1] as NSJSInt32)?.Value).GetValueOrDefault(); } try { result = unchecked ((int)stream.Seek(offset, origin)); } catch (Exception e) { exception = e; } } if (exception != null) { Throwable.Exception(arguments.VirtualMachine, exception); } else { arguments.SetReturnValue(result.GetValueOrDefault()); } } }
public static NSJSObject New(NSJSVirtualMachine machine, WebSocket websocket) { if (machine == null || websocket == null) { return(null); } object usertoken = websocket.UserToken; if (usertoken != null) { return(usertoken as NSJSObject); } NSJSObject objective = NSJSObject.New(machine); objective.Set("Open", m_OpenProc); objective.Set("Close", m_CloseProc); objective.Set("Dispose", m_CloseProc); objective.Set("Send", m_SendProc); objective.Set("Path", websocket.Path); objective.Set("Ttl", websocket.Ttl); objective.Set("Handle", websocket.Handle.ToInt32()); objective.Set("LocalEndPoint", ObjectAuxiliary.ToObject(machine, websocket.LocalEndPoint)); objective.Set("RemoteEndPoint", ObjectAuxiliary.ToObject(machine, websocket.RemoteEndPoint)); objective.Set("OnMessage", NSJSValue.Null(machine)); objective.Set("OnClose", NSJSValue.Null(machine)); objective.Set("OnError", NSJSValue.Null(machine)); objective.Set("OnOpen", NSJSValue.Null(machine)); websocket.OnMessage += m_OnMessageProc; websocket.OnOpen += m_OnOpenProc; websocket.OnError += m_OnErrorProc; websocket.OnClose += m_OnCloseProc; websocket.UserToken = objective; objective.CrossThreading = true; objective.DefineProperty("NoDelay", m_NoDelayProc, m_NoDelayProc); objective.DefineProperty("Available", m_AvailableProc, (NSJSFunctionCallback)null); NSJSKeyValueCollection.Set(objective, websocket); return(objective); }
private static void ReadBytes(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); BaseStream stream = NSJSKeyValueCollection.Get <BaseStream>(arguments.This); if (stream == null) { Throwable.ObjectDisposedException(arguments.VirtualMachine); } else { NSJSValue result = null; Exception exception = null; if (arguments.Length > 0) { int max = ((arguments[0] as NSJSInt32)?.Value).GetValueOrDefault(); if (max >= 0) { try { byte[] ch = new byte[max]; int len = stream.Read(ch, 0, max); result = NSJSUInt8Array.New(arguments.VirtualMachine, ch, len); } catch (Exception e) { exception = e; } } } if (exception != null) { Throwable.Exception(arguments.VirtualMachine, exception); } else if (result != null) { arguments.SetReturnValue(result); } else { arguments.SetReturnValue(NSJSValue.Undefined(arguments.VirtualMachine)); } } }
private static void GetOrSetProperty <TThis>(IntPtr info, Action <TThis, NSJSFunctionCallbackInfo> get, Action <TThis, NSJSFunctionCallbackInfo, NSJSValue> set) { if (info == NULL) { throw new ArgumentNullException("info"); } if (get == null) { throw new ArgumentNullException("get"); } if (set == null) { throw new ArgumentNullException("set"); } NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); TThis response = NSJSKeyValueCollection.Get <TThis>(arguments.This); if (response == null) { Throwable.ObjectDisposedException(arguments.VirtualMachine); } else { NSJSVirtualMachine machine = arguments.VirtualMachine; if (arguments.Length <= 0) { get(response, arguments); } else { try { set(response, arguments, arguments[0]); arguments.SetReturnValue(true); } catch (Exception exception) { Throwable.Exception(arguments.VirtualMachine, exception); } } } }