wasm: add support for js.FuncOf

This commit is contained in:
Ayke van Laethem
2019-05-24 15:30:09 +02:00
committed by Ayke
parent 3313decb68
commit eb1d834dd4
9 changed files with 129 additions and 27 deletions
+4
View File
@@ -49,3 +49,7 @@ func lookupPanic() {
func slicePanic() {
runtimePanic("slice out of range")
}
func blockingPanic() {
runtimePanic("trying to do blocking operation in exported function")
}
+8 -1
View File
@@ -37,9 +37,16 @@ func putchar(c byte) {
resource_write(stdout, &c, 1)
}
var handleEvent func()
//go:linkname setEventHandler syscall/js.setEventHandler
func setEventHandler(fn func()) {
// TODO
handleEvent = fn
}
//go:export resume
func resume() {
handleEvent()
}
//go:export go_scheduler
+3
View File
@@ -120,6 +120,9 @@ func setTaskPromisePtr(task *coroutine, value unsafe.Pointer) {
// getTaskPromisePtr is a helper function to get the current .ptr field from a
// coroutine promise.
func getTaskPromisePtr(task *coroutine) unsafe.Pointer {
if task == nil {
blockingPanic()
}
return task.promise().ptr
}