SetValueAtIndex() private method

private SetValueAtIndex ( uint index, Object value ) : void
index uint
value Object
return void
Example #1
0
        public ArrayObject CreateInstance(params object[] args)
        {
            ArrayObject obj2 = new ArrayObject(this.originalPrototype, typeof(ArrayObject));

            if (args.Length != 0)
            {
                if (args.Length == 1)
                {
                    object       ob           = args[0];
                    IConvertible iConvertible = Microsoft.JScript.Convert.GetIConvertible(ob);
                    switch (Microsoft.JScript.Convert.GetTypeCode(ob, iConvertible))
                    {
                    case TypeCode.Char:
                    case TypeCode.SByte:
                    case TypeCode.Byte:
                    case TypeCode.Int16:
                    case TypeCode.UInt16:
                    case TypeCode.Int32:
                    case TypeCode.UInt32:
                    case TypeCode.Int64:
                    case TypeCode.UInt64:
                    case TypeCode.Single:
                    case TypeCode.Double:
                    case TypeCode.Decimal:
                    {
                        double num  = Microsoft.JScript.Convert.ToNumber(ob, iConvertible);
                        uint   num2 = Microsoft.JScript.Convert.ToUint32(ob, iConvertible);
                        if (num != num2)
                        {
                            throw new JScriptException(JSError.ArrayLengthConstructIncorrect);
                        }
                        obj2.length = num2;
                        return(obj2);
                    }
                    }
                }
                if ((args.Length == 1) && (args[0] is Array))
                {
                    Array array = (Array)args[0];
                    if (array.Rank != 1)
                    {
                        throw new JScriptException(JSError.TypeMismatch);
                    }
                    obj2.length = array.Length;
                    for (int j = 0; j < array.Length; j++)
                    {
                        obj2.SetValueAtIndex((uint)j, array.GetValue(j));
                    }
                    return(obj2);
                }
                obj2.length = args.Length;
                for (int i = 0; i < args.Length; i++)
                {
                    obj2.SetValueAtIndex((uint)i, args[i]);
                }
            }
            return(obj2);
        }
        public new ArrayObject CreateInstance(params Object[] args)
        {
            ArrayObject arrayObj = new ArrayObject(this.originalPrototype, typeof(ArrayObject));

            if (args.Length != 0)
            {
                if (args.Length == 1)
                {
                    Object       arg0 = args[0];
                    IConvertible ic   = Convert.GetIConvertible(arg0);
                    switch (Convert.GetTypeCode(arg0, ic))
                    {
                    case TypeCode.Char:
                    case TypeCode.SByte:
                    case TypeCode.Byte:
                    case TypeCode.Int16:
                    case TypeCode.UInt16:
                    case TypeCode.Int32:
                    case TypeCode.UInt32:
                    case TypeCode.Int64:
                    case TypeCode.UInt64:
                    case TypeCode.Single:
                    case TypeCode.Double:
                    case TypeCode.Decimal:
                        double d   = Convert.ToNumber(arg0, ic);
                        uint   len = Convert.ToUint32(arg0, ic);
                        if (d != (double)len)
                        {
                            throw new JScriptException(JSError.ArrayLengthConstructIncorrect);
                        }
                        arrayObj.length = len;
                        return(arrayObj);
                    }
                }
                if (args.Length == 1 && args[0] is Array)
                {
                    Array array = (Array)args[0];
                    if (array.Rank != 1)
                    {
                        throw new JScriptException(JSError.TypeMismatch);
                    }
                    arrayObj.length = array.Length;
                    for (int i = 0; i < array.Length; i++)
                    {
                        arrayObj.SetValueAtIndex((uint)i, array.GetValue(i));
                    }
                }
                else
                {
                    arrayObj.length = args.Length;
                    for (int i = 0; i < args.Length; i++)
                    {
                        arrayObj.SetValueAtIndex((uint)i, args[i]);
                    }
                }
            }
            return(arrayObj);
        }
        protected void SpliceSlowly(uint start, uint deleteCount, object[] args, ArrayObject outArray, uint oldLength, uint newLength)
        {
            for (uint i = 0; i < deleteCount; i++)
            {
                outArray.SetValueAtIndex(i, this.GetValueAtIndex(i + start));
            }
            uint num2 = (oldLength - start) - deleteCount;

            if (newLength < oldLength)
            {
                for (uint k = 0; k < num2; k++)
                {
                    this.SetValueAtIndex((k + start) + ((uint)args.Length), this.GetValueAtIndex((k + start) + deleteCount));
                }
                this.SetLength((ulong)newLength);
            }
            else
            {
                if (newLength > oldLength)
                {
                    this.SetLength((ulong)newLength);
                }
                for (uint m = num2; m > 0; m--)
                {
                    this.SetValueAtIndex((uint)(((m + start) + args.Length) - 1), this.GetValueAtIndex(((m + start) + deleteCount) - 1));
                }
            }
            int num5 = (args == null) ? 0 : args.Length;

            for (uint j = 0; j < num5; j++)
            {
                this.SetValueAtIndex(j + start, args[j]);
            }
        }
 /// <summary>
 /// Helper method that constructs a new JScript array and initializes it with values.
 /// </summary>
 /// <internalonly/>
 public ArrayObject ConstructArray(Object[] args){
   ArrayObject arrayObj = new ArrayObject(originalPrototype, typeof(ArrayObject));
   arrayObj.length = args.Length;
   for (int i = 0; i < args.Length; i++)
     arrayObj.SetValueAtIndex((uint)i, args[i]);
   return arrayObj;
 }
        protected void SpliceSlowly(uint start, uint deleteCount, Object[] args, ArrayObject outArray, uint oldLength, uint newLength)
        {
            for (uint i = 0; i < deleteCount; i++)
            {
                outArray.SetValueAtIndex(i, this.GetValueAtIndex(i + start));
            }
            uint n = oldLength - start - deleteCount;

            if (newLength < oldLength)
            {
                for (uint i = 0; i < n; i++)
                {
                    this.SetValueAtIndex(i + start + (uint)args.Length, this.GetValueAtIndex(i + start + deleteCount));
                }
                this.SetLength(newLength);
            }
            else
            {
                if (newLength > oldLength)
                {
                    this.SetLength(newLength);
                }
                for (uint i = n; i > 0; i--)
                {
                    this.SetValueAtIndex(i + start + (uint)args.Length - 1, this.GetValueAtIndex(i + start + deleteCount - 1));
                }
            }
            int m = args == null ? 0 : args.Length;

            for (uint i = 0; i < m; i++)
            {
                this.SetValueAtIndex(i + start, args[i]);
            }
        }
