From ee31080b094a3cb32d2da8e09cb217be97d5ec2e Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 25 Jun 2018 20:33:39 +0200 Subject: [PATCH 01/12] Format comments so they become more readable in editor --- src/js.rs | 70 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/src/js.rs b/src/js.rs index 7e718d41..f82573c6 100644 --- a/src/js.rs +++ b/src/js.rs @@ -70,8 +70,8 @@ extern { extern { pub type Array; - /// The copyWithin() method shallow copies part of an array to another location in the same - /// array and returns it, without modifying its size. + /// The copyWithin() method shallow copies part of an array to another + /// location in the same array and returns it, without modifying its size. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin #[wasm_bindgen(method, js_name = copyWithin)] @@ -84,29 +84,31 @@ extern { #[wasm_bindgen(method)] pub fn concat(this: &Array, array: &Array) -> Array; - /// The fill() method fills all the elements of an array from a start index to an - /// end index with a static value. The end index is not included. + /// The fill() method fills all the elements of an array from a start index + /// to an end index with a static value. The end index is not included. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill #[wasm_bindgen(method)] pub fn fill(this: &Array, value: JsValue, start: u32, end: u32) -> Array; - /// The length property of an object which is an instance of type Array sets or returns the number of elements in that array. - /// The value is an unsigned, 32-bit integer that is always numerically greater than the highest index in the array. + /// The length property of an object which is an instance of type Array + /// sets or returns the number of elements in that array. The value is an + /// unsigned, 32-bit integer that is always numerically greater than the + /// highest index in the array. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length #[wasm_bindgen(method, getter, structural)] pub fn length(this: &Array) -> u32; - /// The indexOf() method returns the first index at which a given element can be - /// found in the array, or -1 if it is not present. + /// The indexOf() method returns the first index at which a given element + /// can be found in the array, or -1 if it is not present. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf #[wasm_bindgen(method, js_name = indexOf)] pub fn index_of(this: &Array, value: JsValue, from_index: i32) -> i32; - /// The includes() method determines whether an array includes a certain element, - /// returning true or false as appropriate. + /// The includes() method determines whether an array includes a certain + /// element, returning true or false as appropriate. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes #[wasm_bindgen(method)] @@ -119,45 +121,45 @@ extern { #[wasm_bindgen(method)] pub fn join(this: &Array, delimiter: &str) -> JsString; - /// The lastIndexOf() method returns the last index at which a given element can - /// be found in the array, or -1 if it is not present. The array is searched - /// backwards, starting at fromIndex. + /// The lastIndexOf() method returns the last index at which a given element + /// can be found in the array, or -1 if it is not present. The array is + /// searched backwards, starting at fromIndex. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf #[wasm_bindgen(method, js_name = lastIndexOf)] pub fn last_index_of(this: &Array, value: JsValue, from_index: i32) -> i32; - /// The pop() method removes the last element from an array and returns that element. - /// This method changes the length of the array. + /// The pop() method removes the last element from an array and returns that + /// element. This method changes the length of the array. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop #[wasm_bindgen(method)] pub fn pop(this: &Array) -> JsValue; - /// The push() method adds one or more elements to the end of an array and returns - /// the new length of the array. + /// The push() method adds one or more elements to the end of an array and + /// returns the new length of the array. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push #[wasm_bindgen(method)] pub fn push(this: &Array, value: JsValue) -> u32; - /// The reverse() method reverses an array in place. - /// The first array element becomes the last, and the last array element becomes the first. + /// The reverse() method reverses an array in place. The first array + /// element becomes the last, and the last array element becomes the first. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse #[wasm_bindgen(method)] pub fn reverse(this: &Array) -> Array; - /// The slice() method returns a shallow copy of a portion of an array into a new array - /// object selected from begin to end (end not included). + /// The slice() method returns a shallow copy of a portion of an array into + /// a new array object selected from begin to end (end not included). /// The original array will not be modified. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice #[wasm_bindgen(method)] pub fn slice(this: &Array, start: u32, end: u32) -> Array; - /// The shift() method removes the first element from an array and returns that removed element. - /// This method changes the length of the array. + /// The shift() method removes the first element from an array and returns + /// that removed element. This method changes the length of the array. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift #[wasm_bindgen(method)] @@ -174,14 +176,15 @@ extern { #[wasm_bindgen(method)] pub fn sort(this: &Array) -> Array; - /// The toString() method returns a string representing the specified array and its elements. + /// The toString() method returns a string representing the specified array + /// and its elements. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString #[wasm_bindgen(method, js_name = toString)] pub fn to_string(this: &Array) -> JsString; - /// The unshift() method adds one or more elements to the beginning of an array - /// and returns the new length of the array. + /// The unshift() method adds one or more elements to the beginning of an + /// array and returns the new length of the array. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift #[wasm_bindgen(method)] @@ -193,13 +196,15 @@ extern { extern { pub type ArrayIterator; - /// The keys() method returns a new Array Iterator object that contains the keys for each index in the array. + /// The keys() method returns a new Array Iterator object that contains the + /// keys for each index in the array. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys #[wasm_bindgen(method)] pub fn keys(this: &Array) -> ArrayIterator; - /// The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array. + /// The entries() method returns a new Array Iterator object that contains + /// the key/value pairs for each index in the array. /// /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries #[wasm_bindgen(method)] @@ -217,8 +222,9 @@ extern { #[wasm_bindgen(method, getter, structural)] pub fn length(this: &JsFunction) -> u32; - /// A Function object's read-only name property indicates the function's name as specified when it was created - /// or "anonymous" for functions created anonymously. + /// A Function object's read-only name property indicates the function's + /// name as specified when it was created or "anonymous" for functions + /// created anonymously. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name #[wasm_bindgen(method, getter, structural)] @@ -314,8 +320,8 @@ extern { pub fn property_is_enumerable(this: &Object, property: &JsValue) -> bool; /// The toLocaleString() method returns a string representing the object. - /// This method is meant to be overridden by derived objects for locale-specific - /// purposes. + /// This method is meant to be overridden by derived objects for + /// locale-specific purposes. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString #[wasm_bindgen(method, js_name = toLocaleString)] From 9633642e6ed7ff494b0b610cdd62dc9eea13c5b3 Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 25 Jun 2018 21:41:28 +0200 Subject: [PATCH 02/12] Add abs to Math --- src/js.rs | 12 ++++++++++++ tests/all/js_globals/Math.rs | 31 +++++++++++++++++++++++++++++++ tests/all/js_globals/mod.rs | 1 + 3 files changed, 44 insertions(+) create mode 100644 tests/all/js_globals/Math.rs diff --git a/src/js.rs b/src/js.rs index f82573c6..e50b3b40 100644 --- a/src/js.rs +++ b/src/js.rs @@ -231,6 +231,18 @@ extern { pub fn name(this: &JsFunction) -> JsString; } +// Math +#[wasm_bindgen] +extern { + pub type Math; + /// The Math.abs() function returns the absolute value of a number, that is + /// Math.abs(x) = |x| + /// + /// 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; +} + // Number. #[wasm_bindgen] extern { diff --git a/tests/all/js_globals/Math.rs b/tests/all/js_globals/Math.rs new file mode 100644 index 00000000..98992f45 --- /dev/null +++ b/tests/all/js_globals/Math.rs @@ -0,0 +1,31 @@ +#![allow(non_snake_case)] + +use super::project; + + +#[test] +fn abs() { + 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 abs(number: i32) -> js::Number { + js::Math::abs(number) + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.abs(-32), Math.abs(-32)); + assert.equal(wasm.abs(32), 32)); + } + "#) + .test() +} diff --git a/tests/all/js_globals/mod.rs b/tests/all/js_globals/mod.rs index a5d24246..3fd54d80 100644 --- a/tests/all/js_globals/mod.rs +++ b/tests/all/js_globals/mod.rs @@ -8,6 +8,7 @@ mod ArrayIterator; mod JsFunction; mod JsString; mod Number; +mod Math; #[test] #[cfg(feature = "std")] From 230650055cafb35eff20162f36aab620a15b1eef Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 25 Jun 2018 21:46:01 +0200 Subject: [PATCH 03/12] Add acos to Math --- src/js.rs | 9 +++++++++ tests/all/js_globals/Math.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) 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() From d40a314a91896ce55ca3eb21caadcca017f1c85f Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 25 Jun 2018 21:54:24 +0200 Subject: [PATCH 04/12] Add acosh to Math --- src/js.rs | 8 ++++++++ tests/all/js_globals/Math.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/js.rs b/src/js.rs index cc39d01e..39c7ca9b 100644 --- a/src/js.rs +++ b/src/js.rs @@ -250,6 +250,14 @@ extern { #[wasm_bindgen(static_method_of = Math)] pub fn acos(adjacent: i32, hypotenuse: i32) -> Number; + /// The Math.acosh() function returns the hyperbolic arc-cosine of a + /// number, that is ∀x ≥ 1 + /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh + #[wasm_bindgen(static_method_of = Math)] + pub fn acosh(number: i32) -> Number; + } // Number. diff --git a/tests/all/js_globals/Math.rs b/tests/all/js_globals/Math.rs index beee88bb..b234aaa7 100644 --- a/tests/all/js_globals/Math.rs +++ b/tests/all/js_globals/Math.rs @@ -55,3 +55,30 @@ fn acos() { "#) .test() } + +#[test] +fn acosh() { + 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 acosh(number: i32) -> js::Number { + js::Math::acosh(number) + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.acosh(1), 0); + assert.equal(wasm.acosh(2), Math.acosh(2)); + } + "#) + .test() +} From 94255c1ba952a443942542cd5a8088f13cf4cd22 Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 25 Jun 2018 22:04:59 +0200 Subject: [PATCH 05/12] Add asin to Math --- src/js.rs | 8 ++++++++ tests/all/js_globals/Math.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/js.rs b/src/js.rs index 39c7ca9b..9832a66e 100644 --- a/src/js.rs +++ b/src/js.rs @@ -258,6 +258,14 @@ extern { #[wasm_bindgen(static_method_of = Math)] pub fn acosh(number: i32) -> Number; + /// The Math.asin() function returns the arcsine (in radians) of a + /// number, that is ∀x ∊ [-1;1] + /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin + #[wasm_bindgen(static_method_of = Math)] + pub fn asin(number: i32) -> Number; + } // Number. diff --git a/tests/all/js_globals/Math.rs b/tests/all/js_globals/Math.rs index b234aaa7..7aeca2f5 100644 --- a/tests/all/js_globals/Math.rs +++ b/tests/all/js_globals/Math.rs @@ -82,3 +82,29 @@ fn acosh() { "#) .test() } + +#[test] +fn asin() { + 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 asin(opposite: i32, hypotenuse: i32) -> js::Number { + js::Math::asin(opposite / hypotenuse) + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.asin(1, 1), Math.asin(1)); + } + "#) + .test() +} From 4b812ee47de7dc8586c466047e0a12537d006b51 Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 25 Jun 2018 22:23:24 +0200 Subject: [PATCH 06/12] Add asinh to Math --- src/js.rs | 8 ++++++++ tests/all/js_globals/Math.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/js.rs b/src/js.rs index 9832a66e..5e2cf0f3 100644 --- a/src/js.rs +++ b/src/js.rs @@ -266,6 +266,14 @@ extern { #[wasm_bindgen(static_method_of = Math)] pub fn asin(number: i32) -> Number; + /// The Math.asinh() function returns the hyperbolic arcsine of a + /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh + #[wasm_bindgen(static_method_of = Math)] + pub fn asinh(number: i32) -> Number; + + } // Number. diff --git a/tests/all/js_globals/Math.rs b/tests/all/js_globals/Math.rs index 7aeca2f5..144c91e7 100644 --- a/tests/all/js_globals/Math.rs +++ b/tests/all/js_globals/Math.rs @@ -108,3 +108,29 @@ fn asin() { "#) .test() } + +#[test] +fn asinh() { + 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 asinh(number: i32) -> js::Number { + js::Math::asinh(number) + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.asinh(1), Math.asinh(1)); + } + "#) + .test() +} From 7e514b939fb83c25d04cbf3bd48dcf9a9e633316 Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 25 Jun 2018 22:23:58 +0200 Subject: [PATCH 07/12] Add atan to Math --- src/js.rs | 5 +++++ tests/all/js_globals/Math.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/js.rs b/src/js.rs index 5e2cf0f3..ba11048e 100644 --- a/src/js.rs +++ b/src/js.rs @@ -273,6 +273,11 @@ extern { #[wasm_bindgen(static_method_of = Math)] pub fn asinh(number: i32) -> Number; + /// The Math.atan() function returns the arctangent (in radians) of a + /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that + /// tan(y) = x + #[wasm_bindgen(static_method_of = Math)] + pub fn atan(number: i32) -> Number; } diff --git a/tests/all/js_globals/Math.rs b/tests/all/js_globals/Math.rs index 144c91e7..ec08dde9 100644 --- a/tests/all/js_globals/Math.rs +++ b/tests/all/js_globals/Math.rs @@ -134,3 +134,29 @@ fn asinh() { "#) .test() } + +#[test] +fn atan() { + 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 atan(number: i32) -> js::Number { + js::Math::atan(number) + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.atan(1), Math.atan(1)); + } + "#) + .test() +} From 3223a9af752c9c851eeb8a6955284e10d1973fe1 Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 25 Jun 2018 22:27:55 +0200 Subject: [PATCH 08/12] Add atan2 to Math --- src/js.rs | 7 +++++++ tests/all/js_globals/Math.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/js.rs b/src/js.rs index ba11048e..99d21288 100644 --- a/src/js.rs +++ b/src/js.rs @@ -279,6 +279,13 @@ extern { #[wasm_bindgen(static_method_of = Math)] pub fn atan(number: i32) -> Number; + /// The Math.atan2() function returns the arctangent of the quotient of + /// its arguments. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2 + #[wasm_bindgen(static_method_of = Math)] + pub fn atan2(y: i32, x: i32) -> Number; + } // Number. diff --git a/tests/all/js_globals/Math.rs b/tests/all/js_globals/Math.rs index ec08dde9..9026b158 100644 --- a/tests/all/js_globals/Math.rs +++ b/tests/all/js_globals/Math.rs @@ -160,3 +160,29 @@ fn atan() { "#) .test() } + +#[test] +fn atan2() { + 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 atan2(x: i32, y: i32) -> js::Number { + js::Math::atan2(x, y) + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.atan2(1, 2), Math.atan2(1, 2)); + } + "#) + .test() +} From 5eb744c7d6efa3ecffa18b2768da11f848bb9612 Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 25 Jun 2018 22:32:04 +0200 Subject: [PATCH 09/12] Add atanh to Math --- src/js.rs | 8 ++++++++ tests/all/js_globals/Math.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/js.rs b/src/js.rs index 99d21288..094f80fe 100644 --- a/src/js.rs +++ b/src/js.rs @@ -286,6 +286,14 @@ extern { #[wasm_bindgen(static_method_of = Math)] pub fn atan2(y: i32, x: i32) -> Number; + /// The Math.atanh() function returns the hyperbolic arctangent of a number, + /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that + /// tanh(y) = x + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh + #[wasm_bindgen(static_method_of = Math)] + pub fn atanh(x: i32) -> Number; + } // Number. diff --git a/tests/all/js_globals/Math.rs b/tests/all/js_globals/Math.rs index 9026b158..de520b52 100644 --- a/tests/all/js_globals/Math.rs +++ b/tests/all/js_globals/Math.rs @@ -186,3 +186,29 @@ fn atan2() { "#) .test() } + +#[test] +fn atanh() { + 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 atanh(x: i32) -> js::Number { + js::Math::atanh(x) + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.atanh(1), Math.atanh(1)); + } + "#) + .test() +} From 2de2a815d5d0b5c98b23d393a8a81fc35e0fc5a0 Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 25 Jun 2018 22:35:55 +0200 Subject: [PATCH 10/12] Add cube root (cbrt) to Math --- src/js.rs | 8 ++++++++ tests/all/js_globals/Math.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/js.rs b/src/js.rs index 094f80fe..7dfd72a9 100644 --- a/src/js.rs +++ b/src/js.rs @@ -294,6 +294,14 @@ extern { #[wasm_bindgen(static_method_of = Math)] pub fn atanh(x: i32) -> Number; + + /// The Math.cbrt() function returns the cube root of a number, that is + /// Math.cbrt(x) = x^3 = the unique y such that y^3 = x + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt + #[wasm_bindgen(static_method_of = Math)] + pub fn cbrt(x: i32) -> Number; + } // Number. diff --git a/tests/all/js_globals/Math.rs b/tests/all/js_globals/Math.rs index de520b52..fe55ac40 100644 --- a/tests/all/js_globals/Math.rs +++ b/tests/all/js_globals/Math.rs @@ -212,3 +212,29 @@ fn atanh() { "#) .test() } + +#[test] +fn cbrt() { + 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 cbrt(x: i32) -> js::Number { + js::Math::cbrt(x) + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.cbrt(27), 3); + } + "#) + .test() +} From 9b70f14a1c81207996c34cf1e27f3686a05e43b9 Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 25 Jun 2018 22:41:22 +0200 Subject: [PATCH 11/12] Add ceil to Math --- src/js.rs | 6 ++++++ tests/all/js_globals/Math.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/js.rs b/src/js.rs index 7dfd72a9..3221ebad 100644 --- a/src/js.rs +++ b/src/js.rs @@ -302,6 +302,12 @@ extern { #[wasm_bindgen(static_method_of = Math)] pub fn cbrt(x: i32) -> Number; + /// The Math.ceil() function returns the smallest integer greater than + /// or equal to a given number. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil + #[wasm_bindgen(static_method_of = Math)] + pub fn ceil(x: f32) -> Number; } // Number. diff --git a/tests/all/js_globals/Math.rs b/tests/all/js_globals/Math.rs index fe55ac40..a6907704 100644 --- a/tests/all/js_globals/Math.rs +++ b/tests/all/js_globals/Math.rs @@ -238,3 +238,30 @@ fn cbrt() { "#) .test() } + +#[test] +fn ceil() { + 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 ceil(x: f32) -> js::Number { + js::Math::ceil(x) + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.ceil(1.1), 2); + assert.equal(wasm.ceil(-1.1), -1); + } + "#) + .test() +} From e05b1ae6ba9127b9b6c1869cc83f670c53813b6e Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Mon, 25 Jun 2018 22:47:21 +0200 Subject: [PATCH 12/12] Add clz32 to Math --- src/js.rs | 7 +++++++ tests/all/js_globals/Math.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/js.rs b/src/js.rs index 3221ebad..1dad9a92 100644 --- a/src/js.rs +++ b/src/js.rs @@ -308,6 +308,13 @@ extern { /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil #[wasm_bindgen(static_method_of = Math)] pub fn ceil(x: f32) -> Number; + + /// The Math.clz32() function returns the number of leading zero bits in + /// the 32-bit binary representation of a number. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32 + #[wasm_bindgen(static_method_of = Math)] + pub fn clz32(x: i32) -> Number; } // Number. diff --git a/tests/all/js_globals/Math.rs b/tests/all/js_globals/Math.rs index a6907704..1fbf9502 100644 --- a/tests/all/js_globals/Math.rs +++ b/tests/all/js_globals/Math.rs @@ -265,3 +265,30 @@ fn ceil() { "#) .test() } + +#[test] +fn clz32() { + 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 clz32(x: i32) -> js::Number { + js::Math::clz32(x) + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.clz32(1), 31); + assert.equal(wasm.clz32(1000), 22); + } + "#) + .test() +}