Last round of fixes

This commit is contained in:
Syrus Akbary
2021-07-17 16:16:12 -07:00
parent 2912d20892
commit 1e6762389d
12 changed files with 58 additions and 57 deletions

View File

@@ -8,7 +8,7 @@ WebAssembly via `wasm-bindgen`.
## Usage
We recommend aliasing `wasmer_js` to `wasmer`.
We recommend aliasing `wasmer_js` to `wasmer` at the top of your crate.
```rust
#[cfg(feature = "js")]
@@ -47,7 +47,8 @@ pub extern fn do_add_one_in_wasmer() -> i32 {
## Feature flags
`wasmer-js` has the following feature flags:
* `wasm-types-polyfill` (enabled by default): it parses the Wasm file to introspect the inner types. __It adds 100Kb to the Wasm bundle__ (28Kb gzipped). You can disable it and use `Module::set_type_hints` manually instead if you want a lightweight alternative.
* `wasm-types-polyfill` (enabled by default): it parses the Wasm file, allowing to do type reflection of the inner WebAssembly types.
__It adds 100Kb to the Wasm bundle__ (28Kb gzipped). You can disable it and use `Module::set_type_hints` manually instead if you want a lightweight alternative.
This is needed until the [Wasm JS introspection API proposal](https://github.com/WebAssembly/js-types/blob/master/proposals/js-types/Overview.md) is adopted by browsers
* `wat`: It allows to read WebAssembly files in their text format.

View File

@@ -96,7 +96,7 @@ impl<'a, T: Copy> WasmCell<'a, T> {
///
/// ```
/// use std::cell::Cell;
/// use wasmer::WasmCell;
/// use wasmer_js::WasmCell;
///
/// let cell = Cell::new(5);
/// let wasm_cell = WasmCell::new(&cell);
@@ -123,7 +123,7 @@ impl<T: Sized> WasmCell<'_, T> {
///
/// ```
/// use std::cell::Cell;
/// use wasmer::WasmCell;
/// use wasmer_js::WasmCell;
///
/// let cell = Cell::new(5);
/// let wasm_cell = WasmCell::new(&cell);

View File