Example #6
0
        private static ArrayObject SplitWithRegExp(String thisob, VsaEngine engine, RegExpObject regExpObject, uint limit)
        {
            ArrayObject array = (ArrayObject)engine.GetOriginalArrayConstructor().Construct();
            Match       match = regExpObject.regex.Match(thisob);

            if (!match.Success)
            {
                array.SetValueAtIndex(0, thisob);
                regExpObject.lastIndexInt = 0;
                return(array);
            }


            Match lastMatch;
            int   prevIndex = 0;
            uint  i         = 0;

            do
            {
                int len = match.Index - prevIndex;
                if (len > 0)
                {
                    array.SetValueAtIndex(i++, thisob.Substring(prevIndex, len));
                    if (limit > 0 && i >= limit)
                    {
                        regExpObject.lastIndexInt = regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, match, thisob);
                        return(array);
                    }
                }


                prevIndex = match.Index + match.Length;
                lastMatch = match;
                match     = match.NextMatch();
            }while(match.Success);

            if (prevIndex < thisob.Length)
            {
                array.SetValueAtIndex(i, thisob.Substring(prevIndex));
            }
            regExpObject.lastIndexInt = regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, lastMatch, thisob);

            return(array);
        }
        /// <summary>
        /// Helper method that constructs a new JScript array and initializes it with values.
        /// </summary>
        /// <internalonly/>
        public ArrayObject ConstructArray(Object[] args)
        {
            ArrayObject arrayObj = new ArrayObject(originalPrototype, typeof(ArrayObject));

            arrayObj.length = args.Length;
            for (int i = 0; i < args.Length; i++)
            {
                arrayObj.SetValueAtIndex((uint)i, args[i]);
            }
            return(arrayObj);
        }
