[js-api] Can we get a constant for page size?
Currently in order to prepare some memory in the JS API we need to specify the size of the memory in page sizes. However if we already have some memory in say a ArrayBuffer, in order to actually be able to store that in WASM memory we need to convert it's size using the page size:
const PAGE_SIZE = 2**16;
function allocateMemory(buffer) {
const memory = new WebAssembly.Memory({
initial: Math.ceil(buffer.byteLength / PAGE_SIZE),
});
const memBytes = new Uint8Array(memory.buffer);
memBytes.set(new Uint8Array(buffer), 0);
return memory;
}
For users who are manually intiailizing memories, the exact value of the page size is fairly immaterial (and I for one have to look it up everytime). It would be nice if this were just exposed as a constant so we can just use it without remembering:
const { PAGE_SIZE } = WebAssembly.Memory;
The change for this would be pretty trivial, just add the following line to Memory in the IDL:
interface Memory {
const unsigned long PAGE_SIZE = 65536;
// ...
}
I'm not sure if Wasm64 is intended to have a different page size, if so it would probably be better to call it PAGE_SIZE_32.
The page size will remain 64KiB with https://github.com/webassembly/memory64.