1#![no_std]
42#![cfg_attr(wasm_bindgen_unstable_test_coverage, feature(coverage_attribute))]
43#![cfg_attr(target_feature = "atomics", feature(thread_local))]
44#![cfg_attr(
45 any(target_feature = "atomics", wasm_bindgen_unstable_test_coverage),
46 feature(allow_internal_unstable),
47 allow(internal_features)
48)]
49#![cfg_attr(
50 all(not(debug_assertions), not(feature = "std"), target_arch = "wasm64"),
51 feature(simd_wasm64)
52)]
53#![doc(html_root_url = "https://docs.rs/wasm-bindgen/0.2")]
54
55extern crate alloc;
56#[cfg(feature = "std")]
57extern crate std;
58
59use crate::convert::{TryFromJsValue, UpcastFrom, VectorIntoWasmAbi};
60use crate::sys::Promising;
61use alloc::boxed::Box;
62use alloc::string::String;
63use alloc::vec::Vec;
64use core::convert::TryFrom;
65use core::marker::PhantomData;
66use core::ops::{
67 Add, BitAnd, BitOr, BitXor, Deref, DerefMut, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub,
68};
69use core::ptr::NonNull;
70
71const _: () = {
72 #[no_mangle]
90 pub extern "C" fn __wbindgen_skip_interpret_calls() {}
91};
92
93macro_rules! externs {
94 ($(#[$attr:meta])* extern "C" { $(fn $name:ident($($args:tt)*) -> $ret:ty;)* }) => (
95 #[cfg(target_family = "wasm")]
96 $(#[$attr])*
97 extern "C" {
98 $(fn $name($($args)*) -> $ret;)*
99 }
100
101 $(
102 #[cfg(not(target_family = "wasm"))]
103 #[allow(unused_variables)]
104 unsafe extern "C" fn $name($($args)*) -> $ret {
105 panic!("function not implemented on non-wasm32 targets")
106 }
107 )*
108 )
109}
110
111pub mod prelude {
117 pub use crate::closure::{Closure, ScopedClosure};
118 pub use crate::convert::Upcast; pub use crate::JsCast;
120 pub use crate::JsValue;
121 pub use crate::UnwrapThrowExt;
122 #[doc(hidden)]
123 pub use wasm_bindgen_macro::__wasm_bindgen_class_marker;
124 pub use wasm_bindgen_macro::wasm_bindgen;
125
126 pub use crate::JsError;
127}
128
129pub use wasm_bindgen_macro::link_to;
130
131pub mod closure;
132pub mod convert;
133pub mod describe;
134mod link;
135pub mod sys;
136
137#[cfg(wbg_reference_types)]
138mod externref;
139#[cfg(wbg_reference_types)]
140use externref::__wbindgen_externref_heap_live_count;
141
142pub use crate::__rt::marker::ErasableGeneric;
143pub use crate::convert::{IntoJsGeneric, JsGeneric};
144
145#[doc(hidden)]
146pub mod handler;
147
148mod cast;
149pub use crate::cast::JsCast;
150
151mod parent;
152pub use crate::parent::Parent;
153
154mod cache;
155pub use cache::intern::{intern, unintern};
156
157#[doc(hidden)]
158#[path = "rt/mod.rs"]
159pub mod __rt;
160use __rt::wbg_cast;
161
162pub struct JsValue {
169 idx: u32,
170 _marker: PhantomData<*mut u8>, }
172
173#[cfg(not(target_feature = "atomics"))]
174unsafe impl Send for JsValue {}
175#[cfg(not(target_feature = "atomics"))]
176unsafe impl Sync for JsValue {}
177
178unsafe impl ErasableGeneric for JsValue {
179 type Repr = JsValue;
180}
181
182impl Promising for JsValue {
183 type Resolution = JsValue;
184}
185
186impl JsValue {
187 pub const NULL: JsValue = JsValue::_new(__rt::JSIDX_NULL);
189
190 pub const UNDEFINED: JsValue = JsValue::_new(__rt::JSIDX_UNDEFINED);
192
193 pub const TRUE: JsValue = JsValue::_new(__rt::JSIDX_TRUE);
195
196 pub const FALSE: JsValue = JsValue::_new(__rt::JSIDX_FALSE);
198
199 #[inline]
200 const fn _new(idx: u32) -> JsValue {
201 JsValue {
202 idx,
203 _marker: PhantomData,
204 }
205 }
206
207 #[allow(clippy::should_implement_trait)] #[inline]
213 pub fn from_str(s: &str) -> JsValue {
214 wbg_cast(s)
215 }
216
217 #[inline]
222 pub fn from_f64(n: f64) -> JsValue {
223 wbg_cast(n)
224 }
225
226 #[inline]
231 pub fn bigint_from_str(s: &str) -> JsValue {
232 __wbindgen_bigint_from_str(s)
233 }
234
235 #[inline]
240 pub const fn from_bool(b: bool) -> JsValue {
241 if b {
242 JsValue::TRUE
243 } else {
244 JsValue::FALSE
245 }
246 }
247
248 #[inline]
250 pub const fn undefined() -> JsValue {
251 JsValue::UNDEFINED
252 }
253
254 #[inline]
256 pub const fn null() -> JsValue {
257 JsValue::NULL
258 }
259
260 pub fn symbol(description: Option<&str>) -> JsValue {
265 __wbindgen_symbol_new(description)
266 }
267
268 #[cfg(feature = "serde-serialize")]
292 #[deprecated = "causes dependency cycles, use `serde-wasm-bindgen` or `gloo_utils::format::JsValueSerdeExt` instead"]
293 pub fn from_serde<T>(t: &T) -> serde_json::Result<JsValue>
294 where
295 T: serde::ser::Serialize + ?Sized,
296 {
297 let s = serde_json::to_string(t)?;
298 Ok(__wbindgen_json_parse(s))
299 }
300
301 #[cfg(feature = "serde-serialize")]
323 #[deprecated = "causes dependency cycles, use `serde-wasm-bindgen` or `gloo_utils::format::JsValueSerdeExt` instead"]
324 pub fn into_serde<T>(&self) -> serde_json::Result<T>
325 where
326 T: for<'a> serde::de::Deserialize<'a>,
327 {
328 let s = __wbindgen_json_serialize(self);
329 serde_json::from_str(s.as_deref().unwrap_or("null"))
333 }
334
335 #[inline]
341 pub fn as_f64(&self) -> Option<f64> {
342 __wbindgen_number_get(self)
343 }
344
345 #[inline]
347 pub fn is_string(&self) -> bool {
348 __wbindgen_is_string(self)
349 }
350
351 #[inline]
372 pub fn as_string(&self) -> Option<String> {
373 __wbindgen_string_get(self)
374 }
375
376 #[inline]
382 pub fn as_bool(&self) -> Option<bool> {
383 __wbindgen_boolean_get(self)
384 }
385
386 #[inline]
388 pub fn is_null(&self) -> bool {
389 __wbindgen_is_null(self)
390 }
391
392 #[inline]
394 pub fn is_undefined(&self) -> bool {
395 __wbindgen_is_undefined(self)
396 }
397
398 #[inline]
400 pub fn is_null_or_undefined(&self) -> bool {
401 __wbindgen_is_null_or_undefined(self)
402 }
403
404 #[inline]
406 pub fn is_symbol(&self) -> bool {
407 __wbindgen_is_symbol(self)
408 }
409
410 #[inline]
412 pub fn is_object(&self) -> bool {
413 __wbindgen_is_object(self)
414 }
415
416 #[inline]
418 pub fn is_array(&self) -> bool {
419 __wbindgen_is_array(self)
420 }
421
422 #[inline]
424 pub fn is_function(&self) -> bool {
425 __wbindgen_is_function(self)
426 }
427
428 #[inline]
430 pub fn is_bigint(&self) -> bool {
431 __wbindgen_is_bigint(self)
432 }
433
434 #[inline]
438 pub fn js_typeof(&self) -> JsValue {
439 __wbindgen_typeof(self)
440 }
441
442 #[inline]
446 pub fn js_in(&self, obj: &JsValue) -> bool {
447 __wbindgen_in(self, obj)
448 }
449
450 #[inline]
454 pub fn is_truthy(&self) -> bool {
455 !self.is_falsy()
456 }
457
458 #[inline]
462 pub fn is_falsy(&self) -> bool {
463 __wbindgen_is_falsy(self)
464 }
465
466 fn as_debug_string(&self) -> String {
468 __wbindgen_debug_string(self)
469 }
470
471 #[inline]
475 pub fn loose_eq(&self, other: &Self) -> bool {
476 __wbindgen_jsval_loose_eq(self, other)
477 }
478
479 #[inline]
483 pub fn bit_not(&self) -> JsValue {
484 __wbindgen_bit_not(self)
485 }
486
487 #[inline]
491 pub fn unsigned_shr(&self, rhs: &Self) -> u32 {
492 __wbindgen_unsigned_shr(self, rhs)
493 }
494
495 #[inline]
499 pub fn checked_div(&self, rhs: &Self) -> Self {
500 __wbindgen_checked_div(self, rhs)
501 }
502
503 #[inline]
507 pub fn pow(&self, rhs: &Self) -> Self {
508 __wbindgen_pow(self, rhs)
509 }
510
511 #[inline]
515 pub fn lt(&self, other: &Self) -> bool {
516 __wbindgen_lt(self, other)
517 }
518
519 #[inline]
523 pub fn le(&self, other: &Self) -> bool {
524 __wbindgen_le(self, other)
525 }
526
527 #[inline]
531 pub fn ge(&self, other: &Self) -> bool {
532 __wbindgen_ge(self, other)
533 }
534
535 #[inline]
539 pub fn gt(&self, other: &Self) -> bool {
540 __wbindgen_gt(self, other)
541 }
542
543 #[inline]
547 pub fn unchecked_into_f64(&self) -> f64 {
548 __wbindgen_as_number(self)
551 }
552}
553
554impl PartialEq for JsValue {
555 #[inline]
559 fn eq(&self, other: &Self) -> bool {
560 __wbindgen_jsval_eq(self, other)
561 }
562}
563
564impl PartialEq<bool> for JsValue {
565 #[inline]
566 fn eq(&self, other: &bool) -> bool {
567 self.as_bool() == Some(*other)
568 }
569}
570
571impl PartialEq<str> for JsValue {
572 #[inline]
573 fn eq(&self, other: &str) -> bool {
574 *self == JsValue::from_str(other)
575 }
576}
577
578impl<'a> PartialEq<&'a str> for JsValue {
579 #[inline]
580 fn eq(&self, other: &&'a str) -> bool {
581 <JsValue as PartialEq<str>>::eq(self, other)
582 }
583}
584
585impl PartialEq<String> for JsValue {
586 #[inline]
587 fn eq(&self, other: &String) -> bool {
588 <JsValue as PartialEq<str>>::eq(self, other)
589 }
590}
591impl<'a> PartialEq<&'a String> for JsValue {
592 #[inline]
593 fn eq(&self, other: &&'a String) -> bool {
594 <JsValue as PartialEq<str>>::eq(self, other)
595 }
596}
597
598macro_rules! forward_deref_unop {
599 (impl $imp:ident, $method:ident for $t:ty) => {
600 impl $imp for $t {
601 type Output = <&'static $t as $imp>::Output;
602
603 #[inline]
604 fn $method(self) -> <&'static $t as $imp>::Output {
605 $imp::$method(&self)
606 }
607 }
608 };
609}
610
611macro_rules! forward_deref_binop {
612 (impl $imp:ident, $method:ident for $t:ty) => {
613 impl<'a> $imp<$t> for &'a $t {
614 type Output = <&'static $t as $imp<&'static $t>>::Output;
615
616 #[inline]
617 fn $method(self, other: $t) -> <&'static $t as $imp<&'static $t>>::Output {
618 $imp::$method(self, &other)
619 }
620 }
621
622 impl $imp<&$t> for $t {
623 type Output = <&'static $t as $imp<&'static $t>>::Output;
624
625 #[inline]
626 fn $method(self, other: &$t) -> <&'static $t as $imp<&'static $t>>::Output {
627 $imp::$method(&self, other)
628 }
629 }
630
631 impl $imp<$t> for $t {
632 type Output = <&'static $t as $imp<&'static $t>>::Output;
633
634 #[inline]
635 fn $method(self, other: $t) -> <&'static $t as $imp<&'static $t>>::Output {
636 $imp::$method(&self, &other)
637 }
638 }
639 };
640}
641
642impl Not for &JsValue {
643 type Output = bool;
644
645 #[inline]
649 fn not(self) -> Self::Output {
650 JsValue::is_falsy(self)
651 }
652}
653
654forward_deref_unop!(impl Not, not for JsValue);
655
656impl TryFrom<JsValue> for f64 {
657 type Error = JsValue;
658
659 #[inline]
664 fn try_from(val: JsValue) -> Result<Self, Self::Error> {
665 f64::try_from(&val)
666 }
667}
668
669impl TryFrom<&JsValue> for f64 {
670 type Error = JsValue;
671
672 #[inline]
677 fn try_from(val: &JsValue) -> Result<Self, Self::Error> {
678 let jsval = __wbindgen_try_into_number(val);
679 match jsval.as_f64() {
680 Some(num) => Ok(num),
681 None => Err(jsval),
682 }
683 }
684}
685
686impl Neg for &JsValue {
687 type Output = JsValue;
688
689 #[inline]
693 fn neg(self) -> Self::Output {
694 __wbindgen_neg(self)
695 }
696}
697
698forward_deref_unop!(impl Neg, neg for JsValue);
699
700impl BitAnd for &JsValue {
701 type Output = JsValue;
702
703 #[inline]
707 fn bitand(self, rhs: Self) -> Self::Output {
708 __wbindgen_bit_and(self, rhs)
709 }
710}
711
712forward_deref_binop!(impl BitAnd, bitand for JsValue);
713
714impl BitOr for &JsValue {
715 type Output = JsValue;
716
717 #[inline]
721 fn bitor(self, rhs: Self) -> Self::Output {
722 __wbindgen_bit_or(self, rhs)
723 }
724}
725
726forward_deref_binop!(impl BitOr, bitor for JsValue);
727
728impl BitXor for &JsValue {
729 type Output = JsValue;
730
731 #[inline]
735 fn bitxor(self, rhs: Self) -> Self::Output {
736 __wbindgen_bit_xor(self, rhs)
737 }
738}
739
740forward_deref_binop!(impl BitXor, bitxor for JsValue);
741
742impl Shl for &JsValue {
743 type Output = JsValue;
744
745 #[inline]
749 fn shl(self, rhs: Self) -> Self::Output {
750 __wbindgen_shl(self, rhs)
751 }
752}
753
754forward_deref_binop!(impl Shl, shl for JsValue);
755
756impl Shr for &JsValue {
757 type Output = JsValue;
758
759 #[inline]
763 fn shr(self, rhs: Self) -> Self::Output {
764 __wbindgen_shr(self, rhs)
765 }
766}
767
768forward_deref_binop!(impl Shr, shr for JsValue);
769
770impl Add for &JsValue {
771 type Output = JsValue;
772
773 #[inline]
777 fn add(self, rhs: Self) -> Self::Output {
778 __wbindgen_add(self, rhs)
779 }
780}
781
782forward_deref_binop!(impl Add, add for JsValue);
783
784impl Sub for &JsValue {
785 type Output = JsValue;
786
787 #[inline]
791 fn sub(self, rhs: Self) -> Self::Output {
792 __wbindgen_sub(self, rhs)
793 }
794}
795
796forward_deref_binop!(impl Sub, sub for JsValue);
797
798impl Div for &JsValue {
799 type Output = JsValue;
800
801 #[inline]
805 fn div(self, rhs: Self) -> Self::Output {
806 __wbindgen_div(self, rhs)
807 }
808}
809
810forward_deref_binop!(impl Div, div for JsValue);
811
812impl Mul for &JsValue {
813 type Output = JsValue;
814
815 #[inline]
819 fn mul(self, rhs: Self) -> Self::Output {
820 __wbindgen_mul(self, rhs)
821 }
822}
823
824forward_deref_binop!(impl Mul, mul for JsValue);
825
826impl Rem for &JsValue {
827 type Output = JsValue;
828
829 #[inline]
833 fn rem(self, rhs: Self) -> Self::Output {
834 __wbindgen_rem(self, rhs)
835 }
836}
837
838forward_deref_binop!(impl Rem, rem for JsValue);
839
840impl<'a> From<&'a str> for JsValue {
841 #[inline]
842 fn from(s: &'a str) -> JsValue {
843 JsValue::from_str(s)
844 }
845}
846
847impl<T> From<*mut T> for JsValue {
848 #[inline]
849 fn from(s: *mut T) -> JsValue {
850 JsValue::from(s as usize)
851 }
852}
853
854impl<T> From<*const T> for JsValue {
855 #[inline]
856 fn from(s: *const T) -> JsValue {
857 JsValue::from(s as usize)
858 }
859}
860
861impl<T> From<NonNull<T>> for JsValue {
862 #[inline]
863 fn from(s: NonNull<T>) -> JsValue {
864 JsValue::from(s.as_ptr() as usize)
865 }
866}
867
868impl<'a> From<&'a String> for JsValue {
869 #[inline]
870 fn from(s: &'a String) -> JsValue {
871 JsValue::from_str(s)
872 }
873}
874
875impl From<String> for JsValue {
876 #[inline]
877 fn from(s: String) -> JsValue {
878 JsValue::from_str(&s)
879 }
880}
881
882impl TryFrom<JsValue> for String {
883 type Error = JsValue;
884
885 fn try_from(value: JsValue) -> Result<Self, Self::Error> {
886 match value.as_string() {
887 Some(s) => Ok(s),
888 None => Err(value),
889 }
890 }
891}
892
893impl TryFromJsValue for String {
894 fn try_from_js_value_ref(value: &JsValue) -> Option<Self> {
895 value.as_string()
896 }
897}
898
899impl From<bool> for JsValue {
900 #[inline]
901 fn from(s: bool) -> JsValue {
902 JsValue::from_bool(s)
903 }
904}
905
906impl TryFromJsValue for bool {
907 fn try_from_js_value_ref(value: &JsValue) -> Option<Self> {
908 value.as_bool()
909 }
910}
911
912impl TryFromJsValue for char {
913 fn try_from_js_value_ref(value: &JsValue) -> Option<Self> {
914 let s = value.as_string()?;
915 if s.len() == 1 {
916 Some(s.chars().nth(0).unwrap())
917 } else {
918 None
919 }
920 }
921}
922
923impl<'a, T> From<&'a T> for JsValue
924where
925 T: JsCast,
926{
927 #[inline]
928 fn from(s: &'a T) -> JsValue {
929 s.as_ref().clone()
930 }
931}
932
933impl<T> From<Option<T>> for JsValue
934where
935 JsValue: From<T>,
936{
937 #[inline]
938 fn from(s: Option<T>) -> JsValue {
939 match s {
940 Some(s) => s.into(),
941 None => JsValue::undefined(),
942 }
943 }
944}
945
946impl JsCast for JsValue {
948 #[inline]
949 fn instanceof(_val: &JsValue) -> bool {
950 true
951 }
952 #[inline]
953 fn unchecked_from_js(val: JsValue) -> Self {
954 val
955 }
956 #[inline]
957 fn unchecked_from_js_ref(val: &JsValue) -> &Self {
958 val
959 }
960}
961
962impl AsRef<JsValue> for JsValue {
963 #[inline]
964 fn as_ref(&self) -> &JsValue {
965 self
966 }
967}
968
969impl UpcastFrom<JsValue> for JsValue {}
970
971fn to_uint_32(v: &JsValue) -> Option<u32> {
974 v.as_f64().map(|n| {
975 if n.is_infinite() {
976 0
977 } else {
978 (n as i64) as u32
979 }
980 })
981}
982
983macro_rules! integers {
984 ($($n:ident)*) => ($(
985 impl PartialEq<$n> for JsValue {
986 #[inline]
987 fn eq(&self, other: &$n) -> bool {
988 self.as_f64() == Some(f64::from(*other))
989 }
990 }
991
992 impl From<$n> for JsValue {
993 #[inline]
994 fn from(n: $n) -> JsValue {
995 JsValue::from_f64(n.into())
996 }
997 }
998
999 impl TryFromJsValue for $n {
1001 #[inline]
1002 fn try_from_js_value_ref(val: &JsValue) -> Option<$n> {
1003 to_uint_32(val).map(|n| n as $n)
1004 }
1005 }
1006 )*)
1007}
1008
1009integers! { i8 u8 i16 u16 i32 u32 }
1010
1011macro_rules! floats {
1012 ($($n:ident)*) => ($(
1013 impl PartialEq<$n> for JsValue {
1014 #[inline]
1015 fn eq(&self, other: &$n) -> bool {
1016 self.as_f64() == Some(f64::from(*other))
1017 }
1018 }
1019
1020 impl From<$n> for JsValue {
1021 #[inline]
1022 fn from(n: $n) -> JsValue {
1023 JsValue::from_f64(n.into())
1024 }
1025 }
1026
1027 impl TryFromJsValue for $n {
1028 #[inline]
1029 fn try_from_js_value_ref(val: &JsValue) -> Option<$n> {
1030 val.as_f64().map(|n| n as $n)
1031 }
1032 }
1033 )*)
1034}
1035
1036floats! { f32 f64 }
1037
1038macro_rules! big_integers {
1039 ($($n:ident)*) => ($(
1040 impl PartialEq<$n> for JsValue {
1041 #[inline]
1042 fn eq(&self, other: &$n) -> bool {
1043 self == &JsValue::from(*other)
1044 }
1045 }
1046
1047 impl From<$n> for JsValue {
1048 #[inline]
1049 fn from(arg: $n) -> JsValue {
1050 wbg_cast(arg)
1051 }
1052 }
1053
1054 impl TryFrom<JsValue> for $n {
1055 type Error = JsValue;
1056
1057 #[inline]
1058 fn try_from(v: JsValue) -> Result<Self, JsValue> {
1059 Self::try_from_js_value(v)
1060 }
1061 }
1062
1063 impl TryFromJsValue for $n {
1064 #[inline]
1065 fn try_from_js_value_ref(val: &JsValue) -> Option<$n> {
1066 let as_i64 = __wbindgen_bigint_get_as_i64(&val)?;
1067 let as_self = as_i64 as $n;
1070 if val == &as_self {
1072 Some(as_self)
1073 } else {
1074 None
1075 }
1076 }
1077 }
1078 )*)
1079}
1080
1081big_integers! { i64 u64 }
1082
1083macro_rules! num128 {
1084 ($ty:ty, $hi_ty:ty) => {
1085 impl PartialEq<$ty> for JsValue {
1086 #[inline]
1087 fn eq(&self, other: &$ty) -> bool {
1088 self == &JsValue::from(*other)
1089 }
1090 }
1091
1092 impl From<$ty> for JsValue {
1093 #[inline]
1094 fn from(arg: $ty) -> JsValue {
1095 wbg_cast(arg)
1096 }
1097 }
1098
1099 impl TryFrom<JsValue> for $ty {
1100 type Error = JsValue;
1101
1102 #[inline]
1103 fn try_from(v: JsValue) -> Result<Self, JsValue> {
1104 Self::try_from_js_value(v)
1105 }
1106 }
1107
1108 impl TryFromJsValue for $ty {
1109 fn try_from_js_value_ref(v: &JsValue) -> Option<$ty> {
1111 let lo = __wbindgen_bigint_get_as_i64(&v)? as u64;
1114 let hi = v >> JsValue::from(64_u64);
1117 <$hi_ty>::try_from_js_value_ref(&hi).map(|hi| Self::from(hi) << 64 | Self::from(lo))
1120 }
1121 }
1122 };
1123}
1124
1125num128!(i128, i64);
1126
1127num128!(u128, u64);
1128
1129impl TryFromJsValue for () {
1130 fn try_from_js_value_ref(value: &JsValue) -> Option<Self> {
1131 if value.is_undefined() {
1132 Some(())
1133 } else {
1134 None
1135 }
1136 }
1137}
1138
1139impl<T: TryFromJsValue> TryFromJsValue for Option<T> {
1140 fn try_from_js_value_ref(value: &JsValue) -> Option<Self> {
1141 if value.is_undefined() {
1142 Some(None)
1143 } else {
1144 T::try_from_js_value_ref(value).map(Some)
1145 }
1146 }
1147}
1148
1149impl PartialEq<usize> for JsValue {
1152 #[inline]
1153 fn eq(&self, other: &usize) -> bool {
1154 *self == (*other as crate::__rt::WasmWordRepr)
1155 }
1156}
1157
1158impl From<usize> for JsValue {
1159 #[inline]
1160 fn from(n: usize) -> Self {
1161 Self::from(n as crate::__rt::WasmWordRepr)
1162 }
1163}
1164
1165impl PartialEq<isize> for JsValue {
1166 #[inline]
1167 fn eq(&self, other: &isize) -> bool {
1168 *self == (*other as crate::__rt::WasmSignedWordRepr)
1169 }
1170}
1171
1172impl From<isize> for JsValue {
1173 #[inline]
1174 fn from(n: isize) -> Self {
1175 Self::from(n as crate::__rt::WasmSignedWordRepr)
1176 }
1177}
1178
1179impl TryFromJsValue for isize {
1181 #[inline]
1182 fn try_from_js_value_ref(val: &JsValue) -> Option<isize> {
1183 val.as_f64().map(|n| n as isize)
1184 }
1185}
1186
1187impl TryFromJsValue for usize {
1189 #[inline]
1190 fn try_from_js_value_ref(val: &JsValue) -> Option<usize> {
1191 val.as_f64().map(|n| n as usize)
1192 }
1193}
1194
1195#[wasm_bindgen_macro::wasm_bindgen(wasm_bindgen = crate)]
1197extern "C" {
1198 #[wasm_bindgen(js_namespace = Array, js_name = isArray)]
1199 fn __wbindgen_is_array(v: &JsValue) -> bool;
1200
1201 #[wasm_bindgen(js_name = BigInt)]
1202 fn __wbindgen_bigint_from_str(s: &str) -> JsValue;
1203
1204 #[wasm_bindgen(js_name = Symbol)]
1205 fn __wbindgen_symbol_new(description: Option<&str>) -> JsValue;
1206
1207 #[wasm_bindgen(js_name = Error)]
1208 fn __wbindgen_error_new(msg: &str) -> JsValue;
1209
1210 #[wasm_bindgen(js_namespace = JSON, js_name = parse)]
1211 fn __wbindgen_json_parse(json: String) -> JsValue;
1212
1213 #[wasm_bindgen(js_namespace = JSON, js_name = stringify)]
1214 fn __wbindgen_json_serialize(v: &JsValue) -> Option<String>;
1215
1216 #[wasm_bindgen(js_name = Number)]
1217 fn __wbindgen_as_number(v: &JsValue) -> f64;
1218}
1219
1220#[wasm_bindgen_macro::wasm_bindgen(wasm_bindgen = crate, raw_module = "__wbindgen_placeholder__")]
1223extern "C" {
1224 #[cfg(not(wbg_reference_types))]
1225 fn __wbindgen_externref_heap_live_count() -> u32;
1226
1227 fn __wbindgen_is_null(js: &JsValue) -> bool;
1228 fn __wbindgen_is_undefined(js: &JsValue) -> bool;
1229 fn __wbindgen_is_null_or_undefined(js: &JsValue) -> bool;
1230 fn __wbindgen_is_symbol(js: &JsValue) -> bool;
1231 fn __wbindgen_is_object(js: &JsValue) -> bool;
1232 fn __wbindgen_is_function(js: &JsValue) -> bool;
1233 fn __wbindgen_is_string(js: &JsValue) -> bool;
1234 fn __wbindgen_is_bigint(js: &JsValue) -> bool;
1235 fn __wbindgen_typeof(js: &JsValue) -> JsValue;
1236
1237 fn __wbindgen_in(prop: &JsValue, obj: &JsValue) -> bool;
1238
1239 fn __wbindgen_is_falsy(js: &JsValue) -> bool;
1240 fn __wbindgen_try_into_number(js: &JsValue) -> JsValue;
1241 fn __wbindgen_neg(js: &JsValue) -> JsValue;
1242 fn __wbindgen_bit_and(a: &JsValue, b: &JsValue) -> JsValue;
1243 fn __wbindgen_bit_or(a: &JsValue, b: &JsValue) -> JsValue;
1244 fn __wbindgen_bit_xor(a: &JsValue, b: &JsValue) -> JsValue;
1245 fn __wbindgen_bit_not(js: &JsValue) -> JsValue;
1246 fn __wbindgen_shl(a: &JsValue, b: &JsValue) -> JsValue;
1247 fn __wbindgen_shr(a: &JsValue, b: &JsValue) -> JsValue;
1248 fn __wbindgen_unsigned_shr(a: &JsValue, b: &JsValue) -> u32;
1249 fn __wbindgen_add(a: &JsValue, b: &JsValue) -> JsValue;
1250 fn __wbindgen_sub(a: &JsValue, b: &JsValue) -> JsValue;
1251 fn __wbindgen_div(a: &JsValue, b: &JsValue) -> JsValue;
1252 fn __wbindgen_checked_div(a: &JsValue, b: &JsValue) -> JsValue;
1253 fn __wbindgen_mul(a: &JsValue, b: &JsValue) -> JsValue;
1254 fn __wbindgen_rem(a: &JsValue, b: &JsValue) -> JsValue;
1255 fn __wbindgen_pow(a: &JsValue, b: &JsValue) -> JsValue;
1256 fn __wbindgen_lt(a: &JsValue, b: &JsValue) -> bool;
1257 fn __wbindgen_le(a: &JsValue, b: &JsValue) -> bool;
1258 fn __wbindgen_ge(a: &JsValue, b: &JsValue) -> bool;
1259 fn __wbindgen_gt(a: &JsValue, b: &JsValue) -> bool;
1260
1261 fn __wbindgen_number_get(js: &JsValue) -> Option<f64>;
1262 fn __wbindgen_boolean_get(js: &JsValue) -> Option<bool>;
1263 fn __wbindgen_string_get(js: &JsValue) -> Option<String>;
1264 fn __wbindgen_bigint_get_as_i64(js: &JsValue) -> Option<i64>;
1265
1266 fn __wbindgen_debug_string(js: &JsValue) -> String;
1267
1268 fn __wbindgen_throw(msg: &str) ;
1269 fn __wbindgen_rethrow(js: JsValue) ;
1270
1271 fn __wbindgen_jsval_eq(a: &JsValue, b: &JsValue) -> bool;
1272 fn __wbindgen_jsval_loose_eq(a: &JsValue, b: &JsValue) -> bool;
1273
1274 fn __wbindgen_copy_to_typed_array(data: &[u8], js: &JsValue);
1275
1276 fn __wbindgen_init_externref_table();
1277
1278 fn __wbindgen_exports() -> JsValue;
1279 fn __wbindgen_memory() -> JsValue;
1280 fn __wbindgen_module() -> JsValue;
1281 fn __wbindgen_instance() -> JsValue;
1282 fn __wbindgen_function_table() -> JsValue;
1283
1284 fn __wbindgen_reinit();
1285}
1286
1287externs! {
1290 #[link(wasm_import_module = "__wbindgen_placeholder__")]
1291 extern "C" {
1292 fn __wbindgen_object_clone_ref(idx: u32) -> u32;
1293 fn __wbindgen_object_drop_ref(idx: u32) -> ();
1294
1295 fn __wbindgen_describe(v: u32) -> ();
1296 fn __wbindgen_describe_cast(func: *const (), prims: *const ()) -> *const ();
1297 }
1298}
1299
1300impl Clone for JsValue {
1301 #[inline]
1302 fn clone(&self) -> JsValue {
1303 JsValue::_new(unsafe { __wbindgen_object_clone_ref(self.idx) })
1304 }
1305}
1306
1307impl core::fmt::Debug for JsValue {
1308 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
1309 write!(f, "JsValue({})", self.as_debug_string())
1310 }
1311}
1312
1313impl Drop for JsValue {
1314 #[inline]
1315 fn drop(&mut self) {
1316 unsafe {
1317 debug_assert!(
1319 self.idx >= __rt::JSIDX_OFFSET,
1320 "free of stack slot {}",
1321 self.idx
1322 );
1323
1324 if self.idx >= __rt::JSIDX_RESERVED {
1328 __wbindgen_object_drop_ref(self.idx);
1329 }
1330 }
1331 }
1332}
1333
1334impl Default for JsValue {
1335 fn default() -> Self {
1336 Self::UNDEFINED
1337 }
1338}
1339
1340#[cfg(feature = "std")]
1361#[deprecated = "use with `#[wasm_bindgen(thread_local_v2)]` instead"]
1362pub struct JsStatic<T: 'static> {
1363 #[doc(hidden)]
1364 pub __inner: &'static std::thread::LocalKey<T>,
1365}
1366
1367#[cfg(feature = "std")]
1368#[allow(deprecated)]
1369#[cfg(not(target_feature = "atomics"))]
1370impl<T: crate::convert::FromWasmAbi + 'static> Deref for JsStatic<T> {
1371 type Target = T;
1372 fn deref(&self) -> &T {
1373 unsafe { self.__inner.with(|ptr| &*(ptr as *const T)) }
1374 }
1375}
1376
1377pub struct JsThreadLocal<T: 'static> {
1396 #[doc(hidden)]
1397 #[cfg(not(target_feature = "atomics"))]
1398 pub __inner: &'static __rt::LazyCell<T>,
1399 #[doc(hidden)]
1400 #[cfg(target_feature = "atomics")]
1401 pub __inner: fn() -> *const T,
1402}
1403
1404impl<T> JsThreadLocal<T> {
1405 pub fn with<F, R>(&'static self, f: F) -> R
1406 where
1407 F: FnOnce(&T) -> R,
1408 {
1409 #[cfg(not(target_feature = "atomics"))]
1410 return f(self.__inner);
1411 #[cfg(target_feature = "atomics")]
1412 f(unsafe { &*(self.__inner)() })
1413 }
1414}
1415
1416#[cold]
1417#[inline(never)]
1418#[deprecated(note = "renamed to `throw_str`")]
1419#[doc(hidden)]
1420pub fn throw(s: &str) -> ! {
1421 throw_str(s)
1422}
1423
1424#[cold]
1439#[inline(never)]
1440pub fn throw_str(s: &str) -> ! {
1441 __wbindgen_throw(s);
1442 unsafe { core::hint::unreachable_unchecked() }
1443}
1444
1445#[cold]
1460#[inline(never)]
1461pub fn throw_val(s: JsValue) -> ! {
1462 __wbindgen_rethrow(s);
1463 unsafe { core::hint::unreachable_unchecked() }
1464}
1465
1466pub fn externref_heap_live_count() -> u32 {
1511 __wbindgen_externref_heap_live_count()
1512}
1513
1514#[doc(hidden)]
1515pub fn anyref_heap_live_count() -> u32 {
1516 externref_heap_live_count()
1517}
1518
1519pub trait UnwrapThrowExt<T>: Sized {
1549 #[cfg_attr(any(debug_assertions, not(target_family = "wasm")), track_caller)]
1552 fn unwrap_throw(self) -> T {
1553 if cfg!(all(debug_assertions, target_family = "wasm")) {
1554 let loc = core::panic::Location::caller();
1555 let msg = alloc::format!(
1556 "called `{}::unwrap_throw()` ({}:{}:{})",
1557 core::any::type_name::<Self>(),
1558 loc.file(),
1559 loc.line(),
1560 loc.column()
1561 );
1562 self.expect_throw(&msg)
1563 } else {
1564 self.expect_throw("called `unwrap_throw()`")
1565 }
1566 }
1567
1568 #[cfg_attr(any(debug_assertions, not(target_family = "wasm")), track_caller)]
1572 fn expect_throw(self, message: &str) -> T;
1573}
1574
1575impl<T> UnwrapThrowExt<T> for Option<T> {
1576 fn unwrap_throw(self) -> T {
1577 const MSG: &str = "called `Option::unwrap_throw()` on a `None` value";
1578
1579 if cfg!(target_family = "wasm") {
1580 if let Some(val) = self {
1581 val
1582 } else if cfg!(debug_assertions) {
1583 let loc = core::panic::Location::caller();
1584 let msg = alloc::format!("{MSG} ({}:{}:{})", loc.file(), loc.line(), loc.column(),);
1585
1586 throw_str(&msg)
1587 } else {
1588 throw_str(MSG)
1589 }
1590 } else {
1591 self.expect(MSG)
1592 }
1593 }
1594
1595 fn expect_throw(self, message: &str) -> T {
1596 if cfg!(target_family = "wasm") {
1597 if let Some(val) = self {
1598 val
1599 } else if cfg!(debug_assertions) {
1600 let loc = core::panic::Location::caller();
1601 let msg =
1602 alloc::format!("{message} ({}:{}:{})", loc.file(), loc.line(), loc.column(),);
1603
1604 throw_str(&msg)
1605 } else {
1606 throw_str(message)
1607 }
1608 } else {
1609 self.expect(message)
1610 }
1611 }
1612}
1613
1614impl<T, E> UnwrapThrowExt<T> for Result<T, E>
1615where
1616 E: core::fmt::Debug,
1617{
1618 fn unwrap_throw(self) -> T {
1619 const MSG: &str = "called `Result::unwrap_throw()` on an `Err` value";
1620
1621 if cfg!(target_family = "wasm") {
1622 match self {
1623 Ok(val) => val,
1624 Err(err) => {
1625 if cfg!(debug_assertions) {
1626 let loc = core::panic::Location::caller();
1627 let msg = alloc::format!(
1628 "{MSG} ({}:{}:{}): {err:?}",
1629 loc.file(),
1630 loc.line(),
1631 loc.column(),
1632 );
1633
1634 throw_str(&msg)
1635 } else {
1636 throw_str(MSG)
1637 }
1638 }
1639 }
1640 } else {
1641 self.expect(MSG)
1642 }
1643 }
1644
1645 fn expect_throw(self, message: &str) -> T {
1646 if cfg!(target_family = "wasm") {
1647 match self {
1648 Ok(val) => val,
1649 Err(err) => {
1650 if cfg!(debug_assertions) {
1651 let loc = core::panic::Location::caller();
1652 let msg = alloc::format!(
1653 "{message} ({}:{}:{}): {err:?}",
1654 loc.file(),
1655 loc.line(),
1656 loc.column(),
1657 );
1658
1659 throw_str(&msg)
1660 } else {
1661 throw_str(message)
1662 }
1663 }
1664 }
1665 } else {
1666 self.expect(message)
1667 }
1668 }
1669}
1670
1671pub fn module() -> JsValue {
1676 __wbindgen_module()
1677}
1678
1679pub fn instance() -> JsValue {
1684 __wbindgen_instance()
1685}
1686
1687pub fn exports() -> JsValue {
1690 __wbindgen_exports()
1691}
1692
1693pub fn memory() -> JsValue {
1695 __wbindgen_memory()
1696}
1697
1698pub fn function_table() -> JsValue {
1701 __wbindgen_function_table()
1702}
1703
1704#[derive(Copy, Clone, PartialEq, Debug, Eq)]
1717pub struct Clamped<T>(pub T);
1718
1719impl<T> Deref for Clamped<T> {
1720 type Target = T;
1721
1722 fn deref(&self) -> &T {
1723 &self.0
1724 }
1725}
1726
1727impl<T> DerefMut for Clamped<T> {
1728 fn deref_mut(&mut self) -> &mut T {
1729 &mut self.0
1730 }
1731}
1732
1733#[derive(Clone, Debug)]
1790#[repr(transparent)]
1791pub struct JsError {
1792 value: JsValue,
1793}
1794
1795impl JsError {
1796 #[inline]
1798 pub fn new(s: &str) -> JsError {
1799 Self {
1800 value: __wbindgen_error_new(s),
1801 }
1802 }
1803}
1804
1805#[cfg(feature = "std")]
1806impl<E> From<E> for JsError
1807where
1808 E: std::error::Error,
1809{
1810 fn from(error: E) -> Self {
1811 use std::string::ToString;
1812
1813 JsError::new(&error.to_string())
1814 }
1815}
1816
1817impl From<JsError> for JsValue {
1818 fn from(error: JsError) -> Self {
1819 error.value
1820 }
1821}
1822
1823impl<T: VectorIntoWasmAbi> From<Box<[T]>> for JsValue {
1824 fn from(vector: Box<[T]>) -> Self {
1825 wbg_cast(vector)
1826 }
1827}
1828
1829impl<T: VectorIntoWasmAbi> From<Clamped<Box<[T]>>> for JsValue {
1830 fn from(vector: Clamped<Box<[T]>>) -> Self {
1831 wbg_cast(vector)
1832 }
1833}
1834
1835impl<T: VectorIntoWasmAbi> From<Vec<T>> for JsValue {
1836 fn from(vector: Vec<T>) -> Self {
1837 JsValue::from(vector.into_boxed_slice())
1838 }
1839}
1840
1841impl<T: VectorIntoWasmAbi> From<Clamped<Vec<T>>> for JsValue {
1842 fn from(vector: Clamped<Vec<T>>) -> Self {
1843 JsValue::from(Clamped(vector.0.into_boxed_slice()))
1844 }
1845}
1846
1847#[cfg(target_os = "emscripten")]
1848#[doc(hidden)]
1849#[used]
1850#[link_section = "__wasm_bindgen_emscripten_marker"]
1851pub static __WASM_BINDGEN_EMSCRIPTEN_MARKER: [u8; 1] = [1];