GetValueAtIndex() private method

private GetValueAtIndex ( Object obj, ulong index ) : Object
obj Object
index ulong
return Object
コード例 #1
0
        public static Object unshift(Object thisob, params Object[] args)
        {
            if (args == null || args.Length == 0)
            {
                return(thisob);
            }
            if (thisob is ArrayObject)
            {
                return(((ArrayObject)thisob).Unshift(args));
            }
            uint oldLength = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));
            long newLength = oldLength + args.Length;

            LateBinding.SetMemberValue(thisob, "length", newLength);
            // shift the array
            for (long i = oldLength - 1; i >= 0; i--)
            {
                Object val = LateBinding.GetValueAtIndex(thisob, (ulong)i);
                if (val is Missing)
                {
                    LateBinding.DeleteValueAtIndex(thisob, (ulong)(i + args.Length));
                }
                else
                {
                    LateBinding.SetValueAtIndex(thisob, (ulong)(i + args.Length), val);
                }
            }
            // copy the input args
            for (uint i = 0; i < args.Length; i++)
            {
                LateBinding.SetValueAtIndex(thisob, i, args[i]);
            }
            return(thisob);
        }
コード例 #2
0
        internal static String Join(Object thisob, String separator, bool localize)
        {
            StringBuilder str        = new StringBuilder();
            uint          thisLength = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));

            if (thisLength > int.MaxValue)
            {
                throw new JScriptException(JSError.OutOfMemory);
            }
            // Small optimization so we're not doing a bunch of reallocs for large arrays.
            if (thisLength > str.Capacity)
            {
                str.Capacity = (int)thisLength;
            }
            for (uint i = 0; i < thisLength; i++)
            {
                Object value = LateBinding.GetValueAtIndex(thisob, i);
                if (value != null && !(value is Missing))
                {
                    if (localize)
                    {
                        str.Append(Convert.ToLocaleString(value));
                    }
                    else
                    {
                        str.Append(Convert.ToString(value));
                    }
                }
                if (i < thisLength - 1)
                {
                    str.Append(separator);
                }
            }
            return(str.ToString());
        }
コード例 #3
0
        internal void SortObject(long left, long right) //left and right are longs to allow for values < 0. Their positives values are always < UInt32.MaxValue.
        {
            Object x, y;

            if (right > left)
            {
                long piv = left + (long)((right - left) * MathObject.random());
                LateBinding.SwapValues(this.obj, (uint)piv, (uint)right);
                x = LateBinding.GetValueAtIndex(this.obj, (ulong)right);
                long i = left - 1, j = right;
                while (true)
                {
                    do
                    {
                        y = LateBinding.GetValueAtIndex(this.obj, (ulong)++i);
                    }while(i < j && this.Compare(x, y) >= 0);
                    do
                    {
                        y = LateBinding.GetValueAtIndex(this.obj, (ulong)--j);
                    }while(j > i && this.Compare(x, y) <= 0);
                    if (i >= j)
                    {
                        break;
                    }
                    LateBinding.SwapValues(this.obj, (uint)i, (uint)j);
                }
                LateBinding.SwapValues(this.obj, (uint)i, (uint)right);
                this.SortObject(left, i - 1);
                this.SortObject(i + 1, right);
            }
        }
コード例 #4
0
        public static Object shift(Object thisob)
        {
            Object res = null;

            if (thisob is ArrayObject)
            {
                return(((ArrayObject)thisob).Shift());
            }
            uint length = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));

            if (length == 0)
            {
                LateBinding.SetMemberValue(thisob, "length", 0);
                return(res);
            }
            res = LateBinding.GetValueAtIndex(thisob, 0);
            for (uint i = 1; i < length; i++)
            {
                Object val = LateBinding.GetValueAtIndex(thisob, i);
                if (val is Missing)
                {
                    LateBinding.DeleteValueAtIndex(thisob, i - 1);
                }
                else
                {
                    LateBinding.SetValueAtIndex(thisob, i - 1, val);
                }
            }
            LateBinding.DeleteValueAtIndex(thisob, length - 1);
            LateBinding.SetMemberValue(thisob, "length", length - 1);
            return(res);
        }
