| 1 |
use wasm_bindgen::prelude::*; |
| 2 |
use wasm_bindgen_test::*; |
| 3 |
|
| 4 |
#[wasm_bindgen] |
| 5 |
pub struct OwnedValue { |
| 6 |
pub n: f64, |
| 7 |
} |
| 8 |
|
| 9 |
#[wasm_bindgen] |
| 10 |
impl OwnedValue { |
| 11 |
#[wasm_bindgen(constructor)] |
| 12 |
pub fn new(n: f64) -> Self { |
| 13 |
Self { n } |
| 14 |
} |
| 15 |
|
| 16 |
#[allow(clippy::should_implement_trait)] // traits unsupported by wasm_bindgen |
| 17 |
pub fn add(self, other: OwnedValue) -> Self { |
| 18 |
Self { |
| 19 |
n: self.n + other.n, |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
pub fn n(self) -> f64 { |
| 24 |
self.n |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
#[wasm_bindgen(module = "tests/wasm/owned.js")] |
| 29 |
extern "C" { |
| 30 |
fn create_garbage(); |
| 31 |
} |
| 32 |
|
| 33 |
#[wasm_bindgen_test] |
| 34 |
fn test_create_garbage() { |
| 35 |
create_garbage() |
| 36 |
} |