상속: JSObject
        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]);
            }
        }
예제 #2
0
        public static object shift(object thisObj)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;
            Hashtable   elems     = array_obj.elems;

            uint   n      = (uint)array_obj.length;
            object result = null;

            if (n > 0)
            {
                if (elems.ContainsKey((uint)0))
                {
                    result = elems [(uint)0];
                    elems.Remove((uint)0);
                    for (uint i = 1; i < n; i++)
                    {
                        elems [i - 1] = elems [i];
                    }
                }
                // Last element gets removed automatically
                array_obj.length = n - 1;
            }
            return(result);
        }
        internal virtual void Concat(ArrayObject source)
        {
            uint len = source.len;

            if (len != 0)
            {
                uint num2 = this.len;
                this.SetLength(num2 + len);
                uint denseArrayLength = len;
                if (!(source is ArrayWrapper) && (len > source.denseArrayLength))
                {
                    denseArrayLength = source.denseArrayLength;
                }
                uint num4 = num2;
                for (uint i = 0; i < denseArrayLength; i++)
                {
                    this.SetValueAtIndex(num4++, source.GetValueAtIndex(i));
                }
                if (denseArrayLength != len)
                {
                    IDictionaryEnumerator enumerator = source.NameTable.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        long num6 = Array_index_for(enumerator.Key.ToString());
                        if (num6 >= 0L)
                        {
                            this.SetValueAtIndex(num2 + ((uint)num6), ((JSField)enumerator.Value).GetValue(null));
                        }
                    }
                }
            }
        }
        internal void SortArray(int left, int right)
        {
            ArrayObject array = (ArrayObject)this.obj;
            Object      x, y;

            if (right > left)
            {
                int piv = left + (int)((right - left) * MathObject.random());
                x = array.denseArray[piv];
                array.denseArray[piv]   = array.denseArray[right];
                array.denseArray[right] = x;
                int i = left - 1, j = right;
                while (true)
                {
                    do
                    {
                        y = array.denseArray[++i];
                    }while(i < j && this.Compare(x, y) >= 0);
                    do
                    {
                        y = array.denseArray[--j];
                    }while(j > i && this.Compare(x, y) <= 0);
                    if (i >= j)
                    {
                        break;
                    }
                    QuickSort.Swap(array.denseArray, i, j);
                }
                QuickSort.Swap(array.denseArray, i, right);
                this.SortArray(left, i - 1);
                this.SortArray(i + 1, right);
            }
        }
예제 #5
0
        public static ArrayObject concat(object thisObj, VsaEngine engine,
            params object [] args)
        {
            uint i = 0;
            ArrayObject result = new ArrayObject ();
            int arg_idx = -1;
            int arg_count = args.Length;

            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type (thisObj, typeof (ArrayObject));
            object cur_obj = thisObj;

            ArrayObject cur_ary;
            while (cur_obj != null) {
                if (cur_obj is ArrayObject) {
                    cur_ary = (ArrayObject) cur_obj;

                    uint n = (uint) cur_ary.length;
                    for (uint j = 0; j < n; j++, i++)
                        result.elems [i] = cur_ary.elems [j];
                } else
                    result.elems [i++] = cur_obj;

                arg_idx++;
                cur_obj = arg_idx < arg_count ? args [arg_idx] : null;
            }

            result.length = i;

            return result;
        }
예제 #6
0
        public static object unshift(object thisObj, params object [] args)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;
            Hashtable   elems     = array_obj.elems;

            uint old_length = (uint)array_obj.length;
            uint arg_length = (uint)args.Length;
            uint new_length = old_length + arg_length;

            if (arg_length > 0)
            {
                // First let's make some free space for the new items
                long i = (long)old_length - 1;
                long j = i + (long)arg_length;
                for (; i >= 0; i--, j--)
                {
                    elems [(uint)j] = elems [(uint)i];
                }

                // Then insert the new items in the now free space
                for (; j >= 0; j--)
                {
                    elems [(uint)j] = args [(uint)j];
                }
            }
            //
            // NOTE: MSC returns the new array, but
            // ECMA-262 says to return the new length. We
            // conform to the standard.
            //
            array_obj.length = new_length;
            return(new_length);
        }
 internal ArrayEnumerator(ArrayObject arrayOb, IEnumerator denseEnum){
   this.curr = -1;
   this.doDenseEnum = false;
   this.didDenseEnum = false;
   this.arrayOb = arrayOb;
   this.denseEnum = denseEnum;
 }
 /// <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;
 }
