(str, slice, start, length)
| 790 | } |
| 791 | |
| 792 | function checkEncoding(str, slice, start, length) { |
| 793 | let bytes = encodeWtf16LE(slice); |
| 794 | function clearMemory(low, high) { |
| 795 | for (let i = low; i < high; i++) { |
| 796 | memory[i] = 0; |
| 797 | } |
| 798 | } |
| 799 | function assertMemoryBytesZero(low, high) { |
| 800 | for (let i = low; i < high; i++) { |
| 801 | assertEquals(0, memory[i]); |
| 802 | } |
| 803 | } |
| 804 | function checkMemory(offset, bytes) { |
| 805 | let slop = 64; |
| 806 | assertMemoryBytesZero(Math.max(0, offset - slop), offset); |
| 807 | for (let i = 0; i < bytes.length; i++) { |
| 808 | assertEquals(bytes[i], memory[offset + i]); |
| 809 | } |
| 810 | assertMemoryBytesZero(offset + bytes.length, |
| 811 | Math.min(memory.length, |
| 812 | offset + bytes.length + slop)); |
| 813 | } |
| 814 | |
| 815 | for (let offset of [0, 42, memory.length - bytes.length]) { |
| 816 | assertEquals(slice.length, |
| 817 | instance.exports.encode(str, offset, start, length)); |
| 818 | checkMemory(offset, bytes); |
| 819 | clearMemory(offset, offset + bytes.length); |
| 820 | } |
| 821 | |
| 822 | assertThrows(() => instance.exports.encode(str, 1, start, length), |
| 823 | WebAssembly.RuntimeError, |
| 824 | "operation does not support unaligned accesses"); |
| 825 | assertThrows( |
| 826 | () => instance.exports.encode(str, memory.length - bytes.length + 2, |
| 827 | start, length), |
| 828 | WebAssembly.RuntimeError, "memory access out of bounds"); |
| 829 | checkMemory(memory.length - bytes.length - 2, []); |
| 830 | } |
| 831 | checkEncoding("fox", "f", 0, 1); |
| 832 | checkEncoding("fox", "fo", 0, 2); |
| 833 | checkEncoding("fox", "fox", 0, 3); |
no test coverage detected