aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata/wasmexport.go
diff options
context:
space:
mode:
Diffstat (limited to 'testdata/wasmexport.go')
-rw-r--r--testdata/wasmexport.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/testdata/wasmexport.go b/testdata/wasmexport.go
new file mode 100644
index 000000000..9065d6e92
--- /dev/null
+++ b/testdata/wasmexport.go
@@ -0,0 +1,52 @@
+package main
+
+import "time"
+
+func init() {
+ println("called init")
+ go adder()
+}
+
+//go:wasmimport tester callTestMain
+func callTestMain()
+
+func main() {
+ // main.main is not used when using -buildmode=c-shared.
+ callTestMain()
+}
+
+//go:wasmexport hello
+func hello() {
+ println("hello!")
+}
+
+//go:wasmexport add
+func add(a, b int) int {
+ println("called add:", a, b)
+ addInputs <- a
+ addInputs <- b
+ return <-addOutput
+}
+
+var addInputs = make(chan int)
+var addOutput = make(chan int)
+
+func adder() {
+ for {
+ a := <-addInputs
+ b := <-addInputs
+ time.Sleep(time.Millisecond)
+ addOutput <- a + b
+ }
+}
+
+//go:wasmimport tester callOutside
+func callOutside(a, b int) int
+
+//go:wasmexport reentrantCall
+func reentrantCall(a, b int) int {
+ println("reentrantCall:", a, b)
+ result := callOutside(a, b)
+ println("reentrantCall result:", result)
+ return result
+}