/// <summary>
        /// 15.4.4.9
        /// </summary>
        /// <param name="target"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public JsInstance Shift(JsDictionaryObject target, JsInstance[] parameters)
        {
            if (target.Length == 0)
            {
                return(JsUndefined.Instance);
            }

            JsInstance first = target[0.ToString()];

            for (int k = 1; k < target.Length; k++)
            {
                JsInstance result = null;

                string from = k.ToString();
                string to   = (k - 1).ToString();
                if (target.TryGetProperty(from, out result))
                {
                    target[to] = result;
                }
                else
                {
                    target.Delete(to);
                }
            }
            target.Delete((target.Length - 1).ToString());
            if (length != int.MinValue)
            {
                length -= parameters.Length;
            }
            return(first);
        }
        public JsInstance SetLengthImpl(JsInstance target, JsInstance[] parameters)
        {
            int length = (int)parameters[0].ToNumber();

            if (length < 0 || double.IsNaN(length) || double.IsInfinity(length))
            {
                throw new JsException(Global.RangeErrorClass.New("invalid array length"));
            }

            JsDictionaryObject array = (JsDictionaryObject)target;

            if (length < array.Length)
            {
                int oldLength = array.Length;
                for (int i = length; i < oldLength; i++)
                {
                    array.Delete(i.ToString());
                }
            }
            else
            {
                for (int i = array.Length; i < length; i++)
                {
                    array[i.ToString()] = JsUndefined.Instance;
                }
            }

            return(parameters[0]);
        }
Ejemplo n.º 3
0
        public JsInstance Shift(JsDictionaryObject target, JsInstance[] parameters)
        {
            if (target.Length == 0)
            {
                return((JsInstance)JsUndefined.Instance);
            }
            JsInstance jsInstance = target[0.ToString()];
            int        num;

            for (int index1 = 1; index1 < target.Length; ++index1)
            {
                JsInstance result = (JsInstance)null;
                string     index2 = index1.ToString();
                num = index1 - 1;
                string index3 = num.ToString();
                if (target.TryGetProperty(index2, out result))
                {
                    target[index3] = result;
                }
                else
                {
                    target.Delete(index3);
                }
            }
            JsDictionaryObject dictionaryObject = target;

            num = target.Length - 1;
            string index = num.ToString();

            dictionaryObject.Delete(index);
            num = target.Length--;
            return(jsInstance);
        }