Skip to content

WASM: Simple syscall/js demo panics #296

Description

@johanbrandhorst

Initial syscall/js support was implemented in #53. I know everything doesn't work yet, but I did expect this simple demo to work without problems:

// +build js,wasm

package main

import "syscall/js"

var document js.Value

func init() {
	document = js.Global().Get("document")
}

func main() {
	div := document.Call("getElementById", "target")

	node := document.Call("createElement", "div")
	node.Set("innerText", "Hello World")

	div.Call("appendChild", node)
}

This, when compiled and executed in the browser prints the following to the console:

Firefox 67.0b11:

panic: (21:0x00010618) wasm_exec.js:199:18
RuntimeError: unreachable executed test.wasm:457:1

Chromium 73.0.3683.103

panic: (21:0x00010618)
wasm-a2b042a6-7:9 Uncaught (in promise) RuntimeError: unreachable
    at runtime._panic (wasm-function[7]:31)
    at (syscall/js.Value).Call (wasm-function[16]:301)
    at cwa_main (wasm-function[15]:297)
    at global.Go.run (http://localhost:8080/wasm_exec.js:347:24)
    at run (http://localhost:8080/:41:13)
    at HTMLButtonElement.onclick (http://localhost:8080/:46:51)
runtime._panic @ wasm-a2b042a6-7:9
(syscall/js.Value).Call @ wasm-a2b042a6-16:127
cwa_main @ wasm-a2b042a6-15:101
run @ wasm_exec.js:347
run @ (index):41
onclick @ (index):46
async function (async)
run @ (index):41
onclick @ (index):46

The example works as expected when compiled with gc. This was tested with tinygo 0.5.0.

This can be reproduced by cloning my wasm-experiments repo and running make tinygo target=js.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions