Address feedback on commit dab6ba1

This commit is contained in:
Ryan Levick 2018-02-28 17:29:40 +01:00
parent dab6ba1df8
commit 37da9eba14
3 changed files with 6 additions and 7 deletions

View File

@ -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

View File

@ -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[]",
}
}
}

View File

@ -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();