put() public method

public put ( int i, JsInstance value ) : JsInstance
i int
value JsInstance
return JsInstance
Esempio n. 1
0
        public override JsObject Construct(JsInstance[] parameters, Type[] genericArgs, IJintVisitor visitor)
        {
            JsArray array = New();

            for (int i = 0; i < parameters.Length; i++)
            {
                array.put(i, parameters[i]); // fast versin since it avoids a type conversion
            }
            return(array);
        }
Esempio n. 2
0
        public override JsObject Construct(
            JsInstance[] parameters,
            Type[] genericArgs,
            IJintVisitor visitor)
        {
            JsArray jsArray = this.New();

            for (int i = 0; i < parameters.Length; ++i)
            {
                jsArray.put(i, parameters[i]);
            }
            return((JsObject)jsArray);
        }
Esempio n. 3
0
        /// <summary>
        /// 15.4.4.4
        /// </summary>
        /// <param name="target"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public JsInstance Concat(JsObject target, JsInstance[] parameters)
        {
            if (target is JsArray)
            {
                return(((JsArray)target).concat(Global, parameters));
            }
            JsArray           array = Global.ArrayClass.New();
            List <JsInstance> items = new List <JsInstance>();

            items.Add(target);
            items.AddRange(parameters);
            int n = 0;

            while (items.Count > 0)
            {
                JsInstance e = items[0];
                items.RemoveAt(0);
                if (Global.ArrayClass.HasInstance(e as JsObject))
                {
                    for (int k = 0; k < ((JsObject)e).Length; k++)
                    {
                        string     p      = k.ToString();
                        JsInstance result = null;
                        if (((JsObject)e).TryGetProperty(p, out result))
                        {
                            array.put(n, result);
                        }
                        n++;
                    }
                }
                else
                {
                    array.put(n, e);
                    n++;
                }
            }
            return(array);
        }
Esempio n. 4
0
        public JsInstance Concat(JsObject target, JsInstance[] parameters)
        {
            if (target is JsArray)
            {
                return((JsInstance)((JsArray)target).concat(this.Global, parameters));
            }
            JsArray           jsArray        = this.Global.ArrayClass.New();
            List <JsInstance> jsInstanceList = new List <JsInstance>();

            jsInstanceList.Add((JsInstance)target);
            jsInstanceList.AddRange((IEnumerable <JsInstance>)parameters);
            int i = 0;

            while (jsInstanceList.Count > 0)
            {
                JsInstance jsInstance = jsInstanceList[0];
                jsInstanceList.RemoveAt(0);
                if (this.Global.ArrayClass.HasInstance(jsInstance as JsObject))
                {
                    for (int index1 = 0; index1 < ((JsDictionaryObject)jsInstance).Length; ++index1)
                    {
                        string     index2 = index1.ToString();
                        JsInstance result = (JsInstance)null;
                        if (((JsDictionaryObject)jsInstance).TryGetProperty(index2, out result))
                        {
                            jsArray.put(i, result);
                        }
                        ++i;
                    }
                }
                else
                {
                    jsArray.put(i, jsInstance);
                    ++i;
                }
            }
            return((JsInstance)jsArray);
        }
Esempio n. 5
0
        public override JsObject Construct(JsInstance[] parameters, Type[] genericArgs, IJintVisitor visitor)
        {
            JsArray array = New();

            if (parameters.Length == 1 && parameters[0].Class == CLASS_NUMBER)
            {
                var num = parameters[0].ToNumber();
                if (Math.Abs(num - (int)num) > 0 || num < 0 || num >= int.MaxValue)
                {
                    throw new JsException(Global.RangeErrorClass.New("Invalid array length"));
                }
                for (int i = 0; i < num; i++)
                {
                    array.put(i, JsUndefined.Instance);
                }
                return(array);
            }

            for (int i = 0; i < parameters.Length; i++)
            {
                array.put(i, parameters[i]); // fast versin since it avoids a type conversion
            }
            return(array);
        }
Esempio n. 6
0
        /// <summary>
        /// 15.4.4.12
        /// </summary>
        /// <param name="target"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public JsInstance Splice(JsObject target, JsInstance[] parameters)
        {
            JsArray array             = Global.ArrayClass.New();
            int     relativeStart     = Convert.ToInt32(parameters[0].ToNumber());
            int     actualStart       = relativeStart < 0 ? Math.Max(target.Length + relativeStart, 0) : Math.Min(relativeStart, target.Length);
            int     actualDeleteCount = Math.Min(Math.Max(Convert.ToInt32(parameters[1].ToNumber()), 0), target.Length - actualStart);
            int     len = target.Length;

            for (int k = 0; k < actualDeleteCount; k++)
            {
                string     from   = (relativeStart + k).ToString();
                JsInstance result = null;
                if (target.TryGetProperty(from, out result))
                {
                    array.put(k, result);
                }
            }

            List <JsInstance> items = new List <JsInstance>();

            items.AddRange(parameters);
            items.RemoveAt(0);
            items.RemoveAt(0);

            // use non-distructional copy, determine direction
            if (items.Count < actualDeleteCount)
            {
                for (int k = actualStart; k < len - actualDeleteCount; k++)
                {
                    JsInstance result = null;
                    string     from   = (k + actualDeleteCount).ToString();
                    string     to     = (k + items.Count).ToString();
                    if (target.TryGetProperty(from, out result))
                    {
                        target[to] = result;
                    }
                    else
                    {
                        target.Delete(to);
                    }
                }

                for (int k = target.Length; k > len - actualDeleteCount + items.Count; k--)
                {
                    target.Delete((k - 1).ToString());
                }

                target.Length = len - actualDeleteCount + items.Count;
            }
            else
            {
                for (int k = len - actualDeleteCount; k > actualStart; k--)
                {
                    JsInstance result = null;
                    string     from   = (k + actualDeleteCount - 1).ToString();
                    string     to     = (k + items.Count - 1).ToString();
                    if (target.TryGetProperty(from, out result))
                    {
                        target[to] = result;
                    }
                    else
                    {
                        target.Delete(to);
                    }
                }
            }
            for (int k = 0; k < items.Count; k++)
            {
                target[k.ToString()] = items[k];
            }

            return(array);
        }
Esempio n. 7
0
        public JsInstance Splice(JsObject target, JsInstance[] parameters)
        {
            JsArray jsArray = this.Global.ArrayClass.New();
            int     int32   = Convert.ToInt32(parameters[0].ToNumber());
            int     num1    = int32 < 0 ? Math.Max(target.Length + int32, 0) : Math.Min(int32, target.Length);
            int     num2    = Math.Min(Math.Max(Convert.ToInt32(parameters[1].ToNumber()), 0), target.Length - num1);
            int     length1 = target.Length;
            int     num3;

            for (int i = 0; i < num2; ++i)
            {
                num3 = int32 + i;
                string     index  = num3.ToString();
                JsInstance result = (JsInstance)null;
                if (target.TryGetProperty(index, out result))
                {
                    jsArray.put(i, result);
                }
            }
            List <JsInstance> jsInstanceList = new List <JsInstance>();

            jsInstanceList.AddRange((IEnumerable <JsInstance>)parameters);
            jsInstanceList.RemoveAt(0);
            jsInstanceList.RemoveAt(0);
            if (jsInstanceList.Count < num2)
            {
                for (int index1 = num1; index1 < length1 - num2; ++index1)
                {
                    JsInstance result = (JsInstance)null;
                    num3 = index1 + num2;
                    string index2 = num3.ToString();
                    num3 = index1 + jsInstanceList.Count;
                    string index3 = num3.ToString();
                    if (target.TryGetProperty(index2, out result))
                    {
                        target[index3] = result;
                    }
                    else
                    {
                        target.Delete(index3);
                    }
                }
                for (int length2 = target.Length; length2 > length1 - num2 + jsInstanceList.Count; --length2)
                {
                    JsObject jsObject = target;
                    num3 = length2 - 1;
                    string index = num3.ToString();
                    jsObject.Delete(index);
                }
                target.Length = length1 - num2 + jsInstanceList.Count;
            }
            else
            {
                for (int index1 = length1 - num2; index1 > num1; --index1)
                {
                    JsInstance result = (JsInstance)null;
                    num3 = index1 + num2 - 1;
                    string index2 = num3.ToString();
                    num3 = index1 + jsInstanceList.Count - 1;
                    string index3 = num3.ToString();
                    if (target.TryGetProperty(index2, out result))
                    {
                        target[index3] = result;
                    }
                    else
                    {
                        target.Delete(index3);
                    }
                }
            }
            for (int index = 0; index < jsInstanceList.Count; ++index)
            {
                target[index.ToString()] = jsInstanceList[index];
            }
            return((JsInstance)jsArray);
        }