Add syscall/js.valueSetIndex support
Этот коммит содержится в:
родитель
efd9cf72ba
коммит
61750be9aa
5 изменённых файлов: 84 добавлений и 3 удалений
|
@ -8,6 +8,12 @@ callback: clean wasm_exec
|
|||
cp ./callback/wasm.js ./html/
|
||||
cp ./callback/index.html ./html/
|
||||
|
||||
slices: clean wasm_exec
|
||||
tinygo build -o ./html/wasm.wasm -target wasm -no-debug ./slices/wasm.go
|
||||
cp ./slices/wasm.js ./html/
|
||||
cp ./slices/index.html ./html/
|
||||
|
||||
|
||||
main: clean wasm_exec
|
||||
tinygo build -o ./html/wasm.wasm -target wasm -no-debug ./main/main.go
|
||||
cp ./main/index.html ./html/
|
||||
|
|
19
src/examples/wasm/slices/index.html
Обычный файл
19
src/examples/wasm/slices/index.html
Обычный файл
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Go WebAssembly</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<script src="wasm_exec.js" defer></script>
|
||||
<script src="wasm.js" defer></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>WebAssembly</h1>
|
||||
<p>type values separated by comma, using WebAssembly:</p>
|
||||
<input type="text" id="a" value=""/>==<div id="b"></div>
|
||||
</body>
|
||||
|
||||
</html>
|
23
src/examples/wasm/slices/wasm.go
Обычный файл
23
src/examples/wasm/slices/wasm.go
Обычный файл
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"syscall/js"
|
||||
)
|
||||
|
||||
func splitter(this js.Value, args []js.Value) interface{} {
|
||||
values := strings.Split(args[0].String(), ",")
|
||||
|
||||
result := make([]interface{}, 0)
|
||||
for _, each := range values {
|
||||
result = append(result, each)
|
||||
}
|
||||
|
||||
return js.ValueOf(result)
|
||||
}
|
||||
|
||||
func main() {
|
||||
wait := make(chan struct{}, 0)
|
||||
js.Global().Set("splitter", js.FuncOf(splitter))
|
||||
<-wait
|
||||
}
|
33
src/examples/wasm/slices/wasm.js
Обычный файл
33
src/examples/wasm/slices/wasm.js
Обычный файл
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
const WASM_URL = 'wasm.wasm';
|
||||
|
||||
var wasm;
|
||||
|
||||
function update() {
|
||||
const value = document.getElementById("a").value;
|
||||
document.getElementById("b").innerHTML = JSON.stringify(window.splitter(value));
|
||||
}
|
||||
|
||||
function init() {
|
||||
document.querySelector('#a').oninput = update;
|
||||
|
||||
const go = new Go();
|
||||
if ('instantiateStreaming' in WebAssembly) {
|
||||
WebAssembly.instantiateStreaming(fetch(WASM_URL), go.importObject).then(function (obj) {
|
||||
wasm = obj.instance;
|
||||
go.run(wasm);
|
||||
})
|
||||
} else {
|
||||
fetch(WASM_URL).then(resp =>
|
||||
resp.arrayBuffer()
|
||||
).then(bytes =>
|
||||
WebAssembly.instantiate(bytes, go.importObject).then(function (obj) {
|
||||
wasm = obj.instance;
|
||||
go.run(wasm);
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
init();
|
|
@ -245,9 +245,9 @@
|
|||
},
|
||||
|
||||
// valueSetIndex(v ref, i int, x ref)
|
||||
//"syscall/js.valueSetIndex": (sp) => {
|
||||
// Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
|
||||
//},
|
||||
"syscall/js.valueSetIndex": (v_addr, i, x_addr) => {
|
||||
Reflect.set(loadValue(v_addr), i, loadValue(x_addr));
|
||||
},
|
||||
|
||||
// func valueCall(v ref, m string, args []ref) (ref, bool)
|
||||
"syscall/js.valueCall": (ret_addr, v_addr, m_ptr, m_len, args_ptr, args_len, args_cap) => {
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче