File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -231,6 +231,18 @@ extern {
231
231
pub fn name ( this : & JsFunction ) -> JsString ;
232
232
}
233
233
234
+ // Math
235
+ #[ wasm_bindgen]
236
+ extern {
237
+ pub type Math ;
238
+ /// The Math.abs() function returns the absolute value of a number, that is
239
+ /// Math.abs(x) = |x|
240
+ ///
241
+ /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs
242
+ #[ wasm_bindgen( static_method_of = Math ) ]
243
+ pub fn abs ( number : i32 ) -> Number ;
244
+ }
245
+
234
246
// Number.
235
247
#[ wasm_bindgen]
236
248
extern {
Original file line number Diff line number Diff line change
1
+ #![ allow( non_snake_case) ]
2
+
3
+ use super :: project;
4
+
5
+
6
+ #[ test]
7
+ fn abs ( ) {
8
+ project ( )
9
+ . file ( "src/lib.rs" , r#"
10
+ #![feature(proc_macro, wasm_custom_section)]
11
+
12
+ extern crate wasm_bindgen;
13
+ use wasm_bindgen::prelude::*;
14
+ use wasm_bindgen::js;
15
+
16
+ #[wasm_bindgen]
17
+ pub fn abs(number: i32) -> js::Number {
18
+ js::Math::abs(number)
19
+ }
20
+ "# )
21
+ . file ( "test.ts" , r#"
22
+ import * as assert from "assert";
23
+ import * as wasm from "./out";
24
+
25
+ export function test() {
26
+ assert.equal(wasm.abs(-32), Math.abs(-32));
27
+ assert.equal(wasm.abs(32), 32));
28
+ }
29
+ "# )
30
+ . test ( )
31
+ }
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ mod ArrayIterator;
8
8
mod JsFunction ;
9
9
mod JsString ;
10
10
mod Number ;
11
+ mod Math ;
11
12
12
13
#[ test]
13
14
#[ cfg( feature = "std" ) ]
You can’t perform that action at this time.
0 commit comments