diff --git a/src/js.rs b/src/js.rs index e50b3b40..cc39d01e 100644 --- a/src/js.rs +++ b/src/js.rs @@ -241,6 +241,15 @@ extern { /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs #[wasm_bindgen(static_method_of = Math)] pub fn abs(number: i32) -> Number; + + /// The Math.acos() function returns the arccosine (in radians) of a + /// number, that is ∀x∊[-1;1] + /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos + #[wasm_bindgen(static_method_of = Math)] + pub fn acos(adjacent: i32, hypotenuse: i32) -> Number; + } // Number. diff --git a/tests/all/js_globals/Math.rs b/tests/all/js_globals/Math.rs index 98992f45..beee88bb 100644 --- a/tests/all/js_globals/Math.rs +++ b/tests/all/js_globals/Math.rs @@ -24,7 +24,33 @@ fn abs() { export function test() { assert.equal(wasm.abs(-32), Math.abs(-32)); - assert.equal(wasm.abs(32), 32)); + assert.equal(wasm.abs(32), 32); + } + "#) + .test() +} + +#[test] +fn acos() { + project() + .file("src/lib.rs", r#" + #![feature(proc_macro, wasm_custom_section)] + + extern crate wasm_bindgen; + use wasm_bindgen::prelude::*; + use wasm_bindgen::js; + + #[wasm_bindgen] + pub fn acos(adjacent: i32, hypotenuse: i32) -> js::Number { + js::Math::acos(adjacent, hypotenuse) + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.acos(-1, 1), Math.PI); } "#) .test()