Skip to content

Commit 3212b0a

Browse files
authored
Merge pull request #312 from jonathan-s/moar-methods
Lots of methods for Math
2 parents 02328cf + e05b1ae commit 3212b0a

File tree

3 files changed

+419
-32
lines changed

3 files changed

+419
-32
lines changed

src/js.rs

Lines changed: 124 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ extern {
7070
extern {
7171
pub type Array;
7272

73-
/// The copyWithin() method shallow copies part of an array to another location in the same
74-
/// array and returns it, without modifying its size.
73+
/// The copyWithin() method shallow copies part of an array to another
74+
/// location in the same array and returns it, without modifying its size.
7575
///
7676
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin
7777
#[wasm_bindgen(method, js_name = copyWithin)]
@@ -84,29 +84,31 @@ extern {
8484
#[wasm_bindgen(method)]
8585
pub fn concat(this: &Array, array: &Array) -> Array;
8686

87-
/// The fill() method fills all the elements of an array from a start index to an
88-
/// end index with a static value. The end index is not included.
87+
/// The fill() method fills all the elements of an array from a start index
88+
/// to an end index with a static value. The end index is not included.
8989
///
9090
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill
9191
#[wasm_bindgen(method)]
9292
pub fn fill(this: &Array, value: JsValue, start: u32, end: u32) -> Array;
9393

94-
/// The length property of an object which is an instance of type Array sets or returns the number of elements in that array.
95-
/// The value is an unsigned, 32-bit integer that is always numerically greater than the highest index in the array.
94+
/// The length property of an object which is an instance of type Array
95+
/// sets or returns the number of elements in that array. The value is an
96+
/// unsigned, 32-bit integer that is always numerically greater than the
97+
/// highest index in the array.
9698
///
9799
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length
98100
#[wasm_bindgen(method, getter, structural)]
99101
pub fn length(this: &Array) -> u32;
100102

101-
/// The indexOf() method returns the first index at which a given element can be
102-
/// found in the array, or -1 if it is not present.
103+
/// The indexOf() method returns the first index at which a given element
104+
/// can be found in the array, or -1 if it is not present.
103105
///
104106
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
105107
#[wasm_bindgen(method, js_name = indexOf)]
106108
pub fn index_of(this: &Array, value: JsValue, from_index: i32) -> i32;
107109

108-
/// The includes() method determines whether an array includes a certain element,
109-
/// returning true or false as appropriate.
110+
/// The includes() method determines whether an array includes a certain
111+
/// element, returning true or false as appropriate.
110112
///
111113
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
112114
#[wasm_bindgen(method)]
@@ -119,45 +121,45 @@ extern {
119121
#[wasm_bindgen(method)]
120122
pub fn join(this: &Array, delimiter: &str) -> JsString;
121123

122-
/// The lastIndexOf() method returns the last index at which a given element can
123-
/// be found in the array, or -1 if it is not present. The array is searched
124-
/// backwards, starting at fromIndex.
124+
/// The lastIndexOf() method returns the last index at which a given element
125+
/// can be found in the array, or -1 if it is not present. The array is
126+
/// searched backwards, starting at fromIndex.
125127
///
126128
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf
127129
#[wasm_bindgen(method, js_name = lastIndexOf)]
128130
pub fn last_index_of(this: &Array, value: JsValue, from_index: i32) -> i32;
129131

130-
/// The pop() method removes the last element from an array and returns that element.
131-
/// This method changes the length of the array.
132+
/// The pop() method removes the last element from an array and returns that
133+
/// element. This method changes the length of the array.
132134
///
133135
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop
134136
#[wasm_bindgen(method)]
135137
pub fn pop(this: &Array) -> JsValue;
136138

137-
/// The push() method adds one or more elements to the end of an array and returns
138-
/// the new length of the array.
139+
/// The push() method adds one or more elements to the end of an array and
140+
/// returns the new length of the array.
139141
///
140142
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push
141143
#[wasm_bindgen(method)]
142144
pub fn push(this: &Array, value: JsValue) -> u32;
143145

144-
/// The reverse() method reverses an array in place.
145-
/// The first array element becomes the last, and the last array element becomes the first.
146+
/// The reverse() method reverses an array in place. The first array
147+
/// element becomes the last, and the last array element becomes the first.
146148
///
147149
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse
148150
#[wasm_bindgen(method)]
149151
pub fn reverse(this: &Array) -> Array;
150152

151-
/// The slice() method returns a shallow copy of a portion of an array into a new array
152-
/// object selected from begin to end (end not included).
153+
/// The slice() method returns a shallow copy of a portion of an array into
154+
/// a new array object selected from begin to end (end not included).
153155
/// The original array will not be modified.
154156
///
155157
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
156158
#[wasm_bindgen(method)]
157159
pub fn slice(this: &Array, start: u32, end: u32) -> Array;
158160

159-
/// The shift() method removes the first element from an array and returns that removed element.
160-
/// This method changes the length of the array.
161+
/// The shift() method removes the first element from an array and returns
162+
/// that removed element. This method changes the length of the array.
161163
///
162164
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift
163165
#[wasm_bindgen(method)]
@@ -174,14 +176,15 @@ extern {
174176
#[wasm_bindgen(method)]
175177
pub fn sort(this: &Array) -> Array;
176178

177-
/// The toString() method returns a string representing the specified array and its elements.
179+
/// The toString() method returns a string representing the specified array
180+
/// and its elements.
178181
///
179182
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString
180183
#[wasm_bindgen(method, js_name = toString)]
181184
pub fn to_string(this: &Array) -> JsString;
182185

183-
/// The unshift() method adds one or more elements to the beginning of an array
184-
/// and returns the new length of the array.
186+
/// The unshift() method adds one or more elements to the beginning of an
187+
/// array and returns the new length of the array.
185188
///
186189
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift
187190
#[wasm_bindgen(method)]
@@ -193,13 +196,15 @@ extern {
193196
extern {
194197
pub type ArrayIterator;
195198

196-
/// The keys() method returns a new Array Iterator object that contains the keys for each index in the array.
199+
/// The keys() method returns a new Array Iterator object that contains the
200+
/// keys for each index in the array.
197201
///
198202
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys
199203
#[wasm_bindgen(method)]
200204
pub fn keys(this: &Array) -> ArrayIterator;
201205

202-
/// The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array.
206+
/// The entries() method returns a new Array Iterator object that contains
207+
/// the key/value pairs for each index in the array.
203208
///
204209
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries
205210
#[wasm_bindgen(method)]
@@ -217,14 +222,101 @@ extern {
217222
#[wasm_bindgen(method, getter, structural)]
218223
pub fn length(this: &JsFunction) -> u32;
219224

220-
/// A Function object's read-only name property indicates the function's name as specified when it was created
221-
/// or "anonymous" for functions created anonymously.
225+
/// A Function object's read-only name property indicates the function's
226+
/// name as specified when it was created or "anonymous" for functions
227+
/// created anonymously.
222228
///
223229
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
224230
#[wasm_bindgen(method, getter, structural)]
225231
pub fn name(this: &JsFunction) -> JsString;
226232
}
227233

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+
/// The Math.acos() function returns the arccosine (in radians) of a
246+
/// number, that is ∀x∊[-1;1]
247+
/// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
248+
///
249+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos
250+
#[wasm_bindgen(static_method_of = Math)]
251+
pub fn acos(adjacent: i32, hypotenuse: i32) -> Number;
252+
253+
/// The Math.acosh() function returns the hyperbolic arc-cosine of a
254+
/// number, that is ∀x ≥ 1
255+
/// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
256+
///
257+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh
258+
#[wasm_bindgen(static_method_of = Math)]
259+
pub fn acosh(number: i32) -> Number;
260+
261+
/// The Math.asin() function returns the arcsine (in radians) of a
262+
/// number, that is ∀x ∊ [-1;1]
263+
/// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
264+
///
265+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin
266+
#[wasm_bindgen(static_method_of = Math)]
267+
pub fn asin(number: i32) -> Number;
268+
269+
/// The Math.asinh() function returns the hyperbolic arcsine of a
270+
/// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
271+
///
272+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh
273+
#[wasm_bindgen(static_method_of = Math)]
274+
pub fn asinh(number: i32) -> Number;
275+
276+
/// The Math.atan() function returns the arctangent (in radians) of a
277+
/// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
278+
/// tan(y) = x
279+
#[wasm_bindgen(static_method_of = Math)]
280+
pub fn atan(number: i32) -> Number;
281+
282+
/// The Math.atan2() function returns the arctangent of the quotient of
283+
/// its arguments.
284+
///
285+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2
286+
#[wasm_bindgen(static_method_of = Math)]
287+
pub fn atan2(y: i32, x: i32) -> Number;
288+
289+
/// The Math.atanh() function returns the hyperbolic arctangent of a number,
290+
/// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
291+
/// tanh(y) = x
292+
///
293+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh
294+
#[wasm_bindgen(static_method_of = Math)]
295+
pub fn atanh(x: i32) -> Number;
296+
297+
298+
/// The Math.cbrt() function returns the cube root of a number, that is
299+
/// Math.cbrt(x) = x^3 = the unique y such that y^3 = x
300+
///
301+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt
302+
#[wasm_bindgen(static_method_of = Math)]
303+
pub fn cbrt(x: i32) -> Number;
304+
305+
/// The Math.ceil() function returns the smallest integer greater than
306+
/// or equal to a given number.
307+
///
308+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil
309+
#[wasm_bindgen(static_method_of = Math)]
310+
pub fn ceil(x: f32) -> Number;
311+
312+
/// The Math.clz32() function returns the number of leading zero bits in
313+
/// the 32-bit binary representation of a number.
314+
///
315+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
316+
#[wasm_bindgen(static_method_of = Math)]
317+
pub fn clz32(x: i32) -> Number;
318+
}
319+
228320
// Number.
229321
#[wasm_bindgen]
230322
extern {
@@ -314,8 +406,8 @@ extern {
314406
pub fn property_is_enumerable(this: &Object, property: &JsValue) -> bool;
315407

316408
/// The toLocaleString() method returns a string representing the object.
317-
/// This method is meant to be overridden by derived objects for locale-specific
318-
/// purposes.
409+
/// This method is meant to be overridden by derived objects for
410+
/// locale-specific purposes.
319411
///
320412
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString
321413
#[wasm_bindgen(method, js_name = toLocaleString)]

0 commit comments

Comments
 (0)