mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-18 21:40:29 +00:00
wasm: use shared, imported memory
This switches our wasm build to use "shared" memory. Shared memory can be shared across multiple web workers, which is something we'll want to support for our multi-threaded behaviors later. Shared memory has a number of different restrictions so this updates zig-js to support it as well as updates some of our functions that need to be aware of it.
This commit is contained in:
@@ -4,9 +4,11 @@ const zjs = new ZigJS();
|
||||
const importObject = {
|
||||
module: {},
|
||||
env: {
|
||||
memory: new WebAssembly.Memory({ initial: 25, maximum: 65536, shared: true }),
|
||||
log: (ptr: number, len: number) => {
|
||||
const view = new DataView(zjs.memory.buffer, ptr, Number(len));
|
||||
const str = new TextDecoder('utf-8').decode(view);
|
||||
const arr = new Uint8ClampedArray(zjs.memory.buffer, ptr, len);
|
||||
const data = arr.slice();
|
||||
const str = new TextDecoder('utf-8').decode(data);
|
||||
console.log(str);
|
||||
},
|
||||
},
|
||||
@@ -20,8 +22,8 @@ fetch(url.href).then(response =>
|
||||
).then(bytes =>
|
||||
WebAssembly.instantiate(bytes, importObject)
|
||||
).then(results => {
|
||||
const memory = importObject.env.memory;
|
||||
const {
|
||||
memory,
|
||||
malloc,
|
||||
free,
|
||||
face_new,
|
||||
|
||||
Reference in New Issue
Block a user