wasm: add js.copyBytesToJS()
Этот коммит содержится в:
родитель
978a0cd9b0
коммит
aeb7539f67
1 изменённых файлов: 19 добавлений и 0 удалений
|
@ -319,6 +319,25 @@
|
||||||
//"syscall/js.valueInstanceOf": (sp) => {
|
//"syscall/js.valueInstanceOf": (sp) => {
|
||||||
// mem().setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16));
|
// mem().setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16));
|
||||||
//},
|
//},
|
||||||
|
|
||||||
|
// copyBytesToJS(dst ref, src []byte) (int, bool)
|
||||||
|
// Originally copied from upstream Go project, then modified:
|
||||||
|
// https://github.com/golang/go/blob/3f995c3f3b43033013013e6c7ccc93a9b1411ca9/misc/wasm/wasm_exec.js#L404-L416
|
||||||
|
"syscall/js.copyBytesToJS": (ret_addr, dest_addr, source_addr, source_len, source_cap) => {
|
||||||
|
let num_bytes_copied_addr = ret_addr;
|
||||||
|
let returned_status_addr = ret_addr + 4; // Address of returned boolean status variable
|
||||||
|
|
||||||
|
const dst = loadValue(dest_addr);
|
||||||
|
const src = loadSlice(source_addr, source_len);
|
||||||
|
if (!(dst instanceof Uint8Array)) {
|
||||||
|
mem().setUint8(returned_status_addr, 0); // Return "not ok" status
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const toCopy = src.subarray(0, dst.length);
|
||||||
|
dst.set(toCopy);
|
||||||
|
setInt64(num_bytes_copied_addr, toCopy.length);
|
||||||
|
mem().setUint8(returned_status_addr, 1); // Return "ok" status
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче