Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

285
Visualizações
How to pass an array of object from javascript to webAssembly

I know it is possible to pass arrays of integer to web assembly using something like this :

const bin = ...; // WebAssembly binary, I assume below that it imports a memory from module "imports", field "memory".
const module = new WebAssembly.Module(bin);
const memory = new WebAssembly.Memory({ initial: 2 }); // Size is in pages.
const instance = new WebAssembly.Instance(module, { imports: { memory: memory } });
const arrayBuffer = memory.buffer;
const buffer = new Uint8Array(arrayBuffer);

I have read a lot of documentation and some questions that looks like what I was looking for :

  • How to pass an array of objects to WebAssembly and convert it to a vector of structs with wasm-bindgen?
  • Pass a JavaScript array as argument to a WebAssembly function
  • https://becominghuman.ai/passing-and-returning-webassembly-array-parameters-a0f572c65d97
  • https://rob-blackbourn.github.io/blog/webassembly/wasm/array/arrays/javascript/c/2020/06/07/wasm-arrays.html

And yet none of those answered my question.

here is a small example of AssemblyScript that describe the kind of function I would like to use :

class Dummy {
  constructor()
}

export function getDummy(): Dummy {
   return new Dummy();
}

export function workWithDummy(dummies: Dummy[] = []) {
  // do something
}

and in the javaScript code :

const fs = require('fs');
const {resolve} = require('../utils/utils.js');
const env = {
    abort: (message, filename, line, column) => {
        throw new Error(`${message} in ${filename} at ${line}:${column}`);
    }
};

module.exports = fs.promises.readFile(resolve('parser.wasm')).then(buffer => {
    return WebAssembly.instantiate(buffer, {env: env}).then(wasmModule => {
       const module = wasmModule.instance.exports;
       module.workWithDummy([module.getDummy()]); //won't work
    });
});

I am running this code in nodeJs 18.1.0

To sum up my question is : how to make this line work ? module.workWithDummy([module.getDummy()]); //won't work

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda