diff --git a/README.md b/README.md index 150024ba..b1c641f3 100644 --- a/README.md +++ b/README.md @@ -402,7 +402,7 @@ are: * Imported types in a foreign module annotated with `#[wasm_bindgen]` * Borrowed exported structs (`&Foo` or `&mut Bar`) * The `JsValue` type and `&JsValue` (not mutable references) -* Vectors and slices of supported integer types +* Vectors and slices of supported integer types and of the `JsValue` type. All of the above can also be returned except borrowed references. Strings are implemented with shim functions to copy data in/out of the Rust heap. That is, a diff --git a/crates/wasm-bindgen-cli-support/src/js.rs b/crates/wasm-bindgen-cli-support/src/js.rs index e1810ce6..a099d646 100644 --- a/crates/wasm-bindgen-cli-support/src/js.rs +++ b/crates/wasm-bindgen-cli-support/src/js.rs @@ -660,12 +660,12 @@ impl<'a> Context<'a> { if !self.exposed_globals.insert("get_array_js_value_from_wasm") { return } - self.expose_get_array_u8_from_wasm(); + self.expose_get_array_u32_from_wasm(); self.expose_get_object(); self.globals.push_str(&format!(" function getArrayJsValueFromWasm(ptr, len) {{ - const mem = getUint8Memory(); - const slice = mem.slice(ptr, ptr + len); + const mem = getUint32Memory(); + const slice = mem.slice(ptr / 4, ptr / 4 + len); const result = [] for (ptr in slice) {{ result.push(getObject(ptr)) @@ -1569,7 +1569,7 @@ impl VectorType { VectorKind::U32 => "Uint32Array", VectorKind::F32 => "Float32Array", VectorKind::F64 => "Float64Array", - VectorKind::JsValue => "object[]", + VectorKind::JsValue => "any[]", } } } diff --git a/tests/jsobjects.rs b/tests/jsobjects.rs index be88b225..06b338e6 100644 --- a/tests/jsobjects.rs +++ b/tests/jsobjects.rs @@ -206,8 +206,7 @@ fn returning_vector() { import * as wasm from "./out"; import * as assert from "assert"; - - export function foo(): any { return { "foo": "bar" } } + export function foo(): any { return { "foo": "bar" }; } export function test() { const result = wasm.bar();