Define is_truthy in terms of is_falsy

This commit is contained in:
Thomas 2019-07-02 19:06:44 +02:00
parent e61f691e0b
commit 0ee7236698
3 changed files with 3 additions and 12 deletions

View File

@ -85,9 +85,6 @@ intrinsics! {
#[symbol = "__wbindgen_is_string"]
#[signature = fn(ref_anyref()) -> Boolean]
IsString,
#[symbol = "__wbindgen_is_truthy"]
#[signature = fn(ref_anyref()) -> Boolean]
IsTruthy,
#[symbol = "__wbindgen_is_falsy"]
#[signature = fn(ref_anyref()) -> Boolean]
IsFalsy,

View File

@ -2299,11 +2299,6 @@ impl<'a> Context<'a> {
format!("typeof({}) === 'string'", args[0])
}
Intrinsic::IsTruthy => {
assert_eq!(args.len(), 1);
format!("!!{}", args[0])
}
Intrinsic::IsFalsy => {
assert_eq!(args.len(), 1);
format!("!{}", args[0])

View File

@ -333,15 +333,15 @@ impl JsValue {
}
/// Tests whether the value is ["truthy"].
///
///
/// ["truthy"]: https://developer.mozilla.org/en-US/docs/Glossary/Truthy
#[inline]
pub fn is_truthy(&self) -> bool {
unsafe { __wbindgen_is_truthy(self.idx) == 1 }
!self.is_falsy()
}
/// Tests whether the value is ["falsy"].
///
///
/// ["falsy"]: https://developer.mozilla.org/en-US/docs/Glossary/Falsy
#[inline]
pub fn is_falsy(&self) -> bool {
@ -518,7 +518,6 @@ externs! {
fn __wbindgen_is_object(idx: u32) -> u32;
fn __wbindgen_is_function(idx: u32) -> u32;
fn __wbindgen_is_string(idx: u32) -> u32;
fn __wbindgen_is_truthy(idx: u32) -> u32;
fn __wbindgen_is_falsy(idx: u32) -> u32;
fn __wbindgen_number_get(idx: u32, invalid: *mut u8) -> f64;