예제 #9
0
        public static string toLocaleString(object thisObj)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;

            string separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator + " ";

            Hashtable     elems = array_obj.elems;
            uint          n     = (uint)array_obj.length;
            StringBuilder str   = new StringBuilder();
            bool          first = true;

            for (uint i = 0; i < n; i++)
            {
                ScriptObject elem = (ScriptObject)Convert.ToObject(elems [i], null);
                if (!first && elem != null)
                {
                    str.Append(separator);
                }
                first = false;
                if (elem != null)
                {
                    str.Append(Convert.ToString(elem.CallMethod("toLocaleString", new object [] { })));
                }
            }
            return(str.ToString());
        }
        internal virtual ArrayObject Unshift(Object[] args)
        {
            Debug.PreCondition(args != null && args.Length > 0);
            uint  oldLength = this.len;
            int   numArgs   = args.Length;
            ulong newLength = oldLength + (ulong)numArgs;

            this.SetLength(newLength);
            if (newLength <= this.denseArrayLength)
            {
                for (int i = (int)(oldLength - 1); i >= 0; i--)
                {
                    this.denseArray[i + numArgs] = this.denseArray[i];
                }
                ArrayObject.Copy(args, 0, this.denseArray, 0, args.Length);
            }
            else
            {
                for (long i = oldLength - 1; i >= 0; i--)
                {
                    this.SetValueAtIndex((uint)(i + numArgs), this.GetValueAtIndex((uint)i));
                }
                for (uint i = 0; i < numArgs; i++)
                {
                    this.SetValueAtIndex(i, args[i]);
                }
            }
            return(this);
        }
        private void DeleteRange(uint start, uint end)
        {
            uint denseEnd = this.denseArrayLength;

            if (denseEnd > end)
            {
                denseEnd = end;
            }
            for (; start < denseEnd; start++)
            {
                denseArray[(int)start] = Missing.Value;
            }
            if (denseEnd == end)
            {
                return;
            }
            //Go through the field table entries, deleting those with names that are indices between start and end
            IDictionaryEnumerator e   = this.NameTable.GetEnumerator();
            ArrayList             arr = new ArrayList(this.name_table.count);

            while (e.MoveNext())
            {
                long i = ArrayObject.Array_index_for(e.Key.ToString());
                if (i >= start && i <= end)
                {
                    arr.Add(e.Key);
                }
            }
            IEnumerator ae = arr.GetEnumerator();

            while (ae.MoveNext())
            {
                this.DeleteMember((String)ae.Current);
            }
        }
        internal virtual Object Shift()
        {
            Object res        = null;
            uint   thisLength = this.len;

            if (thisLength == 0)
            {
                return(res);
            }
            uint lastItemInDense = (this.denseArrayLength >= thisLength) ? thisLength : this.denseArrayLength;

            if (lastItemInDense > 0)
            {
                res = this.denseArray[0];
                ArrayObject.Copy(this.denseArray, 1, this.denseArray, 0, (int)(lastItemInDense - 1));
            }
            else
            {
                res = base.GetValueAtIndex(0);
            }
            for (uint i = lastItemInDense; i < thisLength; i++)
            {
                this.SetValueAtIndex(i - 1, this.GetValueAtIndex(i));
            }
            this.SetValueAtIndex(thisLength - 1, Missing.Value);
            SetLength(thisLength - 1);
            if (res is Missing)
            {
                return(null);
            }
            return(res);
        }
        internal virtual Object[] ToArray()
        {
            int thisLength = (int)this.len;

            if (thisLength == 0)
            {
                return(new Object[0]);
            }
            else if (thisLength == this.denseArrayLength)
            {
                return(this.denseArray);
            }
            else if (thisLength < this.denseArrayLength)
            {
                Object[] result = new Object[thisLength];
                ArrayObject.Copy(this.denseArray, 0, result, 0, thisLength);
                return(result);
            }
            else
            {
                Object[] result = new Object[thisLength];
                ArrayObject.Copy(this.denseArray, 0, result, 0, (int)this.denseArrayLength);
                for (uint i = this.denseArrayLength; i < thisLength; i++)
                {
                    result[i] = this.GetValueAtIndex(i);
                }
                return(result);
            }
        }
        public static ArrayObject concat(Object thisob, VsaEngine engine, params Object[] args)
        {
            ArrayObject arrayObj = engine.GetOriginalArrayConstructor().Construct();

            if (thisob is ArrayObject)
            {
                arrayObj.Concat((ArrayObject)thisob);
            }
            else
            {
                arrayObj.Concat(thisob);
            }
            for (int i = 0; i < args.Length; i++)
            {
                Object arg = args[i];
                if (arg is ArrayObject)
                {
                    arrayObj.Concat((ArrayObject)arg);
                }
                else
                {
                    arrayObj.Concat(arg);
                }
            }
            return(arrayObj);
        }