Example #8
0
        private static ArrayObject SplitWithString(String thisob, VsaEngine engine, String separator, uint limit)
        {
            ArrayObject array = (ArrayObject)engine.GetOriginalArrayConstructor().Construct();

            if (separator.Length == 0)
            {
                if (limit > thisob.Length)
                {
                    limit = (uint)thisob.Length;
                }
                for (int i = 0; i < limit; i++)
                {
                    array.SetValueAtIndex((uint)i, thisob[i].ToString());
                }
            }
            else
            {
                int  prevIndex = 0;
                uint i         = 0;
                int  index;
                while ((index = thisob.IndexOf(separator, prevIndex)) >= 0)
                {
                    array.SetValueAtIndex(i++, thisob.Substring(prevIndex, index - prevIndex));
                    if (i >= limit)
                    {
                        return(array);
                    }
                    prevIndex = index + separator.Length;
                }
                if (i == 0)
                {
                    array.SetValueAtIndex(0, thisob);
                }
                else
                {
                    array.SetValueAtIndex(i, thisob.Substring(prevIndex));
                }
            }
            return(array);
        }
Example #9
0
        public ArrayObject ConstructArray(object[] args)
        {
            ArrayObject obj2 = new ArrayObject(this.originalPrototype, typeof(ArrayObject))
            {
                length = args.Length
            };

            for (int i = 0; i < args.Length; i++)
            {
                obj2.SetValueAtIndex((uint)i, args[i]);
            }
            return(obj2);
        }
        private static ArrayObject SplitWithRegExp(string thisob, VsaEngine engine, RegExpObject regExpObject, uint limit)
        {
            Match       match2;
            ArrayObject obj2  = engine.GetOriginalArrayConstructor().Construct();
            Match       match = regExpObject.regex.Match(thisob);

            if (!match.Success)
            {
                obj2.SetValueAtIndex(0, thisob);
                regExpObject.lastIndexInt = 0;
                return(obj2);
            }
            int  startIndex = 0;
            uint index      = 0;

            do
            {
                int length = match.Index - startIndex;
                if (length > 0)
                {
                    obj2.SetValueAtIndex(index++, thisob.Substring(startIndex, length));
                    if ((limit > 0) && (index >= limit))
                    {
                        regExpObject.lastIndexInt = regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, match, thisob);
                        return(obj2);
                    }
                }
                startIndex = match.Index + match.Length;
                match2     = match;
                match      = match.NextMatch();
            }while (match.Success);
            if (startIndex < thisob.Length)
            {
                obj2.SetValueAtIndex(index, thisob.Substring(startIndex));
            }
            regExpObject.lastIndexInt = regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, match2, thisob);
            return(obj2);
        }
        private static ArrayObject SplitWithString(string thisob, VsaEngine engine, string separator, uint limit)
        {
            int         num4;
            ArrayObject obj2 = engine.GetOriginalArrayConstructor().Construct();

            if (separator.Length == 0)
            {
                if (limit > thisob.Length)
                {
                    limit = (uint)thisob.Length;
                }
                for (int i = 0; i < limit; i++)
                {
                    obj2.SetValueAtIndex((uint)i, thisob[i].ToString());
                }
                return(obj2);
            }
            int  startIndex = 0;
            uint index      = 0;

            while ((num4 = thisob.IndexOf(separator, startIndex)) >= 0)
            {
                obj2.SetValueAtIndex(index++, thisob.Substring(startIndex, num4 - startIndex));
                if (index >= limit)
                {
                    return(obj2);
                }
                startIndex = num4 + separator.Length;
            }
            if (index == 0)
            {
                obj2.SetValueAtIndex(0, thisob);
                return(obj2);
            }
            obj2.SetValueAtIndex(index, thisob.Substring(startIndex));
            return(obj2);
        }
        internal virtual ArrayObject toArray(VsaEngine engine)
        {
            IList       aList  = this.array;
            ArrayObject result = engine.GetOriginalArrayConstructor().Construct();
            uint        i      = 0;
            int         n      = aList.Count;
            IEnumerator e      = aList.GetEnumerator();

            result.length = n;
            while (e.MoveNext())
            {
                result.SetValueAtIndex(i++, e.Current);
            }
            return(result);
        }
        internal virtual ArrayObject toArray(VsaEngine engine)
        {
            IList       array      = this.array;
            ArrayObject obj2       = engine.GetOriginalArrayConstructor().Construct();
            uint        num        = 0;
            int         count      = array.Count;
            IEnumerator enumerator = array.GetEnumerator();

            obj2.length = count;
            while (enumerator.MoveNext())
            {
                obj2.SetValueAtIndex(num++, enumerator.Current);
            }
            return(obj2);
        }
        public static ArrayObject split(object thisob, VsaEngine engine, object separator, object limit)
        {
            string str      = Microsoft.JScript.Convert.ToString(thisob);
            uint   maxValue = uint.MaxValue;

            if (((limit != null) && !(limit is Missing)) && (limit != DBNull.Value))
            {
                double num2 = Microsoft.JScript.Convert.ToInteger(limit);
                if ((num2 >= 0.0) && (num2 < 4294967295))
                {
                    maxValue = (uint)num2;
                }
            }
            if (maxValue == 0)
            {
                return(engine.GetOriginalArrayConstructor().Construct());
            }
            if ((separator == null) || (separator is Missing))
            {
                ArrayObject obj2 = engine.GetOriginalArrayConstructor().Construct();
                obj2.SetValueAtIndex(0, thisob);
                return(obj2);
            }
            RegExpObject regExpObject = separator as RegExpObject;

            if (regExpObject != null)
            {
                return(SplitWithRegExp(str, engine, regExpObject, maxValue));
            }
            Regex regex = separator as Regex;

            if (regex != null)
            {
                return(SplitWithRegExp(str, engine, new RegExpObject(regex), maxValue));
            }
            return(SplitWithString(str, engine, Microsoft.JScript.Convert.ToString(separator), maxValue));
        }
