mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-24 14:42:35 +03:00
Correct how slices are iterated over
This commit fixes how the `getArrayJsValueFromWasm` function is defined to correctly iterate over the slice by looking at the values rather than the indices. Closes #169
This commit is contained in:
parent
b2ecf56cb6
commit
faed98b843
@ -225,7 +225,6 @@ impl<'a> Context<'a> {
|
||||
Ok(format!("
|
||||
function(ptr, len) {{
|
||||
let a;
|
||||
console.log(ptr, len);
|
||||
if (ptr === 0) {{
|
||||
a = Symbol();
|
||||
}} else {{
|
||||
@ -889,8 +888,8 @@ impl<'a> Context<'a> {
|
||||
const mem = getUint32Memory();
|
||||
const slice = mem.slice(ptr / 4, ptr / 4 + len);
|
||||
const result = [];
|
||||
for (ptr in slice) {{
|
||||
result.push(getObject(ptr))
|
||||
for (let i = 0; i < slice.length; i++) {{
|
||||
result.push(getObject(slice[i]))
|
||||
}}
|
||||
return result;
|
||||
}}
|
||||
|
@ -210,3 +210,37 @@ fn returning_vector() {
|
||||
"#)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn another_vector_return() {
|
||||
project()
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_array() -> Vec<JsValue> {
|
||||
vec![
|
||||
JsValue::from(1),
|
||||
JsValue::from(2),
|
||||
JsValue::from(3),
|
||||
JsValue::from(4),
|
||||
JsValue::from(5),
|
||||
JsValue::from(6),
|
||||
]
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import { get_array } from "./out";
|
||||
import * as assert from "assert";
|
||||
|
||||
export function test() {
|
||||
assert.deepStrictEqual(get_array(), [1, 2, 3, 4, 5, 6]);
|
||||
}
|
||||
"#)
|
||||
.test();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user