예제 #15
0
        public static bool hasOwnProperty(object thisob, object name)
        {
            string str = Microsoft.JScript.Convert.ToString(name);

            if (thisob is ArrayObject)
            {
                long num = ArrayObject.Array_index_for(str);
                if (num >= 0L)
                {
                    object valueAtIndex = ((ArrayObject)thisob).GetValueAtIndex((uint)num);
                    return((valueAtIndex != null) && (valueAtIndex != Microsoft.JScript.Missing.Value));
                }
            }
            if (!(thisob is JSObject))
            {
                return(!(LateBinding.GetMemberValue(thisob, str) is Microsoft.JScript.Missing));
            }
            MemberInfo[] member = ((JSObject)thisob).GetMember(str, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            int          length = member.Length;

            if (length <= 1)
            {
                if (length < 1)
                {
                    return(false);
                }
                if (member[0] is JSPrototypeField)
                {
                    return(!(((JSPrototypeField)member[0]).value is Microsoft.JScript.Missing));
                }
            }
            return(true);
        }
        public static ArrayObject concat(object thisob, VsaEngine engine, params object[] args)
        {
            ArrayObject obj2 = engine.GetOriginalArrayConstructor().Construct();

            if (thisob is ArrayObject)
            {
                obj2.Concat((ArrayObject)thisob);
            }
            else
            {
                obj2.Concat(thisob);
            }
            for (int i = 0; i < args.Length; i++)
            {
                object obj3 = args[i];
                if (obj3 is ArrayObject)
                {
                    obj2.Concat((ArrayObject)obj3);
                }
                else
                {
                    obj2.Concat(obj3);
                }
            }
            return(obj2);
        }
예제 #17
0
        public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
        {
            MethodInfo setter = this.setter;
            JSObject   obj2   = obj as JSObject;

            if ((setter == null) && (obj2 != null))
            {
                setter = obj2.GetMethod("set_" + this.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                JSWrappedMethod method = setter as JSWrappedMethod;
                if (method != null)
                {
                    setter = method.method;
                }
            }
            if (setter == null)
            {
                setter = this.GetSetMethod(false);
            }
            if (setter != null)
            {
                if ((index == null) || (index.Length == 0))
                {
                    setter.Invoke(obj, invokeAttr, binder, new object[] { value }, culture);
                }
                else
                {
                    int      length = index.Length;
                    object[] target = new object[length + 1];
                    ArrayObject.Copy(index, 0, target, 0, length);
                    target[length] = value;
                    setter.Invoke(obj, invokeAttr, binder, target, culture);
                }
            }
        }
예제 #18
0
        internal static void SetValue(PropertyInfo prop, object obj, object value, object[] index)
        {
            JSProperty property = prop as JSProperty;

            if (property != null)
            {
                property.SetValue(obj, value, BindingFlags.ExactBinding, null, index, null);
            }
            else
            {
                MethodInfo setMethod = GetSetMethod(prop, false);
                if (setMethod == null)
                {
                    throw new MissingMethodException();
                }
                int      n      = (index == null) ? 0 : index.Length;
                object[] target = new object[n + 1];
                if (n > 0)
                {
                    ArrayObject.Copy(index, 0, target, 0, n);
                }
                target[n] = value;
                setMethod.Invoke(obj, BindingFlags.ExactBinding, null, target, null);
            }
        }
예제 #19
0
        public static bool hasOwnProperty(Object thisob, Object name)
        {
            String nameStr = Convert.ToString(name);

            if (thisob is ArrayObject)
            {
                long index = ArrayObject.Array_index_for(nameStr);
                if (index >= 0)
                {
                    Object ob = ((ArrayObject)thisob).GetValueAtIndex((uint)index);
                    return(ob != null && ob != Missing.Value);
                }
            }
            if (thisob is JSObject)
            {
                MemberInfo[] members = ((JSObject)thisob).GetMember(nameStr, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly);
                int          n       = members.Length;
                if (n > 1)
                {
                    return(true);
                }
                if (n < 1)
                {
                    return(false);
                }
                if (members[0] is JSPrototypeField)
                {
                    //Do not count it as an "own" property unless it has been written to
                    return(!(((JSPrototypeField)members[0]).value is Missing));
                }
                return(true);
            }
            return(!(LateBinding.GetMemberValue(thisob, nameStr) is Missing));
        }
예제 #20
0
 // Splice the array slowly.
 protected void SpliceSlowly(uint start, uint deleteCount,
                             Object[] args, ArrayObject outArray,
                             uint oldLength, uint newLength)
 {
     // This exists for backwards-compatibility, but there
     // is actually no way to call it from user code.
 }
        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]);
            }
        }
예제 #22
0
        public static object match(object thisObj, VsaEngine engine, object regExp)
        {
            string       string_obj = Convert.ToString(thisObj);
            RegExpObject regex_obj  = Convert.ToRegExp(regExp);
            bool         global     = regex_obj.global;

            if (!global)
            {
                return(RegExpPrototype.exec(regex_obj, string_obj));
            }

            MatchCollection md        = regex_obj.regex.Matches(string_obj);
            uint            n         = (uint)md.Count;
            Match           lastMatch = md [(int)(n - 1)];

            regex_obj.lastIndex = lastMatch.Index + 1;
            RegExpConstructor.UpdateLastMatch(lastMatch, string_obj);

            ArrayObject result = new ArrayObject();

            result.length = n;
            for (uint i = 0; i < n; i++)
            {
                result.elems [i] = md [(int)i].Value;
            }

            return(result);
        }
 internal override void Concat(ArrayObject source)
 {
     if (!this.hydrated)
     {
         this.Hydrate();
     }
     base.Concat(source);
 }
예제 #24
0
 internal ArrayEnumerator(ArrayObject arrayOb, IEnumerator denseEnum)
 {
     this.curr         = -1;
     this.doDenseEnum  = false;
     this.didDenseEnum = false;
     this.arrayOb      = arrayOb;
     this.denseEnum    = denseEnum;
 }
예제 #25
0
 internal override void Splice(uint start, uint deleteCount, Object[] args, ArrayObject outArray, uint oldLength, uint newLength)
 {
     if (oldLength != newLength)
     {
         throw new JScriptException(JSError.ActionNotSupported);
     }
     SpliceSlowly(start, deleteCount, args, outArray, oldLength, newLength);
 }
 internal override void Concat(ArrayObject source)
 {
     if (!this.hydrated)
     {
         this.Hydrate();
     }
     base.Concat(source);
 }
 internal override void Splice(uint start, uint deleteItems, object[] args, ArrayObject outArray, uint oldLength, uint newLength)
 {
     if (!this.hydrated)
     {
         this.Hydrate();
     }
     base.Splice(start, deleteItems, args, outArray, oldLength, newLength);
 }
예제 #28
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);
        }
예제 #30
0
        private static void AdjustArrayLength(ArrayObject ary, uint index)
        {
            uint old_len = (uint)ary.length;

            if (index > 0 && index != 4294967295 && index > old_len)
            {
                ary.length = index + 1;
            }
        }
예제 #31
0
        internal override object GetMemberValue(string name)
        {
            long num = ArrayObject.Array_index_for(name);

            if (num < 0L)
            {
                return(base.GetMemberValue(name));
            }
            return(this.GetValueAtIndex((uint)num));
        }
예제 #32
0
 internal void Push(object item)
 {
     if (++this.top >= this.elements.Length)
     {
         object[] target = new object[this.elements.Length + 0x20];
         ArrayObject.Copy(this.elements, target, this.elements.Length);
         this.elements = target;
     }
     this.elements[this.top] = item;
 }
예제 #33
0
 internal void Push(Object item)
 {
     if (++this.top >= this.elements.Length)
     {
         Object[] newelems = new Object[this.elements.Length + 32];
         ArrayObject.Copy(this.elements, newelems, this.elements.Length);
         this.elements = newelems;
     }
     this.elements[this.top] = item;
 }