Example #15
0
        public static ArrayObject split(Object thisob, VsaEngine engine, Object separator, Object limit)
        {
            String thisStr    = Convert.ToString(thisob);
            uint   limitValue = UInt32.MaxValue;

            if (limit != null && !(limit is Missing) && limit != DBNull.Value)
            {
                double lmt = Convert.ToInteger(limit);
                if (lmt >= 0 && lmt < UInt32.MaxValue)
                {
                    limitValue = (uint)lmt;
                }
            }
            if (limitValue == 0)
            {
                return((ArrayObject)engine.GetOriginalArrayConstructor().Construct());
            }
            if (separator == null || separator is Missing)
            {
                ArrayObject array = (ArrayObject)engine.GetOriginalArrayConstructor().Construct();
                array.SetValueAtIndex(0, thisob);
                return(array);
            }
            RegExpObject regExpObject = separator as RegExpObject;

            if (regExpObject != null)
            {
                return(StringPrototype.SplitWithRegExp(thisStr, engine, regExpObject, limitValue));
            }
            Regex regex = separator as Regex;

            if (regex != null)
            {
                return(StringPrototype.SplitWithRegExp(thisStr, engine, new RegExpObject(regex), limitValue));
            }
            return(StringPrototype.SplitWithString(thisStr, engine, Convert.ToString(separator), limitValue));
        }
 public new ArrayObject CreateInstance(params Object[] args){
   ArrayObject arrayObj = new ArrayObject(this.originalPrototype, typeof(ArrayObject));
   if (args.Length != 0){
     if (args.Length == 1){
       Object arg0 = args[0];
       IConvertible ic = Convert.GetIConvertible(arg0);
       switch (Convert.GetTypeCode(arg0, ic)){
         case TypeCode.Char: 
         case TypeCode.SByte: 
         case TypeCode.Byte:
         case TypeCode.Int16: 
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64:
         case TypeCode.UInt64:
         case TypeCode.Single:
         case TypeCode.Double:
         case TypeCode.Decimal:
           double d = Convert.ToNumber(arg0, ic);
           uint len = Convert.ToUint32(arg0, ic);
           if (d != (double)len)
             throw new JScriptException(JSError.ArrayLengthConstructIncorrect);
           arrayObj.length = len;
           return arrayObj;
       }
     }
     if (args.Length == 1 && args[0] is Array){
       Array array = (Array)args[0];
       if (array.Rank != 1)
         throw new JScriptException(JSError.TypeMismatch);
       arrayObj.length = array.Length;
       for (int i = 0; i < array.Length; i++)
         arrayObj.SetValueAtIndex((uint)i, array.GetValue(i));
     } else {
       arrayObj.length = args.Length;
       for (int i = 0; i < args.Length; i++)
         arrayObj.SetValueAtIndex((uint)i, args[i]);
     }
   }
   return arrayObj;
 }
 protected void SpliceSlowly(uint start, uint deleteCount, object[] args, ArrayObject outArray, uint oldLength, uint newLength)
 {
     for (uint i = 0; i < deleteCount; i++)
     {
         outArray.SetValueAtIndex(i, this.GetValueAtIndex(i + start));
     }
     uint num2 = (oldLength - start) - deleteCount;
     if (newLength < oldLength)
     {
         for (uint k = 0; k < num2; k++)
         {
             this.SetValueAtIndex((k + start) + ((uint) args.Length), this.GetValueAtIndex((k + start) + deleteCount));
         }
         this.SetLength((ulong) newLength);
     }
     else
     {
         if (newLength > oldLength)
         {
             this.SetLength((ulong) newLength);
         }
         for (uint m = num2; m > 0; m--)
         {
             this.SetValueAtIndex((uint) (((m + start) + args.Length) - 1), this.GetValueAtIndex(((m + start) + deleteCount) - 1));
         }
     }
     int num5 = (args == null) ? 0 : args.Length;
     for (uint j = 0; j < num5; j++)
     {
         this.SetValueAtIndex(j + start, args[j]);
     }
 }
        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);
        }
 protected void SpliceSlowly(uint start, uint deleteCount, Object[] args, ArrayObject outArray, uint oldLength, uint newLength){
   for (uint i = 0; i < deleteCount; i++)
     outArray.SetValueAtIndex(i, this.GetValueAtIndex(i+start));
   uint n = oldLength-start-deleteCount;
   if (newLength < oldLength){
     for (uint i = 0; i < n; i++)
       this.SetValueAtIndex(i+start+(uint)args.Length, this.GetValueAtIndex(i+start+deleteCount));
     this.SetLength(newLength);
   }else{
     if (newLength > oldLength)
       this.SetLength(newLength);
     for (uint i = n; i > 0; i--)
       this.SetValueAtIndex(i+start+(uint)args.Length-1, this.GetValueAtIndex(i+start+deleteCount-1));
   }
   int m = args == null ? 0 : args.Length;
   for (uint i = 0; i < m; i++)
     this.SetValueAtIndex(i+start, args[i]);
 }
        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);
        }