mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-29 13:06:06 +03:00
Add Number.isNaN() binding (#532)
This commit is contained in:
parent
c174262cf0
commit
b7acb0785d
@ -1263,6 +1263,13 @@ extern "C" {
|
||||
#[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
|
||||
pub fn is_integer(value: &JsValue) -> bool;
|
||||
|
||||
/// The Number.isNaN() method determines whether the passed value is NaN and its type is Number.
|
||||
/// It is a more robust version of the original, global isNaN().
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN
|
||||
#[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
|
||||
pub fn is_nan(value: &JsValue) -> bool;
|
||||
|
||||
/// The Number.isSafeInteger() method determines whether the provided value is a number
|
||||
/// that is a safe integer.
|
||||
///
|
||||
|
@ -19,6 +19,24 @@ fn is_integer() {
|
||||
assert!(!Number::is_integer(&42.1.into()));
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn is_nan() {
|
||||
assert!(Number::is_nan(&NAN.into()));
|
||||
|
||||
assert!(!Number::is_nan(&JsValue::TRUE));
|
||||
assert!(!Number::is_nan(&JsValue::NULL));
|
||||
assert!(!Number::is_nan(&37.into()));
|
||||
assert!(!Number::is_nan(&"37".into()));
|
||||
assert!(!Number::is_nan(&"37.37".into()));
|
||||
assert!(!Number::is_nan(&"".into()));
|
||||
assert!(!Number::is_nan(&" ".into()));
|
||||
|
||||
// These would all return true with the global isNaN()
|
||||
assert!(!Number::is_nan(&"NaN".into()));
|
||||
assert!(!Number::is_nan(&JsValue::UNDEFINED));
|
||||
assert!(!Number::is_nan(&"blabla".into()));
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn is_safe_integer() {
|
||||
assert_eq!(Number::is_safe_integer(&42.into()), true);
|
||||
|
Loading…
Reference in New Issue
Block a user