예제 #34
0
        public static ArrayObject slice(object thisObj, VsaEngine engine, double start, object end)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;
            uint        array_len = (uint)array_obj.length;
            uint        _start, _end;

            if (start > array_len)
            {
                _start = array_len;
            }
            else
            {
                _start = (uint)start;
                if (_start < 0)
                {
                    _start += array_len;
                }
            }

            if (end == null)
            {
                _end = array_len;
            }
            else
            {
                _end = Convert.ToUint32(end);

                if (_end < 0)
                {
                    _end += array_len;
                }
                else if (_end > array_len)
                {
                    _end = array_len;
                }
            }

            if (_end < _start)
            {
                _end = _start;
            }

            ArrayObject result = new ArrayObject();

            result.length = _end - _start;

            for (uint i = _start; i < _end; i++)
            {
                result.elems [i - _start] = array_obj.elems [i];
            }

            return(result);
        }
	// Construct a new array from a list of elements.
	public ArrayObject ConstructArray(Object[] args)
			{
				ArrayObject obj = new ArrayObject
					(EngineInstance.GetEngineInstance(engine)
							.GetArrayPrototype());
				int index, len;
				len = args.Length;
				for(index = 0; index < len; ++index)
				{
					obj.PutIndex(index, args[index]);
				}
				return obj;
			}
 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;
 }
예제 #37
0
 internal override void Concat(ArrayObject source){
   throw new JScriptException(JSError.ActionNotSupported);
 }
예제 #38
0
 internal override void Splice(uint start, uint deleteCount, Object[] args, ArrayObject outArray, uint oldLength, uint newLength){
   if (oldLength != newLength)
     throw new JScriptException(JSError.ActionNotSupported); 
   SpliceSlowly(start, deleteCount, args, outArray, oldLength, newLength);
 }
예제 #39
0
 internal virtual void Concat(ArrayObject source){
   uint sourceLength = source.len;
   if (sourceLength == 0)
     return;
   uint oldLength = this.len;
   this.SetLength(oldLength + (ulong)sourceLength);
   uint slen = sourceLength;
   if (!(source is ArrayWrapper) && sourceLength > source.denseArrayLength) 
     slen = source.denseArrayLength;
   uint j = oldLength;
   for (uint i = 0; i < slen; i++)
     this.SetValueAtIndex(j++, source.GetValueAtIndex(i));
   if (slen == sourceLength) return;
   //Iterate over the sparse indices of source
   IDictionaryEnumerator e = source.NameTable.GetEnumerator();
   while (e.MoveNext()){
     long i = ArrayObject.Array_index_for(e.Key.ToString());
     if (i >= 0)
       this.SetValueAtIndex(oldLength+(uint)i, ((JSField)e.Value).GetValue(null));
   }
 }
 internal override void Splice(uint start, uint deleteItems, object[] args, ArrayObject outArray, uint oldLength, uint newLength)
 {
     if (!this.hydrated)
     {
         this.Hydrate();
     }
     base.Splice(start, deleteItems, args, outArray, oldLength, newLength);
 }
예제 #41
0
        public static ArrayObject splice(object thisObj, VsaEngine engine,
            double start, double deleteCnt,
            params object [] args)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type (thisObj, typeof (ArrayObject));
            ArrayObject array_obj = (ArrayObject) thisObj;
            ArrayObject result = new ArrayObject ();
            Hashtable elems = array_obj.elems;
            Hashtable del_elems = result.elems;

            uint old_length = (uint) array_obj.length;
            start = (long) start;
            if (start < 0)
                start = Math.Max (start + old_length, 0);
            else
                start = Math.Min (old_length, start);

            deleteCnt = (long) deleteCnt;
            deleteCnt = Math.Min (Math.Max (deleteCnt, 0), old_length - start);

            uint arg_length = (uint) args.Length;
            long add_length = (long) ((long) arg_length - (uint) deleteCnt);
            add_length = (long) Math.Max (add_length, -((long) old_length));
            long del_length = -add_length;
            uint new_length = (uint) ((long) old_length + add_length);

            long i, j, m;
            // First let's make some free space for the new items (if needed)
            if (add_length > 0) {
                i = (long) old_length - 1;
                j = (uint) (i + add_length);
                for (; i >= start; i--, j--)
                    elems [(uint) j] = elems [(uint) i];
            }

            // Then insert the new items in the now free space / replace existing ones
            j = m = 0;
            long old_start = (long) (start + add_length);
            for (i = (long) start; j < arg_length; i++, j++) {
                if (i >= old_start && elems.ContainsKey ((uint) i)) {
                    del_elems [(uint) m] = elems [(uint) i];
                    m++;
                    elems.Remove ((uint) i);
                }

                if (j < arg_length)
                    elems [(uint) i] = args [(uint) j];
            }

            // Finally, delete elements which have no replacement elements
            if (add_length < 0) {
                uint last_elem_idx = (uint) (i + del_length);
                for (uint k = 0; k < del_length; i++, j++, k++) {
                    if (elems.ContainsKey ((uint) i)) {
                        del_elems [(uint) m] = elems [(uint) i];
                        m++;
                        elems.Remove ((uint) i);
                    }
                }

                // And move up trailing elements
                uint l = (uint) (last_elem_idx - del_length);
                for (uint k = last_elem_idx; l < old_length; k++, l++) {
                    if (elems.ContainsKey (k))
                        elems [l] = elems [k];
                    else if (elems.ContainsKey (l))
                        elems.Remove (l);
                }
            }

            array_obj.length = new_length;
            result.length = (uint) deleteCnt;
            return result;
        }
예제 #42
0
        public static ArrayObject split(object thisObj, VsaEngine engine,
            object separator, object limit)
        {
            string string_obj = Convert.ToString (thisObj);
            int length = string_obj.Length;
            int max_count = (limit != null) ? Convert.ToInt32 (limit) : -1;
            ArrayObject result = new ArrayObject ();

            if (separator == null) {
                result.length = (uint) 1;
                result.elems [(uint) 0] = string_obj;
                return result;
            }

            int start_pos = 0;
            int end_pos = -1;
            int match_len = 0;
            uint count = 0;
            int sep_len = 0;

            if (!(separator is RegExpObject)) {
                string sep_str = Convert.ToString (separator);
                sep_len = sep_str.Length;

                if (string_obj.Length == 0) {
                    if (sep_len > 0) {
                        result.length = (uint) 1;
                        result.elems [(uint) 0] = string_obj;
                    }

                    return result;
                }

                while (end_pos != length && (max_count == -1 || count < max_count)) {
                    end_pos = (length != 0) ? string_obj.IndexOf (sep_str, start_pos) : length;
                    if (end_pos == -1)
                        end_pos = length;
                    else if (sep_len == 0)
                        end_pos++;

                    match_len = end_pos - start_pos;
                    result.elems [count] = string_obj.Substring (start_pos, match_len);

                    start_pos += match_len + sep_len;
                    count++;
                }

                result.length = count;
                return result;
            }

            RegExpObject sep_re = (RegExpObject) separator;
            MatchCollection md = sep_re.regex.Matches (string_obj);
            uint n = (uint) md.Count;

            Match match = null;
            for (int i = 0; i < n; i++) {
                if (max_count != -1 && count >= max_count)
                    break;

                match = md [i];
                sep_len = match.Length;
                end_pos = match.Index;
                match_len = end_pos - start_pos;

                //
                // The specification says that "ab".split(/a*/) is ["", "b"], but would
                // that would also mean that "abcdef".split(/./).length would not be 6.
                // I'm currently going with the Rhino behavior that seems to make more
                // sense.
                //
                if (!(end_pos == 0 && sep_len == 0)) {
                    result.elems [count] = string_obj.Substring (start_pos, match_len);
                    count++;
                }

                bool first_cap = true;
                foreach (Capture cap in match.Groups) {
                    if (max_count != -1 && count >= max_count)
                        break;

                    if (first_cap) {
                        first_cap = false;
                        continue;
                    }

                    result.elems [count] = cap.Value;
                    count++;
                }

                start_pos += match_len + sep_len;
            }

            if (n > 0 && (max_count == -1 || count < max_count)) {
                sep_re.lastIndex = match.Index + match.Length;
                RegExpConstructor.UpdateLastMatch (match, string_obj);

                if (start_pos < length) {
                    result.elems [count] = string_obj.Substring (start_pos);
                    count++;
                }
            } else if (n == 0) {
                result.elems [(uint) 0] = string_obj;
                count++;
            }

            result.length = count;
            return result;
        }
 internal DebugArrayFieldEnumerator(ScriptObjectPropertyEnumerator enumerator, ArrayObject arrayObject)
 {
     this.enumerator = enumerator;
     this.arrayObject = arrayObject;
     this.EnsureCount();
 }
 internal virtual void Splice(uint start, uint deleteCount, object[] args, ArrayObject outArray, uint oldLength, uint newLength)
 {
     if (oldLength > this.denseArrayLength)
     {
         this.SpliceSlowly(start, deleteCount, args, outArray, oldLength, newLength);
     }
     else
     {
         if (newLength > oldLength)
         {
             this.SetLength((ulong) newLength);
             if (newLength > this.denseArrayLength)
             {
                 this.SpliceSlowly(start, deleteCount, args, outArray, oldLength, newLength);
                 return;
             }
         }
         if (deleteCount > oldLength)
         {
             deleteCount = oldLength;
         }
         if (deleteCount > 0)
         {
             Copy(this.denseArray, (int) start, outArray.denseArray, 0, (int) deleteCount);
         }
         if (oldLength > 0)
         {
             Copy(this.denseArray, (int) (start + deleteCount), this.denseArray, ((int) start) + args.Length, (int) ((oldLength - start) - deleteCount));
         }
         if (args != null)
         {
             int length = args.Length;
             if (length > 0)
             {
                 Copy(args, 0, this.denseArray, (int) start, length);
             }
             if (length < deleteCount)
             {
                 this.SetLength((ulong) newLength);
             }
         }
         else if (deleteCount > 0)
         {
             this.SetLength((ulong) newLength);
         }
     }
 }
 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]);
     }
 }
 internal virtual void Concat(ArrayObject source)
 {
     uint len = source.len;
     if (len != 0)
     {
         uint num2 = this.len;
         this.SetLength(num2 + len);
         uint denseArrayLength = len;
         if (!(source is ArrayWrapper) && (len > source.denseArrayLength))
         {
             denseArrayLength = source.denseArrayLength;
         }
         uint num4 = num2;
         for (uint i = 0; i < denseArrayLength; i++)
         {
             this.SetValueAtIndex(num4++, source.GetValueAtIndex(i));
         }
         if (denseArrayLength != len)
         {
             IDictionaryEnumerator enumerator = source.NameTable.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 long num6 = Array_index_for(enumerator.Key.ToString());
                 if (num6 >= 0L)
                 {
                     this.SetValueAtIndex(num2 + ((uint) num6), ((JSField) enumerator.Value).GetValue(null));
                 }
             }
         }
     }
 }
예제 #47
0
 private static void AdjustArrayLength(ArrayObject ary, uint index)
 {
     uint old_len = (uint) ary.length;
     if (index > 0 && index != 4294967295 && index > old_len)
         ary.length = index + 1;
 }
 internal ArrayEnumerator(ArrayObject arrayOb, IEnumerator denseEnum)
 {
     this.arrayOb = arrayOb;
     this.denseEnum = denseEnum;
 }
예제 #49
0
	// Splice the array slowly.
	protected void SpliceSlowly(uint start, uint deleteCount,
								Object[] args, ArrayObject outArray,
								uint oldLength, uint newLength)
			{
				// This exists for backwards-compatibility, but there
				// is actually no way to call it from user code.
			}
	// Perform a constructor call on this object.
	internal override Object Construct(VsaEngine engine, Object[] args)
			{
				ArrayObject obj;
				int index, len;
				if(args.Length != 1)
				{
					// Construct an array from a list of values.
					obj = new ArrayObject
						(EngineInstance.GetEngineInstance(engine)
								.GetArrayPrototype(), (uint)(args.Length));
					len = args.Length;
					for(index = 0; index < len; ++index)
					{
						obj.PutIndex(index, args[index]);
					}
				}
				else if(args[0] is Array)
				{
					// Wrap an existing array.
					Array array = (Array)(args[0]);
					if(array.Rank != 1)
					{
						throw new JScriptException(JSError.TypeMismatch);
					}
					obj = new ArrayObject.Wrapper
						(EngineInstance.GetEngineInstance(engine)
								.GetArrayPrototype(), (Array)(args[0]));
				}
				else
				{
					// Construct an array from a length value.
					switch(Support.TypeCodeForObject(args[0]))
					{
						case TypeCode.Byte:
						case TypeCode.SByte: 
						case TypeCode.Char: 
						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 = Convert.ToNumber(args[0]);
							uint inum = Convert.ToUInt32(args[0]);
							if(num == (double)inum)
							{
								return new ArrayObject
									(EngineInstance.GetEngineInstance(engine)
											.GetArrayPrototype(), inum);
							}
							else
							{
								throw new JScriptException
									(JSError.ArrayLengthConstructIncorrect);
							}
						}
						// Not reached.
					}

					// The length is not numeric, so it is actually a value.
					obj = new ArrayObject
						(EngineInstance.GetEngineInstance(engine)
								.GetArrayPrototype());
					obj.PutIndex(0, args[0]);
				}
				return obj;
			}
