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 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); } } } }
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); } } } }
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); } } }
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 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)); } }
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()); } } }
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); } } } }
public static BaseStream Get(NSJSObject stream) { return(NSJSKeyValueCollection.Get <BaseStream>(stream)); }
public static DATATableGateway GetGateway(NSJSObject value) { return(NSJSKeyValueCollection.Get <DATATableGateway>(value)); }
public static IDbTransaction GetTransaction(NSJSObject value) { return(NSJSKeyValueCollection.Get <IDbTransaction>(value)); }
private static void Write(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; if (arguments.Length > 0) { NSJSUInt8Array buffer = arguments[0] as NSJSUInt8Array; if (buffer != null) { int?count = null; int offset = 0; switch (arguments.Length) { case 2: count = (arguments[1] as NSJSInt32)?.Value; break; case 3: offset = ((arguments[1] as NSJSInt32)?.Value).GetValueOrDefault(); count = (arguments[2] as NSJSInt32)?.Value; break; } if (offset < 0) { offset = 0; } if (count == null) { count = buffer.Length; } if ((offset + count) > buffer.Length) { count = (buffer.Length - offset); } if (!(offset < 0 || offset >= count)) { try { stream.Write(buffer.Buffer, offset, count.Value); } catch (Exception e) { exception = e; } } } } if (exception != null) { Throwable.Exception(arguments.VirtualMachine, exception); } else { arguments.SetReturnValue(success); } } }
public static DatabaseAccessAdapter GetAdapter(NSJSObject value) { return(NSJSKeyValueCollection.Get <DatabaseAccessAdapter>(value)); }
private static void Read(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? len = null; if (arguments.Length > 0) { NSJSUInt8Array buffer = arguments[0] as NSJSUInt8Array; if (buffer != null) { int?count = null; int offset = 0; switch (arguments.Length) { case 2: count = ((arguments[1] as NSJSInt32)?.Value).GetValueOrDefault(); break; case 3: offset = ((arguments[1] as NSJSInt32)?.Value).GetValueOrDefault(); count = (arguments[2] as NSJSInt32)?.Value; break; } if (offset < 0) { offset = 0; } if (count == null) { count = buffer.Length; } if ((offset + count) > buffer.Length) { count = (buffer.Length - offset); } if (offset < 0 || offset >= count) { len = 0; } else { try { byte[] cch = new byte[count.Value]; len = stream.Read(cch, offset, cch.Length); if (len > 0) { for (int i = offset; i < len; i++) { buffer[i] = cch[i]; } } } catch (Exception e) { exception = e; } } } } if (exception != null) { Throwable.Exception(arguments.VirtualMachine, exception); } else { arguments.SetReturnValue(len.GetValueOrDefault()); } } }