mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-28 05:52:21 +03:00
Merge branch 'node-math' of https://github.com/ashleygwilliams/wasm-bindgen
This commit is contained in:
commit
455e86ef6d
@ -337,10 +337,17 @@ impl<'a> Context<'a> {
|
||||
|
||||
let mut globals = &mut self.globals;
|
||||
let renamed_import = format!("__wbindgen_{}", import.field());
|
||||
let node = self.config.nodejs;
|
||||
let mut bind_math = |expr: &str| {
|
||||
if node {
|
||||
globals.push_str(&format!("
|
||||
exports.{} = function{};
|
||||
", renamed_import, expr));
|
||||
} else {
|
||||
globals.push_str(&format!("
|
||||
export function {}{}
|
||||
", renamed_import, expr));
|
||||
}
|
||||
};
|
||||
|
||||
// FIXME(#32): try to not use function shims
|
||||
|
@ -54,6 +54,61 @@ fn works() {
|
||||
Color::Red => Color::Green,
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn math(a: f32, b: f64) -> f64 {
|
||||
b.acos() +
|
||||
b.asin() +
|
||||
b.atan() +
|
||||
b.atan2(b) +
|
||||
b.cbrt() +
|
||||
b.cosh() +
|
||||
b.exp_m1() +
|
||||
b.ln_1p() +
|
||||
b.sinh() +
|
||||
b.tan() +
|
||||
b.tanh() +
|
||||
b.hypot(b) +
|
||||
b.cos() +
|
||||
b.exp() +
|
||||
b.exp2() +
|
||||
b.mul_add(b, b) +
|
||||
b.ln() +
|
||||
b.log(b) +
|
||||
b.log10() +
|
||||
b.log2() +
|
||||
b.powi(8) +
|
||||
b.powf(b) +
|
||||
b.round() +
|
||||
b.sin() +
|
||||
b.abs() +
|
||||
b.signum() +
|
||||
b.floor() +
|
||||
b.ceil() +
|
||||
b.trunc() +
|
||||
b.sqrt() +
|
||||
(b % (a as f64)) +
|
||||
((a.cos() +
|
||||
a.exp() +
|
||||
a.exp2() +
|
||||
a.mul_add(a, a) +
|
||||
a.ln() +
|
||||
a.log(a) +
|
||||
a.log10() +
|
||||
a.log2() +
|
||||
a.powi(8) +
|
||||
a.powf(a) +
|
||||
a.round() +
|
||||
a.sin() +
|
||||
a.abs() +
|
||||
a.signum() +
|
||||
a.floor() +
|
||||
a.ceil() +
|
||||
a.trunc() +
|
||||
a.sqrt() +
|
||||
(a % (b as f32))) as f64) +
|
||||
(b + 2.0f64.powf(a as f64))
|
||||
}
|
||||
"#)
|
||||
.file("test.js", r#"
|
||||
const assert = require('assert');
|
||||
@ -64,7 +119,7 @@ fn works() {
|
||||
called = true;
|
||||
};
|
||||
|
||||
const { run, Foo, Color, cycle } = require('./out');
|
||||
const { math, run, Foo, Color, cycle } = require('./out');
|
||||
|
||||
module.exports.test = function() {
|
||||
run();
|
||||
@ -87,6 +142,8 @@ fn works() {
|
||||
assert.strictEqual(Color.Red, 2);
|
||||
assert.strictEqual(Object.keys(Color).length, 3);
|
||||
assert.strictEqual(cycle(Color.Green), Color.Yellow);
|
||||
|
||||
math(1.0, 2.0);
|
||||
};
|
||||
|
||||
"#)
|
||||
|
Loading…
Reference in New Issue
Block a user