aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-10-03 17:58:48 +0200
committerRon Evans <[email protected]>2024-10-18 10:07:21 +0100
commit4ef5109a07afb895c28a5703b839f0c681062410 (patch)
treeeededfbea0fae4e7dcdf7260134c211e3057672e /src
parent6016d0c73936026ad9f21a40e7deb04436d99ab9 (diff)
downloadtinygo-4ef5109a07afb895c28a5703b839f0c681062410.tar.gz
tinygo-4ef5109a07afb895c28a5703b839f0c681062410.zip
wasm: add //go:wasmexport support to js/wasm
This adds support for //go:wasmexport with `-target=wasm` (in the browser). This follows the //go:wasmexport proposal, meaning that blocking functions are not allowed. Both `-buildmode=default` and `-buildmode=c-shared` are supported. The latter allows calling exported functions after `go.run()` has returned.
Diffstat (limited to 'src')
-rw-r--r--src/runtime/runtime_wasm_js.go21
-rw-r--r--src/runtime/runtime_wasmentry.go2
2 files changed, 8 insertions, 15 deletions
diff --git a/src/runtime/runtime_wasm_js.go b/src/runtime/runtime_wasm_js.go
index 0b1aa5bc4..89898b554 100644
--- a/src/runtime/runtime_wasm_js.go
+++ b/src/runtime/runtime_wasm_js.go
@@ -2,26 +2,15 @@
package runtime
-import "unsafe"
-
type timeUnit float64 // time in milliseconds, just like Date.now() in JavaScript
// wasmNested is used to detect scheduler nesting (WASM calls into JS calls back into WASM).
// When this happens, we need to use a reduced version of the scheduler.
+//
+// TODO: this variable can probably be removed once //go:wasmexport is the only
+// allowed way to export a wasm function (currently, //export also works).
var wasmNested bool
-//export _start
-func _start() {
- // These need to be initialized early so that the heap can be initialized.
- heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
- heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
-
- wasmNested = true
- run()
- __stdio_exit()
- wasmNested = false
-}
-
var handleEvent func()
//go:linkname setEventHandler syscall/js.setEventHandler
@@ -50,3 +39,7 @@ func sleepTicks(d timeUnit)
//go:wasmimport gojs runtime.ticks
func ticks() timeUnit
+
+func beforeExit() {
+ __stdio_exit()
+}
diff --git a/src/runtime/runtime_wasmentry.go b/src/runtime/runtime_wasmentry.go
index 7bb1e1b44..ff7b0c119 100644
--- a/src/runtime/runtime_wasmentry.go
+++ b/src/runtime/runtime_wasmentry.go
@@ -1,4 +1,4 @@
-//go:build tinygo.wasm && !js
+//go:build tinygo.wasm
package runtime