コード例 #5
0
        internal static String Join(Object thisob, String separator, bool localize)
        {
            StringBuilder str        = new StringBuilder();
            uint          thisLength = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));

            for (uint i = 0; i < thisLength; i++)
            {
                Object value = LateBinding.GetValueAtIndex(thisob, i);
                if (value != null && !(value is Missing))
                {
                    if (localize)
                    {
                        str.Append(Convert.ToLocaleString(value));
                    }
                    else
                    {
                        str.Append(Convert.ToString(value));
                    }
                }
                if (i < thisLength - 1)
                {
                    str.Append(separator);
                }
            }
            return(str.ToString());
        }
コード例 #6
0
        internal static string Join(object thisob, string separator, bool localize)
        {
            StringBuilder builder = new StringBuilder();
            uint          num     = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));

            if (num > 0x7fffffff)
            {
                throw new JScriptException(JSError.OutOfMemory);
            }
            if (num > builder.Capacity)
            {
                builder.Capacity = (int)num;
            }
            for (uint i = 0; i < num; i++)
            {
                object valueAtIndex = LateBinding.GetValueAtIndex(thisob, (ulong)i);
                if ((valueAtIndex != null) && !(valueAtIndex is Missing))
                {
                    if (localize)
                    {
                        builder.Append(Microsoft.JScript.Convert.ToLocaleString(valueAtIndex));
                    }
                    else
                    {
                        builder.Append(Microsoft.JScript.Convert.ToString(valueAtIndex));
                    }
                }
                if (i < (num - 1))
                {
                    builder.Append(separator);
                }
            }
            return(builder.ToString());
        }
コード例 #7
0
        internal void SortObject(long left, long right)
        {
            object obj3;

            if (right <= left)
            {
                return;
            }
            long num = left + ((long)((right - left) * MathObject.random()));

            LateBinding.SwapValues(this.obj, (uint)num, (uint)right);
            object valueAtIndex = LateBinding.GetValueAtIndex(this.obj, (ulong)right);
            long   num2         = left - 1L;
            long   num3         = right;

Label_0039:
            obj3 = LateBinding.GetValueAtIndex(this.obj, (ulong)(num2 += 1L));
            if ((num2 < num3) && (this.Compare(valueAtIndex, obj3) >= 0))
            {
                goto Label_0039;
            }
            do
            {
                obj3 = LateBinding.GetValueAtIndex(this.obj, (ulong)(num3 -= 1L));
            }while ((num3 > num2) && (this.Compare(valueAtIndex, obj3) <= 0));
            if (num2 < num3)
            {
                LateBinding.SwapValues(this.obj, (uint)num2, (uint)num3);
                goto Label_0039;
            }
            LateBinding.SwapValues(this.obj, (uint)num2, (uint)right);
            this.SortObject(left, num2 - 1L);
            this.SortObject(num2 + 1L, right);
        }
コード例 #8
0
 public static object unshift(object thisob, params object[] args)
 {
     if ((args != null) && (args.Length != 0))
     {
         if (thisob is ArrayObject)
         {
             return(((ArrayObject)thisob).Unshift(args));
         }
         uint num  = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));
         long num2 = num + args.Length;
         LateBinding.SetMemberValue(thisob, "length", num2);
         for (long i = num - 1; i >= 0L; i -= 1L)
         {
             object valueAtIndex = LateBinding.GetValueAtIndex(thisob, (ulong)i);
             if (valueAtIndex is Missing)
             {
                 LateBinding.DeleteValueAtIndex(thisob, (ulong)(i + args.Length));
             }
             else
             {
                 LateBinding.SetValueAtIndex(thisob, (ulong)(i + args.Length), valueAtIndex);
             }
         }
         for (uint j = 0; j < args.Length; j++)
         {
             LateBinding.SetValueAtIndex(thisob, (ulong)j, args[j]);
         }
     }
     return(thisob);
 }
コード例 #9
0
        public static object shift(object thisob)
        {
            object valueAtIndex = null;

            if (thisob is ArrayObject)
            {
                return(((ArrayObject)thisob).Shift());
            }
            uint num = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));

            if (num == 0)
            {
                LateBinding.SetMemberValue(thisob, "length", 0);
                return(valueAtIndex);
            }
            valueAtIndex = LateBinding.GetValueAtIndex(thisob, 0L);
            for (uint i = 1; i < num; i++)
            {
                object obj3 = LateBinding.GetValueAtIndex(thisob, (ulong)i);
                if (obj3 is Missing)
                {
                    LateBinding.DeleteValueAtIndex(thisob, (ulong)(i - 1));
                }
                else
                {
                    LateBinding.SetValueAtIndex(thisob, (ulong)(i - 1), obj3);
                }
            }
            LateBinding.DeleteValueAtIndex(thisob, (ulong)(num - 1));
            LateBinding.SetMemberValue(thisob, "length", num - 1);
            return(valueAtIndex);
        }
コード例 #10
0
        public static ArrayObject slice(Object thisob, VsaEngine engine, double start, Object end)
        {
            ArrayObject array  = engine.GetOriginalArrayConstructor().Construct();
            uint        length = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));
            // compute the start index
            long startIndex = Runtime.DoubleToInt64(Convert.ToInteger(start));

            if (startIndex < 0)
            {
                startIndex = length + startIndex;
                if (startIndex < 0)
                {
                    startIndex = 0;
                }
            }
            else if (startIndex > length)
            {
                startIndex = length;
            }
            // compute the end index
            long endIndex = length;

            if (end != null && !(end is Missing))
            {
                endIndex = Runtime.DoubleToInt64(Convert.ToInteger(end));
                if (endIndex < 0)
                {
                    endIndex = length + endIndex;
                    if (endIndex < 0)
                    {
                        endIndex = 0;
                    }
                }
                else if (endIndex > length)
                {
                    endIndex = length;
                }
            }
            // slice
            if (endIndex > startIndex)
            {
                array.length = endIndex - startIndex;
                for (ulong i = (ulong)startIndex, j = 0; i < (ulong)endIndex; i++, j++)
                {
                    Object val = LateBinding.GetValueAtIndex(thisob, i);
                    if (!(val is Missing))
                    {
                        LateBinding.SetValueAtIndex(array, j, val);
                    }
                }
            }
            return(array);
        }
コード例 #11
0
        public static ArrayObject slice(object thisob, VsaEngine engine, double start, object end)
        {
            ArrayObject obj2 = engine.GetOriginalArrayConstructor().Construct();
            uint        num  = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));
            long        num2 = Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(start));

            if (num2 < 0L)
            {
                num2 = num + num2;
                if (num2 < 0L)
                {
                    num2 = 0L;
                }
            }
            else if (num2 > num)
            {
                num2 = num;
            }
            long num3 = num;

            if ((end != null) && !(end is Missing))
            {
                num3 = Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(end));
                if (num3 < 0L)
                {
                    num3 = num + num3;
                    if (num3 < 0L)
                    {
                        num3 = 0L;
                    }
                }
                else if (num3 > num)
                {
                    num3 = num;
                }
            }
            if (num3 > num2)
            {
                obj2.length = num3 - num2;
                ulong index = (ulong)num2;
                for (ulong i = 0L; index < num3; i += (ulong)1L)
                {
                    object valueAtIndex = LateBinding.GetValueAtIndex(thisob, index);
                    if (!(valueAtIndex is Missing))
                    {
                        LateBinding.SetValueAtIndex(obj2, i, valueAtIndex);
                    }
                    index += (ulong)1L;
                }
            }
            return(obj2);
        }
コード例 #12
0
        public static Object pop(Object thisob)
        {
            uint thisLength = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));

            if (thisLength == 0)
            {
                LateBinding.SetMemberValue(thisob, "length", 0);
                return(null);
            }
            Object result = LateBinding.GetValueAtIndex(thisob, thisLength - 1);

            LateBinding.DeleteValueAtIndex(thisob, thisLength - 1);
            LateBinding.SetMemberValue(thisob, "length", thisLength - 1);
            return(result);
        }
コード例 #13
0
        public static object pop(object thisob)
        {
            uint num = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));

            if (num == 0)
            {
                LateBinding.SetMemberValue(thisob, "length", 0);
                return(null);
            }
            object valueAtIndex = LateBinding.GetValueAtIndex(thisob, (ulong)(num - 1));

            LateBinding.DeleteValueAtIndex(thisob, (ulong)(num - 1));
            LateBinding.SetMemberValue(thisob, "length", num - 1);
            return(valueAtIndex);
        }
コード例 #14
0
        public static ArrayObject splice(Object thisob, VsaEngine engine, double start, double deleteCnt, params Object[] args)
        {
            uint oldLength = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));
            // compute the start index
            long startIndex = Runtime.DoubleToInt64(Convert.ToInteger(start));

            if (startIndex < 0)
            {
                startIndex = oldLength + startIndex;
                if (startIndex < 0)
                {
                    startIndex = 0;
                }
            }
            else if (startIndex > oldLength)
            {
                startIndex = oldLength;
            }

            // compute the number of items to delete
            long deleteCount = Runtime.DoubleToInt64(Convert.ToInteger(deleteCnt));

            if (deleteCount < 0)
            {
                deleteCount = 0;
            }
            else if (deleteCount > oldLength - startIndex)
            {
                deleteCount = oldLength - startIndex;
            }
            long newLength = oldLength + args.Length - deleteCount;

            // create an array for the result
            ArrayObject result = engine.GetOriginalArrayConstructor().Construct();

            result.length = deleteCount;

            // special case array objects (nice speedup if dense)
            if (thisob is ArrayObject)
            {
                ((ArrayObject)thisob).Splice((uint)startIndex, (uint)deleteCount, args, result, (uint)oldLength, (uint)newLength);
                return(result);
            }

            // copy the deleted items to the result array
            for (ulong i = 0; i < (ulong)deleteCount; i++)
            {
                result.SetValueAtIndex((uint)i, LateBinding.GetValueAtIndex(thisob, i + (ulong)startIndex));
            }

            // shift the remaining elements left or right
            long n = oldLength - startIndex - deleteCount;

            if (newLength < oldLength)
            {
                for (long i = 0; i < n; i++)
                {
                    LateBinding.SetValueAtIndex(thisob, (ulong)(i + startIndex + args.Length), LateBinding.GetValueAtIndex(thisob, (ulong)(i + startIndex + deleteCount)));
                }
                LateBinding.SetMemberValue(thisob, "length", newLength);
            }
            else
            {
                LateBinding.SetMemberValue(thisob, "length", newLength);
                for (long i = n - 1; i >= 0; i--)
                {
                    LateBinding.SetValueAtIndex(thisob, (ulong)(i + startIndex + args.Length), LateBinding.GetValueAtIndex(thisob, (ulong)(i + startIndex + deleteCount)));
                }
            }

            // splice in the arguments
            int m = args == null ? 0 : args.Length;

            for (uint i = 0; i < m; i++)
            {
                LateBinding.SetValueAtIndex(thisob, i + (ulong)startIndex, args[i]);
            }

            return(result);
        }
コード例 #15
0
        public static ArrayObject splice(object thisob, VsaEngine engine, double start, double deleteCnt, params object[] args)
        {
            uint oldLength = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));
            long num2      = Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(start));

            if (num2 < 0L)
            {
                num2 = oldLength + num2;
                if (num2 < 0L)
                {
                    num2 = 0L;
                }
            }
            else if (num2 > oldLength)
            {
                num2 = oldLength;
            }
            long num3 = Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(deleteCnt));

            if (num3 < 0L)
            {
                num3 = 0L;
            }
            else if (num3 > (oldLength - num2))
            {
                num3 = oldLength - num2;
            }
            long        num4     = (oldLength + args.Length) - num3;
            ArrayObject outArray = engine.GetOriginalArrayConstructor().Construct();

            outArray.length = num3;
            if (thisob is ArrayObject)
            {
                ((ArrayObject)thisob).Splice((uint)num2, (uint)num3, args, outArray, oldLength, (uint)num4);
                return(outArray);
            }
            for (ulong i = 0L; i < num3; i += (ulong)1L)
            {
                outArray.SetValueAtIndex((uint)i, LateBinding.GetValueAtIndex(thisob, i + ((ulong)num2)));
            }
            long num6 = (oldLength - num2) - num3;

            if (num4 < oldLength)
            {
                for (long k = 0L; k < num6; k += 1L)
                {
                    LateBinding.SetValueAtIndex(thisob, (ulong)((k + num2) + args.Length), LateBinding.GetValueAtIndex(thisob, (ulong)((k + num2) + num3)));
                }
                LateBinding.SetMemberValue(thisob, "length", num4);
            }
            else
            {
                LateBinding.SetMemberValue(thisob, "length", num4);
                for (long m = num6 - 1L; m >= 0L; m -= 1L)
                {
                    LateBinding.SetValueAtIndex(thisob, (ulong)((m + num2) + args.Length), LateBinding.GetValueAtIndex(thisob, (ulong)((m + num2) + num3)));
                }
            }
            int num9 = (args == null) ? 0 : args.Length;

            for (uint j = 0; j < num9; j++)
            {
                LateBinding.SetValueAtIndex(thisob, (ulong)(j + num2), args[j]);
            }
            return(outArray);
        }