Copy() static private method

static private Copy ( Object source, Object target, int n ) : void
source Object
target Object
n int
return void
        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);
        }
        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);
            }
        }
Example #3
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);
            }
        }
        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);
        }
Example #5
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);
                }
            }
        }
Example #6
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;
 }
Example #7
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;
 }
Example #8
0
        public override object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)
        {
            if (target != this)
            {
                throw new TargetException();
            }
            string str = "this";

            if (name.Equals("[DISPID=0]"))
            {
                name = string.Empty;
                if (namedParameters != null)
                {
                    str = "[DISPID=-613]";
                }
            }
            if ((name == null) || (name == string.Empty))
            {
                if ((invokeAttr & BindingFlags.CreateInstance) != BindingFlags.Default)
                {
                    if ((invokeAttr & (BindingFlags.PutDispProperty | BindingFlags.SetProperty | BindingFlags.GetProperty | BindingFlags.SetField | BindingFlags.GetField | BindingFlags.InvokeMethod)) != BindingFlags.Default)
                    {
                        throw new ArgumentException();
                    }
                    return(this.Construct(args));
                }
                if ((invokeAttr & BindingFlags.InvokeMethod) != BindingFlags.Default)
                {
                    object thisob = null;
                    if (namedParameters != null)
                    {
                        int index = Array.IndexOf <string>(namedParameters, str);
                        if (index == 0)
                        {
                            thisob = args[0];
                            int      n        = args.Length - 1;
                            object[] objArray = new object[n];
                            ArrayObject.Copy(args, 1, objArray, 0, n);
                            args = objArray;
                        }
                        if ((index != 0) || (namedParameters.Length != 1))
                        {
                            throw new ArgumentException();
                        }
                    }
                    if ((args.Length > 0) || ((invokeAttr & (BindingFlags.GetProperty | BindingFlags.GetField)) == BindingFlags.Default))
                    {
                        return(this.Call(args, thisob, binder, culture));
                    }
                }
            }
            return(base.InvokeMember(name, invokeAttr, binder, target, args, modifiers, culture, namedParameters));
        }
Example #9
0
        public override Object InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args,
                                            ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
        {
            if (target != this)
            {
                throw new TargetException();
            }

            String thisName = "this";

            if (name == null || name == String.Empty)
            {
                if ((invokeAttr & BindingFlags.CreateInstance) != 0)
                {
                    if ((invokeAttr & (BindingFlags.InvokeMethod | BindingFlags.GetField | BindingFlags.GetProperty |
                                       BindingFlags.SetField | BindingFlags.SetProperty | BindingFlags.PutDispProperty)) != 0)
                    {
                        throw new ArgumentException();
                    }
                    return(this.Construct(args));
                }

                if ((invokeAttr & BindingFlags.InvokeMethod) != 0)
                {
                    //Get the this object
                    Object thisob = null;
                    if (namedParameters != null)
                    {
                        int i = Array.IndexOf(namedParameters, thisName);
                        if (i == 0)
                        {
                            thisob = args[0];
                            int      n     = args.Length - 1;
                            Object[] args2 = new Object[n];
                            ArrayObject.Copy(args, 1, args2, 0, n);
                            args = args2;
                        }
                        if (i != 0 || namedParameters.Length != 1)
                        {
                            throw new ArgumentException();
                        }
                    }

                    //Prefer call only if there GetXXX is not set, or there is one or more args.
                    if (args.Length > 0 || (invokeAttr & (BindingFlags.GetField | BindingFlags.GetProperty)) == 0)
                    {
                        return(this.Call(args, thisob, binder, culture));
                    }
                }
            }
            return(base.InvokeMember(name, invokeAttr, binder, target, args, modifiers, culture, namedParameters));
        }
Example #10
0
 internal void GuardedPush(object item)
 {
     if (this.top > 500)
     {
         throw new JScriptException(JSError.OutOfStack);
     }
     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;
 }
Example #11
0
 internal void GuardedPush(Object item)
 {
     if (this.top > 500)
     {
         throw new JScriptException(JSError.OutOfStack);
     }
     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;
 }
 private Object[] CheckArguments(Object[] args)
 {
     Object[] newArgs = args;
     if (args != null && args.Length < this.pars.Length)
     {
         newArgs = new Object[this.pars.Length];
         ArrayObject.Copy(args, newArgs, args.Length);
         for (int i = args.Length, size = this.pars.Length; i < size; i++)
         {
             newArgs[i] = System.Type.Missing; // this will take care of the default value
         }
     }
     return(newArgs);
 }
Example #13
0
 public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
 {
     if ((index == null) || (index.Length == 0))
     {
         this.GetSetMethod(false).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;
         this.GetSetMethod(false).Invoke(obj, invokeAttr, binder, target, culture);
     }
 }
 public override void SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
 {
     if (index == null || index.Length == 0)
     {
         this.GetSetMethod(false).Invoke(obj, invokeAttr, binder, new Object[] { value }, culture);
     }
     else
     {
         int      n    = index.Length;
         Object[] args = new Object[n + 1];
         ArrayObject.Copy(index, 0, args, 0, n);
         args[n] = value;
         this.GetSetMethod(false).Invoke(obj, invokeAttr, binder, args, culture);
     }
 }
Example #15
0
        public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
        {
            if (this.setMeth == null)
            {
                throw new MissingMethodException();
            }
            int n = (index == null) ? 0 : index.Length;

            object[] target = new object[n + 1];
            target[0] = value;
            if (n > 0)
            {
                ArrayObject.Copy(index, 0, target, 1, n);
            }
            this.setMeth.Invoke(obj, invokeAttr, binder, target, culture);
        }
Example #16
0
        public override void SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
        {
            if (this.setMeth == null)
            {
                throw new MissingMethodException();
            }
            int n = index == null ? 0 : index.Length;

            Object[] pars = new Object[n + 1];
            pars[0] = value;
            if (n > 0)
            {
                ArrayObject.Copy(index, 0, pars, 1, n);
            }
            this.setMeth.Invoke(obj, invokeAttr, binder, pars, culture);
        }
Example #17
0
 private object[] CheckArguments(object[] args)
 {
     object[] target = args;
     if ((args != null) && (args.Length < this.pars.Length))
     {
         target = new object[this.pars.Length];
         ArrayObject.Copy(args, target, args.Length);
         int length = args.Length;
         int num2   = this.pars.Length;
         while (length < num2)
         {
             target[length] = Type.Missing;
             length++;
         }
     }
     return(target);
 }
 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);
     }
 }
