Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!