Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 public void SetReturnValue(NSJSFunctionCallback callback)
 {
     if (callback == null)
     {
         this.SetReturnValue(NSJSValue.Null(this.VirtualMachine));
         return;
     }
     this.SetReturnValue(NSJSFunction.New(This.VirtualMachine, callback));
 }
Exemplo n.º 3
0
 static Mail()
 {
     NSJSVirtualMachine.ExtensionObjectTemplate owner = new NSJSVirtualMachine.ExtensionObjectTemplate();
     ClassTemplate = owner;
     owner.Set("New", NSJSPinnedCollection.Pinned <NSJSFunctionCallback2>(New));
     g_SendProc      = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Send);
     g_CloseProc     = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Close);
     m_SendAsyncProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(SendAsync);
 }
Exemplo n.º 4
0
        public static NSJSFunction New(NSJSVirtualMachine machine, NSJSFunctionCallback value)
        {
            IntPtr address = NULL;

            if (value != null)
            {
                address = NSJSFunction.DelegateToFunctionPtr(value);
            }
            return(InternalNew(machine, address));
        }
Exemplo n.º 5
0
        public RijndaelAlgorithm()
        {
            NSJSVirtualMachine.ExtensionObjectTemplate owner = new NSJSVirtualMachine.ExtensionObjectTemplate();
            ClassTemplate = owner;
            ClassTemplate.Set("New", NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(New));

            this.m_EncryptProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(this.Encrypt);
            this.m_DecryptProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(this.Decrypt);
            this.m_DisposeProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(this.Dispose);
        }
Exemplo n.º 6
0
        static RC4()
        {
            NSJSVirtualMachine.ExtensionObjectTemplate owner = new NSJSVirtualMachine.ExtensionObjectTemplate();
            ClassTemplate = owner;
            owner.Set("New", NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(New));

            m_EncryptProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Encrypt);
            m_DecryptProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Decrypt);
            m_DisposeProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Dispose);
        }
Exemplo n.º 7
0
 static DataTableGateway()
 {
     NSJSVirtualMachine.ExtensionObjectTemplate owner = new NSJSVirtualMachine.
                                                        ExtensionObjectTemplate();
     ClassTemplate = owner;
     owner.Set("New", NSJSPinnedCollection.Pinned <NSJSFunctionCallback2>(New));
     owner.Set("Invalid", NSJSPinnedCollection.Pinned <NSJSFunctionCallback2>(Invalid));
     g_CloseProc            = NSJSPinnedCollection.Pinned <NSJSFunctionCallback2>(Close);
     g_SelectProc           = NSJSPinnedCollection.Pinned <NSJSFunctionCallback2>(Select);
     g_ExecuteNonQueryProc  = NSJSPinnedCollection.Pinned <NSJSFunctionCallback2>(ExecuteNonQuery);
     g_DeriveParametersProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback2>(DeriveParameters);
     g_BeginTransactionProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(BeginTransaction);
 }
Exemplo n.º 8
0
 public virtual void DefineProperty(string key, NSJSFunctionCallback get, NSJSFunctionCallback set)
 {
     this.InternalDefineProperty(key, (machine, function) =>
     {
         NSJSValue[] s = new NSJSValue[]
         {
             this,
             NSJSString.New(machine, key),
             get == null ? NSJSValue.Undefined(machine) : NSJSFunction.New(machine, get),
             set == null ? NSJSValue.Undefined(machine) : NSJSFunction.New(machine, set),
         };
         function.Call(s);
     });
 }
Exemplo n.º 9
0
 static HttpApplication()
 {
     NSJSVirtualMachine.ExtensionObjectTemplate owner = new NSJSVirtualMachine.ExtensionObjectTemplate();
     ClassTemplate = owner;
     g_StartProc   = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Start);
     g_StopProc    = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Stop);
     g_RootProc    = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Root);
     g_NameProc    = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Name);
     g_CloseProc   = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Close);
     owner.Set("New", NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(New));
     owner.Set("Invalid", NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Invalid));
     g_EndProcessRequestProc   = OnEndProcessRequest;
     g_BeginProcessRequestProc = OnBeginProcessRequest;
 }
Exemplo n.º 10
0
 static HttpResponse()
 {
     g_ContentEncodingProc   = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(ContentEncoding);
     g_ContentTypeProc       = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(ContentType);
     g_StatusDescriptionProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(StatusDescription);
     g_StatusCodeProc        = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(StatusCode);
     g_KeepAliveProc         = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(KeepAlive);
     g_ProtocolVersionProc   = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(ProtocolVersion);
     g_RedirectLocationProc  = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(RedirectLocation);
     g_SendChunkedProc       = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(SendChunked);
     g_HeadersProc           = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Headers);
     g_RedirectProc          = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Redirect);
     g_WriteProc             = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Write);
     g_WriteFileProc         = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(WriteFile);
     g_BinaryWriteProc       = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(BinaryWrite);
     g_EndProc       = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(End);
     g_AbortProc     = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Abort);
     g_SetCookieProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(SetCookie);
     g_AddHeaderProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(AddHeader);
     g_CookiesProc   = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Cookies);
 }
Exemplo n.º 11
0
 static Socket()
 {
     NSJSVirtualMachine.ExtensionObjectTemplate owner = new NSJSVirtualMachine.ExtensionObjectTemplate();
     ClassTemplate = owner;
     owner.Set("New", NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(New));
     owner.Set("Invalid", NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Invalid));
     owner.Set("GetActiveTcpListeners", NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(GetActiveTcpListeners));
     owner.Set("GetActiveTcpListeners", NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(GetActiveUdpListeners));
     m_SendProc             = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Send);
     m_BindProc             = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Bind);
     m_CloseProc            = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Close);
     m_ConnectProc          = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Connect);
     m_ReceiveProc          = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Receive);
     m_AcceptProc           = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Accept);
     m_ConnectedProc        = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(Connected);
     m_ConnectAsyncProc     = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(ConnectAsync);
     m_AcceptAsyncProc      = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(AcceptAsync);
     m_SendAsyncProc        = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(SendAsync);
     m_ReceiveAsyncProc     = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(ReceiveAsync);
     m_SendToProc           = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(SendTo);
     m_SendToAsyncProc      = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(SendToAsync);
     m_ReceiveFromProc      = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(ReceiveFrom);
     m_ReceiveFromAsyncProc = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(ReceiveFromAsync);
 }
Exemplo n.º 12
0
        protected internal static NSJSValue ToObject(NSJSVirtualMachine machine, object obj)
        {
            if (machine == null)
            {
                return(null);
            }
            if (obj == null)
            {
                return(NSJSValue.Null(machine));
            }
            Type       owner     = obj.GetType();
            NSJSObject objective = NSJSObject.New(machine);

            foreach (MemberInfo mi in InternalCheckKeyMembers(owner).Values)
            {
                PropertyInfo pi    = mi as PropertyInfo;
                FieldInfo    fi    = mi as FieldInfo;
                object       value = null;
                Type         clazz = null;
                string       key   = mi.Name;
                if (pi != null)
                {
                    clazz = pi.PropertyType;
                    value = pi.GetValue(obj, null);
                }
                else
                {
                    clazz = fi.FieldType;
                    value = fi.GetValue(obj);
                }
                NSJSValue result = null;
                do
                {
                    if (value == null)
                    {
                        break;
                    }
                    Type element = TypeTool.GetArrayElement(clazz);
                    if (element == null && value is IList)
                    {
                        result = ArrayAuxiliary.ToArray(machine, element, (IList)value);
                    }
                    else if (TypeTool.IsBasicType(clazz) && !TypeTool.IsIPAddress(clazz))
                    {
                        result = value.As(machine);
                    }
                    else
                    {
                        result = ToObject(machine, value);
                    }
                } while (false);
                if (result == null)
                {
                    result = NSJSValue.Null(machine);
                }
                objective.Set(key, result);
            }
            NetToObjectCallables callables = InternalCheckNetToObjectCallables(owner);

            if (callables != null)
            {
                if (callables.funcs != null)
                {
                    foreach (MethodInfo m in callables.funcs)
                    {
                        objective.Set(m.Name, NSJSPinnedCollection.Pinned(Complier(m)));
                    }
                }
                if (callables.props != null)
                {
                    foreach (PropertyInfo p in callables.props)
                    {
                        MethodInfo           gm  = p.GetGetMethod();
                        NSJSFunctionCallback get = null;
                        NSJSFunctionCallback set = null;
                        if (gm != null)
                        {
                            get = NSJSPinnedCollection.Pinned(Complier(gm));
                        }
                        MethodInfo sm = p.GetSetMethod();
                        if (sm != null)
                        {
                            set = NSJSPinnedCollection.Pinned(Complier(sm));
                        }
                        if (set != null || get != null)
                        {
                            objective.DefineProperty(p.Name, get, set);
                        }
                    }
                }
                objective.Set("Dispose", FDEFAULTDISPOSE);
                if (!objective.IsDefined("Close"))
                {
                    objective.Set("Close", FDEFAULTDISPOSE);
                }
                NSJSKeyValueCollection.Set(objective, obj);
            }
            return(objective);
        }
Exemplo n.º 13
0
 public virtual bool Set(string key, NSJSFunctionCallback value)
 {
     return(InternalSet(key, value));
 }
Exemplo n.º 14
0
 public virtual bool Set(string name, NSJSFunctionCallback value, PropertyAttribute attributes = PropertyAttribute.None)
 {
     return(InternalSet(name, value, attributes));
 }
Exemplo n.º 15
0
 public ExtensionObjectTemplate(NSJSFunctionCallback constructor) : this((Delegate)constructor)
 {
 }