@@ -28,7 +28,7 @@ impl From<ExportError> for HostEnvInitError {
/// This trait can be derived like so:
///
/// ```
/// use wasmer::{WasmerEnv, LazyInit, Memory, NativeFunc};
/// use wasmer_js::{WasmerEnv, LazyInit, Memory, NativeFunc};
///
/// #[derive(WasmerEnv, Clone)]
/// pub struct MyEnvWithNoInstanceData {
@@ -63,7 +63,7 @@ impl From<ExportError> for HostEnvInitError {
///
/// This trait may also be implemented manually:
/// ```
/// # use wasmer::{WasmerEnv, LazyInit, Memory, Instance, HostEnvInitError};
/// # use wasmer_js::{WasmerEnv, LazyInit, Memory, Instance, HostEnvInitError};
/// #[derive(Clone)]
/// pub struct MyEnv {
/// memory: LazyInit<Memory>,

View File

@@ -19,7 +19,7 @@ use thiserror::Error;
/// ## Incompatible export type
///
/// ```should_panic
/// # use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, Type, Value, ExportError};
/// # use wasmer_js::{imports, wat2wasm, Function, Instance, Module, Store, Type, Value, ExportError};
/// # let store = Store::default();
/// # let wasm_bytes = wat2wasm(r#"
/// # (module
@@ -36,7 +36,7 @@ use thiserror::Error;
/// ## Missing export
///
/// ```should_panic
/// # use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, Type, Value, ExportError};
/// # use wasmer_js::{imports, wat2wasm, Function, Instance, Module, Store, Type, Value, ExportError};
/// # let store = Store::default();
/// # let wasm_bytes = wat2wasm("(module)".as_bytes()).unwrap();
/// # let module = Module::new(&store, wasm_bytes).unwrap();

View File

@@ -68,7 +68,7 @@ impl Function {
/// # Examples
///
/// ```
/// # use wasmer::{Function, FunctionType, Type, Store, Value};
/// # use wasmer_js::{Function, FunctionType, Type, Store, Value};
/// # let store = Store::default();
/// #
/// let signature = FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32]);
@@ -82,7 +82,7 @@ impl Function {
/// With constant signature:
///
/// ```
/// # use wasmer::{Function, FunctionType, Type, Store, Value};
/// # use wasmer_js::{Function, FunctionType, Type, Store, Value};
/// # let store = Store::default();
/// #
/// const I32_I32_TO_I32: ([Type; 2], [Type; 1]) = ([Type::I32, Type::I32], [Type::I32]);
@@ -162,7 +162,7 @@ impl Function {
/// # Examples
///
/// ```
/// # use wasmer::{Function, FunctionType, Type, Store, Value, WasmerEnv};
/// # use wasmer_js::{Function, FunctionType, Type, Store, Value, WasmerEnv};
/// # let store = Store::default();
/// #
/// #[derive(WasmerEnv, Clone)]
@@ -182,7 +182,7 @@ impl Function {
/// With constant signature:
///
/// ```
/// # use wasmer::{Function, FunctionType, Type, Store, Value, WasmerEnv};
/// # use wasmer_js::{Function, FunctionType, Type, Store, Value, WasmerEnv};
/// # let store = Store::default();
/// const I32_I32_TO_I32: ([Type; 2], [Type; 1]) = ([Type::I32, Type::I32], [Type::I32]);
///
@@ -275,7 +275,7 @@ impl Function {
/// # Example
///
/// ```
/// # use wasmer::{Store, Function};
/// # use wasmer_js::{Store, Function};
/// # let store = Store::default();
/// #
/// fn sum(a: i32, b: i32) -> i32 {
@@ -316,7 +316,7 @@ impl Function {
/// # Example
///
/// ```
/// # use wasmer::{Store, Function, WasmerEnv};
/// # use wasmer_js::{Store, Function, WasmerEnv};
/// # let store = Store::default();
/// #
/// #[derive(WasmerEnv, Clone)]
@@ -365,7 +365,7 @@ impl Function {
/// # Example
///
/// ```
/// # use wasmer::{Function, Store, Type};
/// # use wasmer_js::{Function, Store, Type};
/// # let store = Store::default();
/// #
/// fn sum(a: i32, b: i32) -> i32 {
@@ -391,7 +391,7 @@ impl Function {
/// # Example
///
/// ```
/// # use wasmer::{Function, Store, Type};
/// # use wasmer_js::{Function, Store, Type};
/// # let store = Store::default();
/// #
/// fn sum(a: i32, b: i32) -> i32 {
@@ -411,7 +411,7 @@ impl Function {
/// # Example
///
/// ```
/// # use wasmer::{Function, Store, Type};
/// # use wasmer_js::{Function, Store, Type};
/// # let store = Store::default();
/// #
/// fn sum(a: i32, b: i32) -> i32 {
@@ -437,7 +437,7 @@ impl Function {
/// # Examples
///
/// ```
/// # use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, Type, Value};
/// # use wasmer_js::{imports, wat2wasm, Function, Instance, Module, Store, Type, Value};
/// # let store = Store::default();
/// # let wasm_bytes = wat2wasm(r#"
/// # (module
@@ -496,7 +496,7 @@ impl Function {
/// # Examples
///
/// ```
/// # use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, Type, Value};
/// # use wasmer_js::{imports, wat2wasm, Function, Instance, Module, Store, Type, Value};
/// # let store = Store::default();
/// # let wasm_bytes = wat2wasm(r#"
/// # (module
@@ -522,7 +522,7 @@ impl Function {
/// an error will be raised:
///
/// ```should_panic
/// # use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, Type, Value};
/// # use wasmer_js::{imports, wat2wasm, Function, Instance, Module, Store, Type, Value};
/// # let store = Store::default();
/// # let wasm_bytes = wat2wasm(r#"
/// # (module
@@ -546,7 +546,7 @@ impl Function {
/// an error will be raised:
///
/// ```should_panic
/// # use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, Type, Value};
/// # use wasmer_js::{imports, wat2wasm, Function, Instance, Module, Store, Type, Value};
/// # let store = Store::default();
/// # let wasm_bytes = wat2wasm(r#"
/// # (module
@@ -655,7 +655,7 @@ mod inner {
#[cfg(feature = "experimental-reference-types-extern-ref")]
pub use wasmer_types::{ExternRef, VMExternRef};
use wasmer_types::{FunctionType, NativeWasmType, Type};
// use wasmer::{raise_user_trap, resume_panic};
// use wasmer_js::{raise_user_trap, resume_panic};
/// A trait to convert a Rust value to a `WasmNativeType` value,
/// or to convert `WasmNativeType` value to a Rust value.

View File

@@ -28,7 +28,7 @@ impl Global {
/// # Example
///
/// ```
/// # use wasmer::{Global, Mutability, Store, Value};
/// # use wasmer_js::{Global, Mutability, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new(&store, Value::I32(1));
@@ -45,7 +45,7 @@ impl Global {
/// # Example
///
/// ```
/// # use wasmer::{Global, Mutability, Store, Value};
/// # use wasmer_js::{Global, Mutability, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new_mut(&store, Value::I32(1));
@@ -94,7 +94,7 @@ impl Global {
/// # Example
///
/// ```
/// # use wasmer::{Global, Mutability, Store, Type, Value, GlobalType};
/// # use wasmer_js::{Global, Mutability, Store, Type, Value, GlobalType};
/// # let store = Store::default();
/// #
/// let c = Global::new(&store, Value::I32(1));
@@ -112,7 +112,7 @@ impl Global {
/// # Example
///
/// ```
/// # use wasmer::{Global, Store, Value};
/// # use wasmer_js::{Global, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new(&store, Value::I32(1));
@@ -128,7 +128,7 @@ impl Global {
/// # Example
///
/// ```
/// # use wasmer::{Global, Store, Value};
/// # use wasmer_js::{Global, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new(&store, Value::I32(1));
@@ -150,7 +150,7 @@ impl Global {
/// # Example
///
/// ```
/// # use wasmer::{Global, Store, Value};
/// # use wasmer_js::{Global, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new_mut(&store, Value::I32(1));
@@ -167,7 +167,7 @@ impl Global {
/// Trying to mutate a immutable global will raise an error:
///
/// ```should_panic
/// # use wasmer::{Global, Store, Value};
/// # use wasmer_js::{Global, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new(&store, Value::I32(1));
@@ -178,7 +178,7 @@ impl Global {
/// Trying to set a value of a incompatible type will raise an error:
///
/// ```should_panic
/// # use wasmer::{Global, Store, Value};
/// # use wasmer_js::{Global, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new(&store, Value::I32(1));
@@ -216,7 +216,7 @@ impl Global {
/// # Example
///
/// ```
/// # use wasmer::{Global, Store, Value};
/// # use wasmer_js::{Global, Store, Value};
/// # let store = Store::default();
/// #
/// let g = Global::new(&store, Value::I32(1));

View File

@@ -75,7 +75,7 @@ impl Memory {
/// # Example
///
/// ```
/// # use wasmer::{Memory, MemoryType, Pages, Store, Type, Value};
/// # use wasmer_js::{Memory, MemoryType, Pages, Store, Type, Value};
/// # let store = Store::default();
/// #
/// let m = Memory::new(&store, MemoryType::new(1, None, false)).unwrap();
@@ -103,7 +103,7 @@ impl Memory {
/// # Example
///
/// ```
/// # use wasmer::{Memory, MemoryType, Pages, Store, Type, Value};
/// # use wasmer_js::{Memory, MemoryType, Pages, Store, Type, Value};
/// # let store = Store::default();
/// #
/// let mt = MemoryType::new(1, None, false);
@@ -122,7 +122,7 @@ impl Memory {
/// # Example
///
/// ```
/// # use wasmer::{Memory, MemoryType, Pages, Store, Type, Value};
/// # use wasmer_js::{Memory, MemoryType, Pages, Store, Type, Value};
/// # let store = Store::default();
/// #
/// let m = Memory::new(&store, MemoryType::new(1, None, false)).unwrap();
@@ -177,7 +177,7 @@ impl Memory {
/// # Example
///
/// ```
/// # use wasmer::{Memory, MemoryType, Pages, Store, Type, Value};
/// # use wasmer_js::{Memory, MemoryType, Pages, Store, Type, Value};
/// # let store = Store::default();
/// #
/// let m = Memory::new(&store, MemoryType::new(1, None, false)).unwrap();
@@ -198,7 +198,7 @@ impl Memory {
/// # Example
///
/// ```
/// # use wasmer::{Memory, MemoryType, Pages, Store, Type, Value, WASM_MAX_PAGES};
/// # use wasmer_js::{Memory, MemoryType, Pages, Store, Type, Value, WASM_MAX_PAGES};
/// # let store = Store::default();
/// #
/// let m = Memory::new(&store, MemoryType::new(1, Some(3), false)).unwrap();
@@ -214,7 +214,7 @@ impl Memory {
/// of pages.
///
/// ```should_panic
/// # use wasmer::{Memory, MemoryType, Pages, Store, Type, Value, WASM_MAX_PAGES};
/// # use wasmer_js::{Memory, MemoryType, Pages, Store, Type, Value, WASM_MAX_PAGES};
/// # let store = Store::default();
/// #
/// let m = Memory::new(&store, MemoryType::new(1, Some(1), false)).unwrap();
@@ -256,7 +256,7 @@ impl Memory {
/// # Usage:
///
/// ```
/// # use wasmer::{Memory, MemoryView};
/// # use wasmer_js::{Memory, MemoryView};
/// # use std::{cell::Cell, sync::atomic::Ordering};
/// # fn view_memory(memory: Memory) {
/// // Without synchronization.
@@ -293,7 +293,7 @@ impl Memory {
/// # Example
///
/// ```
/// # use wasmer::{Memory, MemoryType, Store, Value};
/// # use wasmer_js::{Memory, MemoryType, Store, Value};
/// # let store = Store::default();
/// #
/// let m = Memory::new(&store, MemoryType::new(1, None, false)).unwrap();

View File

@@ -28,7 +28,7 @@ pub trait LikeNamespace {
///
/// # Usage:
/// ```ignore
/// use wasmer::{Exports, ImportObject, Function};
/// use wasmer_js::{Exports, ImportObject, Function};
///
/// let mut import_object = ImportObject::new();
/// let mut env = Exports::new();
@@ -55,7 +55,7 @@ impl ImportObject {
///
/// # Usage
/// ```ignore
/// # use wasmer::{ImportObject, Instance, Namespace};
/// # use wasmer_js::{ImportObject, Instance, Namespace};
/// let mut import_object = ImportObject::new();
/// import_object.get_export("module", "name");
/// ```
@@ -78,7 +78,7 @@ impl ImportObject {
///
/// # Usage:
/// ```ignore
/// # use wasmer::{ImportObject, Instance, Namespace};
/// # use wasmer_js::{ImportObject, Instance, Namespace};
/// let mut import_object = ImportObject::new();
///
/// import_object.register("namespace0", instance);
@@ -188,9 +188,9 @@ impl fmt::Debug for ImportObject {
/// # Usage
///
/// ```
/// # use wasmer::{Function, Store};
/// # use wasmer_js::{Function, Store};
/// # let store = Store::default();
/// use wasmer::imports;
/// use wasmer_js::imports;
///
/// let import_object = imports! {
/// "env" => {

View File

@@ -75,7 +75,7 @@ impl Instance {
/// [`ImportObject`]: crate::ImportObject
///
/// ```
/// # use wasmer::{imports, Store, Module, Global, Value, Instance};
/// # use wasmer_js::{imports, Store, Module, Global, Value, Instance};
/// # fn main() -> anyhow::Result<()> {
/// let store = Store::default();
/// let module = Module::new(&store, "(module)")?;

View File

@@ -86,7 +86,7 @@ impl Module {
/// Reading from a WAT file.
///
/// ```
/// use wasmer::*;
/// use wasmer_js::*;
/// # fn main() -> anyhow::Result<()> {
/// # let store = Store::default();
/// let wat = "(module)";
@@ -98,7 +98,7 @@ impl Module {
/// Reading from bytes:
///
/// ```
/// use wasmer::*;
/// use wasmer_js::*;
/// # fn main() -> anyhow::Result<()> {
/// # let store = Store::default();
/// // The following is the same as:
@@ -257,7 +257,7 @@ impl Module {
/// # Example
///
/// ```
/// # use wasmer::*;
/// # use wasmer_js::*;
/// # fn main() -> anyhow::Result<()> {
/// # let store = Store::default();
/// let wat = "(module $moduleName)";
@@ -281,7 +281,7 @@ impl Module {
/// # Example
///
/// ```
/// # use wasmer::*;
/// # use wasmer_js::*;
/// # fn main() -> anyhow::Result<()> {
/// # let store = Store::default();
/// let wat = "(module)";
@@ -316,7 +316,7 @@ impl Module {
/// # Example
///
/// ```
/// # use wasmer::*;
/// # use wasmer_js::*;
/// # fn main() -> anyhow::Result<()> {
/// # let store = Store::default();
/// let wat = r#"(module
@@ -414,7 +414,7 @@ impl Module {
/// # Example
///
/// ```
/// # use wasmer::*;
/// # use wasmer_js::*;
/// # fn main() -> anyhow::Result<()> {
/// # let store = Store::default();
/// let wat = r#"(module

View File

@@ -23,8 +23,8 @@ pub struct Item;
///
/// This type can be used directly in the host function arguments:
/// ```
/// # use wasmer::Memory;
/// # use wasmer::WasmPtr;
/// # use wasmer_js::Memory;
/// # use wasmer_js::WasmPtr;
/// pub fn host_import(memory: Memory, ptr: WasmPtr<u32>) {
/// let derefed_ptr = ptr.deref(&memory).expect("pointer in bounds");
/// let inner_val: u32 = derefed_ptr.get();
@@ -37,9 +37,9 @@ pub struct Item;
/// This type can also be used with primitive-filled structs, but be careful of
/// guarantees required by `ValueType`.
/// ```
/// # use wasmer::Memory;
/// # use wasmer::WasmPtr;
/// # use wasmer::ValueType;
/// # use wasmer_js::Memory;
/// # use wasmer_js::WasmPtr;
/// # use wasmer_js::ValueType;
///
/// #[derive(Copy, Clone, Debug)]
/// #[repr(C)]