예제 #51
0
        private List<PayloadObject> ParseJsonArray(ArrayObject jsonData)
        {
            List<PayloadObject> payloadObjects = new List<PayloadObject>();

            for (int i = 0; i < (int)jsonData.length; i++)
            {
                JSObject resource = (JSObject)jsonData[i];
                payloadObjects.Add(parseJsonObject(resource));
            }

            return payloadObjects;
        }
예제 #52
0
        public static object match(object thisObj, VsaEngine engine, object regExp)
        {
            string string_obj = Convert.ToString (thisObj);
            RegExpObject regex_obj = Convert.ToRegExp (regExp);
            bool global = regex_obj.global;

            if (!global)
                return RegExpPrototype.exec (regex_obj, string_obj);

            MatchCollection md = regex_obj.regex.Matches (string_obj);
            uint n = (uint) md.Count;
            Match lastMatch = md [(int) (n - 1)];
            regex_obj.lastIndex = lastMatch.Index + 1;
            RegExpConstructor.UpdateLastMatch (lastMatch, string_obj);

            ArrayObject result = new ArrayObject ();
            result.length = n;
            for (uint i = 0; i < n; i++)
                result.elems [i] = md [(int) i].Value;

            return result;
        }
예제 #53
0
 protected void SpliceSlowly(uint start, uint deleteCount, object [] args, ArrayObject outArray, uint oldLength, uint newLength)
 {
     ArrayPrototype.splice (outArray, null, start, deleteCount, args);
 }
예제 #54
0
        public static ArrayObject slice(object thisObj, VsaEngine engine, double start, object end)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type (thisObj, typeof (ArrayObject));
            ArrayObject array_obj = (ArrayObject) thisObj;
            uint array_len = (uint) array_obj.length;
            uint _start, _end;

            if (start > array_len)
                _start = array_len;
            else {
                _start = (uint) start;
                if (_start < 0)
                    _start += array_len;
            }

            if (end == null)
                _end = array_len;
            else {
                _end = Convert.ToUint32 (end);

                if (_end < 0)
                    _end += array_len;
                else if (_end > array_len)
                    _end = array_len;
            }

            if (_end < _start)
                _end = _start;

            ArrayObject result = new ArrayObject();
            result.length = _end - _start;

            for (uint i = _start; i < _end; i++)
                result.elems [i - _start] = array_obj.elems [i];

            return result;
        }
예제 #55
0
 internal virtual void Splice(uint start, uint deleteCount, Object[] args, ArrayObject outArray, uint oldLength, uint newLength){
   if (oldLength > this.denseArrayLength){
     SpliceSlowly(start, deleteCount, args, outArray, oldLength, newLength);
     return;
   }
   if (newLength > oldLength){
     this.SetLength(newLength);
     if (newLength > this.denseArrayLength){
       SpliceSlowly(start, deleteCount, args, outArray, oldLength, newLength);
       return;
     }
   }
   if (deleteCount > oldLength)
     deleteCount = oldLength;
   if (deleteCount > 0)
     ArrayObject.Copy(this.denseArray, (int)start, outArray.denseArray, 0, (int)deleteCount);
   if (oldLength > 0)
     ArrayObject.Copy(this.denseArray, (int)(start+deleteCount), this.denseArray, (int)(start)+args.Length, (int)(oldLength-start-deleteCount));
   if (args != null){
     int n = args.Length;
     if (n > 0)
       ArrayObject.Copy(args, 0, this.denseArray, (int)start, n);
     if (n < deleteCount)
       this.SetLength(newLength);
   }else if (deleteCount > 0)
     this.SetLength(newLength);
 }
예제 #56
0
 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]);
 }
예제 #57
0
	public override Object Eval(VsaEngine engine)
#line 42 "./Nodes/JExpr.tc"
	{
		// Create a new instance of "Array".
		ArrayObject value = new ArrayObject
			(EngineInstance.GetEngineInstance(engine).GetArrayPrototype());
	
		// Evaluate and add the elements.
		JExprListElem elem = first;
		int index = 0;
		while(elem != null)
		{
			value[index++] = elem.expr.Eval(engine);
			elem = elem.next;
		}
	
		// Return the object to the caller.
		return value;
	}