Ejemplo n.º 1
0
        public void GrowMemory()
        {
            var limits = new ResizableLimits(1, 2);
            var memory = new LinearMemory(limits);

            Assert.AreEqual(1, memory.Size);
            Assert.AreEqual(1, memory.Grow(1));
            Assert.AreEqual(2, memory.Size);
            Assert.AreEqual(-1, memory.Grow(1));
            Assert.AreEqual(2, memory.Size);
        }
Ejemplo n.º 2
0
        public void RoundTripInt64()
        {
            var limits = new ResizableLimits(1, 2);
            var memory = new LinearMemory(limits);

            uint offset   = MemoryType.PageSize / 2;
            long data     = 0x1F2E3D4C5B6A7988;
            var  int64Mem = memory.Int64;

            int64Mem[offset] = data;
            Assert.AreEqual((long)data, (long)int64Mem[offset]);
        }
Ejemplo n.º 3
0
        public void RoundTripInt32()
        {
            var limits = new ResizableLimits(1, 2);
            var memory = new LinearMemory(limits);

            uint offset   = MemoryType.PageSize / 2;
            int  data     = 0x1F2E3D4C;
            var  int32Mem = memory.Int32;

            int32Mem[offset] = data;
            Assert.AreEqual((int)data, (int)int32Mem[offset]);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a function table from the given resizable limits.
        /// The table's initial contents are trap values.
        /// </summary>
        /// <param name="limits">The table's limits.</param>
        public FunctionTable(ResizableLimits limits)
        {
            this.Limits   = limits;
            this.contents = new List <FunctionDefinition>((int)limits.Initial);
            var funcDef = new ThrowFunctionDefinition(
                new WasmValueType[0],
                new WasmValueType[0],
                new TrapException("Indirect call target not initialized yet.", TrapException.SpecMessages.UninitializedElement));

            for (int i = 0; i < limits.Initial; i++)
            {
                contents.Add(funcDef);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a function table from the given resizable limits.
        /// The table's initial contents are trap values.
        /// </summary>
        /// <param name="Limits">The table's limits.</param>
        public FunctionTable(ResizableLimits Limits)
        {
            this.Limits   = Limits;
            this.contents = new List <FunctionDefinition>((int)Limits.Initial);
            var funcDef = new ThrowFunctionDefinition(
                new WasmValueType[0],
                new WasmValueType[0],
                new WasmException("Indirect call target not initialized yet."));

            for (int i = 0; i < Limits.Initial; i++)
            {
                contents.Add(funcDef);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a linear memory from the given specification.
 /// </summary>
 /// <param name="limits">The specification for this linear memory: a range in units of pages.</param>
 public LinearMemory(ResizableLimits limits)
 {
     this.Limits = limits;
     this.memory = new List <byte>();
     GrowToSize(limits.Initial);
 }