Exemple #1
0
 private static void AssetDate(EcmaHeadObject obj)
 {
     if (obj.Class != "Date")
     {
         throw new EcmaRuntimeException("Cant call this function without the object is a Date object");
     }
 }
Exemple #2
0
        public EcmaValue Include(EcmaHeadObject self, EcmaValue[] arg)
        {
            string a = arg[0].ToString(state);

            switch (a)
            {
            case "System.Class":
                return(EcmaValue.Object(new NativeFunctionInstance(1, state, GetClass)));

            case "System.Alert":
                return(EcmaValue.Object(new NativeFunctionInstance(1, state, Alert)));

            case "System.IO.File.GetContents":
                return(EcmaValue.Object(new NativeFunctionInstance(1, state, GetFileContents)));

            case "System.IO.File.PutContents":
                return(EcmaValue.Object(new NativeFunctionInstance(2, state, PutFileContents)));

            case "System.Hash.Sha1":
                return(EcmaValue.Object(new NativeFunctionInstance(1, state, Sha1)));

            case "System.IO.File":
                return(GetFil());

            case "System.Encoding.Ben":
                return(LoadScriptFile("Include/Encoding/Ben.js"));

            default:
                return(LoadScriptFile("Script/" + a));
            }
        }
Exemple #3
0
        private EcmaValue OpenNewServerDialog(EcmaHeadObject self, EcmaValue[] args)
        {
            NewServer server = new NewServer(args[0].ToObject(this.Client.State), this.Client.State);

            server.Show(this);
            return(EcmaValue.Undefined());
        }
Exemple #4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            this.Form1_Resize(this, new EventArgs());
            EcmaHeadObject Main = this.Client.GetVariabel("main").ToObject(this.Client.State);

            (Main as ICallable).Call(Main, new EcmaValue[0]);
        }
Exemple #5
0
        public void AppendChannel(string identify, string channel)
        {
            this.channel1.CreateChannel(identify, channel);

            this.AppendNodeChannel(identify, channel);

            if (channel.IndexOf("#") == 0)
            {
                this.channel1.Write(identify, channel, "", "You joined the channel");
            }

            if (this.ScriptClient.HasProperty("onOwnJoin"))
            {
                EcmaHeadObject callable = this.ScriptClient.Get("onOwnJoin").ToObject(Client.State);
                if (callable is ICallable)
                {
                    (callable as ICallable).Call(this.ScriptClient, new EcmaValue[]
                    {
                        EcmaValue.String(identify),
                        EcmaValue.String(channel)
                    });
                }
            }


            IrcConection connection = this.GetConnection(identify);

            if (connection.scriptAction.ContainsKey("channel.open"))
            {
                connection.DoAction("channel.open", EcmaValue.String(channel).ToObject(connection.script.State));
            }
        }
Exemple #6
0
        public static void Init(EcmaScript energy)
        {
            EcmaHeadObject obj = new EcmaHeadObject();

            obj.Class = "MysqlConnector";
            obj.Put("connect", EcmaValue.Object(new NativeFunctionInstance(4, energy.State, (EcmaHeadObject o, EcmaValue[] arg) =>
            {
                MySqlConnection connection = new MySqlConnection("SERVER=" + arg[0].ToString(energy.State) + ";UID=" + arg[1].ToString(energy.State) + ";PASSWORD="******";DATABASE=" + arg[3].ToString(energy.State) + ";");
                try
                {
                    connection.Open();
                    return(EcmaValue.Object(new MysqlValue(energy.State, connection)));
                }
                catch (MySqlException)
                {
                    return(EcmaValue.Null());
                }
            })));
            energy.CreateVariable("MysqlConnector", EcmaValue.Object(obj));

            obj       = new EcmaHeadObject();
            obj.Class = "Mysql";
            obj.Put("escape", EcmaValue.Object(new NativeFunctionInstance(1, energy.State, (EcmaHeadObject o, EcmaValue[] arg) =>
            {
                return(EcmaValue.String(MySqlHelper.EscapeString(arg[0].ToString(energy.State))));
            })));
        }
Exemple #7
0
 private EcmaValue On(EcmaHeadObject obj, EcmaValue[] args)
 {
     if (!this.connection.scriptEvenets.ContainsKey(args[0].ToString(this.energy.State)))
     {
         this.connection.scriptEvenets.Add(args[0].ToString(this.energy.State), args[1].ToObject(this.energy.State));
     }
     return(EcmaValue.Null());
 }
Exemple #8
0
        private EcmaValue Privmsg(EcmaHeadObject obj, EcmaValue[] args)
        {
            this.connection.SendLine("PRIVMSG " + args[0].ToString(this.energy.State) + " :" + args[1].ToString(this.energy.State));
            this.connection.Flush();
            this.main.channel1.Write(this.connection.GetIdentify(), args[0].ToString(this.energy.State), this.connection.GetNick(), args[1].ToString(this.energy.State));

            return(EcmaValue.Null());
        }
Exemple #9
0
        public EcmaValue IndexOf(EcmaHeadObject obj, EcmaValue[] arg)
        {
            string str = EcmaValue.Object(obj).ToString(State);
            string s   = arg[0].ToString(State);
            int    pos = arg.Length == 1 ? 0 : arg[1].ToInt32(State);

            return(EcmaValue.Number(str.IndexOf(s, pos)));
        }
Exemple #10
0
        private static EcmaValue ConvertToString(EcmaState state, EcmaHeadObject obj)
        {
            DateTime      time    = new DateTime() + TimeSpan.FromMilliseconds(obj.Value.ToInteger(state));
            StringBuilder builder = new StringBuilder();

            builder.Append(time.Year + "/" + time.Month + "/" + time.Day + " " + time.Hour + ":" + time.Minute + ":" + time.Second + ":" + time.Millisecond);
            return(EcmaValue.String(builder.ToString()));
        }
Exemple #11
0
 public EcmaValue Call(EcmaHeadObject obj, EcmaValue[] arg)
 {
     if (arg.Length == 0)
     {
         return(EcmaValue.String(""));
     }
     return(EcmaValue.String(arg[0].ToString(State)));
 }
Exemple #12
0
 public void DoAction(string type, EcmaHeadObject data)
 {
     if (scriptAction[type] is ICallable)
     {
         (scriptAction[type] as ICallable).Call(null, new EcmaValue[] {
             EcmaValue.Object(data)
         });
     }
 }
Exemple #13
0
        public EcmaValue ValueOf(EcmaHeadObject obj, EcmaValue[] args)
        {
            if (!(obj is StringInstance))
            {
                throw new EcmaRuntimeException("String.prototype.valueOf can only be called when it is a part of string object");
            }

            return(obj.Value);
        }
Exemple #14
0
        public EcmaValue Call(EcmaHeadObject self, EcmaValue[] args)
        {
            if (this.Cached == null)
            {
                this.MakeCache();
            }

            return(this.Cached.Call(self, args));
        }
Exemple #15
0
 public static string[] ToStringArray(EcmaState state, EcmaHeadObject obj)
 {
     string[] result = new string[obj.Get("length").ToInt32(state)];
     for (int i = 0; i < result.Length; i++)
     {
         result[i] = obj.Get(i.ToString()).ToString(state);
     }
     return(result);
 }
Exemple #16
0
        private EcmaValue Query(EcmaHeadObject obj, EcmaValue[] arg)
        {
            string          query   = arg[0].ToString(this.state);
            DataTable       table   = new DataTable();
            MySqlDataReader command = new MySqlCommand(query, this.connection).ExecuteReader();

            table.Load(command);
            command.Close();
            return(EcmaValue.Object(new MysqlReaderValue(state, table)));
        }
Exemple #17
0
 private void DoPlugin(string type, EcmaHeadObject message)
 {
     if (scriptEvenets[type] is ICallable)
     {
         (scriptEvenets[type] as ICallable).Call(null, new EcmaValue[]
         {
             EcmaValue.Object(message)
         });
     }
 }
Exemple #18
0
        private EcmaValue FileGetContent(EcmaHeadObject self, EcmaValue[] arg)
        {
            string file = arg[0].ToString(state);

            if (File.Exists(file))
            {
                return(EcmaValue.String(File.ReadAllText(file)));
            }
            return(EcmaValue.Null());
        }
Exemple #19
0
        public EcmaValue FromCharCode(EcmaHeadObject obj, EcmaValue[] args)
        {
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < args.Length; i++)
            {
                builder.Append((char)args[i].ToInt32(State));
            }
            return(EcmaValue.String(builder.ToString()));
        }
Exemple #20
0
        public override EcmaValue Call(EcmaHeadObject obj, EcmaValue[] arg)
        {
            EcmaValue value = this._Call(obj, arg);

            if (value == null)
            {
                return(EcmaValue.Null());
            }
            return(value);
        }
Exemple #21
0
        public EcmaValue Construct(EcmaValue[] arg)
        {
            EcmaHeadObject obj   = this.Get("prototype").ToObject(State);
            EcmaValue      value = this.Call(obj, arg);

            if (value.IsObject())
            {
                return(value);
            }
            return(EcmaValue.Object(obj));
        }
Exemple #22
0
        public EcmaValue GetFileContents(EcmaHeadObject self, EcmaValue[] args)
        {
            string path = args[0].ToString(state);

            if (File.Exists(path))
            {
                return(EcmaValue.String(File.ReadAllText(path)));
            }

            return(EcmaValue.Null());
        }
Exemple #23
0
        public EcmaValue CharAt(EcmaHeadObject obj, EcmaValue[] arg)
        {
            string str = obj == null ? "" : obj.Value.ToString(State);
            double pos = arg[0].ToInteger(State);

            if (pos < 0 || pos >= str.Length)
            {
                return(EcmaValue.String(""));
            }
            return(EcmaValue.String(str.ToCharArray()[(int)pos].ToString()));
        }
Exemple #24
0
        private EcmaValue FileWriteContents(EcmaHeadObject self, EcmaValue[] arg)
        {
            string file = arg[0].ToString(state);

            if (!File.Exists(file))
            {
                return(EcmaValue.Boolean(false));
            }

            File.WriteAllText(file, arg[1].ToString(state));
            return(EcmaValue.Boolean(true));
        }
Exemple #25
0
        private EcmaValue GetFil()
        {
            EcmaHeadObject fil = new EcmaHeadObject();

            fil.Put("exists", EcmaValue.Object(new NativeFunctionInstance(1, state, FileExists)));
            fil.Put("create", EcmaValue.Object(new NativeFunctionInstance(1, state, FileCreate)));
            fil.Put("getContent", EcmaValue.Object(new NativeFunctionInstance(1, state, FileGetContent)));
            fil.Put("writeContents", EcmaValue.Object(new NativeFunctionInstance(2, state, FileWriteContents)));
            fil.Put("writeLine", EcmaValue.Object(new NativeFunctionInstance(2, state, FileWriteLine)));

            return(EcmaValue.Object(fil));
        }
Exemple #26
0
        public EcmaValue PutFileContents(EcmaHeadObject self, EcmaValue[] args)
        {
            string path = args[0].ToString(state);

            if (!File.Exists(path))
            {
                File.Create(path).Close();
            }

            File.WriteAllText(path, args[1].ToString(state));
            return(EcmaValue.Null());
        }
Exemple #27
0
 public EcmaValue Call(EcmaHeadObject self, EcmaValue[] arg)
 {
     return(this.Construct(new EcmaValue[] {
         EcmaValue.Undefined(),
         EcmaValue.Undefined(),
         EcmaValue.Undefined(),
         EcmaValue.Undefined(),
         EcmaValue.Undefined(),
         EcmaValue.Undefined(),
         EcmaValue.Undefined(),
     }));
 }
Exemple #28
0
        private EcmaValue OpenConnection(EcmaHeadObject self, EcmaValue[] arg)
        {
            EcmaState state = this.Client.State;

            OpenConnection(
                arg[0].ToString(state),
                arg[1].ToString(state),
                arg[2].ToInt32(state),
                arg[3].ToString(state),
                EcmaUntil.ToStringArray(state, arg[4].ToObject(state))
                );
            return(EcmaValue.Undefined());
        }
Exemple #29
0
        public static void PutValue(Reference V, EcmaValue W, EcmaHeadObject Global)
        {
            EcmaHeadObject obj = V.Base;

            if (obj != null)
            {
                obj.Put(V.Name, W);
            }
            else
            {
                Global.Put(V.Name, W);
            }
        }
Exemple #30
0
        public EcmaValue CharCodeAt(EcmaHeadObject obj, EcmaValue[] arg)
        {
            string str    = EcmaValue.Object(obj).ToString(State);
            int    pos    = arg[0].ToInt32(State);
            int    length = str.Length;

            if (pos < 0 || pos > length)
            {
                return(EcmaValue.Number(Double.NaN));
            }

            return(EcmaValue.Number((int)str.ToCharArray()[pos]));
        }