Skip to content

Commit

Permalink
Improved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Jul 22, 2021
1 parent 14c75e7 commit 3117db4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
3 changes: 3 additions & 0 deletions lib/js-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ API than the `wasmer` crate, but when compiled to WebAssembly, it only targets
a JavaScript host. It means that it is possible to write a Rust program that uses Wasmer,
and compiles everything to WebAssembly to run in a browser, Node.js, Deno and so on.

This crate doesn't ship with any compilers or engines, as it leverages the Javascript VM to
compile and run WebAssembly.

## Usage

We recommend aliasing `wasmer_js` to `wasmer` at the top of your crate.
Expand Down
2 changes: 1 addition & 1 deletion lib/js-api/src/externals/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl Memory {
/// # }
/// ```
pub fn view<T: ValueType>(&self) -> MemoryView<T> {
unimplemented!();
unimplemented!("The view function is not yet implemented in Wasmer Javascript");
}

/// example view
Expand Down
2 changes: 1 addition & 1 deletion lib/js-api/src/externals/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Table {
_src_index: u32,
_len: u32,
) -> Result<(), RuntimeError> {
unimplemented!();
unimplemented!("Table.copy is not natively supported in Javascript");
}

pub(crate) fn from_vm_export(store: &Store, vm_table: VMTable) -> Self {
Expand Down
27 changes: 13 additions & 14 deletions lib/js-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
)
)]

//! This crate contains the `wasmer` API. The `wasmer` API facilitates the efficient,
//! sandboxed execution of [WebAssembly (Wasm)][wasm] modules.
//! This crate contains the `wasmer-js` API. The `wasmer-js` API facilitates the efficient,
//! sandboxed execution of [WebAssembly (Wasm)][wasm] modules, leveraging on the same
//! API as the `wasmer` crate, but targeting Javascript.
//!
//! This crate uses the same WebAssembly engine as the Javascript VM where it's used.
//!
//! Here's an example of the `wasmer` API in action:
//! Here's an example of the `wasmer-js` API in action:
//! ```
//! use wasmer_js::{Store, Module, Instance, Value, imports};
//!
//! fn main() -> anyhow::Result<()> {
//! #[wasm_bindgen]
//! pub extern fn do_add_one_in_wasmer() -> i32 {
//! let module_wat = r#"
//! (module
//! (type $t0 (func (param i32) (result i32)))
Expand All @@ -42,18 +44,15 @@
//! i32.const 1
//! i32.add))
//! "#;
//!
//! let store = Store::default();
//! let module = Module::new(&store, &module_wat)?;
//! let module = Module::new(&store, &module_wat).unwrap();
//! // The module doesn't import anything, so we create an empty import object.
//! let import_object = imports! {};
//! let instance = Instance::new(&module, &import_object)?;
//!
//! let add_one = instance.exports.get_function("add_one")?;
//! let result = add_one.call(&[Value::I32(42)])?;
//! let instance = Instance::new(&module, &import_object).unwrap();
//! let add_one = instance.exports.get_function("add_one").unwrap();
//! let result = add_one.call(&[Value::I32(42)]).unwrap();
//! assert_eq!(result[0], Value::I32(43));
//!
//! Ok(())
//! result[0].unwrap_i32()
//! }
//! ```
//!
Expand Down

0 comments on commit 3117db4

Please sign in to comment.