Exemple #1
0
        private DInt16Array createArrayFromObject(mdr.DObject array, int byteoffset = 0, int bytelength = 0)
        {
            var buffer = array as DArrayBuffer;

            if (buffer != null)
            {
                bytelength = (bytelength > 0) ? bytelength : buffer.ByteLength - byteoffset;
                checkOffsetCompatibility(byteoffset, bytelength);
                return(new DInt16Array(TargetPrototype, buffer, byteoffset, bytelength, TypeSize));
            }

            var darray = array as DTypedArray;

            if (darray != null)
            {
                bytelength = (bytelength > 0) ? bytelength : darray.ByteLength / darray.TypeSize * TypeSize;
                checkOffsetCompatibility(byteoffset, bytelength);
                DInt16Array tarray = new DInt16Array(TargetPrototype, bytelength, TypeSize);
                fillArray(tarray, darray);
                return(tarray);
            }

            Trace.Fail("invalid Arguments");
            return(null);
        }
Exemple #2
0
 private void fillArray(DInt16Array dst, mdr.DArrayBase src)
 {
     for (int i = 0; i < dst.ByteLength / dst.TypeSize; ++i)
     {
         Int16 value = src.GetPropertyDescriptor(i).Get(src).AsInt16();
         dst.AddPropertyDescriptor(i).Set(dst, value);
     }
 }
Exemple #3
0
        public JSInt16Array()
            : base(new mdr.DObject(), "Int16Array", TypeSize)
        {
            JittedCode = (ref mdr.CallFrame callFrame) =>
            {
                DInt16Array int16array = new DInt16Array(TargetPrototype, 0, TypeSize);
                var         argsCount  = callFrame.PassedArgsCount;

                if (argsCount == 1)
                {
                    switch (callFrame.Arg0.ValueType)
                    {
                    case mdr.ValueTypes.Int32:
                        int16array = new DInt16Array(TargetPrototype, callFrame.Arg0.AsInt32() * TypeSize, TypeSize);
                        break;

                    case mdr.ValueTypes.Object:
                        int16array = createArrayFromObject(callFrame.Arg0.AsDObject());
                        break;

                    case mdr.ValueTypes.Array:
                        mdr.DArray array = callFrame.Arg0.AsDArray();
                        int16array = new DInt16Array(TargetPrototype, array.Length * TypeSize, TypeSize);
                        fillArray(int16array, array);
                        break;

                    default:
                        Trace.Fail("invalid Arguments");
                        break;
                    }
                }
                if (argsCount == 2)
                {
                    int byteoffset = callFrame.Arg1.AsInt32();
                    int16array = createArrayFromObject(callFrame.Arg0.AsDObject(), byteoffset);
                }
                if (argsCount == 3)
                {
                    var byteoffset = callFrame.Arg1.AsInt32();
                    var length     = callFrame.Arg2.AsInt32();
                    checkOffsetMemBoundary(byteoffset);
                    int16array = createArrayFromObject(callFrame.Arg0.AsDObject(), byteoffset, length * TypeSize);
                }

                if (IsConstrutor)
                {
                    callFrame.This = (int16array);
                }
                else
                {
                    callFrame.Return.Set(int16array);
                }
            };

            TargetPrototype.DefineOwnProperty("subarray", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
            {
                DInt16Array array = (callFrame.This as DInt16Array);
                var argsCount     = callFrame.PassedArgsCount;
                var begin         = (argsCount >= 1) ? callFrame.Arg0.AsInt32() : 0;
                var end           = array.ByteLength / array.TypeSize;
                end            = (argsCount >= 2) ? callFrame.Arg1.AsInt32() : end;
                begin          = begin < 0 ? begin += array.ByteLength / array.TypeSize : begin;
                end            = end < 0 ? end += array.ByteLength / array.TypeSize : end;
                var bytelength = Math.Max(0, (end - begin)) * array.TypeSize;
                end            = Math.Max(array.ByteLength, bytelength);
                var int16array = new DInt16Array(TargetPrototype, bytelength, array.TypeSize);
                int offset     = (begin <= 0) ? 0 : begin * array.TypeSize;
                for (int i = 0; i < int16array.ByteLength; ++i)
                {
                    int16array.Elements_[i] = array.Elements_[i + offset];
                }
                callFrame.Return.Set(int16array);
            }), mdr.PropertyDescriptor.Attributes.NotEnumerable | mdr.PropertyDescriptor.Attributes.Data);
        }
Exemple #4
0
        private DInt16Array createArrayFromObject(mdr.DObject array, int byteoffset = 0, int bytelength = 0)
        {
            var buffer = array as DArrayBuffer;
            if (buffer != null)
            {
                bytelength = (bytelength > 0) ? bytelength : buffer.ByteLength - byteoffset;
                checkOffsetCompatibility(byteoffset, bytelength);
                return new DInt16Array(TargetPrototype, buffer, byteoffset, bytelength, TypeSize);
            }

            var darray = array as DTypedArray;
            if (darray != null)
            {
                bytelength = (bytelength > 0) ? bytelength : darray.ByteLength / darray.TypeSize * TypeSize;
                checkOffsetCompatibility(byteoffset, bytelength);
                DInt16Array tarray = new DInt16Array(TargetPrototype, bytelength, TypeSize);
                fillArray(tarray, darray);
                return tarray;
            }

            Trace.Fail("invalid Arguments");
            return null;
        }
Exemple #5
0
        public JSInt16Array()
            : base(new mdr.DObject(), "Int16Array", TypeSize)
        {
            JittedCode = (ref mdr.CallFrame callFrame) =>
            {
                DInt16Array int16array = new DInt16Array(TargetPrototype, 0, TypeSize);
                var argsCount = callFrame.PassedArgsCount;

                if (argsCount == 1)
                {
                    switch (callFrame.Arg0.ValueType)
                    {
                        case mdr.ValueTypes.Int32:
                            int16array = new DInt16Array(TargetPrototype, callFrame.Arg0.AsInt32() * TypeSize, TypeSize);
                            break;

                        case mdr.ValueTypes.Object:
                            int16array = createArrayFromObject(callFrame.Arg0.AsDObject());
                            break;

                        case mdr.ValueTypes.Array:
                            mdr.DArray array = callFrame.Arg0.AsDArray();
                            int16array = new DInt16Array(TargetPrototype, array.Length * TypeSize, TypeSize);
                            fillArray(int16array, array);
                            break;

                        default:
                            Trace.Fail("invalid Arguments");
                            break;
                    }
                }
                if (argsCount == 2)
                {
                    int byteoffset = callFrame.Arg1.AsInt32();
                    int16array = createArrayFromObject(callFrame.Arg0.AsDObject(), byteoffset);
                }
                if (argsCount == 3)
                {
                    var byteoffset = callFrame.Arg1.AsInt32();
                    var length = callFrame.Arg2.AsInt32();
                    checkOffsetMemBoundary(byteoffset);
                    int16array = createArrayFromObject(callFrame.Arg0.AsDObject(), byteoffset, length * TypeSize);
                }

                if (IsConstrutor)
                    callFrame.This = (int16array);
                else
                    callFrame.Return.Set(int16array);
            };

            TargetPrototype.DefineOwnProperty("subarray", new mdr.DFunction((ref mdr.CallFrame callFrame) =>
            {
                DInt16Array array = (callFrame.This as DInt16Array);
                var argsCount = callFrame.PassedArgsCount;
                var begin = (argsCount >= 1) ? callFrame.Arg0.AsInt32() : 0;
                var end = array.ByteLength / array.TypeSize;
                end = (argsCount >= 2) ? callFrame.Arg1.AsInt32() : end;
                begin = begin < 0 ? begin += array.ByteLength / array.TypeSize : begin;
                end = end < 0 ? end += array.ByteLength / array.TypeSize : end;
                var bytelength = Math.Max(0, (end - begin)) * array.TypeSize;
                end = Math.Max(array.ByteLength, bytelength);
                var int16array = new DInt16Array(TargetPrototype, bytelength, array.TypeSize);
                int offset = (begin <= 0) ? 0 : begin * array.TypeSize;
                for (int i = 0; i < int16array.ByteLength; ++i)
                    int16array.Elements_[i] = array.Elements_[i + offset];
                callFrame.Return.Set(int16array);
            }), mdr.PropertyDescriptor.Attributes.NotEnumerable | mdr.PropertyDescriptor.Attributes.Data);
        }
Exemple #6
0
 private void fillArray(DInt16Array dst, mdr.DArrayBase src)
 {
     for (int i = 0; i < dst.ByteLength / dst.TypeSize; ++i)
     {
         Int16 value = src.GetPropertyDescriptor(i).Get(src).AsInt16();
         dst.AddPropertyDescriptor(i).Set(dst, value);
     }
 }