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)); }
public Form1() { this.Client.BuildStandartLibary(); new DefaultScript(this.Client); ScriptClient.Put("showServerDialog", EcmaValue.Object(new NativeFunctionInstance(1, this.Client.State, OpenNewServerDialog))); ScriptClient.Put("openConnection", EcmaValue.Object(new NativeFunctionInstance(5, this.Client.State, OpenConnection))); this.Client.CreateVariable("Client", EcmaValue.Object(ScriptClient)); using (TextReader script = File.OpenText("Script/Client.js")) { this.Client.RunCode(script); } InitializeComponent(); }
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)))); }))); }
public virtual EcmaValue Call(EcmaHeadObject obj, EcmaValue[] arg) { EcmaHeadObject argument = new EcmaHeadObject(); EcmaHeadObject var = new EcmaHeadObject(); int i = 0; for (; i < this.arg.Length; i++) { if (i < arg.Length) { argument.Put(this.arg[i], arg[i]); argument.Put(i.ToString(), arg[i]); var.Put(this.arg[i], arg[i]); } else { var.Put(this.arg[i], EcmaValue.Undefined()); } } for (; i < arg.Length; i++) { argument.Put(i.ToString(), arg[i]); } argument.Prototype = State.Object; argument.Put("length", EcmaValue.Number(arg.Length)); argument.Property["length"].DontEnum = true; var.Put("arguments", EcmaValue.Object(argument)); var.Put("callee", EcmaValue.Object(this)); var.Property["callee"].DontEnum = true; EcmaHeadObject[] scope = State.GetScope().Clone() as EcmaHeadObject[]; System.Array.Resize <EcmaHeadObject>(ref scope, scope.Length + 1); scope[scope.Length - 1] = var; State.PushContext(obj, scope, var); EcmaComplication com = EcmaEvulator.Evulate(State, this.body); State.PopContext(); if (com.Type == EcmaComplicationType.Return) { return(com.Value); } return(EcmaValue.Undefined()); }
private EcmaValue Fetch(EcmaHeadObject obj, EcmaValue[] arg) { if (this.reader.Count() < this.Current) { return(EcmaValue.Null()); } DataRow row = this.reader[this.Current]; this.Current++; EcmaHeadObject result = new EcmaHeadObject(); for (int i = 0; i < row.ItemArray.Length; i++) { EcmaValue c = EcmaValue.String(row[i].ToString()); result.Put(i.ToString(), c); result.Put(row.Table.Columns[i].ColumnName, c); } return(EcmaValue.Object(result)); }
private EcmaValue Reverse(EcmaHeadObject obj, EcmaValue[] arg) { uint length = obj.Get("length").ToUint32(state); uint mid = (uint)Math.Floor((double)length / 2); uint k = 0; while (k != mid) { uint l = length - k - 1; if (obj.HasProperty(k.ToString())) { if (obj.HasProperty(l.ToString())) { EcmaValue a = obj.Get(k.ToString()); obj.Put(k.ToString(), obj.Get(l.ToString())); obj.Put(l.ToString(), a); } else { obj.Put(l.ToString(), obj.Get(k.ToString())); obj.Delete(k.ToString()); } } else { if (obj.HasProperty(l.ToString())) { obj.Put(k.ToString(), obj.Get(l.ToString())); obj.Delete(l.ToString()); } else { obj.Delete(l.ToString()); obj.Delete(k.ToString()); } } k++; } return(EcmaValue.Object(obj)); }
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); } }
public static void PutValue(EcmaValue V, EcmaValue W, EcmaHeadObject Global) { if (!V.IsRefrence()) { throw new EcmaRuntimeException("Cant put value on non refrence"); } EcmaHeadObject obj = GetBase(V); if (obj != null) { obj.Put(GetPropertyName(V), W); } else { Global.Put(GetPropertyName(V), W); } }
internal static EcmaComplication Evulate(EcmaState state, EcmaStatment statment) { EcmaComplication c = new EcmaComplication(EcmaComplicationType.Normal, EcmaValue.Undefined()); switch (statment.Type) { case EcmaStatmentType.FunctionDec: return(CreateFuncDec(state, statment)); case EcmaStatmentType.Expresion: return(new EcmaComplication(EcmaComplicationType.Normal, EvulateExpresion(state, statment.Expresion))); case EcmaStatmentType.Return: return(new EcmaComplication(EcmaComplicationType.Return, statment.Expresion == null ? EcmaValue.Undefined() : EvulateExpresion(state, statment.Expresion))); case EcmaStatmentType.If: if (Reference.GetValue(EvulateExpresion(state, statment.Expresion)).ToBoolean(state)) { return(Evulate(state, statment.Statment)); } else { if (statment.Else == null) { return(new EcmaComplication(EcmaComplicationType.Normal, EcmaValue.Undefined())); } return(Evulate(state, statment.Else)); } case EcmaStatmentType.Block: for (int i = 0; i < statment.Statments.Count; i++) { c = Evulate(state, statment.Statments[i]); if (c.Type != EcmaComplicationType.Normal) { return(c); } } return(new EcmaComplication(EcmaComplicationType.Normal, EcmaValue.Null())); case EcmaStatmentType.Var: EcmaHeadObject putIn = state.GetScope()[state.GetScope().Length - 1]; foreach (string key in statment.VarList.Keys) { putIn.Put(key, statment.VarList[key] == null ? EcmaValue.Undefined() : Reference.GetValue(EvulateExpresion(state, statment.VarList[key]))); } return(new EcmaComplication(EcmaComplicationType.Normal, EcmaValue.Undefined())); case EcmaStatmentType.While: c = new EcmaComplication(EcmaComplicationType.Normal, EcmaValue.Undefined()); while (EvulateExpresion(state, statment.Expresion).ToBoolean(state)) { c = Evulate(state, statment.Statment); if (c.Type == EcmaComplicationType.Break) { return(new EcmaComplication(EcmaComplicationType.Normal, EcmaValue.Undefined())); } else if (c.Type == EcmaComplicationType.Continue) { c = new EcmaComplication(EcmaComplicationType.Normal, EcmaValue.Undefined()); } else if (c.Type == EcmaComplicationType.Return) { return(c); } } return(c); case EcmaStatmentType.For: if (statment.Expresion != null) { Reference.GetValue(EvulateExpresion(state, statment.Expresion)); } while (statment.Second == null || Reference.GetValue(EvulateExpresion(state, statment.Second)).ToBoolean(state)) { c = Evulate(state, statment.Statment); if (c.Type == EcmaComplicationType.Break) { return(new EcmaComplication(EcmaComplicationType.Normal, EcmaValue.Undefined())); } else if (c.Type == EcmaComplicationType.Return) { return(c); } else if (c.Type == EcmaComplicationType.Continue) { c = new EcmaComplication(EcmaComplicationType.Normal, EcmaValue.Undefined()); } if (statment.Tree != null) { Reference.GetValue(EvulateExpresion(state, statment.Tree)); } } return(c); case EcmaStatmentType.ForIn: EcmaHeadObject obj = Reference.GetValue(EvulateExpresion(state, statment.Second)).ToObject(state); c = new EcmaComplication(EcmaComplicationType.Normal, EcmaValue.Undefined()); foreach (string key in obj.Property.Keys) { if (obj.Property[key].DontEnum) { continue; } if (statment.Expresion.Type == ExpresionType.VarList) { Reference.PutValue(EvulateExpresion(state, statment.Expresion.Multi[0].Left), EcmaValue.String(key), state.GlobalObject); } else { Reference.PutValue(EvulateExpresion(state, statment.Expresion), EcmaValue.String(key), state.GlobalObject); } c = Evulate(state, statment.Statment); if (c.Type != EcmaComplicationType.Normal) { if (c.Type == EcmaComplicationType.Break) { return(new EcmaComplication(EcmaComplicationType.Normal, EcmaValue.Undefined())); } if (c.Type == EcmaComplicationType.Continue) { c = new EcmaComplication(EcmaComplicationType.Normal, EcmaValue.Undefined()); } if (c.Type == EcmaComplicationType.Return) { return(c); } } } return(c); case EcmaStatmentType.Continue: return(new EcmaComplication(EcmaComplicationType.Continue, EcmaValue.Undefined())); default: throw new EcmaRuntimeException("Evulator out of sync. Unknown statment type: " + statment.Type.ToString()); } }