mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 02:00:51 +00:00
Fix compilation and docs
The compilation part is effectively a cherry pick from master
This commit is contained in:
parent
f45ce1f239
commit
770d7365c4
18
DESIGN.md
18
DESIGN.md
@ -538,22 +538,14 @@ code for this we'll see:
|
||||
```js
|
||||
import * as wasm from './js_hello_world_bg';
|
||||
|
||||
export class Foo {
|
||||
static __construct(ptr) {
|
||||
return new Foo(ptr);
|
||||
}
|
||||
|
||||
class ConstructorToken {
|
||||
constructor(ptr) {
|
||||
this.ptr = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
export class Foo {
|
||||
|
||||
constructor(...args) {
|
||||
if (args.length === 1 && args[0] instanceof ConstructorToken) {
|
||||
this.ptr = args[0].ptr;
|
||||
return;
|
||||
}
|
||||
throw new Error('you cannot invoke `new` directly without having a method annotated a constructor');
|
||||
}
|
||||
|
||||
free() {
|
||||
const ptr = this.ptr;
|
||||
@ -563,7 +555,7 @@ export class Foo {
|
||||
|
||||
static new(arg0) {
|
||||
const ret = wasm.foo_new(arg0);
|
||||
return new Foo(new ConstructorToken(ret));
|
||||
return Foo.__construct(ret)
|
||||
}
|
||||
|
||||
get() {
|
||||
|
@ -110,7 +110,7 @@ impl Bindgen {
|
||||
// execute a shim function which informs us about its type so we can
|
||||
// then generate the appropriate bindings.
|
||||
let instance = wasmi::Module::from_parity_wasm_module(module.clone())?;
|
||||
let instance = wasmi::ModuleInstance::new(&imodule, &MyResolver)?;
|
||||
let instance = wasmi::ModuleInstance::new(&instance, &MyResolver)?;
|
||||
let instance = instance.not_started_instance();
|
||||
|
||||
let (js, ts) = {
|
||||
@ -128,7 +128,7 @@ impl Bindgen {
|
||||
function_table_needed: false,
|
||||
run_descriptor: &|name| {
|
||||
let mut v = MyExternals(Vec::new());
|
||||
let ret = imodulei
|
||||
let ret = instance
|
||||
.invoke_export(name, &[], &mut v)
|
||||
.expect("failed to run export");
|
||||
assert!(ret.is_none());
|
||||
|
Loading…
x
Reference in New Issue
Block a user