Beispiel #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
            {
                throw new NotImplementedException();
            }

            return(array);
        }
Beispiel #2
0
        public static void Uint16ArrayFrom(Function objectPrototype)
        {
            var         array = new ushort[50];
            Uint16Array from  = Uint16Array.From(array);

            Assert.Equal(50, from.Length);
            Assert.Equal("[object Uint16Array]", objectPrototype.Call(from));
        }
Beispiel #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) });
        }
 private static void SetTypedArrayUShort(JSObject obj)
 {
     ushort[] buffer = Enumerable.Repeat((ushort)0x20, 14).ToArray();
     obj.SetObjectProperty("typedArray", Uint16Array.From(buffer));
 }
Beispiel #5
0
        public static Uint16Array Uint16ArrayFrom()
        {
            var array = new ushort[50];

            return(Uint16Array.From(array));
        }