WebAssembly / WebAssembly/binaryen

How use wasm code without import external file

Open
#1,048 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 19h
Merged PRs (30d)
69

Description

1- How use this wasm code without import external file ('test.wasm')?

var test = `0061 736d 0100 0000 0186 8080 8000 0160
017f 017f 0382 8080 8000 0100 0484 8080
8000 0170 0000 0583 8080 8000 0100 0106
8180 8080 0000 079e 8080 8000 0206 6d65
6d6f 7279 0200 115f 5a31 3274 6573 7446
756e 6374 696f 6e69 0000 0a8d 8080 8000
0187 8080 8000 0020 0041 0a6a 0b`;

2- How to pass parameters to an imported function out of fetch?

var importObject = {
  imports: {
    _Z12testFunctioni: function(arg) {
      console.log(arg);
    }
  }
};

fetch('test.wasm').then(function(response) {
  response.arrayBuffer().then(function(bytes) {
    WebAssembly.instantiate(bytes, importObject).then(function(obj) {
    	 obj.instance.exports._Z12testFunctioni(num)       
    })
  })
});

console.log( _Z12testFunctioni(10) )

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the inline hexadecimal wasm string and the JavaScript fetch/WebAssembly.instantiate example in the issue. Determine the intended usage guidance for embedding the wasm bytes and supplying parameters to the imported function; done means both questions have clear, verified documentation or examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, wasm
Domain
compilers, web-dev
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.