-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix passing large arrays with JS values into Wasm detaching memory (#…
- Loading branch information
Showing
7 changed files
with
45 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const assert = require('assert'); | ||
const wasm = require('wasm-bindgen-test'); | ||
|
||
// Test if passing large arrays which cause allocation in Wasm are properly handled. | ||
exports.pass_array_with_allocation = () => { | ||
const values = new Array(10_000).fill(1) | ||
assert.strictEqual(wasm.test_sum(values), 10_000); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use js_sys::Number; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use wasm_bindgen_test::wasm_bindgen_test; | ||
|
||
#[wasm_bindgen(module = "tests/wasm/js_vec.js")] | ||
extern "C" { | ||
fn pass_array_with_allocation(); | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn test_sum(param: Vec<Number>) -> f64 { | ||
let mut sum = 0.; | ||
|
||
for data in param { | ||
sum += data.value_of(); | ||
} | ||
|
||
sum | ||
} | ||
|
||
#[wasm_bindgen_test] | ||
fn test() { | ||
pass_array_with_allocation(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters