public JSListInstance FindAll(object a) { if (!(a is UserDefinedFunction)) { throw new JavaScriptException(this.Engine, ErrorType.Error, "expecting comparison function"); } UserDefinedFunction f = (UserDefinedFunction)a; List <object> list = new List <object>(); foreach (object obj in this.array) { if (TypeConverter.ToBoolean(f.Call(this.Engine.Global, obj))) { list.Add(obj); } } JSListInstance result = new JSListInstance(this.Engine.Object.InstancePrototype); foreach (object obj in list) { result.Add(obj); } return(result); }
public static void Records(ScriptEngine eng, object f) { if (f is UserDefinedFunction) { UserDefinedFunction function = (UserDefinedFunction)f; try { Server.Users.Records(x => function.Call(eng.Global, new Objects.JSRecord(eng.Object.InstancePrototype, x, eng.UserData as string))); } catch { } } }
public static void Banned(ScriptEngine eng, object f) { if (f is UserDefinedFunction) { UserDefinedFunction function = (UserDefinedFunction)f; try { Server.Users.Banned(x => function.Call(eng.Global, new Objects.JSBannedUser(eng.Object.InstancePrototype, x, eng.ScriptName))); } catch { } } }
public void R_Users(object a) { if (a is UserDefinedFunction) { UserDefinedFunction f = (UserDefinedFunction)a; this.UserList.ForEach(x => { try { f.Call(this.Engine.Global, x); } catch (Jurassic.JavaScriptException je) { ScriptManager.ErrorHandler(f.Engine.ScriptName, je.LineNumber, je.Message); } catch { } }); } }
public void Users(object a) { if (a is UserDefinedFunction) { JSScript script = ScriptManager.Scripts.Find(x => x.ScriptName == this.ScriptName); if (script != null) { UserDefinedFunction x = (UserDefinedFunction)a; try { this.users.ForEach(z => x.Call(script.JS.Global, z)); } catch { } } } }
public static void DoRoomsTask(ScriptEngine eng, object a) { if (a is UserDefinedFunction) { UserDefinedFunction f = (UserDefinedFunction)a; JSScript script = ScriptManager.Scripts.Find(x => x.ScriptName == eng.ScriptName); if (script != null) { foreach (Objects.JSRoom r in script.Rooms) { try { f.Call(script.JS.Global, r); } catch (Jurassic.JavaScriptException je) { ScriptManager.ErrorHandler(f.Engine.ScriptName, je.LineNumber, je.Message); } } }
public static void Local(ScriptEngine eng, object f) { if (f is UserDefinedFunction) { JSScript script = ScriptManager.Scripts.Find(x => x.ScriptName == eng.UserData as string); if (script != null) { UserDefinedFunction function = (UserDefinedFunction)f; try { script.local_users.ForEach(u => function.Call(eng.Global, u)); } catch { } } } }
public int FindLastIndex(object a) { if (!(a is UserDefinedFunction)) { throw new JavaScriptException(this.Engine, ErrorType.Error, "expecting comparison function"); } UserDefinedFunction f = (UserDefinedFunction)a; for (int i = (this.array.Length - 1); i > -1; i--) { if (TypeConverter.ToBoolean(f.Call(this.Engine.Global, this.array[i]))) { return(i); } } return(-1); }
public object Find(object a) { if (!(a is UserDefinedFunction)) { throw new JavaScriptException(this.Engine, ErrorType.Error, "expecting comparison function"); } UserDefinedFunction f = (UserDefinedFunction)a; foreach (object obj in this.array) { if (TypeConverter.ToBoolean(f.Call(this.Engine.Global, obj))) { return(obj); } } return(null); }
public int FindIndex(object a) { if (!(a is UserDefinedFunction)) { throw new JavaScriptException(this.Engine, "invalid casting", "expecting comparison function"); } UserDefinedFunction f = (UserDefinedFunction)a; for (int i = 0; i < this.array.Length; i++) { if (TypeConverter.ToBoolean(f.Call(this.Engine.Global, this.array[i]))) { return(i); } } return(-1); }
public bool Sort(object a) { if (this.array.Length < 2) { return(false); } if (a is Undefined) { List <object> nocomp = this.array.ToList(); nocomp.Sort(); this.array = nocomp.ToArray(); for (uint i = 0; i < this.array.Length; i++) { this.SetPropertyValue(i, this.array[i], true); } return(true); } if (!(a is UserDefinedFunction)) { throw new JavaScriptException(this.Engine, ErrorType.Error, "expecting comparison function"); } UserDefinedFunction f = (UserDefinedFunction)a; List <object> list = this.array.ToList(); list.Sort((x, y) => TypeConverter.ToInt32(f.Call(this.Engine, x, y))); this.array = list.ToArray(); for (uint i = 0; i < this.array.Length; i++) { this.SetPropertyValue(i, this.array[i], true); } return(true); }
public static void Leaves(ScriptEngine eng, object f) { if (Server.Link.IsLinked) { if (f is UserDefinedFunction) { JSScript script = ScriptManager.Scripts.Find(x => x.ScriptName == eng.ScriptName); if (script != null) { UserDefinedFunction function = (UserDefinedFunction)f; try { script.leaves.ForEach(l => function.Call(eng.Global, l)); } catch { } } } } }
public int RemoveAll(object a) { if (!(a is UserDefinedFunction)) { throw new JavaScriptException(this.Engine, ErrorType.Error, "expecting comparison function"); } UserDefinedFunction f = (UserDefinedFunction)a; List <object> list = new List <object>(); foreach (object obj in this.array) { if (!TypeConverter.ToBoolean(f.Call(this.Engine.Global, obj))) { list.Add(obj); } } int current = this.array.Length; this.array = new object[list.Count]; for (uint i = 0; i < current; i++) { if (i < this.array.Length) { this.array[i] = list[(int)i]; this.SetPropertyValue(i, this.array[i], true); } else { this.Delete(i, true); } } return(current - this.array.Length); }