示例#1
0
        public ITypedArray CastNativeArray(object managedArray)
        {
            var         arrayType = managedArray.GetType();
            ITypedArray array;

            // Here are listed some JavaScript array types:
            // https://github.com/mono/mono/blob/a7f5952c69ae76015ccaefd4dfa8be2274498a21/sdks/wasm/bindings-test.cs
            if (arrayType == typeof(byte[]))
            {
                array = Uint8Array.From((byte[])managedArray);
            }
            else if (arrayType == typeof(float[]))
            {
                array = Float32Array.From((float[])managedArray);
            }
            else if (arrayType == typeof(ushort[]))
            {
                array = Uint16Array.From((ushort[])managedArray);
            }
            else if (arrayType == typeof(uint[]))
            {
                array = Uint32Array.From((uint[])managedArray);
            }
            else
            {
                throw new NotImplementedException();
            }

            return(array);
        }
示例#2
0
        public static void Uint32ArrayFrom(Function objectPrototype)
        {
            var         array = new uint[50];
            Uint32Array from  = Uint32Array.From(array);

            Assert.Equal(50, from.Length);
            Assert.Equal("[object Uint32Array]", objectPrototype.Call(from));
        }
示例#3
0
        public static IEnumerable <object[]> ArrayType_TestData()
        {
            _objectPrototype ??= new Function("return Object.prototype.toString;");
            yield return(new object[] { _objectPrototype.Call(), "Uint8Array", Uint8Array.From(new byte[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Uint8ClampedArray", Uint8ClampedArray.From(new byte[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Int8Array", Int8Array.From(new sbyte[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Uint16Array", Uint16Array.From(new ushort[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Int16Array", Int16Array.From(new short[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Uint32Array", Uint32Array.From(new uint[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Int32Array", Int32Array.From(new int[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Float32Array", Float32Array.From(new float[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Float64Array", Float64Array.From(new double[10]) });

            yield return(new object[] { _objectPrototype.Call(), "Array", new Array(10) });
        }
示例#4
0
 public static void SetTypedArrayUInt(JSObject obj)
 {
     uint[] buffer = Enumerable.Repeat((uint)0x20, 16).ToArray();
     obj.SetObjectProperty("typedArray", Uint32Array.From(buffer));
 }
示例#5
0
        public static Uint32Array Uint32ArrayFrom()
        {
            var array = new uint[50];

            return(Uint32Array.From(array));
        }