Skip to content

Commit

Permalink
Add #[inline]s
Browse files Browse the repository at this point in the history
  • Loading branch information
Jules-Bertholet committed Jul 20, 2021
1 parent a1da53e commit 02d2b8c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,13 @@ impl JsValue {
///
/// If this JS value is not an instance of a number then this returns
/// `None`.
#[inline]
pub fn as_f64(&self) -> Option<f64> {
unsafe { FromWasmAbi::from_abi(__wbindgen_number_get(self.idx)) }
}

/// Tests whether this JS value is a JS string.
#[inline]
pub fn is_string(&self) -> bool {
unsafe { __wbindgen_is_string(self.idx) == 1 }
}
Expand All @@ -272,6 +274,7 @@ impl JsValue {
///
/// [caveats]: https://rustwasm.github.io/docs/wasm-bindgen/reference/types/str.html
#[cfg(feature = "std")]
#[inline]
pub fn as_string(&self) -> Option<String> {
unsafe { FromWasmAbi::from_abi(__wbindgen_string_get(self.idx)) }
}
Expand All @@ -281,6 +284,7 @@ impl JsValue {
///
/// If this JS value is not an instance of a boolean then this returns
/// `None`.
#[inline]
pub fn as_bool(&self) -> Option<bool> {
unsafe {
match __wbindgen_boolean_get(self.idx) {
Expand Down Expand Up @@ -373,55 +377,63 @@ impl JsValue {
/// Compare two `JsValue`s for equality, using the `==` operator in JS.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality)
#[inline]
pub fn loose_eq(&self, other: &Self) -> bool {
unsafe { __wbindgen_jsval_loose_eq(self.idx, other.idx) != 0 }
}

/// Applies the binary `>>>` JS operator on the two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
#[inline]
pub fn unsigned_shr(self, rhs: &Self) -> u32 {
unsafe { __wbindgen_unsigned_shr(self.idx, rhs.idx) }
}

/// Applies the binary `**` JS operator on the two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
#[inline]
pub fn pow(self, rhs: &Self) -> Self {
unsafe { JsValue::_new(__wbindgen_pow(self.idx, rhs.idx)) }
}

/// Applies the binary `<` JS operator on the two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than)
#[inline]
pub fn lt(&self, other: &Self) -> bool {
unsafe { __wbindgen_lt(self.idx, other.idx) == 1 }
}

/// Applies the binary `<` JS operator on the two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than_or_equal)
#[inline]
pub fn le(&self, other: &Self) -> bool {
unsafe { __wbindgen_le(self.idx, other.idx) == 1 }
}

/// Applies the binary `>=` JS operator on the two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than_or_equal)
#[inline]
pub fn ge(&self, other: &Self) -> bool {
unsafe { __wbindgen_ge(self.idx, other.idx) == 1 }
}

/// Applies the binary `>` JS operator on the two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than)
#[inline]
pub fn gt(&self, other: &Self) -> bool {
unsafe { __wbindgen_gt(self.idx, other.idx) == 1 }
}

/// Applies the unary `+` JS operator on a `JsValue`. Can throw.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus)
#[inline]
pub fn unchecked_into_f64(&self) -> f64 {
unsafe { __wbindgen_as_number(self.idx) }
}
Expand Down Expand Up @@ -537,6 +549,7 @@ impl TryFrom<JsValue> for f64 {
/// Returns the numeric result on success, or the JS error value on error.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus)
#[inline]
fn try_from(val: JsValue) -> Result<Self, Self::Error> {
f64::try_from(&val)
}
Expand All @@ -549,6 +562,7 @@ impl TryFrom<&JsValue> for f64 {
/// Returns the numeric result on success, or the JS error value on error.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus)
#[inline]
fn try_from(val: &JsValue) -> Result<Self, Self::Error> {
let jsval = unsafe { JsValue::_new(__wbindgen_try_into_number(val.idx)) };
return match jsval.as_f64() {
Expand All @@ -564,6 +578,7 @@ impl Neg for &JsValue {
/// Applies the unary `-` JS operator on a `JsValue`.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unary_negation)
#[inline]
fn neg(self) -> Self::Output {
unsafe { JsValue::_new(__wbindgen_neg(self.idx)) }
}
Expand All @@ -577,6 +592,7 @@ impl BitAnd for &JsValue {
/// Applies the binary `&` JS operator on two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND)
#[inline]
fn bitand(self, rhs: Self) -> Self::Output {
unsafe { JsValue::_new(__wbindgen_bit_and(self.idx, rhs.idx)) }
}
Expand All @@ -590,6 +606,7 @@ impl BitOr for &JsValue {
/// Applies the binary `|` JS operator on two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_OR)
#[inline]
fn bitor(self, rhs: Self) -> Self::Output {
unsafe { JsValue::_new(__wbindgen_bit_or(self.idx, rhs.idx)) }
}
Expand All @@ -603,6 +620,7 @@ impl BitXor for &JsValue {
/// Applies the binary `^` JS operator on two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_XOR)
#[inline]
fn bitxor(self, rhs: Self) -> Self::Output {
unsafe { JsValue::_new(__wbindgen_bit_xor(self.idx, rhs.idx)) }
}
Expand All @@ -616,6 +634,7 @@ impl Shl for &JsValue {
/// Applies the binary `<<` JS operator on two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift)
#[inline]
fn shl(self, rhs: Self) -> Self::Output {
unsafe { JsValue::_new(__wbindgen_shl(self.idx, rhs.idx)) }
}
Expand All @@ -629,6 +648,7 @@ impl Shr for &JsValue {
/// Applies the binary `>>` JS operator on two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Right_shift)
#[inline]
fn shr(self, rhs: Self) -> Self::Output {
unsafe { JsValue::_new(__wbindgen_shr(self.idx, rhs.idx)) }
}
Expand All @@ -642,6 +662,7 @@ impl Add for &JsValue {
/// Applies the binary `+` JS operator on two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition)
#[inline]
fn add(self, rhs: Self) -> Self::Output {
unsafe { JsValue::_new(__wbindgen_add(self.idx, rhs.idx)) }
}
Expand All @@ -655,6 +676,7 @@ impl Sub for &JsValue {
/// Applies the binary `-` JS operator on two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Subtraction)
#[inline]
fn sub(self, rhs: Self) -> Self::Output {
unsafe { JsValue::_new(__wbindgen_sub(self.idx, rhs.idx)) }
}
Expand All @@ -668,6 +690,7 @@ impl Div for &JsValue {
/// Applies the binary `/` JS operator on two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division)
#[inline]
fn div(self, rhs: Self) -> Self::Output {
unsafe { JsValue::_new(__wbindgen_div(self.idx, rhs.idx)) }
}
Expand All @@ -681,6 +704,7 @@ impl Mul for &JsValue {
/// Applies the binary `*` JS operator on two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Multiplication)
#[inline]
fn mul(self, rhs: Self) -> Self::Output {
unsafe { JsValue::_new(__wbindgen_mul(self.idx, rhs.idx)) }
}
Expand All @@ -694,6 +718,7 @@ impl Rem for &JsValue {
/// Applies the binary `%` JS operator on two `JsValue`s.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder)
#[inline]
fn rem(self, rhs: Self) -> Self::Output {
unsafe { JsValue::_new(__wbindgen_rem(self.idx, rhs.idx)) }
}
Expand Down

0 comments on commit 02d2b8c

Please sign in to comment.