browserify / browserify/rustify

Should we register modules directly?

Open
#4 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
491
Forks
6
PR merge metrics
No merged PRs in 30d

Description

I was thinking: perhaps it would make sense to register modules directly?

E.g. turn this:
```js
var rust = require('rustify')

var wasm = rust`
#[no_mangle]
pub fn add_one(x: i32) -> i32 {
x + 1
}
`

WebAssembly.instantiate(wasm, {})
.then(function (res) {
var addOne = res.instance.exports.add_one
console.log(addOne(41))
console.log(addOne(68))
}).catch(function (e) {
console.error('Creating WASM module failed', e)
})
```
Into this:
```js
var rust = require('rustify')

var wasm = rust`
#[no_mangle]
pub fn add_one(x: i32) -> i32 {
x + 1
}
`

wasm.then((mod) => {
console.log(mod.add_one(41))
console.log(mod.add_one(68))
}).catch((e) => console.error('WASM error', e))
```

The benefit is that there's way less code to remember (ugh, `res.instance.exports`). The downside is that we're no long just exposing a Uint8Array, so doing things like registering a function twice is not going to be possible.

Would this be worth it?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.