Example #19
0
        public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
        {
            int    index = parameters.Length - 1;
            object obj2  = parameters[index];

            object[] target = null;
            if (index > 0)
            {
                target = new object[index];
                ArrayObject.Copy(parameters, 0, target, 0, index);
            }
            else
            {
                target = new object[0];
            }
            base._comObject.SetValue(obj2, invokeAttr, binder, target, culture);
            return(null);
        }
        private object[] CheckArguments(object[] arguments)
        {
            if (arguments == null)
            {
                return(arguments);
            }
            int length = arguments.Length;
            int num2   = this.parameters.Length;

            if (length >= num2)
            {
                return(arguments);
            }
            object[] target = new object[num2];
            ArrayObject.Copy(arguments, target, length);
            for (int i = length; i < num2; i++)
            {
                target[i] = Type.Missing;
            }
            return(target);
        }
        private Object[] CheckArguments(Object[] arguments)
        {
            if (arguments == null)
            {
                return(arguments);
            }
            int cArguments  = arguments.Length;
            int cParameters = this.parameters.Length;

            if (cArguments >= cParameters)
            {
                return(arguments);
            }
            Object[] newArgs = new Object[cParameters];
            ArrayObject.Copy(arguments, newArgs, cArguments);
            for (int i = cArguments; i < cParameters; i++)
            {
                newArgs[i] = System.Type.Missing;
            }
            return(newArgs);
        }
        public static object GetDefaultIndexedPropertyValue(object thisob, object[] arguments, VsaEngine engine, string[] namedParameters)
        {
            if (engine == null)
            {
                engine = VsaEngine.CreateEngine();
            }
            object[] target = null;
            int      num    = (arguments == null) ? 0 : arguments.Length;

            if (((namedParameters != null) && (namedParameters.Length > 0)) && ((namedParameters[0] == "this") && (num > 0)))
            {
                target = new object[num - 1];
                ArrayObject.Copy(arguments, 1, target, 0, num - 1);
            }
            else
            {
                target = arguments;
            }
            LateBinding binding = new LateBinding(null, thisob, true);

            return(binding.Call(target, false, false, engine));
        }
        private void Realloc(uint newLength)
        {
            Debug.PreCondition(this.denseArrayLength >= this.len);
            Debug.PreCondition(newLength <= ArrayObject.MaxIndex);
            uint oldDenseLength = this.denseArrayLength;
            uint newDenseLength = oldDenseLength * 2;

            if (newDenseLength < newLength)
            {
                newDenseLength = newLength;
            }
            Object[] newArray = new Object[(int)newDenseLength];
            if (oldDenseLength > 0)
            {
                ArrayObject.Copy(this.denseArray, newArray, (int)oldDenseLength);
            }
            for (int i = (int)oldDenseLength; i < newDenseLength; i++)
            {
                newArray[i] = Missing.Value;
            }
            this.denseArray       = newArray;
            this.denseArrayLength = newDenseLength;
        }
        public static void SetDefaultIndexedPropertyValue(object thisob, object[] arguments, VsaEngine engine, string[] namedParameters)
        {
            object obj2 = null;

            object[] target = null;
            int      length = arguments.Length;

            if (length > 0)
            {
                obj2 = arguments[length - 1];
            }
            int i = 0;
            int n = length - 1;

            if (((namedParameters != null) && (namedParameters.Length > 0)) && (namedParameters[0] == "this"))
            {
                n--;
                i = 1;
            }
            target = new object[n];
            ArrayObject.Copy(arguments, i, target, 0, n);
            new LateBinding(null, thisob, true).SetIndexedPropertyValue(target, obj2);
        }
Example #25
0
        internal override object Invoke(object obj, object thisob, BindingFlags options, Binder binder, object[] parameters, CultureInfo culture)
        {
            int length = this.formalParams.Length;
            int n      = (parameters != null) ? parameters.Length : 0;

            if ((!this.hasThis && !this.hasVarargs) && (length == n))
            {
                if (binder != null)
                {
                    return(TypeReferences.ToExecutionContext(this.method).Invoke(base.obj, BindingFlags.SuppressChangeType, null, this.ConvertParams(0, parameters, binder, culture), null));
                }
                return(TypeReferences.ToExecutionContext(this.method).Invoke(base.obj, options, binder, parameters, culture));
            }
            int index = (this.hasThis ? 1 : 0) + (this.hasEngine ? 1 : 0);

            object[] target = new object[length];
            if (this.hasThis)
            {
                target[0] = thisob;
                if (this.hasEngine)
                {
                    target[1] = this.engine;
                }
            }
            else if (this.hasEngine)
            {
                target[0] = this.engine;
            }
            if (this.hasVarargs)
            {
                if (length == (index + 1))
                {
                    target[index] = parameters;
                }
                else
                {
                    int num4 = (length - 1) - index;
                    if (n > num4)
                    {
                        ArrayObject.Copy(parameters, 0, target, index, num4);
                        int      num5      = n - num4;
                        object[] objArray2 = new object[num5];
                        ArrayObject.Copy(parameters, num4, objArray2, 0, num5);
                        target[length - 1] = objArray2;
                    }
                    else
                    {
                        ArrayObject.Copy(parameters, 0, target, index, n);
                        for (int i = n; i < num4; i++)
                        {
                            target[i + index] = Microsoft.JScript.Missing.Value;
                        }
                        target[length - 1] = new object[0];
                    }
                }
            }
            else
            {
                if (parameters != null)
                {
                    if ((length - index) < n)
                    {
                        ArrayObject.Copy(parameters, 0, target, index, length - index);
                    }
                    else
                    {
                        ArrayObject.Copy(parameters, 0, target, index, n);
                    }
                }
                if ((length - index) > n)
                {
                    for (int j = n + index; j < length; j++)
                    {
                        if (((j == (length - 1)) && this.formalParams[j].ParameterType.IsArray) && Microsoft.JScript.CustomAttribute.IsDefined(this.formalParams[j], typeof(ParamArrayAttribute), true))
                        {
                            target[j] = Array.CreateInstance(this.formalParams[j].ParameterType.GetElementType(), 0);
                        }
                        else
                        {
                            target[j] = Microsoft.JScript.Missing.Value;
                        }
                    }
                }
            }
            if (binder != null)
            {
                return(TypeReferences.ToExecutionContext(this.method).Invoke(base.obj, BindingFlags.SuppressChangeType, null, this.ConvertParams(index, target, binder, culture), null));
            }
            return(TypeReferences.ToExecutionContext(this.method).Invoke(base.obj, options, binder, target, culture));
        }
Example #26
0
        internal override Object Invoke(Object obj, Object thisob, BindingFlags options, Binder binder, Object[] parameters, CultureInfo culture)
        {
            int n  = this.formalParams.Length;
            int pn = (parameters != null ? parameters.Length : 0);

            if (!this.hasThis && !this.hasVarargs && n == pn)
            {
                if (binder != null)
                {
                    return(TypeReferences.ToExecutionContext(this.method).Invoke(this.obj, BindingFlags.SuppressChangeType, null, this.ConvertParams(0, parameters, binder, culture), null));
                }
                else
                {
                    return(TypeReferences.ToExecutionContext(this.method).Invoke(this.obj, options, binder, parameters, culture));
                }
            }

            int offset = (this.hasThis ? 1 : 0) + (this.hasEngine ? 1 : 0);

            Object[] arguments = new Object[n];
            if (this.hasThis)
            {
                arguments[0] = thisob;
                if (this.hasEngine)
                {
                    arguments[1] = this.engine;
                }
            }
            else if (this.hasEngine)
            {
                arguments[0] = this.engine;
            }
            if (this.hasVarargs)
            {
                if (n == offset + 1) //No params other than the vararg array
                {
                    arguments[offset] = parameters;
                }
                else
                {
                    //Some of the values in parameters must be passed separately from the vararg array
                    int argsToCopy = n - 1 - offset; //The number of separate arguments
                    if (pn > argsToCopy)
                    {
                        ArrayObject.Copy(parameters, 0, arguments, offset, argsToCopy);
                        int      vn      = pn - argsToCopy;
                        Object[] varargs = new Object[vn];
                        ArrayObject.Copy(parameters, argsToCopy, varargs, 0, vn);
                        arguments[n - 1] = varargs;
                    }
                    else
                    {
                        ArrayObject.Copy(parameters, 0, arguments, offset, pn);
                        for (int i = pn; i < argsToCopy; i++)
                        {
                            arguments[i + offset] = Missing.Value;
                        }
                        arguments[n - 1] = new Object[0];
                    }
                }
            }
            else
            {
                if (parameters != null)
                {
                    if (n - offset < pn)
                    {
                        ArrayObject.Copy(parameters, 0, arguments, offset, n - offset);
                    }
                    else
                    {
                        ArrayObject.Copy(parameters, 0, arguments, offset, pn);
                    }
                }
                if (n - offset > pn)
                {
                    for (int i = pn + offset; i < n; i++)
                    {
                        if (i == n - 1 && this.formalParams[i].ParameterType.IsArray && CustomAttribute.IsDefined(this.formalParams[i], typeof(ParamArrayAttribute), true))
                        {
                            arguments[i] = System.Array.CreateInstance(this.formalParams[i].ParameterType.GetElementType(), 0);
                        }
                        else
                        {
                            arguments[i] = Missing.Value;
                        }
                    }
                }
            }
            if (binder != null)
            {
                return(TypeReferences.ToExecutionContext(this.method).Invoke(this.obj, BindingFlags.SuppressChangeType, null, this.ConvertParams(offset, arguments, binder, culture), null));
            }
            else
            {
                return(TypeReferences.ToExecutionContext(this.method).Invoke(this.obj, options, binder, arguments, culture));
            }
        }
 internal static void Copy(Object[] source, Object[] target, int n)
 {
     ArrayObject.Copy(source, 0, target, 0, n);
 }