-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
While there are some browser tests, Node.js is just a lot better for testing this kind of stuff because it's much faster and we don't need a browser for this.
- Loading branch information
1 parent
5e3c816
commit cd2bb83
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import "syscall/js" | ||
|
||
func main() { | ||
js.Global().Call("setCallback", js.FuncOf(func(this js.Value, args []js.Value) any { | ||
println("inside callback! parameters:") | ||
sum := 0 | ||
for _, value := range args { | ||
n := value.Int() | ||
println(" parameter:", n) | ||
sum += n | ||
} | ||
return sum | ||
})) | ||
js.Global().Call("callCallback") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require('../targets/wasm_exec.js'); | ||
|
||
var callback; | ||
|
||
global.setCallback = (cb) => { | ||
callback = cb; | ||
}; | ||
|
||
global.callCallback = () => { | ||
console.log('calling callback!'); | ||
let result = callback(1, 2, 3, 4); | ||
console.log('result from callback:', result); | ||
}; | ||
|
||
let go = new Go(); | ||
WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => { | ||
go.run(result.instance); | ||
}).catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
calling callback! | ||
inside callback! parameters: | ||
parameter: 1 | ||
parameter: 2 | ||
parameter: 3 | ||
parameter: 4 | ||
result from callback: 10 |