Пример #1
0
 public IronJS.Object CreateServer(IronJS.Function callback)
 {
     Console.WriteLine("net.createServer() called.");
     Net.NetServer server = new Net.NetServer(callback, Env);
     Console.WriteLine(server);
     return(server);
 }
Пример #2
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++)
     {
         // ( ( IFunction )listeningCallbacks[i] ).Call( this, new object[]{} );
         IronJS.Function func = (IronJS.Function)listeningCallbacks[i];
         Action <IronJS.Function, IronJS.Object, object[]> fun =
             func.Compiler.compileAs <Action <IronJS.Function, IronJS.Object, object[]> >(func);
         fun.Invoke(func, func.Env.Globals, new object[] {});
     }
 }
Пример #3
0
 public void addListener(string eventname, IronJS.Function callback)
 {
     Console.WriteLine("NetStream: adding listener: " + eventname);
     if (eventname == "data")
     {
         dataCallbacks.Add(callback);
     }
     else if (eventname == "end")
     {
         endCallbacks.Add(callback);
     }
 }
Пример #4
0
 public void raiseEndEvent(object[] args)
 {
     Console.WriteLine("net.stream.raiseEndEvent()");
     for (var i = 0; i < endCallbacks.Count; i++)
     {
         // ( ( IFunction )endCallbacks[i] ).Call( this, new object[] {} );
         IronJS.Function func = (IronJS.Function)endCallbacks[i];
         Action <IronJS.Function, IronJS.Object, object[]> fun =
             func.Compiler.compileAs <Action <IronJS.Function, IronJS.Object, object[]> >(func);
         fun.Invoke(func, func.Env.Globals, new object[] {});
     }
 }
Пример #5
0
        public void raiseConnectionEvent(object[] args)
        {
            NetStream stream = ( NetStream )args[0];

            Console.WriteLine("http.server.raiseConnectionEvent() - calling " + connectionCallbacks.Count + " callbacks");

            foreach (object callback in connectionCallbacks)
            {
                Console.WriteLine("calling js function callback");
                // ( ( IFunction )callback ).Call( this, new object[] { stream } );
                IronJS.Function func = (IronJS.Function)callback;
                Action <IronJS.Function, IronJS.Object, IronJS.Object> fun =
                    func.Compiler.compileAs <Action <IronJS.Function, IronJS.Object, IronJS.Object> >(func);
                fun.Invoke(func, this, stream);
            }
        }
Пример #6
0
        public void raiseDataEvent(object[] args)
        {
            string chunk = ( string )args[0];

            Console.WriteLine("net.stream.raiseDataEvent():" + chunk);
            for (var i = 0; i < dataCallbacks.Count; i++)
            {
                // ( ( IronJS.Function )dataCallbacks[i] ).Call( this, new object[] { chunk } );
                IronJS.Function func = (IronJS.Function)dataCallbacks[i];
                Action <IronJS.Function, IronJS.Object, string> fun =
                    func.Compiler.compileAs <Action <IronJS.Function, IronJS.Object, string> >(func);
                // fun.Invoke(func, func.Env.Globals, new object[] {chunk} );
                Console.WriteLine("invoking JS raiseDataEvent callback");
                fun.Invoke(func, this, chunk);
            }
        }
Пример #7
0
        public NetServer(IronJS.Function 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
            Env     = env;
            Methods = Env.Methods.Object;

            // Prototype = context.ObjectConstructor.Object_prototype;
            // Class = ObjClass.Array;

            Console.WriteLine("creating NetServer");

            //this.SetOwnProperty( "listen", new Action<object, string>( listen ) );
            var objMethod = IronJS.Api.HostFunction.create <Action <object, string> >(env, listen);

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

            this.addListener("connection", callback);
        }
Пример #8
0
 public void addListener(string eventname, IronJS.Function callback)
 {
     Console.WriteLine("NetServer - 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");
     }
 }