website example
This commit is contained in:
parent
c6c62e5852
commit
c4f764e4ce
6 changed files with 198 additions and 182 deletions
|
|
@ -42,10 +42,29 @@ function writeStringToWasm(str) {
|
|||
return ptr;
|
||||
}
|
||||
|
||||
function getElementById(id, idLenght) {
|
||||
const obj = document.getElementById(decoder.decode(new Int8Array(window.crafter_webbuild_wasi.instance.exports.memory.buffer, id, idLenght)));
|
||||
jsmemory.set(++memorycounter, obj);
|
||||
return memorycounter;
|
||||
function getElementById(id, idLength) {
|
||||
try {
|
||||
// Decode the id from WASM memory
|
||||
const elementId = decoder.decode(
|
||||
new Int8Array(window.crafter_webbuild_wasi.instance.exports.memory.buffer, id, idLength)
|
||||
);
|
||||
|
||||
// Attempt to get the element
|
||||
const obj = document.getElementById(elementId);
|
||||
|
||||
// Check if element exists
|
||||
if (!obj) {
|
||||
throw new Error(`Element with id "${elementId}" does not exist.`);
|
||||
}
|
||||
|
||||
// Store in jsmemory
|
||||
jsmemory.set(++memorycounter, obj);
|
||||
|
||||
return memorycounter;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function setInnerHTML(ptr, html, htmlLenght) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue