From 3117db4fd2e327639525af23bed847d2d8981117 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Thu, 22 Jul 2021 16:57:03 -0700 Subject: [PATCH] Improved comments --- lib/js-api/README.md | 3 +++ lib/js-api/src/externals/memory.rs | 2 +- lib/js-api/src/externals/table.rs | 2 +- lib/js-api/src/lib.rs | 27 +++++++++++++-------------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/js-api/README.md b/lib/js-api/README.md index 2563f9ab2e7..297f103afc1 100644 --- a/lib/js-api/README.md +++ b/lib/js-api/README.md @@ -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. diff --git a/lib/js-api/src/externals/memory.rs b/lib/js-api/src/externals/memory.rs index c7398ec01e9..badc4c1bf2c 100644 --- a/lib/js-api/src/externals/memory.rs +++ b/lib/js-api/src/externals/memory.rs @@ -285,7 +285,7 @@ impl Memory { /// # } /// ``` pub fn view(&self) -> MemoryView { - unimplemented!(); + unimplemented!("The view function is not yet implemented in Wasmer Javascript"); } /// example view diff --git a/lib/js-api/src/externals/table.rs b/lib/js-api/src/externals/table.rs index 0e1c4d47657..a7f7ee7fc53 100644 --- a/lib/js-api/src/externals/table.rs +++ b/lib/js-api/src/externals/table.rs @@ -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 { diff --git a/lib/js-api/src/lib.rs b/lib/js-api/src/lib.rs index 22ee08a2b98..951a406de7a 100644 --- a/lib/js-api/src/lib.rs +++ b/lib/js-api/src/lib.rs @@ -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))) @@ -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() //! } //! ``` //!