Exemple #1
0
        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);
        }
Exemple #2
0
        public JSListInstance GetRange(object st, object co)
        {
            if (!(st is int || st is double))
            {
                throw new JavaScriptException(this.Engine, ErrorType.Error, "start must be an int or double");
            }

            int start = TypeConverter.ToInt32(st);

            if (!(co is int || co is double))
            {
                throw new JavaScriptException(this.Engine, ErrorType.Error, "count must be an int or double");
            }

            int count = TypeConverter.ToInt32(co);

            if (start > this.array.Length || start < 0)
            {
                throw new JavaScriptException(this.Engine, ErrorType.RangeError, "start was out of bounds");
            }

            if ((start + count) > this.array.Length || count < start)
            {
                throw new JavaScriptException(this.Engine, ErrorType.RangeError, "count was out of bounds");
            }

            JSListInstance result = new JSListInstance(this.Engine.Object.InstancePrototype);

            for (int i = 0; i < this.array.Length; i++)
            {
                if (i >= start && i <= (start + count))
                {
                    result.Add(this.array[i]);
                }
            }

            return(result);
        }