Since this is my first foray into WebAssembly, I am not entirely clear this is a bug. Went in today to complete
Hello World. After happily changing “Goodby, Mars!” to “Hello, World!”, I was quite perplexed to have the tests fail:
(module (memory (export "mem") 1) ;; Initializes the WebAssembly Linear Memory with a UTF-8 string of 14 characters starting at offset 64 (data (i32.const 64) "Hello, World!") ;; Returns the base offset and length of the greeting (func (export "hello") (result i32 i32) (i32.const 64) (i32.const 14) ) )
The code above resulted in the following test failure:
expect(currentInstance).toBeTruthy(); const [offset, length] = currentInstance.exports.hello(); expect(length).toBe(13); const greeting = currentInstance.get_mem_as_utf8(offset, length); expect(greeting).toBe("Hello, World!"); Error: expect(received).toBe(expected) // Object.is equality Expected: 13 Received: 14
export line fixes the issue:
;; Returns the base offset and length of the greeting (func (export "hello") (result i32 i32) (i32.const 64) (i32.const 13) )
But someone new to WebAssembly wouldn’t necessarily know to do that, so wondering if either the instructions or the stub need changing?