diff --git a/cmd/wasm/main.go b/cmd/wasm/main.go index cb6191e..c1a87a6 100644 --- a/cmd/wasm/main.go +++ b/cmd/wasm/main.go @@ -46,6 +46,10 @@ func yellerWrapper() js.Func { if err := png.Encode(enc, yelledAt); err != nil { return newError(fmt.Errorf("encoding image: %w", err)) } + if err := enc.Close(); err != nil { + return newError(fmt.Errorf("closing encoder: %w", err)) + } + return map[string]any{ "result": buf.String(), } diff --git a/docs/wasm_exec.js b/docs/wasm_exec.js index e6c8921..e818734 100644 --- a/docs/wasm_exec.js +++ b/docs/wasm_exec.js @@ -113,6 +113,10 @@ this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true); } + const setInt32 = (addr, v) => { + this.mem.setUint32(addr + 0, v, true); + } + const getInt64 = (addr) => { const low = this.mem.getUint32(addr + 0, true); const high = this.mem.getInt32(addr + 4, true); @@ -206,7 +210,10 @@ const timeOrigin = Date.now() - performance.now(); this.importObject = { - go: { + _gotest: { + add: (a, b) => a + b, + }, + gojs: { // Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters) // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function). @@ -269,7 +276,7 @@ this._resume(); } }, - getInt64(sp + 8) + 1, // setTimeout has been seen to fire up to 1 millisecond early + getInt64(sp + 8), )); this.mem.setInt32(sp + 16, id, true); }, @@ -551,4 +558,4 @@ }; } } -})(); +})(); \ No newline at end of file diff --git a/docs/yell-at.wasm b/docs/yell-at.wasm index 408a78f..24cba5b 100755 Binary files a/docs/yell-at.wasm and b/docs/yell-at.wasm differ