#![no_std]
#![cfg_attr(wasm_bindgen_unstable_test_coverage, feature(coverage_attribute))]
#![cfg_attr(target_feature = "atomics", feature(thread_local))]
#![cfg_attr(
any(target_feature = "atomics", wasm_bindgen_unstable_test_coverage),
feature(allow_internal_unstable),
allow(internal_features)
)]
#![doc(html_root_url = "https://docs.rs/wasm-bindgen/0.2")]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
use crate::convert::{TryFromJsValue, UpcastFrom, VectorIntoWasmAbi};
use crate::sys::Promising;
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use core::convert::TryFrom;
use core::marker::PhantomData;
use core::ops::{
Add, BitAnd, BitOr, BitXor, Deref, DerefMut, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub,
};
use core::ptr::NonNull;
const _: () = {
#[no_mangle]
pub extern "C" fn __wbindgen_skip_interpret_calls() {}
};
macro_rules! externs {
($(#[$attr:meta])* extern "C" { $(fn $name:ident($($args:tt)*) -> $ret:ty;)* }) => (
#[cfg(target_family = "wasm")]
$(#[$attr])*
extern "C" {
$(fn $name($($args)*) -> $ret;)*
}
$(
#[cfg(not(target_family = "wasm"))]
#[allow(unused_variables)]
unsafe extern "C" fn $name($($args)*) -> $ret {
panic!("function not implemented on non-wasm32 targets")
}
)*
)
}
pub mod prelude {
pub use crate::closure::{Closure, ScopedClosure};
pub use crate::convert::Upcast; pub use crate::JsCast;
pub use crate::JsValue;
pub use crate::UnwrapThrowExt;
#[doc(hidden)]
pub use wasm_bindgen_macro::__wasm_bindgen_class_marker;
pub use wasm_bindgen_macro::wasm_bindgen;
pub use crate::JsError;
}
pub use wasm_bindgen_macro::link_to;
pub mod closure;
pub mod convert;
pub mod describe;
mod link;
pub mod sys;
#[cfg(wbg_reference_types)]
mod externref;
#[cfg(wbg_reference_types)]
use externref::__wbindgen_externref_heap_live_count;
pub use crate::__rt::marker::ErasableGeneric;
pub use crate::convert::JsGeneric;
#[doc(hidden)]
pub mod handler;
mod cast;
pub use crate::cast::JsCast;
mod cache;
pub use cache::intern::{intern, unintern};
#[doc(hidden)]
#[path = "rt/mod.rs"]
pub mod __rt;
use __rt::wbg_cast;
pub struct JsValue {
idx: u32,
_marker: PhantomData<*mut u8>, }
#[cfg(not(target_feature = "atomics"))]
unsafe impl Send for JsValue {}
#[cfg(not(target_feature = "atomics"))]
unsafe impl Sync for JsValue {}
unsafe impl ErasableGeneric for JsValue {
type Repr = JsValue;
}
impl Promising for JsValue {
type Resolution = JsValue;
}
impl JsValue {
pub const NULL: JsValue = JsValue::_new(__rt::JSIDX_NULL);
pub const UNDEFINED: JsValue = JsValue::_new(__rt::JSIDX_UNDEFINED);
pub const TRUE: JsValue = JsValue::_new(__rt::JSIDX_TRUE);
pub const FALSE: JsValue = JsValue::_new(__rt::JSIDX_FALSE);
#[inline]
const fn _new(idx: u32) -> JsValue {
JsValue {
idx,
_marker: PhantomData,
}
}
#[allow(clippy::should_implement_trait)] #[inline]
pub fn from_str(s: &str) -> JsValue {
wbg_cast(s)
}
#[inline]
pub fn from_f64(n: f64) -> JsValue {
wbg_cast(n)
}
#[inline]
pub fn bigint_from_str(s: &str) -> JsValue {
__wbindgen_bigint_from_str(s)
}
#[inline]
pub const fn from_bool(b: bool) -> JsValue {
if b {
JsValue::TRUE
} else {
JsValue::FALSE
}
}
#[inline]
pub const fn undefined() -> JsValue {
JsValue::UNDEFINED
}
#[inline]
pub const fn null() -> JsValue {
JsValue::NULL
}
pub fn symbol(description: Option<&str>) -> JsValue {
__wbindgen_symbol_new(description)
}
#[cfg(feature = "serde-serialize")]
#[deprecated = "causes dependency cycles, use `serde-wasm-bindgen` or `gloo_utils::format::JsValueSerdeExt` instead"]
pub fn from_serde<T>(t: &T) -> serde_json::Result<JsValue>
where
T: serde::ser::Serialize + ?Sized,
{
let s = serde_json::to_string(t)?;
Ok(__wbindgen_json_parse(s))
}
#[cfg(feature = "serde-serialize")]
#[deprecated = "causes dependency cycles, use `serde-wasm-bindgen` or `gloo_utils::format::JsValueSerdeExt` instead"]
pub fn into_serde<T>(&self) -> serde_json::Result<T>
where
T: for<'a> serde::de::Deserialize<'a>,
{
let s = __wbindgen_json_serialize(self);
serde_json::from_str(s.as_deref().unwrap_or("null"))
}
#[inline]
pub fn as_f64(&self) -> Option<f64> {
__wbindgen_number_get(self)
}
#[inline]
pub fn is_string(&self) -> bool {
__wbindgen_is_string(self)
}
#[inline]
pub fn as_string(&self) -> Option<String> {
__wbindgen_string_get(self)
}
#[inline]
pub fn as_bool(&self) -> Option<bool> {
__wbindgen_boolean_get(self)
}
#[inline]
pub fn is_null(&self) -> bool {
__wbindgen_is_null(self)
}
#[inline]
pub fn is_undefined(&self) -> bool {
__wbindgen_is_undefined(self)
}
#[inline]
pub fn is_null_or_undefined(&self) -> bool {
__wbindgen_is_null_or_undefined(self)
}
#[inline]
pub fn is_symbol(&self) -> bool {
__wbindgen_is_symbol(self)
}
#[inline]
pub fn is_object(&self) -> bool {
__wbindgen_is_object(self)
}
#[inline]
pub fn is_array(&self) -> bool {
__wbindgen_is_array(self)
}
#[inline]
pub fn is_function(&self) -> bool {
__wbindgen_is_function(self)
}
#[inline]
pub fn is_bigint(&self) -> bool {
__wbindgen_is_bigint(self)
}
#[inline]
pub fn js_typeof(&self) -> JsValue {
__wbindgen_typeof(self)
}
#[inline]
pub fn js_in(&self, obj: &JsValue) -> bool {
__wbindgen_in(self, obj)
}
#[inline]
pub fn is_truthy(&self) -> bool {
!self.is_falsy()
}
#[inline]
pub fn is_falsy(&self) -> bool {
__wbindgen_is_falsy(self)
}
fn as_debug_string(&self) -> String {
__wbindgen_debug_string(self)
}
#[inline]
pub fn loose_eq(&self, other: &Self) -> bool {
__wbindgen_jsval_loose_eq(self, other)
}
#[inline]
pub fn bit_not(&self) -> JsValue {
__wbindgen_bit_not(self)
}
#[inline]
pub fn unsigned_shr(&self, rhs: &Self) -> u32 {
__wbindgen_unsigned_shr(self, rhs)
}
#[inline]
pub fn checked_div(&self, rhs: &Self) -> Self {
__wbindgen_checked_div(self, rhs)
}
#[inline]
pub fn pow(&self, rhs: &Self) -> Self {
__wbindgen_pow(self, rhs)
}
#[inline]
pub fn lt(&self, other: &Self) -> bool {
__wbindgen_lt(self, other)
}
#[inline]
pub fn le(&self, other: &Self) -> bool {
__wbindgen_le(self, other)
}
#[inline]
pub fn ge(&self, other: &Self) -> bool {
__wbindgen_ge(self, other)
}
#[inline]
pub fn gt(&self, other: &Self) -> bool {
__wbindgen_gt(self, other)
}
#[inline]
pub fn unchecked_into_f64(&self) -> f64 {
__wbindgen_as_number(self)
}
}
impl PartialEq for JsValue {
#[inline]
fn eq(&self, other: &Self) -> bool {
__wbindgen_jsval_eq(self, other)
}
}
impl PartialEq<bool> for JsValue {
#[inline]
fn eq(&self, other: &bool) -> bool {
self.as_bool() == Some(*other)
}
}
impl PartialEq<str> for JsValue {
#[inline]
fn eq(&self, other: &str) -> bool {
*self == JsValue::from_str(other)
}
}
impl<'a> PartialEq<&'a str> for JsValue {
#[inline]
fn eq(&self, other: &&'a str) -> bool {
<JsValue as PartialEq<str>>::eq(self, other)
}
}
impl PartialEq<String> for JsValue {
#[inline]
fn eq(&self, other: &String) -> bool {
<JsValue as PartialEq<str>>::eq(self, other)
}
}
impl<'a> PartialEq<&'a String> for JsValue {
#[inline]
fn eq(&self, other: &&'a String) -> bool {
<JsValue as PartialEq<str>>::eq(self, other)
}
}
macro_rules! forward_deref_unop {
(impl $imp:ident, $method:ident for $t:ty) => {
impl $imp for $t {
type Output = <&'static $t as $imp>::Output;
#[inline]
fn $method(self) -> <&'static $t as $imp>::Output {
$imp::$method(&self)
}
}
};
}
macro_rules! forward_deref_binop {
(impl $imp:ident, $method:ident for $t:ty) => {
impl<'a> $imp<$t> for &'a $t {
type Output = <&'static $t as $imp<&'static $t>>::Output;
#[inline]
fn $method(self, other: $t) -> <&'static $t as $imp<&'static $t>>::Output {
$imp::$method(self, &other)
}
}
impl $imp<&$t> for $t {
type Output = <&'static $t as $imp<&'static $t>>::Output;
#[inline]
fn $method(self, other: &$t) -> <&'static $t as $imp<&'static $t>>::Output {
$imp::$method(&self, other)
}
}
impl $imp<$t> for $t {
type Output = <&'static $t as $imp<&'static $t>>::Output;
#[inline]
fn $method(self, other: $t) -> <&'static $t as $imp<&'static $t>>::Output {
$imp::$method(&self, &other)
}
}
};
}
impl Not for &JsValue {
type Output = bool;
#[inline]
fn not(self) -> Self::Output {
JsValue::is_falsy(self)
}
}
forward_deref_unop!(impl Not, not for JsValue);
impl TryFrom<JsValue> for f64 {
type Error = JsValue;
#[inline]
fn try_from(val: JsValue) -> Result<Self, Self::Error> {
f64::try_from(&val)
}
}
impl TryFrom<&JsValue> for f64 {
type Error = JsValue;
#[inline]
fn try_from(val: &JsValue) -> Result<Self, Self::Error> {
let jsval = __wbindgen_try_into_number(val);
match jsval.as_f64() {
Some(num) => Ok(num),
None => Err(jsval),
}
}
}
impl Neg for &JsValue {
type Output = JsValue;
#[inline]
fn neg(self) -> Self::Output {
__wbindgen_neg(self)
}
}
forward_deref_unop!(impl Neg, neg for JsValue);
impl BitAnd for &JsValue {
type Output = JsValue;
#[inline]
fn bitand(self, rhs: Self) -> Self::Output {
__wbindgen_bit_and(self, rhs)
}
}
forward_deref_binop!(impl BitAnd, bitand for JsValue);
impl BitOr for &JsValue {
type Output = JsValue;
#[inline]
fn bitor(self, rhs: Self) -> Self::Output {
__wbindgen_bit_or(self, rhs)
}
}
forward_deref_binop!(impl BitOr, bitor for JsValue);
impl BitXor for &JsValue {
type Output = JsValue;
#[inline]
fn bitxor(self, rhs: Self) -> Self::Output {
__wbindgen_bit_xor(self, rhs)
}
}
forward_deref_binop!(impl BitXor, bitxor for JsValue);
impl Shl for &JsValue {
type Output = JsValue;
#[inline]
fn shl(self, rhs: Self) -> Self::Output {
__wbindgen_shl(self, rhs)
}
}
forward_deref_binop!(impl Shl, shl for JsValue);
impl Shr for &JsValue {
type Output = JsValue;
#[inline]
fn shr(self, rhs: Self) -> Self::Output {
__wbindgen_shr(self, rhs)
}
}
forward_deref_binop!(impl Shr, shr for JsValue);
impl Add for &JsValue {
type Output = JsValue;
#[inline]
fn add(self, rhs: Self) -> Self::Output {
__wbindgen_add(self, rhs)
}
}
forward_deref_binop!(impl Add, add for JsValue);
impl Sub for &JsValue {
type Output = JsValue;
#[inline]
fn sub(self, rhs: Self) -> Self::Output {
__wbindgen_sub(self, rhs)
}
}
forward_deref_binop!(impl Sub, sub for JsValue);
impl Div for &JsValue {
type Output = JsValue;
#[inline]
fn div(self, rhs: Self) -> Self::Output {
__wbindgen_div(self, rhs)
}
}
forward_deref_binop!(impl Div, div for JsValue);
impl Mul for &JsValue {
type Output = JsValue;
#[inline]
fn mul(self, rhs: Self) -> Self::Output {
__wbindgen_mul(self, rhs)
}
}
forward_deref_binop!(impl Mul, mul for JsValue);
impl Rem for &JsValue {
type Output = JsValue;
#[inline]
fn rem(self, rhs: Self) -> Self::Output {
__wbindgen_rem(self, rhs)
}
}
forward_deref_binop!(impl Rem, rem for JsValue);
impl<'a> From<&'a str> for JsValue {
#[inline]
fn from(s: &'a str) -> JsValue {
JsValue::from_str(s)
}
}
impl<T> From<*mut T> for JsValue {
#[inline]
fn from(s: *mut T) -> JsValue {
JsValue::from(s as usize)
}
}
impl<T> From<*const T> for JsValue {
#[inline]
fn from(s: *const T) -> JsValue {
JsValue::from(s as usize)
}
}
impl<T> From<NonNull<T>> for JsValue {
#[inline]
fn from(s: NonNull<T>) -> JsValue {
JsValue::from(s.as_ptr() as usize)
}
}
impl<'a> From<&'a String> for JsValue {
#[inline]
fn from(s: &'a String) -> JsValue {
JsValue::from_str(s)
}
}
impl From<String> for JsValue {
#[inline]
fn from(s: String) -> JsValue {
JsValue::from_str(&s)
}
}
impl TryFrom<JsValue> for String {
type Error = JsValue;
fn try_from(value: JsValue) -> Result<Self, Self::Error> {
match value.as_string() {
Some(s) => Ok(s),
None => Err(value),
}
}
}
impl TryFromJsValue for String {
fn try_from_js_value_ref(value: &JsValue) -> Option<Self> {
value.as_string()
}
}
impl From<bool> for JsValue {
#[inline]
fn from(s: bool) -> JsValue {
JsValue::from_bool(s)
}
}
impl TryFromJsValue for bool {
fn try_from_js_value_ref(value: &JsValue) -> Option<Self> {
value.as_bool()
}
}
impl TryFromJsValue for char {
fn try_from_js_value_ref(value: &JsValue) -> Option<Self> {
let s = value.as_string()?;
if s.len() == 1 {
Some(s.chars().nth(0).unwrap())
} else {
None
}
}
}
impl<'a, T> From<&'a T> for JsValue
where
T: JsCast,
{
#[inline]
fn from(s: &'a T) -> JsValue {
s.as_ref().clone()
}
}
impl<T> From<Option<T>> for JsValue
where
JsValue: From<T>,
{
#[inline]
fn from(s: Option<T>) -> JsValue {
match s {
Some(s) => s.into(),
None => JsValue::undefined(),
}
}
}
impl JsCast for JsValue {
#[inline]
fn instanceof(_val: &JsValue) -> bool {
true
}
#[inline]
fn unchecked_from_js(val: JsValue) -> Self {
val
}
#[inline]
fn unchecked_from_js_ref(val: &JsValue) -> &Self {
val
}
}
impl AsRef<JsValue> for JsValue {
#[inline]
fn as_ref(&self) -> &JsValue {
self
}
}
impl UpcastFrom<JsValue> for JsValue {}
fn to_uint_32(v: &JsValue) -> Option<u32> {
v.as_f64().map(|n| {
if n.is_infinite() {
0
} else {
(n as i64) as u32
}
})
}
macro_rules! integers {
($($n:ident)*) => ($(
impl PartialEq<$n> for JsValue {
#[inline]
fn eq(&self, other: &$n) -> bool {
self.as_f64() == Some(f64::from(*other))
}
}
impl From<$n> for JsValue {
#[inline]
fn from(n: $n) -> JsValue {
JsValue::from_f64(n.into())
}
}
impl TryFromJsValue for $n {
#[inline]
fn try_from_js_value_ref(val: &JsValue) -> Option<$n> {
to_uint_32(val).map(|n| n as $n)
}
}
)*)
}
integers! { i8 u8 i16 u16 i32 u32 }
macro_rules! floats {
($($n:ident)*) => ($(
impl PartialEq<$n> for JsValue {
#[inline]
fn eq(&self, other: &$n) -> bool {
self.as_f64() == Some(f64::from(*other))
}
}
impl From<$n> for JsValue {
#[inline]
fn from(n: $n) -> JsValue {
JsValue::from_f64(n.into())
}
}
impl TryFromJsValue for $n {
#[inline]
fn try_from_js_value_ref(val: &JsValue) -> Option<$n> {
val.as_f64().map(|n| n as $n)
}
}
)*)
}
floats! { f32 f64 }
macro_rules! big_integers {
($($n:ident)*) => ($(
impl PartialEq<$n> for JsValue {
#[inline]
fn eq(&self, other: &$n) -> bool {
self == &JsValue::from(*other)
}
}
impl From<$n> for JsValue {
#[inline]
fn from(arg: $n) -> JsValue {
wbg_cast(arg)
}
}
impl TryFrom<JsValue> for $n {
type Error = JsValue;
#[inline]
fn try_from(v: JsValue) -> Result<Self, JsValue> {
Self::try_from_js_value(v)
}
}
impl TryFromJsValue for $n {
#[inline]
fn try_from_js_value_ref(val: &JsValue) -> Option<$n> {
let as_i64 = __wbindgen_bigint_get_as_i64(&val)?;
let as_self = as_i64 as $n;
if val == &as_self {
Some(as_self)
} else {
None
}
}
}
)*)
}
big_integers! { i64 u64 }
macro_rules! num128 {
($ty:ty, $hi_ty:ty) => {
impl PartialEq<$ty> for JsValue {
#[inline]
fn eq(&self, other: &$ty) -> bool {
self == &JsValue::from(*other)
}
}
impl From<$ty> for JsValue {
#[inline]
fn from(arg: $ty) -> JsValue {
wbg_cast(arg)
}
}
impl TryFrom<JsValue> for $ty {
type Error = JsValue;
#[inline]
fn try_from(v: JsValue) -> Result<Self, JsValue> {
Self::try_from_js_value(v)
}
}
impl TryFromJsValue for $ty {
fn try_from_js_value_ref(v: &JsValue) -> Option<$ty> {
let lo = __wbindgen_bigint_get_as_i64(&v)? as u64;
let hi = v >> JsValue::from(64_u64);
<$hi_ty>::try_from_js_value_ref(&hi).map(|hi| Self::from(hi) << 64 | Self::from(lo))
}
}
};
}
num128!(i128, i64);
num128!(u128, u64);
impl TryFromJsValue for () {
fn try_from_js_value_ref(value: &JsValue) -> Option<Self> {
if value.is_undefined() {
Some(())
} else {
None
}
}
}
impl<T: TryFromJsValue> TryFromJsValue for Option<T> {
fn try_from_js_value_ref(value: &JsValue) -> Option<Self> {
if value.is_undefined() {
Some(None)
} else {
T::try_from_js_value_ref(value).map(Some)
}
}
}
impl PartialEq<usize> for JsValue {
#[inline]
fn eq(&self, other: &usize) -> bool {
*self == (*other as u32)
}
}
impl From<usize> for JsValue {
#[inline]
fn from(n: usize) -> Self {
Self::from(n as u32)
}
}
impl PartialEq<isize> for JsValue {
#[inline]
fn eq(&self, other: &isize) -> bool {
*self == (*other as i32)
}
}
impl From<isize> for JsValue {
#[inline]
fn from(n: isize) -> Self {
Self::from(n as i32)
}
}
impl TryFromJsValue for isize {
#[inline]
fn try_from_js_value_ref(val: &JsValue) -> Option<isize> {
val.as_f64().map(|n| n as isize)
}
}
impl TryFromJsValue for usize {
#[inline]
fn try_from_js_value_ref(val: &JsValue) -> Option<usize> {
val.as_f64().map(|n| n as usize)
}
}
#[wasm_bindgen_macro::wasm_bindgen(wasm_bindgen = crate)]
extern "C" {
#[wasm_bindgen(js_namespace = Array, js_name = isArray)]
fn __wbindgen_is_array(v: &JsValue) -> bool;
#[wasm_bindgen(js_name = BigInt)]
fn __wbindgen_bigint_from_str(s: &str) -> JsValue;
#[wasm_bindgen(js_name = Symbol)]
fn __wbindgen_symbol_new(description: Option<&str>) -> JsValue;
#[wasm_bindgen(js_name = Error)]
fn __wbindgen_error_new(msg: &str) -> JsValue;
#[wasm_bindgen(js_namespace = JSON, js_name = parse)]
fn __wbindgen_json_parse(json: String) -> JsValue;
#[wasm_bindgen(js_namespace = JSON, js_name = stringify)]
fn __wbindgen_json_serialize(v: &JsValue) -> Option<String>;
#[wasm_bindgen(js_name = Number)]
fn __wbindgen_as_number(v: &JsValue) -> f64;
}
#[wasm_bindgen_macro::wasm_bindgen(wasm_bindgen = crate, raw_module = "__wbindgen_placeholder__")]
extern "C" {
#[cfg(not(wbg_reference_types))]
fn __wbindgen_externref_heap_live_count() -> u32;
fn __wbindgen_is_null(js: &JsValue) -> bool;
fn __wbindgen_is_undefined(js: &JsValue) -> bool;
fn __wbindgen_is_null_or_undefined(js: &JsValue) -> bool;
fn __wbindgen_is_symbol(js: &JsValue) -> bool;
fn __wbindgen_is_object(js: &JsValue) -> bool;
fn __wbindgen_is_function(js: &JsValue) -> bool;
fn __wbindgen_is_string(js: &JsValue) -> bool;
fn __wbindgen_is_bigint(js: &JsValue) -> bool;
fn __wbindgen_typeof(js: &JsValue) -> JsValue;
fn __wbindgen_in(prop: &JsValue, obj: &JsValue) -> bool;
fn __wbindgen_is_falsy(js: &JsValue) -> bool;
fn __wbindgen_try_into_number(js: &JsValue) -> JsValue;
fn __wbindgen_neg(js: &JsValue) -> JsValue;
fn __wbindgen_bit_and(a: &JsValue, b: &JsValue) -> JsValue;
fn __wbindgen_bit_or(a: &JsValue, b: &JsValue) -> JsValue;
fn __wbindgen_bit_xor(a: &JsValue, b: &JsValue) -> JsValue;
fn __wbindgen_bit_not(js: &JsValue) -> JsValue;
fn __wbindgen_shl(a: &JsValue, b: &JsValue) -> JsValue;
fn __wbindgen_shr(a: &JsValue, b: &JsValue) -> JsValue;
fn __wbindgen_unsigned_shr(a: &JsValue, b: &JsValue) -> u32;
fn __wbindgen_add(a: &JsValue, b: &JsValue) -> JsValue;
fn __wbindgen_sub(a: &JsValue, b: &JsValue) -> JsValue;
fn __wbindgen_div(a: &JsValue, b: &JsValue) -> JsValue;
fn __wbindgen_checked_div(a: &JsValue, b: &JsValue) -> JsValue;
fn __wbindgen_mul(a: &JsValue, b: &JsValue) -> JsValue;
fn __wbindgen_rem(a: &JsValue, b: &JsValue) -> JsValue;
fn __wbindgen_pow(a: &JsValue, b: &JsValue) -> JsValue;
fn __wbindgen_lt(a: &JsValue, b: &JsValue) -> bool;
fn __wbindgen_le(a: &JsValue, b: &JsValue) -> bool;
fn __wbindgen_ge(a: &JsValue, b: &JsValue) -> bool;
fn __wbindgen_gt(a: &JsValue, b: &JsValue) -> bool;
fn __wbindgen_number_get(js: &JsValue) -> Option<f64>;
fn __wbindgen_boolean_get(js: &JsValue) -> Option<bool>;
fn __wbindgen_string_get(js: &JsValue) -> Option<String>;
fn __wbindgen_bigint_get_as_i64(js: &JsValue) -> Option<i64>;
fn __wbindgen_debug_string(js: &JsValue) -> String;
fn __wbindgen_throw(msg: &str) ;
fn __wbindgen_rethrow(js: JsValue) ;
fn __wbindgen_jsval_eq(a: &JsValue, b: &JsValue) -> bool;
fn __wbindgen_jsval_loose_eq(a: &JsValue, b: &JsValue) -> bool;
fn __wbindgen_copy_to_typed_array(data: &[u8], js: &JsValue);
fn __wbindgen_init_externref_table();
fn __wbindgen_exports() -> JsValue;
fn __wbindgen_memory() -> JsValue;
fn __wbindgen_module() -> JsValue;
fn __wbindgen_function_table() -> JsValue;
fn __wbindgen_reinit();
}
externs! {
#[link(wasm_import_module = "__wbindgen_placeholder__")]
extern "C" {
fn __wbindgen_object_clone_ref(idx: u32) -> u32;
fn __wbindgen_object_drop_ref(idx: u32) -> ();
fn __wbindgen_describe(v: u32) -> ();
fn __wbindgen_describe_cast(func: *const (), prims: *const ()) -> *const ();
}
}
impl Clone for JsValue {
#[inline]
fn clone(&self) -> JsValue {
JsValue::_new(unsafe { __wbindgen_object_clone_ref(self.idx) })
}
}
impl core::fmt::Debug for JsValue {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "JsValue({})", self.as_debug_string())
}
}
impl Drop for JsValue {
#[inline]
fn drop(&mut self) {
unsafe {
debug_assert!(
self.idx >= __rt::JSIDX_OFFSET,
"free of stack slot {}",
self.idx
);
if self.idx >= __rt::JSIDX_RESERVED {
__wbindgen_object_drop_ref(self.idx);
}
}
}
}
impl Default for JsValue {
fn default() -> Self {
Self::UNDEFINED
}
}
#[cfg(feature = "std")]
#[deprecated = "use with `#[wasm_bindgen(thread_local_v2)]` instead"]
pub struct JsStatic<T: 'static> {
#[doc(hidden)]
pub __inner: &'static std::thread::LocalKey<T>,
}
#[cfg(feature = "std")]
#[allow(deprecated)]
#[cfg(not(target_feature = "atomics"))]
impl<T: crate::convert::FromWasmAbi + 'static> Deref for JsStatic<T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { self.__inner.with(|ptr| &*(ptr as *const T)) }
}
}
pub struct JsThreadLocal<T: 'static> {
#[doc(hidden)]
#[cfg(not(target_feature = "atomics"))]
pub __inner: &'static __rt::LazyCell<T>,
#[doc(hidden)]
#[cfg(target_feature = "atomics")]
pub __inner: fn() -> *const T,
}
impl<T> JsThreadLocal<T> {
pub fn with<F, R>(&'static self, f: F) -> R
where
F: FnOnce(&T) -> R,
{
#[cfg(not(target_feature = "atomics"))]
return f(self.__inner);
#[cfg(target_feature = "atomics")]
f(unsafe { &*(self.__inner)() })
}
}
#[cold]
#[inline(never)]
#[deprecated(note = "renamed to `throw_str`")]
#[doc(hidden)]
pub fn throw(s: &str) -> ! {
throw_str(s)
}
#[cold]
#[inline(never)]
pub fn throw_str(s: &str) -> ! {
__wbindgen_throw(s);
unsafe { core::hint::unreachable_unchecked() }
}
#[cold]
#[inline(never)]
pub fn throw_val(s: JsValue) -> ! {
__wbindgen_rethrow(s);
unsafe { core::hint::unreachable_unchecked() }
}
pub fn externref_heap_live_count() -> u32 {
__wbindgen_externref_heap_live_count()
}
#[doc(hidden)]
pub fn anyref_heap_live_count() -> u32 {
externref_heap_live_count()
}
pub trait UnwrapThrowExt<T>: Sized {
#[cfg_attr(any(debug_assertions, not(target_family = "wasm")), track_caller)]
fn unwrap_throw(self) -> T {
if cfg!(all(debug_assertions, target_family = "wasm")) {
let loc = core::panic::Location::caller();
let msg = alloc::format!(
"called `{}::unwrap_throw()` ({}:{}:{})",
core::any::type_name::<Self>(),
loc.file(),
loc.line(),
loc.column()
);
self.expect_throw(&msg)
} else {
self.expect_throw("called `unwrap_throw()`")
}
}
#[cfg_attr(any(debug_assertions, not(target_family = "wasm")), track_caller)]
fn expect_throw(self, message: &str) -> T;
}
impl<T> UnwrapThrowExt<T> for Option<T> {
fn unwrap_throw(self) -> T {
const MSG: &str = "called `Option::unwrap_throw()` on a `None` value";
if cfg!(target_family = "wasm") {
if let Some(val) = self {
val
} else if cfg!(debug_assertions) {
let loc = core::panic::Location::caller();
let msg = alloc::format!("{MSG} ({}:{}:{})", loc.file(), loc.line(), loc.column(),);
throw_str(&msg)
} else {
throw_str(MSG)
}
} else {
self.expect(MSG)
}
}
fn expect_throw(self, message: &str) -> T {
if cfg!(target_family = "wasm") {
if let Some(val) = self {
val
} else if cfg!(debug_assertions) {
let loc = core::panic::Location::caller();
let msg =
alloc::format!("{message} ({}:{}:{})", loc.file(), loc.line(), loc.column(),);
throw_str(&msg)
} else {
throw_str(message)
}
} else {
self.expect(message)
}
}
}
impl<T, E> UnwrapThrowExt<T> for Result<T, E>
where
E: core::fmt::Debug,
{
fn unwrap_throw(self) -> T {
const MSG: &str = "called `Result::unwrap_throw()` on an `Err` value";
if cfg!(target_family = "wasm") {
match self {
Ok(val) => val,
Err(err) => {
if cfg!(debug_assertions) {
let loc = core::panic::Location::caller();
let msg = alloc::format!(
"{MSG} ({}:{}:{}): {err:?}",
loc.file(),
loc.line(),
loc.column(),
);
throw_str(&msg)
} else {
throw_str(MSG)
}
}
}
} else {
self.expect(MSG)
}
}
fn expect_throw(self, message: &str) -> T {
if cfg!(target_family = "wasm") {
match self {
Ok(val) => val,
Err(err) => {
if cfg!(debug_assertions) {
let loc = core::panic::Location::caller();
let msg = alloc::format!(
"{message} ({}:{}:{}): {err:?}",
loc.file(),
loc.line(),
loc.column(),
);
throw_str(&msg)
} else {
throw_str(message)
}
}
}
} else {
self.expect(message)
}
}
}
pub fn module() -> JsValue {
__wbindgen_module()
}
pub fn exports() -> JsValue {
__wbindgen_exports()
}
pub fn memory() -> JsValue {
__wbindgen_memory()
}
pub fn function_table() -> JsValue {
__wbindgen_function_table()
}
#[derive(Copy, Clone, PartialEq, Debug, Eq)]
pub struct Clamped<T>(pub T);
impl<T> Deref for Clamped<T> {
type Target = T;
fn deref(&self) -> &T {
&self.0
}
}
impl<T> DerefMut for Clamped<T> {
fn deref_mut(&mut self) -> &mut T {
&mut self.0
}
}
#[derive(Clone, Debug)]
pub struct JsError {
value: JsValue,
}
impl JsError {
#[inline]
pub fn new(s: &str) -> JsError {
Self {
value: __wbindgen_error_new(s),
}
}
}
#[cfg(feature = "std")]
impl<E> From<E> for JsError
where
E: std::error::Error,
{
fn from(error: E) -> Self {
use std::string::ToString;
JsError::new(&error.to_string())
}
}
impl From<JsError> for JsValue {
fn from(error: JsError) -> Self {
error.value
}
}
impl<T: VectorIntoWasmAbi> From<Box<[T]>> for JsValue {
fn from(vector: Box<[T]>) -> Self {
wbg_cast(vector)
}
}
impl<T: VectorIntoWasmAbi> From<Clamped<Box<[T]>>> for JsValue {
fn from(vector: Clamped<Box<[T]>>) -> Self {
wbg_cast(vector)
}
}
impl<T: VectorIntoWasmAbi> From<Vec<T>> for JsValue {
fn from(vector: Vec<T>) -> Self {
JsValue::from(vector.into_boxed_slice())
}
}
impl<T: VectorIntoWasmAbi> From<Clamped<Vec<T>>> for JsValue {
fn from(vector: Clamped<Vec<T>>) -> Self {
JsValue::from(Clamped(vector.0.into_boxed_slice()))
}
}
#[cfg(target_os = "emscripten")]
#[doc(hidden)]
#[used]
#[link_section = "__wasm_bindgen_emscripten_marker"]
pub static __WASM_BINDGEN_EMSCRIPTEN_MARKER: [u8; 1] = [1];