示例#1
0
 public IronJS.CommonObject CreateServer(IronJS.FunctionObject callback)
 {
     Console.WriteLine("http.createServer() called.");
     Http.HttpServer server = new Http.HttpServer(callback, Env);
     Console.WriteLine(server);
     return(server);
 }
示例#2
0
 public IronJS.CommonObject CreateServer(IronJS.FunctionObject callback)
 {
     log.Trace("net.createServer() called.");
     Net.NetServer server = new Net.NetServer(callback, Env);
     log.Trace(server);
     return(server);
 }
示例#3
0
 public void raiseEndEvent(object[] args)
 {
     log.Trace("net.stream.raiseEndEvent()");
     for (var i = 0; i < endCallbacks.Count; i++)
     {
         IronJS.FunctionObject func = (IronJS.FunctionObject)endCallbacks[i];
         func.Call(this);
     }
 }
示例#4
0
        public void raiseDataEvent(object[] args)
        {
            string chunk = ( string )args[0];

            log.Trace("net.stream.raiseDataEvent():" + chunk);
            for (var i = 0; i < dataCallbacks.Count; i++)
            {
                IronJS.FunctionObject func = (IronJS.FunctionObject)dataCallbacks[i];
                func.Call <string>(this, chunk);
            }
        }
示例#5
0
        public HttpServer(IronJS.FunctionObject callback, IronJS.Environment env) : base(env, env.Maps.Base, env.Prototypes.Object, IronJS.Classes.Object)
        {
            // have to set this stuff up. not sure why yet

            Console.WriteLine("creating HttpServer");
            var objMethod = Utils.createHostFunction <Action <object, string> >(env, listen);

            // this.Methods.PutRefProperty(this, "listen", objMethod, IronJS.TypeTags.Function);
            this.Put("listen", objMethod, TypeTags.Function)

            this.addListener("connection", callback);
        }
示例#6
0
 public void addListener(string eventname, IronJS.FunctionObject callback)
 {
     Server.instance.Listeners++;
     log.Trace("NetStream: adding listener: " + eventname);
     if (eventname == "data")
     {
         dataCallbacks.Add(callback);
     }
     else if (eventname == "end")
     {
         endCallbacks.Add(callback);
     }
 }
示例#7
0
        // TODO: pull this stuff out to an event class
        public void raiseListeningEvent(object[] args)
        {
            Console.WriteLine("http.server.raiseListeningEvent()");
            for (var i = 0; i < listeningCallbacks.Count; i++)
            {
                // ( ( IronJS.FunctionObject )listeningCallbacks[i] ).Call( this, new object[]{} );
                IronJS.FunctionObject func = (IronJS.FunctionObject)listeningCallbacks[i];

                /*
                 * Action<IronJS.FunctionObject,IronJS.CommonObject,object[]> fun =
                 *      func.Compiler.compileAs<Action<IronJS.FunctionObject,IronJS.CommonObject,object[]>>(func);
                 * fun.Invoke(func, func.Env.Globals, new object[] {} );
                 */
                func.Call(this, new BoxedValue[] { });
            }
        }
示例#8
0
 public void addListener(string eventname, IronJS.FunctionObject callback)
 {
     Console.WriteLine("HttpServerRequest - adding listener: " + eventname);
     if (eventname == "data")
     {
         netStream.addListener("data", callback);
     }
     else if (eventname == "end")
     {
         netStream.addListener("end", callback);
     }
     else
     {
         throw new Exception("addListener called for unsupported event");
     }
 }
示例#9
0
        public void raiseConnectionEventCont()
        {
            Console.WriteLine("raiseConnectionEventCont()");
            foreach (object callback in connectionCallbacks)
            {
                // ( ( IFunction )callback ).Call( this, new object[] { req, resp } );
                IronJS.FunctionObject func = (IronJS.FunctionObject)callback;

                /*
                 * Action<IronJS.FunctionObject,IronJS.CommonObject,IronJS.CommonObject,IronJS.CommonObject> fun =
                 *      func.Compiler.compileAs<Action<IronJS.FunctionObject,IronJS.CommonObject,IronJS.CommonObject,IronJS.CommonObject>>(func);
                 * fun.Invoke(func, this, req, resp );
                 */
                func.Call <HttpServerRequest, HttpServerResponse>(this, req, resp);                  // func.Env.Globals for this?
            }
        }
示例#10
0
        public NetServer(IronJS.FunctionObject callback, IronJS.Environment env) : base(env)
        {
            // TODO: move as much of this as possible to EventEmitter
            Callbacks = new Dictionary <string, ArrayList>()
            {
                { "connect", new ArrayList() },
                { "close", new ArrayList() }
            };

            log.Trace("creating NetServer");

            var objMethod = Utils.createHostFunction <Func <object, string, CommonObject> >(env, listen);

            var removeAllListenersMethod = Utils.createHostFunction <Action <string> >(env, removeAllListeners);

            this.Put("listen", objMethod, TypeTags.Function);
            this.Put("removeAllListeners", removeAllListenersMethod, TypeTags.Function);
            this.addListener("connect", callback);
        }
示例#11
0
 public void addListener(string eventname, IronJS.FunctionObject callback)
 {
     Console.WriteLine("HttpServer - adding listener: " + eventname);
     if (eventname == "listening")
     {
         listeningCallbacks.Add(callback);
     }
     else if (eventname == "connection")
     {
         connectionCallbacks.Add(callback);
     }
     else if (eventname == "close")
     {
         closeCallbacks.Add(callback);
     }
     else
     {
         throw new Exception("addListener called for unsupported event");
     }
 }
示例#12
0
 public void addListener(string eventname, IronJS.FunctionObject callback)
 {
     log.Trace("NetServer - adding listener: " + eventname);
     on(eventname, callback);
 }