| 1 |
use wasm_bindgen::prelude::*; |
| 2 |
use wasm_bindgen_test::*; |
| 3 |
|
| 4 |
#[wasm_bindgen(module = "tests/wasm/node.js")] |
| 5 |
extern "C" { |
| 6 |
fn test_works(); |
| 7 |
static FOO: JsValue; |
| 8 |
fn hit(); |
| 9 |
} |
| 10 |
|
| 11 |
#[wasm_bindgen_test] |
| 12 |
fn works() { |
| 13 |
hit(); |
| 14 |
assert_eq!(FOO.as_f64(), Some(1.0)); |
| 15 |
test_works(); |
| 16 |
} |
| 17 |
|
| 18 |
#[wasm_bindgen] |
| 19 |
pub struct Foo { |
| 20 |
contents: u32, |
| 21 |
} |
| 22 |
|
| 23 |
#[wasm_bindgen] |
| 24 |
impl Foo { |
| 25 |
pub fn new() -> Foo { |
| 26 |
Foo::with_contents(0) |
| 27 |
} |
| 28 |
pub fn with_contents(a: u32) -> Foo { |
| 29 |
Foo { contents: a } |
| 30 |
} |
| 31 |
pub fn add(&mut self, amt: u32) -> u32 { |
| 32 |
self.contents += amt; |
| 33 |
self.contents |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
// Use a different name to avoid a collision with the `Color` enum in enums.rs when --no-modules is used. |
| 38 |
#[wasm_bindgen] |
| 39 |
pub enum NodeColor { |
| 40 |
Green, |
| 41 |
Yellow, |
| 42 |
Red, |
| 43 |
} |
| 44 |
#[wasm_bindgen] |
| 45 |
pub fn cycle(color: NodeColor) -> NodeColor { |
| 46 |
match color { |
| 47 |
NodeColor::Green => NodeColor::Yellow, |
| 48 |
NodeColor::Yellow => NodeColor::Red, |
| 49 |
NodeColor::Red => NodeColor::Green, |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
#[wasm_bindgen] |
| 54 |
pub fn node_math(a: f32, b: f64) -> f64 { |
| 55 |
b.acos() |
| 56 |
+ b.asin() |
| 57 |
+ b.atan() |
| 58 |
+ b.atan2(b) |
| 59 |
+ b.cbrt() |
| 60 |
+ b.cosh() |
| 61 |
+ b.exp_m1() |
| 62 |
+ b.ln_1p() |
| 63 |
+ b.sinh() |
| 64 |
+ b.tan() |
| 65 |
+ b.tanh() |
| 66 |
+ b.hypot(b) |
| 67 |
+ b.cos() |
| 68 |
+ b.exp() |
| 69 |
+ b.exp2() |
| 70 |
+ b.mul_add(b, b) |
| 71 |
+ b.ln() |
| 72 |
+ b.log(b) |
| 73 |
+ b.log10() |
| 74 |
+ b.log2() |
| 75 |
+ b.powi(8) |
| 76 |
+ b.powf(b) |
| 77 |
+ b.round() |
| 78 |
+ b.sin() |
| 79 |
+ b.abs() |
| 80 |
+ b.signum() |
| 81 |
+ b.floor() |
| 82 |
+ b.ceil() |
| 83 |
+ b.trunc() |
| 84 |
+ b.sqrt() |
| 85 |
+ (b % (a as f64)) |
| 86 |
+ ((a.cos() |
| 87 |
+ a.exp() |
| 88 |
+ a.exp2() |
| 89 |
+ a.mul_add(a, a) |
| 90 |
+ a.ln() |
| 91 |
+ a.log(a) |
| 92 |
+ a.log10() |
| 93 |
+ a.log2() |
| 94 |
+ a.powi(8) |
| 95 |
+ a.powf(a) |
| 96 |
+ a.round() |
| 97 |
+ a.sin() |
| 98 |
+ a.abs() |
| 99 |
+ a.signum() |
| 100 |
+ a.floor() |
| 101 |
+ a.ceil() |
| 102 |
+ a.trunc() |
| 103 |
+ a.sqrt() |
| 104 |
+ (a % (b as f32))) as f64) |
| 105 |
+ (b + 2.0f64.powf(a as f64)) |
| 106 |
} |