DefineOwnProperty() 공개 메소드

public DefineOwnProperty ( string key, Descriptor d ) : void
key string
d Descriptor
리턴 void
        /// <summary>
        /// 15.4.4.4
        /// </summary>
        /// <param name="target"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public JsInstance Concat(JsObject target, JsInstance[] 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 (e.Class == JsArray.TYPEOF)
                {
                    for (int k = 0; k < ((JsArray)e).Length; k++)
                    {
                        string     p      = k.ToString();
                        JsInstance result = null;
                        if (((JsDictionaryObject)e).TryGetProperty(p, out result))
                        {
                            array.DefineOwnProperty(n.ToString(), new ValueDescriptor(this, n.ToString(), result));
                            n++;
                        }
                    }
                }
                else
                {
                    array.DefineOwnProperty(n.ToString(), new ValueDescriptor(this, n.ToString(), e));
                    n++;
                }
            }
            return(array);
        }
        /// <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.DefineOwnProperty(k.ToString(), new ValueDescriptor(target, k.ToString(), result));
                }
            }

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

            items.AddRange(parameters);
            items.RemoveAt(0);
            items.RemoveAt(0);
            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());
                }
            }
            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);
                    }
                }
                if (target.length != int.MinValue && target.Prototype != Prototype)
                {
                    target.length += len - actualDeleteCount + items.Count;
                }

                for (int k = 0; items.Count > 0; k++)
                {
                    JsInstance e = items[0];
                    items.RemoveAt(0);
                    target[k.ToString()] = e;
                }
            }
            return(array);
        }