Exemplo n.º 1
0
        public static EcmaValue CopyWithin([This] EcmaValue thisValue, EcmaValue target, EcmaValue start, EcmaValue end)
        {
            TypedArray array = thisValue.GetUnderlyingObject <TypedArray>();

            Guard.BufferNotDetached(array);
            int len   = array.Length;
            int to    = ArrayHelper.GetBoundIndex(target, len, 0);
            int from  = ArrayHelper.GetBoundIndex(start, len, 0);
            int until = ArrayHelper.GetBoundIndex(end, len, len);
            int count = Math.Min(until - from, len - to);

            if (count > 0)
            {
                int elementSize = array.ElementSize;
                int srcOffset   = (int)(from * elementSize + array.ByteOffset);
                int dstOffset   = (int)(to * elementSize + array.ByteOffset);
                Guard.BufferNotDetached(array);
                ArrayBuffer.CopyBytes(array.Buffer, srcOffset, array.Buffer, dstOffset, (int)count * elementSize);
            }
            return(thisValue);
        }