Skip to main content

js_sys/
lib.rs

1//! Bindings to JavaScript's standard, built-in objects, including their methods
2//! and properties.
3//!
4//! This does *not* include any Web, Node, or any other JS environment
5//! APIs. Only the things that are guaranteed to exist in the global scope by
6//! the ECMAScript standard.
7//!
8//! <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects>
9//!
10//! ## A Note About `camelCase`, `snake_case`, and Naming Conventions
11//!
12//! JavaScript's global objects use `camelCase` naming conventions for functions
13//! and methods, but Rust style is to use `snake_case`. These bindings expose
14//! the Rust style `snake_case` name. Additionally, acronyms within a method
15//! name are all lower case, where as in JavaScript they are all upper case. For
16//! example, `decodeURI` in JavaScript is exposed as `decode_uri` in these
17//! bindings.
18//!
19//! ## A Note About `toString` and `to_js_string`
20//!
21//! JavaScript's `toString()` method is exposed as `to_js_string()` in these
22//! bindings to avoid confusion with Rust's [`ToString`] trait and its
23//! `to_string()` method. This allows types to implement both the Rust
24//! [`Display`](core::fmt::Display) trait (which provides `to_string()` via
25//! [`ToString`]) and still expose the JavaScript `toString()` functionality.
26
27#![doc(html_root_url = "https://docs.rs/js-sys/0.2")]
28#![cfg_attr(not(feature = "std"), no_std)]
29#![cfg_attr(target_feature = "atomics", feature(thread_local))]
30#![cfg_attr(target_feature = "atomics", feature(stdarch_wasm_atomic_wait))]
31#![cfg_attr(
32    all(target_feature = "atomics", target_arch = "wasm64"),
33    feature(simd_wasm64)
34)]
35
36extern crate alloc;
37
38use alloc::string::String;
39use alloc::vec::Vec;
40use core::cmp::Ordering;
41#[cfg(not(js_sys_unstable_apis))]
42use core::convert::Infallible;
43use core::convert::{self, TryFrom};
44use core::fmt;
45use core::iter::{self, Product, Sum};
46use core::marker::PhantomData;
47use core::mem::MaybeUninit;
48use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub};
49use core::str;
50use core::str::FromStr;
51pub use wasm_bindgen;
52use wasm_bindgen::closure::{ScopedClosure, WasmClosure};
53use wasm_bindgen::convert::{FromWasmAbi, IntoWasmAbi, Upcast, UpcastFrom};
54use wasm_bindgen::prelude::*;
55use wasm_bindgen::JsError;
56
57// Re-export sys types as js-sys types
58pub use wasm_bindgen::sys::{JsNullable, JsOption, Null, Promising, Undefined};
59pub use wasm_bindgen::{IntoJsGeneric, JsGeneric, Nullable};
60
61// When adding new imports:
62//
63// * Keep imports in alphabetical order.
64//
65// * Rename imports with `js_name = ...` according to the note about `camelCase`
66//   and `snake_case` in the module's documentation above.
67//
68// * Include the one sentence summary of the import from the MDN link in the
69//   module's documentation above, and the MDN link itself.
70//
71// * If a function or method can throw an exception, make it catchable by adding
72//   `#[wasm_bindgen(catch)]`.
73//
74// * Add a new `#[test]` into the appropriate file in the
75//   `crates/js-sys/tests/wasm/` directory. If the imported function or method
76//   can throw an exception, make sure to also add test coverage for that case.
77//
78// * Arguments that are `JsValue`s or imported JavaScript types should be taken
79//   by reference.
80//
81// * Name JavaScript's `toString()` method as `to_js_string()` to avoid conflict
82//   with Rust's `ToString` trait.
83
84macro_rules! forward_deref_unop {
85    (impl $imp:ident, $method:ident for $t:ty) => {
86        impl $imp for $t {
87            type Output = <&'static $t as $imp>::Output;
88
89            #[inline]
90            fn $method(self) -> Self::Output {
91                $imp::$method(&self)
92            }
93        }
94    };
95    (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
96        impl<$($gen),+> $imp for $t {
97            type Output = <&'static $t as $imp>::Output;
98
99            #[inline]
100            fn $method(self) -> Self::Output {
101                $imp::$method(&self)
102            }
103        }
104    };
105}
106
107macro_rules! forward_deref_binop {
108    (impl $imp:ident, $method:ident for $t:ty) => {
109        impl<'a> $imp<$t> for &'a $t {
110            type Output = <&'static $t as $imp<&'static $t>>::Output;
111
112            #[inline]
113            fn $method(self, other: $t) -> Self::Output {
114                $imp::$method(self, &other)
115            }
116        }
117
118        impl $imp<&$t> for $t {
119            type Output = <&'static $t as $imp<&'static $t>>::Output;
120
121            #[inline]
122            fn $method(self, other: &$t) -> Self::Output {
123                $imp::$method(&self, other)
124            }
125        }
126
127        impl $imp<$t> for $t {
128            type Output = <&'static $t as $imp<&'static $t>>::Output;
129
130            #[inline]
131            fn $method(self, other: $t) -> Self::Output {
132                $imp::$method(&self, &other)
133            }
134        }
135    };
136    (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
137        impl<'a, $($gen),+> $imp<$t> for &'a $t {
138            type Output = <&'static $t as $imp<&'static $t>>::Output;
139
140            #[inline]
141            fn $method(self, other: $t) -> Self::Output {
142                $imp::$method(self, &other)
143            }
144        }
145
146        impl<$($gen),+> $imp<&$t> for $t {
147            type Output = <&'static $t as $imp<&'static $t>>::Output;
148
149            #[inline]
150            fn $method(self, other: &$t) -> Self::Output {
151                $imp::$method(&self, other)
152            }
153        }
154
155        impl<$($gen),+> $imp<$t> for $t {
156            type Output = <&'static $t as $imp<&'static $t>>::Output;
157
158            #[inline]
159            fn $method(self, other: $t) -> Self::Output {
160                $imp::$method(&self, &other)
161            }
162        }
163    };
164}
165
166macro_rules! forward_js_unop {
167    (impl $imp:ident, $method:ident for $t:ty) => {
168        impl $imp for &$t {
169            type Output = $t;
170
171            #[inline]
172            fn $method(self) -> Self::Output {
173                $imp::$method(JsValue::as_ref(self)).unchecked_into()
174            }
175        }
176
177        forward_deref_unop!(impl $imp, $method for $t);
178    };
179    (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
180        impl<$($gen),+> $imp for &$t {
181            type Output = $t;
182
183            #[inline]
184            fn $method(self) -> Self::Output {
185                $imp::$method(JsValue::as_ref(self)).unchecked_into()
186            }
187        }
188
189        forward_deref_unop!(impl<$($gen),+> $imp, $method for $t);
190    };
191}
192
193macro_rules! forward_js_binop {
194    (impl $imp:ident, $method:ident for $t:ty) => {
195        impl $imp<&$t> for &$t {
196            type Output = $t;
197
198            #[inline]
199            fn $method(self, other: &$t) -> Self::Output {
200                $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
201            }
202        }
203
204        forward_deref_binop!(impl $imp, $method for $t);
205    };
206    (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
207        impl<$($gen),+> $imp<&$t> for &$t {
208            type Output = $t;
209
210            #[inline]
211            fn $method(self, other: &$t) -> Self::Output {
212                $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
213            }
214        }
215
216        forward_deref_binop!(impl<$($gen),+> $imp, $method for $t);
217    };
218}
219
220macro_rules! sum_product {
221    ($($a:ident)*) => ($(
222        impl Sum for $a {
223            #[inline]
224            fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
225                iter.fold(
226                    $a::from(0),
227                    |a, b| a + b,
228                )
229            }
230        }
231
232        impl Product for $a {
233            #[inline]
234            fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
235                iter.fold(
236                    $a::from(1),
237                    |a, b| a * b,
238                )
239            }
240        }
241
242        impl<'a> Sum<&'a $a> for $a {
243            fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
244                iter.fold(
245                    $a::from(0),
246                    |a, b| a + b,
247                )
248            }
249        }
250
251        impl<'a> Product<&'a $a> for $a {
252            #[inline]
253            fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
254                iter.fold(
255                    $a::from(1),
256                    |a, b| a * b,
257                )
258            }
259        }
260    )*);
261    // Generic variant: impl<T> for Type<T>
262    (impl<$gen:ident> $a:ident<$g2:ident>) => {
263        impl<$gen> Sum for $a<$g2>
264        where
265            $a<$g2>: From<$gen>,
266            $g2: From<u32>
267        {
268            #[inline]
269            fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
270                iter.fold(
271                    $a::from($g2::from(0)),
272                    |a, b| a + b,
273                )
274            }
275        }
276
277        impl<$gen> Product for $a<$g2>
278        where
279            $a<$g2>: From<$gen>,
280            $g2: From<u32>
281        {
282            #[inline]
283            fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
284                iter.fold(
285                    $a::from($g2::from(1)),
286                    |a, b| a * b,
287                )
288            }
289        }
290
291        impl<'a, $gen> Sum<&'a $a<$g2>> for $a<$g2>
292        where
293            $a<$g2>: From<$gen>,
294            $g2: From<u32>
295        {
296            fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
297                iter.fold(
298                    $a::from($g2::from(0)),
299                    |a, b| a + b,
300                )
301            }
302        }
303
304        impl<'a, $gen> Product<&'a $a<$g2>> for $a<$g2>
305        where
306            $a<$g2>: From<$gen>,
307            $g2: From<u32>
308        {
309            #[inline]
310            fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
311                iter.fold(
312                    $a::from($g2::from(1)),
313                    |a, b| a * b,
314                )
315            }
316        }
317    };
318}
319
320macro_rules! partialord_ord {
321    ($t:ident) => {
322        impl PartialOrd for $t {
323            #[inline]
324            fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
325                Some(self.cmp(other))
326            }
327
328            #[inline]
329            fn lt(&self, other: &Self) -> bool {
330                JsValue::as_ref(self).lt(JsValue::as_ref(other))
331            }
332
333            #[inline]
334            fn le(&self, other: &Self) -> bool {
335                JsValue::as_ref(self).le(JsValue::as_ref(other))
336            }
337
338            #[inline]
339            fn ge(&self, other: &Self) -> bool {
340                JsValue::as_ref(self).ge(JsValue::as_ref(other))
341            }
342
343            #[inline]
344            fn gt(&self, other: &Self) -> bool {
345                JsValue::as_ref(self).gt(JsValue::as_ref(other))
346            }
347        }
348
349        impl Ord for $t {
350            #[inline]
351            fn cmp(&self, other: &Self) -> Ordering {
352                if self == other {
353                    Ordering::Equal
354                } else if self.lt(other) {
355                    Ordering::Less
356                } else {
357                    Ordering::Greater
358                }
359            }
360        }
361    };
362}
363
364#[wasm_bindgen]
365extern "C" {
366    /// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
367    /// previously created by `encodeURI` or by a similar routine.
368    ///
369    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI)
370    #[wasm_bindgen(catch, js_name = decodeURI)]
371    pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
372
373    /// The `decodeURIComponent()` function decodes a Uniform Resource Identifier (URI) component
374    /// previously created by `encodeURIComponent` or by a similar routine.
375    ///
376    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
377    #[wasm_bindgen(catch, js_name = decodeURIComponent)]
378    pub fn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>;
379
380    /// The `encodeURI()` function encodes a Uniform Resource Identifier (URI)
381    /// by replacing each instance of certain characters by one, two, three, or
382    /// four escape sequences representing the UTF-8 encoding of the character
383    /// (will only be four escape sequences for characters composed of two
384    /// "surrogate" characters).
385    ///
386    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
387    #[wasm_bindgen(js_name = encodeURI)]
388    pub fn encode_uri(decoded: &str) -> JsString;
389
390    /// The `encodeURIComponent()` function encodes a Uniform Resource Identifier (URI) component
391    /// by replacing each instance of certain characters by one, two, three, or four escape sequences
392    /// representing the UTF-8 encoding of the character
393    /// (will only be four escape sequences for characters composed of two "surrogate" characters).
394    ///
395    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
396    #[wasm_bindgen(js_name = encodeURIComponent)]
397    pub fn encode_uri_component(decoded: &str) -> JsString;
398
399    /// The `eval()` function evaluates JavaScript code represented as a string.
400    ///
401    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)
402    #[cfg(feature = "unsafe-eval")]
403    #[wasm_bindgen(catch)]
404    pub fn eval(js_source_text: &str) -> Result<JsValue, JsValue>;
405
406    /// The global `isFinite()` function determines whether the passed value is a finite number.
407    /// If needed, the parameter is first converted to a number.
408    ///
409    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
410    #[wasm_bindgen(js_name = isFinite)]
411    pub fn is_finite(value: &JsValue) -> bool;
412
413    /// The `parseInt()` function parses a string argument and returns an integer
414    /// of the specified radix (the base in mathematical numeral systems), or NaN on error.
415    ///
416    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
417    #[wasm_bindgen(js_name = parseInt)]
418    pub fn parse_int(text: &str, radix: u8) -> f64;
419
420    /// The `parseFloat()` function parses an argument and returns a floating point number,
421    /// or NaN on error.
422    ///
423    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
424    #[wasm_bindgen(js_name = parseFloat)]
425    pub fn parse_float(text: &str) -> f64;
426
427    /// The `escape()` function computes a new string in which certain characters have been
428    /// replaced by a hexadecimal escape sequence.
429    ///
430    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape)
431    #[wasm_bindgen]
432    pub fn escape(string: &str) -> JsString;
433
434    /// The `unescape()` function computes a new string in which hexadecimal escape
435    /// sequences are replaced with the character that it represents. The escape sequences might
436    /// be introduced by a function like `escape`. Usually, `decodeURI` or `decodeURIComponent`
437    /// are preferred over `unescape`.
438    ///
439    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape)
440    #[wasm_bindgen]
441    pub fn unescape(string: &str) -> JsString;
442}
443
444// AggregateError
445#[wasm_bindgen]
446extern "C" {
447    /// The `AggregateError` object represents an error when several errors need
448    /// to be wrapped in a single error. It is thrown when multiple errors need
449    /// to be reported by an operation, for example by [`Promise::any`], when
450    /// all promises passed to it reject.
451    ///
452    /// `AggregateError` is a subclass of [`Error`].
453    ///
454    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError)
455    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "AggregateError")]
456    #[derive(Clone, Debug, PartialEq, Eq)]
457    pub type AggregateError;
458
459    /// Creates a new `AggregateError` from the given iterable of errors.
460    ///
461    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError/AggregateError)
462    #[wasm_bindgen(constructor)]
463    pub fn new(errors: &[JsValue]) -> AggregateError;
464
465    /// Creates a new `AggregateError` from the given iterable of errors with a
466    /// human-readable description of the aggregate error.
467    ///
468    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError/AggregateError)
469    #[wasm_bindgen(constructor)]
470    pub fn new_with_message(errors: &[JsValue], message: &str) -> AggregateError;
471
472    /// Creates a new `AggregateError` from the given iterable of errors, a
473    /// human-readable description of the aggregate error, and an
474    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
475    /// original cause of the error.
476    ///
477    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError/AggregateError)
478    #[wasm_bindgen(constructor)]
479    pub fn new_with_options(
480        errors: &[JsValue],
481        message: &str,
482        options: &ErrorOptions,
483    ) -> AggregateError;
484
485    /// The `errors` property of an `AggregateError` instance is an array
486    /// representing the errors that were aggregated.
487    ///
488    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError/errors)
489    #[wasm_bindgen(method, getter)]
490    pub fn errors(this: &AggregateError) -> Array;
491}
492
493// ErrorOptions
494#[wasm_bindgen]
495extern "C" {
496    /// The options dictionary accepted as the second argument to the
497    /// [`Error`] constructor (and other built-in error constructors such as
498    /// [`AggregateError`]). Its sole standard property is `cause`, which
499    /// indicates the original cause of the error.
500    ///
501    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
502    #[wasm_bindgen(extends = Object, typescript_type = "ErrorOptions")]
503    #[derive(Clone, Debug, PartialEq, Eq)]
504    pub type ErrorOptions;
505
506    /// The `cause` property indicates the underlying cause of an error.
507    ///
508    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause)
509    // Next major: dictionary getters throughout js-sys become `foo()` alongside
510    // `set_foo()`, matching web-sys interface attributes.
511    #[wasm_bindgen(method, getter = "cause")]
512    pub fn get_cause(this: &ErrorOptions) -> JsValue;
513
514    /// Sets the `cause` property of this `ErrorOptions` dictionary.
515    ///
516    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause)
517    #[wasm_bindgen(method, setter = "cause")]
518    pub fn set_cause(this: &ErrorOptions, cause: &JsValue);
519}
520
521impl ErrorOptions {
522    /// Construct a new `ErrorOptions` dictionary with the given `cause`.
523    pub fn new(cause: &JsValue) -> Self {
524        let ret: Self = ::wasm_bindgen::JsCast::unchecked_into(Object::new());
525        ret.set_cause(cause);
526        ret
527    }
528}
529
530// Array
531#[wasm_bindgen]
532extern "C" {
533    #[wasm_bindgen(extends = Object, is_type_of = Array::is_array, typescript_type = "Array<any>")]
534    #[derive(Clone, Debug, PartialEq, Eq)]
535    pub type Array<T = JsValue>;
536
537    /// Creates a new empty array.
538    ///
539    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
540    #[cfg(not(js_sys_unstable_apis))]
541    #[wasm_bindgen(constructor)]
542    pub fn new() -> Array;
543
544    /// Creates a new empty array.
545    ///
546    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
547    #[cfg(js_sys_unstable_apis)]
548    #[wasm_bindgen(constructor)]
549    pub fn new<T>() -> Array<T>;
550
551    // Next major: deprecate
552    /// Creates a new empty array.
553    ///
554    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
555    #[wasm_bindgen(constructor)]
556    pub fn new_typed<T>() -> Array<T>;
557
558    /// Creates a new array with the specified length (elements are initialized to `undefined`).
559    ///
560    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
561    #[cfg(not(js_sys_unstable_apis))]
562    #[wasm_bindgen(constructor)]
563    pub fn new_with_length(len: u32) -> Array;
564
565    /// Creates a new array with the specified length (elements are initialized to `undefined`).
566    ///
567    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
568    #[cfg(js_sys_unstable_apis)]
569    #[wasm_bindgen(constructor)]
570    pub fn new_with_length<T>(len: u32) -> Array<T>;
571
572    // Next major: deprecate
573    /// Creates a new array with the specified length (elements are initialized to `undefined`).
574    ///
575    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
576    #[wasm_bindgen(constructor)]
577    pub fn new_with_length_typed<T>(len: u32) -> Array<T>;
578
579    /// Retrieves the element at the index, counting from the end if negative
580    /// (returns `undefined` if the index is out of range).
581    ///
582    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
583    #[cfg(not(js_sys_unstable_apis))]
584    #[wasm_bindgen(method)]
585    pub fn at<T>(this: &Array<T>, index: i32) -> T;
586
587    /// Retrieves the element at the index, counting from the end if negative
588    /// (returns `None` if the index is out of range).
589    ///
590    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
591    #[cfg(js_sys_unstable_apis)]
592    #[wasm_bindgen(method)]
593    pub fn at<T>(this: &Array<T>, index: i32) -> Option<T>;
594
595    /// Retrieves the element at the index (returns `undefined` if the index is out of range).
596    ///
597    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
598    #[cfg(not(js_sys_unstable_apis))]
599    #[wasm_bindgen(method, indexing_getter)]
600    pub fn get<T>(this: &Array<T>, index: u32) -> T;
601
602    /// Retrieves the element at the index (returns `None` if the index is out of range).
603    ///
604    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
605    #[cfg(js_sys_unstable_apis)]
606    #[wasm_bindgen(method, indexing_getter)]
607    pub fn get<T>(this: &Array<T>, index: u32) -> Option<T>;
608
609    /// Retrieves the element at the index (returns `undefined` if the index is out of range).
610    ///
611    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
612    #[wasm_bindgen(method, indexing_getter)]
613    pub fn get_unchecked<T>(this: &Array<T>, index: u32) -> T;
614
615    // Next major: deprecate
616    /// Retrieves the element at the index (returns `None` if the index is out of range,
617    /// or if the element is explicitly `undefined`).
618    #[wasm_bindgen(method, indexing_getter)]
619    pub fn get_checked<T>(this: &Array<T>, index: u32) -> Option<T>;
620
621    /// Sets the element at the index (auto-enlarges the array if the index is out of range).
622    #[cfg(not(js_sys_unstable_apis))]
623    #[wasm_bindgen(method, indexing_setter)]
624    pub fn set<T>(this: &Array<T>, index: u32, value: T);
625
626    /// Sets the element at the index (auto-enlarges the array if the index is out of range).
627    #[cfg(js_sys_unstable_apis)]
628    #[wasm_bindgen(method, indexing_setter)]
629    pub fn set<T>(this: &Array<T>, index: u32, value: &T);
630
631    // Next major: deprecate
632    /// Sets the element at the index (auto-enlarges the array if the index is out of range).
633    #[wasm_bindgen(method, indexing_setter)]
634    pub fn set_ref<T>(this: &Array<T>, index: u32, value: &T);
635
636    /// Deletes the element at the index (does nothing if the index is out of range).
637    ///
638    /// The element at the index is set to `undefined`.
639    ///
640    /// This does not resize the array, the array will still be the same length.
641    #[wasm_bindgen(method, indexing_deleter)]
642    pub fn delete<T>(this: &Array<T>, index: u32);
643
644    /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
645    /// from an array-like or iterable object.
646    ///
647    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
648    #[cfg(not(js_sys_unstable_apis))]
649    #[wasm_bindgen(static_method_of = Array)]
650    pub fn from(val: &JsValue) -> Array;
651
652    /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
653    /// from an array-like or iterable object.
654    ///
655    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
656    #[cfg(js_sys_unstable_apis)]
657    #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
658    pub fn from<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
659
660    // Next major: deprecate
661    /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
662    /// from an array-like or iterable object.
663    ///
664    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
665    #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
666    pub fn from_iterable<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
667
668    /// The `Array.from()` static method with a map function creates a new, shallow-copied
669    /// `Array` instance from an array-like or iterable object, applying the map function
670    /// to each value.
671    ///
672    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
673    #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
674    pub fn from_iterable_map<I: Iterable, U>(
675        val: &I,
676        map: &mut dyn FnMut(I::Item, u32) -> Result<U, JsError>,
677    ) -> Result<Array<U>, JsValue>;
678
679    /// The `Array.fromAsync()` static method creates a new, shallow-copied `Array` instance
680    /// from an async iterable, iterable or array-like object.
681    ///
682    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
683    #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
684    pub fn from_async<I: AsyncIterable>(val: &I) -> Result<Promise<Array<I::Item>>, JsValue>;
685
686    /// The `Array.fromAsync()` static method with a map function creates a new, shallow-copied
687    /// `Array` instance from an async iterable, iterable or array-like object, applying the map
688    /// function to each value.
689    ///
690    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
691    #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
692    pub fn from_async_map<'a, I: AsyncIterable, R: Promising>(
693        val: &I,
694        map: &ScopedClosure<'a, dyn FnMut(I::Item, u32) -> Result<R, JsError>>,
695    ) -> Result<Promise<Array<R::Resolution>>, JsValue>;
696
697    /// The `copyWithin()` method shallow copies part of an array to another
698    /// location in the same array and returns it, without modifying its size.
699    ///
700    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)
701    #[wasm_bindgen(method, js_name = copyWithin)]
702    pub fn copy_within<T>(this: &Array<T>, target: i32, start: i32, end: i32) -> Array<T>;
703
704    /// The `concat()` method is used to merge two or more arrays. This method
705    /// does not change the existing arrays, but instead returns a new array.
706    ///
707    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
708    #[wasm_bindgen(method)]
709    pub fn concat<T, U: Upcast<T>>(this: &Array<T>, array: &Array<U>) -> Array<T>;
710
711    /// The `concat()` method is used to merge two or more arrays. This method
712    /// does not change the existing arrays, but instead returns a new array.
713    ///
714    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
715    #[wasm_bindgen(method)]
716    pub fn concat_many<T, U: Upcast<T>>(this: &Array<T>, array: &[Array<U>]) -> Array<T>;
717
718    /// The `every()` method tests whether all elements in the array pass the test
719    /// implemented by the provided function.
720    ///
721    /// **Note:** Consider using [`Array::try_every`] if the predicate might throw an error.
722    ///
723    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
724    #[wasm_bindgen(method)]
725    pub fn every<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> bool;
726
727    /// The `every()` method tests whether all elements in the array pass the test
728    /// implemented by the provided function. _(Fallible variation)_
729    ///
730    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
731    #[wasm_bindgen(method, js_name = every, catch)]
732    pub fn try_every<T>(
733        this: &Array<T>,
734        predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
735    ) -> Result<bool, JsValue>;
736
737    /// The `fill()` method fills all the elements of an array from a start index
738    /// to an end index with a static value. The end index is not included.
739    ///
740    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
741    #[wasm_bindgen(method)]
742    pub fn fill<T>(this: &Array<T>, value: &T, start: u32, end: u32) -> Array<T>;
743
744    /// The `filter()` method creates a new array with all elements that pass the
745    /// test implemented by the provided function.
746    ///
747    /// **Note:** Consider using [`Array::try_filter`] if the predicate might throw an error.
748    ///
749    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
750    #[wasm_bindgen(method)]
751    pub fn filter<T>(
752        this: &Array<T>,
753        predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
754    ) -> Array<T>;
755
756    /// The `filter()` method creates a new array with all elements that pass the
757    /// test implemented by the provided function. _(Fallible variation)_
758    ///
759    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
760    #[wasm_bindgen(method, js_name = filter, catch)]
761    pub fn try_filter<T>(
762        this: &Array<T>,
763        predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
764    ) -> Result<Array<T>, JsValue>;
765
766    /// The `find()` method returns the value of the first element in the array that satisfies
767    /// the provided testing function. Otherwise `undefined` is returned.
768    ///
769    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
770    #[cfg(not(js_sys_unstable_apis))]
771    #[wasm_bindgen(method)]
772    pub fn find<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
773
774    /// The `find()` method returns the value of the first element in the array that satisfies
775    /// the provided testing function. Returns `None` if no element matches.
776    ///
777    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
778    #[cfg(js_sys_unstable_apis)]
779    #[wasm_bindgen(method)]
780    pub fn find<T>(
781        this: &Array<T>,
782        predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
783    ) -> Option<T>;
784
785    /// The `find()` method returns the value of the first element in the array that satisfies
786    ///  the provided testing function. Otherwise `undefined` is returned. _(Fallible variation)_
787    ///
788    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
789    #[wasm_bindgen(method, js_name = find, catch)]
790    pub fn try_find<T>(
791        this: &Array<T>,
792        predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
793    ) -> Result<Option<T>, JsValue>;
794
795    /// The `findIndex()` method returns the index of the first element in the array that
796    /// satisfies the provided testing function. Otherwise -1 is returned.
797    ///
798    /// **Note:** Consider using [`Array::try_find_index`] if the predicate might throw an error.
799    ///
800    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
801    #[wasm_bindgen(method, js_name = findIndex)]
802    pub fn find_index<T>(
803        this: &Array<T>,
804        predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
805    ) -> i32;
806
807    /// The `findIndex()` method returns the index of the first element in the array that
808    /// satisfies the provided testing function. Otherwise -1 is returned. _(Fallible variation)_
809    ///
810    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
811    #[wasm_bindgen(method, js_name = findIndex, catch)]
812    pub fn try_find_index<T>(
813        this: &Array<T>,
814        predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
815    ) -> Result<i32, JsValue>;
816
817    /// The `findLast()` method of Array instances iterates the array in reverse order
818    /// and returns the value of the first element that satisfies the provided testing function.
819    /// If no elements satisfy the testing function, undefined is returned.
820    ///
821    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
822    #[cfg(not(js_sys_unstable_apis))]
823    #[wasm_bindgen(method, js_name = findLast)]
824    pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
825
826    /// The `findLast()` method of Array instances iterates the array in reverse order
827    /// and returns the value of the first element that satisfies the provided testing function.
828    /// Returns `None` if no element matches.
829    ///
830    /// **Note:** Consider using [`Array::try_find_last`] if the predicate might throw an error.
831    ///
832    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
833    #[cfg(js_sys_unstable_apis)]
834    #[wasm_bindgen(method, js_name = findLast)]
835    pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32) -> bool) -> Option<T>;
836
837    /// The `findLast()` method of Array instances iterates the array in reverse order
838    /// and returns the value of the first element that satisfies the provided testing function.
839    /// If no elements satisfy the testing function, undefined is returned. _(Fallible variation)_
840    ///
841    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
842    #[wasm_bindgen(method, js_name = findLast, catch)]
843    pub fn try_find_last<T>(
844        this: &Array<T>,
845        predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
846    ) -> Result<Option<T>, JsValue>;
847
848    /// The `findLastIndex()` method of Array instances iterates the array in reverse order
849    /// and returns the index of the first element that satisfies the provided testing function.
850    /// If no elements satisfy the testing function, -1 is returned.
851    ///
852    /// **Note:** Consider using [`Array::try_find_last_index`] if the predicate might throw an error.
853    ///
854    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
855    #[wasm_bindgen(method, js_name = findLastIndex)]
856    pub fn find_last_index<T>(
857        this: &Array<T>,
858        predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
859    ) -> i32;
860
861    /// The `findLastIndex()` method of Array instances iterates the array in reverse order
862    /// and returns the index of the first element that satisfies the provided testing function.
863    /// If no elements satisfy the testing function, -1 is returned. _(Fallible variation)_
864    ///
865    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
866    #[wasm_bindgen(method, js_name = findLastIndex, catch)]
867    pub fn try_find_last_index<T>(
868        this: &Array<T>,
869        predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
870    ) -> Result<i32, JsValue>;
871
872    /// The `flat()` method creates a new array with all sub-array elements concatenated into it
873    /// recursively up to the specified depth.
874    ///
875    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
876    #[wasm_bindgen(method)]
877    pub fn flat<T>(this: &Array<T>, depth: i32) -> Array<JsValue>;
878
879    /// The `flatMap()` method first maps each element using a mapping function, then flattens
880    /// the result into a new array.
881    ///
882    /// **Note:** Consider using [`Array::try_flat_map`] for safer fallible handling.
883    ///
884    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
885    #[wasm_bindgen(method, js_name = flatMap)]
886    pub fn flat_map<T, U>(
887        this: &Array<T>,
888        callback: &mut dyn FnMut(T, u32, Array<T>) -> Vec<U>,
889    ) -> Array<U>;
890
891    /// The `flatMap()` method first maps each element using a mapping function, then flattens
892    /// the result into a new array.
893    ///
894    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
895    #[wasm_bindgen(method, js_name = flatMap, catch)]
896    pub fn try_flat_map<T, U>(
897        this: &Array<T>,
898        callback: &mut dyn FnMut(T, u32) -> Vec<U>,
899    ) -> Result<Array<U>, JsValue>;
900
901    /// The `forEach()` method executes a provided function once for each array element.
902    ///
903    /// **Note:** Consider using [`Array::try_for_each`] if the callback might throw an error.
904    ///
905    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
906    #[wasm_bindgen(method, js_name = forEach)]
907    pub fn for_each<T: JsGeneric>(this: &Array<T>, callback: &mut dyn FnMut(T, u32, Array<T>));
908
909    /// The `forEach()` method executes a provided function once for each array element. _(Fallible variation)_
910    ///
911    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
912    #[wasm_bindgen(method, js_name = forEach, catch)]
913    pub fn try_for_each<T>(
914        this: &Array<T>,
915        callback: &mut dyn FnMut(T, u32) -> Result<(), JsError>,
916    ) -> Result<(), JsValue>;
917
918    /// The `includes()` method determines whether an array includes a certain
919    /// element, returning true or false as appropriate.
920    ///
921    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
922    #[wasm_bindgen(method)]
923    pub fn includes<T>(this: &Array<T>, value: &T, from_index: i32) -> bool;
924
925    /// The `indexOf()` method returns the first index at which a given element
926    /// can be found in the array, or -1 if it is not present.
927    ///
928    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
929    #[wasm_bindgen(method, js_name = indexOf)]
930    pub fn index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
931
932    /// The `Array.isArray()` method determines whether the passed value is an Array.
933    ///
934    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)
935    #[wasm_bindgen(static_method_of = Array, js_name = isArray)]
936    pub fn is_array(value: &JsValue) -> bool;
937
938    /// The `join()` method joins all elements of an array (or an array-like object)
939    /// into a string and returns this string.
940    ///
941    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
942    #[wasm_bindgen(method)]
943    pub fn join<T>(this: &Array<T>, delimiter: &str) -> JsString;
944
945    /// The `lastIndexOf()` method returns the last index at which a given element
946    /// can be found in the array, or -1 if it is not present. The array is
947    /// searched backwards, starting at fromIndex.
948    ///
949    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
950    #[wasm_bindgen(method, js_name = lastIndexOf)]
951    pub fn last_index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
952
953    /// The length property of an object which is an instance of type Array
954    /// sets or returns the number of elements in that array. The value is an
955    /// unsigned, 32-bit integer that is always numerically greater than the
956    /// highest index in the array.
957    ///
958    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
959    #[wasm_bindgen(method, getter)]
960    pub fn length<T>(this: &Array<T>) -> u32;
961
962    /// Sets the length of the array.
963    ///
964    /// If it is set to less than the current length of the array, it will
965    /// shrink the array.
966    ///
967    /// If it is set to more than the current length of the array, it will
968    /// increase the length of the array, filling the new space with empty
969    /// slots.
970    ///
971    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
972    #[wasm_bindgen(method, setter)]
973    pub fn set_length<T>(this: &Array<T>, value: u32);
974
975    /// `map()` calls a provided callback function once for each element in an array,
976    /// in order, and constructs a new array from the results. callback is invoked
977    /// only for indexes of the array which have assigned values, including undefined.
978    /// It is not called for missing elements of the array (that is, indexes that have
979    /// never been set, which have been deleted or which have never been assigned a value).
980    ///
981    /// **Note:** Consider using [`Array::try_map`] for safer fallible handling.
982    ///
983    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
984    #[wasm_bindgen(method)]
985    pub fn map<T, U>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> U)
986        -> Array<U>;
987
988    /// `map()` calls a provided callback function once for each element in an array,
989    /// in order, and constructs a new array from the results. callback is invoked
990    /// only for indexes of the array which have assigned values, including undefined.
991    /// It is not called for missing elements of the array (that is, indexes that have
992    /// never been set, which have been deleted or which have never been assigned a value).
993    /// _(Fallible variation)_
994    ///
995    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
996    #[wasm_bindgen(method, js_name = map, catch)]
997    pub fn try_map<T, U>(
998        this: &Array<T>,
999        predicate: &mut dyn FnMut(T, u32) -> Result<U, JsError>,
1000    ) -> Result<Array<U>, JsValue>;
1001
1002    /// The `Array.of()` method creates a new Array instance with a variable
1003    /// number of arguments, regardless of number or type of the arguments.
1004    ///
1005    /// Note: For type inference use `Array::<T>::of(&[T])`.
1006    ///
1007    /// The difference between `Array.of()` and the `Array` constructor is in the
1008    /// handling of integer arguments: `Array.of(7)` creates an array with a single
1009    /// element, `7`, whereas `Array(7)` creates an empty array with a `length`
1010    /// property of `7` (Note: this implies an array of 7 empty slots, not slots
1011    /// with actual undefined values).
1012    ///
1013    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1014    #[wasm_bindgen(static_method_of = Array, js_name = of, variadic)]
1015    pub fn of<T>(values: &[T]) -> Array<T>;
1016
1017    // Next major: deprecate these
1018    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1019    #[wasm_bindgen(static_method_of = Array, js_name = of)]
1020    pub fn of1(a: &JsValue) -> Array;
1021
1022    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1023    #[wasm_bindgen(static_method_of = Array, js_name = of)]
1024    pub fn of2(a: &JsValue, b: &JsValue) -> Array;
1025
1026    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1027    #[wasm_bindgen(static_method_of = Array, js_name = of)]
1028    pub fn of3(a: &JsValue, b: &JsValue, c: &JsValue) -> Array;
1029
1030    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1031    #[wasm_bindgen(static_method_of = Array, js_name = of)]
1032    pub fn of4(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue) -> Array;
1033
1034    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1035    #[wasm_bindgen(static_method_of = Array, js_name = of)]
1036    pub fn of5(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue, e: &JsValue) -> Array;
1037
1038    /// The `pop()` method removes the last element from an array and returns that
1039    /// element. This method changes the length of the array.
1040    ///
1041    /// **Note:** Consider using [`Array::pop_checked`] for handling empty arrays.
1042    ///
1043    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
1044    #[cfg(not(js_sys_unstable_apis))]
1045    #[wasm_bindgen(method)]
1046    pub fn pop<T>(this: &Array<T>) -> T;
1047
1048    /// The `pop()` method removes the last element from an array and returns that
1049    /// element. This method changes the length of the array.
1050    /// Returns `None` if the array is empty.
1051    ///
1052    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
1053    #[cfg(js_sys_unstable_apis)]
1054    #[wasm_bindgen(method)]
1055    pub fn pop<T>(this: &Array<T>) -> Option<T>;
1056
1057    // Next major: deprecate
1058    /// The `pop()` method removes the last element from an array and returns that
1059    /// element. This method changes the length of the array.
1060    ///
1061    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
1062    #[wasm_bindgen(method, js_name = pop)]
1063    pub fn pop_checked<T>(this: &Array<T>) -> Option<T>;
1064
1065    /// The `push()` method adds one element to the end of an array and
1066    /// returns the new length of the array.
1067    ///
1068    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
1069    #[wasm_bindgen(method)]
1070    pub fn push<T>(this: &Array<T>, value: &T) -> u32;
1071
1072    /// The `push()` method adds one or more elements to the end of an array and
1073    /// returns the new length of the array.
1074    ///
1075    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
1076    #[wasm_bindgen(method, js_name = push, variadic)]
1077    pub fn push_many<T>(this: &Array<T>, values: &[T]) -> u32;
1078
1079    /// The `reduce()` method applies a function against an accumulator and each element in
1080    /// the array (from left to right) to reduce it to a single value.
1081    ///
1082    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1083    #[cfg(not(js_sys_unstable_apis))]
1084    #[wasm_bindgen(method)]
1085    pub fn reduce<T>(
1086        this: &Array<T>,
1087        predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
1088        initial_value: &JsValue,
1089    ) -> JsValue;
1090
1091    /// The `reduce()` method applies a function against an accumulator and each element in
1092    /// the array (from left to right) to reduce it to a single value.
1093    ///
1094    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1095    #[cfg(js_sys_unstable_apis)]
1096    #[wasm_bindgen(method)]
1097    pub fn reduce<T, A>(
1098        this: &Array<T>,
1099        predicate: &mut dyn FnMut(A, T, u32, Array<T>) -> A,
1100        initial_value: &A,
1101    ) -> A;
1102
1103    /// The `reduce()` method applies a function against an accumulator and each element in
1104    /// the array (from left to right) to reduce it to a single value. _(Fallible variation)_
1105    ///
1106    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1107    #[wasm_bindgen(method, js_name = reduce, catch)]
1108    pub fn try_reduce<T, A>(
1109        this: &Array<T>,
1110        predicate: &mut dyn FnMut(A, T, u32) -> Result<A, JsError>,
1111        initial_value: &A,
1112    ) -> Result<A, JsValue>;
1113
1114    /// The `reduceRight()` method applies a function against an accumulator and each value
1115    /// of the array (from right-to-left) to reduce it to a single value.
1116    ///
1117    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1118    #[cfg(not(js_sys_unstable_apis))]
1119    #[wasm_bindgen(method, js_name = reduceRight)]
1120    pub fn reduce_right<T>(
1121        this: &Array<T>,
1122        predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
1123        initial_value: &JsValue,
1124    ) -> JsValue;
1125
1126    /// The `reduceRight()` method applies a function against an accumulator and each value
1127    /// of the array (from right-to-left) to reduce it to a single value.
1128    ///
1129    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1130    #[cfg(js_sys_unstable_apis)]
1131    #[wasm_bindgen(method, js_name = reduceRight)]
1132    pub fn reduce_right<T, A>(
1133        this: &Array<T>,
1134        predicate: &mut dyn FnMut(A, T, u32, Array<T>) -> A,
1135        initial_value: &A,
1136    ) -> A;
1137
1138    /// The `reduceRight()` method applies a function against an accumulator and each value
1139    /// of the array (from right-to-left) to reduce it to a single value. _(Fallible variation)_
1140    ///
1141    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1142    #[wasm_bindgen(method, js_name = reduceRight, catch)]
1143    pub fn try_reduce_right<T, A>(
1144        this: &Array<T>,
1145        predicate: &mut dyn FnMut(JsValue, T, u32) -> Result<A, JsError>,
1146        initial_value: &A,
1147    ) -> Result<A, JsValue>;
1148
1149    /// The `reverse()` method reverses an array in place. The first array
1150    /// element becomes the last, and the last array element becomes the first.
1151    ///
1152    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
1153    #[wasm_bindgen(method)]
1154    pub fn reverse<T>(this: &Array<T>) -> Array<T>;
1155
1156    /// The `shift()` method removes the first element from an array and returns
1157    /// that removed element. This method changes the length of the array.
1158    ///
1159    /// **Note:** Consider using [`Array::shift_checked`] for handling empty arrays.
1160    ///
1161    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1162    #[cfg(not(js_sys_unstable_apis))]
1163    #[wasm_bindgen(method)]
1164    pub fn shift<T>(this: &Array<T>) -> T;
1165
1166    /// The `shift()` method removes the first element from an array and returns
1167    /// that removed element. This method changes the length of the array.
1168    /// Returns `None` if the array is empty.
1169    ///
1170    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1171    #[cfg(js_sys_unstable_apis)]
1172    #[wasm_bindgen(method)]
1173    pub fn shift<T>(this: &Array<T>) -> Option<T>;
1174
1175    // Next major: deprecate
1176    /// The `shift()` method removes the first element from an array and returns
1177    /// that removed element. This method changes the length of the array.
1178    ///
1179    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1180    #[wasm_bindgen(method, js_name = shift)]
1181    pub fn shift_checked<T>(this: &Array<T>) -> Option<T>;
1182
1183    /// The `slice()` method returns a shallow copy of a portion of an array into
1184    /// a new array object selected from begin to end (end not included).
1185    /// The original array will not be modified.
1186    ///
1187    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1188    #[cfg(not(js_sys_unstable_apis))]
1189    #[wasm_bindgen(method)]
1190    pub fn slice<T>(this: &Array<T>, start: u32, end: u32) -> Array<T>;
1191
1192    /// The `slice()` method returns a shallow copy of a portion of an array into
1193    /// a new array object selected from begin to end (end not included).
1194    /// The original array will not be modified. Negative indices count from the end.
1195    ///
1196    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1197    #[cfg(js_sys_unstable_apis)]
1198    #[wasm_bindgen(method)]
1199    pub fn slice<T>(this: &Array<T>, start: i32, end: i32) -> Array<T>;
1200
1201    /// The `slice()` method returns a shallow copy of a portion of an array into
1202    /// a new array object selected from the given index to the end.
1203    /// The original array will not be modified.
1204    ///
1205    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1206    #[cfg(not(js_sys_unstable_apis))]
1207    #[wasm_bindgen(method, js_name = slice)]
1208    pub fn slice_from<T>(this: &Array<T>, start: u32) -> Array<T>;
1209
1210    /// The `slice()` method returns a shallow copy of a portion of an array into
1211    /// a new array object selected from the given index to the end.
1212    /// The original array will not be modified. Negative indices count from the end.
1213    ///
1214    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1215    #[cfg(js_sys_unstable_apis)]
1216    #[wasm_bindgen(method, js_name = slice)]
1217    pub fn slice_from<T>(this: &Array<T>, start: i32) -> Array<T>;
1218
1219    /// The `some()` method tests whether at least one element in the array passes the test implemented
1220    /// by the provided function.
1221    /// Note: This method returns false for any condition put on an empty array.
1222    ///
1223    /// **Note:** Consider using [`Array::try_some`] if the predicate might throw an error.
1224    ///
1225    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1226    #[wasm_bindgen(method)]
1227    pub fn some<T>(this: &Array<T>, predicate: &mut dyn FnMut(T) -> bool) -> bool;
1228
1229    /// The `some()` method tests whether at least one element in the array passes the test implemented
1230    /// by the provided function. _(Fallible variation)_
1231    /// Note: This method returns false for any condition put on an empty array.
1232    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1233    #[wasm_bindgen(method, js_name = some, catch)]
1234    pub fn try_some<T>(
1235        this: &Array<T>,
1236        predicate: &mut dyn FnMut(T) -> Result<bool, JsError>,
1237    ) -> Result<bool, JsValue>;
1238
1239    /// The `sort()` method sorts the elements of an array in place and returns
1240    /// the array. The sort is not necessarily stable. The default sort
1241    /// order is according to string Unicode code points.
1242    ///
1243    /// The time and space complexity of the sort cannot be guaranteed as it
1244    /// is implementation dependent.
1245    ///
1246    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1247    #[wasm_bindgen(method)]
1248    pub fn sort<T>(this: &Array<T>) -> Array<T>;
1249
1250    /// The `sort()` method with a custom compare function.
1251    ///
1252    /// **Note:** Consider using [`Array::try_sort_by`] if the predicate might throw an error.
1253    ///
1254    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1255    #[wasm_bindgen(method, js_name = sort)]
1256    pub fn sort_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1257
1258    /// The `sort()` method with a custom compare function. _(Fallible variation)_
1259    ///
1260    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1261    #[wasm_bindgen(method, js_name = sort, catch)]
1262    pub fn try_sort_by<T>(
1263        this: &Array<T>,
1264        compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>,
1265    ) -> Result<Array<T>, JsValue>;
1266
1267    /// The `splice()` method changes the contents of an array by removing existing elements and/or
1268    /// adding new elements.
1269    ///
1270    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1271    #[wasm_bindgen(method)]
1272    pub fn splice<T>(this: &Array<T>, start: u32, delete_count: u32, item: &T) -> Array<T>;
1273
1274    /// The `splice()` method changes the contents of an array by removing existing elements and/or
1275    /// adding new elements.
1276    ///
1277    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1278    #[wasm_bindgen(method, js_name = splice, variadic)]
1279    pub fn splice_many<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1280
1281    /// The `toLocaleString()` method returns a string representing the elements of the array.
1282    /// The elements are converted to Strings using their toLocaleString methods and these
1283    /// Strings are separated by a locale-specific String (such as a comma ",").
1284    ///
1285    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1286    #[cfg(not(js_sys_unstable_apis))]
1287    #[wasm_bindgen(method, js_name = toLocaleString)]
1288    pub fn to_locale_string<T>(this: &Array<T>, locales: &JsValue, options: &JsValue) -> JsString;
1289
1290    /// The `toLocaleString()` method returns a string representing the elements of the array.
1291    /// The elements are converted to Strings using their toLocaleString methods and these
1292    /// Strings are separated by a locale-specific String (such as a comma ",").
1293    ///
1294    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1295    #[cfg(js_sys_unstable_apis)]
1296    #[wasm_bindgen(method, js_name = toLocaleString)]
1297    pub fn to_locale_string<T>(
1298        this: &Array<T>,
1299        locales: &[JsString],
1300        options: &Intl::NumberFormatOptions,
1301    ) -> JsString;
1302
1303    /// The `toReversed()` method returns a new array with the elements in reversed order,
1304    /// without modifying the original array.
1305    ///
1306    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed)
1307    #[wasm_bindgen(method, js_name = toReversed)]
1308    pub fn to_reversed<T>(this: &Array<T>) -> Array<T>;
1309
1310    /// The `toSorted()` method returns a new array with the elements sorted in ascending order,
1311    /// without modifying the original array.
1312    ///
1313    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1314    #[wasm_bindgen(method, js_name = toSorted)]
1315    pub fn to_sorted<T>(this: &Array<T>) -> Array<T>;
1316
1317    /// The `toSorted()` method with a custom compare function.
1318    ///
1319    /// **Note:** Consider using [`Array::try_to_sorted_by`] if the predicate might throw an error.
1320    ///
1321    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1322    #[wasm_bindgen(method, js_name = toSorted)]
1323    pub fn to_sorted_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1324
1325    /// The `toSorted()` method with a custom compare function. _(Fallible variation)_
1326    ///
1327    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1328    #[wasm_bindgen(method, js_name = toSorted, catch)]
1329    pub fn try_to_sorted_by<T>(
1330        this: &Array<T>,
1331        compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>,
1332    ) -> Result<Array<T>, JsValue>;
1333
1334    /// The `toSpliced()` method returns a new array with some elements removed and/or
1335    /// replaced at a given index, without modifying the original array.
1336    ///
1337    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced)
1338    #[wasm_bindgen(method, js_name = toSpliced, variadic)]
1339    pub fn to_spliced<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1340
1341    /// The `toString()` method returns a string representing the specified array
1342    /// and its elements.
1343    ///
1344    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)
1345    #[cfg(not(js_sys_unstable_apis))]
1346    #[wasm_bindgen(method, js_name = toString)]
1347    pub fn to_string<T>(this: &Array<T>) -> JsString;
1348
1349    /// Converts the Array into a Vector.
1350    #[wasm_bindgen(method, js_name = slice)]
1351    pub fn to_vec<T>(this: &Array<T>) -> Vec<T>;
1352
1353    /// The `unshift()` method adds one element to the beginning of an
1354    /// array and returns the new length of the array.
1355    ///
1356    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1357    #[wasm_bindgen(method)]
1358    pub fn unshift<T>(this: &Array<T>, value: &T) -> u32;
1359
1360    /// The `unshift()` method adds one or more elements to the beginning of an
1361    /// array and returns the new length of the array.
1362    ///
1363    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1364    #[wasm_bindgen(method, js_name = unshift, variadic)]
1365    pub fn unshift_many<T>(this: &Array<T>, values: &[T]) -> u32;
1366
1367    /// The `with()` method returns a new array with the element at the given index
1368    /// replaced with the given value, without modifying the original array.
1369    ///
1370    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/with)
1371    #[wasm_bindgen(method, js_name = with)]
1372    pub fn with<T>(this: &Array<T>, index: u32, value: &T) -> Array<T>;
1373}
1374
1375// Tuples as a typed array variant
1376#[wasm_bindgen]
1377extern "C" {
1378    #[wasm_bindgen(extends = Object, js_name = Array, is_type_of = Array::is_array, no_upcast, typescript_type = "Array<any>")]
1379    #[derive(Clone, Debug)]
1380    pub type ArrayTuple<T: JsTuple = (JsValue,)>;
1381
1382    /// Creates a new JS array typed as a 1-tuple.
1383    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1384    pub fn new1<T1>(t1: &T1) -> ArrayTuple<(T1,)>;
1385
1386    /// Creates a new JS array typed as a 2-tuple.
1387    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1388    pub fn new2<T1, T2>(t1: &T1, t2: &T2) -> ArrayTuple<(T1, T2)>;
1389
1390    /// Creates a new JS array typed as a 3-tuple.
1391    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1392    pub fn new3<T1, T2, T3>(t1: &T1, t2: &T2, t3: &T3) -> ArrayTuple<(T1, T2, T3)>;
1393
1394    /// Creates a new JS array typed as a 4-tuple.
1395    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1396    pub fn new4<T1, T2, T3, T4>(t1: &T1, t2: &T2, t3: &T3, t4: &T4)
1397        -> ArrayTuple<(T1, T2, T3, T4)>;
1398
1399    /// Creates a new JS array typed as a 5-tuple.
1400    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1401    pub fn new5<T1, T2, T3, T4, T5>(
1402        t1: &T1,
1403        t2: &T2,
1404        t3: &T3,
1405        t4: &T4,
1406        t5: &T5,
1407    ) -> ArrayTuple<(T1, T2, T3, T4, T5)>;
1408
1409    /// Creates a new JS array typed as a 6-tuple.
1410    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1411    pub fn new6<T1, T2, T3, T4, T5, T6>(
1412        t1: &T1,
1413        t2: &T2,
1414        t3: &T3,
1415        t4: &T4,
1416        t5: &T5,
1417        t6: &T6,
1418    ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6)>;
1419
1420    /// Creates a new JS array typed as a 7-tuple.
1421    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1422    pub fn new7<T1, T2, T3, T4, T5, T6, T7>(
1423        t1: &T1,
1424        t2: &T2,
1425        t3: &T3,
1426        t4: &T4,
1427        t5: &T5,
1428        t6: &T6,
1429        t7: &T7,
1430    ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7)>;
1431
1432    /// Creates a new JS array typed as a 8-tuple.
1433    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1434    pub fn new8<T1, T2, T3, T4, T5, T6, T7, T8>(
1435        t1: &T1,
1436        t2: &T2,
1437        t3: &T3,
1438        t4: &T4,
1439        t5: &T5,
1440        t6: &T6,
1441        t7: &T7,
1442        t8: &T8,
1443    ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7, T8)>;
1444
1445    /// Gets the 1st item
1446    #[wasm_bindgen(
1447        method,
1448        js_class = Array,
1449        getter,
1450        js_name = "0"
1451    )]
1452    pub fn get0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>) -> <T as JsTuple1>::T1;
1453
1454    /// Gets the 2nd item
1455    #[wasm_bindgen(
1456        method,
1457        js_class = Array,
1458        getter,
1459        js_name = "1"
1460    )]
1461    pub fn get1<T: JsTuple2 = (JsValue, JsValue)>(this: &ArrayTuple<T>) -> <T as JsTuple2>::T2;
1462
1463    /// Gets the 3rd item
1464    #[wasm_bindgen(
1465        method,
1466        js_class = Array,
1467        getter,
1468        js_name = "2"
1469    )]
1470    pub fn get2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1471        this: &ArrayTuple<T>,
1472    ) -> <T as JsTuple3>::T3;
1473
1474    /// Gets the 4th item
1475    #[wasm_bindgen(
1476        method,
1477        js_class = Array,
1478        getter,
1479        js_name = "3"
1480    )]
1481    pub fn get3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1482        this: &ArrayTuple<T>,
1483    ) -> <T as JsTuple4>::T4;
1484
1485    /// Gets the 5th item
1486    #[wasm_bindgen(
1487        method,
1488        js_class = Array,
1489        getter,
1490        js_name = "4"
1491    )]
1492    pub fn get4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1493        this: &ArrayTuple<T>,
1494    ) -> <T as JsTuple5>::T5;
1495
1496    /// Gets the 6th item
1497    #[wasm_bindgen(
1498        method,
1499        js_class = Array,
1500        getter,
1501        js_name = "5"
1502    )]
1503    pub fn get5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1504        this: &ArrayTuple<T>,
1505    ) -> <T as JsTuple6>::T6;
1506
1507    /// Gets the 7th item
1508    #[wasm_bindgen(
1509        method,
1510        js_class = Array,
1511        getter,
1512        js_name = "6"
1513    )]
1514    pub fn get6<
1515        T: JsTuple7 = (
1516            JsValue,
1517            JsValue,
1518            JsValue,
1519            JsValue,
1520            JsValue,
1521            JsValue,
1522            JsValue,
1523        ),
1524    >(
1525        this: &ArrayTuple<T>,
1526    ) -> <T as JsTuple7>::T7;
1527
1528    /// Gets the 8th item
1529    #[wasm_bindgen(
1530        method,
1531        js_class = Array,
1532        getter,
1533        js_name = "7"
1534    )]
1535    pub fn get7<
1536        T: JsTuple8 = (
1537            JsValue,
1538            JsValue,
1539            JsValue,
1540            JsValue,
1541            JsValue,
1542            JsValue,
1543            JsValue,
1544            JsValue,
1545        ),
1546    >(
1547        this: &ArrayTuple<T>,
1548    ) -> <T as JsTuple8>::T8;
1549
1550    /// Sets the 1st item
1551    #[wasm_bindgen(
1552        method,
1553        js_class = Array,
1554        setter,
1555        js_name = "0"
1556    )]
1557    pub fn set0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>, value: &<T as JsTuple1>::T1);
1558
1559    /// Sets the 2nd item
1560    #[wasm_bindgen(
1561        method,
1562        js_class = Array,
1563        setter,
1564        js_name = "1"
1565    )]
1566    pub fn set1<T: JsTuple2 = (JsValue, JsValue)>(
1567        this: &ArrayTuple<T>,
1568        value: &<T as JsTuple2>::T2,
1569    );
1570
1571    /// Sets the 3rd item
1572    #[wasm_bindgen(
1573        method,
1574        js_class = Array,
1575        setter,
1576        js_name = "2"
1577    )]
1578    pub fn set2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1579        this: &ArrayTuple<T>,
1580        value: &<T as JsTuple3>::T3,
1581    );
1582
1583    /// Sets the 4th item
1584    #[wasm_bindgen(
1585        method,
1586        js_class = Array,
1587        setter,
1588        js_name = "3"
1589    )]
1590    pub fn set3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1591        this: &ArrayTuple<T>,
1592        value: &<T as JsTuple4>::T4,
1593    );
1594
1595    /// Sets the 5th item
1596    #[wasm_bindgen(
1597        method,
1598        js_class = Array,
1599        setter,
1600        js_name = "4"
1601    )]
1602    pub fn set4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1603        this: &ArrayTuple<T>,
1604        value: &<T as JsTuple5>::T5,
1605    );
1606
1607    /// Sets the 6th item
1608    #[wasm_bindgen(
1609        method,
1610        js_class = Array,
1611        setter,
1612        js_name = "5"
1613    )]
1614    pub fn set5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1615        this: &ArrayTuple<T>,
1616        value: &<T as JsTuple6>::T6,
1617    );
1618
1619    /// Sets the 7th item
1620    #[wasm_bindgen(
1621        method,
1622        js_class = Array,
1623        setter,
1624        js_name = "6"
1625    )]
1626    pub fn set6<
1627        T: JsTuple7 = (
1628            JsValue,
1629            JsValue,
1630            JsValue,
1631            JsValue,
1632            JsValue,
1633            JsValue,
1634            JsValue,
1635        ),
1636    >(
1637        this: &ArrayTuple<T>,
1638        value: &<T as JsTuple7>::T7,
1639    );
1640
1641    /// Sets the 8th item
1642    #[wasm_bindgen(
1643        method,
1644        js_class = Array,
1645        setter,
1646        js_name = "7"
1647    )]
1648    pub fn set7<
1649        T: JsTuple8 = (
1650            JsValue,
1651            JsValue,
1652            JsValue,
1653            JsValue,
1654            JsValue,
1655            JsValue,
1656            JsValue,
1657            JsValue,
1658        ),
1659    >(
1660        this: &ArrayTuple<T>,
1661        value: &<T as JsTuple8>::T8,
1662    );
1663}
1664
1665/// Base trait for tuple types.
1666pub trait JsTuple {
1667    const ARITY: usize;
1668}
1669
1670macro_rules! impl_tuple_traits {
1671    // Base case: first trait has no parent (besides JsTuple)
1672    ($name:ident $ty:tt) => {
1673        pub trait $name: JsTuple {
1674            type $ty;
1675        }
1676    };
1677
1678    // Recursive case: define trait with parent, then recurse
1679    ($name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1680        pub trait $name: JsTuple {
1681            type $ty;
1682        }
1683
1684        impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1685    };
1686
1687    // Internal: traits that have a parent
1688    (@with_parent $trait:ident $name:ident $ty:tt) => {
1689        pub trait $name: $trait {
1690            type $ty;
1691        }
1692    };
1693
1694    (@with_parent $trait:ident $name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1695        pub trait $name: $trait {
1696            type $ty;
1697        }
1698
1699        impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1700    };
1701}
1702
1703macro_rules! impl_parent_traits {
1704    ([$($types:tt),+] [] []) => {};
1705
1706    ([$($types:tt),+] [$trait:ident $($rest_traits:ident)*] [$ty:tt $($rest_tys:tt)*]) => {
1707        impl<$($types),+> $trait for ($($types),+,) {
1708            type $ty = $ty;
1709        }
1710
1711        impl_parent_traits!([$($types),+] [$($rest_traits)*] [$($rest_tys)*]);
1712    };
1713}
1714
1715// Define the trait hierarchy once
1716impl_tuple_traits!(
1717    JsTuple1 T1
1718    JsTuple2 T2
1719    JsTuple3 T3
1720    JsTuple4 T4
1721    JsTuple5 T5
1722    JsTuple6 T6
1723    JsTuple7 T7
1724    JsTuple8 T8
1725);
1726
1727impl<T: JsTuple> ArrayTuple<T> {
1728    /// Get the static arity of the ArrayTuple type.
1729    #[allow(clippy::len_without_is_empty)]
1730    pub fn len(&self) -> usize {
1731        <T as JsTuple>::ARITY
1732    }
1733}
1734
1735macro_rules! impl_tuple {
1736    ($arity:literal [$($traits:ident)*] [$($T:tt)+] [$($vars:tt)+] $new:ident $last:ident $last_ty:tt) => {
1737        impl<$($T),+> JsTuple for ($($T),+,) {
1738            const ARITY: usize = $arity;
1739        }
1740
1741        impl_parent_traits!([$($T),+] [$($traits)*] [$($T)*]);
1742
1743        impl<$($T: JsGeneric),+> From<($($T,)+)> for ArrayTuple<($($T),+,)> {
1744            fn from(($($vars,)+): ($($T,)+)) -> Self {
1745                $(let $vars: JsValue = $vars.upcast_into();)+
1746                Array::of(&[$($vars),+]).unchecked_into()
1747            }
1748        }
1749
1750        impl<$($T: JsGeneric + Default),+> Default for ArrayTuple<($($T),+,)> {
1751            fn default() -> Self {
1752                (
1753                    $($T::default(),)+
1754                ).into()
1755            }
1756        }
1757
1758        impl<$($T: JsGeneric),+> ArrayTuple<($($T),+,)> {
1759            /// Get the first element of the ArrayTuple
1760            pub fn first(&self) -> T1 {
1761                self.get0()
1762            }
1763
1764            /// Get the last element of the ArrayTuple
1765            pub fn last(&self) -> $last_ty {
1766                self.$last()
1767            }
1768
1769            /// Convert the ArrayTuple into its corresponding Rust tuple.
1770            pub fn into_tuple(self) -> ($($T,)+) {
1771                ($(self.$vars(),)+)
1772            }
1773
1774            /// Deprecated alias for [`ArrayTuple::into_tuple`].
1775            #[deprecated(note = "renamed to `into_tuple`")]
1776            pub fn into_parts(self) -> ($($T,)+) {
1777                self.into_tuple()
1778            }
1779
1780            /// Create a new ArrayTuple from the corresponding parts.
1781            ///
1782            /// # Example
1783            ///
1784            /// ```
1785            /// use js_sys::{ArrayTuple, JsString};
1786            ///
1787            /// let tuple = ArrayTuple::<JsString, JsString>::new(&"a".into(), &"b".into());
1788            /// ```
1789            ///
1790            /// Note: You must specify the T using `::<...>` syntax on `ArrayTuple`.
1791            /// Alternatively, use `new1`, `new2`, etc. for type inference from the left-hand side.
1792            pub fn new($($vars: &$T),+) -> ArrayTuple<($($T),+,)> {
1793                ArrayTuple::$new($($vars),+)
1794            }
1795        }
1796    };
1797}
1798
1799// Implement for each tuple size
1800impl_tuple!(1 [JsTuple1] [T1] [get0] new1 get0 T1);
1801impl_tuple!(2 [JsTuple1 JsTuple2] [T1 T2] [get0 get1] new2 get1 T2);
1802impl_tuple!(3 [JsTuple1 JsTuple2 JsTuple3] [T1 T2 T3] [get0 get1 get2] new3 get2 T3);
1803impl_tuple!(4 [JsTuple1 JsTuple2 JsTuple3 JsTuple4] [T1 T2 T3 T4] [get0 get1 get2 get3] new4 get3 T4);
1804impl_tuple!(5 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5] [T1 T2 T3 T4 T5] [get0 get1 get2 get3 get4] new5 get4 T5);
1805impl_tuple!(6 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5 JsTuple6] [T1 T2 T3 T4 T5 T6] [get0 get1 get2 get3 get4 get5] new6 get5 T6);
1806impl_tuple!(7 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5 JsTuple6 JsTuple7] [T1 T2 T3 T4 T5 T6 T7] [get0 get1 get2 get3 get4 get5 get6] new7 get6 T7);
1807impl_tuple!(8 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5 JsTuple6 JsTuple7 JsTuple8] [T1 T2 T3 T4 T5 T6 T7 T8] [get0 get1 get2 get3 get4 get5 get6 get7] new8 get7 T8);
1808
1809// Macro to generate structural covariance impls for each arity
1810macro_rules! impl_tuple_covariance {
1811    ([$($T:ident)+] [$($Target:ident)+]) => {
1812        // ArrayTuple -> Array
1813        // Allows (T1, T2, ...) to be used where (Target) is expected
1814        // when all T1, T2, ... are covariant to Target
1815        impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for Array<Target>
1816        where
1817            $(Target: UpcastFrom<$T>,)+
1818        {
1819        }
1820        impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for JsOption<Array<Target>>
1821        where
1822            $(Target: UpcastFrom<$T>,)+
1823        {}
1824        impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for JsNullable<Array<Target>>
1825        where
1826            $(Target: UpcastFrom<$T>,)+
1827        {}
1828    };
1829}
1830
1831impl_tuple_covariance!([T1][Target1]);
1832impl_tuple_covariance!([T1 T2] [Target1 Target2]);
1833impl_tuple_covariance!([T1 T2 T3] [Target1 Target2 Target3]);
1834impl_tuple_covariance!([T1 T2 T3 T4] [Target1 Target2 Target3 Target4]);
1835impl_tuple_covariance!([T1 T2 T3 T4 T5] [Target1 Target2 Target3 Target4 Target5]);
1836impl_tuple_covariance!([T1 T2 T3 T4 T5 T6] [Target1 Target2 Target3 Target4 Target5 Target6]);
1837impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7] [Target1 Target2 Target3 Target4 Target5 Target6 Target7]);
1838impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7 T8] [Target1 Target2 Target3 Target4 Target5 Target6 Target7 Target8]);
1839
1840// Tuple casting is implemented in core
1841impl<T: JsTuple, U: JsTuple> UpcastFrom<ArrayTuple<T>> for ArrayTuple<U> where U: UpcastFrom<T> {}
1842impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsValue {}
1843impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsOption<JsValue> {}
1844impl<T: JsTuple, Target: UpcastFrom<ArrayTuple<T>>> UpcastFrom<ArrayTuple<T>> for Option<Target> {}
1845impl<T: JsTuple, Target: UpcastFrom<ArrayTuple<T>>> UpcastFrom<ArrayTuple<T>> for Nullable<Target> {}
1846impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsNullable<JsValue> {}
1847
1848/// Iterator returned by `Array::into_iter`
1849#[derive(Debug, Clone)]
1850pub struct ArrayIntoIter<T: JsGeneric = JsValue> {
1851    range: core::ops::Range<u32>,
1852    array: Array<T>,
1853}
1854
1855#[cfg(not(js_sys_unstable_apis))]
1856impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1857    type Item = T;
1858
1859    fn next(&mut self) -> Option<Self::Item> {
1860        let index = self.range.next()?;
1861        Some(self.array.get(index))
1862    }
1863
1864    #[inline]
1865    fn size_hint(&self) -> (usize, Option<usize>) {
1866        self.range.size_hint()
1867    }
1868
1869    #[inline]
1870    fn count(self) -> usize
1871    where
1872        Self: Sized,
1873    {
1874        self.range.count()
1875    }
1876
1877    #[inline]
1878    fn last(self) -> Option<Self::Item>
1879    where
1880        Self: Sized,
1881    {
1882        let Self { range, array } = self;
1883        range.last().map(|index| array.get(index))
1884    }
1885
1886    #[inline]
1887    fn nth(&mut self, n: usize) -> Option<Self::Item> {
1888        self.range.nth(n).map(|index| self.array.get(index))
1889    }
1890}
1891
1892#[cfg(js_sys_unstable_apis)]
1893impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1894    type Item = T;
1895
1896    fn next(&mut self) -> Option<Self::Item> {
1897        let index = self.range.next()?;
1898        self.array.get(index)
1899    }
1900
1901    #[inline]
1902    fn size_hint(&self) -> (usize, Option<usize>) {
1903        self.range.size_hint()
1904    }
1905
1906    #[inline]
1907    fn count(self) -> usize
1908    where
1909        Self: Sized,
1910    {
1911        self.range.count()
1912    }
1913
1914    #[inline]
1915    fn last(self) -> Option<Self::Item>
1916    where
1917        Self: Sized,
1918    {
1919        let Self { range, array } = self;
1920        range.last().and_then(|index| array.get(index))
1921    }
1922
1923    #[inline]
1924    fn nth(&mut self, n: usize) -> Option<Self::Item> {
1925        self.range.nth(n).and_then(|index| self.array.get(index))
1926    }
1927}
1928
1929#[cfg(not(js_sys_unstable_apis))]
1930impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1931    fn next_back(&mut self) -> Option<Self::Item> {
1932        let index = self.range.next_back()?;
1933        Some(self.array.get(index))
1934    }
1935
1936    fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1937        self.range.nth_back(n).map(|index| self.array.get(index))
1938    }
1939}
1940
1941#[cfg(js_sys_unstable_apis)]
1942impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1943    fn next_back(&mut self) -> Option<Self::Item> {
1944        let index = self.range.next_back()?;
1945        self.array.get(index)
1946    }
1947
1948    fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1949        self.range
1950            .nth_back(n)
1951            .and_then(|index| self.array.get(index))
1952    }
1953}
1954
1955impl<T: JsGeneric> core::iter::FusedIterator for ArrayIntoIter<T> {}
1956
1957impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIntoIter<T> {}
1958
1959/// Iterator returned by `Array::iter`
1960#[derive(Debug, Clone)]
1961pub struct ArrayIter<'a, T: JsGeneric = JsValue> {
1962    range: core::ops::Range<u32>,
1963    array: &'a Array<T>,
1964}
1965
1966impl<T: JsGeneric> core::iter::Iterator for ArrayIter<'_, T> {
1967    type Item = T;
1968
1969    fn next(&mut self) -> Option<Self::Item> {
1970        let index = self.range.next()?;
1971        Some(self.array.get_unchecked(index))
1972    }
1973
1974    #[inline]
1975    fn size_hint(&self) -> (usize, Option<usize>) {
1976        self.range.size_hint()
1977    }
1978
1979    #[inline]
1980    fn count(self) -> usize
1981    where
1982        Self: Sized,
1983    {
1984        self.range.count()
1985    }
1986
1987    #[inline]
1988    fn last(self) -> Option<Self::Item>
1989    where
1990        Self: Sized,
1991    {
1992        let Self { range, array } = self;
1993        range.last().map(|index| array.get_unchecked(index))
1994    }
1995
1996    #[inline]
1997    fn nth(&mut self, n: usize) -> Option<Self::Item> {
1998        self.range
1999            .nth(n)
2000            .map(|index| self.array.get_unchecked(index))
2001    }
2002}
2003
2004impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIter<'_, T> {
2005    fn next_back(&mut self) -> Option<Self::Item> {
2006        let index = self.range.next_back()?;
2007        Some(self.array.get_unchecked(index))
2008    }
2009
2010    fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
2011        self.range
2012            .nth_back(n)
2013            .map(|index| self.array.get_unchecked(index))
2014    }
2015}
2016
2017impl<T: JsGeneric> core::iter::FusedIterator for ArrayIter<'_, T> {}
2018
2019impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIter<'_, T> {}
2020
2021impl<T: JsGeneric> Array<T> {
2022    /// Returns an iterator over the values of the JS array.
2023    pub fn iter(&self) -> ArrayIter<'_, T> {
2024        ArrayIter {
2025            range: 0..self.length(),
2026            array: self,
2027        }
2028    }
2029}
2030
2031impl<T: JsGeneric> core::iter::IntoIterator for Array<T> {
2032    type Item = T;
2033    type IntoIter = ArrayIntoIter<T>;
2034
2035    fn into_iter(self) -> Self::IntoIter {
2036        ArrayIntoIter {
2037            range: 0..self.length(),
2038            array: self,
2039        }
2040    }
2041}
2042
2043// `FromIterator` / `Extend` for `Array` (= `Array<JsValue>` via the default
2044// type parameter) preserve the long-standing stable behaviour: any iterator
2045// of items convertible to `&JsValue` collects into an erased `Array<JsValue>`.
2046//
2047// Typed collection (where the element type is inferred from the iterator
2048// item via [`IntoJsGeneric`]) is exposed as the inherent constructor
2049// [`Array::from_iter_typed`] rather than a second `FromIterator` impl. A
2050// blanket `impl<A: IntoJsGeneric> FromIterator<A> for Array<A::JsCanon>`
2051// would overlap with the stable `AsRef<JsValue>` impl on `Array<JsValue>`
2052// (since `JsValue: IntoJsGeneric` with `JsCanon = JsValue`), so the two
2053// cannot coexist as `FromIterator` impls without coherence violations.
2054//
2055// TODO(next major): deprecate this `FromIterator`/`Extend` pair in favour
2056// of a single `IntoJsGeneric`-based impl, and rename `from_iter_typed` to
2057// take its place. That migration is source-breaking for callers relying on
2058// `.collect::<Array>()` implicit erasure of typed items, so it is deferred.
2059
2060impl<A> core::iter::FromIterator<A> for Array
2061where
2062    A: AsRef<JsValue>,
2063{
2064    fn from_iter<I>(iter: I) -> Array
2065    where
2066        I: IntoIterator<Item = A>,
2067    {
2068        let mut out = Array::new();
2069        out.extend(iter);
2070        out
2071    }
2072}
2073
2074impl<A> core::iter::Extend<A> for Array
2075where
2076    A: AsRef<JsValue>,
2077{
2078    fn extend<I>(&mut self, iter: I)
2079    where
2080        I: IntoIterator<Item = A>,
2081    {
2082        for value in iter {
2083            self.push(value.as_ref());
2084        }
2085    }
2086}
2087
2088impl<T: JsGeneric> Array<T> {
2089    /// Collect an iterator into a typed `Array<T>`, projecting each item
2090    /// through its canonical [`JsGeneric`] via [`IntoJsGeneric`].
2091    ///
2092    /// This is the typed counterpart to the stable
2093    /// `impl FromIterator<A> for Array where A: AsRef<JsValue>`, which always
2094    /// produces an erased `Array<JsValue>`. Use `from_iter_typed` when you
2095    /// want the element type inferred from the iterator item:
2096    ///
2097    /// ```ignore
2098    /// use js_sys::{Array, Number};
2099    ///
2100    /// let arr = Array::from_iter_typed((0..10).map(Number::from));
2101    /// // arr: Array<Number>
2102    /// ```
2103    ///
2104    /// Reference iteration (`Item = &U`) is supported transparently via the
2105    /// `&U: IntoJsGeneric` blanket in `wasm-bindgen` core.
2106    //
2107    // TODO(next major): replace the stable `FromIterator` impl above with
2108    // this behaviour and remove `from_iter_typed`.
2109    pub fn from_iter_typed<A, I>(iter: I) -> Array<T>
2110    where
2111        A: IntoJsGeneric<JsCanon = T>,
2112        I: IntoIterator<Item = A>,
2113    {
2114        let mut out = Array::<T>::new_typed();
2115        out.extend_typed(iter);
2116        out
2117    }
2118
2119    /// Extend a typed `Array<T>` with an iterator of items convertible to
2120    /// `T` via [`IntoJsGeneric`]. Companion to [`Array::from_iter_typed`].
2121    //
2122    // TODO(next major): replace the stable `Extend` impl above with this
2123    // behaviour and remove `extend_typed`.
2124    pub fn extend_typed<A, I>(&mut self, iter: I)
2125    where
2126        A: IntoJsGeneric<JsCanon = T>,
2127        I: IntoIterator<Item = A>,
2128    {
2129        for value in iter {
2130            self.push(&value.to_js());
2131        }
2132    }
2133}
2134
2135impl Default for Array<JsValue> {
2136    fn default() -> Self {
2137        Self::new()
2138    }
2139}
2140
2141impl<T> Iterable for Array<T> {
2142    type Item = T;
2143}
2144
2145impl<T: JsTuple> Iterable for ArrayTuple<T> {
2146    type Item = JsValue;
2147}
2148
2149// ArrayBufferOptions
2150#[wasm_bindgen]
2151extern "C" {
2152    #[wasm_bindgen(extends = Object, typescript_type = "ArrayBufferOptions")]
2153    #[derive(Clone, Debug, PartialEq, Eq)]
2154    pub type ArrayBufferOptions;
2155
2156    /// The maximum size, in bytes, that the array buffer can be resized to.
2157    #[wasm_bindgen(method, setter, js_name = maxByteLength)]
2158    pub fn set_max_byte_length(this: &ArrayBufferOptions, max_byte_length: usize);
2159
2160    /// The maximum size, in bytes, that the array buffer can be resized to.
2161    #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2162    pub fn get_max_byte_length(this: &ArrayBufferOptions) -> usize;
2163}
2164
2165impl ArrayBufferOptions {
2166    #[cfg(not(js_sys_unstable_apis))]
2167    pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2168        let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::new());
2169        options.set_max_byte_length(max_byte_length);
2170        options
2171    }
2172
2173    #[cfg(js_sys_unstable_apis)]
2174    pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2175        let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::<JsValue>::new());
2176        options.set_max_byte_length(max_byte_length);
2177        options
2178    }
2179}
2180
2181// ArrayBuffer
2182#[wasm_bindgen]
2183extern "C" {
2184    #[wasm_bindgen(extends = Object, typescript_type = "ArrayBuffer")]
2185    #[derive(Clone, Debug, PartialEq, Eq)]
2186    pub type ArrayBuffer;
2187
2188    /// The `ArrayBuffer` object is used to represent a generic,
2189    /// fixed-length raw binary data buffer. You cannot directly
2190    /// manipulate the contents of an `ArrayBuffer`; instead, you
2191    /// create one of the typed array objects or a `DataView` object
2192    /// which represents the buffer in a specific format, and use that
2193    /// to read and write the contents of the buffer.
2194    ///
2195    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2196    #[cfg(not(js_sys_unstable_apis))]
2197    #[wasm_bindgen(constructor)]
2198    pub fn new(length: u32) -> ArrayBuffer;
2199
2200    /// The `ArrayBuffer` object is used to represent a generic,
2201    /// fixed-length raw binary data buffer. You cannot directly
2202    /// manipulate the contents of an `ArrayBuffer`; instead, you
2203    /// create one of the typed array objects or a `DataView` object
2204    /// which represents the buffer in a specific format, and use that
2205    /// to read and write the contents of the buffer.
2206    ///
2207    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2208    #[cfg(js_sys_unstable_apis)]
2209    #[wasm_bindgen(constructor)]
2210    pub fn new(length: usize) -> ArrayBuffer;
2211
2212    /// The `ArrayBuffer` object is used to represent a generic,
2213    /// fixed-length raw binary data buffer. You cannot directly
2214    /// manipulate the contents of an `ArrayBuffer`; instead, you
2215    /// create one of the typed array objects or a `DataView` object
2216    /// which represents the buffer in a specific format, and use that
2217    /// to read and write the contents of the buffer.
2218    ///
2219    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2220    #[wasm_bindgen(constructor)]
2221    pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> ArrayBuffer;
2222
2223    /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2224    /// it's an accessor property whose set accessor function is undefined,
2225    /// meaning that you can only read this property.
2226    /// The value is established when the array is constructed and cannot be changed.
2227    /// This property returns 0 if this ArrayBuffer has been detached.
2228    ///
2229    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2230    #[cfg(not(js_sys_unstable_apis))]
2231    #[wasm_bindgen(method, getter, js_name = byteLength)]
2232    pub fn byte_length(this: &ArrayBuffer) -> u32;
2233
2234    /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2235    /// it's an accessor property whose set accessor function is undefined,
2236    /// meaning that you can only read this property.
2237    /// The value is established when the array is constructed and cannot be changed.
2238    /// This property returns 0 if this ArrayBuffer has been detached.
2239    ///
2240    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2241    #[cfg(js_sys_unstable_apis)]
2242    #[wasm_bindgen(method, getter, js_name = byteLength)]
2243    pub fn byte_length(this: &ArrayBuffer) -> usize;
2244
2245    /// The `detached` accessor property of `ArrayBuffer` instances returns a boolean indicating
2246    /// whether or not this buffer has been detached (transferred).
2247    ///
2248    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/detached)
2249    #[wasm_bindgen(method, getter)]
2250    pub fn detached(this: &ArrayBuffer) -> bool;
2251
2252    /// The `isView()` method returns true if arg is one of the `ArrayBuffer`
2253    /// views, such as typed array objects or a DataView; false otherwise.
2254    ///
2255    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView)
2256    #[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
2257    pub fn is_view(value: &JsValue) -> bool;
2258
2259    /// The `maxByteLength` accessor property of ArrayBuffer instances returns the maximum
2260    /// length (in bytes) that this array buffer can be resized to.
2261    ///
2262    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/maxByteLength)
2263    #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2264    pub fn max_byte_length(this: &ArrayBuffer) -> usize;
2265
2266    /// The `resizable` accessor property of `ArrayBuffer` instances returns whether this array buffer
2267    /// can be resized or not.
2268    ///
2269    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resizable)
2270    #[wasm_bindgen(method, getter)]
2271    pub fn resizable(this: &ArrayBuffer) -> bool;
2272
2273    /// The `resize()` method of ArrayBuffer instances resizes the ArrayBuffer to the
2274    /// specified size, in bytes.
2275    ///
2276    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resize)
2277    #[wasm_bindgen(method, catch)]
2278    pub fn resize(this: &ArrayBuffer, new_len: usize) -> Result<(), JsValue>;
2279
2280    /// The `slice()` method returns a new `ArrayBuffer` whose contents
2281    /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2282    /// up to end, exclusive.
2283    ///
2284    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2285    #[cfg(not(js_sys_unstable_apis))]
2286    #[wasm_bindgen(method)]
2287    pub fn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer;
2288
2289    /// The `slice()` method returns a new `ArrayBuffer` whose contents
2290    /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2291    /// up to end, exclusive. Negative indices count from the end.
2292    ///
2293    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2294    #[cfg(js_sys_unstable_apis)]
2295    #[wasm_bindgen(method)]
2296    pub fn slice(this: &ArrayBuffer, begin: isize, end: isize) -> ArrayBuffer;
2297
2298    /// The `slice()` method returns a new `ArrayBuffer` whose contents
2299    /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2300    /// up to end, exclusive.
2301    ///
2302    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2303    #[cfg(not(js_sys_unstable_apis))]
2304    #[wasm_bindgen(method, js_name = slice)]
2305    pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2306
2307    /// The `slice()` method returns a new `ArrayBuffer` whose contents
2308    /// are a copy of this `ArrayBuffer`'s bytes from begin to the end.
2309    /// Negative indices count from the end.
2310    ///
2311    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2312    #[cfg(js_sys_unstable_apis)]
2313    #[wasm_bindgen(method, js_name = slice)]
2314    pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2315
2316    // Next major: deprecate
2317    /// Like `slice()` but with the `end` argument.
2318    ///
2319    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2320    #[wasm_bindgen(method, js_name = slice)]
2321    pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer;
2322
2323    /// The `transfer()` method of ArrayBuffer instances creates a new `ArrayBuffer`
2324    /// with the same byte content as this buffer, then detaches this buffer.
2325    ///
2326    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2327    #[wasm_bindgen(method, catch)]
2328    pub fn transfer(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2329
2330    /// The `transfer()` method of `ArrayBuffer` instances creates a new `ArrayBuffer`
2331    /// with the same byte content as this buffer, then detaches this buffer.
2332    ///
2333    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2334    #[wasm_bindgen(method, catch, js_name = transfer)]
2335    pub fn transfer_with_length(
2336        this: &ArrayBuffer,
2337        new_byte_length: usize,
2338    ) -> Result<ArrayBuffer, JsValue>;
2339
2340    /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2341    /// ArrayBuffer with the same byte content as this buffer, then detaches this buffer.
2342    ///
2343    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2344    #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2345    pub fn transfer_to_fixed_length(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2346
2347    /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2348    /// `ArrayBuffer` with the same byte content as this buffer, then detaches this buffer.
2349    ///
2350    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2351    #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2352    pub fn transfer_to_fixed_length_with_length(
2353        this: &ArrayBuffer,
2354        new_byte_length: usize,
2355    ) -> Result<ArrayBuffer, JsValue>;
2356}
2357
2358impl UpcastFrom<&[u8]> for ArrayBuffer {}
2359
2360// SharedArrayBuffer
2361#[wasm_bindgen]
2362extern "C" {
2363    #[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
2364    #[derive(Clone, Debug)]
2365    pub type SharedArrayBuffer;
2366
2367    /// The `SharedArrayBuffer` object is used to represent a generic,
2368    /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2369    /// object, but in a way that they can be used to create views
2370    /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2371    /// cannot become detached.
2372    ///
2373    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2374    #[cfg(not(js_sys_unstable_apis))]
2375    #[wasm_bindgen(constructor)]
2376    pub fn new(length: u32) -> SharedArrayBuffer;
2377
2378    /// The `SharedArrayBuffer` object is used to represent a generic,
2379    /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2380    /// object, but in a way that they can be used to create views
2381    /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2382    /// cannot become detached.
2383    ///
2384    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2385    #[cfg(js_sys_unstable_apis)]
2386    #[wasm_bindgen(constructor)]
2387    pub fn new(length: usize) -> SharedArrayBuffer;
2388
2389    /// The `SharedArrayBuffer` object is used to represent a generic,
2390    /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2391    /// object, but in a way that they can be used to create views
2392    /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2393    /// cannot become detached.
2394    ///
2395    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2396    #[wasm_bindgen(constructor)]
2397    pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> SharedArrayBuffer;
2398
2399    /// The `byteLength` accessor property represents the length of
2400    /// an `SharedArrayBuffer` in bytes. This is established when
2401    /// the `SharedArrayBuffer` is constructed and cannot be changed.
2402    ///
2403    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2404    #[cfg(not(js_sys_unstable_apis))]
2405    #[wasm_bindgen(method, getter, js_name = byteLength)]
2406    pub fn byte_length(this: &SharedArrayBuffer) -> u32;
2407
2408    /// The `byteLength` accessor property represents the length of
2409    /// an `SharedArrayBuffer` in bytes. This is established when
2410    /// the `SharedArrayBuffer` is constructed and cannot be changed.
2411    ///
2412    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2413    #[cfg(js_sys_unstable_apis)]
2414    #[wasm_bindgen(method, getter, js_name = byteLength)]
2415    pub fn byte_length(this: &SharedArrayBuffer) -> usize;
2416
2417    /// The `growable` accessor property of `SharedArrayBuffer` instances returns whether
2418    /// this `SharedArrayBuffer` can be grown or not.
2419    ///
2420    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/growable)
2421    #[wasm_bindgen(method, getter)]
2422    pub fn growable(this: &SharedArrayBuffer) -> bool;
2423
2424    /// The `grow()` method of `SharedArrayBuffer` instances grows the
2425    /// `SharedArrayBuffer` to the specified size, in bytes.
2426    ///
2427    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/grow)
2428    #[wasm_bindgen(method, catch)]
2429    pub fn grow(this: &SharedArrayBuffer, new_byte_length: usize) -> Result<(), JsValue>;
2430
2431    /// The `maxByteLength` accessor property of `SharedArrayBuffer` instances returns the maximum
2432    /// length (in bytes) that this `SharedArrayBuffer` can be resized to.
2433    ///
2434    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/maxByteLength)
2435    #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2436    pub fn max_byte_length(this: &SharedArrayBuffer) -> usize;
2437
2438    /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2439    /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2440    /// up to end, exclusive.
2441    ///
2442    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2443    #[cfg(not(js_sys_unstable_apis))]
2444    #[wasm_bindgen(method)]
2445    pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer;
2446
2447    /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2448    /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2449    /// up to end, exclusive. Negative indices count from the end.
2450    ///
2451    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2452    #[cfg(js_sys_unstable_apis)]
2453    #[wasm_bindgen(method)]
2454    pub fn slice(this: &SharedArrayBuffer, begin: isize, end: isize) -> SharedArrayBuffer;
2455
2456    /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2457    /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2458    /// up to end, exclusive.
2459    ///
2460    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2461    #[cfg(not(js_sys_unstable_apis))]
2462    #[wasm_bindgen(method)]
2463    pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2464
2465    /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2466    /// are a copy of this `SharedArrayBuffer`'s bytes from begin to end.
2467    /// Negative indices count from the end.
2468    ///
2469    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2470    #[cfg(js_sys_unstable_apis)]
2471    #[wasm_bindgen(method)]
2472    pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2473
2474    // Next major: deprecate
2475    /// Like `slice()` but with the `end` argument.
2476    ///
2477    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2478    #[wasm_bindgen(method, js_name = slice)]
2479    pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer;
2480}
2481
2482// Array Iterator
2483#[wasm_bindgen]
2484extern "C" {
2485    /// The `keys()` method returns a new Array Iterator object that contains the
2486    /// keys for each index in the array.
2487    ///
2488    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys)
2489    #[wasm_bindgen(method)]
2490    pub fn keys<T>(this: &Array<T>) -> Iterator<T>;
2491
2492    /// The `entries()` method returns a new Array Iterator object that contains
2493    /// the key/value pairs for each index in the array.
2494    ///
2495    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2496    #[cfg(not(js_sys_unstable_apis))]
2497    #[wasm_bindgen(method)]
2498    #[deprecated(note = "recommended to use `Array::entries_typed` instead for typing")]
2499    #[allow(deprecated)]
2500    pub fn entries<T>(this: &Array<T>) -> Iterator<T>;
2501
2502    /// The `entries()` method returns a new Array Iterator object that contains
2503    /// the key/value pairs for each index in the array.
2504    ///
2505    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2506    #[cfg(js_sys_unstable_apis)]
2507    #[wasm_bindgen(method)]
2508    pub fn entries<T>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2509
2510    // Next major: deprecate
2511    /// The `entries()` method returns a new Array Iterator object that contains
2512    /// the key/value pairs for each index in the array.
2513    ///
2514    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2515    #[wasm_bindgen(method, js_name = entries)]
2516    pub fn entries_typed<T>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2517
2518    /// The `values()` method returns a new Array Iterator object that
2519    /// contains the values for each index in the array.
2520    ///
2521    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
2522    #[wasm_bindgen(method)]
2523    pub fn values<T>(this: &Array<T>) -> Iterator<T>;
2524}
2525
2526// FIXME(next-major): rename this trait to `ArrayBufferView`. The DOM/WebIDL
2527// spec name `ArrayBufferView` covers both `DataView` and the typed-array
2528// types, which more accurately reflects the set of types that implement this
2529// trait. The `TypedArray` name is kept for now to avoid a breaking change.
2530pub trait TypedArray: JsGeneric {}
2531
2532impl TypedArray for DataView {}
2533
2534// Next major: use usize/isize for indices
2535/// The `Atomics` object provides atomic operations as static methods.
2536/// They are used with `SharedArrayBuffer` objects.
2537///
2538/// The Atomic operations are installed on an `Atomics` module. Unlike
2539/// the other global objects, `Atomics` is not a constructor. You cannot
2540/// use it with a new operator or invoke the `Atomics` object as a
2541/// function. All properties and methods of `Atomics` are static
2542/// (as is the case with the Math object, for example).
2543/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
2544#[allow(non_snake_case)]
2545pub mod Atomics {
2546    use super::*;
2547
2548    #[wasm_bindgen]
2549    extern "C" {
2550        /// The static `Atomics.add()` method adds a given value at a given
2551        /// position in the array and returns the old value at that position.
2552        /// This atomic operation guarantees that no other write happens
2553        /// until the modified value is written back.
2554        ///
2555        /// You should use `add_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2556        ///
2557        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2558        #[wasm_bindgen(js_namespace = Atomics, catch)]
2559        pub fn add<T: TypedArray = Int32Array>(
2560            typed_array: &T,
2561            index: u32,
2562            value: i32,
2563        ) -> Result<i32, JsValue>;
2564
2565        /// The static `Atomics.add()` method adds a given value at a given
2566        /// position in the array and returns the old value at that position.
2567        /// This atomic operation guarantees that no other write happens
2568        /// until the modified value is written back.
2569        ///
2570        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2571        ///
2572        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2573        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = add)]
2574        pub fn add_bigint<T: TypedArray = Int32Array>(
2575            typed_array: &T,
2576            index: u32,
2577            value: i64,
2578        ) -> Result<i64, JsValue>;
2579
2580        /// The static `Atomics.and()` method computes a bitwise AND with a given
2581        /// value at a given position in the array, and returns the old value
2582        /// at that position.
2583        /// This atomic operation guarantees that no other write happens
2584        /// until the modified value is written back.
2585        ///
2586        /// You should use `and_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2587        ///
2588        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2589        #[wasm_bindgen(js_namespace = Atomics, catch)]
2590        pub fn and<T: TypedArray = Int32Array>(
2591            typed_array: &T,
2592            index: u32,
2593            value: i32,
2594        ) -> Result<i32, JsValue>;
2595
2596        /// The static `Atomics.and()` method computes a bitwise AND with a given
2597        /// value at a given position in the array, and returns the old value
2598        /// at that position.
2599        /// This atomic operation guarantees that no other write happens
2600        /// until the modified value is written back.
2601        ///
2602        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2603        ///
2604        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2605        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = and)]
2606        pub fn and_bigint<T: TypedArray = Int32Array>(
2607            typed_array: &T,
2608            index: u32,
2609            value: i64,
2610        ) -> Result<i64, JsValue>;
2611
2612        /// The static `Atomics.compareExchange()` method exchanges a given
2613        /// replacement value at a given position in the array, if a given expected
2614        /// value equals the old value. It returns the old value at that position
2615        /// whether it was equal to the expected value or not.
2616        /// This atomic operation guarantees that no other write happens
2617        /// until the modified value is written back.
2618        ///
2619        /// You should use `compare_exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2620        ///
2621        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2622        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2623        pub fn compare_exchange<T: TypedArray = Int32Array>(
2624            typed_array: &T,
2625            index: u32,
2626            expected_value: i32,
2627            replacement_value: i32,
2628        ) -> Result<i32, JsValue>;
2629
2630        /// The static `Atomics.compareExchange()` method exchanges a given
2631        /// replacement value at a given position in the array, if a given expected
2632        /// value equals the old value. It returns the old value at that position
2633        /// whether it was equal to the expected value or not.
2634        /// This atomic operation guarantees that no other write happens
2635        /// until the modified value is written back.
2636        ///
2637        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2638        ///
2639        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2640        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2641        pub fn compare_exchange_bigint<T: TypedArray = Int32Array>(
2642            typed_array: &T,
2643            index: u32,
2644            expected_value: i64,
2645            replacement_value: i64,
2646        ) -> Result<i64, JsValue>;
2647
2648        /// The static `Atomics.exchange()` method stores a given value at a given
2649        /// position in the array and returns the old value at that position.
2650        /// This atomic operation guarantees that no other write happens
2651        /// until the modified value is written back.
2652        ///
2653        /// You should use `exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2654        ///
2655        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2656        #[wasm_bindgen(js_namespace = Atomics, catch)]
2657        pub fn exchange<T: TypedArray = Int32Array>(
2658            typed_array: &T,
2659            index: u32,
2660            value: i32,
2661        ) -> Result<i32, JsValue>;
2662
2663        /// The static `Atomics.exchange()` method stores a given value at a given
2664        /// position in the array and returns the old value at that position.
2665        /// This atomic operation guarantees that no other write happens
2666        /// until the modified value is written back.
2667        ///
2668        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2669        ///
2670        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2671        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = exchange)]
2672        pub fn exchange_bigint<T: TypedArray = Int32Array>(
2673            typed_array: &T,
2674            index: u32,
2675            value: i64,
2676        ) -> Result<i64, JsValue>;
2677
2678        /// The static `Atomics.isLockFree()` method is used to determine
2679        /// whether to use locks or atomic operations. It returns true,
2680        /// if the given size is one of the `BYTES_PER_ELEMENT` property
2681        /// of integer `TypedArray` types.
2682        ///
2683        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree)
2684        #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)]
2685        pub fn is_lock_free(size: u32) -> bool;
2686
2687        /// The static `Atomics.load()` method returns a value at a given
2688        /// position in the array.
2689        ///
2690        /// You should use `load_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2691        ///
2692        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2693        #[wasm_bindgen(js_namespace = Atomics, catch)]
2694        pub fn load<T: TypedArray = Int32Array>(
2695            typed_array: &T,
2696            index: u32,
2697        ) -> Result<i32, JsValue>;
2698
2699        /// The static `Atomics.load()` method returns a value at a given
2700        /// position in the array.
2701        ///
2702        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2703        ///
2704        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2705        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = load)]
2706        pub fn load_bigint<T: TypedArray = Int32Array>(
2707            typed_array: &T,
2708            index: i64,
2709        ) -> Result<i64, JsValue>;
2710
2711        /// The static `Atomics.notify()` method notifies up some agents that
2712        /// are sleeping in the wait queue.
2713        /// Note: This operation works with a shared `Int32Array` only.
2714        /// If `count` is not provided, notifies all the agents in the queue.
2715        ///
2716        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2717        #[wasm_bindgen(js_namespace = Atomics, catch)]
2718        pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>;
2719
2720        /// The static `Atomics.notify()` method notifies up some agents that
2721        /// are sleeping in the wait queue.
2722        /// Note: This operation works with a shared `Int32Array` only.
2723        /// If `count` is not provided, notifies all the agents in the queue.
2724        ///
2725        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2726        #[wasm_bindgen(js_namespace = Atomics, catch)]
2727        pub fn notify_bigint(typed_array: &BigInt64Array, index: u32) -> Result<u32, JsValue>;
2728
2729        /// Notifies up to `count` agents in the wait queue.
2730        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2731        pub fn notify_with_count(
2732            typed_array: &Int32Array,
2733            index: u32,
2734            count: u32,
2735        ) -> Result<u32, JsValue>;
2736
2737        /// Notifies up to `count` agents in the wait queue.
2738        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2739        pub fn notify_bigint_with_count(
2740            typed_array: &BigInt64Array,
2741            index: u32,
2742            count: u32,
2743        ) -> Result<u32, JsValue>;
2744
2745        /// The static `Atomics.or()` method computes a bitwise OR with a given value
2746        /// at a given position in the array, and returns the old value at that position.
2747        /// This atomic operation guarantees that no other write happens
2748        /// until the modified value is written back.
2749        ///
2750        /// You should use `or_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2751        ///
2752        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2753        #[wasm_bindgen(js_namespace = Atomics, catch)]
2754        pub fn or<T: TypedArray = Int32Array>(
2755            typed_array: &T,
2756            index: u32,
2757            value: i32,
2758        ) -> Result<i32, JsValue>;
2759
2760        /// The static `Atomics.or()` method computes a bitwise OR with a given value
2761        /// at a given position in the array, and returns the old value at that position.
2762        /// This atomic operation guarantees that no other write happens
2763        /// until the modified value is written back.
2764        ///
2765        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2766        ///
2767        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2768        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = or)]
2769        pub fn or_bigint<T: TypedArray = Int32Array>(
2770            typed_array: &T,
2771            index: u32,
2772            value: i64,
2773        ) -> Result<i64, JsValue>;
2774
2775        /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2776        /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2777        /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2778        /// current thread.
2779        ///
2780        /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2781        /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2782        /// per Intel's optimization manual. It could be a no-op in certain platforms.
2783        ///
2784        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2785        ///
2786        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2787        #[wasm_bindgen(js_namespace = Atomics)]
2788        pub fn pause();
2789
2790        /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2791        /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2792        /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2793        /// current thread.
2794        ///
2795        /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2796        /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2797        /// per Intel's optimization manual. It could be a no-op in certain platforms.
2798        ///
2799        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2800        ///
2801        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2802        #[wasm_bindgen(js_namespace = Atomics)]
2803        pub fn pause_with_hint(duration_hint: u32);
2804
2805        /// The static `Atomics.store()` method stores a given value at the given
2806        /// position in the array and returns that value.
2807        ///
2808        /// You should use `store_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2809        ///
2810        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2811        #[wasm_bindgen(js_namespace = Atomics, catch)]
2812        pub fn store<T: TypedArray = Int32Array>(
2813            typed_array: &T,
2814            index: u32,
2815            value: i32,
2816        ) -> Result<i32, JsValue>;
2817
2818        /// The static `Atomics.store()` method stores a given value at the given
2819        /// position in the array and returns that value.
2820        ///
2821        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2822        ///
2823        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2824        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = store)]
2825        pub fn store_bigint<T: TypedArray = Int32Array>(
2826            typed_array: &T,
2827            index: u32,
2828            value: i64,
2829        ) -> Result<i64, JsValue>;
2830
2831        /// The static `Atomics.sub()` method subtracts a given value at a
2832        /// given position in the array and returns the old value at that position.
2833        /// This atomic operation guarantees that no other write happens
2834        /// until the modified value is written back.
2835        ///
2836        /// You should use `sub_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2837        ///
2838        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2839        #[wasm_bindgen(js_namespace = Atomics, catch)]
2840        pub fn sub<T: TypedArray = Int32Array>(
2841            typed_array: &T,
2842            index: u32,
2843            value: i32,
2844        ) -> Result<i32, JsValue>;
2845
2846        /// The static `Atomics.sub()` method subtracts a given value at a
2847        /// given position in the array and returns the old value at that position.
2848        /// This atomic operation guarantees that no other write happens
2849        /// until the modified value is written back.
2850        ///
2851        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2852        ///
2853        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2854        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = sub)]
2855        pub fn sub_bigint<T: TypedArray = Int32Array>(
2856            typed_array: &T,
2857            index: u32,
2858            value: i64,
2859        ) -> Result<i64, JsValue>;
2860
2861        /// The static `Atomics.wait()` method verifies that a given
2862        /// position in an `Int32Array` still contains a given value
2863        /// and if so sleeps, awaiting a wakeup or a timeout.
2864        /// It returns a string which is either "ok", "not-equal", or "timed-out".
2865        /// Note: This operation only works with a shared `Int32Array`
2866        /// and may not be allowed on the main thread.
2867        ///
2868        /// You should use `wait_bigint` to operate on a `BigInt64Array`.
2869        ///
2870        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2871        #[wasm_bindgen(js_namespace = Atomics, catch)]
2872        pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>;
2873
2874        /// The static `Atomics.wait()` method verifies that a given
2875        /// position in an `BigInt64Array` still contains a given value
2876        /// and if so sleeps, awaiting a wakeup or a timeout.
2877        /// It returns a string which is either "ok", "not-equal", or "timed-out".
2878        /// Note: This operation only works with a shared `BigInt64Array`
2879        /// and may not be allowed on the main thread.
2880        ///
2881        /// You should use `wait` to operate on a `Int32Array`.
2882        ///
2883        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2884        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2885        pub fn wait_bigint(
2886            typed_array: &BigInt64Array,
2887            index: u32,
2888            value: i64,
2889        ) -> Result<JsString, JsValue>;
2890
2891        /// Like `wait()`, but with timeout
2892        ///
2893        /// You should use `wait_with_timeout_bigint` to operate on a `BigInt64Array`.
2894        ///
2895        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2896        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2897        pub fn wait_with_timeout(
2898            typed_array: &Int32Array,
2899            index: u32,
2900            value: i32,
2901            timeout: f64,
2902        ) -> Result<JsString, JsValue>;
2903
2904        /// Like `wait()`, but with timeout
2905        ///
2906        /// You should use `wait_with_timeout` to operate on a `Int32Array`.
2907        ///
2908        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2909        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2910        pub fn wait_with_timeout_bigint(
2911            typed_array: &BigInt64Array,
2912            index: u32,
2913            value: i64,
2914            timeout: f64,
2915        ) -> Result<JsString, JsValue>;
2916
2917        /// The static `Atomics.waitAsync()` method verifies that a given position in an
2918        /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2919        /// wakeup or a timeout. It returns an object with two properties. The first
2920        /// property `async` is a boolean which if true indicates that the second
2921        /// property `value` is a promise. If `async` is false then value is a string
2922        /// whether equal to either "not-equal" or "timed-out".
2923        /// Note: This operation only works with a shared `Int32Array` and may be used
2924        /// on the main thread.
2925        ///
2926        /// You should use `wait_async_bigint` to operate on a `BigInt64Array`.
2927        ///
2928        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2929        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2930        pub fn wait_async(
2931            typed_array: &Int32Array,
2932            index: u32,
2933            value: i32,
2934        ) -> Result<Object, JsValue>;
2935
2936        /// The static `Atomics.waitAsync()` method verifies that a given position in an
2937        /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2938        /// wakeup or a timeout. It returns an object with two properties. The first
2939        /// property `async` is a boolean which if true indicates that the second
2940        /// property `value` is a promise. If `async` is false then value is a string
2941        /// whether equal to either "not-equal" or "timed-out".
2942        /// Note: This operation only works with a shared `BigInt64Array` and may be used
2943        /// on the main thread.
2944        ///
2945        /// You should use `wait_async` to operate on a `Int32Array`.
2946        ///
2947        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2948        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2949        pub fn wait_async_bigint(
2950            typed_array: &BigInt64Array,
2951            index: u32,
2952            value: i64,
2953        ) -> Result<Object, JsValue>;
2954
2955        /// Like `waitAsync()`, but with timeout
2956        ///
2957        /// You should use `wait_async_with_timeout_bigint` to operate on a `BigInt64Array`.
2958        ///
2959        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2960        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2961        pub fn wait_async_with_timeout(
2962            typed_array: &Int32Array,
2963            index: u32,
2964            value: i32,
2965            timeout: f64,
2966        ) -> Result<Object, JsValue>;
2967
2968        /// Like `waitAsync()`, but with timeout
2969        ///
2970        /// You should use `wait_async_with_timeout` to operate on a `Int32Array`.
2971        ///
2972        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2973        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2974        pub fn wait_async_with_timeout_bigint(
2975            typed_array: &BigInt64Array,
2976            index: u32,
2977            value: i64,
2978            timeout: f64,
2979        ) -> Result<Object, JsValue>;
2980
2981        /// The static `Atomics.xor()` method computes a bitwise XOR
2982        /// with a given value at a given position in the array,
2983        /// and returns the old value at that position.
2984        /// This atomic operation guarantees that no other write happens
2985        /// until the modified value is written back.
2986        ///
2987        /// You should use `xor_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2988        ///
2989        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2990        #[wasm_bindgen(js_namespace = Atomics, catch)]
2991        pub fn xor<T: TypedArray = Int32Array>(
2992            typed_array: &T,
2993            index: u32,
2994            value: i32,
2995        ) -> Result<i32, JsValue>;
2996
2997        /// The static `Atomics.xor()` method computes a bitwise XOR
2998        /// with a given value at a given position in the array,
2999        /// and returns the old value at that position.
3000        /// This atomic operation guarantees that no other write happens
3001        /// until the modified value is written back.
3002        ///
3003        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
3004        ///
3005        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
3006        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = xor)]
3007        pub fn xor_bigint<T: TypedArray = Int32Array>(
3008            typed_array: &T,
3009            index: u32,
3010            value: i64,
3011        ) -> Result<i64, JsValue>;
3012    }
3013}
3014
3015// BigInt
3016#[wasm_bindgen]
3017extern "C" {
3018    #[wasm_bindgen(extends = Object, is_type_of = |v| v.is_bigint(), typescript_type = "bigint")]
3019    #[derive(Clone, PartialEq, Eq)]
3020    pub type BigInt;
3021
3022    #[wasm_bindgen(catch, js_name = BigInt)]
3023    fn new_bigint(value: &JsValue) -> Result<BigInt, Error>;
3024
3025    #[wasm_bindgen(js_name = BigInt)]
3026    fn new_bigint_unchecked(value: &JsValue) -> BigInt;
3027
3028    /// Clamps a BigInt value to a signed integer value, and returns that value.
3029    ///
3030    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)
3031    #[wasm_bindgen(static_method_of = BigInt, js_name = asIntN)]
3032    pub fn as_int_n(bits: f64, bigint: &BigInt) -> BigInt;
3033
3034    /// Clamps a BigInt value to an unsigned integer value, and returns that value.
3035    ///
3036    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)
3037    #[wasm_bindgen(static_method_of = BigInt, js_name = asUintN)]
3038    pub fn as_uint_n(bits: f64, bigint: &BigInt) -> BigInt;
3039
3040    /// Returns a string with a language-sensitive representation of this BigInt value. Overrides the [`Object.prototype.toLocaleString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString) method.
3041    ///
3042    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
3043    #[cfg(not(js_sys_unstable_apis))]
3044    #[wasm_bindgen(method, js_name = toLocaleString)]
3045    pub fn to_locale_string(this: &BigInt, locales: &JsValue, options: &JsValue) -> JsString;
3046
3047    /// Returns a string with a language-sensitive representation of this BigInt value. Overrides the [`Object.prototype.toLocaleString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString) method.
3048    ///
3049    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
3050    #[cfg(js_sys_unstable_apis)]
3051    #[wasm_bindgen(method, js_name = toLocaleString)]
3052    pub fn to_locale_string(
3053        this: &BigInt,
3054        locales: &[JsString],
3055        options: &Intl::NumberFormatOptions,
3056    ) -> JsString;
3057
3058    // Next major: deprecate
3059    /// Returns a string representing this BigInt value in the specified radix (base). Overrides the [`Object.prototype.toString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString) method.
3060    ///
3061    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
3062    #[wasm_bindgen(catch, method, js_name = toString)]
3063    pub fn to_string(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
3064
3065    /// Returns a string representing this BigInt value in the specified radix (base).
3066    ///
3067    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
3068    #[cfg(js_sys_unstable_apis)]
3069    #[wasm_bindgen(catch, method, js_name = toString)]
3070    pub fn to_string_with_radix(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
3071
3072    #[wasm_bindgen(method, js_name = toString)]
3073    fn to_string_unchecked(this: &BigInt, radix: u8) -> String;
3074
3075    /// Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method.
3076    ///
3077    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)
3078    #[wasm_bindgen(method, js_name = valueOf)]
3079    pub fn value_of(this: &BigInt, radix: u8) -> BigInt;
3080}
3081
3082impl BigInt {
3083    /// Creates a new BigInt value.
3084    ///
3085    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)
3086    #[inline]
3087    pub fn new(value: &JsValue) -> Result<BigInt, Error> {
3088        new_bigint(value)
3089    }
3090
3091    /// Applies the binary `/` JS operator on two `BigInt`s, catching and returning any `RangeError` thrown.
3092    ///
3093    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division)
3094    pub fn checked_div(&self, rhs: &Self) -> Result<Self, RangeError> {
3095        let result = JsValue::as_ref(self).checked_div(JsValue::as_ref(rhs));
3096
3097        if result.is_instance_of::<RangeError>() {
3098            Err(result.unchecked_into())
3099        } else {
3100            Ok(result.unchecked_into())
3101        }
3102    }
3103
3104    /// Applies the binary `**` JS operator on the two `BigInt`s.
3105    ///
3106    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
3107    #[inline]
3108    pub fn pow(&self, rhs: &Self) -> Self {
3109        JsValue::as_ref(self)
3110            .pow(JsValue::as_ref(rhs))
3111            .unchecked_into()
3112    }
3113
3114    /// Returns a tuple of this [`BigInt`]'s absolute value along with a
3115    /// [`bool`] indicating whether the [`BigInt`] was negative.
3116    fn abs(&self) -> (Self, bool) {
3117        if self < &BigInt::from(0) {
3118            (-self, true)
3119        } else {
3120            (self.clone(), false)
3121        }
3122    }
3123}
3124
3125macro_rules! bigint_from {
3126    ($($x:ident)*) => ($(
3127        impl From<$x> for BigInt {
3128            #[inline]
3129            fn from(x: $x) -> BigInt {
3130                new_bigint_unchecked(&JsValue::from(x))
3131            }
3132        }
3133
3134        impl PartialEq<$x> for BigInt {
3135            #[inline]
3136            fn eq(&self, other: &$x) -> bool {
3137                JsValue::from(self) == JsValue::from(BigInt::from(*other))
3138            }
3139        }
3140    )*)
3141}
3142bigint_from!(i8 u8 i16 u16 i32 u32 isize usize);
3143
3144macro_rules! bigint_from_big {
3145    ($($x:ident)*) => ($(
3146        impl From<$x> for BigInt {
3147            #[inline]
3148            fn from(x: $x) -> BigInt {
3149                JsValue::from(x).unchecked_into()
3150            }
3151        }
3152
3153        impl PartialEq<$x> for BigInt {
3154            #[inline]
3155            fn eq(&self, other: &$x) -> bool {
3156                self == &BigInt::from(*other)
3157            }
3158        }
3159
3160        impl TryFrom<BigInt> for $x {
3161            type Error = BigInt;
3162
3163            #[inline]
3164            fn try_from(x: BigInt) -> Result<Self, BigInt> {
3165                Self::try_from(JsValue::from(x)).map_err(JsCast::unchecked_into)
3166            }
3167        }
3168    )*)
3169}
3170bigint_from_big!(i64 u64 i128 u128);
3171
3172impl PartialEq<Number> for BigInt {
3173    #[inline]
3174    fn eq(&self, other: &Number) -> bool {
3175        JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
3176    }
3177}
3178
3179impl Not for &BigInt {
3180    type Output = BigInt;
3181
3182    #[inline]
3183    fn not(self) -> Self::Output {
3184        JsValue::as_ref(self).bit_not().unchecked_into()
3185    }
3186}
3187
3188forward_deref_unop!(impl Not, not for BigInt);
3189forward_js_unop!(impl Neg, neg for BigInt);
3190forward_js_binop!(impl BitAnd, bitand for BigInt);
3191forward_js_binop!(impl BitOr, bitor for BigInt);
3192forward_js_binop!(impl BitXor, bitxor for BigInt);
3193forward_js_binop!(impl Shl, shl for BigInt);
3194forward_js_binop!(impl Shr, shr for BigInt);
3195forward_js_binop!(impl Add, add for BigInt);
3196forward_js_binop!(impl Sub, sub for BigInt);
3197forward_js_binop!(impl Div, div for BigInt);
3198forward_js_binop!(impl Mul, mul for BigInt);
3199forward_js_binop!(impl Rem, rem for BigInt);
3200sum_product!(BigInt);
3201
3202partialord_ord!(BigInt);
3203
3204impl Default for BigInt {
3205    fn default() -> Self {
3206        BigInt::from(i32::default())
3207    }
3208}
3209
3210impl FromStr for BigInt {
3211    type Err = Error;
3212
3213    #[inline]
3214    fn from_str(s: &str) -> Result<Self, Self::Err> {
3215        BigInt::new(&s.into())
3216    }
3217}
3218
3219impl fmt::Debug for BigInt {
3220    #[inline]
3221    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3222        fmt::Display::fmt(self, f)
3223    }
3224}
3225
3226impl fmt::Display for BigInt {
3227    #[inline]
3228    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3229        let (abs, is_neg) = self.abs();
3230        f.pad_integral(!is_neg, "", &abs.to_string_unchecked(10))
3231    }
3232}
3233
3234impl fmt::Binary for BigInt {
3235    #[inline]
3236    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3237        let (abs, is_neg) = self.abs();
3238        f.pad_integral(!is_neg, "0b", &abs.to_string_unchecked(2))
3239    }
3240}
3241
3242impl fmt::Octal for BigInt {
3243    #[inline]
3244    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3245        let (abs, is_neg) = self.abs();
3246        f.pad_integral(!is_neg, "0o", &abs.to_string_unchecked(8))
3247    }
3248}
3249
3250impl fmt::LowerHex for BigInt {
3251    #[inline]
3252    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3253        let (abs, is_neg) = self.abs();
3254        f.pad_integral(!is_neg, "0x", &abs.to_string_unchecked(16))
3255    }
3256}
3257
3258impl fmt::UpperHex for BigInt {
3259    #[inline]
3260    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3261        let (abs, is_neg) = self.abs();
3262        let mut s: String = abs.to_string_unchecked(16);
3263        s.make_ascii_uppercase();
3264        f.pad_integral(!is_neg, "0x", &s)
3265    }
3266}
3267
3268// Boolean
3269#[wasm_bindgen]
3270extern "C" {
3271    #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
3272    #[derive(Clone, PartialEq, Eq)]
3273    pub type Boolean;
3274
3275    /// The `Boolean()` constructor creates an object wrapper for a boolean value.
3276    ///
3277    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
3278    #[cfg(not(js_sys_unstable_apis))]
3279    #[wasm_bindgen(constructor)]
3280    #[deprecated(note = "recommended to use `Boolean::from` instead")]
3281    #[allow(deprecated)]
3282    pub fn new(value: &JsValue) -> Boolean;
3283
3284    /// The `valueOf()` method returns the primitive value of a `Boolean` object.
3285    ///
3286    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf)
3287    #[wasm_bindgen(method, js_name = valueOf)]
3288    pub fn value_of(this: &Boolean) -> bool;
3289}
3290
3291impl UpcastFrom<bool> for Boolean {}
3292impl UpcastFrom<Boolean> for bool {}
3293
3294impl Boolean {
3295    /// Typed Boolean true constant.
3296    pub const TRUE: Boolean = Self {
3297        obj: Object {
3298            obj: JsValue::TRUE,
3299            generics: PhantomData,
3300        },
3301    };
3302
3303    /// Typed Boolean false constant.
3304    pub const FALSE: Boolean = Self {
3305        obj: Object {
3306            obj: JsValue::FALSE,
3307            generics: PhantomData,
3308        },
3309    };
3310}
3311
3312impl From<bool> for Boolean {
3313    #[inline]
3314    fn from(b: bool) -> Boolean {
3315        Boolean::unchecked_from_js(JsValue::from(b))
3316    }
3317}
3318
3319impl From<Boolean> for bool {
3320    #[inline]
3321    fn from(b: Boolean) -> bool {
3322        b.value_of()
3323    }
3324}
3325
3326impl PartialEq<bool> for Boolean {
3327    #[inline]
3328    fn eq(&self, other: &bool) -> bool {
3329        self.value_of() == *other
3330    }
3331}
3332
3333impl fmt::Debug for Boolean {
3334    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3335        fmt::Debug::fmt(&self.value_of(), f)
3336    }
3337}
3338
3339impl fmt::Display for Boolean {
3340    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3341        fmt::Display::fmt(&self.value_of(), f)
3342    }
3343}
3344
3345impl Default for Boolean {
3346    fn default() -> Self {
3347        Self::from(bool::default())
3348    }
3349}
3350
3351impl Not for &Boolean {
3352    type Output = Boolean;
3353
3354    #[inline]
3355    fn not(self) -> Self::Output {
3356        (!JsValue::as_ref(self)).into()
3357    }
3358}
3359
3360forward_deref_unop!(impl Not, not for Boolean);
3361
3362partialord_ord!(Boolean);
3363
3364// DataView
3365#[wasm_bindgen]
3366extern "C" {
3367    #[wasm_bindgen(extends = Object, typescript_type = "DataView")]
3368    #[derive(Clone, Debug, PartialEq, Eq)]
3369    pub type DataView;
3370
3371    /// The `DataView` view provides a low-level interface for reading and
3372    /// writing multiple number types in an `ArrayBuffer` irrespective of the
3373    /// platform's endianness.
3374    ///
3375    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3376    #[wasm_bindgen(constructor)]
3377    pub fn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView;
3378
3379    /// The `DataView` view provides a low-level interface for reading and
3380    /// writing multiple number types in an `ArrayBuffer` irrespective of the
3381    /// platform's endianness.
3382    ///
3383    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3384    #[wasm_bindgen(constructor)]
3385    pub fn new_with_shared_array_buffer(
3386        buffer: &SharedArrayBuffer,
3387        byteOffset: usize,
3388        byteLength: usize,
3389    ) -> DataView;
3390
3391    /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
3392    ///
3393    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer)
3394    #[wasm_bindgen(method, getter)]
3395    pub fn buffer(this: &DataView) -> ArrayBuffer;
3396
3397    /// The length (in bytes) of this view from the start of its ArrayBuffer.
3398    /// Fixed at construction time and thus read only.
3399    ///
3400    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength)
3401    #[wasm_bindgen(method, getter, js_name = byteLength)]
3402    pub fn byte_length(this: &DataView) -> usize;
3403
3404    /// The offset (in bytes) of this view from the start of its ArrayBuffer.
3405    /// Fixed at construction time and thus read only.
3406    ///
3407    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset)
3408    #[wasm_bindgen(method, getter, js_name = byteOffset)]
3409    pub fn byte_offset(this: &DataView) -> usize;
3410
3411    /// The `getInt8()` method gets a signed 8-bit integer (byte) at the
3412    /// specified byte offset from the start of the DataView.
3413    ///
3414    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8)
3415    #[wasm_bindgen(method, js_name = getInt8)]
3416    pub fn get_int8(this: &DataView, byte_offset: usize) -> i8;
3417
3418    /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified
3419    /// byte offset from the start of the DataView.
3420    ///
3421    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8)
3422    #[wasm_bindgen(method, js_name = getUint8)]
3423    pub fn get_uint8(this: &DataView, byte_offset: usize) -> u8;
3424
3425    /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3426    /// byte offset from the start of the DataView.
3427    ///
3428    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3429    #[wasm_bindgen(method, js_name = getInt16)]
3430    pub fn get_int16(this: &DataView, byte_offset: usize) -> i16;
3431
3432    /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3433    /// byte offset from the start of the DataView.
3434    ///
3435    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3436    #[wasm_bindgen(method, js_name = getInt16)]
3437    pub fn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16;
3438
3439    /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3440    /// byte offset from the start of the view.
3441    ///
3442    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3443    #[wasm_bindgen(method, js_name = getUint16)]
3444    pub fn get_uint16(this: &DataView, byte_offset: usize) -> u16;
3445
3446    /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3447    /// byte offset from the start of the view.
3448    ///
3449    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3450    #[wasm_bindgen(method, js_name = getUint16)]
3451    pub fn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16;
3452
3453    /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3454    /// byte offset from the start of the DataView.
3455    ///
3456    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3457    #[wasm_bindgen(method, js_name = getInt32)]
3458    pub fn get_int32(this: &DataView, byte_offset: usize) -> i32;
3459
3460    /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3461    /// byte offset from the start of the DataView.
3462    ///
3463    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3464    #[wasm_bindgen(method, js_name = getInt32)]
3465    pub fn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32;
3466
3467    /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3468    /// byte offset from the start of the view.
3469    ///
3470    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3471    #[wasm_bindgen(method, js_name = getUint32)]
3472    pub fn get_uint32(this: &DataView, byte_offset: usize) -> u32;
3473
3474    /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3475    /// byte offset from the start of the view.
3476    ///
3477    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3478    #[wasm_bindgen(method, js_name = getUint32)]
3479    pub fn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32;
3480
3481    /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3482    /// byte offset from the start of the DataView.
3483    ///
3484    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3485    #[wasm_bindgen(method, js_name = getFloat32)]
3486    pub fn get_float32(this: &DataView, byte_offset: usize) -> f32;
3487
3488    /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3489    /// byte offset from the start of the DataView.
3490    ///
3491    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3492    #[wasm_bindgen(method, js_name = getFloat32)]
3493    pub fn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32;
3494
3495    /// The `getFloat16()` method gets a signed 16-bit float at the specified
3496    /// byte offset from the start of the DataView as an `f32`.
3497    ///
3498    /// The unsuffixed `get_float16` name is reserved for a future native
3499    /// `f16` binding once Rust stabilizes the type.
3500    ///
3501    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16)
3502    #[wasm_bindgen(method, js_name = getFloat16)]
3503    pub fn get_float16_as_f32(this: &DataView, byte_offset: usize) -> f32;
3504
3505    /// The `getFloat16()` method gets a signed 16-bit float at the specified
3506    /// byte offset from the start of the DataView as an `f32`.
3507    ///
3508    /// The unsuffixed `get_float16_endian` name is reserved for a future
3509    /// native `f16` binding once Rust stabilizes the type.
3510    ///
3511    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16)
3512    #[wasm_bindgen(method, js_name = getFloat16)]
3513    pub fn get_float16_endian_as_f32(
3514        this: &DataView,
3515        byte_offset: usize,
3516        little_endian: bool,
3517    ) -> f32;
3518
3519    /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3520    /// byte offset from the start of the DataView.
3521    ///
3522    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3523    #[wasm_bindgen(method, js_name = getFloat64)]
3524    pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
3525
3526    /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3527    /// byte offset from the start of the DataView.
3528    ///
3529    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3530    #[wasm_bindgen(method, js_name = getFloat64)]
3531    pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
3532
3533    /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
3534    /// specified byte offset from the start of the DataView.
3535    ///
3536    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
3537    #[wasm_bindgen(method, js_name = setInt8)]
3538    pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
3539
3540    /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
3541    /// specified byte offset from the start of the DataView.
3542    ///
3543    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
3544    #[wasm_bindgen(method, js_name = setUint8)]
3545    pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
3546
3547    /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3548    /// specified byte offset from the start of the DataView.
3549    ///
3550    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3551    #[wasm_bindgen(method, js_name = setInt16)]
3552    pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
3553
3554    /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3555    /// specified byte offset from the start of the DataView.
3556    ///
3557    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3558    #[wasm_bindgen(method, js_name = setInt16)]
3559    pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
3560
3561    /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3562    /// specified byte offset from the start of the DataView.
3563    ///
3564    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3565    #[wasm_bindgen(method, js_name = setUint16)]
3566    pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
3567
3568    /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3569    /// specified byte offset from the start of the DataView.
3570    ///
3571    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3572    #[wasm_bindgen(method, js_name = setUint16)]
3573    pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
3574
3575    /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3576    /// specified byte offset from the start of the DataView.
3577    ///
3578    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3579    #[wasm_bindgen(method, js_name = setInt32)]
3580    pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
3581
3582    /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3583    /// specified byte offset from the start of the DataView.
3584    ///
3585    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3586    #[wasm_bindgen(method, js_name = setInt32)]
3587    pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
3588
3589    /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3590    /// specified byte offset from the start of the DataView.
3591    ///
3592    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3593    #[wasm_bindgen(method, js_name = setUint32)]
3594    pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
3595
3596    /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3597    /// specified byte offset from the start of the DataView.
3598    ///
3599    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3600    #[wasm_bindgen(method, js_name = setUint32)]
3601    pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
3602
3603    /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3604    /// specified byte offset from the start of the DataView.
3605    ///
3606    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3607    #[wasm_bindgen(method, js_name = setFloat32)]
3608    pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
3609
3610    /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3611    /// specified byte offset from the start of the DataView.
3612    ///
3613    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3614    #[wasm_bindgen(method, js_name = setFloat32)]
3615    pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
3616
3617    /// The `setFloat16()` method stores a signed 16-bit float value from an
3618    /// `f32` at the specified byte offset from the start of the DataView.
3619    ///
3620    /// The unsuffixed `set_float16` name is reserved for a future native
3621    /// `f16` binding once Rust stabilizes the type.
3622    ///
3623    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16)
3624    #[wasm_bindgen(method, js_name = setFloat16)]
3625    pub fn set_float16_from_f32(this: &DataView, byte_offset: usize, value: f32);
3626
3627    /// The `setFloat16()` method stores a signed 16-bit float value from an
3628    /// `f32` at the specified byte offset from the start of the DataView.
3629    ///
3630    /// The unsuffixed `set_float16_endian` name is reserved for a future
3631    /// native `f16` binding once Rust stabilizes the type.
3632    ///
3633    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16)
3634    #[wasm_bindgen(method, js_name = setFloat16)]
3635    pub fn set_float16_endian_from_f32(
3636        this: &DataView,
3637        byte_offset: usize,
3638        value: f32,
3639        little_endian: bool,
3640    );
3641
3642    /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3643    /// specified byte offset from the start of the DataView.
3644    ///
3645    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3646    #[wasm_bindgen(method, js_name = setFloat64)]
3647    pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
3648
3649    /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3650    /// specified byte offset from the start of the DataView.
3651    ///
3652    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3653    #[wasm_bindgen(method, js_name = setFloat64)]
3654    pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
3655}
3656
3657// DisposableStack
3658#[wasm_bindgen]
3659extern "C" {
3660    /// A `DisposableStack` aggregates disposable resources, disposing them
3661    /// in reverse order of registration when `dispose()` is called.
3662    ///
3663    /// Callbacks registered with `adopt()` and `defer()` run later, at
3664    /// disposal time, so they are taken as [`ScopedClosure`]s which must
3665    /// outlive the stack's disposal. A stack disposed within the scope its
3666    /// closures live in needs nothing more. One that outlives that scope,
3667    /// through `move()` or by being stored, needs `'static` [`Closure`]s
3668    /// handed to JS with [`Closure::forget`]; a disposer runs once, so
3669    /// [`Closure::once`] frees its captures as soon as it has run.
3670    ///
3671    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack)
3672    #[wasm_bindgen(extends = Object, typescript_type = "DisposableStack")]
3673    #[derive(Clone, Debug, PartialEq, Eq)]
3674    pub type DisposableStack;
3675
3676    /// Creates a new, empty `DisposableStack`.
3677    ///
3678    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/DisposableStack)
3679    #[wasm_bindgen(constructor)]
3680    pub fn new() -> DisposableStack;
3681
3682    /// The `disposed` accessor property returns whether this stack has
3683    /// already been disposed.
3684    ///
3685    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/disposed)
3686    #[wasm_bindgen(method, getter)]
3687    pub fn disposed(this: &DisposableStack) -> bool;
3688
3689    /// The `dispose()` method disposes every resource in the stack in
3690    /// reverse order of registration. Errors thrown by disposers are
3691    /// collected into a [`SuppressedError`] chain and rethrown.
3692    ///
3693    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/dispose)
3694    #[wasm_bindgen(method, catch)]
3695    pub fn dispose(this: &DisposableStack) -> Result<(), JsValue>;
3696
3697    /// The `use()` method registers a value implementing `Symbol.dispose`
3698    /// for disposal and returns it. Throws a `TypeError` if the value is
3699    /// not `null`, `undefined` or disposable.
3700    ///
3701    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/use)
3702    #[wasm_bindgen(method, catch, js_name = use)]
3703    pub fn use_<T>(this: &DisposableStack, value: &T) -> Result<T, JsValue>;
3704
3705    /// The `adopt()` method registers a non-disposable value together with
3706    /// a callback to dispose it, and returns the value.
3707    ///
3708    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/adopt)
3709    #[wasm_bindgen(method, catch)]
3710    pub fn adopt<'a, T>(
3711        this: &DisposableStack,
3712        value: &T,
3713        on_dispose: &ScopedClosure<'a, dyn FnMut(T)>,
3714    ) -> Result<T, JsValue>;
3715
3716    /// The `defer()` method registers a callback to run when the stack is
3717    /// disposed.
3718    ///
3719    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/defer)
3720    #[wasm_bindgen(method, catch)]
3721    pub fn defer(
3722        this: &DisposableStack,
3723        on_dispose: &ScopedClosure<dyn FnMut()>,
3724    ) -> Result<(), JsValue>;
3725
3726    /// The `move()` method transfers every resource into a new
3727    /// `DisposableStack`, marking this one as disposed.
3728    ///
3729    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/move)
3730    #[wasm_bindgen(method, catch, js_name = move)]
3731    pub fn move_(this: &DisposableStack) -> Result<DisposableStack, JsValue>;
3732}
3733
3734impl Default for DisposableStack {
3735    fn default() -> Self {
3736        Self::new()
3737    }
3738}
3739
3740// AsyncDisposableStack
3741#[wasm_bindgen]
3742extern "C" {
3743    /// An `AsyncDisposableStack` aggregates async-disposable resources,
3744    /// disposing them in reverse order of registration when
3745    /// `disposeAsync()` is called.
3746    ///
3747    /// Callbacks registered with `adopt()` and `defer()` run later, at
3748    /// disposal time, so they are taken as [`ScopedClosure`]s which must
3749    /// outlive the stack's disposal. A stack disposed within the scope its
3750    /// closures live in needs nothing more. One that outlives that scope,
3751    /// through `move()` or by being stored, needs `'static` [`Closure`]s
3752    /// handed to JS with [`Closure::forget`]; a disposer runs once, so
3753    /// [`Closure::once`] frees its captures as soon as it has run.
3754    ///
3755    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack)
3756    #[wasm_bindgen(extends = Object, typescript_type = "AsyncDisposableStack")]
3757    #[derive(Clone, Debug, PartialEq, Eq)]
3758    pub type AsyncDisposableStack;
3759
3760    /// Creates a new, empty `AsyncDisposableStack`.
3761    ///
3762    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/AsyncDisposableStack)
3763    #[wasm_bindgen(constructor)]
3764    pub fn new() -> AsyncDisposableStack;
3765
3766    /// The `disposed` accessor property returns whether this stack has
3767    /// already been disposed.
3768    ///
3769    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/disposed)
3770    #[wasm_bindgen(method, getter)]
3771    pub fn disposed(this: &AsyncDisposableStack) -> bool;
3772
3773    /// The `disposeAsync()` method disposes every resource in the stack in
3774    /// reverse order of registration, awaiting each, and returns a promise
3775    /// that settles once all have completed.
3776    ///
3777    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/disposeAsync)
3778    #[wasm_bindgen(method, js_name = disposeAsync)]
3779    pub fn dispose_async(this: &AsyncDisposableStack) -> Promise<Undefined>;
3780
3781    /// The `use()` method registers a value implementing `Symbol.asyncDispose`
3782    /// or `Symbol.dispose` for disposal and returns it.
3783    ///
3784    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/use)
3785    #[wasm_bindgen(method, catch, js_name = use)]
3786    pub fn use_<T>(this: &AsyncDisposableStack, value: &T) -> Result<T, JsValue>;
3787
3788    /// The `adopt()` method registers a non-disposable value together with
3789    /// an async callback to dispose it, and returns the value.
3790    ///
3791    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/adopt)
3792    #[wasm_bindgen(method, catch)]
3793    pub fn adopt<'a, T, R: Promising>(
3794        this: &AsyncDisposableStack,
3795        value: &T,
3796        on_dispose_async: &ScopedClosure<'a, dyn FnMut(T) -> R>,
3797    ) -> Result<T, JsValue>;
3798
3799    /// The `defer()` method registers an async callback to run when the
3800    /// stack is disposed.
3801    ///
3802    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/defer)
3803    #[wasm_bindgen(method, catch)]
3804    pub fn defer<'a, R: Promising>(
3805        this: &AsyncDisposableStack,
3806        on_dispose_async: &ScopedClosure<'a, dyn FnMut() -> R>,
3807    ) -> Result<(), JsValue>;
3808
3809    /// The `move()` method transfers every resource into a new
3810    /// `AsyncDisposableStack`, marking this one as disposed.
3811    ///
3812    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/move)
3813    #[wasm_bindgen(method, catch, js_name = move)]
3814    pub fn move_(this: &AsyncDisposableStack) -> Result<AsyncDisposableStack, JsValue>;
3815}
3816
3817impl Default for AsyncDisposableStack {
3818    fn default() -> Self {
3819        Self::new()
3820    }
3821}
3822
3823// Error
3824#[wasm_bindgen]
3825extern "C" {
3826    #[wasm_bindgen(extends = Object, typescript_type = "Error")]
3827    #[derive(Clone, Debug, PartialEq, Eq)]
3828    pub type Error;
3829
3830    /// The Error constructor creates an error object.
3831    /// Instances of Error objects are thrown when runtime errors occur.
3832    /// The Error object can also be used as a base object for user-defined exceptions.
3833    /// See below for standard built-in error types.
3834    ///
3835    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
3836    #[wasm_bindgen(constructor)]
3837    pub fn new(message: &str) -> Error;
3838
3839    /// Creates a new `Error` with the given message and an untyped options
3840    /// object whose `cause` property indicates the original cause of the
3841    /// error.
3842    ///
3843    /// New code should prefer [`Error::new_with_error_options`], which takes
3844    /// a typed [`ErrorOptions`] dictionary.
3845    ///
3846    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
3847    #[wasm_bindgen(constructor)]
3848    pub fn new_with_options(message: &str, options: &Object) -> Error;
3849
3850    /// Creates a new `Error` with the given message and a typed
3851    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
3852    /// original cause of the error.
3853    ///
3854    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
3855    #[wasm_bindgen(constructor)]
3856    pub fn new_with_error_options(message: &str, options: &ErrorOptions) -> Error;
3857
3858    /// The cause property is the underlying cause of the error.
3859    /// Usually this is used to add context to re-thrown errors.
3860    ///
3861    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors)
3862    #[wasm_bindgen(method, getter)]
3863    pub fn cause(this: &Error) -> JsValue;
3864    #[wasm_bindgen(method, setter)]
3865    pub fn set_cause(this: &Error, cause: &JsValue);
3866
3867    /// The message property is a human-readable description of the error.
3868    ///
3869    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
3870    #[wasm_bindgen(method, getter)]
3871    pub fn message(this: &Error) -> JsString;
3872    #[wasm_bindgen(method, setter)]
3873    pub fn set_message(this: &Error, message: &str);
3874
3875    /// The name property represents a name for the type of error. The initial value is "Error".
3876    ///
3877    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
3878    #[wasm_bindgen(method, getter)]
3879    pub fn name(this: &Error) -> JsString;
3880    #[wasm_bindgen(method, setter)]
3881    pub fn set_name(this: &Error, name: &str);
3882
3883    /// The `toString()` method returns a string representing the specified Error object
3884    ///
3885    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
3886    #[cfg(not(js_sys_unstable_apis))]
3887    #[wasm_bindgen(method, js_name = toString)]
3888    pub fn to_string(this: &Error) -> JsString;
3889
3890    /// The `Error.stackTraceLimit` property controls the number of stack
3891    /// frames collected by a stack trace.
3892    ///
3893    /// This is a non-standard V8/Node.js API.
3894    ///
3895    /// [V8 documentation](https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions)
3896    #[wasm_bindgen(static_method_of = Error, getter, js_name = stackTraceLimit)]
3897    pub fn stack_trace_limit() -> JsValue;
3898
3899    /// Set `Error.stackTraceLimit` to control the number of stack frames
3900    /// collected by a stack trace.
3901    ///
3902    /// This is a non-standard V8/Node.js API.
3903    ///
3904    /// [V8 documentation](https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions)
3905    #[wasm_bindgen(static_method_of = Error, setter, js_name = stackTraceLimit)]
3906    pub fn set_stack_trace_limit(value: &JsValue);
3907
3908    /// The `Error.isError()` static method determines whether the passed
3909    /// value is an `Error` instance, including across realms, by checking
3910    /// for the internal `[[ErrorData]]` slot rather than the prototype chain.
3911    ///
3912    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/isError)
3913    #[wasm_bindgen(static_method_of = Error, js_name = isError)]
3914    pub fn is_error(value: &JsValue) -> bool;
3915}
3916
3917partialord_ord!(JsString);
3918
3919// EvalError
3920#[wasm_bindgen]
3921extern "C" {
3922    #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
3923    #[derive(Clone, Debug, PartialEq, Eq)]
3924    pub type EvalError;
3925
3926    /// The `EvalError` object indicates an error regarding the global eval() function. This
3927    /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
3928    /// compatibility.
3929    ///
3930    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
3931    #[wasm_bindgen(constructor)]
3932    pub fn new(message: &str) -> EvalError;
3933
3934    /// Creates a new `EvalError` with the given message and a typed
3935    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
3936    /// original cause of the error.
3937    ///
3938    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError/EvalError)
3939    #[wasm_bindgen(constructor)]
3940    pub fn new_with_options(message: &str, options: &ErrorOptions) -> EvalError;
3941}
3942
3943#[wasm_bindgen]
3944extern "C" {
3945    #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, no_upcast, typescript_type = "Function")]
3946    #[derive(Clone, Debug, PartialEq, Eq)]
3947    /// `Function` represents any generic Function in JS, by treating all arguments as `JsValue`.
3948    ///
3949    /// It takes a generic parameter of phantom type `fn (Arg1, ..., Argn) -> Ret` which
3950    /// is used to type the JS function. For example, `Function<fn () -> Number>` represents
3951    /// a function taking no arguments that returns a number.
3952    ///
3953    /// The 8 generic argument parameters (`Arg1` through `Arg8`) are the argument
3954    /// types. Arguments not provided enable strict arity checking at compile time.
3955    ///
3956    /// A void function is represented by `fn (Arg) -> Undefined`, and **not** the `()` unit
3957    /// type. This is because generics must be based on JS values in the JS generic type system.
3958    ///
3959    /// _The default without any parameters is as a void function - no arguments, `Undefined` return._
3960    ///
3961    /// _The default generic for `Function` is `fn (JsValue, JsValue, ...) -> JsValue`,
3962    /// representing any function, since all functions safely upcast into this function._
3963    ///
3964    /// ### Arity Enforcement
3965    ///
3966    /// It is not possible to use `call4` or `bind4` on a function that does not have
3967    /// at least 4 arguments — the compiler will reject this because only arguments that
3968    /// are not `None` support the trait bound for `ErasableGeneric`.
3969    ///
3970    /// ### Examples
3971    ///
3972    /// ```ignore
3973    /// // A function taking no args, returning Number
3974    /// let f: Function<Number> = get_some_fn();
3975    ///
3976    /// // A function taking (String, Number) and returning Boolean
3977    /// let f: Function<Boolean, String, Number> = get_some_fn();
3978    ///
3979    /// ### Upcasting
3980    ///
3981    /// To pass a typed `Function` where a different generic Function is expected, `upcast()` may be used
3982    /// to convert into any generic `Function` at zero cost with type-safety.
3983    ///
3984    /// MDN documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3985    pub type Function<
3986        T: JsFunction = fn(
3987            JsValue,
3988            JsValue,
3989            JsValue,
3990            JsValue,
3991            JsValue,
3992            JsValue,
3993            JsValue,
3994            JsValue,
3995        ) -> JsValue,
3996    >;
3997}
3998
3999#[wasm_bindgen]
4000extern "C" {
4001    /// The `Function` constructor creates a new `Function` object. Calling the
4002    /// constructor directly can create functions dynamically, but suffers from
4003    /// security and similar (but far less significant) performance issues
4004    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
4005    /// allows executing code in the global scope, prompting better programming
4006    /// habits and allowing for more efficient code minification.
4007    ///
4008    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
4009    #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
4010    #[wasm_bindgen(constructor)]
4011    pub fn new_with_args(args: &str, body: &str) -> Function;
4012
4013    /// The `Function` constructor creates a new `Function` object. Calling the
4014    /// constructor directly can create functions dynamically, but suffers from
4015    /// security and similar (but far less significant) performance issues
4016    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
4017    /// allows executing code in the global scope, prompting better programming
4018    /// habits and allowing for more efficient code minification.
4019    ///
4020    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
4021    #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
4022    #[wasm_bindgen(constructor)]
4023    pub fn new_with_args<T: JsFunction = fn() -> JsValue>(args: &str, body: &str) -> Function<T>;
4024
4025    // Next major: deprecate
4026    /// The `Function` constructor creates a new `Function` object. Calling the
4027    /// constructor directly can create functions dynamically, but suffers from
4028    /// security and similar (but far less significant) performance issues
4029    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
4030    /// allows executing code in the global scope, prompting better programming
4031    /// habits and allowing for more efficient code minification.
4032    ///
4033    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
4034    #[cfg(feature = "unsafe-eval")]
4035    #[wasm_bindgen(constructor)]
4036    pub fn new_with_args_typed<T: JsFunction = fn() -> JsValue>(
4037        args: &str,
4038        body: &str,
4039    ) -> Function<T>;
4040
4041    /// The `Function` constructor creates a new `Function` object. Calling the
4042    /// constructor directly can create functions dynamically, but suffers from
4043    /// security and similar (but far less significant) performance issues
4044    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
4045    /// allows executing code in the global scope, prompting better programming
4046    /// habits and allowing for more efficient code minification.
4047    ///
4048    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
4049    #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
4050    #[wasm_bindgen(constructor)]
4051    pub fn new_no_args(body: &str) -> Function;
4052
4053    /// The `Function` constructor creates a new `Function` object. Calling the
4054    /// constructor directly can create functions dynamically, but suffers from
4055    /// security and similar (but far less significant) performance issues
4056    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
4057    /// allows executing code in the global scope, prompting better programming
4058    /// habits and allowing for more efficient code minification.
4059    ///
4060    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
4061    #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
4062    #[wasm_bindgen(constructor)]
4063    pub fn new_no_args<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
4064
4065    // Next major: deprecate
4066    /// The `Function` constructor creates a new `Function` object.
4067    ///
4068    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
4069    #[cfg(feature = "unsafe-eval")]
4070    #[wasm_bindgen(constructor)]
4071    pub fn new_no_args_typed<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
4072
4073    /// The `apply()` method calls a function with a given this value, and arguments provided as an array
4074    /// (or an array-like object).
4075    ///
4076    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
4077    #[wasm_bindgen(method, catch)]
4078    pub fn apply<T: JsFunction = fn() -> JsValue>(
4079        this: &Function<T>,
4080        context: &JsValue,
4081        args: &Array,
4082    ) -> Result<<T as JsFunction>::Ret, JsValue>;
4083
4084    // Next major: Deprecate, and separately provide provide impl
4085    /// The `call()` method calls a function with a given this value and
4086    /// arguments provided individually.
4087    ///
4088    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4089    ///
4090    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4091    #[wasm_bindgen(method, catch, js_name = call)]
4092    pub fn call0<Ret: JsGeneric, F: JsFunction<Ret = Ret> = fn() -> JsValue>(
4093        this: &Function<F>,
4094        context: &JsValue,
4095    ) -> Result<Ret, JsValue>;
4096
4097    // Next major: Deprecate, and separately provide provide impl
4098    /// The `call()` method calls a function with a given this value and
4099    /// arguments provided individually.
4100    ///
4101    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4102    ///
4103    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4104    #[wasm_bindgen(method, catch, js_name = call)]
4105    pub fn call1<
4106        Ret: JsGeneric,
4107        Arg1: JsGeneric,
4108        F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> = fn(JsValue) -> JsValue,
4109    >(
4110        this: &Function<F>,
4111        context: &JsValue,
4112        arg1: &Arg1,
4113    ) -> Result<Ret, JsValue>;
4114
4115    // Next major: Deprecate, and separately provide provide impl
4116    /// The `call()` method calls a function with a given this value and
4117    /// arguments provided individually.
4118    ///
4119    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4120    ///
4121    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4122    #[wasm_bindgen(method, catch, js_name = call)]
4123    pub fn call2<
4124        Ret: JsGeneric,
4125        Arg1: JsGeneric,
4126        Arg2: JsGeneric,
4127        F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> + JsFunction2<Arg2 = Arg2> = fn(
4128            JsValue,
4129            JsValue,
4130        ) -> JsValue,
4131    >(
4132        this: &Function<F>,
4133        context: &JsValue,
4134        arg1: &Arg1,
4135        arg2: &Arg2,
4136    ) -> Result<Ret, JsValue>;
4137
4138    // Next major: Deprecate, and separately provide provide impl
4139    /// The `call()` method calls a function with a given this value and
4140    /// arguments provided individually.
4141    ///
4142    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4143    ///
4144    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4145    #[wasm_bindgen(method, catch, js_name = call)]
4146    pub fn call3<
4147        Ret: JsGeneric,
4148        Arg1: JsGeneric,
4149        Arg2: JsGeneric,
4150        Arg3: JsGeneric,
4151        F: JsFunction<Ret = Ret> + JsFunction3<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
4152            JsValue,
4153            JsValue,
4154            JsValue,
4155        ) -> JsValue,
4156    >(
4157        this: &Function<F>,
4158        context: &JsValue,
4159        arg1: &Arg1,
4160        arg2: &Arg2,
4161        arg3: &Arg3,
4162    ) -> Result<Ret, JsValue>;
4163
4164    // Next major: Deprecate, and separately provide provide impl
4165    /// The `call()` method calls a function with a given this value and
4166    /// arguments provided individually.
4167    ///
4168    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4169    ///
4170    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4171    #[wasm_bindgen(method, catch, js_name = call)]
4172    pub fn call4<
4173        Ret: JsGeneric,
4174        Arg1: JsGeneric,
4175        Arg2: JsGeneric,
4176        Arg3: JsGeneric,
4177        Arg4: JsGeneric,
4178        F: JsFunction<Ret = Ret> + JsFunction4<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
4179            JsValue,
4180            JsValue,
4181            JsValue,
4182            JsValue,
4183        ) -> JsValue,
4184    >(
4185        this: &Function<F>,
4186        context: &JsValue,
4187        arg1: &Arg1,
4188        arg2: &Arg2,
4189        arg3: &Arg3,
4190        arg4: &Arg4,
4191    ) -> Result<Ret, JsValue>;
4192
4193    // Next major: Deprecate, and separately provide provide impl
4194    /// The `call()` method calls a function with a given this value and
4195    /// arguments provided individually.
4196    ///
4197    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4198    ///
4199    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4200    #[wasm_bindgen(method, catch, js_name = call)]
4201    pub fn call5<
4202        Ret: JsGeneric,
4203        Arg1: JsGeneric,
4204        Arg2: JsGeneric,
4205        Arg3: JsGeneric,
4206        Arg4: JsGeneric,
4207        Arg5: JsGeneric,
4208        F: JsFunction<Ret = Ret>
4209            + JsFunction5<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4210            JsValue,
4211            JsValue,
4212            JsValue,
4213            JsValue,
4214            JsValue,
4215        ) -> JsValue,
4216    >(
4217        this: &Function<F>,
4218        context: &JsValue,
4219        arg1: &Arg1,
4220        arg2: &Arg2,
4221        arg3: &Arg3,
4222        arg4: &Arg4,
4223        arg5: &Arg5,
4224    ) -> Result<Ret, JsValue>;
4225
4226    // Next major: Deprecate, and separately provide provide impl
4227    /// The `call()` method calls a function with a given this value and
4228    /// arguments provided individually.
4229    ///
4230    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4231    ///
4232    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4233    #[wasm_bindgen(method, catch, js_name = call)]
4234    pub fn call6<
4235        Ret: JsGeneric,
4236        Arg1: JsGeneric,
4237        Arg2: JsGeneric,
4238        Arg3: JsGeneric,
4239        Arg4: JsGeneric,
4240        Arg5: JsGeneric,
4241        Arg6: JsGeneric,
4242        F: JsFunction<Ret = Ret>
4243            + JsFunction6<
4244                Arg1 = Arg1,
4245                Arg2 = Arg2,
4246                Arg3 = Arg3,
4247                Arg4 = Arg4,
4248                Arg5 = Arg5,
4249                Arg6 = Arg6,
4250            > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4251    >(
4252        this: &Function<F>,
4253        context: &JsValue,
4254        arg1: &Arg1,
4255        arg2: &Arg2,
4256        arg3: &Arg3,
4257        arg4: &Arg4,
4258        arg5: &Arg5,
4259        arg6: &Arg6,
4260    ) -> Result<Ret, JsValue>;
4261
4262    // Next major: Deprecate, and separately provide provide impl
4263    /// The `call()` method calls a function with a given this value and
4264    /// arguments provided individually.
4265    ///
4266    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4267    ///
4268    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4269    #[wasm_bindgen(method, catch, js_name = call)]
4270    pub fn call7<
4271        Ret: JsGeneric,
4272        Arg1: JsGeneric,
4273        Arg2: JsGeneric,
4274        Arg3: JsGeneric,
4275        Arg4: JsGeneric,
4276        Arg5: JsGeneric,
4277        Arg6: JsGeneric,
4278        Arg7: JsGeneric,
4279        F: JsFunction<Ret = Ret>
4280            + JsFunction7<
4281                Arg1 = Arg1,
4282                Arg2 = Arg2,
4283                Arg3 = Arg3,
4284                Arg4 = Arg4,
4285                Arg5 = Arg5,
4286                Arg6 = Arg6,
4287                Arg7 = Arg7,
4288            > = fn(
4289            JsValue,
4290            JsValue,
4291            JsValue,
4292            JsValue,
4293            JsValue,
4294            JsValue,
4295            JsValue,
4296        ) -> JsValue,
4297    >(
4298        this: &Function<F>,
4299        context: &JsValue,
4300        arg1: &Arg1,
4301        arg2: &Arg2,
4302        arg3: &Arg3,
4303        arg4: &Arg4,
4304        arg5: &Arg5,
4305        arg6: &Arg6,
4306        arg7: &Arg7,
4307    ) -> Result<Ret, JsValue>;
4308
4309    // Next major: Deprecate, and separately provide provide impl
4310    /// The `call()` method calls a function with a given this value and
4311    /// arguments provided individually.
4312    ///
4313    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4314    ///
4315    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4316    #[wasm_bindgen(method, catch, js_name = call)]
4317    pub fn call8<
4318        Ret: JsGeneric,
4319        Arg1: JsGeneric,
4320        Arg2: JsGeneric,
4321        Arg3: JsGeneric,
4322        Arg4: JsGeneric,
4323        Arg5: JsGeneric,
4324        Arg6: JsGeneric,
4325        Arg7: JsGeneric,
4326        Arg8: JsGeneric,
4327        F: JsFunction8<
4328            Ret = Ret,
4329            Arg1 = Arg1,
4330            Arg2 = Arg2,
4331            Arg3 = Arg3,
4332            Arg4 = Arg4,
4333            Arg5 = Arg5,
4334            Arg6 = Arg6,
4335            Arg7 = Arg7,
4336            Arg8 = Arg8,
4337        > = fn(
4338            JsValue,
4339            JsValue,
4340            JsValue,
4341            JsValue,
4342            JsValue,
4343            JsValue,
4344            JsValue,
4345            JsValue,
4346        ) -> JsValue,
4347    >(
4348        this: &Function<F>,
4349        context: &JsValue,
4350        arg1: &Arg1,
4351        arg2: &Arg2,
4352        arg3: &Arg3,
4353        arg4: &Arg4,
4354        arg5: &Arg5,
4355        arg6: &Arg6,
4356        arg7: &Arg7,
4357        arg8: &Arg8,
4358    ) -> Result<Ret, JsValue>;
4359
4360    /// The `call()` method calls a function with a given this value and
4361    /// arguments provided individually.
4362    ///
4363    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4364    ///
4365    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4366    #[deprecated]
4367    #[allow(deprecated)]
4368    #[wasm_bindgen(method, catch, js_name = call)]
4369    pub fn call9<
4370        Ret: JsGeneric,
4371        Arg1: JsGeneric,
4372        Arg2: JsGeneric,
4373        Arg3: JsGeneric,
4374        Arg4: JsGeneric,
4375        Arg5: JsGeneric,
4376        Arg6: JsGeneric,
4377        Arg7: JsGeneric,
4378        Arg8: JsGeneric,
4379        F: JsFunction8<
4380            Ret = Ret,
4381            Arg1 = Arg1,
4382            Arg2 = Arg2,
4383            Arg3 = Arg3,
4384            Arg4 = Arg4,
4385            Arg5 = Arg5,
4386            Arg6 = Arg6,
4387            Arg7 = Arg7,
4388            Arg8 = Arg8,
4389        > = fn(
4390            JsValue,
4391            JsValue,
4392            JsValue,
4393            JsValue,
4394            JsValue,
4395            JsValue,
4396            JsValue,
4397            JsValue,
4398        ) -> JsValue,
4399    >(
4400        this: &Function<F>,
4401        context: &JsValue,
4402        arg1: &Arg1,
4403        arg2: &Arg2,
4404        arg3: &Arg3,
4405        arg4: &Arg4,
4406        arg5: &Arg5,
4407        arg6: &Arg6,
4408        arg7: &Arg7,
4409        arg8: &Arg8,
4410        arg9: &JsValue,
4411    ) -> Result<Ret, JsValue>;
4412
4413    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4414    /// with a given sequence of arguments preceding any provided when the new function is called.
4415    ///
4416    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4417    #[cfg(not(js_sys_unstable_apis))]
4418    #[deprecated(note = "Use `Function::bind0` instead.")]
4419    #[allow(deprecated)]
4420    #[wasm_bindgen(method, js_name = bind)]
4421    pub fn bind<T: JsFunction = fn() -> JsValue>(
4422        this: &Function<T>,
4423        context: &JsValue,
4424    ) -> Function<T>;
4425
4426    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4427    /// with a given sequence of arguments preceding any provided when the new function is called.
4428    ///
4429    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4430    ///
4431    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4432    #[wasm_bindgen(method, js_name = bind)]
4433    pub fn bind0<T: JsFunction = fn() -> JsValue>(
4434        this: &Function<T>,
4435        context: &JsValue,
4436    ) -> Function<T>;
4437
4438    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4439    /// with a given sequence of arguments preceding any provided when the new function is called.
4440    ///
4441    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4442    ///
4443    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4444    #[wasm_bindgen(method, js_name = bind)]
4445    pub fn bind1<
4446        Ret: JsGeneric,
4447        Arg1: JsGeneric,
4448        F: JsFunction1<Ret = Ret, Arg1 = Arg1> = fn(JsValue) -> JsValue,
4449    >(
4450        this: &Function<F>,
4451        context: &JsValue,
4452        arg1: &Arg1,
4453    ) -> Function<<F as JsFunction1>::Bind1>;
4454
4455    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4456    /// with a given sequence of arguments preceding any provided when the new function is called.
4457    ///
4458    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4459    ///
4460    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4461    #[wasm_bindgen(method, js_name = bind)]
4462    pub fn bind2<
4463        Ret: JsGeneric,
4464        Arg1: JsGeneric,
4465        Arg2: JsGeneric,
4466        F: JsFunction2<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2> = fn(JsValue, JsValue) -> JsValue,
4467    >(
4468        this: &Function<F>,
4469        context: &JsValue,
4470        arg1: &Arg1,
4471        arg2: &Arg2,
4472    ) -> Function<<F as JsFunction2>::Bind2>;
4473
4474    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4475    /// with a given sequence of arguments preceding any provided when the new function is called.
4476    ///
4477    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4478    ///
4479    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4480    #[wasm_bindgen(method, js_name = bind)]
4481    pub fn bind3<
4482        Ret: JsGeneric,
4483        Arg1: JsGeneric,
4484        Arg2: JsGeneric,
4485        Arg3: JsGeneric,
4486        F: JsFunction3<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
4487            JsValue,
4488            JsValue,
4489            JsValue,
4490        ) -> JsValue,
4491    >(
4492        this: &Function<F>,
4493        context: &JsValue,
4494        arg1: &Arg1,
4495        arg2: &Arg2,
4496        arg3: &Arg3,
4497    ) -> Function<<F as JsFunction3>::Bind3>;
4498
4499    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4500    /// with a given sequence of arguments preceding any provided when the new function is called.
4501    ///
4502    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4503    ///
4504    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4505    #[wasm_bindgen(method, js_name = bind)]
4506    pub fn bind4<
4507        Ret: JsGeneric,
4508        Arg1: JsGeneric,
4509        Arg2: JsGeneric,
4510        Arg3: JsGeneric,
4511        Arg4: JsGeneric,
4512        F: JsFunction4<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
4513            JsValue,
4514            JsValue,
4515            JsValue,
4516            JsValue,
4517        ) -> JsValue,
4518    >(
4519        this: &Function<F>,
4520        context: &JsValue,
4521        arg1: &Arg1,
4522        arg2: &Arg2,
4523        arg3: &Arg3,
4524        arg4: &Arg4,
4525    ) -> Function<<F as JsFunction4>::Bind4>;
4526
4527    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4528    /// with a given sequence of arguments preceding any provided when the new function is called.
4529    ///
4530    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4531    ///
4532    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4533    #[wasm_bindgen(method, js_name = bind)]
4534    pub fn bind5<
4535        Ret: JsGeneric,
4536        Arg1: JsGeneric,
4537        Arg2: JsGeneric,
4538        Arg3: JsGeneric,
4539        Arg4: JsGeneric,
4540        Arg5: JsGeneric,
4541        F: JsFunction5<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4542            JsValue,
4543            JsValue,
4544            JsValue,
4545            JsValue,
4546            JsValue,
4547        ) -> JsValue,
4548    >(
4549        this: &Function<F>,
4550        context: &JsValue,
4551        arg1: &Arg1,
4552        arg2: &Arg2,
4553        arg3: &Arg3,
4554        arg4: &Arg4,
4555        arg5: &Arg5,
4556    ) -> Function<<F as JsFunction5>::Bind5>;
4557
4558    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4559    /// with a given sequence of arguments preceding any provided when the new function is called.
4560    ///
4561    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4562    ///
4563    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4564    #[wasm_bindgen(method, js_name = bind)]
4565    pub fn bind6<
4566        Ret: JsGeneric,
4567        Arg1: JsGeneric,
4568        Arg2: JsGeneric,
4569        Arg3: JsGeneric,
4570        Arg4: JsGeneric,
4571        Arg5: JsGeneric,
4572        Arg6: JsGeneric,
4573        F: JsFunction6<
4574            Ret = Ret,
4575            Arg1 = Arg1,
4576            Arg2 = Arg2,
4577            Arg3 = Arg3,
4578            Arg4 = Arg4,
4579            Arg5 = Arg5,
4580            Arg6 = Arg6,
4581        > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4582    >(
4583        this: &Function<F>,
4584        context: &JsValue,
4585        arg1: &Arg1,
4586        arg2: &Arg2,
4587        arg3: &Arg3,
4588        arg4: &Arg4,
4589        arg5: &Arg5,
4590        arg6: &Arg6,
4591    ) -> Function<<F as JsFunction6>::Bind6>;
4592
4593    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4594    /// with a given sequence of arguments preceding any provided when the new function is called.
4595    ///
4596    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4597    ///
4598    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4599    #[wasm_bindgen(method, js_name = bind)]
4600    pub fn bind7<
4601        Ret: JsGeneric,
4602        Arg1: JsGeneric,
4603        Arg2: JsGeneric,
4604        Arg3: JsGeneric,
4605        Arg4: JsGeneric,
4606        Arg5: JsGeneric,
4607        Arg6: JsGeneric,
4608        Arg7: JsGeneric,
4609        F: JsFunction7<
4610            Ret = Ret,
4611            Arg1 = Arg1,
4612            Arg2 = Arg2,
4613            Arg3 = Arg3,
4614            Arg4 = Arg4,
4615            Arg5 = Arg5,
4616            Arg6 = Arg6,
4617            Arg7 = Arg7,
4618        > = fn(
4619            JsValue,
4620            JsValue,
4621            JsValue,
4622            JsValue,
4623            JsValue,
4624            JsValue,
4625            JsValue,
4626        ) -> JsValue,
4627    >(
4628        this: &Function<F>,
4629        context: &JsValue,
4630        arg1: &Arg1,
4631        arg2: &Arg2,
4632        arg3: &Arg3,
4633        arg4: &Arg4,
4634        arg5: &Arg5,
4635        arg6: &Arg6,
4636        arg7: &Arg7,
4637    ) -> Function<<F as JsFunction7>::Bind7>;
4638
4639    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4640    /// with a given sequence of arguments preceding any provided when the new function is called.
4641    ///
4642    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4643    ///
4644    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4645    #[wasm_bindgen(method, js_name = bind)]
4646    pub fn bind8<
4647        Ret: JsGeneric,
4648        Arg1: JsGeneric,
4649        Arg2: JsGeneric,
4650        Arg3: JsGeneric,
4651        Arg4: JsGeneric,
4652        Arg5: JsGeneric,
4653        Arg6: JsGeneric,
4654        Arg7: JsGeneric,
4655        Arg8: JsGeneric,
4656        F: JsFunction8<
4657            Ret = Ret,
4658            Arg1 = Arg1,
4659            Arg2 = Arg2,
4660            Arg3 = Arg3,
4661            Arg4 = Arg4,
4662            Arg5 = Arg5,
4663            Arg6 = Arg6,
4664            Arg7 = Arg7,
4665            Arg8 = Arg8,
4666        > = fn(
4667            JsValue,
4668            JsValue,
4669            JsValue,
4670            JsValue,
4671            JsValue,
4672            JsValue,
4673            JsValue,
4674            JsValue,
4675        ) -> JsValue,
4676    >(
4677        this: &Function<F>,
4678        context: &JsValue,
4679        arg1: &Arg1,
4680        arg2: &Arg2,
4681        arg3: &Arg3,
4682        arg4: &Arg4,
4683        arg5: &Arg5,
4684        arg6: &Arg6,
4685        arg7: &Arg7,
4686        arg8: &Arg8,
4687    ) -> Function<<F as JsFunction8>::Bind8>;
4688
4689    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4690    /// with a given sequence of arguments preceding any provided when the new function is called.
4691    ///
4692    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4693    ///
4694    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4695    #[deprecated]
4696    #[allow(deprecated)]
4697    #[wasm_bindgen(method, js_name = bind)]
4698    pub fn bind9<
4699        Ret: JsGeneric,
4700        Arg1: JsGeneric,
4701        Arg2: JsGeneric,
4702        Arg3: JsGeneric,
4703        Arg4: JsGeneric,
4704        Arg5: JsGeneric,
4705        Arg6: JsGeneric,
4706        Arg7: JsGeneric,
4707        Arg8: JsGeneric,
4708        F: JsFunction8<
4709            Ret = Ret,
4710            Arg1 = Arg1,
4711            Arg2 = Arg2,
4712            Arg3 = Arg3,
4713            Arg4 = Arg4,
4714            Arg5 = Arg5,
4715            Arg6 = Arg6,
4716            Arg7 = Arg7,
4717            Arg8 = Arg8,
4718        > = fn(
4719            JsValue,
4720            JsValue,
4721            JsValue,
4722            JsValue,
4723            JsValue,
4724            JsValue,
4725            JsValue,
4726            JsValue,
4727        ) -> JsValue,
4728    >(
4729        this: &Function<F>,
4730        context: &JsValue,
4731        arg1: &Arg1,
4732        arg2: &Arg2,
4733        arg3: &Arg3,
4734        arg4: &Arg4,
4735        arg5: &Arg5,
4736        arg6: &Arg6,
4737        arg7: &Arg7,
4738        arg8: &Arg8,
4739        arg9: &JsValue,
4740    ) -> Function<fn() -> Ret>;
4741
4742    /// The length property indicates the number of arguments expected by the function.
4743    ///
4744    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
4745    #[wasm_bindgen(method, getter)]
4746    pub fn length<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> u32;
4747
4748    /// A Function object's read-only name property indicates the function's
4749    /// name as specified when it was created or "anonymous" for functions
4750    /// created anonymously.
4751    ///
4752    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
4753    #[wasm_bindgen(method, getter)]
4754    pub fn name<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4755
4756    /// The `toString()` method returns a string representing the source code of the function.
4757    ///
4758    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
4759    #[cfg(not(js_sys_unstable_apis))]
4760    #[wasm_bindgen(method, js_name = toString)]
4761    pub fn to_string<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4762}
4763
4764// Basic UpcastFrom impls for Function<T>
4765impl<T: JsFunction> UpcastFrom<Function<T>> for JsValue {}
4766impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<JsValue> {}
4767impl<T: JsFunction, Target: UpcastFrom<Function<T>>> UpcastFrom<Function<T>> for Option<Target> {}
4768impl<T: JsFunction, Target: UpcastFrom<Function<T>>> UpcastFrom<Function<T>> for Nullable<Target> {}
4769impl<T: JsFunction> UpcastFrom<Function<T>> for JsNullable<JsValue> {}
4770impl<T: JsFunction> UpcastFrom<Function<T>> for Object {}
4771impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<Object> {}
4772impl<T: JsFunction> UpcastFrom<Function<T>> for JsNullable<Object> {}
4773
4774// Blanket trait for Function upcast
4775// Function<T> upcasts to Function<U> when the underlying fn type T upcasts to U.
4776// The fn signature UpcastFrom impls already encode correct variance (covariant return, contravariant args).
4777impl<T: JsFunction, U: JsFunction> UpcastFrom<Function<T>> for Function<U> where U: UpcastFrom<T> {}
4778
4779// len() method for Function<T> using JsFunction::ARITY
4780impl<T: JsFunction> Function<T> {
4781    /// Get the static arity of this function type.
4782    #[allow(clippy::len_without_is_empty)]
4783    pub fn len(&self) -> usize {
4784        T::ARITY
4785    }
4786
4787    /// Returns true if this is a zero-argument function.
4788    pub fn is_empty(&self) -> bool {
4789        T::ARITY == 0
4790    }
4791}
4792
4793/// The signature a `Function<T>` is typed with: a `fn(Args..) -> Ret` whose
4794/// slots name the JS types the function takes and returns.
4795///
4796/// A slot may be any Rust carrier of a JS type, a handle such as `JsString`
4797/// or a converted value such as `Nullable<JsString>` or `Option<Number>`, as
4798/// a `Promise<T>` or `Array<T>` type argument may. The `call*` and `bind*`
4799/// methods marshal through the erased `JsValue` representation and so bound
4800/// their slots to [`JsGeneric`] handles themselves.
4801pub trait JsFunction {
4802    type Ret;
4803    const ARITY: usize;
4804}
4805
4806pub trait JsFunction1: JsFunction {
4807    type Arg1;
4808    type Bind1: JsFunction;
4809}
4810pub trait JsFunction2: JsFunction1 {
4811    type Arg2;
4812    type Bind2: JsFunction;
4813}
4814pub trait JsFunction3: JsFunction2 {
4815    type Arg3;
4816    type Bind3: JsFunction;
4817}
4818pub trait JsFunction4: JsFunction3 {
4819    type Arg4;
4820    type Bind4: JsFunction;
4821}
4822pub trait JsFunction5: JsFunction4 {
4823    type Arg5;
4824    type Bind5: JsFunction;
4825}
4826pub trait JsFunction6: JsFunction5 {
4827    type Arg6;
4828    type Bind6: JsFunction;
4829}
4830pub trait JsFunction7: JsFunction6 {
4831    type Arg7;
4832    type Bind7: JsFunction;
4833}
4834pub trait JsFunction8: JsFunction7 {
4835    type Arg8;
4836    type Bind8: JsFunction;
4837}
4838
4839// Manual impl for fn() -> R
4840impl<Ret> JsFunction for fn() -> Ret {
4841    type Ret = Ret;
4842    const ARITY: usize = 0;
4843}
4844
4845macro_rules! impl_fn {
4846    () => {
4847        impl_fn!(@impl 1 [Arg1] [
4848            JsFunction1 Arg1 Bind1 {fn() -> Ret}
4849        ]);
4850        impl_fn!(@impl 2 [Arg1 Arg2] [
4851            JsFunction1 Arg1 Bind1 {fn(Arg2) -> Ret}
4852            JsFunction2 Arg2 Bind2 {fn() -> Ret}
4853        ]);
4854        impl_fn!(@impl 3 [Arg1 Arg2 Arg3] [
4855            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3) -> Ret}
4856            JsFunction2 Arg2 Bind2 {fn(Arg3) -> Ret}
4857            JsFunction3 Arg3 Bind3 {fn() -> Ret}
4858        ]);
4859        impl_fn!(@impl 4 [Arg1 Arg2 Arg3 Arg4] [
4860            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4) -> Ret}
4861            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4) -> Ret}
4862            JsFunction3 Arg3 Bind3 {fn(Arg4) -> Ret}
4863            JsFunction4 Arg4 Bind4 {fn() -> Ret}
4864        ]);
4865        impl_fn!(@impl 5 [Arg1 Arg2 Arg3 Arg4 Arg5] [
4866            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5) -> Ret}
4867            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5) -> Ret}
4868            JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5) -> Ret}
4869            JsFunction4 Arg4 Bind4 {fn(Arg5) -> Ret}
4870            JsFunction5 Arg5 Bind5 {fn() -> Ret}
4871        ]);
4872        impl_fn!(@impl 6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [
4873            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6) -> Ret}
4874            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6) -> Ret}
4875            JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6) -> Ret}
4876            JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6) -> Ret}
4877            JsFunction5 Arg5 Bind5 {fn(Arg6) -> Ret}
4878            JsFunction6 Arg6 Bind6 {fn() -> Ret}
4879        ]);
4880        impl_fn!(@impl 7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [
4881            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4882            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4883            JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7) -> Ret}
4884            JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7) -> Ret}
4885            JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7) -> Ret}
4886            JsFunction6 Arg6 Bind6 {fn(Arg7) -> Ret}
4887            JsFunction7 Arg7 Bind7 {fn() -> Ret}
4888        ]);
4889        impl_fn!(@impl 8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [
4890            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4891            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4892            JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4893            JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7, Arg8) -> Ret}
4894            JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7, Arg8) -> Ret}
4895            JsFunction6 Arg6 Bind6 {fn(Arg7, Arg8) -> Ret}
4896            JsFunction7 Arg7 Bind7 {fn(Arg8) -> Ret}
4897            JsFunction8 Arg8 Bind8 {fn() -> Ret}
4898        ]);
4899    };
4900
4901    (@impl $arity:literal [$($A:ident)+] [$($trait:ident $arg:ident $bind:ident {$bind_ty:ty})+]) => {
4902        impl<Ret $(, $A)+> JsFunction for fn($($A),+) -> Ret {
4903            type Ret = Ret;
4904            const ARITY: usize = $arity;
4905        }
4906
4907        impl_fn!(@traits [$($A)+] [$($trait $arg $bind {$bind_ty})+]);
4908    };
4909
4910    (@traits [$($A:ident)+] []) => {};
4911
4912    (@traits [$($A:ident)+] [$trait:ident $arg:ident $bind:ident {$bind_ty:ty} $($rest:tt)*]) => {
4913        impl<Ret $(, $A)+> $trait for fn($($A),+) -> Ret {
4914            type $arg = $arg;
4915            type $bind = $bind_ty;
4916        }
4917
4918        impl_fn!(@traits [$($A)+] [$($rest)*]);
4919    };
4920}
4921
4922impl_fn!();
4923
4924/// Trait for argument tuples that can call or bind a `Function<T>`.
4925pub trait JsArgs<T: JsFunction> {
4926    type BindOutput;
4927    fn apply_call(self, func: &Function<T>, context: &JsValue) -> Result<T::Ret, JsValue>;
4928    fn apply_bind(self, func: &Function<T>, context: &JsValue) -> Self::BindOutput;
4929}
4930
4931// Manual impl for 0-arg
4932impl<Ret: JsGeneric, F: JsFunction<Ret = Ret>> JsArgs<F> for () {
4933    type BindOutput = Function<F>;
4934
4935    #[inline]
4936    fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4937        func.call0(context)
4938    }
4939
4940    #[inline]
4941    fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4942        func.bind0(context)
4943    }
4944}
4945
4946macro_rules! impl_js_args {
4947    ($arity:literal $trait:ident $bind_output:ident [$($A:ident)+] [$($idx:tt)+] $call:ident $bind:ident) => {
4948        impl<Ret: JsGeneric, $($A: JsGeneric,)+ F: $trait<Ret = Ret, $($A = $A,)*>> JsArgs<F> for ($(&$A,)+)
4949        {
4950            type BindOutput = Function<<F as $trait>::$bind_output>;
4951
4952            #[inline]
4953            fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4954                func.$call(context, $(self.$idx),+)
4955            }
4956
4957            #[inline]
4958            fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4959                func.$bind(context, $(self.$idx),+)
4960            }
4961        }
4962    };
4963}
4964
4965impl_js_args!(1 JsFunction1 Bind1 [Arg1] [0] call1 bind1);
4966impl_js_args!(2 JsFunction2 Bind2 [Arg1 Arg2] [0 1] call2 bind2);
4967impl_js_args!(3 JsFunction3 Bind3 [Arg1 Arg2 Arg3] [0 1 2] call3 bind3);
4968impl_js_args!(4 JsFunction4 Bind4 [Arg1 Arg2 Arg3 Arg4] [0 1 2 3] call4 bind4);
4969impl_js_args!(5 JsFunction5 Bind5 [Arg1 Arg2 Arg3 Arg4 Arg5] [0 1 2 3 4] call5 bind5);
4970impl_js_args!(6 JsFunction6 Bind6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [0 1 2 3 4 5] call6 bind6);
4971impl_js_args!(7 JsFunction7 Bind7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [0 1 2 3 4 5 6] call7 bind7);
4972impl_js_args!(8 JsFunction8 Bind8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [0 1 2 3 4 5 6 7] call8 bind8);
4973
4974impl<T: JsFunction> Function<T> {
4975    /// The `call()` method calls a function with a given `this` value and
4976    /// arguments provided as a tuple.
4977    ///
4978    /// This method accepts a tuple of references matching the function's
4979    /// argument types.
4980    ///
4981    /// # Example
4982    ///
4983    /// ```ignore
4984    /// // 0-arg function
4985    /// let f: Function<fn() -> Number> = get_fn();
4986    /// let result = f.call(&JsValue::NULL, ())?;
4987    ///
4988    /// // 1-arg function (note trailing comma for 1-tuple)
4989    /// let f: Function<fn(JsString) -> Number> = get_fn();
4990    /// let result = f.call(&JsValue::NULL, (&name,))?;
4991    ///
4992    /// // 2-arg function
4993    /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4994    /// let result = f.call(&JsValue::NULL, (&name, &flag))?;
4995    /// ```
4996    ///
4997    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4998    #[inline]
4999    pub fn call<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Result<T::Ret, JsValue> {
5000        args.apply_call(self, context)
5001    }
5002
5003    /// The `bind()` method creates a new function that, when called, has its
5004    /// `this` keyword set to the provided value, with a given sequence of
5005    /// arguments preceding any provided when the new function is called.
5006    ///
5007    /// This method accepts a tuple of references to bind.
5008    ///
5009    /// # Example
5010    ///
5011    /// ```ignore
5012    /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
5013    ///
5014    /// // Bind no args - same signature
5015    /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
5016    ///
5017    /// // Bind one arg (use 1-tuple of references)
5018    /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
5019    ///
5020    /// // Bind two args - becomes 0-arg function
5021    /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
5022    /// ```
5023    ///
5024    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
5025    #[inline]
5026    pub fn bindn<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
5027        args.apply_bind(self, context)
5028    }
5029
5030    /// The `bind()` method creates a new function that, when called, has its
5031    /// `this` keyword set to the provided value, with a given sequence of
5032    /// arguments preceding any provided when the new function is called.
5033    ///
5034    /// This method accepts a tuple of references to bind.
5035    ///
5036    /// # Example
5037    ///
5038    /// ```ignore
5039    /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
5040    ///
5041    /// // Bind no args - same signature
5042    /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
5043    ///
5044    /// // Bind one arg (use 1-tuple of references)
5045    /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
5046    ///
5047    /// // Bind two args - becomes 0-arg function
5048    /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
5049    /// ```
5050    ///
5051    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
5052    #[cfg(js_sys_unstable_apis)]
5053    #[inline]
5054    pub fn bind<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
5055        args.apply_bind(self, context)
5056    }
5057}
5058
5059pub trait FunctionIntoClosure: JsFunction {
5060    type ClosureTypeMut: WasmClosure + ?Sized;
5061}
5062
5063macro_rules! impl_function_into_closure {
5064    ( $(($($var:ident)*))* ) => {$(
5065        impl<$($var: FromWasmAbi,)* R: IntoWasmAbi> FunctionIntoClosure for fn($($var),*) -> R {
5066            type ClosureTypeMut = dyn FnMut($($var),*) -> R;
5067        }
5068    )*};
5069}
5070
5071impl_function_into_closure! {
5072    ()
5073    (A)
5074    (A B)
5075    (A B C)
5076    (A B C D)
5077    (A B C D E)
5078    (A B C D E F)
5079    (A B C D E F G)
5080    (A B C D E F G H)
5081}
5082
5083impl<F: JsFunction> Function<F> {
5084    /// Convert a borrowed `ScopedClosure` into a typed JavaScript Function reference.
5085    ///
5086    /// The conversion is a direct type-safe conversion and upcast of a
5087    /// closure into its corresponding typed JavaScript Function,
5088    /// based on covariance and contravariance [`Upcast`] trait hierarchy.
5089    ///
5090    /// For transferring ownership to JS, use [`Function::from_closure`].
5091    #[inline]
5092    pub fn closure_ref<'a, C>(closure: &'a ScopedClosure<'_, C>) -> &'a Self
5093    where
5094        F: FunctionIntoClosure,
5095        C: WasmClosure + ?Sized,
5096        <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
5097    {
5098        closure.as_js_value().unchecked_ref()
5099    }
5100
5101    /// Convert a Rust closure into a typed JavaScript Function.
5102    ///
5103    /// This function releases ownership of the closure to JS, and provides
5104    /// an owned function handle for the same closure.
5105    ///
5106    /// The conversion is a direct type-safe conversion and upcast of a
5107    /// closure into its corresponding typed JavaScript Function,
5108    /// based on covariance and contravariance [`Upcast`] trait hierarchy.
5109    ///
5110    /// This method is only supported for static closures which do not have
5111    /// borrowed lifetime data, and thus can be released into JS.
5112    ///
5113    /// For borrowed closures, which cannot cede ownership to JS,
5114    /// instead use [`Function::closure_ref`].
5115    #[inline]
5116    pub fn from_closure<C>(closure: ScopedClosure<'static, C>) -> Self
5117    where
5118        F: FunctionIntoClosure,
5119        C: WasmClosure + ?Sized,
5120        <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
5121    {
5122        closure.into_js_value().unchecked_into()
5123    }
5124}
5125
5126#[cfg(not(js_sys_unstable_apis))]
5127impl Function {
5128    /// Returns the `Function` value of this JS value if it's an instance of a
5129    /// function.
5130    ///
5131    /// If this JS value is not an instance of a function then this returns
5132    /// `None`.
5133    #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
5134    pub fn try_from(val: &JsValue) -> Option<&Function> {
5135        val.dyn_ref()
5136    }
5137}
5138
5139#[cfg(feature = "unsafe-eval")]
5140impl Default for Function {
5141    fn default() -> Self {
5142        Self::new_no_args("")
5143    }
5144}
5145
5146// FinalizationRegistry
5147#[wasm_bindgen]
5148extern "C" {
5149    /// The `FinalizationRegistry` object lets you request a callback when an
5150    /// object is garbage-collected.
5151    ///
5152    /// `FinalizationRegistry` provides a way to request that a cleanup
5153    /// callback get called at some point when an object registered with the
5154    /// registry has been reclaimed (garbage-collected). Cleanup callbacks
5155    /// are sometimes called *finalizers*.
5156    ///
5157    /// Avoid where possible: cleanup callbacks should not be relied upon for
5158    /// anything essential. They are best used to reduce memory usage over the
5159    /// course of a program for objects that benefit from cleanup. Whether,
5160    /// when, and in what order callbacks fire is implementation-defined.
5161    ///
5162    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry)
5163    #[wasm_bindgen(extends = Object, typescript_type = "FinalizationRegistry<any>")]
5164    #[derive(Clone, Debug, PartialEq, Eq)]
5165    pub type FinalizationRegistry;
5166
5167    /// Creates a new `FinalizationRegistry` with the given cleanup callback.
5168    ///
5169    /// The cleanup callback is invoked, at some point after a registered
5170    /// target is garbage-collected, with the `held_value` that was passed to
5171    /// [`FinalizationRegistry::register`]. Because callbacks may be deferred
5172    /// or skipped entirely, the callback should normally outlive the
5173    /// `FinalizationRegistry` (for example by being created via
5174    /// [`Function::from_closure`]).
5175    ///
5176    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/FinalizationRegistry)
5177    #[wasm_bindgen(constructor)]
5178    pub fn new(cleanup_callback: &Function<fn(JsValue) -> Undefined>) -> FinalizationRegistry;
5179
5180    /// Registers `target` with this `FinalizationRegistry`. When `target` is
5181    /// reclaimed by the garbage collector the cleanup callback may be called
5182    /// with `held_value`.
5183    ///
5184    /// `target` must be an object (or a non-registered symbol).
5185    ///
5186    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/register)
5187    #[wasm_bindgen(method)]
5188    pub fn register(this: &FinalizationRegistry, target: &JsValue, held_value: &JsValue);
5189
5190    /// Registers `target` with this `FinalizationRegistry`, with an
5191    /// `unregister_token` that can later be passed to
5192    /// [`FinalizationRegistry::unregister`] to remove the registration.
5193    ///
5194    /// `target` and `unregister_token` must be objects (or non-registered
5195    /// symbols), and the same value may be passed for both.
5196    ///
5197    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/register)
5198    #[wasm_bindgen(method, js_name = register)]
5199    pub fn register_with_token(
5200        this: &FinalizationRegistry,
5201        target: &JsValue,
5202        held_value: &JsValue,
5203        unregister_token: &JsValue,
5204    );
5205
5206    /// Unregisters all entries registered with this `FinalizationRegistry`
5207    /// using `unregister_token`. Returns `true` if any cells were removed.
5208    ///
5209    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/unregister)
5210    #[wasm_bindgen(method)]
5211    pub fn unregister(this: &FinalizationRegistry, unregister_token: &JsValue) -> bool;
5212}
5213
5214// Generator
5215#[wasm_bindgen]
5216extern "C" {
5217    #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
5218    #[derive(Clone, Debug, PartialEq, Eq)]
5219    pub type Generator<T = JsValue>;
5220
5221    /// The `next()` method returns an object with two properties done and value.
5222    /// You can also provide a parameter to the next method to send a value to the generator.
5223    ///
5224    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5225    #[cfg(not(js_sys_unstable_apis))]
5226    #[wasm_bindgen(method, catch)]
5227    pub fn next<T>(this: &Generator<T>, value: &T) -> Result<JsValue, JsValue>;
5228
5229    /// The `next()` method returns an object with two properties done and value.
5230    /// You can also provide a parameter to the next method to send a value to the generator.
5231    ///
5232    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5233    #[cfg(js_sys_unstable_apis)]
5234    #[wasm_bindgen(method, catch, js_name = next)]
5235    pub fn next<T: FromWasmAbi>(this: &Generator<T>, value: &T)
5236        -> Result<IteratorNext<T>, JsValue>;
5237
5238    // Next major: deprecate
5239    /// The `next()` method returns an object with two properties done and value.
5240    /// You can also provide a parameter to the next method to send a value to the generator.
5241    ///
5242    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5243    #[wasm_bindgen(method, catch)]
5244    pub fn next_iterator<T: FromWasmAbi>(
5245        this: &Generator<T>,
5246        value: &T,
5247    ) -> Result<IteratorNext<T>, JsValue>;
5248
5249    /// The `return()` method returns the given value and finishes the generator.
5250    ///
5251    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5252    #[cfg(not(js_sys_unstable_apis))]
5253    #[wasm_bindgen(method, js_name = "return")]
5254    pub fn return_<T>(this: &Generator<T>, value: &T) -> JsValue;
5255
5256    /// The `return()` method returns the given value and finishes the generator.
5257    ///
5258    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5259    #[cfg(js_sys_unstable_apis)]
5260    #[wasm_bindgen(method, catch, js_name = "return")]
5261    pub fn return_<T: FromWasmAbi>(
5262        this: &Generator<T>,
5263        value: &T,
5264    ) -> Result<IteratorNext<T>, JsValue>;
5265
5266    // Next major: deprecate
5267    /// The `return()` method returns the given value and finishes the generator.
5268    ///
5269    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5270    #[wasm_bindgen(method, catch, js_name = "return")]
5271    pub fn try_return<T: FromWasmAbi>(
5272        this: &Generator<T>,
5273        value: &T,
5274    ) -> Result<IteratorNext<T>, JsValue>;
5275
5276    /// The `throw()` method resumes the execution of a generator by throwing an error into it
5277    /// and returns an object with two properties done and value.
5278    ///
5279    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5280    #[cfg(not(js_sys_unstable_apis))]
5281    #[wasm_bindgen(method, catch)]
5282    pub fn throw<T>(this: &Generator<T>, error: &Error) -> Result<JsValue, JsValue>;
5283
5284    /// The `throw()` method resumes the execution of a generator by throwing an error into it
5285    /// and returns an object with two properties done and value.
5286    ///
5287    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5288    #[cfg(js_sys_unstable_apis)]
5289    #[wasm_bindgen(method, catch, js_name = throw)]
5290    pub fn throw<T: FromWasmAbi>(
5291        this: &Generator<T>,
5292        error: &JsValue,
5293    ) -> Result<IteratorNext<T>, JsValue>;
5294
5295    // Next major: deprecate
5296    /// The `throw()` method resumes the execution of a generator by throwing an error into it
5297    /// and returns an object with two properties done and value.
5298    ///
5299    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5300    #[wasm_bindgen(method, catch, js_name = throw)]
5301    pub fn throw_value<T: FromWasmAbi>(
5302        this: &Generator<T>,
5303        error: &JsValue,
5304    ) -> Result<IteratorNext<T>, JsValue>;
5305}
5306
5307impl<T: FromWasmAbi> Iterable for Generator<T> {
5308    type Item = T;
5309}
5310
5311// AsyncGenerator
5312#[wasm_bindgen]
5313extern "C" {
5314    #[wasm_bindgen(extends = Object, typescript_type = "AsyncGenerator<any, any, any>")]
5315    #[derive(Clone, Debug, PartialEq, Eq)]
5316    pub type AsyncGenerator<T = JsValue>;
5317
5318    /// The `next()` method returns an object with two properties done and value.
5319    /// You can also provide a parameter to the next method to send a value to the generator.
5320    ///
5321    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/next)
5322    #[wasm_bindgen(method, catch)]
5323    pub fn next<T>(
5324        this: &AsyncGenerator<T>,
5325        value: &T,
5326    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5327
5328    /// The `return()` method returns the given value and finishes the generator.
5329    ///
5330    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/return)
5331    #[wasm_bindgen(method, js_name = "return", catch)]
5332    pub fn return_<T>(
5333        this: &AsyncGenerator<T>,
5334        value: &T,
5335    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5336
5337    /// The `throw()` method resumes the execution of a generator by throwing an error into it
5338    /// and returns an object with two properties done and value.
5339    ///
5340    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/throw)
5341    #[wasm_bindgen(method, catch)]
5342    pub fn throw<T>(
5343        this: &AsyncGenerator<T>,
5344        error: &JsValue,
5345    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5346}
5347
5348impl<T: FromWasmAbi> AsyncIterable for AsyncGenerator<T> {
5349    type Item = T;
5350}
5351
5352// Map
5353#[wasm_bindgen]
5354extern "C" {
5355    #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
5356    #[derive(Clone, Debug, PartialEq, Eq)]
5357    pub type Map<K = JsValue, V = JsValue>;
5358
5359    /// The Map object holds key-value pairs. Any value (both objects and
5360    /// primitive values) maybe used as either a key or a value.
5361    ///
5362    /// **Note:** Consider using [`Map::new_typed`] for typing support.
5363    ///
5364    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5365    #[cfg(not(js_sys_unstable_apis))]
5366    #[wasm_bindgen(constructor)]
5367    pub fn new() -> Map;
5368
5369    /// The Map object holds key-value pairs. Any value (both objects and
5370    /// primitive values) maybe used as either a key or a value.
5371    ///
5372    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5373    #[cfg(js_sys_unstable_apis)]
5374    #[wasm_bindgen(constructor)]
5375    pub fn new<K, V>() -> Map<K, V>;
5376
5377    // Next major: deprecate
5378    /// The Map object holds key-value pairs. Any value (both objects and
5379    /// primitive values) maybe used as either a key or a value.
5380    ///
5381    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5382    #[wasm_bindgen(constructor)]
5383    pub fn new_typed<K, V>() -> Map<K, V>;
5384
5385    /// The Map object holds key-value pairs. Any value (both objects and
5386    /// primitive values) maybe used as either a key or a value.
5387    ///
5388    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5389    #[wasm_bindgen(constructor, js_name = new)]
5390    pub fn new_from_entries<K, V, I: Iterable<Item = ArrayTuple<(K, V)>>>(entries: &I)
5391        -> Map<K, V>;
5392
5393    /// The `clear()` method removes all elements from a Map object.
5394    ///
5395    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
5396    #[wasm_bindgen(method)]
5397    pub fn clear<K, V>(this: &Map<K, V>);
5398
5399    /// The `delete()` method removes the specified element from a Map object.
5400    ///
5401    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
5402    #[wasm_bindgen(method)]
5403    pub fn delete<K, V>(this: &Map<K, V>, key: &K) -> bool;
5404
5405    /// The `forEach()` method executes a provided function once per each
5406    /// key/value pair in the Map object, in insertion order.
5407    /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
5408    /// # Examples
5409    /// ```
5410    /// let js_map = Map::new();
5411    /// js_map.for_each(&mut |value, key| {
5412    ///     // Do something here...
5413    /// })
5414    /// ```
5415    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
5416    #[wasm_bindgen(method, js_name = forEach)]
5417    pub fn for_each<K, V>(this: &Map<K, V>, callback: &mut dyn FnMut(V, K));
5418
5419    /// The `forEach()` method executes a provided function once per each
5420    /// key/value pair in the Map object, in insertion order. _(Fallible variation)_
5421    /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
5422    /// # Examples
5423    /// ```
5424    /// let js_map = Map::new();
5425    /// js_map.for_each(&mut |value, key| {
5426    ///     // Do something here...
5427    /// })
5428    /// ```
5429    ///
5430    /// **Note:** Consider using [`Map::try_for_each`] if the callback might throw an error.
5431    ///
5432    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
5433    #[wasm_bindgen(method, js_name = forEach, catch)]
5434    pub fn try_for_each<K, V>(
5435        this: &Map<K, V>,
5436        callback: &mut dyn FnMut(V, K) -> Result<(), JsError>,
5437    ) -> Result<(), JsValue>;
5438
5439    /// The `get()` method returns a specified element from a Map object.
5440    /// Returns `undefined` if the key is not found.
5441    ///
5442    /// **Note:** Consider using [`Map::get_checked`] to get an `Option<V>` instead.
5443    ///
5444    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5445    #[cfg(not(js_sys_unstable_apis))]
5446    #[wasm_bindgen(method)]
5447    pub fn get<K, V>(this: &Map<K, V>, key: &K) -> V;
5448
5449    /// The `get()` method returns a specified element from a Map object.
5450    /// Returns `None` if the key is not found.
5451    ///
5452    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5453    #[cfg(js_sys_unstable_apis)]
5454    #[wasm_bindgen(method)]
5455    pub fn get<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
5456
5457    /// The `get()` method returns a specified element from a Map object.
5458    /// Returns `None` if the key is not found.
5459    ///
5460    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5461    #[wasm_bindgen(method, js_name = get)]
5462    pub fn get_checked<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
5463
5464    /// The `has()` method returns a boolean indicating whether an element with
5465    /// the specified key exists or not.
5466    ///
5467    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
5468    #[wasm_bindgen(method)]
5469    pub fn has<K, V>(this: &Map<K, V>, key: &K) -> bool;
5470
5471    /// The `set()` method adds or updates an element with a specified key
5472    /// and value to a Map object.
5473    ///
5474    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
5475    #[wasm_bindgen(method)]
5476    pub fn set<K, V>(this: &Map<K, V>, key: &K, value: &V) -> Map<K, V>;
5477
5478    /// The value of size is an integer representing how many entries
5479    /// the Map object has. A set accessor function for size is undefined;
5480    /// you can not change this property.
5481    ///
5482    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
5483    #[wasm_bindgen(method, getter)]
5484    pub fn size<K, V>(this: &Map<K, V>) -> u32;
5485
5486    /// The `getOrInsert()` method returns the value for `key`, first
5487    /// inserting `default_value` under it if the key is absent.
5488    ///
5489    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/getOrInsert)
5490    #[wasm_bindgen(method, js_name = getOrInsert)]
5491    pub fn get_or_insert<K, V>(this: &Map<K, V>, key: &K, default_value: &V) -> V;
5492
5493    /// The `getOrInsertComputed()` method returns the value for `key`,
5494    /// first inserting the result of `callback(key)` under it if the key
5495    /// is absent.
5496    ///
5497    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/getOrInsertComputed)
5498    #[wasm_bindgen(method, js_name = getOrInsertComputed)]
5499    pub fn get_or_insert_computed<K, V>(
5500        this: &Map<K, V>,
5501        key: &K,
5502        callback: &mut dyn FnMut(K) -> V,
5503    ) -> V;
5504
5505    /// The `Map.groupBy()` static method groups the values of an iterable
5506    /// into a `Map` keyed by the result of `callback`, which may be any
5507    /// value, compared with SameValueZero.
5508    ///
5509    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/groupBy)
5510    #[wasm_bindgen(static_method_of = Map, catch, js_name = groupBy)]
5511    pub fn group_by<T, K, I: Iterable<Item = T>>(
5512        items: &I,
5513        callback: &mut dyn FnMut(T, u32) -> K,
5514    ) -> Result<Map<K, Array<T>>, JsValue>;
5515}
5516
5517impl Default for Map<JsValue, JsValue> {
5518    fn default() -> Self {
5519        Self::new()
5520    }
5521}
5522
5523// Map Iterator
5524#[wasm_bindgen]
5525extern "C" {
5526    /// The `entries()` method returns a new Iterator object that contains
5527    /// the [key, value] pairs for each element in the Map object in
5528    /// insertion order.
5529    ///
5530    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5531    #[cfg(not(js_sys_unstable_apis))]
5532    #[wasm_bindgen(method)]
5533    pub fn entries<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator;
5534
5535    /// The `entries()` method returns a new Iterator object that contains
5536    /// the [key, value] pairs for each element in the Map object in
5537    /// insertion order.
5538    ///
5539    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5540    #[cfg(js_sys_unstable_apis)]
5541    #[wasm_bindgen(method, js_name = entries)]
5542    pub fn entries<K, V>(this: &Map<K, V>) -> Iterator<ArrayTuple<(K, V)>>;
5543
5544    // Next major: deprecate
5545    /// The `entries()` method returns a new Iterator object that contains
5546    /// the [key, value] pairs for each element in the Map object in
5547    /// insertion order.
5548    ///
5549    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5550    #[wasm_bindgen(method, js_name = entries)]
5551    pub fn entries_typed<K, V>(this: &Map<K, V>) -> Iterator<ArrayTuple<(K, V)>>;
5552
5553    /// The `keys()` method returns a new Iterator object that contains the
5554    /// keys for each element in the Map object in insertion order.
5555    ///
5556    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
5557    #[wasm_bindgen(method)]
5558    pub fn keys<K: FromWasmAbi, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<K>;
5559
5560    /// The `values()` method returns a new Iterator object that contains the
5561    /// values for each element in the Map object in insertion order.
5562    ///
5563    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values)
5564    #[wasm_bindgen(method)]
5565    pub fn values<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<V>;
5566}
5567
5568impl<K, V> Iterable for Map<K, V> {
5569    type Item = ArrayTuple<(K, V)>;
5570}
5571
5572// Iterator
5573#[wasm_bindgen]
5574extern "C" {
5575    /// Any object that conforms to the JS iterator protocol. For example,
5576    /// something returned by `myArray[Symbol.iterator]()`.
5577    ///
5578    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5579    #[derive(Clone, Debug)]
5580    #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
5581    pub type Iterator<T = JsValue>;
5582
5583    /// The `next()` method always has to return an object with appropriate
5584    /// properties including done and value. If a non-object value gets returned
5585    /// (such as false or undefined), a TypeError ("iterator.next() returned a
5586    /// non-object value") will be thrown.
5587    #[wasm_bindgen(catch, method)]
5588    pub fn next<T: FromWasmAbi>(this: &Iterator<T>) -> Result<IteratorNext<T>, JsValue>;
5589
5590    /// The `Iterator.from()` static method wraps any iterable or
5591    /// iterator-like object in an `Iterator` inheriting from
5592    /// `Iterator.prototype`. Named `from_iterable` as `from` is taken by
5593    /// `From<JsValue>`.
5594    ///
5595    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/from)
5596    #[wasm_bindgen(static_method_of = Iterator, js_name = from)]
5597    pub fn from_iterable<I: Iterable>(obj: &I) -> Iterator<I::Item>;
5598
5599    /// The `Iterator.concat()` static method returns an iterator yielding
5600    /// the values of each given iterable in turn.
5601    ///
5602    /// # Errors
5603    /// Throws a `TypeError` for an `Iterator<T>` that is a bare `{ next }`
5604    /// object, as those have no `Symbol.iterator`.
5605    ///
5606    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/concat)
5607    #[wasm_bindgen(static_method_of = Iterator, catch, variadic)]
5608    pub fn concat<I: Iterable>(iterables: &[I]) -> Result<Iterator<I::Item>, JsValue>;
5609
5610    /// The `map()` method returns a new iterator helper that yields each
5611    /// value of this iterator transformed by `mapper`.
5612    ///
5613    /// The mapper runs lazily, as the returned iterator is consumed, so it
5614    /// is taken as a [`ScopedClosure`] which must outlive that consumption.
5615    ///
5616    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/map)
5617    #[wasm_bindgen(method, final)]
5618    pub fn map<'a, T, U>(
5619        this: &Iterator<T>,
5620        mapper: &ScopedClosure<'a, dyn FnMut(T, u32) -> U>,
5621    ) -> Iterator<U>;
5622
5623    /// The `filter()` method returns a new iterator helper that yields only
5624    /// the values of this iterator for which `predicate` returns `true`.
5625    ///
5626    /// The predicate runs lazily, as the returned iterator is consumed, so
5627    /// it is taken as a [`ScopedClosure`] which must outlive that
5628    /// consumption.
5629    ///
5630    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/filter)
5631    #[wasm_bindgen(method, final)]
5632    pub fn filter<'a, T>(
5633        this: &Iterator<T>,
5634        predicate: &ScopedClosure<'a, dyn FnMut(T, u32) -> bool>,
5635    ) -> Iterator<T>;
5636
5637    /// The `take()` method returns a new iterator helper that yields at
5638    /// most `limit` values of this iterator.
5639    ///
5640    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/take)
5641    #[wasm_bindgen(method, final)]
5642    pub fn take<T>(this: &Iterator<T>, limit: u32) -> Iterator<T>;
5643
5644    /// The `drop()` method returns a new iterator helper that skips the
5645    /// first `limit` values of this iterator and yields the rest.
5646    ///
5647    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/drop)
5648    #[wasm_bindgen(method, final)]
5649    pub fn drop<T>(this: &Iterator<T>, limit: u32) -> Iterator<T>;
5650
5651    /// The `flatMap()` method returns a new iterator helper that yields the
5652    /// values of each iterable or iterator returned by `mapper`.
5653    ///
5654    /// The mapper runs lazily, as the returned iterator is consumed, so it
5655    /// is taken as a [`ScopedClosure`] which must outlive that consumption.
5656    ///
5657    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/flatMap)
5658    #[wasm_bindgen(method, final, js_name = flatMap)]
5659    pub fn flat_map<'a, T, I: Iterable>(
5660        this: &Iterator<T>,
5661        mapper: &ScopedClosure<'a, dyn FnMut(T, u32) -> I>,
5662    ) -> Iterator<I::Item>;
5663
5664    /// The `reduce()` method consumes this iterator, folding every value
5665    /// into an accumulator starting from `initial_value`.
5666    ///
5667    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/reduce)
5668    #[wasm_bindgen(method, final, catch)]
5669    pub fn reduce<T, A>(
5670        this: &Iterator<T>,
5671        reducer: &mut dyn FnMut(A, T, u32) -> A,
5672        initial_value: &A,
5673    ) -> Result<A, JsValue>;
5674
5675    /// The `toArray()` method consumes this iterator, collecting its values
5676    /// into an `Array`.
5677    ///
5678    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/toArray)
5679    #[wasm_bindgen(method, final, catch, js_name = toArray)]
5680    pub fn to_array<T>(this: &Iterator<T>) -> Result<Array<T>, JsValue>;
5681
5682    /// The `forEach()` method consumes this iterator, calling `callback`
5683    /// with each value and its index.
5684    ///
5685    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/forEach)
5686    #[wasm_bindgen(method, final, catch, js_name = forEach)]
5687    pub fn for_each<T>(this: &Iterator<T>, callback: &mut dyn FnMut(T, u32))
5688        -> Result<(), JsValue>;
5689
5690    /// The `some()` method consumes this iterator until `predicate` returns
5691    /// `true` for a value, returning whether it did.
5692    ///
5693    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/some)
5694    #[wasm_bindgen(method, final, catch)]
5695    pub fn some<T>(
5696        this: &Iterator<T>,
5697        predicate: &mut dyn FnMut(T, u32) -> bool,
5698    ) -> Result<bool, JsValue>;
5699
5700    /// The `every()` method consumes this iterator until `predicate` returns
5701    /// `false` for a value, returning whether it never did.
5702    ///
5703    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/every)
5704    #[wasm_bindgen(method, final, catch)]
5705    pub fn every<T>(
5706        this: &Iterator<T>,
5707        predicate: &mut dyn FnMut(T, u32) -> bool,
5708    ) -> Result<bool, JsValue>;
5709
5710    /// The `find()` method consumes this iterator until `predicate` returns
5711    /// `true` for a value, returning that value if any.
5712    ///
5713    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/find)
5714    #[wasm_bindgen(method, final, catch)]
5715    pub fn find<T>(
5716        this: &Iterator<T>,
5717        predicate: &mut dyn FnMut(T, u32) -> bool,
5718    ) -> Result<Option<T>, JsValue>;
5719}
5720
5721impl<T> UpcastFrom<Iterator<T>> for Object {}
5722
5723impl Iterator {
5724    fn looks_like_iterator(it: &JsValue) -> bool {
5725        #[wasm_bindgen]
5726        extern "C" {
5727            #[derive(Clone, Debug)]
5728            type MaybeIterator;
5729
5730            #[wasm_bindgen(method, getter)]
5731            fn next(this: &MaybeIterator) -> JsValue;
5732        }
5733
5734        if !it.is_object() {
5735            return false;
5736        }
5737
5738        let it = it.unchecked_ref::<MaybeIterator>();
5739
5740        it.next().is_function()
5741    }
5742}
5743
5744// iterators in JS are themselves iterable
5745impl<T> Iterable for Iterator<T> {
5746    type Item = T;
5747}
5748
5749// Async Iterator
5750#[wasm_bindgen]
5751extern "C" {
5752    /// Any object that conforms to the JS async iterator protocol. For example,
5753    /// something returned by `myObject[Symbol.asyncIterator]()`.
5754    ///
5755    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
5756    #[derive(Clone, Debug)]
5757    #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>")]
5758    pub type AsyncIterator<T = JsValue>;
5759
5760    /// The `next()` method always has to return a Promise which resolves to an object
5761    /// with appropriate properties including done and value. If a non-object value
5762    /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5763    /// returned a non-object value") will be thrown.
5764    #[cfg(not(js_sys_unstable_apis))]
5765    #[wasm_bindgen(catch, method)]
5766    pub fn next<T>(this: &AsyncIterator<T>) -> Result<Promise, JsValue>;
5767
5768    /// The `next()` method always has to return a Promise which resolves to an object
5769    /// with appropriate properties including done and value. If a non-object value
5770    /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5771    /// returned a non-object value") will be thrown.
5772    #[cfg(js_sys_unstable_apis)]
5773    #[wasm_bindgen(catch, method, js_name = next)]
5774    pub fn next<T: FromWasmAbi>(
5775        this: &AsyncIterator<T>,
5776    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5777
5778    // Next major: deprecate
5779    /// The `next()` method always has to return a Promise which resolves to an object
5780    /// with appropriate properties including done and value. If a non-object value
5781    /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5782    /// returned a non-object value") will be thrown.
5783    #[wasm_bindgen(catch, method, js_name = next)]
5784    pub fn next_iterator<T: FromWasmAbi>(
5785        this: &AsyncIterator<T>,
5786    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5787}
5788
5789impl<T> UpcastFrom<AsyncIterator<T>> for Object {}
5790
5791// iterators in JS are themselves iterable
5792impl<T> AsyncIterable for AsyncIterator<T> {
5793    type Item = T;
5794}
5795
5796/// An iterator over the JS `Symbol.iterator` iteration protocol.
5797///
5798/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
5799pub struct Iter<'a, T = JsValue> {
5800    js: &'a Iterator<T>,
5801    state: IterState,
5802}
5803
5804/// An iterator over the JS `Symbol.iterator` iteration protocol.
5805///
5806/// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
5807pub struct IntoIter<T = JsValue> {
5808    js: Iterator<T>,
5809    state: IterState,
5810}
5811
5812struct IterState {
5813    done: bool,
5814}
5815
5816impl<'a, T: FromWasmAbi + JsGeneric> IntoIterator for &'a Iterator<T> {
5817    type Item = Result<T, JsValue>;
5818    type IntoIter = Iter<'a, T>;
5819
5820    fn into_iter(self) -> Iter<'a, T> {
5821        Iter {
5822            js: self,
5823            state: IterState::new(),
5824        }
5825    }
5826}
5827
5828impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for Iter<'_, T> {
5829    type Item = Result<T, JsValue>;
5830
5831    fn next(&mut self) -> Option<Self::Item> {
5832        self.state.next(self.js)
5833    }
5834}
5835
5836impl<T: FromWasmAbi + JsGeneric> IntoIterator for Iterator<T> {
5837    type Item = Result<T, JsValue>;
5838    type IntoIter = IntoIter<T>;
5839
5840    fn into_iter(self) -> IntoIter<T> {
5841        IntoIter {
5842            js: self,
5843            state: IterState::new(),
5844        }
5845    }
5846}
5847
5848impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for IntoIter<T> {
5849    type Item = Result<T, JsValue>;
5850
5851    fn next(&mut self) -> Option<Self::Item> {
5852        self.state.next(&self.js)
5853    }
5854}
5855
5856impl IterState {
5857    fn new() -> IterState {
5858        IterState { done: false }
5859    }
5860
5861    fn next<T: FromWasmAbi + JsGeneric>(&mut self, js: &Iterator<T>) -> Option<Result<T, JsValue>> {
5862        if self.done {
5863            return None;
5864        }
5865        let next = match js.next() {
5866            Ok(val) => val,
5867            Err(e) => {
5868                self.done = true;
5869                return Some(Err(e));
5870            }
5871        };
5872        if next.done() {
5873            self.done = true;
5874            None
5875        } else {
5876            Some(Ok(next.value()))
5877        }
5878    }
5879}
5880
5881/// Create an iterator over `val` using the JS iteration protocol and
5882/// `Symbol.iterator`.
5883// #[cfg(not(js_sys_unstable_apis))]
5884pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter<JsValue>>, JsValue> {
5885    let iter_sym = Symbol::iterator();
5886
5887    let iter_fn = Reflect::get_symbol::<Object>(val.unchecked_ref(), iter_sym.as_ref())?;
5888    let iter_fn: Function = match iter_fn.dyn_into() {
5889        Ok(iter_fn) => iter_fn,
5890        Err(_) => return Ok(None),
5891    };
5892
5893    let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
5894        Ok(it) => it,
5895        Err(_) => return Ok(None),
5896    };
5897
5898    Ok(Some(it.into_iter()))
5899}
5900
5901/// Trait for JavaScript types that implement the iterable protocol via `Symbol.iterator`.
5902///
5903/// Types implementing this trait can be iterated over using JavaScript's iteration
5904/// protocol. The `Item` associated type specifies the type of values yielded.
5905///
5906/// ## Built-in Iterables
5907///
5908/// Many `js-sys` collection types implement `Iterable` out of the box:
5909///
5910/// ```ignore
5911/// use js_sys::{Array, Map, Set};
5912///
5913/// // Array<T> yields T
5914/// let arr: Array<Number> = get_numbers();
5915/// for value in arr.iter() {
5916///     let num: Number = value?;
5917/// }
5918///
5919/// // Map<K, V> yields Array (key-value pairs)
5920/// let map: Map<JsString, Number> = get_map();
5921/// for entry in map.iter() {
5922///     let pair: Array = entry?;
5923/// }
5924///
5925/// // Set<T> yields T
5926/// let set: Set<JsString> = get_set();
5927/// for value in set.iter() {
5928///     let s: JsString = value?;
5929/// }
5930/// ```
5931///
5932/// ## Typing Foreign Iterators
5933///
5934/// If you have a JavaScript value that implements the iterator protocol (has a `next()`
5935/// method) but isn't a built-in type, you can use [`JsCast`] to cast it to [`Iterator<T>`]:
5936///
5937/// ```ignore
5938/// use js_sys::Iterator;
5939/// use wasm_bindgen::JsCast;
5940///
5941/// // For a value you know implements the iterator protocol
5942/// fn process_iterator(js_iter: JsValue) {
5943///     // Checked cast - returns None if not an iterator
5944///     if let Some(iter) = js_iter.dyn_ref::<Iterator<Number>>() {
5945///         for value in iter.into_iter() {
5946///             let num: Number = value.unwrap();
5947///             // ...
5948///         }
5949///     }
5950/// }
5951///
5952/// // Or with unchecked cast when you're certain of the type
5953/// fn process_known_iterator(js_iter: JsValue) {
5954///     let iter: &Iterator<JsString> = js_iter.unchecked_ref();
5955///     for value in iter.into_iter() {
5956///         let s: JsString = value.unwrap();
5957///         // ...
5958///     }
5959/// }
5960/// ```
5961///
5962/// ## Using with `JsValue`
5963///
5964/// For dynamic or unknown iterables, use [`try_iter`] which returns an untyped iterator:
5965///
5966/// ```ignore
5967/// fn iterate_unknown(val: &JsValue) -> Result<(), JsValue> {
5968///     if let Some(iter) = js_sys::try_iter(val)? {
5969///         for item in iter {
5970///             let value: JsValue = item?;
5971///             // Handle dynamically...
5972///         }
5973///     }
5974///     Ok(())
5975/// }
5976/// ```
5977///
5978/// [`JsCast`]: wasm_bindgen::JsCast
5979/// [`Iterator<T>`]: Iterator
5980/// [`try_iter`]: crate::try_iter
5981pub trait Iterable {
5982    /// The type of values yielded by this iterable.
5983    type Item;
5984}
5985
5986impl<T: Iterable> Iterable for &T {
5987    type Item = T::Item;
5988}
5989
5990/// Trait for types known to implement the iterator protocol on Symbol.asyncIterator
5991pub trait AsyncIterable {
5992    type Item;
5993}
5994
5995impl<T: AsyncIterable> AsyncIterable for &T {
5996    type Item = T::Item;
5997}
5998
5999impl AsyncIterable for JsValue {
6000    type Item = JsValue;
6001}
6002
6003// IteratorNext
6004#[wasm_bindgen]
6005extern "C" {
6006    /// The result of calling `next()` on a JS iterator.
6007    ///
6008    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
6009    #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
6010    #[derive(Clone, Debug, PartialEq, Eq)]
6011    pub type IteratorNext<T = JsValue>;
6012
6013    /// Has the value `true` if the iterator is past the end of the iterated
6014    /// sequence. In this case value optionally specifies the return value of
6015    /// the iterator.
6016    ///
6017    /// Has the value `false` if the iterator was able to produce the next value
6018    /// in the sequence. This is equivalent of not specifying the done property
6019    /// altogether.
6020    #[wasm_bindgen(method, getter)]
6021    pub fn done<T>(this: &IteratorNext<T>) -> bool;
6022
6023    /// Any JavaScript value returned by the iterator. Can be omitted when done
6024    /// is true.
6025    #[wasm_bindgen(method, getter)]
6026    pub fn value<T>(this: &IteratorNext<T>) -> T;
6027}
6028
6029#[allow(non_snake_case)]
6030pub mod Math {
6031    use super::*;
6032
6033    // Math
6034    #[wasm_bindgen]
6035    extern "C" {
6036        /// The `Math.abs()` function returns the absolute value of a number, that is
6037        /// Math.abs(x) = |x|
6038        ///
6039        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
6040        #[wasm_bindgen(js_namespace = Math)]
6041        pub fn abs(x: f64) -> f64;
6042
6043        /// The `Math.acos()` function returns the arccosine (in radians) of a
6044        /// number, that is ∀x∊[-1;1]
6045        /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
6046        ///
6047        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
6048        #[wasm_bindgen(js_namespace = Math)]
6049        pub fn acos(x: f64) -> f64;
6050
6051        /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
6052        /// number, that is ∀x ≥ 1
6053        /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
6054        ///
6055        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
6056        #[wasm_bindgen(js_namespace = Math)]
6057        pub fn acosh(x: f64) -> f64;
6058
6059        /// The `Math.asin()` function returns the arcsine (in radians) of a
6060        /// number, that is ∀x ∊ [-1;1]
6061        /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
6062        ///
6063        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
6064        #[wasm_bindgen(js_namespace = Math)]
6065        pub fn asin(x: f64) -> f64;
6066
6067        /// The `Math.asinh()` function returns the hyperbolic arcsine of a
6068        /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
6069        ///
6070        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
6071        #[wasm_bindgen(js_namespace = Math)]
6072        pub fn asinh(x: f64) -> f64;
6073
6074        /// The `Math.atan()` function returns the arctangent (in radians) of a
6075        /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
6076        /// tan(y) = x
6077        #[wasm_bindgen(js_namespace = Math)]
6078        pub fn atan(x: f64) -> f64;
6079
6080        /// The `Math.atan2()` function returns the arctangent of the quotient of
6081        /// its arguments.
6082        ///
6083        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
6084        #[wasm_bindgen(js_namespace = Math)]
6085        pub fn atan2(y: f64, x: f64) -> f64;
6086
6087        /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
6088        /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
6089        /// tanh(y) = x
6090        ///
6091        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
6092        #[wasm_bindgen(js_namespace = Math)]
6093        pub fn atanh(x: f64) -> f64;
6094
6095        /// The `Math.cbrt() `function returns the cube root of a number, that is
6096        /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
6097        ///
6098        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
6099        #[wasm_bindgen(js_namespace = Math)]
6100        pub fn cbrt(x: f64) -> f64;
6101
6102        /// The `Math.ceil()` function returns the smallest integer greater than
6103        /// or equal to a given number.
6104        ///
6105        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
6106        #[wasm_bindgen(js_namespace = Math)]
6107        pub fn ceil(x: f64) -> f64;
6108
6109        /// The `Math.clz32()` function returns the number of leading zero bits in
6110        /// the 32-bit binary representation of a number.
6111        ///
6112        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
6113        #[wasm_bindgen(js_namespace = Math)]
6114        pub fn clz32(x: i32) -> u32;
6115
6116        /// The `Math.cos()` static function returns the cosine of the specified angle,
6117        /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
6118        ///
6119        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
6120        #[wasm_bindgen(js_namespace = Math)]
6121        pub fn cos(x: f64) -> f64;
6122
6123        /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
6124        /// that can be expressed using the constant e.
6125        ///
6126        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
6127        #[wasm_bindgen(js_namespace = Math)]
6128        pub fn cosh(x: f64) -> f64;
6129
6130        /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
6131        /// (also known as Napier's constant), the base of the natural logarithms.
6132        ///
6133        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
6134        #[wasm_bindgen(js_namespace = Math)]
6135        pub fn exp(x: f64) -> f64;
6136
6137        /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
6138        /// natural logarithms.
6139        ///
6140        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
6141        #[wasm_bindgen(js_namespace = Math)]
6142        pub fn expm1(x: f64) -> f64;
6143
6144        /// The `Math.floor()` function returns the largest integer less than or
6145        /// equal to a given number.
6146        ///
6147        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
6148        #[wasm_bindgen(js_namespace = Math)]
6149        pub fn floor(x: f64) -> f64;
6150
6151        /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
6152        /// of a Number.
6153        ///
6154        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
6155        #[wasm_bindgen(js_namespace = Math)]
6156        pub fn fround(x: f64) -> f32;
6157
6158        /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
6159        ///
6160        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
6161        #[wasm_bindgen(js_namespace = Math)]
6162        pub fn hypot(x: f64, y: f64) -> f64;
6163
6164        /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
6165        /// two parameters.
6166        ///
6167        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
6168        #[wasm_bindgen(js_namespace = Math)]
6169        pub fn imul(x: i32, y: i32) -> i32;
6170
6171        /// The `Math.log()` function returns the natural logarithm (base e) of a number.
6172        /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
6173        ///
6174        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
6175        #[wasm_bindgen(js_namespace = Math)]
6176        pub fn log(x: f64) -> f64;
6177
6178        /// The `Math.log10()` function returns the base 10 logarithm of a number.
6179        ///
6180        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
6181        #[wasm_bindgen(js_namespace = Math)]
6182        pub fn log10(x: f64) -> f64;
6183
6184        /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
6185        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
6186        #[wasm_bindgen(js_namespace = Math)]
6187        pub fn log1p(x: f64) -> f64;
6188
6189        /// The `Math.log2()` function returns the base 2 logarithm of a number.
6190        ///
6191        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
6192        #[wasm_bindgen(js_namespace = Math)]
6193        pub fn log2(x: f64) -> f64;
6194
6195        /// The `Math.max()` function returns the largest of two numbers.
6196        ///
6197        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
6198        #[wasm_bindgen(js_namespace = Math)]
6199        pub fn max(x: f64, y: f64) -> f64;
6200
6201        /// The static function `Math.min()` returns the lowest-valued number passed into it.
6202        ///
6203        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
6204        #[wasm_bindgen(js_namespace = Math)]
6205        pub fn min(x: f64, y: f64) -> f64;
6206
6207        /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
6208        ///
6209        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
6210        #[wasm_bindgen(js_namespace = Math)]
6211        pub fn pow(base: f64, exponent: f64) -> f64;
6212
6213        /// The `Math.random()` function returns a floating-point, pseudo-random number
6214        /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
6215        /// over that range — which you can then scale to your desired range.
6216        /// The implementation selects the initial seed to the random number generation algorithm;
6217        /// it cannot be chosen or reset by the user.
6218        ///
6219        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
6220        #[wasm_bindgen(js_namespace = Math)]
6221        pub fn random() -> f64;
6222
6223        /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
6224        ///
6225        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
6226        #[wasm_bindgen(js_namespace = Math)]
6227        pub fn round(x: f64) -> f64;
6228
6229        /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
6230        /// positive, negative or zero.
6231        ///
6232        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
6233        #[wasm_bindgen(js_namespace = Math)]
6234        pub fn sign(x: f64) -> f64;
6235
6236        /// The `Math.sin()` function returns the sine of a number.
6237        ///
6238        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
6239        #[wasm_bindgen(js_namespace = Math)]
6240        pub fn sin(x: f64) -> f64;
6241
6242        /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
6243        /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
6244        ///
6245        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
6246        #[wasm_bindgen(js_namespace = Math)]
6247        pub fn sinh(x: f64) -> f64;
6248
6249        /// The `Math.sqrt()` function returns the square root of a number, that is
6250        /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
6251        ///
6252        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
6253        #[wasm_bindgen(js_namespace = Math)]
6254        pub fn sqrt(x: f64) -> f64;
6255
6256        /// The `Math.tan()` function returns the tangent of a number.
6257        ///
6258        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
6259        #[wasm_bindgen(js_namespace = Math)]
6260        pub fn tan(x: f64) -> f64;
6261
6262        /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
6263        /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
6264        ///
6265        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
6266        #[wasm_bindgen(js_namespace = Math)]
6267        pub fn tanh(x: f64) -> f64;
6268
6269        /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
6270        /// digits.
6271        ///
6272        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
6273        #[wasm_bindgen(js_namespace = Math)]
6274        pub fn trunc(x: f64) -> f64;
6275
6276        /// The `Math.f16round()` function returns the nearest 16-bit half
6277        /// precision float representation of a number.
6278        ///
6279        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/f16round)
6280        #[wasm_bindgen(js_namespace = Math)]
6281        pub fn f16round(x: f64) -> f64;
6282
6283        /// The `Math.sumPrecise()` function takes an iterable of numbers and
6284        /// returns their sum, computed as if with infinite precision and
6285        /// rounded once at the end, so it is more accurate than a naive
6286        /// running sum.
6287        ///
6288        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sumPrecise)
6289        #[wasm_bindgen(js_namespace = Math, js_name = sumPrecise, catch)]
6290        pub fn sum_precise<I: Iterable>(values: &I) -> Result<f64, JsValue>;
6291
6292        /// The `Math.PI` property represents the ratio of the circumference of a circle to its diameter,
6293        /// approximately 3.14159.
6294        ///
6295        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI)
6296        #[wasm_bindgen(thread_local_v2, js_namespace = Math)]
6297        pub static PI: f64;
6298    }
6299}
6300
6301// Number.
6302#[wasm_bindgen]
6303extern "C" {
6304    #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
6305    #[derive(Clone, PartialEq)]
6306    pub type Number;
6307
6308    /// The `Number.isFinite()` method determines whether the passed value is a finite number.
6309    ///
6310    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
6311    #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
6312    pub fn is_finite(value: &JsValue) -> bool;
6313
6314    /// The `Number.isInteger()` method determines whether the passed value is an integer.
6315    ///
6316    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
6317    #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
6318    pub fn is_integer(value: &JsValue) -> bool;
6319
6320    /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
6321    /// It is a more robust version of the original, global isNaN().
6322    ///
6323    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
6324    #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
6325    pub fn is_nan(value: &JsValue) -> bool;
6326
6327    /// The `Number.isSafeInteger()` method determines whether the provided value is a number
6328    /// that is a safe integer.
6329    ///
6330    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
6331    #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
6332    pub fn is_safe_integer(value: &JsValue) -> bool;
6333
6334    /// The `Number` JavaScript object is a wrapper object allowing
6335    /// you to work with numerical values. A `Number` object is
6336    /// created using the `Number()` constructor.
6337    ///
6338    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
6339    #[cfg(not(js_sys_unstable_apis))]
6340    #[wasm_bindgen(constructor)]
6341    #[deprecated(note = "recommended to use `Number::from` instead")]
6342    #[allow(deprecated)]
6343    pub fn new(value: &JsValue) -> Number;
6344
6345    #[wasm_bindgen(constructor)]
6346    fn new_from_str(value: &str) -> Number;
6347
6348    /// The `Number.parseInt()` method parses a string argument and returns an
6349    /// integer of the specified radix or base.
6350    ///
6351    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
6352    #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
6353    pub fn parse_int(text: &str, radix: u8) -> f64;
6354
6355    /// The `Number.parseFloat()` method parses a string argument and returns a
6356    /// floating point number.
6357    ///
6358    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
6359    #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
6360    pub fn parse_float(text: &str) -> f64;
6361
6362    /// The `toLocaleString()` method returns a string with a language sensitive
6363    /// representation of this number.
6364    ///
6365    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
6366    #[cfg(not(js_sys_unstable_apis))]
6367    #[wasm_bindgen(method, js_name = toLocaleString)]
6368    pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
6369
6370    /// The `toLocaleString()` method returns a string with a language sensitive
6371    /// representation of this number.
6372    ///
6373    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
6374    #[cfg(js_sys_unstable_apis)]
6375    #[wasm_bindgen(method, js_name = toLocaleString)]
6376    pub fn to_locale_string(
6377        this: &Number,
6378        locales: &[JsString],
6379        options: &Intl::NumberFormatOptions,
6380    ) -> JsString;
6381
6382    /// The `toPrecision()` method returns a string representing the Number
6383    /// object to the specified precision.
6384    ///
6385    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
6386    #[wasm_bindgen(catch, method, js_name = toPrecision)]
6387    pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
6388
6389    /// The `toFixed()` method returns a string representing the Number
6390    /// object using fixed-point notation.
6391    ///
6392    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
6393    #[wasm_bindgen(catch, method, js_name = toFixed)]
6394    pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
6395
6396    /// The `toExponential()` method returns a string representing the Number
6397    /// object in exponential notation.
6398    ///
6399    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
6400    #[wasm_bindgen(catch, method, js_name = toExponential)]
6401    pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
6402
6403    /// The `toString()` method returns a string representing the
6404    /// specified Number object.
6405    ///
6406    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
6407    #[cfg(not(js_sys_unstable_apis))]
6408    #[deprecated(note = "Use `Number::to_string_with_radix` instead.")]
6409    #[allow(deprecated)]
6410    #[wasm_bindgen(catch, method, js_name = toString)]
6411    pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
6412
6413    /// The `toString()` method returns a string representing the
6414    /// specified Number object.
6415    ///
6416    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
6417    #[wasm_bindgen(catch, method, js_name = toString)]
6418    pub fn to_string_with_radix(this: &Number, radix: u8) -> Result<JsString, JsValue>;
6419
6420    /// The `valueOf()` method returns the wrapped primitive value of
6421    /// a Number object.
6422    ///
6423    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
6424    #[wasm_bindgen(method, js_name = valueOf)]
6425    pub fn value_of(this: &Number) -> f64;
6426}
6427
6428impl Number {
6429    /// The smallest interval between two representable numbers.
6430    ///
6431    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
6432    pub const EPSILON: f64 = f64::EPSILON;
6433    /// The maximum safe integer in JavaScript (2^53 - 1).
6434    ///
6435    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
6436    pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
6437    /// The largest positive representable number.
6438    ///
6439    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
6440    pub const MAX_VALUE: f64 = f64::MAX;
6441    /// The minimum safe integer in JavaScript (-(2^53 - 1)).
6442    ///
6443    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
6444    pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
6445    /// The smallest positive representable number—that is, the positive number closest to zero
6446    /// (without actually being zero).
6447    ///
6448    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
6449    // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number.
6450    pub const MIN_VALUE: f64 = 5E-324;
6451    /// Special "Not a Number" value.
6452    ///
6453    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
6454    pub const NAN: f64 = f64::NAN;
6455    /// Special value representing negative infinity. Returned on overflow.
6456    ///
6457    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
6458    pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
6459    /// Special value representing infinity. Returned on overflow.
6460    ///
6461    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
6462    pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
6463
6464    /// Applies the binary `**` JS operator on the two `Number`s.
6465    ///
6466    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
6467    #[inline]
6468    pub fn pow(&self, rhs: &Self) -> Self {
6469        JsValue::as_ref(self)
6470            .pow(JsValue::as_ref(rhs))
6471            .unchecked_into()
6472    }
6473
6474    /// Applies the binary `>>>` JS operator on the two `Number`s.
6475    ///
6476    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
6477    #[inline]
6478    pub fn unsigned_shr(&self, rhs: &Self) -> Self {
6479        Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs)))
6480    }
6481}
6482
6483macro_rules! number_from {
6484    ($($x:ident)*) => ($(
6485        impl From<$x> for Number {
6486            #[inline]
6487            fn from(x: $x) -> Number {
6488                Number::unchecked_from_js(JsValue::from(x))
6489            }
6490        }
6491
6492        impl PartialEq<$x> for Number {
6493            #[inline]
6494            fn eq(&self, other: &$x) -> bool {
6495                self.value_of() == f64::from(*other)
6496            }
6497        }
6498
6499        impl UpcastFrom<$x> for Number {}
6500    )*)
6501}
6502number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
6503
6504// The only guarantee for a JS number
6505impl UpcastFrom<Number> for f64 {}
6506
6507/// The error type returned when a checked integral type conversion fails.
6508#[derive(Debug, Copy, Clone, PartialEq, Eq)]
6509pub struct TryFromIntError(());
6510
6511impl fmt::Display for TryFromIntError {
6512    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
6513        fmt.write_str("out of range integral type conversion attempted")
6514    }
6515}
6516
6517#[cfg(feature = "std")]
6518impl std::error::Error for TryFromIntError {}
6519
6520macro_rules! number_try_from {
6521    ($($x:ident)*) => ($(
6522        impl TryFrom<$x> for Number {
6523            type Error = TryFromIntError;
6524
6525            #[inline]
6526            fn try_from(x: $x) -> Result<Number, Self::Error> {
6527                let x_f64 = x as f64;
6528                if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) {
6529                    Ok(Number::from(x_f64))
6530                } else {
6531                    Err(TryFromIntError(()))
6532                }
6533            }
6534        }
6535    )*)
6536}
6537number_try_from!(i64 u64 i128 u128);
6538
6539impl From<&Number> for f64 {
6540    #[inline]
6541    fn from(n: &Number) -> f64 {
6542        n.value_of()
6543    }
6544}
6545
6546impl From<Number> for f64 {
6547    #[inline]
6548    fn from(n: Number) -> f64 {
6549        <f64 as From<&'_ Number>>::from(&n)
6550    }
6551}
6552
6553impl fmt::Debug for Number {
6554    #[inline]
6555    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6556        fmt::Debug::fmt(&self.value_of(), f)
6557    }
6558}
6559
6560impl fmt::Display for Number {
6561    #[inline]
6562    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6563        fmt::Display::fmt(&self.value_of(), f)
6564    }
6565}
6566
6567impl Default for Number {
6568    fn default() -> Self {
6569        Self::from(f64::default())
6570    }
6571}
6572
6573impl PartialEq<BigInt> for Number {
6574    #[inline]
6575    fn eq(&self, other: &BigInt) -> bool {
6576        JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
6577    }
6578}
6579
6580impl Not for &Number {
6581    type Output = BigInt;
6582
6583    #[inline]
6584    fn not(self) -> Self::Output {
6585        JsValue::as_ref(self).bit_not().unchecked_into()
6586    }
6587}
6588
6589forward_deref_unop!(impl Not, not for Number);
6590forward_js_unop!(impl Neg, neg for Number);
6591forward_js_binop!(impl BitAnd, bitand for Number);
6592forward_js_binop!(impl BitOr, bitor for Number);
6593forward_js_binop!(impl BitXor, bitxor for Number);
6594forward_js_binop!(impl Shl, shl for Number);
6595forward_js_binop!(impl Shr, shr for Number);
6596forward_js_binop!(impl Add, add for Number);
6597forward_js_binop!(impl Sub, sub for Number);
6598forward_js_binop!(impl Div, div for Number);
6599forward_js_binop!(impl Mul, mul for Number);
6600forward_js_binop!(impl Rem, rem for Number);
6601
6602sum_product!(Number);
6603
6604impl PartialOrd for Number {
6605    #[inline]
6606    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
6607        if Number::is_nan(self) || Number::is_nan(other) {
6608            None
6609        } else if self == other {
6610            Some(Ordering::Equal)
6611        } else if self.lt(other) {
6612            Some(Ordering::Less)
6613        } else {
6614            Some(Ordering::Greater)
6615        }
6616    }
6617
6618    #[inline]
6619    fn lt(&self, other: &Self) -> bool {
6620        JsValue::as_ref(self).lt(JsValue::as_ref(other))
6621    }
6622
6623    #[inline]
6624    fn le(&self, other: &Self) -> bool {
6625        JsValue::as_ref(self).le(JsValue::as_ref(other))
6626    }
6627
6628    #[inline]
6629    fn ge(&self, other: &Self) -> bool {
6630        JsValue::as_ref(self).ge(JsValue::as_ref(other))
6631    }
6632
6633    #[inline]
6634    fn gt(&self, other: &Self) -> bool {
6635        JsValue::as_ref(self).gt(JsValue::as_ref(other))
6636    }
6637}
6638
6639#[cfg(not(js_sys_unstable_apis))]
6640impl FromStr for Number {
6641    type Err = Infallible;
6642
6643    #[allow(deprecated)]
6644    #[inline]
6645    fn from_str(s: &str) -> Result<Self, Self::Err> {
6646        Ok(Number::new_from_str(s))
6647    }
6648}
6649
6650// Date.
6651#[wasm_bindgen]
6652extern "C" {
6653    #[wasm_bindgen(extends = Object, typescript_type = "Date")]
6654    #[derive(Clone, Debug, PartialEq, Eq)]
6655    pub type Date;
6656
6657    /// The `getDate()` method returns the day of the month for the
6658    /// specified date according to local time.
6659    ///
6660    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
6661    #[wasm_bindgen(method, js_name = getDate)]
6662    pub fn get_date(this: &Date) -> u32;
6663
6664    /// The `getDay()` method returns the day of the week for the specified date according to local time,
6665    /// where 0 represents Sunday. For the day of the month see getDate().
6666    ///
6667    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
6668    #[wasm_bindgen(method, js_name = getDay)]
6669    pub fn get_day(this: &Date) -> u32;
6670
6671    /// The `getFullYear()` method returns the year of the specified date according to local time.
6672    ///
6673    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
6674    #[wasm_bindgen(method, js_name = getFullYear)]
6675    pub fn get_full_year(this: &Date) -> u32;
6676
6677    /// The `getHours()` method returns the hour for the specified date, according to local time.
6678    ///
6679    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
6680    #[wasm_bindgen(method, js_name = getHours)]
6681    pub fn get_hours(this: &Date) -> u32;
6682
6683    /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
6684    ///
6685    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
6686    #[wasm_bindgen(method, js_name = getMilliseconds)]
6687    pub fn get_milliseconds(this: &Date) -> u32;
6688
6689    /// The `getMinutes()` method returns the minutes in the specified date according to local time.
6690    ///
6691    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
6692    #[wasm_bindgen(method, js_name = getMinutes)]
6693    pub fn get_minutes(this: &Date) -> u32;
6694
6695    /// The `getMonth()` method returns the month in the specified date according to local time,
6696    /// as a zero-based value (where zero indicates the first month of the year).
6697    ///
6698    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
6699    #[wasm_bindgen(method, js_name = getMonth)]
6700    pub fn get_month(this: &Date) -> u32;
6701
6702    /// The `getSeconds()` method returns the seconds in the specified date according to local time.
6703    ///
6704    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
6705    #[wasm_bindgen(method, js_name = getSeconds)]
6706    pub fn get_seconds(this: &Date) -> u32;
6707
6708    /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
6709    /// according to universal time.
6710    ///
6711    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
6712    #[wasm_bindgen(method, js_name = getTime)]
6713    pub fn get_time(this: &Date) -> f64;
6714
6715    /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
6716    /// from current locale (host system settings) to UTC.
6717    ///
6718    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
6719    #[wasm_bindgen(method, js_name = getTimezoneOffset)]
6720    pub fn get_timezone_offset(this: &Date) -> f64;
6721
6722    /// The `getUTCDate()` method returns the day (date) of the month in the specified date
6723    /// according to universal time.
6724    ///
6725    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
6726    #[wasm_bindgen(method, js_name = getUTCDate)]
6727    pub fn get_utc_date(this: &Date) -> u32;
6728
6729    /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
6730    /// where 0 represents Sunday.
6731    ///
6732    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
6733    #[wasm_bindgen(method, js_name = getUTCDay)]
6734    pub fn get_utc_day(this: &Date) -> u32;
6735
6736    /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
6737    ///
6738    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
6739    #[wasm_bindgen(method, js_name = getUTCFullYear)]
6740    pub fn get_utc_full_year(this: &Date) -> u32;
6741
6742    /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
6743    ///
6744    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
6745    #[wasm_bindgen(method, js_name = getUTCHours)]
6746    pub fn get_utc_hours(this: &Date) -> u32;
6747
6748    /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date
6749    /// according to universal time.
6750    ///
6751    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds)
6752    #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
6753    pub fn get_utc_milliseconds(this: &Date) -> u32;
6754
6755    /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
6756    ///
6757    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
6758    #[wasm_bindgen(method, js_name = getUTCMinutes)]
6759    pub fn get_utc_minutes(this: &Date) -> u32;
6760
6761    /// The `getUTCMonth()` returns the month of the specified date according to universal time,
6762    /// as a zero-based value (where zero indicates the first month of the year).
6763    ///
6764    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
6765    #[wasm_bindgen(method, js_name = getUTCMonth)]
6766    pub fn get_utc_month(this: &Date) -> u32;
6767
6768    /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time.
6769    ///
6770    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds)
6771    #[wasm_bindgen(method, js_name = getUTCSeconds)]
6772    pub fn get_utc_seconds(this: &Date) -> u32;
6773
6774    /// Creates a JavaScript `Date` instance that represents
6775    /// a single moment in time. `Date` objects are based on a time value that is
6776    /// the number of milliseconds since 1 January 1970 UTC.
6777    ///
6778    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6779    #[wasm_bindgen(constructor)]
6780    pub fn new(init: &JsValue) -> Date;
6781
6782    /// Creates a JavaScript `Date` instance that represents the current moment in
6783    /// time.
6784    ///
6785    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6786    #[wasm_bindgen(constructor)]
6787    pub fn new_0() -> Date;
6788
6789    /// Creates a JavaScript `Date` instance that represents
6790    /// a single moment in time. `Date` objects are based on a time value that is
6791    /// the number of milliseconds since 1 January 1970 UTC.
6792    ///
6793    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6794    #[wasm_bindgen(constructor)]
6795    pub fn new_with_year_month(year: u32, month: i32) -> Date;
6796
6797    /// Creates a JavaScript `Date` instance that represents
6798    /// a single moment in time. `Date` objects are based on a time value that is
6799    /// the number of milliseconds since 1 January 1970 UTC.
6800    ///
6801    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6802    #[wasm_bindgen(constructor)]
6803    pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
6804
6805    /// Creates a JavaScript `Date` instance that represents
6806    /// a single moment in time. `Date` objects are based on a time value that is
6807    /// the number of milliseconds since 1 January 1970 UTC.
6808    ///
6809    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6810    #[wasm_bindgen(constructor)]
6811    pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
6812
6813    /// Creates a JavaScript `Date` instance that represents
6814    /// a single moment in time. `Date` objects are based on a time value that is
6815    /// the number of milliseconds since 1 January 1970 UTC.
6816    ///
6817    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6818    #[wasm_bindgen(constructor)]
6819    pub fn new_with_year_month_day_hr_min(
6820        year: u32,
6821        month: i32,
6822        day: i32,
6823        hr: i32,
6824        min: i32,
6825    ) -> Date;
6826
6827    /// Creates a JavaScript `Date` instance that represents
6828    /// a single moment in time. `Date` objects are based on a time value that is
6829    /// the number of milliseconds since 1 January 1970 UTC.
6830    ///
6831    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6832    #[wasm_bindgen(constructor)]
6833    pub fn new_with_year_month_day_hr_min_sec(
6834        year: u32,
6835        month: i32,
6836        day: i32,
6837        hr: i32,
6838        min: i32,
6839        sec: i32,
6840    ) -> Date;
6841
6842    /// Creates a JavaScript `Date` instance that represents
6843    /// a single moment in time. `Date` objects are based on a time value that is
6844    /// the number of milliseconds since 1 January 1970 UTC.
6845    ///
6846    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6847    #[wasm_bindgen(constructor)]
6848    pub fn new_with_year_month_day_hr_min_sec_milli(
6849        year: u32,
6850        month: i32,
6851        day: i32,
6852        hr: i32,
6853        min: i32,
6854        sec: i32,
6855        milli: i32,
6856    ) -> Date;
6857
6858    /// The `Date.now()` method returns the number of milliseconds
6859    /// elapsed since January 1, 1970 00:00:00 UTC.
6860    ///
6861    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
6862    #[wasm_bindgen(static_method_of = Date)]
6863    pub fn now() -> f64;
6864
6865    /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
6866    /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
6867    /// contains illegal date values (e.g. 2015-02-31).
6868    ///
6869    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
6870    #[wasm_bindgen(static_method_of = Date)]
6871    pub fn parse(date: &str) -> f64;
6872
6873    /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
6874    ///
6875    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
6876    #[wasm_bindgen(method, js_name = setDate)]
6877    pub fn set_date(this: &Date, day: u32) -> f64;
6878
6879    /// The `setFullYear()` method sets the full year for a specified date according to local time.
6880    /// Returns new timestamp.
6881    ///
6882    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6883    #[wasm_bindgen(method, js_name = setFullYear)]
6884    pub fn set_full_year(this: &Date, year: u32) -> f64;
6885
6886    /// The `setFullYear()` method sets the full year for a specified date according to local time.
6887    /// Returns new timestamp.
6888    ///
6889    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6890    #[wasm_bindgen(method, js_name = setFullYear)]
6891    pub fn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6892
6893    /// The `setFullYear()` method sets the full year for a specified date according to local time.
6894    /// Returns new timestamp.
6895    ///
6896    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6897    #[wasm_bindgen(method, js_name = setFullYear)]
6898    pub fn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6899
6900    /// The `setHours()` method sets the hours for a specified date according to local time,
6901    /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
6902    /// by the updated Date instance.
6903    ///
6904    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
6905    #[wasm_bindgen(method, js_name = setHours)]
6906    pub fn set_hours(this: &Date, hours: u32) -> f64;
6907
6908    /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
6909    ///
6910    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
6911    #[wasm_bindgen(method, js_name = setMilliseconds)]
6912    pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
6913
6914    /// The `setMinutes()` method sets the minutes for a specified date according to local time.
6915    ///
6916    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
6917    #[wasm_bindgen(method, js_name = setMinutes)]
6918    pub fn set_minutes(this: &Date, minutes: u32) -> f64;
6919
6920    /// The `setMonth()` method sets the month for a specified date according to the currently set year.
6921    ///
6922    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
6923    #[wasm_bindgen(method, js_name = setMonth)]
6924    pub fn set_month(this: &Date, month: u32) -> f64;
6925
6926    /// The `setSeconds()` method sets the seconds for a specified date according to local time.
6927    ///
6928    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
6929    #[wasm_bindgen(method, js_name = setSeconds)]
6930    pub fn set_seconds(this: &Date, seconds: u32) -> f64;
6931
6932    /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
6933    /// since January 1, 1970, 00:00:00 UTC.
6934    ///
6935    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
6936    #[wasm_bindgen(method, js_name = setTime)]
6937    pub fn set_time(this: &Date, time: f64) -> f64;
6938
6939    /// The `setUTCDate()` method sets the day of the month for a specified date
6940    /// according to universal time.
6941    ///
6942    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
6943    #[wasm_bindgen(method, js_name = setUTCDate)]
6944    pub fn set_utc_date(this: &Date, day: u32) -> f64;
6945
6946    /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6947    ///
6948    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6949    #[wasm_bindgen(method, js_name = setUTCFullYear)]
6950    pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
6951
6952    /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6953    ///
6954    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6955    #[wasm_bindgen(method, js_name = setUTCFullYear)]
6956    pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6957
6958    /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6959    ///
6960    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6961    #[wasm_bindgen(method, js_name = setUTCFullYear)]
6962    pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6963
6964    /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
6965    /// and returns the number of milliseconds since  January 1, 1970 00:00:00 UTC until the time
6966    /// represented by the updated Date instance.
6967    ///
6968    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
6969    #[wasm_bindgen(method, js_name = setUTCHours)]
6970    pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
6971
6972    /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
6973    /// according to universal time.
6974    ///
6975    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
6976    #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
6977    pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
6978
6979    /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
6980    ///
6981    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
6982    #[wasm_bindgen(method, js_name = setUTCMinutes)]
6983    pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
6984
6985    /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
6986    ///
6987    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
6988    #[wasm_bindgen(method, js_name = setUTCMonth)]
6989    pub fn set_utc_month(this: &Date, month: u32) -> f64;
6990
6991    /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
6992    ///
6993    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
6994    #[wasm_bindgen(method, js_name = setUTCSeconds)]
6995    pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
6996
6997    /// The `toDateString()` method returns the date portion of a Date object
6998    /// in human readable form in American English.
6999    ///
7000    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
7001    #[wasm_bindgen(method, js_name = toDateString)]
7002    pub fn to_date_string(this: &Date) -> JsString;
7003
7004    /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
7005    /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
7006    /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
7007    /// as denoted by the suffix "Z"
7008    ///
7009    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
7010    #[wasm_bindgen(method, js_name = toISOString)]
7011    pub fn to_iso_string(this: &Date) -> JsString;
7012
7013    /// The `toJSON()` method returns a string representation of the Date object.
7014    ///
7015    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
7016    #[wasm_bindgen(method, js_name = toJSON)]
7017    pub fn to_json(this: &Date) -> JsString;
7018
7019    /// The `toLocaleDateString()` method returns a string with a language sensitive
7020    /// representation of the date portion of this date. The new locales and options
7021    /// arguments let applications specify the language whose formatting conventions
7022    /// should be used and allow to customize the behavior of the function.
7023    /// In older implementations, which ignore the locales and options arguments,
7024    /// the locale used and the form of the string
7025    /// returned are entirely implementation dependent.
7026    ///
7027    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
7028    #[cfg(not(js_sys_unstable_apis))]
7029    #[wasm_bindgen(method, js_name = toLocaleDateString)]
7030    pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
7031
7032    /// The `toLocaleDateString()` method returns a string with a language sensitive
7033    /// representation of the date portion of this date.
7034    ///
7035    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
7036    #[cfg(js_sys_unstable_apis)]
7037    #[wasm_bindgen(method, js_name = toLocaleDateString)]
7038    pub fn to_locale_date_string(
7039        this: &Date,
7040        locales: &[JsString],
7041        options: &Intl::DateTimeFormatOptions,
7042    ) -> JsString;
7043
7044    /// The `toLocaleString()` method returns a string with a language sensitive
7045    /// representation of this date. The new locales and options arguments
7046    /// let applications specify the language whose formatting conventions
7047    /// should be used and customize the behavior of the function.
7048    /// In older implementations, which ignore the locales
7049    /// and options arguments, the locale used and the form of the string
7050    /// returned are entirely implementation dependent.
7051    ///
7052    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
7053    #[cfg(not(js_sys_unstable_apis))]
7054    #[wasm_bindgen(method, js_name = toLocaleString)]
7055    pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
7056
7057    /// The `toLocaleString()` method returns a string with a language sensitive
7058    /// representation of this date.
7059    ///
7060    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
7061    #[cfg(js_sys_unstable_apis)]
7062    #[wasm_bindgen(method, js_name = toLocaleString)]
7063    pub fn to_locale_string(
7064        this: &Date,
7065        locales: &[JsString],
7066        options: &Intl::DateTimeFormatOptions,
7067    ) -> JsString;
7068
7069    /// The `toLocaleTimeString()` method returns a string with a language sensitive
7070    /// representation of the time portion of this date. The new locales and options
7071    /// arguments let applications specify the language whose formatting conventions should be
7072    /// used and customize the behavior of the function. In older implementations, which ignore
7073    /// the locales and options arguments, the locale used and the form of the string
7074    /// returned are entirely implementation dependent.
7075    ///
7076    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
7077    #[cfg(not(js_sys_unstable_apis))]
7078    #[wasm_bindgen(method, js_name = toLocaleTimeString)]
7079    pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
7080
7081    /// The `toLocaleTimeString()` method returns a string with a language sensitive
7082    /// representation of the time portion of this date.
7083    ///
7084    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
7085    #[cfg(js_sys_unstable_apis)]
7086    #[wasm_bindgen(method, js_name = toLocaleTimeString)]
7087    pub fn to_locale_time_string(
7088        this: &Date,
7089        locales: &[JsString],
7090        options: &Intl::DateTimeFormatOptions,
7091    ) -> JsString;
7092
7093    #[cfg(not(js_sys_unstable_apis))]
7094    #[wasm_bindgen(method, js_name = toLocaleTimeString)]
7095    pub fn to_locale_time_string_with_options(
7096        this: &Date,
7097        locale: &str,
7098        options: &JsValue,
7099    ) -> JsString;
7100
7101    /// The `toString()` method returns a string representing
7102    /// the specified Date object.
7103    ///
7104    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
7105    #[cfg(not(js_sys_unstable_apis))]
7106    #[wasm_bindgen(method, js_name = toString)]
7107    pub fn to_string(this: &Date) -> JsString;
7108
7109    /// The `toTimeString()` method returns the time portion of a Date object in human
7110    /// readable form in American English.
7111    ///
7112    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
7113    #[wasm_bindgen(method, js_name = toTimeString)]
7114    pub fn to_time_string(this: &Date) -> JsString;
7115
7116    /// The `toUTCString()` method converts a date to a string,
7117    /// using the UTC time zone.
7118    ///
7119    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
7120    #[wasm_bindgen(method, js_name = toUTCString)]
7121    pub fn to_utc_string(this: &Date) -> JsString;
7122
7123    /// The `Date.UTC()` method accepts the same parameters as the
7124    /// longest form of the constructor, and returns the number of
7125    /// milliseconds in a `Date` object since January 1, 1970,
7126    /// 00:00:00, universal time.
7127    ///
7128    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
7129    #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
7130    pub fn utc(year: f64, month: f64) -> f64;
7131
7132    /// The `valueOf()` method  returns the primitive value of
7133    /// a Date object.
7134    ///
7135    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
7136    #[wasm_bindgen(method, js_name = valueOf)]
7137    pub fn value_of(this: &Date) -> f64;
7138
7139    /// The `toTemporalInstant()` method converts this `Date` to a
7140    /// `Temporal.Instant` representing the same moment in time.
7141    ///
7142    /// # Errors
7143    /// Throws a `RangeError` if this is an invalid date.
7144    ///
7145    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTemporalInstant)
7146    #[cfg(all(js_sys_unstable_apis, feature = "temporal"))]
7147    #[wasm_bindgen(method, js_name = toTemporalInstant, catch)]
7148    pub fn to_temporal_instant(this: &Date) -> Result<Temporal::Instant, RangeError>;
7149}
7150
7151// Property Descriptor.
7152#[wasm_bindgen]
7153extern "C" {
7154    #[wasm_bindgen(extends = Object)]
7155    #[derive(Clone, Debug)]
7156    pub type PropertyDescriptor<T = JsValue>;
7157
7158    #[wasm_bindgen(method, getter = writable)]
7159    pub fn get_writable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
7160
7161    #[wasm_bindgen(method, setter = writable)]
7162    pub fn set_writable<T>(this: &PropertyDescriptor<T>, writable: bool);
7163
7164    #[wasm_bindgen(method, getter = enumerable)]
7165    pub fn get_enumerable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
7166
7167    #[wasm_bindgen(method, setter = enumerable)]
7168    pub fn set_enumerable<T>(this: &PropertyDescriptor<T>, enumerable: bool);
7169
7170    #[wasm_bindgen(method, getter = configurable)]
7171    pub fn get_configurable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
7172
7173    #[wasm_bindgen(method, setter = configurable)]
7174    pub fn set_configurable<T>(this: &PropertyDescriptor<T>, configurable: bool);
7175
7176    #[wasm_bindgen(method, getter = get)]
7177    pub fn get_get<T>(this: &PropertyDescriptor<T>) -> Option<Function<fn() -> T>>;
7178
7179    #[wasm_bindgen(method, setter = get)]
7180    pub fn set_get<T>(this: &PropertyDescriptor<T>, get: Function<fn() -> T>);
7181
7182    #[wasm_bindgen(method, getter = set)]
7183    pub fn get_set<T>(this: &PropertyDescriptor<T>) -> Option<Function<fn(T) -> JsValue>>;
7184
7185    #[wasm_bindgen(method, setter = set)]
7186    pub fn set_set<T>(this: &PropertyDescriptor<T>, set: Function<fn(T) -> JsValue>);
7187
7188    #[wasm_bindgen(method, getter = value)]
7189    pub fn get_value<T>(this: &PropertyDescriptor<T>) -> Option<T>;
7190
7191    #[wasm_bindgen(method, setter = value)]
7192    pub fn set_value<T>(this: &PropertyDescriptor<T>, value: &T);
7193}
7194
7195impl PropertyDescriptor {
7196    #[cfg(not(js_sys_unstable_apis))]
7197    pub fn new<T>() -> PropertyDescriptor<T> {
7198        JsCast::unchecked_into(Object::new())
7199    }
7200
7201    #[cfg(js_sys_unstable_apis)]
7202    pub fn new<T>() -> PropertyDescriptor<T> {
7203        JsCast::unchecked_into(Object::<JsValue>::new())
7204    }
7205
7206    #[cfg(not(js_sys_unstable_apis))]
7207    pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
7208        let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::new());
7209        desc.set_value(value);
7210        desc
7211    }
7212
7213    #[cfg(js_sys_unstable_apis)]
7214    pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
7215        let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::<JsValue>::new());
7216        desc.set_value(value);
7217        desc
7218    }
7219}
7220
7221impl Default for PropertyDescriptor {
7222    fn default() -> Self {
7223        PropertyDescriptor::new()
7224    }
7225}
7226
7227// Object.
7228#[wasm_bindgen]
7229extern "C" {
7230    #[wasm_bindgen(typescript_type = "object")]
7231    #[derive(Clone, Debug)]
7232    pub type Object<T = JsValue>;
7233
7234    // Next major: deprecate
7235    /// The `Object.assign()` method is used to copy the values of all enumerable
7236    /// own properties from one or more source objects to a target object. It
7237    /// will return the target object.
7238    ///
7239    /// **Note:** Consider using [`Object::try_assign`] to support error handling.
7240    ///
7241    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
7242    #[wasm_bindgen(static_method_of = Object)]
7243    pub fn assign<T>(target: &Object<T>, source: &Object<T>) -> Object<T>;
7244
7245    // Next major: deprecate
7246    /// The `Object.assign()` method is used to copy the values of all enumerable
7247    /// own properties from one or more source objects to a target object. It
7248    /// will return the target object.
7249    ///
7250    /// **Note:** Consider using [`Object::try_assign`] to support error handling.
7251    ///
7252    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
7253    #[wasm_bindgen(static_method_of = Object, js_name = assign, catch)]
7254    pub fn try_assign<T>(target: &Object<T>, source: &Object<T>) -> Result<Object<T>, JsValue>;
7255
7256    /// The `Object.assign()` method is used to copy the values of all enumerable
7257    /// own properties from one or more source objects to a target object. It
7258    /// will return the target object.
7259    ///
7260    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
7261    #[cfg(not(js_sys_unstable_apis))]
7262    #[wasm_bindgen(static_method_of = Object, js_name = assign)]
7263    #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
7264    #[allow(deprecated)]
7265    pub fn assign2<T>(target: &Object<T>, source1: &Object<T>, source2: &Object<T>) -> Object<T>;
7266
7267    /// The `Object.assign()` method is used to copy the values of all enumerable
7268    /// own properties from one or more source objects to a target object. It
7269    /// will return the target object.
7270    ///
7271    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
7272    #[cfg(not(js_sys_unstable_apis))]
7273    #[wasm_bindgen(static_method_of = Object, js_name = assign)]
7274    #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
7275    #[allow(deprecated)]
7276    pub fn assign3<T>(
7277        target: &Object<T>,
7278        source1: &Object<T>,
7279        source2: &Object<T>,
7280        source3: &Object<T>,
7281    ) -> Object<T>;
7282
7283    /// The `Object.assign()` method is used to copy the values of all enumerable
7284    /// own properties from one or more source objects to a target object. It
7285    /// will return the target object.
7286    ///
7287    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
7288    #[wasm_bindgen(static_method_of = Object, js_name = assign, catch, variadic)]
7289    pub fn assign_many<T>(target: &Object<T>, sources: &[Object<T>]) -> Result<Object<T>, JsValue>;
7290
7291    /// The constructor property returns a reference to the `Object` constructor
7292    /// function that created the instance object.
7293    ///
7294    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
7295    #[wasm_bindgen(method, getter)]
7296    pub fn constructor<T>(this: &Object<T>) -> Function;
7297
7298    // Next major: `prototype: Nullable<&Object<T>>`
7299    /// The `Object.create()` method creates a new object, using an existing
7300    /// object to provide the newly created object's prototype.
7301    ///
7302    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
7303    #[wasm_bindgen(static_method_of = Object)]
7304    pub fn create<T>(prototype: &Object<T>) -> Object<T>;
7305
7306    /// The static method `Object.defineProperty()` defines a new
7307    /// property directly on an object, or modifies an existing
7308    /// property on an object, and returns the object.
7309    ///
7310    /// **Note:** Consider using [`Object::define_property_str`] to support typing and error handling.
7311    ///
7312    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
7313    #[cfg(not(js_sys_unstable_apis))]
7314    #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
7315    pub fn define_property<T>(obj: &Object<T>, prop: &JsValue, descriptor: &Object) -> Object<T>;
7316
7317    // Stable `_key`-suffixed variants of the generic `K: PropertyKey` property
7318    // operations can be added if `PropertyKey` stabilizes first.
7319    /// The static method `Object.defineProperty()` defines a new
7320    /// property directly on an object, or modifies an existing
7321    /// property on an object, and returns the object.
7322    ///
7323    /// The property key may be any JavaScript property-key representation
7324    /// (string, number, or symbol).
7325    ///
7326    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
7327    #[cfg(js_sys_unstable_apis)]
7328    #[wasm_bindgen(
7329        static_method_of = Object,
7330        js_name = defineProperty,
7331        catch,
7332        experimental_generic_mono
7333    )]
7334    pub fn define_property<T, K: PropertyKey>(
7335        obj: &Object<T>,
7336        prop: K,
7337        descriptor: &PropertyDescriptor<T>,
7338    ) -> Result<Object<T>, JsValue>;
7339
7340    // Next major: deprecate
7341    /// The static method `Object.defineProperty()` defines a new
7342    /// property directly on an object, or modifies an existing
7343    /// property on an object, and returns the object.
7344    ///
7345    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
7346    #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
7347    pub fn define_property_str<T>(
7348        obj: &Object<T>,
7349        prop: &JsString,
7350        descriptor: &PropertyDescriptor<T>,
7351    ) -> Result<Object<T>, JsValue>;
7352
7353    /// The static method `Object.defineProperty()` defines a new
7354    /// property directly on an object, or modifies an existing
7355    /// property on an object, and returns the object.
7356    ///
7357    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
7358    #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
7359    pub fn define_property_symbol<T>(
7360        obj: &Object<T>,
7361        prop: &Symbol,
7362        descriptor: &PropertyDescriptor<JsValue>,
7363    ) -> Result<Object<T>, JsValue>;
7364
7365    /// The `Object.defineProperties()` method defines new or modifies
7366    /// existing properties directly on an object, returning the
7367    /// object.
7368    ///
7369    /// **Note:** Consider using [`Object::try_define_properties`] to support typing and error handling.
7370    ///
7371    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
7372    #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
7373    pub fn define_properties<T>(obj: &Object<T>, props: &Object) -> Object<T>;
7374
7375    /// The `Object.defineProperties()` method defines new or modifies
7376    /// existing properties directly on an object, returning the
7377    /// object.
7378    ///
7379    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
7380    #[cfg(js_sys_unstable_apis)]
7381    #[wasm_bindgen(static_method_of = Object, js_name = defineProperties, catch)]
7382    pub fn try_define_properties<T>(
7383        obj: &Object<T>,
7384        props: &Object<PropertyDescriptor<T>>,
7385    ) -> Result<Object<T>, JsValue>;
7386
7387    /// The `Object.entries()` method returns an array of a given
7388    /// object's own enumerable property [key, value] pairs, in the
7389    /// same order as that provided by a for...in loop (the difference
7390    /// being that a for-in loop enumerates properties in the
7391    /// prototype chain as well).
7392    ///
7393    /// **Note:** Consider using [`Object::entries_typed`] to support typing and error handling.
7394    ///
7395    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7396    #[cfg(not(js_sys_unstable_apis))]
7397    #[wasm_bindgen(static_method_of = Object)]
7398    pub fn entries(object: &Object) -> Array;
7399
7400    /// The `Object.entries()` method returns an array of a given
7401    /// object's own enumerable property [key, value] pairs, in the
7402    /// same order as that provided by a for...in loop (the difference
7403    /// being that a for-in loop enumerates properties in the
7404    /// prototype chain as well).
7405    ///
7406    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7407    #[cfg(js_sys_unstable_apis)]
7408    #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
7409    pub fn entries<T>(object: &Object<T>) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
7410
7411    // Next major: deprecate
7412    /// The `Object.entries()` method returns an array of a given
7413    /// object's own enumerable property [key, value] pairs, in the
7414    /// same order as that provided by a for...in loop (the difference
7415    /// being that a for-in loop enumerates properties in the
7416    /// prototype chain as well).
7417    ///
7418    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7419    #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
7420    pub fn entries_typed<T>(
7421        object: &Object<T>,
7422    ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
7423
7424    /// The `Object.groupBy()` static method groups the values of an
7425    /// iterable into a null-prototype object keyed by the property key
7426    /// returned by `callback`.
7427    ///
7428    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy)
7429    #[wasm_bindgen(static_method_of = Object, catch, js_name = groupBy)]
7430    pub fn group_by<T, K, I: Iterable<Item = T>>(
7431        items: &I,
7432        callback: &mut dyn FnMut(T, u32) -> K,
7433    ) -> Result<Object<Array<T>>, JsValue>;
7434
7435    /// The `Object.freeze()` method freezes an object: that is, prevents new
7436    /// properties from being added to it; prevents existing properties from
7437    /// being removed; and prevents existing properties, or their enumerability,
7438    /// configurability, or writability, from being changed, it also prevents
7439    /// the prototype from being changed. The method returns the passed object.
7440    ///
7441    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
7442    #[wasm_bindgen(static_method_of = Object)]
7443    pub fn freeze<T>(value: &Object<T>) -> Object<T>;
7444
7445    /// The `Object.fromEntries()` method transforms a list of key-value pairs
7446    /// into an object.
7447    ///
7448    /// **Note:** Consider using [`Object::from_entries_typed`] to support typing and error handling.
7449    ///
7450    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7451    #[cfg(not(js_sys_unstable_apis))]
7452    #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7453    pub fn from_entries(entries: &JsValue) -> Result<Object, JsValue>;
7454
7455    /// The `Object.fromEntries()` method transforms a list of key-value pairs
7456    /// into an object.
7457    ///
7458    /// Entry keys may use any JavaScript property-key representation
7459    /// (string, number, or symbol).
7460    ///
7461    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7462    #[cfg(js_sys_unstable_apis)]
7463    #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7464    pub fn from_entries<K: PropertyKey, T, I: Iterable<Item = ArrayTuple<(K, T)>>>(
7465        entries: &I,
7466    ) -> Result<Object<T>, JsValue>;
7467
7468    // Next major: deprecate
7469    /// The `Object.fromEntries()` method transforms a list of key-value pairs
7470    /// into an object.
7471    ///
7472    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7473    #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7474    pub fn from_entries_typed<T, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
7475        entries: &I,
7476    ) -> Result<Object<T>, JsValue>;
7477
7478    /// The `Object.getOwnPropertyDescriptor()` method returns a
7479    /// property descriptor for an own property (that is, one directly
7480    /// present on an object and not in the object's prototype chain)
7481    /// of a given object.
7482    ///
7483    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7484    #[cfg(not(js_sys_unstable_apis))]
7485    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
7486    pub fn get_own_property_descriptor<T>(obj: &Object<T>, prop: &JsValue) -> JsValue;
7487
7488    /// The `Object.getOwnPropertyDescriptor()` method returns a
7489    /// property descriptor for an own property (that is, one directly
7490    /// present on an object and not in the object's prototype chain)
7491    /// of a given object.
7492    ///
7493    /// The property key may be any JavaScript property-key representation
7494    /// (string, number, or symbol).
7495    ///
7496    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7497    #[cfg(js_sys_unstable_apis)]
7498    #[wasm_bindgen(
7499        static_method_of = Object,
7500        js_name = getOwnPropertyDescriptor,
7501        catch,
7502        experimental_generic_mono
7503    )]
7504    pub fn get_own_property_descriptor<T, K: PropertyKey>(
7505        obj: &Object<T>,
7506        prop: K,
7507    ) -> Result<Option<PropertyDescriptor<T>>, JsValue>;
7508
7509    // Next major: deprecate
7510    /// The `Object.getOwnPropertyDescriptor()` method returns a
7511    /// property descriptor for an own property (that is, one directly
7512    /// present on an object and not in the object's prototype chain)
7513    /// of a given object.
7514    ///
7515    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7516    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
7517    pub fn get_own_property_descriptor_str<T>(
7518        obj: &Object<T>,
7519        prop: &JsString,
7520    ) -> Result<PropertyDescriptor<T>, JsValue>;
7521
7522    /// The `Object.getOwnPropertyDescriptor()` method returns a
7523    /// property descriptor for an own property (that is, one directly
7524    /// present on an object and not in the object's prototype chain)
7525    /// of a given object.
7526    ///
7527    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7528    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
7529    pub fn get_own_property_descriptor_symbol<T>(
7530        obj: &Object<T>,
7531        prop: &Symbol,
7532    ) -> Result<PropertyDescriptor<JsValue>, JsValue>;
7533
7534    /// The `Object.getOwnPropertyDescriptors()` method returns all own
7535    /// property descriptors of a given object.
7536    ///
7537    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
7538    #[cfg(not(js_sys_unstable_apis))]
7539    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
7540    pub fn get_own_property_descriptors<T>(obj: &Object<T>) -> JsValue;
7541
7542    /// The `Object.getOwnPropertyDescriptors()` method returns all own
7543    /// property descriptors of a given object.
7544    ///
7545    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
7546    #[cfg(js_sys_unstable_apis)]
7547    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors, catch)]
7548    pub fn get_own_property_descriptors<T>(
7549        obj: &Object<T>,
7550    ) -> Result<Object<PropertyDescriptor<T>>, JsValue>;
7551
7552    /// The `Object.getOwnPropertyNames()` method returns an array of
7553    /// all properties (including non-enumerable properties except for
7554    /// those which use Symbol) found directly upon a given object.
7555    ///
7556    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
7557    #[cfg(not(js_sys_unstable_apis))]
7558    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
7559    pub fn get_own_property_names<T>(obj: &Object<T>) -> Array;
7560
7561    /// The `Object.getOwnPropertyNames()` method returns an array of
7562    /// all properties (including non-enumerable properties except for
7563    /// those which use Symbol) found directly upon a given object.
7564    ///
7565    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
7566    #[cfg(js_sys_unstable_apis)]
7567    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames, catch)]
7568    pub fn get_own_property_names<T>(obj: &Object<T>) -> Result<Array<JsString>, JsValue>;
7569
7570    /// The `Object.getOwnPropertySymbols()` method returns an array of
7571    /// all symbol properties found directly upon a given object.
7572    ///
7573    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
7574    #[cfg(not(js_sys_unstable_apis))]
7575    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
7576    pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Array;
7577
7578    /// The `Object.getOwnPropertySymbols()` method returns an array of
7579    /// all symbol properties found directly upon a given object.
7580    ///
7581    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
7582    #[cfg(js_sys_unstable_apis)]
7583    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols, catch)]
7584    pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Result<Array<Symbol>, JsValue>;
7585
7586    // Next major: `-> Nullable<Object>`
7587    /// The `Object.getPrototypeOf()` method returns the prototype
7588    /// (i.e. the value of the internal [[Prototype]] property) of the
7589    /// specified object.
7590    ///
7591    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
7592    #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
7593    pub fn get_prototype_of(obj: &JsValue) -> Object;
7594
7595    /// The `hasOwnProperty()` method returns a boolean indicating whether the
7596    /// object has the specified property as its own property (as opposed to
7597    /// inheriting it).
7598    ///
7599    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
7600    #[deprecated(note = "Use `Object::hasOwn` instead.")]
7601    #[allow(deprecated)]
7602    #[wasm_bindgen(method, js_name = hasOwnProperty)]
7603    pub fn has_own_property<T>(this: &Object<T>, property: &JsValue) -> bool;
7604
7605    /// The `Object.hasOwn()` method returns a boolean indicating whether the
7606    /// object passed in has the specified property as its own property (as
7607    /// opposed to inheriting it).
7608    ///
7609    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7610    #[cfg(not(js_sys_unstable_apis))]
7611    #[wasm_bindgen(static_method_of = Object, js_name = hasOwn)]
7612    pub fn has_own<T>(instance: &Object<T>, property: &JsValue) -> bool;
7613
7614    /// The `Object.hasOwn()` method returns a boolean indicating whether the
7615    /// object passed in has the specified property as its own property (as
7616    /// opposed to inheriting it).
7617    ///
7618    /// The property key may be any JavaScript property-key representation
7619    /// (string, number, or symbol).
7620    ///
7621    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7622    #[cfg(js_sys_unstable_apis)]
7623    #[wasm_bindgen(
7624        static_method_of = Object,
7625        js_name = hasOwn,
7626        catch,
7627        experimental_generic_mono
7628    )]
7629    pub fn has_own<T, K: PropertyKey>(instance: &Object<T>, property: K) -> Result<bool, JsValue>;
7630
7631    // Next major: deprecate
7632    /// The `Object.hasOwn()` method returns a boolean indicating whether the
7633    /// object passed in has the specified property as its own property (as
7634    /// opposed to inheriting it).
7635    ///
7636    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7637    #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7638    pub fn has_own_str<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
7639
7640    /// The `Object.hasOwn()` method returns a boolean indicating whether the
7641    /// object passed in has the specified property as its own property (as
7642    /// opposed to inheriting it).
7643    ///
7644    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7645    #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7646    pub fn has_own_symbol<T>(instance: &Object<T>, property: &Symbol) -> Result<bool, JsValue>;
7647
7648    /// The `Object.is()` method determines whether two values are the same value.
7649    ///
7650    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
7651    #[wasm_bindgen(static_method_of = Object)]
7652    pub fn is(value1: &JsValue, value_2: &JsValue) -> bool;
7653
7654    /// The `Object.isExtensible()` method determines if an object is extensible
7655    /// (whether it can have new properties added to it).
7656    ///
7657    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
7658    #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
7659    pub fn is_extensible<T>(object: &Object<T>) -> bool;
7660
7661    /// The `Object.isFrozen()` determines if an object is frozen.
7662    ///
7663    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
7664    #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
7665    pub fn is_frozen<T>(object: &Object<T>) -> bool;
7666
7667    /// The `Object.isSealed()` method determines if an object is sealed.
7668    ///
7669    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
7670    #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
7671    pub fn is_sealed<T>(object: &Object<T>) -> bool;
7672
7673    /// The `isPrototypeOf()` method checks if an object exists in another
7674    /// object's prototype chain.
7675    ///
7676    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
7677    #[wasm_bindgen(method, js_name = isPrototypeOf)]
7678    pub fn is_prototype_of<T>(this: &Object<T>, value: &JsValue) -> bool;
7679
7680    /// The `Object.keys()` method returns an array of a given object's property
7681    /// names, in the same order as we get with a normal loop.
7682    ///
7683    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7684    #[cfg(not(js_sys_unstable_apis))]
7685    #[wasm_bindgen(static_method_of = Object)]
7686    pub fn keys<T>(object: &Object<T>) -> Array;
7687
7688    /// The `Object.keys()` method returns an array of a given object's property
7689    /// names, in the same order as we get with a normal loop.
7690    ///
7691    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7692    #[cfg(js_sys_unstable_apis)]
7693    #[wasm_bindgen(static_method_of = Object)]
7694    pub fn keys<T>(object: &Object<T>) -> Array<JsString>;
7695
7696    /// The [`Object`] constructor creates an object wrapper.
7697    ///
7698    /// **Note:** Consider using [`Object::new_typed`] for typed object records.
7699    ///
7700    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7701    #[wasm_bindgen(constructor)]
7702    pub fn new() -> Object;
7703
7704    // Next major: deprecate
7705    /// The [`Object`] constructor creates an object wrapper.
7706    ///
7707    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7708    #[wasm_bindgen(constructor)]
7709    pub fn new_typed<T>() -> Object<T>;
7710
7711    /// The `Object.preventExtensions()` method prevents new properties from
7712    /// ever being added to an object (i.e. prevents future extensions to the
7713    /// object).
7714    ///
7715    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
7716    #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
7717    pub fn prevent_extensions<T>(object: &Object<T>);
7718
7719    /// The `propertyIsEnumerable()` method returns a Boolean indicating
7720    /// whether the specified property is enumerable.
7721    ///
7722    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7723    #[cfg(not(js_sys_unstable_apis))]
7724    #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
7725    pub fn property_is_enumerable<T>(this: &Object<T>, property: &JsValue) -> bool;
7726
7727    /// The `propertyIsEnumerable()` method returns whether the specified
7728    /// property is both an own property and enumerable.
7729    ///
7730    /// The property key may be any JavaScript property-key representation
7731    /// (string, number, or symbol).
7732    ///
7733    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7734    #[cfg(js_sys_unstable_apis)]
7735    #[wasm_bindgen(
7736        method,
7737        js_name = propertyIsEnumerable,
7738        experimental_generic_mono
7739    )]
7740    pub fn property_is_enumerable<T, K: PropertyKey>(this: &Object<T>, property: K) -> bool;
7741
7742    /// The `Object.seal()` method seals an object, preventing new properties
7743    /// from being added to it and marking all existing properties as
7744    /// non-configurable.  Values of present properties can still be changed as
7745    /// long as they are writable.
7746    ///
7747    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
7748    #[wasm_bindgen(static_method_of = Object)]
7749    pub fn seal<T>(value: &Object<T>) -> Object<T>;
7750
7751    // Next major: `prototype: Nullable<&Object>`
7752    /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7753    /// internal `[[Prototype]]` property) of a specified object to another
7754    /// object or `null`.
7755    ///
7756    /// **Note:** Consider using [`Object::try_set_prototype_of`] to support errors.
7757    ///
7758    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7759    #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
7760    pub fn set_prototype_of<T>(object: &Object<T>, prototype: &Object) -> Object<T>;
7761
7762    /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7763    /// internal `[[Prototype]]` property) of a specified object to another
7764    /// object or `null`.
7765    ///
7766    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7767    #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf, catch)]
7768    pub fn try_set_prototype_of<T>(
7769        object: &Object<T>,
7770        prototype: &Object,
7771    ) -> Result<Object<T>, JsValue>;
7772
7773    /// The `toLocaleString()` method returns a string representing the object.
7774    /// This method is meant to be overridden by derived objects for
7775    /// locale-specific purposes.
7776    ///
7777    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
7778    #[wasm_bindgen(method, js_name = toLocaleString)]
7779    pub fn to_locale_string<T>(this: &Object<T>) -> JsString;
7780
7781    // Next major: deprecate
7782    /// The `toString()` method returns a string representing the object.
7783    ///
7784    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7785    #[wasm_bindgen(method, js_name = toString)]
7786    pub fn to_string<T>(this: &Object<T>) -> JsString;
7787
7788    /// The `toString()` method returns a string representing the object.
7789    ///
7790    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7791    #[wasm_bindgen(method, js_name = toString)]
7792    pub fn to_js_string<T>(this: &Object<T>) -> JsString;
7793
7794    /// The `valueOf()` method returns the primitive value of the
7795    /// specified object.
7796    ///
7797    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
7798    #[wasm_bindgen(method, js_name = valueOf)]
7799    pub fn value_of<T>(this: &Object<T>) -> Object;
7800
7801    /// The `Object.values()` method returns an array of a given object's own
7802    /// enumerable property values, in the same order as that provided by a
7803    /// `for...in` loop (the difference being that a for-in loop enumerates
7804    /// properties in the prototype chain as well).
7805    ///
7806    /// **Note:** Consider using [`Object::try_values`] to support errors.
7807    ///
7808    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7809    #[cfg(not(js_sys_unstable_apis))]
7810    #[wasm_bindgen(static_method_of = Object)]
7811    pub fn values<T>(object: &Object<T>) -> Array<T>;
7812
7813    /// The `Object.values()` method returns an array of a given object's own
7814    /// enumerable property values, in the same order as that provided by a
7815    /// `for...in` loop (the difference being that a for-in loop enumerates
7816    /// properties in the prototype chain as well).
7817    ///
7818    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7819    #[cfg(js_sys_unstable_apis)]
7820    #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7821    pub fn values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7822
7823    // Next major: deprecate
7824    /// The `Object.values()` method returns an array of a given object's own
7825    /// enumerable property values, in the same order as that provided by a
7826    /// `for...in` loop (the difference being that a for-in loop enumerates
7827    /// properties in the prototype chain as well).
7828    ///
7829    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7830    #[cfg(not(js_sys_unstable_apis))]
7831    #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7832    pub fn try_values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7833}
7834
7835impl Object {
7836    /// Returns the `Object` value of this JS value if it's an instance of an
7837    /// object.
7838    ///
7839    /// If this JS value is not an instance of an object then this returns
7840    /// `None`.
7841    pub fn try_from(val: &JsValue) -> Option<&Object> {
7842        if val.is_object() {
7843            Some(val.unchecked_ref())
7844        } else {
7845            None
7846        }
7847    }
7848}
7849
7850// `Object.is`, not the derived `===`: subclasses like `Number` can hold
7851// `NaN`, for which `===` is not reflexive as `Eq` requires. Next major: add
7852// a reference-value base type excluding primitives, move `Number` onto
7853// `JsValue`, and derive.
7854impl<T> PartialEq for Object<T> {
7855    #[inline]
7856    fn eq(&self, other: &Object<T>) -> bool {
7857        Object::is(self.as_ref(), other.as_ref())
7858    }
7859}
7860
7861impl<T> Eq for Object<T> {}
7862
7863impl Default for Object<JsValue> {
7864    fn default() -> Self {
7865        Self::new()
7866    }
7867}
7868
7869// Proxy
7870#[wasm_bindgen]
7871extern "C" {
7872    #[wasm_bindgen(typescript_type = "ProxyConstructor")]
7873    #[derive(Clone, Debug)]
7874    pub type Proxy;
7875
7876    /// The [`Proxy`] object is used to define custom behavior for fundamental
7877    /// operations (e.g. property lookup, assignment, enumeration, function
7878    /// invocation, etc).
7879    ///
7880    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
7881    #[wasm_bindgen(constructor)]
7882    pub fn new(target: &JsValue, handler: &Object) -> Proxy;
7883
7884    /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
7885    /// object.
7886    ///
7887    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
7888    #[wasm_bindgen(static_method_of = Proxy)]
7889    pub fn revocable(target: &JsValue, handler: &Object) -> Object;
7890}
7891
7892// RangeError
7893#[wasm_bindgen]
7894extern "C" {
7895    /// The `RangeError` object indicates an error when a value is not in the set
7896    /// or range of allowed values.
7897    ///
7898    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7899    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
7900    #[derive(Clone, Debug, PartialEq, Eq)]
7901    pub type RangeError;
7902
7903    /// The `RangeError` object indicates an error when a value is not in the set
7904    /// or range of allowed values.
7905    ///
7906    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7907    #[wasm_bindgen(constructor)]
7908    pub fn new(message: &str) -> RangeError;
7909
7910    /// Creates a new `RangeError` with the given message and a typed
7911    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
7912    /// original cause of the error.
7913    ///
7914    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError/RangeError)
7915    #[wasm_bindgen(constructor)]
7916    pub fn new_with_options(message: &str, options: &ErrorOptions) -> RangeError;
7917}
7918
7919// ReferenceError
7920#[wasm_bindgen]
7921extern "C" {
7922    /// The `ReferenceError` object represents an error when a non-existent
7923    /// variable is referenced.
7924    ///
7925    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7926    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
7927    #[derive(Clone, Debug, PartialEq, Eq)]
7928    pub type ReferenceError;
7929
7930    /// The `ReferenceError` object represents an error when a non-existent
7931    /// variable is referenced.
7932    ///
7933    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7934    #[wasm_bindgen(constructor)]
7935    pub fn new(message: &str) -> ReferenceError;
7936
7937    /// Creates a new `ReferenceError` with the given message and a typed
7938    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
7939    /// original cause of the error.
7940    ///
7941    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError/ReferenceError)
7942    #[wasm_bindgen(constructor)]
7943    pub fn new_with_options(message: &str, options: &ErrorOptions) -> ReferenceError;
7944}
7945
7946#[allow(non_snake_case)]
7947pub mod Reflect {
7948    use super::*;
7949
7950    // Reflect
7951    #[wasm_bindgen]
7952    extern "C" {
7953        /// The static `Reflect.apply()` method calls a target function with
7954        /// arguments as specified.
7955        ///
7956        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
7957        #[wasm_bindgen(js_namespace = Reflect, catch)]
7958        pub fn apply<T: JsFunction = fn() -> JsValue>(
7959            target: &Function<T>,
7960            this_argument: &JsValue,
7961            arguments_list: &Array,
7962        ) -> Result<<T as JsFunction>::Ret, JsValue>;
7963
7964        /// The static `Reflect.construct()` method acts like the new operator, but
7965        /// as a function.  It is equivalent to calling `new target(...args)`. It
7966        /// gives also the added option to specify a different prototype.
7967        ///
7968        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7969        #[cfg(not(js_sys_unstable_apis))]
7970        #[wasm_bindgen(js_namespace = Reflect, catch)]
7971        pub fn construct<T: JsFunction = fn() -> JsValue>(
7972            target: &Function<T>,
7973            arguments_list: &Array,
7974        ) -> Result<JsValue, JsValue>;
7975
7976        /// The static `Reflect.construct()` method acts like the new operator, but
7977        /// as a function.  It is equivalent to calling `new target(...args)`. It
7978        /// gives also the added option to specify a different prototype.
7979        ///
7980        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7981        #[cfg(js_sys_unstable_apis)]
7982        #[wasm_bindgen(js_namespace = Reflect, catch)]
7983        pub fn construct<T: JsFunction = fn() -> JsValue>(
7984            target: &Function<T>,
7985            arguments_list: &ArrayTuple, // DOTO: <A1, A2, A3, A4, A5, A6, A7, A8>,
7986        ) -> Result<JsValue, JsValue>;
7987
7988        /// The static `Reflect.construct()` method acts like the new operator, but
7989        /// as a function.  It is equivalent to calling `new target(...args)`. It
7990        /// gives also the added option to specify a different prototype.
7991        ///
7992        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7993        #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
7994        pub fn construct_with_new_target(
7995            target: &Function,
7996            arguments_list: &Array,
7997            new_target: &Function,
7998        ) -> Result<JsValue, JsValue>;
7999
8000        /// The static `Reflect.defineProperty()` method is like
8001        /// `Object.defineProperty()` but returns a `Boolean`.
8002        ///
8003        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
8004        #[cfg(not(js_sys_unstable_apis))]
8005        #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
8006        pub fn define_property<T>(
8007            target: &Object<T>,
8008            property_key: &JsValue,
8009            attributes: &Object,
8010        ) -> Result<bool, JsValue>;
8011
8012        /// The static `Reflect.defineProperty()` method is like
8013        /// `Object.defineProperty()` but returns a `Boolean`.
8014        ///
8015        /// The property key may be any JavaScript property-key representation
8016        /// (string, number, or symbol).
8017        ///
8018        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
8019        #[cfg(js_sys_unstable_apis)]
8020        #[wasm_bindgen(
8021            js_namespace = Reflect,
8022            js_name = defineProperty,
8023            catch,
8024            experimental_generic_mono
8025        )]
8026        pub fn define_property<T, K: PropertyKey>(
8027            target: &Object<T>,
8028            property_key: K,
8029            attributes: &PropertyDescriptor<T>,
8030        ) -> Result<bool, JsValue>;
8031
8032        /// The static `Reflect.defineProperty()` method is like
8033        /// `Object.defineProperty()` but returns a `Boolean`.
8034        ///
8035        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
8036        #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
8037        pub fn define_property_str<T>(
8038            target: &Object<T>,
8039            property_key: &JsString,
8040            attributes: &PropertyDescriptor<T>,
8041        ) -> Result<bool, JsValue>;
8042
8043        /// The static `Reflect.deleteProperty()` method allows to delete
8044        /// properties.  It is like the `delete` operator as a function.
8045        ///
8046        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
8047        #[cfg(not(js_sys_unstable_apis))]
8048        #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
8049        pub fn delete_property<T>(target: &Object<T>, key: &JsValue) -> Result<bool, JsValue>;
8050
8051        /// The static `Reflect.deleteProperty()` method allows to delete
8052        /// properties.  It is like the `delete` operator as a function.
8053        ///
8054        /// The property key may be any JavaScript property-key representation
8055        /// (string, number, or symbol).
8056        ///
8057        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
8058        #[cfg(js_sys_unstable_apis)]
8059        #[wasm_bindgen(
8060            js_namespace = Reflect,
8061            js_name = deleteProperty,
8062            catch,
8063            experimental_generic_mono
8064        )]
8065        pub fn delete_property<T, K: PropertyKey>(
8066            target: &Object<T>,
8067            key: K,
8068        ) -> Result<bool, JsValue>;
8069
8070        /// The static `Reflect.deleteProperty()` method allows to delete
8071        /// properties.  It is like the `delete` operator as a function.
8072        ///
8073        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
8074        #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
8075        pub fn delete_property_str<T>(target: &Object<T>, key: &JsString) -> Result<bool, JsValue>;
8076
8077        /// The static `Reflect.get()` method works like getting a property from
8078        /// an object (`target[propertyKey]`) as a function.
8079        ///
8080        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
8081        #[cfg(not(js_sys_unstable_apis))]
8082        #[wasm_bindgen(js_namespace = Reflect, catch)]
8083        pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
8084
8085        /// The static `Reflect.get()` method works like getting a property from
8086        /// an object (`target[propertyKey]`) as a function.
8087        ///
8088        /// The property key may be any JavaScript property-key representation
8089        /// (string, number, or symbol).
8090        ///
8091        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
8092        #[cfg(js_sys_unstable_apis)]
8093        #[wasm_bindgen(js_namespace = Reflect, catch, experimental_generic_mono)]
8094        pub fn get<T, K: PropertyKey>(target: &Object<T>, key: K) -> Result<Option<T>, JsValue>
8095        where
8096            Option<T>: FromWasmAbi;
8097
8098        /// The static `Reflect.get()` method works like getting a property from
8099        /// an object (`target[propertyKey]`) as a function.
8100        ///
8101        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
8102        #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
8103        pub fn get_str<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
8104
8105        /// The static `Reflect.get()` method works like getting a property from
8106        /// an object (`target[propertyKey]`) as a function.
8107        ///
8108        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
8109        #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
8110        pub fn get_symbol<T>(target: &Object<T>, key: &Symbol) -> Result<JsValue, JsValue>;
8111
8112        /// The same as [`get`](fn.get.html)
8113        /// except the key is an `f64`, which is slightly faster.
8114        #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
8115        pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
8116
8117        /// The same as [`get`](fn.get.html)
8118        /// except the key is a `u32`, which is slightly faster.
8119        #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
8120        pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
8121
8122        /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
8123        /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
8124        /// of the given property if it exists on the object, `undefined` otherwise.
8125        ///
8126        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
8127        #[cfg(not(js_sys_unstable_apis))]
8128        #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
8129        pub fn get_own_property_descriptor<T>(
8130            target: &Object<T>,
8131            property_key: &JsValue,
8132        ) -> Result<JsValue, JsValue>;
8133
8134        /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
8135        /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
8136        /// of the given property if it exists on the object, `undefined` otherwise.
8137        ///
8138        /// The property key may be any JavaScript property-key representation
8139        /// (string, number, or symbol).
8140        ///
8141        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
8142        #[cfg(js_sys_unstable_apis)]
8143        #[wasm_bindgen(
8144            js_namespace = Reflect,
8145            js_name = getOwnPropertyDescriptor,
8146            catch,
8147            experimental_generic_mono
8148        )]
8149        pub fn get_own_property_descriptor<T, K: PropertyKey>(
8150            target: &Object<T>,
8151            property_key: K,
8152        ) -> Result<Option<PropertyDescriptor<T>>, JsValue>;
8153
8154        /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
8155        /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
8156        /// of the given property if it exists on the object, `undefined` otherwise.
8157        ///
8158        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
8159        #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
8160        pub fn get_own_property_descriptor_str<T>(
8161            target: &Object<T>,
8162            property_key: &JsString,
8163        ) -> Result<PropertyDescriptor<T>, JsValue>;
8164
8165        // Next major: `-> Result<Nullable<Object>, JsValue>`
8166        /// The static `Reflect.getPrototypeOf()` method is almost the same
8167        /// method as `Object.getPrototypeOf()`. It returns the prototype
8168        /// (i.e. the value of the internal `[[Prototype]]` property) of
8169        /// the specified object.
8170        ///
8171        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
8172        #[cfg(not(js_sys_unstable_apis))]
8173        #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
8174        pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
8175
8176        // Next major: `-> Result<Nullable<Object>, JsValue>`
8177        /// The static `Reflect.getPrototypeOf()` method is almost the same
8178        /// method as `Object.getPrototypeOf()`. It returns the prototype
8179        /// (i.e. the value of the internal `[[Prototype]]` property) of
8180        /// the specified object.
8181        ///
8182        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
8183        #[cfg(js_sys_unstable_apis)]
8184        #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
8185        pub fn get_prototype_of(target: &Object) -> Result<Object, JsValue>;
8186
8187        /// The static `Reflect.has()` method works like the in operator as a
8188        /// function.
8189        ///
8190        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
8191        #[cfg(not(js_sys_unstable_apis))]
8192        #[wasm_bindgen(js_namespace = Reflect, catch)]
8193        pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
8194
8195        /// The static `Reflect.has()` method works like the in operator as a
8196        /// function.
8197        ///
8198        /// The property key may be any JavaScript property-key representation
8199        /// (string, number, or symbol).
8200        ///
8201        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
8202        #[cfg(js_sys_unstable_apis)]
8203        #[wasm_bindgen(js_namespace = Reflect, catch, experimental_generic_mono)]
8204        pub fn has<T, K: PropertyKey>(target: &Object<T>, property_key: K)
8205            -> Result<bool, JsValue>;
8206
8207        // Next major: deprecate
8208        /// The static `Reflect.has()` method works like the in operator as a
8209        /// function.
8210        ///
8211        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
8212        #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
8213        pub fn has_str<T>(target: &Object<T>, property_key: &JsString) -> Result<bool, JsValue>;
8214
8215        /// The static `Reflect.has()` method works like the in operator as a
8216        /// function.
8217        ///
8218        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
8219        #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
8220        pub fn has_symbol<T>(target: &Object<T>, property_key: &Symbol) -> Result<bool, JsValue>;
8221
8222        /// The static `Reflect.isExtensible()` method determines if an object is
8223        /// extensible (whether it can have new properties added to it). It is
8224        /// similar to `Object.isExtensible()`, but with some differences.
8225        ///
8226        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
8227        #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
8228        pub fn is_extensible<T>(target: &Object<T>) -> Result<bool, JsValue>;
8229
8230        /// The static `Reflect.ownKeys()` method returns an array of the
8231        /// target object's own property keys.
8232        ///
8233        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
8234        #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
8235        pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
8236
8237        /// The static `Reflect.preventExtensions()` method prevents new
8238        /// properties from ever being added to an object (i.e. prevents
8239        /// future extensions to the object). It is similar to
8240        /// `Object.preventExtensions()`, but with some differences.
8241        ///
8242        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
8243        #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
8244        pub fn prevent_extensions<T>(target: &Object<T>) -> Result<bool, JsValue>;
8245
8246        /// The static `Reflect.set()` method works like setting a
8247        /// property on an object.
8248        ///
8249        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
8250        #[cfg(not(js_sys_unstable_apis))]
8251        #[wasm_bindgen(js_namespace = Reflect, catch)]
8252        pub fn set(
8253            target: &JsValue,
8254            property_key: &JsValue,
8255            value: &JsValue,
8256        ) -> Result<bool, JsValue>;
8257
8258        /// The static `Reflect.set()` method works like setting a
8259        /// property on an object.
8260        ///
8261        /// The property key may be any JavaScript property-key representation
8262        /// (string, number, or symbol).
8263        ///
8264        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
8265        #[cfg(js_sys_unstable_apis)]
8266        #[wasm_bindgen(js_namespace = Reflect, catch, experimental_generic_mono)]
8267        pub fn set<T, K: PropertyKey>(
8268            target: &Object<T>,
8269            property_key: K,
8270            value: &T,
8271        ) -> Result<bool, JsValue>
8272        where
8273            T: wasm_bindgen::convert::RefIntoWasmAbi;
8274
8275        /// The static `Reflect.set()` method works like setting a
8276        /// property on an object.
8277        ///
8278        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
8279        #[cfg(js_sys_unstable_apis)]
8280        #[wasm_bindgen(js_namespace = Reflect, catch)]
8281        pub fn set_symbol<T>(
8282            target: &Object<T>,
8283            property_key: &Symbol,
8284            value: &JsValue,
8285        ) -> Result<bool, JsValue>;
8286
8287        // Next major: deprecate
8288        /// The static `Reflect.set()` method works like setting a
8289        /// property on an object.
8290        ///
8291        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
8292        #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
8293        pub fn set_str<T>(
8294            target: &Object<T>,
8295            property_key: &JsString,
8296            value: &T,
8297        ) -> Result<bool, JsValue>;
8298
8299        /// The same as [`set`](fn.set.html)
8300        /// except the key is an `f64`, which is slightly faster.
8301        #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
8302        pub fn set_f64(
8303            target: &JsValue,
8304            property_key: f64,
8305            value: &JsValue,
8306        ) -> Result<bool, JsValue>;
8307
8308        /// The same as [`set`](fn.set.html)
8309        /// except the key is a `u32`, which is slightly faster.
8310        #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
8311        pub fn set_u32(
8312            target: &JsValue,
8313            property_key: u32,
8314            value: &JsValue,
8315        ) -> Result<bool, JsValue>;
8316
8317        /// The static `Reflect.set()` method works like setting a
8318        /// property on an object.
8319        ///
8320        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
8321        #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
8322        pub fn set_with_receiver(
8323            target: &JsValue,
8324            property_key: &JsValue,
8325            value: &JsValue,
8326            receiver: &JsValue,
8327        ) -> Result<bool, JsValue>;
8328
8329        // Next major: `prototype: Nullable<&Object>`
8330        /// The static `Reflect.setPrototypeOf()` method is the same
8331        /// method as `Object.setPrototypeOf()`. It sets the prototype
8332        /// (i.e., the internal `[[Prototype]]` property) of a specified
8333        /// object to another object or to null.
8334        ///
8335        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
8336        #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
8337        pub fn set_prototype_of<T>(
8338            target: &Object<T>,
8339            prototype: &JsValue,
8340        ) -> Result<bool, JsValue>;
8341    }
8342}
8343
8344// RegExp
8345#[wasm_bindgen]
8346extern "C" {
8347    #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
8348    #[derive(Clone, Debug, PartialEq, Eq)]
8349    pub type RegExp;
8350
8351    /// The `exec()` method executes a search for a match in a specified
8352    /// string. Returns a result array, or null.
8353    ///
8354    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
8355    #[cfg(not(js_sys_unstable_apis))]
8356    #[wasm_bindgen(method)]
8357    pub fn exec(this: &RegExp, text: &str) -> Option<Array<JsString>>;
8358
8359    /// The `exec()` method executes a search for a match in a specified
8360    /// string. Returns a result array, or null.
8361    ///
8362    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
8363    #[cfg(js_sys_unstable_apis)]
8364    #[wasm_bindgen(method)]
8365    pub fn exec(this: &RegExp, text: &str) -> Nullable<RegExpMatchArray>;
8366
8367    /// The flags property returns a string consisting of the flags of
8368    /// the current regular expression object.
8369    ///
8370    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
8371    #[wasm_bindgen(method, getter)]
8372    pub fn flags(this: &RegExp) -> JsString;
8373
8374    /// The global property indicates whether or not the "g" flag is
8375    /// used with the regular expression. global is a read-only
8376    /// property of an individual regular expression instance.
8377    ///
8378    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
8379    #[wasm_bindgen(method, getter)]
8380    pub fn global(this: &RegExp) -> bool;
8381
8382    /// The ignoreCase property indicates whether or not the "i" flag
8383    /// is used with the regular expression. ignoreCase is a read-only
8384    /// property of an individual regular expression instance.
8385    ///
8386    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
8387    #[wasm_bindgen(method, getter, js_name = ignoreCase)]
8388    pub fn ignore_case(this: &RegExp) -> bool;
8389
8390    /// The non-standard input property is a static property of
8391    /// regular expressions that contains the string against which a
8392    /// regular expression is matched. RegExp.$_ is an alias for this
8393    /// property.
8394    ///
8395    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
8396    #[wasm_bindgen(static_method_of = RegExp, getter)]
8397    pub fn input() -> JsString;
8398
8399    /// The lastIndex is a read/write integer property of regular expression
8400    /// instances that specifies the index at which to start the next match.
8401    ///
8402    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
8403    #[wasm_bindgen(structural, getter = lastIndex, method)]
8404    pub fn last_index(this: &RegExp) -> u32;
8405
8406    /// The lastIndex is a read/write integer property of regular expression
8407    /// instances that specifies the index at which to start the next match.
8408    ///
8409    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
8410    #[wasm_bindgen(structural, setter = lastIndex, method)]
8411    pub fn set_last_index(this: &RegExp, index: u32);
8412
8413    /// The non-standard lastMatch property is a static and read-only
8414    /// property of regular expressions that contains the last matched
8415    /// characters. `RegExp.$&` is an alias for this property.
8416    ///
8417    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
8418    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
8419    pub fn last_match() -> JsString;
8420
8421    /// The non-standard lastParen property is a static and read-only
8422    /// property of regular expressions that contains the last
8423    /// parenthesized substring match, if any. `RegExp.$+` is an alias
8424    /// for this property.
8425    ///
8426    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
8427    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
8428    pub fn last_paren() -> JsString;
8429
8430    /// The non-standard leftContext property is a static and
8431    /// read-only property of regular expressions that contains the
8432    /// substring preceding the most recent match. `RegExp.$`` is an
8433    /// alias for this property.
8434    ///
8435    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
8436    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
8437    pub fn left_context() -> JsString;
8438
8439    /// The multiline property indicates whether or not the "m" flag
8440    /// is used with the regular expression. multiline is a read-only
8441    /// property of an individual regular expression instance.
8442    ///
8443    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
8444    #[wasm_bindgen(method, getter)]
8445    pub fn multiline(this: &RegExp) -> bool;
8446
8447    /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
8448    /// are static and read-only properties of regular expressions
8449    /// that contain parenthesized substring matches.
8450    ///
8451    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
8452    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
8453    pub fn n1() -> JsString;
8454    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
8455    pub fn n2() -> JsString;
8456    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
8457    pub fn n3() -> JsString;
8458    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
8459    pub fn n4() -> JsString;
8460    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
8461    pub fn n5() -> JsString;
8462    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
8463    pub fn n6() -> JsString;
8464    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
8465    pub fn n7() -> JsString;
8466    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
8467    pub fn n8() -> JsString;
8468    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
8469    pub fn n9() -> JsString;
8470
8471    /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
8472    ///
8473    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
8474    #[wasm_bindgen(constructor)]
8475    pub fn new(pattern: &str, flags: &str) -> RegExp;
8476    #[wasm_bindgen(constructor)]
8477    pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
8478
8479    /// The non-standard rightContext property is a static and
8480    /// read-only property of regular expressions that contains the
8481    /// substring following the most recent match. `RegExp.$'` is an
8482    /// alias for this property.
8483    ///
8484    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
8485    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
8486    pub fn right_context() -> JsString;
8487
8488    /// The source property returns a String containing the source
8489    /// text of the regexp object, and it doesn't contain the two
8490    /// forward slashes on both sides and any flags.
8491    ///
8492    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
8493    #[wasm_bindgen(method, getter)]
8494    pub fn source(this: &RegExp) -> JsString;
8495
8496    /// The sticky property reflects whether or not the search is
8497    /// sticky (searches in strings only from the index indicated by
8498    /// the lastIndex property of this regular expression). sticky is
8499    /// a read-only property of an individual regular expression
8500    /// object.
8501    ///
8502    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
8503    #[wasm_bindgen(method, getter)]
8504    pub fn sticky(this: &RegExp) -> bool;
8505
8506    /// The `test()` method executes a search for a match between a
8507    /// regular expression and a specified string. Returns true or
8508    /// false.
8509    ///
8510    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
8511    #[wasm_bindgen(method)]
8512    pub fn test(this: &RegExp, text: &str) -> bool;
8513
8514    /// The `toString()` method returns a string representing the
8515    /// regular expression.
8516    ///
8517    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
8518    #[cfg(not(js_sys_unstable_apis))]
8519    #[wasm_bindgen(method, js_name = toString)]
8520    pub fn to_string(this: &RegExp) -> JsString;
8521
8522    /// The unicode property indicates whether or not the "u" flag is
8523    /// used with a regular expression. unicode is a read-only
8524    /// property of an individual regular expression instance.
8525    ///
8526    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
8527    #[wasm_bindgen(method, getter)]
8528    pub fn unicode(this: &RegExp) -> bool;
8529
8530    /// The `dotAll` property indicates whether the `s` flag is set, making
8531    /// `.` match line terminators too.
8532    ///
8533    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/dotAll)
8534    #[wasm_bindgen(method, getter, js_name = dotAll)]
8535    pub fn dot_all(this: &RegExp) -> bool;
8536
8537    /// The `hasIndices` property indicates whether the `d` flag is set,
8538    /// recording capture group start and end indices on match results.
8539    ///
8540    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices)
8541    #[wasm_bindgen(method, getter, js_name = hasIndices)]
8542    pub fn has_indices(this: &RegExp) -> bool;
8543
8544    /// The `unicodeSets` property indicates whether the `v` flag is set,
8545    /// enabling set notation and string properties in character classes.
8546    ///
8547    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets)
8548    #[wasm_bindgen(method, getter, js_name = unicodeSets)]
8549    pub fn unicode_sets(this: &RegExp) -> bool;
8550
8551    /// The `RegExp.escape()` static method escapes any characters with
8552    /// special meaning in a regular expression so the result matches the
8553    /// input literally when used as a pattern.
8554    ///
8555    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/escape)
8556    #[wasm_bindgen(static_method_of = RegExp)]
8557    pub fn escape(text: &str) -> JsString;
8558}
8559
8560// RegExpMatchArray
8561#[wasm_bindgen]
8562extern "C" {
8563    /// The result array from `RegExp.exec()` or `String.matchAll()`.
8564    ///
8565    /// This is an array of strings with additional properties `index`, `input`, and `groups`.
8566    ///
8567    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#return_value)
8568    #[wasm_bindgen(extends = Object, extends = Array, typescript_type = "RegExpMatchArray")]
8569    #[derive(Clone, Debug, PartialEq, Eq)]
8570    pub type RegExpMatchArray;
8571
8572    /// The 0-based index of the match in the string.
8573    #[wasm_bindgen(method, getter)]
8574    pub fn index(this: &RegExpMatchArray) -> u32;
8575
8576    /// The original string that was matched against.
8577    #[wasm_bindgen(method, getter)]
8578    pub fn input(this: &RegExpMatchArray) -> JsString;
8579
8580    /// An object of named capturing groups whose keys are the names and valuestype Array
8581    /// are the capturing groups, or `undefined` if no named capturing groups were defined.
8582    #[wasm_bindgen(method, getter)]
8583    pub fn groups(this: &RegExpMatchArray) -> Option<Object>;
8584
8585    /// The number of elements in the match array (full match + capture groups).
8586    #[wasm_bindgen(method, getter)]
8587    pub fn length(this: &RegExpMatchArray) -> u32;
8588
8589    /// Gets the matched string or capture group at the given index.
8590    /// Index 0 is the full match, indices 1+ are capture groups.
8591    #[wasm_bindgen(method, indexing_getter)]
8592    pub fn get(this: &RegExpMatchArray, index: u32) -> Option<JsString>;
8593}
8594
8595// Set
8596#[wasm_bindgen]
8597extern "C" {
8598    #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
8599    #[derive(Clone, Debug, PartialEq, Eq)]
8600    pub type Set<T = JsValue>;
8601
8602    /// The [`Set`] object lets you store unique values of any type, whether
8603    /// primitive values or object references.
8604    ///
8605    /// **Note:** Consider using [`Set::new_typed`] to support typing.
8606    ///
8607    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8608    #[cfg(not(js_sys_unstable_apis))]
8609    #[wasm_bindgen(constructor)]
8610    pub fn new(init: &JsValue) -> Set;
8611
8612    /// The [`Set`] object lets you store unique values of any type, whether
8613    /// primitive values or object references.
8614    ///
8615    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8616    #[cfg(js_sys_unstable_apis)]
8617    #[wasm_bindgen(constructor)]
8618    pub fn new<T>() -> Set<T>;
8619
8620    // Next major: deprecate
8621    /// The [`Set`] object lets you store unique values of any type, whether
8622    /// primitive values or object references.
8623    ///
8624    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8625    #[wasm_bindgen(constructor)]
8626    pub fn new_typed<T>() -> Set<T>;
8627
8628    /// The [`Set`] object lets you store unique values of any type, whether
8629    /// primitive values or object references.
8630    ///
8631    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8632    #[wasm_bindgen(constructor, js_name = new)]
8633    pub fn new_empty<T>() -> Set<T>;
8634
8635    /// The [`Set`] object lets you store unique values of any type, whether
8636    /// primitive values or object references.
8637    ///
8638    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8639    #[wasm_bindgen(constructor, js_name = new)]
8640    pub fn new_from_items<T>(items: &[T]) -> Set<T>;
8641
8642    /// The [`Set`] object lets you store unique values of any type, whether
8643    /// primitive values or object references.
8644    ///
8645    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8646    #[wasm_bindgen(constructor, js_name = new, catch)]
8647    pub fn new_from_iterable<T, I: Iterable<Item = T>>(iterable: I) -> Result<Set<T>, JsValue>;
8648
8649    /// The `add()` method appends a new element with a specified value to the
8650    /// end of a [`Set`] object.
8651    ///
8652    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
8653    #[wasm_bindgen(method)]
8654    pub fn add<T>(this: &Set<T>, value: &T) -> Set<T>;
8655
8656    /// The `clear()` method removes all elements from a [`Set`] object.
8657    ///
8658    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
8659    #[wasm_bindgen(method)]
8660    pub fn clear<T>(this: &Set<T>);
8661
8662    /// The `delete()` method removes the specified element from a [`Set`]
8663    /// object.
8664    ///
8665    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
8666    #[wasm_bindgen(method)]
8667    pub fn delete<T>(this: &Set<T>, value: &T) -> bool;
8668
8669    /// The `forEach()` method executes a provided function once for each value
8670    /// in the Set object, in insertion order.
8671    ///
8672    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8673    #[cfg(not(js_sys_unstable_apis))]
8674    #[wasm_bindgen(method, js_name = forEach)]
8675    pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T, T, Set<T>));
8676
8677    /// The `forEach()` method executes a provided function once for each value
8678    /// in the Set object, in insertion order.
8679    ///
8680    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8681    #[cfg(js_sys_unstable_apis)]
8682    #[wasm_bindgen(method, js_name = forEach)]
8683    pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T));
8684
8685    /// The `forEach()` method executes a provided function once for each value
8686    /// in the Set object, in insertion order.
8687    ///
8688    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8689    #[wasm_bindgen(method, js_name = forEach, catch)]
8690    pub fn try_for_each<T>(
8691        this: &Set<T>,
8692        callback: &mut dyn FnMut(T) -> Result<(), JsError>,
8693    ) -> Result<(), JsValue>;
8694
8695    /// The `has()` method returns a boolean indicating whether an element with
8696    /// the specified value exists in a [`Set`] object or not.
8697    ///
8698    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
8699    #[wasm_bindgen(method)]
8700    pub fn has<T>(this: &Set<T>, value: &T) -> bool;
8701
8702    /// The size accessor property returns the number of elements in a [`Set`]
8703    /// object.
8704    ///
8705    /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
8706    #[wasm_bindgen(method, getter)]
8707    pub fn size<T>(this: &Set<T>) -> u32;
8708
8709    /// The `union()` method returns a new set containing elements which are in
8710    /// either or both of this set and the given set.
8711    ///
8712    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union)
8713    #[wasm_bindgen(method)]
8714    pub fn union<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8715
8716    /// The `intersection()` method returns a new set containing elements which are
8717    /// in both this set and the given set.
8718    ///
8719    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection)
8720    #[wasm_bindgen(method)]
8721    pub fn intersection<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8722
8723    /// The `difference()` method returns a new set containing elements which are
8724    /// in this set but not in the given set.
8725    ///
8726    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference)
8727    #[wasm_bindgen(method)]
8728    pub fn difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8729
8730    /// The `symmetricDifference()` method returns a new set containing elements
8731    /// which are in either this set or the given set, but not in both.
8732    ///
8733    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)
8734    #[wasm_bindgen(method, js_name = symmetricDifference)]
8735    pub fn symmetric_difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8736
8737    /// The `isSubsetOf()` method returns a boolean indicating whether all elements
8738    /// of this set are in the given set.
8739    ///
8740    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSubsetOf)
8741    #[wasm_bindgen(method, js_name = isSubsetOf)]
8742    pub fn is_subset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
8743
8744    /// The `isSupersetOf()` method returns a boolean indicating whether all elements
8745    /// of the given set are in this set.
8746    ///
8747    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSupersetOf)
8748    #[wasm_bindgen(method, js_name = isSupersetOf)]
8749    pub fn is_superset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
8750
8751    /// The `isDisjointFrom()` method returns a boolean indicating whether this set
8752    /// has no elements in common with the given set.
8753    ///
8754    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom)
8755    #[wasm_bindgen(method, js_name = isDisjointFrom)]
8756    pub fn is_disjoint_from<T>(this: &Set<T>, other: &Set<T>) -> bool;
8757}
8758
8759impl Default for Set<JsValue> {
8760    fn default() -> Self {
8761        Self::new_typed()
8762    }
8763}
8764
8765impl<T> Iterable for Set<T> {
8766    type Item = T;
8767}
8768
8769// SetIterator
8770#[wasm_bindgen]
8771extern "C" {
8772    /// The `entries()` method returns a new Iterator object that contains an
8773    /// array of [value, value] for each element in the Set object, in insertion
8774    /// order. For Set objects there is no key like in Map objects. However, to
8775    /// keep the API similar to the Map object, each entry has the same value
8776    /// for its key and value here, so that an array [value, value] is returned.
8777    ///
8778    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8779    #[cfg(not(js_sys_unstable_apis))]
8780    #[wasm_bindgen(method)]
8781    pub fn entries<T>(set: &Set<T>) -> Iterator;
8782
8783    /// The `entries()` method returns a new Iterator object that contains an
8784    /// array of [value, value] for each element in the Set object, in insertion
8785    /// order. For Set objects there is no key like in Map objects. However, to
8786    /// keep the API similar to the Map object, each entry has the same value
8787    /// for its key and value here, so that an array [value, value] is returned.
8788    ///
8789    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8790    #[cfg(js_sys_unstable_apis)]
8791    #[wasm_bindgen(method, js_name = entries)]
8792    pub fn entries<T>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
8793
8794    // Next major: deprecate
8795    /// The `entries()` method returns a new Iterator object that contains an
8796    /// array of [value, value] for each element in the Set object, in insertion
8797    /// order. For Set objects there is no key like in Map objects. However, to
8798    /// keep the API similar to the Map object, each entry has the same value
8799    /// for its key and value here, so that an array [value, value] is returned.
8800    ///
8801    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8802    #[wasm_bindgen(method, js_name = entries)]
8803    pub fn entries_typed<T>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
8804
8805    /// The `keys()` method is an alias for this method (for similarity with
8806    /// Map objects); it behaves exactly the same and returns values
8807    /// of Set elements.
8808    ///
8809    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
8810    #[wasm_bindgen(method)]
8811    pub fn keys<T>(set: &Set<T>) -> Iterator<T>;
8812
8813    /// The `values()` method returns a new Iterator object that contains the
8814    /// values for each element in the Set object in insertion order.
8815    ///
8816    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
8817    #[wasm_bindgen(method)]
8818    pub fn values<T>(set: &Set<T>) -> Iterator<T>;
8819}
8820
8821// SuppressedError
8822#[wasm_bindgen]
8823extern "C" {
8824    /// A `SuppressedError` is thrown when disposing a [`DisposableStack`]
8825    /// and one disposer's error masks another; `error` is the newer error
8826    /// and `suppressed` the one it hid.
8827    ///
8828    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SuppressedError)
8829    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SuppressedError")]
8830    #[derive(Clone, Debug, PartialEq, Eq)]
8831    pub type SuppressedError;
8832
8833    /// Creates a new `SuppressedError` wrapping `error` and `suppressed`.
8834    ///
8835    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SuppressedError/SuppressedError)
8836    #[wasm_bindgen(constructor)]
8837    pub fn new(error: &JsValue, suppressed: &JsValue) -> SuppressedError;
8838
8839    /// Creates a new `SuppressedError` with a message.
8840    #[wasm_bindgen(constructor)]
8841    pub fn new_with_message(
8842        error: &JsValue,
8843        suppressed: &JsValue,
8844        message: &str,
8845    ) -> SuppressedError;
8846
8847    /// Creates a new `SuppressedError` with a message and options such as `cause`.
8848    #[wasm_bindgen(constructor)]
8849    pub fn new_with_message_and_error_options(
8850        error: &JsValue,
8851        suppressed: &JsValue,
8852        message: &str,
8853        options: &ErrorOptions,
8854    ) -> SuppressedError;
8855
8856    /// The error that was thrown most recently.
8857    ///
8858    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SuppressedError/error)
8859    #[wasm_bindgen(method, getter)]
8860    pub fn error(this: &SuppressedError) -> JsValue;
8861
8862    /// The error that was suppressed by `error`.
8863    ///
8864    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SuppressedError/suppressed)
8865    #[wasm_bindgen(method, getter)]
8866    pub fn suppressed(this: &SuppressedError) -> JsValue;
8867}
8868
8869// SyntaxError
8870#[wasm_bindgen]
8871extern "C" {
8872    /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8873    /// token order that does not conform to the syntax of the language when
8874    /// parsing code.
8875    ///
8876    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8877    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
8878    #[derive(Clone, Debug, PartialEq, Eq)]
8879    pub type SyntaxError;
8880
8881    /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8882    /// token order that does not conform to the syntax of the language when
8883    /// parsing code.
8884    ///
8885    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8886    #[wasm_bindgen(constructor)]
8887    pub fn new(message: &str) -> SyntaxError;
8888
8889    /// Creates a new `SyntaxError` with the given message and a typed
8890    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8891    /// original cause of the error.
8892    ///
8893    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError/SyntaxError)
8894    #[wasm_bindgen(constructor)]
8895    pub fn new_with_options(message: &str, options: &ErrorOptions) -> SyntaxError;
8896}
8897
8898// TypeError
8899#[wasm_bindgen]
8900extern "C" {
8901    /// The `TypeError` object represents an error when a value is not of the
8902    /// expected type.
8903    ///
8904    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8905    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
8906    #[derive(Clone, Debug, PartialEq, Eq)]
8907    pub type TypeError;
8908
8909    /// The `TypeError` object represents an error when a value is not of the
8910    /// expected type.
8911    ///
8912    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8913    #[wasm_bindgen(constructor)]
8914    pub fn new(message: &str) -> TypeError;
8915
8916    /// Creates a new `TypeError` with the given message and a typed
8917    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8918    /// original cause of the error.
8919    ///
8920    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError/TypeError)
8921    #[wasm_bindgen(constructor)]
8922    pub fn new_with_options(message: &str, options: &ErrorOptions) -> TypeError;
8923}
8924
8925// URIError
8926#[wasm_bindgen]
8927extern "C" {
8928    /// The `URIError` object represents an error when a global URI handling
8929    /// function was used in a wrong way.
8930    ///
8931    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8932    #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
8933    #[derive(Clone, Debug, PartialEq, Eq)]
8934    pub type UriError;
8935
8936    /// The `URIError` object represents an error when a global URI handling
8937    /// function was used in a wrong way.
8938    ///
8939    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8940    #[wasm_bindgen(constructor, js_class = "URIError")]
8941    pub fn new(message: &str) -> UriError;
8942
8943    /// Creates a new `URIError` with the given message and a typed
8944    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8945    /// original cause of the error.
8946    ///
8947    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError/URIError)
8948    #[wasm_bindgen(constructor, js_class = "URIError")]
8949    pub fn new_with_options(message: &str, options: &ErrorOptions) -> UriError;
8950}
8951
8952// WeakMap
8953#[wasm_bindgen]
8954extern "C" {
8955    #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
8956    #[derive(Clone, Debug, PartialEq, Eq)]
8957    pub type WeakMap<K = Object, V = JsValue>;
8958
8959    /// The [`WeakMap`] object is a collection of key/value pairs in which the
8960    /// keys are weakly referenced.  The keys must be objects and the values can
8961    /// be arbitrary values.
8962    ///
8963    /// **Note:** Consider using [`WeakMap::new_typed`] to support typing.
8964    ///
8965    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8966    #[cfg(not(js_sys_unstable_apis))]
8967    #[wasm_bindgen(constructor)]
8968    pub fn new() -> WeakMap;
8969
8970    /// The [`WeakMap`] object is a collection of key/value pairs in which the
8971    /// keys are weakly referenced.  The keys must be objects and the values can
8972    /// be arbitrary values.
8973    ///
8974    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8975    #[cfg(js_sys_unstable_apis)]
8976    #[wasm_bindgen(constructor)]
8977    pub fn new<K = Object, V = Object>() -> WeakMap<K, V>;
8978
8979    // Next major: deprecate
8980    /// The [`WeakMap`] object is a collection of key/value pairs in which the
8981    /// keys are weakly referenced.  The keys must be objects and the values can
8982    /// be arbitrary values.
8983    ///
8984    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8985    #[wasm_bindgen(constructor)]
8986    pub fn new_typed<K = Object, V = Object>() -> WeakMap<K, V>;
8987
8988    /// The `set()` method sets the value for the key in the [`WeakMap`] object.
8989    /// Returns the [`WeakMap`] object.
8990    ///
8991    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
8992    #[wasm_bindgen(method, js_class = "WeakMap")]
8993    pub fn set<K, V>(this: &WeakMap<K, V>, key: &K, value: &V) -> WeakMap<K, V>;
8994
8995    /// The `get()` method returns a specified by key element
8996    /// from a [`WeakMap`] object. Returns `undefined` if the key is not found.
8997    ///
8998    /// **Note:** Consider using [`WeakMap::get_checked`] to get an `Option<V>` instead.
8999    ///
9000    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
9001    #[cfg(not(js_sys_unstable_apis))]
9002    #[wasm_bindgen(method)]
9003    pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> V;
9004
9005    /// The `get()` method returns a specified by key element
9006    /// from a [`WeakMap`] object. Returns `None` if the key is not found.
9007    ///
9008    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
9009    #[cfg(js_sys_unstable_apis)]
9010    #[wasm_bindgen(method)]
9011    pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
9012
9013    /// The `get()` method returns a specified by key element
9014    /// from a [`WeakMap`] object. Returns `None` if the key is not found.
9015    ///
9016    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
9017    #[wasm_bindgen(method, js_name = get)]
9018    pub fn get_checked<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
9019
9020    /// The `has()` method returns a boolean indicating whether an element with
9021    /// the specified key exists in the [`WeakMap`] object or not.
9022    ///
9023    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
9024    #[wasm_bindgen(method)]
9025    pub fn has<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
9026
9027    /// The `delete()` method removes the specified element from a [`WeakMap`]
9028    /// object.
9029    ///
9030    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
9031    #[wasm_bindgen(method)]
9032    pub fn delete<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
9033
9034    /// The `getOrInsert()` method returns the value for `key`, first
9035    /// inserting `default_value` under it if the key is absent.
9036    ///
9037    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/getOrInsert)
9038    #[wasm_bindgen(method, catch, js_name = getOrInsert)]
9039    pub fn get_or_insert<K, V>(
9040        this: &WeakMap<K, V>,
9041        key: &K,
9042        default_value: &V,
9043    ) -> Result<V, JsValue>;
9044
9045    /// The `getOrInsertComputed()` method returns the value for `key`,
9046    /// first inserting the result of `callback(key)` under it if the key
9047    /// is absent.
9048    ///
9049    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/getOrInsertComputed)
9050    #[wasm_bindgen(method, catch, js_name = getOrInsertComputed)]
9051    pub fn get_or_insert_computed<K, V>(
9052        this: &WeakMap<K, V>,
9053        key: &K,
9054        callback: &mut dyn FnMut(K) -> V,
9055    ) -> Result<V, JsValue>;
9056}
9057
9058impl Default for WeakMap {
9059    fn default() -> Self {
9060        Self::new()
9061    }
9062}
9063
9064// WeakSet
9065#[wasm_bindgen]
9066extern "C" {
9067    #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
9068    #[derive(Clone, Debug, PartialEq, Eq)]
9069    pub type WeakSet<T = Object>;
9070
9071    /// The `WeakSet` object lets you store weakly held objects in a collection.
9072    ///
9073    /// **Note:** Consider using [`WeakSet::new_typed`] for typed sets.
9074    ///
9075    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
9076    #[cfg(not(js_sys_unstable_apis))]
9077    #[wasm_bindgen(constructor)]
9078    pub fn new() -> WeakSet;
9079
9080    /// The `WeakSet` object lets you store weakly held objects in a collection.
9081    ///
9082    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
9083    #[cfg(js_sys_unstable_apis)]
9084    #[wasm_bindgen(constructor)]
9085    pub fn new<T = Object>() -> WeakSet<T>;
9086
9087    // Next major: deprecate
9088    /// The `WeakSet` object lets you store weakly held objects in a collection.
9089    ///
9090    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
9091    #[wasm_bindgen(constructor)]
9092    pub fn new_typed<T = Object>() -> WeakSet<T>;
9093
9094    /// The `has()` method returns a boolean indicating whether an object exists
9095    /// in a WeakSet or not.
9096    ///
9097    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
9098    #[wasm_bindgen(method)]
9099    pub fn has<T>(this: &WeakSet<T>, value: &T) -> bool;
9100
9101    /// The `add()` method appends a new object to the end of a WeakSet object.
9102    ///
9103    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
9104    #[wasm_bindgen(method)]
9105    pub fn add<T>(this: &WeakSet<T>, value: &T) -> WeakSet<T>;
9106
9107    /// The `delete()` method removes the specified element from a WeakSet
9108    /// object.
9109    ///
9110    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
9111    #[wasm_bindgen(method)]
9112    pub fn delete<T>(this: &WeakSet<T>, value: &T) -> bool;
9113}
9114
9115impl Default for WeakSet {
9116    fn default() -> Self {
9117        Self::new()
9118    }
9119}
9120
9121// WeakRef
9122#[wasm_bindgen]
9123extern "C" {
9124    #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
9125    #[derive(Clone, Debug, PartialEq, Eq)]
9126    pub type WeakRef<T = Object>;
9127
9128    /// The `WeakRef` object contains a weak reference to an object. A weak
9129    /// reference to an object is a reference that does not prevent the object
9130    /// from being reclaimed by the garbage collector.
9131    ///
9132    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
9133    #[wasm_bindgen(constructor)]
9134    pub fn new<T = Object>(target: &T) -> WeakRef<T>;
9135
9136    /// Returns the `Object` this `WeakRef` points to, or `None` if the
9137    /// object has been garbage collected.
9138    ///
9139    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
9140    #[wasm_bindgen(method)]
9141    pub fn deref<T>(this: &WeakRef<T>) -> Option<T>;
9142}
9143
9144#[cfg(all(js_sys_unstable_apis, feature = "temporal"))]
9145#[allow(non_snake_case)]
9146pub mod Temporal;
9147
9148#[allow(non_snake_case)]
9149pub mod WebAssembly {
9150    use super::*;
9151
9152    // WebAssembly
9153    #[wasm_bindgen]
9154    extern "C" {
9155        /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
9156        /// from WebAssembly binary code.  This function is useful if it is
9157        /// necessary to a compile a module before it can be instantiated
9158        /// (otherwise, the `WebAssembly.instantiate()` function should be used).
9159        ///
9160        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
9161        #[cfg(not(js_sys_unstable_apis))]
9162        #[wasm_bindgen(js_namespace = WebAssembly)]
9163        pub fn compile(buffer_source: &JsValue) -> Promise<JsValue>;
9164
9165        /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
9166        /// from WebAssembly binary code.  This function is useful if it is
9167        /// necessary to a compile a module before it can be instantiated
9168        /// (otherwise, the `WebAssembly.instantiate()` function should be used).
9169        ///
9170        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
9171        #[cfg(js_sys_unstable_apis)]
9172        #[wasm_bindgen(js_namespace = WebAssembly)]
9173        pub fn compile(buffer_source: &JsValue) -> Promise<Module>;
9174
9175        /// The `WebAssembly.compileStreaming()` function compiles a
9176        /// `WebAssembly.Module` module directly from a streamed underlying
9177        /// source. This function is useful if it is necessary to a compile a
9178        /// module before it can be instantiated (otherwise, the
9179        /// `WebAssembly.instantiateStreaming()` function should be used).
9180        ///
9181        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
9182        #[cfg(not(js_sys_unstable_apis))]
9183        #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
9184        pub fn compile_streaming(response: &Promise) -> Promise<JsValue>;
9185
9186        /// The `WebAssembly.compileStreaming()` function compiles a
9187        /// `WebAssembly.Module` module directly from a streamed underlying
9188        /// source. This function is useful if it is necessary to a compile a
9189        /// module before it can be instantiated (otherwise, the
9190        /// `WebAssembly.instantiateStreaming()` function should be used).
9191        ///
9192        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
9193        #[cfg(js_sys_unstable_apis)]
9194        #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
9195        pub fn compile_streaming(response: &Promise) -> Promise<Module>;
9196
9197        /// The `WebAssembly.instantiate()` function allows you to compile and
9198        /// instantiate WebAssembly code.
9199        ///
9200        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
9201        #[cfg(not(js_sys_unstable_apis))]
9202        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
9203        pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<JsValue>;
9204
9205        /// The `WebAssembly.instantiate()` function allows you to compile and
9206        /// instantiate WebAssembly code.
9207        ///
9208        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
9209        #[cfg(js_sys_unstable_apis)]
9210        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
9211        pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<Instance>;
9212
9213        /// The `WebAssembly.instantiate()` function allows you to compile and
9214        /// instantiate WebAssembly code.
9215        ///
9216        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
9217        #[cfg(not(js_sys_unstable_apis))]
9218        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
9219        pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<JsValue>;
9220
9221        /// The `WebAssembly.instantiate()` function allows you to compile and
9222        /// instantiate WebAssembly code.
9223        ///
9224        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
9225        #[cfg(js_sys_unstable_apis)]
9226        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
9227        pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<Instance>;
9228
9229        /// The `WebAssembly.instantiateStreaming()` function compiles and
9230        /// instantiates a WebAssembly module directly from a streamed
9231        /// underlying source. This is the most efficient, optimized way to load
9232        /// Wasm code.
9233        ///
9234        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
9235        #[cfg(not(js_sys_unstable_apis))]
9236        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
9237        pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<JsValue>;
9238
9239        /// The `WebAssembly.instantiateStreaming()` function compiles and
9240        /// instantiates a WebAssembly module directly from a streamed
9241        /// underlying source. This is the most efficient, optimized way to load
9242        /// Wasm code.
9243        ///
9244        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
9245        #[cfg(js_sys_unstable_apis)]
9246        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
9247        pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<Instance>;
9248
9249        /// The `WebAssembly.validate()` function validates a given typed
9250        /// array of WebAssembly binary code, returning whether the bytes
9251        /// form a valid Wasm module (`true`) or not (`false`).
9252        ///
9253        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
9254        #[wasm_bindgen(js_namespace = WebAssembly, catch)]
9255        pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
9256
9257        /// The `WebAssembly.validate()` function validates the given bytes
9258        /// under the given compile options.
9259        ///
9260        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
9261        #[wasm_bindgen(js_namespace = WebAssembly, js_name = validate, catch)]
9262        pub fn validate_with_options(
9263            buffer_source: &JsValue,
9264            options: &CompileOptions,
9265        ) -> Result<bool, JsValue>;
9266
9267        /// The `WebAssembly.compile()` function compiles the given bytes
9268        /// under the given compile options.
9269        ///
9270        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
9271        #[wasm_bindgen(js_namespace = WebAssembly, js_name = compile)]
9272        pub fn compile_with_options(
9273            buffer_source: &JsValue,
9274            options: &CompileOptions,
9275        ) -> Promise<Module>;
9276
9277        /// The `WebAssembly.compileStreaming()` function compiles a module
9278        /// from a streamed `Response` under the given compile options.
9279        ///
9280        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
9281        #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
9282        pub fn compile_streaming_with_options(
9283            response: &Promise,
9284            options: &CompileOptions,
9285        ) -> Promise<Module>;
9286
9287        /// The `WebAssembly.instantiate()` function compiles and instantiates
9288        /// the given bytes under the given compile options, resolving to an
9289        /// [`InstantiatedSource`] holding both the module and the instance.
9290        ///
9291        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
9292        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
9293        pub fn instantiate_buffer_with_options(
9294            buffer: &[u8],
9295            imports: &Object,
9296            options: &CompileOptions,
9297        ) -> Promise<InstantiatedSource>;
9298
9299        /// The `WebAssembly.instantiateStreaming()` function compiles and
9300        /// instantiates a module from a streamed `Response` under the given
9301        /// compile options, resolving to an [`InstantiatedSource`].
9302        ///
9303        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
9304        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
9305        pub fn instantiate_streaming_with_options(
9306            response: &JsValue,
9307            imports: &Object,
9308            options: &CompileOptions,
9309        ) -> Promise<InstantiatedSource>;
9310
9311        /// The `WebAssembly.JSTag` property is the [`Tag`] under which
9312        /// JavaScript exceptions are thrown into and caught from Wasm code.
9313        ///
9314        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/JSTag)
9315        #[wasm_bindgen(thread_local_v2, js_namespace = WebAssembly, js_name = JSTag)]
9316        pub static JS_TAG: Tag;
9317    }
9318
9319    // WebAssembly.InstantiatedSource
9320    // CompileOptions
9321    #[wasm_bindgen]
9322    extern "C" {
9323        /// The compile options accepted by `WebAssembly.validate()`,
9324        /// `compile()`, `instantiate()`, their streaming forms and the
9325        /// `Module` constructor: the JS builtins to enable and the import
9326        /// module name for imported string constants.
9327        ///
9328        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile#compileoptions)
9329        #[wasm_bindgen(extends = Object)]
9330        #[derive(Clone, Debug)]
9331        pub type CompileOptions;
9332
9333        /// The enabled builtin sets, such as `"js-string"`, if set.
9334        #[wasm_bindgen(method, getter, js_name = builtins)]
9335        pub fn get_builtins(this: &CompileOptions) -> Option<Array<JsString>>;
9336        /// Sets the builtin sets to enable, such as `"js-string"`.
9337        #[wasm_bindgen(method, setter)]
9338        pub fn set_builtins(this: &CompileOptions, builtins: &[JsString]);
9339
9340        /// The import module name for imported string constants, if set.
9341        #[wasm_bindgen(method, getter, js_name = importedStringConstants)]
9342        pub fn get_imported_string_constants(this: &CompileOptions) -> Option<JsString>;
9343        /// Sets the import module name for imported string constants.
9344        #[wasm_bindgen(method, setter, js_name = importedStringConstants)]
9345        pub fn set_imported_string_constants(this: &CompileOptions, name: &str);
9346    }
9347
9348    impl CompileOptions {
9349        /// Creates empty `CompileOptions`.
9350        pub fn new() -> CompileOptions {
9351            JsCast::unchecked_into::<CompileOptions>(Object::<JsValue>::new())
9352        }
9353    }
9354
9355    impl Default for CompileOptions {
9356        fn default() -> Self {
9357            Self::new()
9358        }
9359    }
9360
9361    #[wasm_bindgen]
9362    extern "C" {
9363        /// The `{ module, instance }` pair that `WebAssembly.instantiate()`
9364        /// and `WebAssembly.instantiateStreaming()` resolve to when given
9365        /// bytes rather than a compiled `Module`.
9366        ///
9367        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate#return_value)
9368        #[wasm_bindgen(extends = Object, typescript_type = "WebAssembly.WebAssemblyInstantiatedSource")]
9369        #[derive(Clone, Debug, PartialEq, Eq)]
9370        pub type InstantiatedSource;
9371
9372        /// The compiled module.
9373        #[wasm_bindgen(method, getter)]
9374        pub fn module(this: &InstantiatedSource) -> Module;
9375
9376        /// The instance of that module.
9377        #[wasm_bindgen(method, getter)]
9378        pub fn instance(this: &InstantiatedSource) -> Instance;
9379    }
9380
9381    // WebAssembly.CompileError
9382    #[wasm_bindgen]
9383    extern "C" {
9384        /// The `WebAssembly.CompileError()` constructor creates a new
9385        /// WebAssembly `CompileError` object, which indicates an error during
9386        /// WebAssembly decoding or validation.
9387        ///
9388        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
9389        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
9390        #[derive(Clone, Debug, PartialEq, Eq)]
9391        pub type CompileError;
9392
9393        /// The `WebAssembly.CompileError()` constructor creates a new
9394        /// WebAssembly `CompileError` object, which indicates an error during
9395        /// WebAssembly decoding or validation.
9396        ///
9397        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
9398        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9399        pub fn new(message: &str) -> CompileError;
9400
9401        /// Creates a new `WebAssembly.CompileError` with the given message and
9402        /// a typed [`ErrorOptions`] dictionary whose `cause` property
9403        /// indicates the original cause of the error.
9404        ///
9405        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError/CompileError)
9406        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9407        pub fn new_with_options(message: &str, options: &ErrorOptions) -> CompileError;
9408    }
9409
9410    // WebAssembly.Instance
9411    #[wasm_bindgen]
9412    extern "C" {
9413        /// A `WebAssembly.Instance` object is a stateful, executable instance
9414        /// of a `WebAssembly.Module`. Instance objects contain all the exported
9415        /// WebAssembly functions that allow calling into WebAssembly code from
9416        /// JavaScript.
9417        ///
9418        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
9419        #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
9420        #[derive(Clone, Debug, PartialEq, Eq)]
9421        pub type Instance;
9422
9423        /// The `WebAssembly.Instance()` constructor function can be called to
9424        /// synchronously instantiate a given `WebAssembly.Module`
9425        /// object. However, the primary way to get an `Instance` is through the
9426        /// asynchronous `WebAssembly.instantiateStreaming()` function.
9427        ///
9428        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
9429        #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
9430        pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
9431
9432        /// The `exports` readonly property of the `WebAssembly.Instance` object
9433        /// prototype returns an object containing as its members all the
9434        /// functions exported from the WebAssembly module instance, to allow
9435        /// them to be accessed and used by JavaScript.
9436        ///
9437        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
9438        #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
9439        pub fn exports(this: &Instance) -> Object;
9440    }
9441
9442    // WebAssembly.LinkError
9443    #[wasm_bindgen]
9444    extern "C" {
9445        /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
9446        /// LinkError object, which indicates an error during module
9447        /// instantiation (besides traps from the start function).
9448        ///
9449        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
9450        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
9451        #[derive(Clone, Debug, PartialEq, Eq)]
9452        pub type LinkError;
9453
9454        /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
9455        /// LinkError object, which indicates an error during module
9456        /// instantiation (besides traps from the start function).
9457        ///
9458        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
9459        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9460        pub fn new(message: &str) -> LinkError;
9461
9462        /// Creates a new `WebAssembly.LinkError` with the given message and a
9463        /// typed [`ErrorOptions`] dictionary whose `cause` property indicates
9464        /// the original cause of the error.
9465        ///
9466        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError/LinkError)
9467        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9468        pub fn new_with_options(message: &str, options: &ErrorOptions) -> LinkError;
9469    }
9470
9471    // WebAssembly.RuntimeError
9472    #[wasm_bindgen]
9473    extern "C" {
9474        /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
9475        /// `RuntimeError` object — the type that is thrown whenever WebAssembly
9476        /// specifies a trap.
9477        ///
9478        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
9479        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
9480        #[derive(Clone, Debug, PartialEq, Eq)]
9481        pub type RuntimeError;
9482
9483        /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
9484        /// `RuntimeError` object — the type that is thrown whenever WebAssembly
9485        /// specifies a trap.
9486        ///
9487        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
9488        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9489        pub fn new(message: &str) -> RuntimeError;
9490
9491        /// Creates a new `WebAssembly.RuntimeError` with the given message
9492        /// and a typed [`ErrorOptions`] dictionary whose `cause` property
9493        /// indicates the original cause of the error.
9494        ///
9495        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError/RuntimeError)
9496        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9497        pub fn new_with_options(message: &str, options: &ErrorOptions) -> RuntimeError;
9498    }
9499
9500    // WebAssembly.Module
9501    #[wasm_bindgen]
9502    extern "C" {
9503        /// A `WebAssembly.Module` object contains stateless WebAssembly code
9504        /// that has already been compiled by the browser and can be
9505        /// efficiently shared with Workers, and instantiated multiple times.
9506        ///
9507        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
9508        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
9509        #[derive(Clone, Debug, PartialEq, Eq)]
9510        pub type Module;
9511
9512        /// A `WebAssembly.Module` object contains stateless WebAssembly code
9513        /// that has already been compiled by the browser and can be
9514        /// efficiently shared with Workers, and instantiated multiple times.
9515        ///
9516        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
9517        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9518        pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
9519
9520        /// The `WebAssembly.Module()` constructor compiles the given bytes
9521        /// synchronously under the given compile options.
9522        ///
9523        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/Module)
9524        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9525        pub fn new_with_options(
9526            buffer_source: &JsValue,
9527            options: &CompileOptions,
9528        ) -> Result<Module, JsValue>;
9529
9530        /// The `WebAssembly.customSections()` function returns a copy of the
9531        /// contents of all custom sections in the given module with the given
9532        /// string name.
9533        ///
9534        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
9535        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
9536        pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
9537
9538        /// The `WebAssembly.exports()` function returns an array containing
9539        /// descriptions of all the declared exports of the given `Module`.
9540        ///
9541        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
9542        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
9543        pub fn exports(module: &Module) -> Array;
9544
9545        /// The `WebAssembly.imports()` function returns an array containing
9546        /// descriptions of all the declared imports of the given `Module`.
9547        ///
9548        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
9549        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
9550        pub fn imports(module: &Module) -> Array;
9551    }
9552
9553    // WebAssembly.Table
9554    #[wasm_bindgen]
9555    extern "C" {
9556        /// The `WebAssembly.Table()` constructor creates a new `Table` object
9557        /// of the given size and element type.
9558        ///
9559        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
9560        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
9561        #[derive(Clone, Debug, PartialEq, Eq)]
9562        pub type Table;
9563
9564        /// The `WebAssembly.Table()` constructor creates a new `Table` object
9565        /// of the given size and element type.
9566        ///
9567        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
9568        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9569        pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
9570
9571        /// The `WebAssembly.Table()` constructor creates a new `Table` object
9572        /// of the given size and element type.
9573        ///
9574        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
9575        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9576        pub fn new_with_value(table_descriptor: &Object, value: JsValue) -> Result<Table, JsValue>;
9577
9578        /// The length prototype property of the `WebAssembly.Table` object
9579        /// returns the length of the table, i.e. the number of elements in the
9580        /// table.
9581        ///
9582        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
9583        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
9584        pub fn length(this: &Table) -> u32;
9585
9586        /// The `get()` prototype method of the `WebAssembly.Table()` object
9587        /// retrieves a function reference stored at a given index.
9588        ///
9589        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
9590        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
9591        pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
9592
9593        /// The `get()` prototype method of the `WebAssembly.Table()` object
9594        /// retrieves a function reference stored at a given index.
9595        ///
9596        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
9597        #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = get)]
9598        pub fn get_raw(this: &Table, index: u32) -> Result<JsValue, JsValue>;
9599
9600        /// The `grow()` prototype method of the `WebAssembly.Table` object
9601        /// increases the size of the `Table` instance by a specified number of
9602        /// elements.
9603        ///
9604        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
9605        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
9606        pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
9607
9608        /// The `grow()` prototype method of the `WebAssembly.Table` object
9609        /// increases the size of the `Table` instance by a specified number of
9610        /// elements.
9611        ///
9612        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
9613        #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = grow)]
9614        pub fn grow_with_value(
9615            this: &Table,
9616            additional_capacity: u32,
9617            value: JsValue,
9618        ) -> Result<u32, JsValue>;
9619
9620        /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
9621        /// reference stored at a given index to a different value.
9622        ///
9623        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
9624        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
9625        pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
9626
9627        /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
9628        /// reference stored at a given index to a different value.
9629        ///
9630        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
9631        #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = set)]
9632        pub fn set_raw(this: &Table, index: u32, value: &JsValue) -> Result<(), JsValue>;
9633    }
9634
9635    // WebAssembly.Tag
9636    #[wasm_bindgen]
9637    extern "C" {
9638        /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
9639        ///
9640        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
9641        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
9642        #[derive(Clone, Debug, PartialEq, Eq)]
9643        pub type Tag;
9644
9645        /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
9646        ///
9647        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
9648        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9649        pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
9650    }
9651
9652    // WebAssembly.Exception
9653    #[wasm_bindgen]
9654    extern "C" {
9655        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
9656        ///
9657        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
9658        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
9659        #[derive(Clone, Debug, PartialEq, Eq)]
9660        pub type Exception;
9661
9662        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
9663        ///
9664        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
9665        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9666        pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
9667
9668        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
9669        ///
9670        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
9671        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9672        pub fn new_with_options(
9673            tag: &Tag,
9674            payload: &Array,
9675            options: &Object,
9676        ) -> Result<Exception, JsValue>;
9677
9678        /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
9679        /// test if the Exception matches a given tag.
9680        ///
9681        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
9682        #[wasm_bindgen(method, js_namespace = WebAssembly)]
9683        pub fn is(this: &Exception, tag: &Tag) -> bool;
9684
9685        /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
9686        /// to get the value of a specified item in the exception's data arguments
9687        ///
9688        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
9689        #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
9690        pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
9691
9692        /// The `stack` property holds a stack trace when the exception was
9693        /// created with `{ traceStack: true }`, and is `undefined`
9694        /// otherwise.
9695        ///
9696        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/stack)
9697        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
9698        pub fn stack(this: &Exception) -> Option<JsString>;
9699    }
9700
9701    // WebAssembly.Global
9702    #[wasm_bindgen]
9703    extern "C" {
9704        /// The `WebAssembly.Global()` constructor creates a new `Global` object
9705        /// of the given type and value.
9706        ///
9707        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
9708        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
9709        #[derive(Clone, Debug, PartialEq, Eq)]
9710        pub type Global;
9711
9712        /// The `WebAssembly.Global()` constructor creates a new `Global` object
9713        /// of the given type and value.
9714        ///
9715        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
9716        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9717        pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
9718
9719        /// The value prototype property of the `WebAssembly.Global` object
9720        /// returns the value of the global.
9721        ///
9722        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
9723        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
9724        pub fn value(this: &Global) -> JsValue;
9725        #[wasm_bindgen(method, setter = value, js_namespace = WebAssembly)]
9726        pub fn set_value(this: &Global, value: &JsValue);
9727
9728        /// The `valueOf()` method returns the global's current value.
9729        ///
9730        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/valueOf)
9731        #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = valueOf)]
9732        pub fn value_of(this: &Global) -> JsValue;
9733    }
9734
9735    // WebAssembly.Memory
9736    #[wasm_bindgen]
9737    extern "C" {
9738        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
9739        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
9740        #[derive(Clone, Debug, PartialEq, Eq)]
9741        pub type Memory;
9742
9743        /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
9744        /// which is a resizable `ArrayBuffer` that holds the raw bytes of
9745        /// memory accessed by a WebAssembly `Instance`.
9746        ///
9747        /// A memory created by JavaScript or in WebAssembly code will be
9748        /// accessible and mutable from both JavaScript and WebAssembly.
9749        ///
9750        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
9751        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9752        pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
9753
9754        /// An accessor property that returns the buffer contained in the
9755        /// memory.
9756        ///
9757        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
9758        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
9759        pub fn buffer(this: &Memory) -> JsValue;
9760
9761        /// The `grow()` prototype method of the `Memory` object increases the
9762        /// size of the memory instance by a specified number of WebAssembly
9763        /// pages.
9764        ///
9765        /// Takes the number of pages to grow (64KiB in size) and returns the
9766        /// previous size of memory, in pages.
9767        ///
9768        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
9769        #[wasm_bindgen(method, js_namespace = WebAssembly)]
9770        pub fn grow(this: &Memory, pages: u32) -> u32;
9771
9772        /// The `toResizableBuffer()` method makes `buffer` a resizable
9773        /// `ArrayBuffer` (or growable `SharedArrayBuffer`) that tracks the
9774        /// memory as it grows, and returns it. Throws a `TypeError` if the
9775        /// memory has no maximum size.
9776        ///
9777        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/toResizableBuffer)
9778        #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = toResizableBuffer, catch)]
9779        pub fn to_resizable_buffer(this: &Memory) -> Result<JsValue, JsValue>;
9780
9781        /// The `toFixedLengthBuffer()` method makes `buffer` a fixed-length
9782        /// `ArrayBuffer` (or `SharedArrayBuffer`) again, detaching the
9783        /// previous one, and returns it.
9784        ///
9785        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/toFixedLengthBuffer)
9786        #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = toFixedLengthBuffer, catch)]
9787        pub fn to_fixed_length_buffer(this: &Memory) -> Result<JsValue, JsValue>;
9788    }
9789
9790    // WebAssembly.Suspending / WebAssembly.promising (JSPI — JS Promise Integration)
9791    #[wasm_bindgen]
9792    extern "C" {
9793        /// A `WebAssembly.Suspending` object wraps a JavaScript async function
9794        /// so it can be used as a WebAssembly import under
9795        /// [JSPI (JS Promise Integration)][jspi].
9796        ///
9797        /// When WASM calls a `Suspending`-wrapped import that returns a
9798        /// `Promise`, the WASM fiber suspends until the promise settles; the
9799        /// resolved value is then returned to WASM as if the call had returned
9800        /// synchronously.  The browser's event loop is **not** blocked.
9801        ///
9802        /// [jspi]: https://github.com/WebAssembly/js-promise-integration
9803        ///
9804        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Suspending)
9805        #[wasm_bindgen(
9806            js_namespace = WebAssembly,
9807            extends = Object,
9808            typescript_type = "WebAssembly.Suspending"
9809        )]
9810        #[derive(Clone, Debug, PartialEq, Eq)]
9811        pub type Suspending;
9812
9813        /// Wraps `func` (an async function) in a `WebAssembly.Suspending` object.
9814        ///
9815        /// Pass the returned object as a WASM import.  Every call to that
9816        /// import from WASM will suspend the current fiber and resume it with
9817        /// the resolved value once `func`'s returned `Promise` settles.
9818        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9819        pub fn new(func: &Function) -> Suspending;
9820
9821        /// Wraps a WebAssembly exported `Function` so that calling it returns a
9822        /// `Promise` and enables JSPI suspension inside.
9823        ///
9824        /// Use `WebAssembly.promising` to obtain a "promising" wrapper around a
9825        /// raw WASM export; any JSPI suspensions that occur while the function
9826        /// executes will resolve the returned `Promise` when the fiber finishes.
9827        ///
9828        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/promising)
9829        #[wasm_bindgen(js_namespace = WebAssembly)]
9830        pub fn promising(func: &Function) -> Function;
9831    }
9832}
9833
9834/// The `JSON` object contains methods for parsing [JavaScript Object
9835/// Notation (JSON)](https://json.org/) and converting values to JSON. It
9836/// can't be called or constructed, and aside from its two method
9837/// properties, it has no interesting functionality of its own.
9838#[allow(non_snake_case)]
9839pub mod JSON {
9840    use super::*;
9841
9842    // JSON
9843    #[wasm_bindgen]
9844    extern "C" {
9845        /// The `JSON.parse()` method parses a JSON string, constructing the
9846        /// JavaScript value or object described by the string.
9847        ///
9848        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
9849        #[wasm_bindgen(catch, js_namespace = JSON)]
9850        pub fn parse(text: &str) -> Result<JsValue, JsValue>;
9851
9852        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9853        ///
9854        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9855        #[wasm_bindgen(catch, js_namespace = JSON)]
9856        pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
9857
9858        /// The `JSON.rawJSON()` method creates a raw JSON object whose text
9859        /// is emitted verbatim by `JSON.stringify()`, allowing values such
9860        /// as large integers to round-trip without precision loss. Throws
9861        /// a `SyntaxError` unless `text` is valid JSON for a primitive.
9862        ///
9863        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/rawJSON)
9864        #[wasm_bindgen(catch, js_namespace = JSON, js_name = rawJSON)]
9865        pub fn raw_json(text: &str) -> Result<Object, JsValue>;
9866
9867        /// The `JSON.isRawJSON()` method returns whether a value is a raw
9868        /// JSON object created by `JSON.rawJSON()`.
9869        ///
9870        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/isRawJSON)
9871        #[wasm_bindgen(js_namespace = JSON, js_name = isRawJSON)]
9872        pub fn is_raw_json(value: &JsValue) -> bool;
9873
9874        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9875        ///
9876        /// The `replacer` argument is a function that alters the behavior of the stringification
9877        /// process, or an array of String and Number objects that serve as a whitelist
9878        /// for selecting/filtering the properties of the value object to be included
9879        /// in the JSON string. If this value is null or not provided, all properties
9880        /// of the object are included in the resulting JSON string.
9881        ///
9882        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9883        #[cfg(not(js_sys_unstable_apis))]
9884        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9885        pub fn stringify_with_replacer(
9886            obj: &JsValue,
9887            replacer: &JsValue,
9888        ) -> Result<JsString, JsValue>;
9889
9890        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9891        ///
9892        /// The `replacer` argument is a function that alters the behavior of the stringification
9893        /// process, or an array of String and Number objects that serve as a whitelist
9894        /// for selecting/filtering the properties of the value object to be included
9895        /// in the JSON string. If this value is null or not provided, all properties
9896        /// of the object are included in the resulting JSON string.
9897        ///
9898        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9899        #[cfg(js_sys_unstable_apis)]
9900        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9901        pub fn stringify_with_replacer<'a>(
9902            obj: &JsValue,
9903            replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
9904            space: Option<u32>,
9905        ) -> Result<JsString, JsValue>;
9906
9907        // Next major: deprecate
9908        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9909        ///
9910        /// The `replacer` argument is a function that alters the behavior of the stringification
9911        /// process, or an array of String and Number objects that serve as a whitelist
9912        /// for selecting/filtering the properties of the value object to be included
9913        /// in the JSON string. If this value is null or not provided, all properties
9914        /// of the object are included in the resulting JSON string.
9915        ///
9916        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9917        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9918        pub fn stringify_with_replacer_func<'a>(
9919            obj: &JsValue,
9920            replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
9921            space: Option<u32>,
9922        ) -> Result<JsString, JsValue>;
9923
9924        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9925        ///
9926        /// The `replacer` argument is a function that alters the behavior of the stringification
9927        /// process, or an array of String and Number objects that serve as a whitelist
9928        /// for selecting/filtering the properties of the value object to be included
9929        /// in the JSON string. If this value is null or not provided, all properties
9930        /// of the object are included in the resulting JSON string.
9931        ///
9932        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9933        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9934        pub fn stringify_with_replacer_list(
9935            obj: &JsValue,
9936            replacer: Vec<String>,
9937            space: Option<u32>,
9938        ) -> Result<JsString, JsValue>;
9939
9940        // Next major: deprecate
9941        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9942        ///
9943        /// The `replacer` argument is a function that alters the behavior of the stringification
9944        /// process, or an array of String and Number objects that serve as a whitelist
9945        /// for selecting/filtering the properties of the value object to be included
9946        /// in the JSON string. If this value is null or not provided, all properties
9947        /// of the object are included in the resulting JSON string.
9948        ///
9949        /// The `space` argument is a String or Number object that's used to insert white space into
9950        /// the output JSON string for readability purposes. If this is a Number, it
9951        /// indicates the number of space characters to use as white space; this number
9952        /// is capped at 10 (if it is greater, the value is just 10). Values less than
9953        /// 1 indicate that no space should be used. If this is a String, the string
9954        /// (or the first 10 characters of the string, if it's longer than that) is
9955        /// used as white space. If this parameter is not provided (or is null), no
9956        /// white space is used.
9957        ///
9958        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9959        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9960        pub fn stringify_with_replacer_and_space(
9961            obj: &JsValue,
9962            replacer: &JsValue,
9963            space: &JsValue,
9964        ) -> Result<JsString, JsValue>;
9965    }
9966}
9967// JsString
9968#[wasm_bindgen]
9969extern "C" {
9970    #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
9971    #[derive(Clone, PartialEq, Eq)]
9972    pub type JsString;
9973
9974    /// The length property of a String object indicates the length of a string,
9975    /// in UTF-16 code units.
9976    ///
9977    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
9978    #[wasm_bindgen(method, getter)]
9979    pub fn length(this: &JsString) -> u32;
9980
9981    /// The 'at()' method returns a new string consisting of the single UTF-16
9982    /// code unit located at the specified offset into the string, counting from
9983    /// the end if it's negative.
9984    ///
9985    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
9986    #[wasm_bindgen(method, js_class = "String")]
9987    pub fn at(this: &JsString, index: i32) -> Option<JsString>;
9988
9989    /// The String object's `charAt()` method returns a new string consisting of
9990    /// the single UTF-16 code unit located at the specified offset into the
9991    /// string.
9992    ///
9993    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
9994    #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
9995    pub fn char_at(this: &JsString, index: u32) -> JsString;
9996
9997    /// The `charCodeAt()` method returns an integer between 0 and 65535
9998    /// representing the UTF-16 code unit at the given index (the UTF-16 code
9999    /// unit matches the Unicode code point for code points representable in a
10000    /// single UTF-16 code unit, but might also be the first code unit of a
10001    /// surrogate pair for code points not representable in a single UTF-16 code
10002    /// unit, e.g. Unicode code points > 0x10000).  If you want the entire code
10003    /// point value, use `codePointAt()`.
10004    ///
10005    /// Returns `NaN` if index is out of range.
10006    ///
10007    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
10008    #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
10009    pub fn char_code_at(this: &JsString, index: u32) -> f64;
10010
10011    /// The `codePointAt()` method returns a non-negative integer that is the
10012    /// Unicode code point value.
10013    ///
10014    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
10015    #[cfg(not(js_sys_unstable_apis))]
10016    #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
10017    pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
10018
10019    /// The `codePointAt()` method returns a non-negative integer that is the
10020    /// Unicode code point value.
10021    ///
10022    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
10023    #[cfg(js_sys_unstable_apis)]
10024    #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
10025    pub fn code_point_at(this: &JsString, pos: u32) -> Option<u32>;
10026
10027    // Next major: deprecate
10028    /// The `codePointAt()` method returns a non-negative integer that is the
10029    /// Unicode code point value.
10030    ///
10031    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
10032    #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
10033    pub fn try_code_point_at(this: &JsString, pos: u32) -> Option<u16>;
10034
10035    /// The `concat()` method concatenates the string arguments to the calling
10036    /// string and returns a new string.
10037    ///
10038    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
10039    #[cfg(not(js_sys_unstable_apis))]
10040    #[wasm_bindgen(method, js_class = "String")]
10041    pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
10042
10043    /// The `concat()` method concatenates the string arguments to the calling
10044    /// string and returns a new string.
10045    ///
10046    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
10047    #[cfg(js_sys_unstable_apis)]
10048    #[wasm_bindgen(method, js_class = "String")]
10049    pub fn concat(this: &JsString, string: &JsString) -> JsString;
10050
10051    /// The `concat()` method concatenates the string arguments to the calling
10052    /// string and returns a new string.
10053    ///
10054    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
10055    #[wasm_bindgen(method, js_class = "String")]
10056    pub fn concat_many(this: &JsString, strings: &[JsString]) -> JsString;
10057
10058    /// The `endsWith()` method determines whether a string ends with the characters of a
10059    /// specified string, returning true or false as appropriate.
10060    ///
10061    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
10062    #[cfg(not(js_sys_unstable_apis))]
10063    #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
10064    pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
10065
10066    /// The `endsWith()` method determines whether a string ends with the characters of a
10067    /// specified string, returning true or false as appropriate.
10068    ///
10069    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
10070    #[cfg(js_sys_unstable_apis)]
10071    #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
10072    pub fn ends_with(this: &JsString, search_string: &str) -> bool;
10073
10074    /// The static `String.fromCharCode()` method returns a string created from
10075    /// the specified sequence of UTF-16 code units.
10076    ///
10077    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10078    ///
10079    /// # Notes
10080    ///
10081    /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
10082    /// with different arities.
10083    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
10084    pub fn from_char_code(char_codes: &[u16]) -> JsString;
10085
10086    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10087    #[cfg(not(js_sys_unstable_apis))]
10088    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10089    pub fn from_char_code1(a: u32) -> JsString;
10090
10091    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10092    #[cfg(js_sys_unstable_apis)]
10093    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10094    pub fn from_char_code1(a: u16) -> JsString;
10095
10096    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10097    #[cfg(not(js_sys_unstable_apis))]
10098    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10099    pub fn from_char_code2(a: u32, b: u32) -> JsString;
10100
10101    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10102    #[cfg(js_sys_unstable_apis)]
10103    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10104    pub fn from_char_code2(a: u16, b: u16) -> JsString;
10105
10106    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10107    #[cfg(not(js_sys_unstable_apis))]
10108    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10109    pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
10110
10111    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10112    #[cfg(js_sys_unstable_apis)]
10113    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10114    pub fn from_char_code3(a: u16, b: u16, c: u16) -> JsString;
10115
10116    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10117    #[cfg(not(js_sys_unstable_apis))]
10118    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10119    pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
10120
10121    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10122    #[cfg(js_sys_unstable_apis)]
10123    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10124    pub fn from_char_code4(a: u16, b: u16, c: u16, d: u16) -> JsString;
10125
10126    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10127    #[cfg(not(js_sys_unstable_apis))]
10128    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10129    pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
10130
10131    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10132    #[cfg(js_sys_unstable_apis)]
10133    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10134    pub fn from_char_code5(a: u16, b: u16, c: u16, d: u16, e: u16) -> JsString;
10135
10136    /// The static `String.fromCodePoint()` method returns a string created by
10137    /// using the specified sequence of code points.
10138    ///
10139    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
10140    ///
10141    /// # Exceptions
10142    ///
10143    /// A RangeError is thrown if an invalid Unicode code point is given
10144    ///
10145    /// # Notes
10146    ///
10147    /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
10148    /// with different arities.
10149    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
10150    pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
10151
10152    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
10153    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
10154    pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
10155
10156    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
10157    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
10158    pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
10159
10160    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
10161    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
10162    pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
10163
10164    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
10165    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
10166    pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
10167
10168    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
10169    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
10170    pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
10171
10172    /// The `includes()` method determines whether one string may be found
10173    /// within another string, returning true or false as appropriate.
10174    ///
10175    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
10176    #[wasm_bindgen(method, js_class = "String")]
10177    pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
10178
10179    /// The `indexOf()` method returns the index within the calling String
10180    /// object of the first occurrence of the specified value, starting the
10181    /// search at fromIndex.  Returns -1 if the value is not found.
10182    ///
10183    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
10184    #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
10185    pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
10186
10187    /// The `lastIndexOf()` method returns the index within the calling String
10188    /// object of the last occurrence of the specified value, searching
10189    /// backwards from fromIndex.  Returns -1 if the value is not found.
10190    ///
10191    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
10192    #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
10193    pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
10194
10195    /// The `localeCompare()` method returns a number indicating whether
10196    /// a reference string comes before or after or is the same as
10197    /// the given string in sort order.
10198    ///
10199    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
10200    #[cfg(not(js_sys_unstable_apis))]
10201    #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
10202    pub fn locale_compare(
10203        this: &JsString,
10204        compare_string: &str,
10205        locales: &Array,
10206        options: &Object,
10207    ) -> i32;
10208
10209    /// The `localeCompare()` method returns a number indicating whether
10210    /// a reference string comes before or after or is the same as
10211    /// the given string in sort order.
10212    ///
10213    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
10214    #[cfg(js_sys_unstable_apis)]
10215    #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
10216    pub fn locale_compare(
10217        this: &JsString,
10218        compare_string: &str,
10219        locales: &[JsString],
10220        options: &Intl::CollatorOptions,
10221    ) -> i32;
10222
10223    /// The `match()` method retrieves the matches when matching a string against a regular expression.
10224    /// Returns a result array, or null.
10225    ///
10226    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
10227    #[cfg(not(js_sys_unstable_apis))]
10228    #[wasm_bindgen(method, js_class = "String", js_name = match)]
10229    pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
10230    /// The `match()` method retrieves the matches when matching a string against a regular expression.
10231    /// Returns a result array, or null.
10232    ///
10233    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
10234    #[cfg(js_sys_unstable_apis)]
10235    #[wasm_bindgen(method, js_class = "String", js_name = match)]
10236    pub fn match_(this: &JsString, pattern: &RegExp) -> Nullable<Object>;
10237
10238    /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
10239    ///
10240    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
10241    #[cfg(not(js_sys_unstable_apis))]
10242    #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
10243    pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
10244
10245    /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
10246    ///
10247    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
10248    #[cfg(js_sys_unstable_apis)]
10249    #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
10250    pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator<RegExpMatchArray>;
10251
10252    /// The `normalize()` method returns the Unicode Normalization Form
10253    /// of a given string (if the value isn't a string, it will be converted to one first).
10254    ///
10255    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
10256    #[wasm_bindgen(method, js_class = "String")]
10257    pub fn normalize(this: &JsString, form: &str) -> JsString;
10258
10259    /// The `padEnd()` method pads the current string with a given string
10260    /// (repeated, if needed) so that the resulting string reaches a given
10261    /// length. The padding is applied from the end (right) of the current
10262    /// string.
10263    ///
10264    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
10265    #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
10266    pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
10267
10268    /// The `padStart()` method pads the current string with another string
10269    /// (repeated, if needed) so that the resulting string reaches the given
10270    /// length. The padding is applied from the start (left) of the current
10271    /// string.
10272    ///
10273    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
10274    #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
10275    pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
10276
10277    /// The `repeat()` method constructs and returns a new string which contains the specified
10278    /// number of copies of the string on which it was called, concatenated together.
10279    ///
10280    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
10281    #[wasm_bindgen(method, js_class = "String")]
10282    pub fn repeat(this: &JsString, count: i32) -> JsString;
10283
10284    /// The `replace()` method returns a new string with some or all matches of a pattern
10285    /// replaced by a replacement. The pattern can be a string or a RegExp, and
10286    /// the replacement can be a string or a function to be called for each match.
10287    ///
10288    /// Note: The original string will remain unchanged.
10289    ///
10290    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
10291    #[wasm_bindgen(method, js_class = "String")]
10292    pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
10293
10294    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
10295    #[cfg(not(js_sys_unstable_apis))]
10296    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
10297    pub fn replace_with_function(
10298        this: &JsString,
10299        pattern: &str,
10300        replacement: &Function,
10301    ) -> JsString;
10302
10303    /// The replacer function signature is `(match, offset, string) -> replacement`
10304    /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
10305    /// when capture groups are present.
10306    ///
10307    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
10308    #[cfg(js_sys_unstable_apis)]
10309    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
10310    pub fn replace_with_function(
10311        this: &JsString,
10312        pattern: &str,
10313        replacement: &Function<fn(JsString) -> JsString>,
10314    ) -> JsString;
10315
10316    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
10317    pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
10318
10319    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
10320    #[cfg(not(js_sys_unstable_apis))]
10321    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
10322    pub fn replace_by_pattern_with_function(
10323        this: &JsString,
10324        pattern: &RegExp,
10325        replacement: &Function,
10326    ) -> JsString;
10327
10328    /// The replacer function signature is `(match, offset, string) -> replacement`
10329    /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
10330    /// when capture groups are present.
10331    ///
10332    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
10333    #[cfg(js_sys_unstable_apis)]
10334    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
10335    pub fn replace_by_pattern_with_function(
10336        this: &JsString,
10337        pattern: &RegExp,
10338        replacement: &Function<fn(JsString) -> JsString>,
10339    ) -> JsString;
10340
10341    /// The `replace_all()` method returns a new string with all matches of a pattern
10342    /// replaced by a replacement. The pattern can be a string or a global RegExp, and
10343    /// the replacement can be a string or a function to be called for each match.
10344    ///
10345    /// Note: The original string will remain unchanged.
10346    ///
10347    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
10348    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
10349    pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
10350
10351    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
10352    #[cfg(not(js_sys_unstable_apis))]
10353    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
10354    pub fn replace_all_with_function(
10355        this: &JsString,
10356        pattern: &str,
10357        replacement: &Function,
10358    ) -> JsString;
10359
10360    /// The replacer function signature is `(match, offset, string) -> replacement`
10361    /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
10362    /// when capture groups are present.
10363    ///
10364    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
10365    #[cfg(js_sys_unstable_apis)]
10366    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
10367    pub fn replace_all_with_function(
10368        this: &JsString,
10369        pattern: &str,
10370        replacement: &Function<fn(JsString) -> JsString>,
10371    ) -> JsString;
10372
10373    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
10374    pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
10375        -> JsString;
10376
10377    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
10378    #[cfg(not(js_sys_unstable_apis))]
10379    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
10380    pub fn replace_all_by_pattern_with_function(
10381        this: &JsString,
10382        pattern: &RegExp,
10383        replacement: &Function,
10384    ) -> JsString;
10385
10386    /// The replacer function signature is `(match, offset, string) -> replacement`
10387    /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
10388    /// when capture groups are present.
10389    ///
10390    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
10391    #[cfg(js_sys_unstable_apis)]
10392    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
10393    pub fn replace_all_by_pattern_with_function(
10394        this: &JsString,
10395        pattern: &RegExp,
10396        replacement: &Function<fn(JsString) -> JsString>,
10397    ) -> JsString;
10398
10399    /// The `search()` method executes a search for a match between
10400    /// a regular expression and this String object.
10401    ///
10402    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
10403    #[wasm_bindgen(method, js_class = "String")]
10404    pub fn search(this: &JsString, pattern: &RegExp) -> i32;
10405
10406    /// The `slice()` method extracts a section of a string and returns it as a
10407    /// new string, without modifying the original string.
10408    ///
10409    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
10410    #[wasm_bindgen(method, js_class = "String")]
10411    pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
10412
10413    /// The `split()` method splits a String object into an array of strings by separating the string
10414    /// into substrings, using a specified separator string to determine where to make each split.
10415    ///
10416    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
10417    #[wasm_bindgen(method, js_class = "String")]
10418    pub fn split(this: &JsString, separator: &str) -> Array;
10419
10420    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
10421    #[wasm_bindgen(method, js_class = "String", js_name = split)]
10422    pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
10423
10424    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
10425    #[wasm_bindgen(method, js_class = "String", js_name = split)]
10426    pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
10427
10428    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
10429    #[wasm_bindgen(method, js_class = "String", js_name = split)]
10430    pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
10431
10432    /// The `startsWith()` method determines whether a string begins with the
10433    /// characters of a specified string, returning true or false as
10434    /// appropriate.
10435    ///
10436    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
10437    #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
10438    pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
10439
10440    /// The `substring()` method returns the part of the string between the
10441    /// start and end indexes, or to the end of the string.
10442    ///
10443    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
10444    #[wasm_bindgen(method, js_class = "String")]
10445    pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
10446
10447    /// The `substr()` method returns the part of a string between
10448    /// the start index and a number of characters after it.
10449    ///
10450    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
10451    #[wasm_bindgen(method, js_class = "String")]
10452    pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
10453
10454    /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
10455    /// according to any locale-specific case mappings.
10456    ///
10457    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
10458    #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
10459    pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
10460
10461    /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
10462    /// according to any locale-specific case mappings.
10463    ///
10464    /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
10465    #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
10466    pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
10467
10468    /// The `toLowerCase()` method returns the calling string value
10469    /// converted to lower case.
10470    ///
10471    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
10472    #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
10473    pub fn to_lower_case(this: &JsString) -> JsString;
10474
10475    /// The `toString()` method returns a string representing the specified
10476    /// object.
10477    ///
10478    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
10479    #[cfg(not(js_sys_unstable_apis))]
10480    #[wasm_bindgen(method, js_class = "String", js_name = toString)]
10481    pub fn to_string(this: &JsString) -> JsString;
10482
10483    /// The `toUpperCase()` method returns the calling string value converted to
10484    /// uppercase (the value will be converted to a string if it isn't one).
10485    ///
10486    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
10487    #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
10488    pub fn to_upper_case(this: &JsString) -> JsString;
10489
10490    /// The `trim()` method removes whitespace from both ends of a string.
10491    /// Whitespace in this context is all the whitespace characters (space, tab,
10492    /// no-break space, etc.) and all the line terminator characters (LF, CR,
10493    /// etc.).
10494    ///
10495    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
10496    #[wasm_bindgen(method, js_class = "String")]
10497    pub fn trim(this: &JsString) -> JsString;
10498
10499    /// The `isWellFormed()` method returns whether this string contains no
10500    /// lone surrogates.
10501    ///
10502    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/isWellFormed)
10503    #[wasm_bindgen(method, js_class = "String", js_name = isWellFormed)]
10504    pub fn is_well_formed(this: &JsString) -> bool;
10505
10506    /// The `toWellFormed()` method returns a copy of this string with every
10507    /// lone surrogate replaced by U+FFFD.
10508    ///
10509    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toWellFormed)
10510    #[wasm_bindgen(method, js_class = "String", js_name = toWellFormed)]
10511    pub fn to_well_formed(this: &JsString) -> JsString;
10512
10513    /// The `trimEnd()` method removes whitespace from the end of a string.
10514    /// `trimRight()` is an alias of this method.
10515    ///
10516    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
10517    #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
10518    pub fn trim_end(this: &JsString) -> JsString;
10519
10520    /// The `trimEnd()` method removes whitespace from the end of a string.
10521    /// `trimRight()` is an alias of this method.
10522    ///
10523    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
10524    #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
10525    pub fn trim_right(this: &JsString) -> JsString;
10526
10527    /// The `trimStart()` method removes whitespace from the beginning of a
10528    /// string. `trimLeft()` is an alias of this method.
10529    ///
10530    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
10531    #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
10532    pub fn trim_start(this: &JsString) -> JsString;
10533
10534    /// The `trimStart()` method removes whitespace from the beginning of a
10535    /// string. `trimLeft()` is an alias of this method.
10536    ///
10537    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
10538    #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
10539    pub fn trim_left(this: &JsString) -> JsString;
10540
10541    /// The `valueOf()` method returns the primitive value of a `String` object.
10542    ///
10543    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
10544    #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
10545    pub fn value_of(this: &JsString) -> JsString;
10546
10547    /// The static `raw()` method is a tag function of template literals,
10548    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10549    ///
10550    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10551    #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
10552    pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
10553
10554    /// The static `raw()` method is a tag function of template literals,
10555    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10556    ///
10557    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10558    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10559    pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
10560
10561    /// The static `raw()` method is a tag function of template literals,
10562    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10563    ///
10564    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10565    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10566    pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
10567
10568    /// The static `raw()` method is a tag function of template literals,
10569    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10570    ///
10571    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10572    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10573    pub fn raw_2(
10574        call_site: &Object,
10575        substitutions1: &str,
10576        substitutions2: &str,
10577    ) -> Result<JsString, JsValue>;
10578
10579    /// The static `raw()` method is a tag function of template literals,
10580    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10581    ///
10582    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10583    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10584    pub fn raw_3(
10585        call_site: &Object,
10586        substitutions1: &str,
10587        substitutions2: &str,
10588        substitutions3: &str,
10589    ) -> Result<JsString, JsValue>;
10590
10591    /// The static `raw()` method is a tag function of template literals,
10592    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10593    ///
10594    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10595    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10596    pub fn raw_4(
10597        call_site: &Object,
10598        substitutions1: &str,
10599        substitutions2: &str,
10600        substitutions3: &str,
10601        substitutions4: &str,
10602    ) -> Result<JsString, JsValue>;
10603
10604    /// The static `raw()` method is a tag function of template literals,
10605    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10606    ///
10607    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10608    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10609    pub fn raw_5(
10610        call_site: &Object,
10611        substitutions1: &str,
10612        substitutions2: &str,
10613        substitutions3: &str,
10614        substitutions4: &str,
10615        substitutions5: &str,
10616    ) -> Result<JsString, JsValue>;
10617
10618    /// The static `raw()` method is a tag function of template literals,
10619    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10620    ///
10621    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10622    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10623    pub fn raw_6(
10624        call_site: &Object,
10625        substitutions1: &str,
10626        substitutions2: &str,
10627        substitutions3: &str,
10628        substitutions4: &str,
10629        substitutions5: &str,
10630        substitutions6: &str,
10631    ) -> Result<JsString, JsValue>;
10632
10633    /// The static `raw()` method is a tag function of template literals,
10634    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10635    ///
10636    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10637    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10638    pub fn raw_7(
10639        call_site: &Object,
10640        substitutions1: &str,
10641        substitutions2: &str,
10642        substitutions3: &str,
10643        substitutions4: &str,
10644        substitutions5: &str,
10645        substitutions6: &str,
10646        substitutions7: &str,
10647    ) -> Result<JsString, JsValue>;
10648}
10649
10650// These upcasts are non-castable due to the constraints on the function
10651// but the UpcastFrom covariance must still extend through closure types.
10652// (impl UpcastFrom really just means CovariantGeneric relation)
10653impl UpcastFrom<String> for JsString {}
10654impl UpcastFrom<JsString> for String {}
10655
10656impl UpcastFrom<&str> for JsString {}
10657impl UpcastFrom<JsString> for &str {}
10658
10659impl UpcastFrom<char> for JsString {}
10660impl UpcastFrom<JsString> for char {}
10661
10662impl wasm_bindgen::__rt::marker::JsStringLikeSealed for JsString {}
10663impl wasm_bindgen::__rt::marker::JsStringLikeSealed for &JsString {}
10664impl wasm_bindgen::JsStringLike for JsString {}
10665impl wasm_bindgen::JsStringLike for &JsString {}
10666
10667// Each cell is the borrowed handle, which JS reads back without taking it.
10668wasm_bindgen::__wbindgen_encoded_sequence!(&JsString, |s| (*s).into_abi(), [ref_into]);
10669
10670impl JsString {
10671    /// Returns the `JsString` value of this JS value if it's an instance of a
10672    /// string.
10673    ///
10674    /// If this JS value is not an instance of a string then this returns
10675    /// `None`.
10676    #[cfg(not(js_sys_unstable_apis))]
10677    #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
10678    pub fn try_from(val: &JsValue) -> Option<&JsString> {
10679        val.dyn_ref()
10680    }
10681
10682    /// Returns whether this string is a valid UTF-16 string.
10683    ///
10684    /// This is useful for learning whether `String::from(..)` will return a
10685    /// lossless representation of the JS string. If this string contains
10686    /// unpaired surrogates then `String::from` will succeed but it will be a
10687    /// lossy representation of the JS string because unpaired surrogates will
10688    /// become replacement characters.
10689    ///
10690    /// If this function returns `false` then to get a lossless representation
10691    /// of the string you'll need to manually use the `iter` method (or the
10692    /// `char_code_at` accessor) to view the raw character codes.
10693    ///
10694    /// For more information, see the documentation on [JS strings vs Rust
10695    /// strings][docs]
10696    ///
10697    /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
10698    pub fn is_valid_utf16(&self) -> bool {
10699        core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
10700    }
10701
10702    /// Returns an iterator over the `u16` character codes that make up this JS
10703    /// string.
10704    ///
10705    /// This method will call `char_code_at` for each code in this JS string,
10706    /// returning an iterator of the codes in sequence.
10707    pub fn iter(
10708        &self,
10709    ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
10710        (0..self.length()).map(move |i| self.char_code_at(i) as u16)
10711    }
10712
10713    /// If this string consists of a single Unicode code point, then this method
10714    /// converts it into a Rust `char` without doing any allocations.
10715    ///
10716    /// If this JS value is not a valid UTF-8 or consists of more than a single
10717    /// codepoint, then this returns `None`.
10718    ///
10719    /// Note that a single Unicode code point might be represented as more than
10720    /// one code unit on the JavaScript side. For example, a JavaScript string
10721    /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
10722    /// corresponds to a character '𐐷'.
10723    pub fn as_char(&self) -> Option<char> {
10724        let len = self.length();
10725
10726        if len == 0 || len > 2 {
10727            return None;
10728        }
10729
10730        #[cfg(not(js_sys_unstable_apis))]
10731        let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
10732        #[cfg(js_sys_unstable_apis)]
10733        let cp = self.code_point_at(0)?;
10734
10735        let c = core::char::from_u32(cp)?;
10736
10737        if c.len_utf16() as u32 == len {
10738            Some(c)
10739        } else {
10740            None
10741        }
10742    }
10743}
10744
10745impl PartialEq<str> for JsString {
10746    #[allow(clippy::cmp_owned)] // prevent infinite recursion
10747    fn eq(&self, other: &str) -> bool {
10748        String::from(self) == other
10749    }
10750}
10751
10752impl<'a> PartialEq<&'a str> for JsString {
10753    fn eq(&self, other: &&'a str) -> bool {
10754        <JsString as PartialEq<str>>::eq(self, other)
10755    }
10756}
10757
10758impl PartialEq<String> for JsString {
10759    fn eq(&self, other: &String) -> bool {
10760        <JsString as PartialEq<str>>::eq(self, other)
10761    }
10762}
10763
10764impl<'a> PartialEq<&'a String> for JsString {
10765    fn eq(&self, other: &&'a String) -> bool {
10766        <JsString as PartialEq<str>>::eq(self, other)
10767    }
10768}
10769
10770impl Default for JsString {
10771    fn default() -> Self {
10772        Self::from("")
10773    }
10774}
10775
10776impl<'a> From<&'a str> for JsString {
10777    fn from(s: &'a str) -> Self {
10778        JsString::unchecked_from_js(JsValue::from_str(s))
10779    }
10780}
10781
10782impl From<String> for JsString {
10783    fn from(s: String) -> Self {
10784        From::from(&*s)
10785    }
10786}
10787
10788impl From<char> for JsString {
10789    #[inline]
10790    fn from(c: char) -> Self {
10791        JsString::from_code_point1(c as u32).unwrap_throw()
10792    }
10793}
10794
10795impl<'a> From<&'a JsString> for String {
10796    fn from(s: &'a JsString) -> Self {
10797        s.obj.as_string().unwrap_throw()
10798    }
10799}
10800
10801impl From<JsString> for String {
10802    fn from(s: JsString) -> Self {
10803        From::from(&s)
10804    }
10805}
10806
10807impl fmt::Debug for JsString {
10808    #[inline]
10809    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10810        fmt::Debug::fmt(&String::from(self), f)
10811    }
10812}
10813
10814impl fmt::Display for JsString {
10815    #[inline]
10816    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10817        fmt::Display::fmt(&String::from(self), f)
10818    }
10819}
10820
10821impl str::FromStr for JsString {
10822    type Err = convert::Infallible;
10823    fn from_str(s: &str) -> Result<Self, Self::Err> {
10824        Ok(JsString::from(s))
10825    }
10826}
10827
10828// Symbol
10829#[wasm_bindgen]
10830extern "C" {
10831    #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
10832    #[derive(Clone, Debug)]
10833    pub type Symbol;
10834
10835    /// The `Symbol.hasInstance` well-known symbol is used to determine
10836    /// if a constructor object recognizes an object as its instance.
10837    /// The `instanceof` operator's behavior can be customized by this symbol.
10838    ///
10839    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
10840    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = hasInstance)]
10841    pub fn has_instance() -> Symbol;
10842
10843    /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
10844    /// if an object should be flattened to its array elements when using the
10845    /// `Array.prototype.concat()` method.
10846    ///
10847    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
10848    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = isConcatSpreadable)]
10849    pub fn is_concat_spreadable() -> Symbol;
10850
10851    /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
10852    /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
10853    ///
10854    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
10855    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncIterator)]
10856    pub fn async_iterator() -> Symbol;
10857
10858    /// The `Symbol.dispose` well-known symbol names the method that
10859    /// disposes a resource, as used by [`DisposableStack`] and `using`.
10860    ///
10861    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/dispose)
10862    #[wasm_bindgen(static_method_of = Symbol, getter)]
10863    pub fn dispose() -> Symbol;
10864
10865    /// The `Symbol.asyncDispose` well-known symbol names the method that
10866    /// asynchronously disposes a resource, as used by
10867    /// [`AsyncDisposableStack`] and `await using`.
10868    ///
10869    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncDispose)
10870    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncDispose)]
10871    pub fn async_dispose() -> Symbol;
10872
10873    /// The `Symbol.iterator` well-known symbol specifies the default iterator
10874    /// for an object.  Used by `for...of`.
10875    ///
10876    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
10877    #[wasm_bindgen(static_method_of = Symbol, getter)]
10878    pub fn iterator() -> Symbol;
10879
10880    /// The `Symbol.match` well-known symbol specifies the matching of a regular
10881    /// expression against a string. This function is called by the
10882    /// `String.prototype.match()` method.
10883    ///
10884    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
10885    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = match)]
10886    pub fn match_() -> Symbol;
10887
10888    /// The `Symbol.replace` well-known symbol specifies the method that
10889    /// replaces matched substrings of a string.  This function is called by the
10890    /// `String.prototype.replace()` method.
10891    ///
10892    /// For more information, see `RegExp.prototype[@@replace]()` and
10893    /// `String.prototype.replace()`.
10894    ///
10895    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
10896    #[wasm_bindgen(static_method_of = Symbol, getter)]
10897    pub fn replace() -> Symbol;
10898
10899    /// The `Symbol.search` well-known symbol specifies the method that returns
10900    /// the index within a string that matches the regular expression.  This
10901    /// function is called by the `String.prototype.search()` method.
10902    ///
10903    /// For more information, see `RegExp.prototype[@@search]()` and
10904    /// `String.prototype.search()`.
10905    ///
10906    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
10907    #[wasm_bindgen(static_method_of = Symbol, getter)]
10908    pub fn search() -> Symbol;
10909
10910    /// The well-known symbol `Symbol.species` specifies a function-valued
10911    /// property that the constructor function uses to create derived objects.
10912    ///
10913    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
10914    #[wasm_bindgen(static_method_of = Symbol, getter)]
10915    pub fn species() -> Symbol;
10916
10917    /// The `Symbol.split` well-known symbol specifies the method that splits a
10918    /// string at the indices that match a regular expression.  This function is
10919    /// called by the `String.prototype.split()` method.
10920    ///
10921    /// For more information, see `RegExp.prototype[@@split]()` and
10922    /// `String.prototype.split()`.
10923    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
10924    #[wasm_bindgen(static_method_of = Symbol, getter)]
10925    pub fn split() -> Symbol;
10926
10927    /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
10928    /// property that is called to convert an object to a corresponding
10929    /// primitive value.
10930    ///
10931    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
10932    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toPrimitive)]
10933    pub fn to_primitive() -> Symbol;
10934
10935    /// The `Symbol.toStringTag` well-known symbol is a string valued property
10936    /// that is used in the creation of the default string description of an
10937    /// object.  It is accessed internally by the `Object.prototype.toString()`
10938    /// method.
10939    ///
10940    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10941    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toStringTag)]
10942    pub fn to_string_tag() -> Symbol;
10943
10944    /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
10945    /// the given key and returns it if found.
10946    /// Otherwise a new symbol gets created in the global symbol registry with this key.
10947    ///
10948    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
10949    #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
10950    pub fn for_(key: &str) -> Symbol;
10951
10952    /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
10953    ///
10954    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
10955    #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
10956    pub fn key_for(sym: &Symbol) -> JsValue;
10957
10958    // Next major: deprecate
10959    /// The `toString()` method returns a string representing the specified Symbol object.
10960    ///
10961    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10962    #[wasm_bindgen(method, js_name = toString)]
10963    pub fn to_string(this: &Symbol) -> JsString;
10964
10965    /// The `toString()` method returns a string representing the specified Symbol object.
10966    ///
10967    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10968    #[wasm_bindgen(method, js_name = toString)]
10969    pub fn to_js_string(this: &Symbol) -> JsString;
10970
10971    /// The `Symbol.unscopables` well-known symbol is used to specify an object
10972    /// value of whose own and inherited property names are excluded from the
10973    /// with environment bindings of the associated object.
10974    ///
10975    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
10976    #[wasm_bindgen(static_method_of = Symbol, getter)]
10977    pub fn unscopables() -> Symbol;
10978
10979    /// The `valueOf()` method returns the primitive value of a Symbol object.
10980    ///
10981    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
10982    #[wasm_bindgen(method, js_name = valueOf)]
10983    pub fn value_of(this: &Symbol) -> Symbol;
10984
10985    /// The `description` accessor property returns the optional description
10986    /// this symbol was created with.
10987    ///
10988    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/description)
10989    #[wasm_bindgen(method, getter)]
10990    pub fn description(this: &Symbol) -> Option<JsString>;
10991}
10992
10993mod primitive_union_sealed {
10994    /// Seal for the TypeScript primitive-union marker traits.
10995    pub trait Sealed {}
10996}
10997
10998macro_rules! impl_primitive_union_category {
10999    ($trait:path, bigint) => {
11000        impl $trait for i64 {}
11001        impl $trait for u64 {}
11002        impl $trait for i128 {}
11003        impl $trait for u128 {}
11004        impl $trait for BigInt {}
11005        impl $trait for &BigInt {}
11006    };
11007    ($trait:path, boolean) => {
11008        impl $trait for bool {}
11009        impl $trait for Boolean {}
11010        impl $trait for &Boolean {}
11011    };
11012    ($trait:path, number) => {
11013        impl $trait for i8 {}
11014        impl $trait for u8 {}
11015        impl $trait for i16 {}
11016        impl $trait for u16 {}
11017        impl $trait for i32 {}
11018        impl $trait for u32 {}
11019        impl $trait for isize {}
11020        impl $trait for usize {}
11021        impl $trait for f32 {}
11022        impl $trait for f64 {}
11023        impl $trait for Number {}
11024        impl $trait for &Number {}
11025    };
11026    // Mirrors the sealed `wasm_bindgen::JsStringLike` implementations. A
11027    // blanket `impl<T: JsStringLike>` would overlap with the concrete impls
11028    // below, since coherence cannot rule out a foreign trait being implemented
11029    // for `i32` and friends.
11030    ($trait:path, string) => {
11031        impl $trait for String {}
11032        impl $trait for &str {}
11033        impl $trait for &String {}
11034        impl $trait for &alloc::boxed::Box<str> {}
11035        impl $trait for &alloc::borrow::Cow<'_, str> {}
11036        impl $trait for JsString {}
11037        impl $trait for &JsString {}
11038    };
11039    ($trait:path, symbol) => {
11040        impl $trait for Symbol {}
11041        impl $trait for &Symbol {}
11042    };
11043}
11044
11045impl_primitive_union_category!(primitive_union_sealed::Sealed, bigint);
11046impl_primitive_union_category!(primitive_union_sealed::Sealed, boolean);
11047impl_primitive_union_category!(primitive_union_sealed::Sealed, number);
11048impl_primitive_union_category!(primitive_union_sealed::Sealed, string);
11049impl_primitive_union_category!(primitive_union_sealed::Sealed, symbol);
11050
11051macro_rules! primitive_union_category_doc {
11052    (bigint) => {
11053        "- `bigint`: `i64`, `u64`, `i128`, `u128`, [`BigInt`], and `&BigInt`\n"
11054    };
11055    (boolean) => {
11056        "- `boolean`: `bool`, [`Boolean`], and `&Boolean`\n"
11057    };
11058    (number) => {
11059        "- `number`: `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `isize`, `usize`, `f32`, `f64`, [`Number`], and `&Number`\n"
11060    };
11061    (string) => {
11062        "- `string`: `String`, `&str`, `&String`, `&Box<str>`, `&Cow<str>`, \
11063         [`JsString`], and `&JsString` (the \
11064         [`JsStringLike`](wasm_bindgen::JsStringLike) types)\n"
11065    };
11066    (symbol) => {
11067        "- `symbol`: [`Symbol`] and `&Symbol`\n"
11068    };
11069}
11070
11071macro_rules! define_primitive_union_traits {
11072    ($(($(#[$attr:meta])* $name:ident, $typescript:literal, [$($supertrait:ident),*], [$($category:ident),+])),* $(,)?) => {
11073        $(
11074            $(#[$attr])*
11075            #[doc = concat!(
11076                "Marker for Rust parameter types represented by the TypeScript union `",
11077                $typescript,
11078                "`.\n\n",
11079                "Use this trait as a bound on an `experimental_generic_mono` ",
11080                "JavaScript import. Each monomorphisation retains its concrete ",
11081                "ABI representation; this marker only restricts which Rust types ",
11082                "may instantiate the parameter.\n\n",
11083                "The union's primitive categories use these Rust representations:\n\n",
11084                $(primitive_union_category_doc!($category),)+
11085                "\nThis trait is experimental and may change or be removed as ",
11086                "`experimental_generic_mono` evolves."
11087            )]
11088            pub trait $name: IntoWasmAbi + wasm_bindgen::convert::NullableIntoWasmAbi + primitive_union_sealed::Sealed $(+ $supertrait)* {}
11089
11090            $(impl_primitive_union_category!($name, $category);)+
11091        )*
11092    };
11093}
11094
11095// The catalog covers every union of two or more of the primitive categories
11096// with a Rust-native ABI representation (`bigint`, `boolean`, `number`, and
11097// `string`). `symbol` crosses the boundary as an ordinary JS handle, so unions
11098// containing it are better expressed with a `&Symbol` overload; the one
11099// exception is `PropertyKey`, where `symbol` carries semantic identity.
11100define_primitive_union_traits! {
11101    (
11102        JsBigIntOrBooleanOrNumberOrStringLike,
11103        "bigint | boolean | number | string",
11104        [],
11105        [bigint, boolean, number, string]
11106    ),
11107    (
11108        JsBigIntOrBooleanOrNumberLike,
11109        "bigint | boolean | number",
11110        [JsBigIntOrBooleanOrNumberOrStringLike],
11111        [bigint, boolean, number]
11112    ),
11113    (
11114        JsBigIntOrBooleanOrStringLike,
11115        "bigint | boolean | string",
11116        [JsBigIntOrBooleanOrNumberOrStringLike],
11117        [bigint, boolean, string]
11118    ),
11119    (
11120        JsBigIntOrNumberOrStringLike,
11121        "bigint | number | string",
11122        [JsBigIntOrBooleanOrNumberOrStringLike],
11123        [bigint, number, string]
11124    ),
11125    (
11126        JsBooleanOrNumberOrStringLike,
11127        "boolean | number | string",
11128        [JsBigIntOrBooleanOrNumberOrStringLike],
11129        [boolean, number, string]
11130    ),
11131    (
11132        JsBigIntOrBooleanLike,
11133        "bigint | boolean",
11134        [JsBigIntOrBooleanOrNumberLike, JsBigIntOrBooleanOrStringLike],
11135        [bigint, boolean]
11136    ),
11137    (
11138        JsBigIntOrNumberLike,
11139        "bigint | number",
11140        [JsBigIntOrBooleanOrNumberLike, JsBigIntOrNumberOrStringLike],
11141        [bigint, number]
11142    ),
11143    (
11144        JsBigIntOrStringLike,
11145        "bigint | string",
11146        [JsBigIntOrBooleanOrStringLike, JsBigIntOrNumberOrStringLike],
11147        [bigint, string]
11148    ),
11149    (
11150        JsBooleanOrNumberLike,
11151        "boolean | number",
11152        [JsBigIntOrBooleanOrNumberLike, JsBooleanOrNumberOrStringLike],
11153        [boolean, number]
11154    ),
11155    (
11156        JsBooleanOrStringLike,
11157        "boolean | string",
11158        [JsBigIntOrBooleanOrStringLike, JsBooleanOrNumberOrStringLike],
11159        [boolean, string]
11160    ),
11161    (
11162        JsNumberOrStringLike,
11163        "number | string",
11164        [
11165            JsBigIntOrNumberOrStringLike,
11166            JsBooleanOrNumberOrStringLike,
11167            PropertyKey
11168        ],
11169        [number, string]
11170    ),
11171    (
11172        /// TypeScript's `PropertyKey`: the key types accepted by JavaScript
11173        /// property operations and by TypeScript's `Record`.
11174        ///
11175        PropertyKey,
11176        "number | string | symbol",
11177        [],
11178        [number, string, symbol]
11179    ),
11180}
11181
11182#[allow(non_snake_case)]
11183pub mod Intl {
11184    use super::*;
11185
11186    // Intl
11187    #[wasm_bindgen]
11188    extern "C" {
11189        /// The `Intl.getCanonicalLocales()` method returns an array containing
11190        /// the canonical locale names. Duplicates will be omitted and elements
11191        /// will be validated as structurally valid language tags.
11192        ///
11193        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
11194        #[cfg(not(js_sys_unstable_apis))]
11195        #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
11196        pub fn get_canonical_locales(s: &JsValue) -> Array;
11197
11198        /// The `Intl.getCanonicalLocales()` method returns an array containing
11199        /// the canonical locale names. Duplicates will be omitted and elements
11200        /// will be validated as structurally valid language tags.
11201        ///
11202        /// Throws a `RangeError` if any of the strings are not valid locale identifiers.
11203        ///
11204        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
11205        #[cfg(js_sys_unstable_apis)]
11206        #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl, catch)]
11207        pub fn get_canonical_locales(s: &[JsString]) -> Result<Array<JsString>, JsValue>;
11208
11209        /// The `Intl.supportedValuesOf()` method returns an array containing the
11210        /// supported calendar, collation, currency, numbering system, or unit values
11211        /// supported by the implementation.
11212        ///
11213        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
11214        #[wasm_bindgen(js_name = supportedValuesOf, js_namespace = Intl)]
11215        pub fn supported_values_of(key: SupportedValuesKey) -> Array<JsString>;
11216    }
11217
11218    // Intl string enums
11219
11220    /// Key for `Intl.supportedValuesOf()`.
11221    #[wasm_bindgen]
11222    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11223    pub enum SupportedValuesKey {
11224        Calendar = "calendar",
11225        Collation = "collation",
11226        Currency = "currency",
11227        NumberingSystem = "numberingSystem",
11228        TimeZone = "timeZone",
11229        Unit = "unit",
11230    }
11231
11232    /// Locale matching algorithm for Intl constructors.
11233    #[wasm_bindgen]
11234    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11235    pub enum LocaleMatcher {
11236        Lookup = "lookup",
11237        BestFit = "best fit",
11238    }
11239
11240    /// Usage for `Intl.Collator`.
11241    #[wasm_bindgen]
11242    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11243    pub enum CollatorUsage {
11244        Sort = "sort",
11245        Search = "search",
11246    }
11247
11248    /// Sensitivity for `Intl.Collator`.
11249    #[wasm_bindgen]
11250    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11251    pub enum CollatorSensitivity {
11252        Base = "base",
11253        Accent = "accent",
11254        Case = "case",
11255        Variant = "variant",
11256    }
11257
11258    /// Case first option for `Intl.Collator`.
11259    #[wasm_bindgen]
11260    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11261    pub enum CollatorCaseFirst {
11262        Upper = "upper",
11263        Lower = "lower",
11264        False = "false",
11265    }
11266
11267    /// Style for `Intl.NumberFormat`.
11268    #[wasm_bindgen]
11269    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11270    pub enum NumberFormatStyle {
11271        Decimal = "decimal",
11272        Currency = "currency",
11273        Percent = "percent",
11274        Unit = "unit",
11275    }
11276
11277    /// Currency display for `Intl.NumberFormat`.
11278    #[wasm_bindgen]
11279    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11280    pub enum CurrencyDisplay {
11281        Code = "code",
11282        Symbol = "symbol",
11283        NarrowSymbol = "narrowSymbol",
11284        Name = "name",
11285    }
11286
11287    /// Currency sign for `Intl.NumberFormat`.
11288    #[wasm_bindgen]
11289    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11290    pub enum CurrencySign {
11291        Standard = "standard",
11292        Accounting = "accounting",
11293    }
11294
11295    /// Unit display for `Intl.NumberFormat`.
11296    #[wasm_bindgen]
11297    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11298    pub enum UnitDisplay {
11299        Short = "short",
11300        Narrow = "narrow",
11301        Long = "long",
11302    }
11303
11304    /// Notation for `Intl.NumberFormat`.
11305    #[wasm_bindgen]
11306    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11307    pub enum NumberFormatNotation {
11308        Standard = "standard",
11309        Scientific = "scientific",
11310        Engineering = "engineering",
11311        Compact = "compact",
11312    }
11313
11314    /// Compact display for `Intl.NumberFormat`.
11315    #[wasm_bindgen]
11316    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11317    pub enum CompactDisplay {
11318        Short = "short",
11319        Long = "long",
11320    }
11321
11322    /// Sign display for `Intl.NumberFormat`.
11323    #[wasm_bindgen]
11324    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11325    pub enum SignDisplay {
11326        Auto = "auto",
11327        Never = "never",
11328        Always = "always",
11329        ExceptZero = "exceptZero",
11330    }
11331
11332    /// Rounding mode for `Intl.NumberFormat`.
11333    #[wasm_bindgen]
11334    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11335    pub enum RoundingMode {
11336        Ceil = "ceil",
11337        Floor = "floor",
11338        Expand = "expand",
11339        Trunc = "trunc",
11340        HalfCeil = "halfCeil",
11341        HalfFloor = "halfFloor",
11342        HalfExpand = "halfExpand",
11343        HalfTrunc = "halfTrunc",
11344        HalfEven = "halfEven",
11345    }
11346
11347    /// Rounding priority for `Intl.NumberFormat`.
11348    #[wasm_bindgen]
11349    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11350    pub enum RoundingPriority {
11351        Auto = "auto",
11352        MorePrecision = "morePrecision",
11353        LessPrecision = "lessPrecision",
11354    }
11355
11356    /// Trailing zero display for `Intl.NumberFormat`.
11357    #[wasm_bindgen]
11358    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11359    pub enum TrailingZeroDisplay {
11360        Auto = "auto",
11361        StripIfInteger = "stripIfInteger",
11362    }
11363
11364    /// Use grouping option for `Intl.NumberFormat`.
11365    ///
11366    /// Determines whether to use grouping separators, such as thousands
11367    /// separators or thousand/lakh/crore separators.
11368    ///
11369    /// The default is `Min2` if notation is "compact", and `Auto` otherwise.
11370    ///
11371    /// Note: The string values `"true"` and `"false"` are accepted by JavaScript
11372    /// but are always converted to the default value. Use `True` and `False`
11373    /// variants for the boolean behavior.
11374    ///
11375    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#usegrouping)
11376    #[wasm_bindgen]
11377    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11378    pub enum UseGrouping {
11379        /// Display grouping separators even if the locale prefers otherwise.
11380        Always = "always",
11381        /// Display grouping separators based on the locale preference,
11382        /// which may also be dependent on the currency.
11383        Auto = "auto",
11384        /// Display grouping separators when there are at least 2 digits in a group.
11385        Min2 = "min2",
11386        /// Same as `Always`. Display grouping separators even if the locale prefers otherwise.
11387        True = "true",
11388        /// Display no grouping separators.
11389        False = "false",
11390    }
11391
11392    /// Date/time style for `Intl.DateTimeFormat`.
11393    #[wasm_bindgen]
11394    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11395    pub enum DateTimeStyle {
11396        Full = "full",
11397        Long = "long",
11398        Medium = "medium",
11399        Short = "short",
11400    }
11401
11402    /// Hour cycle for `Intl.DateTimeFormat`.
11403    #[wasm_bindgen]
11404    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11405    pub enum HourCycle {
11406        H11 = "h11",
11407        H12 = "h12",
11408        H23 = "h23",
11409        H24 = "h24",
11410    }
11411
11412    /// Weekday format for `Intl.DateTimeFormat`.
11413    #[wasm_bindgen]
11414    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11415    pub enum WeekdayFormat {
11416        Narrow = "narrow",
11417        Short = "short",
11418        Long = "long",
11419    }
11420
11421    /// Era format for `Intl.DateTimeFormat`.
11422    #[wasm_bindgen]
11423    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11424    pub enum EraFormat {
11425        Narrow = "narrow",
11426        Short = "short",
11427        Long = "long",
11428    }
11429
11430    /// Year format for `Intl.DateTimeFormat`.
11431    #[wasm_bindgen]
11432    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11433    pub enum YearFormat {
11434        Numeric = "numeric",
11435        TwoDigit = "2-digit",
11436    }
11437
11438    /// Month format for `Intl.DateTimeFormat`.
11439    #[wasm_bindgen]
11440    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11441    pub enum MonthFormat {
11442        #[wasm_bindgen]
11443        Numeric = "numeric",
11444        #[wasm_bindgen]
11445        TwoDigit = "2-digit",
11446        #[wasm_bindgen]
11447        Narrow = "narrow",
11448        #[wasm_bindgen]
11449        Short = "short",
11450        #[wasm_bindgen]
11451        Long = "long",
11452    }
11453
11454    /// Day format for `Intl.DateTimeFormat`.
11455    #[wasm_bindgen]
11456    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11457    pub enum DayFormat {
11458        #[wasm_bindgen]
11459        Numeric = "numeric",
11460        #[wasm_bindgen]
11461        TwoDigit = "2-digit",
11462    }
11463
11464    /// Hour/minute/second format for `Intl.DateTimeFormat`.
11465    #[wasm_bindgen]
11466    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11467    pub enum NumericFormat {
11468        #[wasm_bindgen]
11469        Numeric = "numeric",
11470        #[wasm_bindgen]
11471        TwoDigit = "2-digit",
11472    }
11473
11474    /// Time zone name format for `Intl.DateTimeFormat`.
11475    #[wasm_bindgen]
11476    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11477    pub enum TimeZoneNameFormat {
11478        Short = "short",
11479        Long = "long",
11480        ShortOffset = "shortOffset",
11481        LongOffset = "longOffset",
11482        ShortGeneric = "shortGeneric",
11483        LongGeneric = "longGeneric",
11484    }
11485
11486    /// Day period format for `Intl.DateTimeFormat`.
11487    #[wasm_bindgen]
11488    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11489    pub enum DayPeriodFormat {
11490        Narrow = "narrow",
11491        Short = "short",
11492        Long = "long",
11493    }
11494
11495    /// Part type for `DateTimeFormat.formatToParts()`.
11496    #[wasm_bindgen]
11497    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11498    pub enum DateTimeFormatPartType {
11499        Day = "day",
11500        DayPeriod = "dayPeriod",
11501        Era = "era",
11502        FractionalSecond = "fractionalSecond",
11503        Hour = "hour",
11504        Literal = "literal",
11505        Minute = "minute",
11506        Month = "month",
11507        RelatedYear = "relatedYear",
11508        Second = "second",
11509        TimeZoneName = "timeZoneName",
11510        Weekday = "weekday",
11511        Year = "year",
11512        YearName = "yearName",
11513    }
11514
11515    /// Part type for `NumberFormat.formatToParts()`.
11516    #[wasm_bindgen]
11517    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11518    pub enum NumberFormatPartType {
11519        Compact = "compact",
11520        Currency = "currency",
11521        Decimal = "decimal",
11522        ExponentInteger = "exponentInteger",
11523        ExponentMinusSign = "exponentMinusSign",
11524        ExponentSeparator = "exponentSeparator",
11525        Fraction = "fraction",
11526        Group = "group",
11527        Infinity = "infinity",
11528        Integer = "integer",
11529        Literal = "literal",
11530        MinusSign = "minusSign",
11531        Nan = "nan",
11532        PercentSign = "percentSign",
11533        PlusSign = "plusSign",
11534        Unit = "unit",
11535        Unknown = "unknown",
11536    }
11537
11538    /// Type for `Intl.PluralRules` (cardinal or ordinal).
11539    #[wasm_bindgen]
11540    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11541    pub enum PluralRulesType {
11542        Cardinal = "cardinal",
11543        Ordinal = "ordinal",
11544    }
11545
11546    /// Plural category returned by `PluralRules.select()`.
11547    #[wasm_bindgen]
11548    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11549    pub enum PluralCategory {
11550        Zero = "zero",
11551        One = "one",
11552        Two = "two",
11553        Few = "few",
11554        Many = "many",
11555        Other = "other",
11556    }
11557
11558    /// Numeric option for `Intl.RelativeTimeFormat`.
11559    #[wasm_bindgen]
11560    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11561    pub enum RelativeTimeFormatNumeric {
11562        Always = "always",
11563        Auto = "auto",
11564    }
11565
11566    /// Style for `Intl.RelativeTimeFormat`.
11567    #[wasm_bindgen]
11568    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11569    pub enum RelativeTimeFormatStyle {
11570        Long = "long",
11571        Short = "short",
11572        Narrow = "narrow",
11573    }
11574
11575    /// Unit for `RelativeTimeFormat.format()`.
11576    #[wasm_bindgen]
11577    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11578    pub enum RelativeTimeFormatUnit {
11579        Year = "year",
11580        Years = "years",
11581        Quarter = "quarter",
11582        Quarters = "quarters",
11583        Month = "month",
11584        Months = "months",
11585        Week = "week",
11586        Weeks = "weeks",
11587        Day = "day",
11588        Days = "days",
11589        Hour = "hour",
11590        Hours = "hours",
11591        Minute = "minute",
11592        Minutes = "minutes",
11593        Second = "second",
11594        Seconds = "seconds",
11595    }
11596
11597    /// Part type for `RelativeTimeFormat.formatToParts()`.
11598    #[wasm_bindgen]
11599    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11600    pub enum RelativeTimeFormatPartType {
11601        Literal = "literal",
11602        Integer = "integer",
11603        Decimal = "decimal",
11604        Fraction = "fraction",
11605    }
11606
11607    /// Source indicator for range format parts.
11608    ///
11609    /// Indicates which part of the range (start, end, or shared) a formatted
11610    /// part belongs to when using `formatRangeToParts()`.
11611    ///
11612    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts#description)
11613    #[wasm_bindgen]
11614    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11615    pub enum RangeSource {
11616        /// The part is from the start of the range.
11617        StartRange = "startRange",
11618        /// The part is from the end of the range.
11619        EndRange = "endRange",
11620        /// The part is shared between start and end (e.g., a separator or common element).
11621        Shared = "shared",
11622    }
11623
11624    /// Type for `Intl.ListFormat`.
11625    #[wasm_bindgen]
11626    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11627    pub enum ListFormatType {
11628        /// For lists of standalone items (default).
11629        Conjunction = "conjunction",
11630        /// For lists representing alternatives.
11631        Disjunction = "disjunction",
11632        /// For lists of values with units.
11633        Unit = "unit",
11634    }
11635
11636    /// Style for `Intl.ListFormat`.
11637    #[wasm_bindgen]
11638    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11639    pub enum ListFormatStyle {
11640        /// "A, B, and C" (default).
11641        Long = "long",
11642        /// "A, B, C".
11643        Short = "short",
11644        /// "A B C".
11645        Narrow = "narrow",
11646    }
11647
11648    /// Part type for `Intl.ListFormat.formatToParts()`.
11649    #[wasm_bindgen]
11650    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11651    pub enum ListFormatPartType {
11652        /// A value from the list.
11653        Element = "element",
11654        /// A linguistic construct (e.g., ", ", " and ").
11655        Literal = "literal",
11656    }
11657
11658    /// Type for `Intl.Segmenter`.
11659    #[wasm_bindgen]
11660    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11661    pub enum SegmenterGranularity {
11662        /// Segment by grapheme clusters (user-perceived characters).
11663        Grapheme = "grapheme",
11664        /// Segment by words.
11665        Word = "word",
11666        /// Segment by sentences.
11667        Sentence = "sentence",
11668    }
11669
11670    /// Type for `Intl.DisplayNames`.
11671    #[wasm_bindgen]
11672    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11673    pub enum DisplayNamesType {
11674        /// Language display names.
11675        Language = "language",
11676        /// Region display names.
11677        Region = "region",
11678        /// Script display names.
11679        Script = "script",
11680        /// Currency display names.
11681        Currency = "currency",
11682        /// Calendar display names.
11683        Calendar = "calendar",
11684        /// Date/time field display names.
11685        DateTimeField = "dateTimeField",
11686    }
11687
11688    /// Style for `Intl.DisplayNames`.
11689    #[wasm_bindgen]
11690    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11691    pub enum DisplayNamesStyle {
11692        /// Full display name (default).
11693        Long = "long",
11694        /// Abbreviated display name.
11695        Short = "short",
11696        /// Minimal display name.
11697        Narrow = "narrow",
11698    }
11699
11700    /// Fallback for `Intl.DisplayNames`.
11701    #[wasm_bindgen]
11702    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11703    pub enum DisplayNamesFallback {
11704        /// Return the input code if no display name is available (default).
11705        Code = "code",
11706        /// Return undefined if no display name is available.
11707        None = "none",
11708    }
11709
11710    /// Language display for `Intl.DisplayNames`.
11711    #[wasm_bindgen]
11712    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11713    pub enum DisplayNamesLanguageDisplay {
11714        /// Use dialect names (e.g., "British English").
11715        Dialect = "dialect",
11716        /// Use standard names (e.g., "English (United Kingdom)").
11717        Standard = "standard",
11718    }
11719
11720    // Intl.RelativeTimeFormatOptions
11721    #[wasm_bindgen]
11722    extern "C" {
11723        /// Options for `Intl.RelativeTimeFormat` constructor.
11724        ///
11725        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#options)
11726        #[wasm_bindgen(extends = Object)]
11727        #[derive(Clone, Debug)]
11728        pub type RelativeTimeFormatOptions;
11729
11730        #[wasm_bindgen(method, getter = localeMatcher)]
11731        pub fn get_locale_matcher(this: &RelativeTimeFormatOptions) -> Option<LocaleMatcher>;
11732        #[wasm_bindgen(method, setter = localeMatcher)]
11733        pub fn set_locale_matcher(this: &RelativeTimeFormatOptions, value: LocaleMatcher);
11734
11735        #[wasm_bindgen(method, getter = numeric)]
11736        pub fn get_numeric(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatNumeric>;
11737        #[wasm_bindgen(method, setter = numeric)]
11738        pub fn set_numeric(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatNumeric);
11739
11740        #[wasm_bindgen(method, getter = style)]
11741        pub fn get_style(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatStyle>;
11742        #[wasm_bindgen(method, setter = style)]
11743        pub fn set_style(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatStyle);
11744    }
11745
11746    impl RelativeTimeFormatOptions {
11747        pub fn new() -> RelativeTimeFormatOptions {
11748            JsCast::unchecked_into(Object::new())
11749        }
11750    }
11751
11752    impl Default for RelativeTimeFormatOptions {
11753        fn default() -> Self {
11754            RelativeTimeFormatOptions::new()
11755        }
11756    }
11757
11758    // Intl.ResolvedRelativeTimeFormatOptions
11759    #[wasm_bindgen]
11760    extern "C" {
11761        /// Resolved options returned by `Intl.RelativeTimeFormat.prototype.resolvedOptions()`.
11762        ///
11763        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11764        #[wasm_bindgen(extends = RelativeTimeFormatOptions)]
11765        #[derive(Clone, Debug)]
11766        pub type ResolvedRelativeTimeFormatOptions;
11767
11768        /// The resolved locale string.
11769        #[wasm_bindgen(method, getter = locale)]
11770        pub fn get_locale(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
11771
11772        /// The numbering system used.
11773        #[wasm_bindgen(method, getter = numberingSystem)]
11774        pub fn get_numbering_system(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
11775    }
11776
11777    // Intl.RelativeTimeFormatPart
11778    #[wasm_bindgen]
11779    extern "C" {
11780        /// A part of the formatted relative time returned by `formatToParts()`.
11781        ///
11782        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11783        #[wasm_bindgen(extends = Object)]
11784        #[derive(Clone, Debug)]
11785        pub type RelativeTimeFormatPart;
11786
11787        /// The type of this part.
11788        #[wasm_bindgen(method, getter = type)]
11789        pub fn type_(this: &RelativeTimeFormatPart) -> RelativeTimeFormatPartType;
11790
11791        /// The string value of this part.
11792        #[wasm_bindgen(method, getter = value)]
11793        pub fn value(this: &RelativeTimeFormatPart) -> JsString;
11794
11795        /// The unit used in this part (only for integer parts).
11796        #[wasm_bindgen(method, getter = unit)]
11797        pub fn unit(this: &RelativeTimeFormatPart) -> Option<JsString>;
11798    }
11799
11800    // Intl.LocaleMatcherOptions
11801    #[wasm_bindgen]
11802    extern "C" {
11803        /// Options for `supportedLocalesOf` methods.
11804        #[wasm_bindgen(extends = Object)]
11805        #[derive(Clone, Debug)]
11806        pub type LocaleMatcherOptions;
11807
11808        #[wasm_bindgen(method, getter = localeMatcher)]
11809        pub fn get_locale_matcher(this: &LocaleMatcherOptions) -> Option<LocaleMatcher>;
11810
11811        #[wasm_bindgen(method, setter = localeMatcher)]
11812        pub fn set_locale_matcher(this: &LocaleMatcherOptions, value: LocaleMatcher);
11813    }
11814
11815    impl LocaleMatcherOptions {
11816        pub fn new() -> LocaleMatcherOptions {
11817            JsCast::unchecked_into(Object::new())
11818        }
11819    }
11820
11821    impl Default for LocaleMatcherOptions {
11822        fn default() -> Self {
11823            LocaleMatcherOptions::new()
11824        }
11825    }
11826
11827    // Intl.Collator Options
11828    #[wasm_bindgen]
11829    extern "C" {
11830        /// Options for `Intl.Collator` and `String.prototype.localeCompare`.
11831        ///
11832        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options)
11833        #[wasm_bindgen(extends = Object)]
11834        #[derive(Clone, Debug)]
11835        pub type CollatorOptions;
11836
11837        #[wasm_bindgen(method, getter = localeMatcher)]
11838        pub fn get_locale_matcher(this: &CollatorOptions) -> Option<LocaleMatcher>;
11839        #[wasm_bindgen(method, setter = localeMatcher)]
11840        pub fn set_locale_matcher(this: &CollatorOptions, value: LocaleMatcher);
11841
11842        #[wasm_bindgen(method, getter = usage)]
11843        pub fn get_usage(this: &CollatorOptions) -> Option<CollatorUsage>;
11844        #[wasm_bindgen(method, setter = usage)]
11845        pub fn set_usage(this: &CollatorOptions, value: CollatorUsage);
11846
11847        #[wasm_bindgen(method, getter = sensitivity)]
11848        pub fn get_sensitivity(this: &CollatorOptions) -> Option<CollatorSensitivity>;
11849        #[wasm_bindgen(method, setter = sensitivity)]
11850        pub fn set_sensitivity(this: &CollatorOptions, value: CollatorSensitivity);
11851
11852        #[wasm_bindgen(method, getter = ignorePunctuation)]
11853        pub fn get_ignore_punctuation(this: &CollatorOptions) -> Option<bool>;
11854        #[wasm_bindgen(method, setter = ignorePunctuation)]
11855        pub fn set_ignore_punctuation(this: &CollatorOptions, value: bool);
11856
11857        #[wasm_bindgen(method, getter = numeric)]
11858        pub fn get_numeric(this: &CollatorOptions) -> Option<bool>;
11859        #[wasm_bindgen(method, setter = numeric)]
11860        pub fn set_numeric(this: &CollatorOptions, value: bool);
11861
11862        #[wasm_bindgen(method, getter = caseFirst)]
11863        pub fn get_case_first(this: &CollatorOptions) -> Option<CollatorCaseFirst>;
11864        #[wasm_bindgen(method, setter = caseFirst)]
11865        pub fn set_case_first(this: &CollatorOptions, value: CollatorCaseFirst);
11866    }
11867    impl CollatorOptions {
11868        pub fn new() -> CollatorOptions {
11869            JsCast::unchecked_into(Object::new())
11870        }
11871    }
11872    impl Default for CollatorOptions {
11873        fn default() -> Self {
11874            CollatorOptions::new()
11875        }
11876    }
11877
11878    // Intl.Collator ResolvedCollatorOptions
11879    #[wasm_bindgen]
11880    extern "C" {
11881        #[wasm_bindgen(extends = CollatorOptions)]
11882        #[derive(Clone, Debug)]
11883        pub type ResolvedCollatorOptions;
11884
11885        #[wasm_bindgen(method, getter = locale)]
11886        pub fn get_locale(this: &ResolvedCollatorOptions) -> JsString; // not Option, always present
11887        #[wasm_bindgen(method, getter = collation)]
11888        pub fn get_collation(this: &ResolvedCollatorOptions) -> JsString;
11889    }
11890
11891    // Intl.Collator
11892    #[wasm_bindgen]
11893    extern "C" {
11894        /// The `Intl.Collator` object is a constructor for collators, objects
11895        /// that enable language sensitive string comparison.
11896        ///
11897        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
11898        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
11899        #[derive(Clone, Debug)]
11900        pub type Collator;
11901
11902        /// The `Intl.Collator` object is a constructor for collators, objects
11903        /// that enable language sensitive string comparison.
11904        ///
11905        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
11906        #[cfg(not(js_sys_unstable_apis))]
11907        #[wasm_bindgen(constructor, js_namespace = Intl)]
11908        pub fn new(locales: &Array, options: &Object) -> Collator;
11909
11910        /// The `Intl.Collator` object is a constructor for collators, objects
11911        /// that enable language sensitive string comparison.
11912        ///
11913        /// Throws a `RangeError` if locales contain invalid values.
11914        ///
11915        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
11916        #[cfg(js_sys_unstable_apis)]
11917        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11918        pub fn new(locales: &[JsString], options: &CollatorOptions) -> Result<Collator, JsValue>;
11919
11920        /// The Intl.Collator.prototype.compare property returns a function that
11921        /// compares two strings according to the sort order of this Collator
11922        /// object.
11923        ///
11924        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
11925        #[cfg(not(js_sys_unstable_apis))]
11926        #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
11927        pub fn compare(this: &Collator) -> Function;
11928
11929        /// Compares two strings according to the sort order of this Collator.
11930        ///
11931        /// Returns a negative value if `a` comes before `b`, positive if `a` comes
11932        /// after `b`, and zero if they are equal.
11933        ///
11934        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare)
11935        #[cfg(js_sys_unstable_apis)]
11936        #[wasm_bindgen(method, js_class = "Intl.Collator")]
11937        pub fn compare(this: &Collator, a: &str, b: &str) -> i32;
11938
11939        /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
11940        /// object with properties reflecting the locale and collation options
11941        /// computed during initialization of this Collator object.
11942        ///
11943        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
11944        #[cfg(not(js_sys_unstable_apis))]
11945        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11946        pub fn resolved_options(this: &Collator) -> Object;
11947
11948        /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
11949        /// object with properties reflecting the locale and collation options
11950        /// computed during initialization of this Collator object.
11951        ///
11952        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
11953        #[cfg(js_sys_unstable_apis)]
11954        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11955        pub fn resolved_options(this: &Collator) -> ResolvedCollatorOptions;
11956
11957        /// The `Intl.Collator.supportedLocalesOf()` method returns an array
11958        /// containing those of the provided locales that are supported in
11959        /// collation without having to fall back to the runtime's default
11960        /// locale.
11961        ///
11962        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
11963        #[cfg(not(js_sys_unstable_apis))]
11964        #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
11965        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11966
11967        /// The `Intl.Collator.supportedLocalesOf()` method returns an array
11968        /// containing those of the provided locales that are supported in
11969        /// collation without having to fall back to the runtime's default
11970        /// locale.
11971        ///
11972        /// Throws a `RangeError` if locales contain invalid values.
11973        ///
11974        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
11975        #[cfg(js_sys_unstable_apis)]
11976        #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11977        pub fn supported_locales_of(
11978            locales: &[JsString],
11979            options: &LocaleMatcherOptions,
11980        ) -> Result<Array<JsString>, JsValue>;
11981    }
11982
11983    #[cfg(not(js_sys_unstable_apis))]
11984    impl Default for Collator {
11985        fn default() -> Self {
11986            Self::new(
11987                &JsValue::UNDEFINED.unchecked_into(),
11988                &JsValue::UNDEFINED.unchecked_into(),
11989            )
11990        }
11991    }
11992
11993    #[cfg(js_sys_unstable_apis)]
11994    impl Default for Collator {
11995        fn default() -> Self {
11996            Self::new(&[], &Default::default()).unwrap()
11997        }
11998    }
11999
12000    // Intl.DateTimeFormatOptions
12001    #[wasm_bindgen]
12002    extern "C" {
12003        /// Options for `Intl.DateTimeFormat` constructor.
12004        ///
12005        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)
12006        #[wasm_bindgen(extends = Object)]
12007        #[derive(Clone, Debug)]
12008        pub type DateTimeFormatOptions;
12009
12010        // Locale matching
12011        #[wasm_bindgen(method, getter = localeMatcher)]
12012        pub fn get_locale_matcher(this: &DateTimeFormatOptions) -> Option<LocaleMatcher>;
12013        #[wasm_bindgen(method, setter = localeMatcher)]
12014        pub fn set_locale_matcher(this: &DateTimeFormatOptions, value: LocaleMatcher);
12015
12016        // Calendar/numbering (free-form strings, no enum)
12017        #[wasm_bindgen(method, getter = calendar)]
12018        pub fn get_calendar(this: &DateTimeFormatOptions) -> Option<JsString>;
12019        #[wasm_bindgen(method, setter = calendar)]
12020        pub fn set_calendar(this: &DateTimeFormatOptions, value: &str);
12021
12022        #[wasm_bindgen(method, getter = numberingSystem)]
12023        pub fn get_numbering_system(this: &DateTimeFormatOptions) -> Option<JsString>;
12024        #[wasm_bindgen(method, setter = numberingSystem)]
12025        pub fn set_numbering_system(this: &DateTimeFormatOptions, value: &str);
12026
12027        // Timezone (free-form string)
12028        #[wasm_bindgen(method, getter = timeZone)]
12029        pub fn get_time_zone(this: &DateTimeFormatOptions) -> Option<JsString>;
12030        #[wasm_bindgen(method, setter = timeZone)]
12031        pub fn set_time_zone(this: &DateTimeFormatOptions, value: &str);
12032
12033        // Hour cycle
12034        #[wasm_bindgen(method, getter = hour12)]
12035        pub fn get_hour12(this: &DateTimeFormatOptions) -> Option<bool>;
12036        #[wasm_bindgen(method, setter = hour12)]
12037        pub fn set_hour12(this: &DateTimeFormatOptions, value: bool);
12038
12039        #[wasm_bindgen(method, getter = hourCycle)]
12040        pub fn get_hour_cycle(this: &DateTimeFormatOptions) -> Option<HourCycle>;
12041        #[wasm_bindgen(method, setter = hourCycle)]
12042        pub fn set_hour_cycle(this: &DateTimeFormatOptions, value: HourCycle);
12043
12044        // Style shortcuts
12045        #[wasm_bindgen(method, getter = dateStyle)]
12046        pub fn get_date_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
12047        #[wasm_bindgen(method, setter = dateStyle)]
12048        pub fn set_date_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
12049
12050        #[wasm_bindgen(method, getter = timeStyle)]
12051        pub fn get_time_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
12052        #[wasm_bindgen(method, setter = timeStyle)]
12053        pub fn set_time_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
12054
12055        // Component options
12056        #[wasm_bindgen(method, getter = weekday)]
12057        pub fn get_weekday(this: &DateTimeFormatOptions) -> Option<WeekdayFormat>;
12058        #[wasm_bindgen(method, setter = weekday)]
12059        pub fn set_weekday(this: &DateTimeFormatOptions, value: WeekdayFormat);
12060
12061        #[wasm_bindgen(method, getter = era)]
12062        pub fn get_era(this: &DateTimeFormatOptions) -> Option<EraFormat>;
12063        #[wasm_bindgen(method, setter = era)]
12064        pub fn set_era(this: &DateTimeFormatOptions, value: EraFormat);
12065
12066        #[wasm_bindgen(method, getter = year)]
12067        pub fn get_year(this: &DateTimeFormatOptions) -> Option<YearFormat>;
12068        #[wasm_bindgen(method, setter = year)]
12069        pub fn set_year(this: &DateTimeFormatOptions, value: YearFormat);
12070
12071        #[wasm_bindgen(method, getter = month)]
12072        pub fn get_month(this: &DateTimeFormatOptions) -> Option<MonthFormat>;
12073        #[wasm_bindgen(method, setter = month)]
12074        pub fn set_month(this: &DateTimeFormatOptions, value: MonthFormat);
12075
12076        #[wasm_bindgen(method, getter = day)]
12077        pub fn get_day(this: &DateTimeFormatOptions) -> Option<DayFormat>;
12078        #[wasm_bindgen(method, setter = day)]
12079        pub fn set_day(this: &DateTimeFormatOptions, value: DayFormat);
12080
12081        #[wasm_bindgen(method, getter = hour)]
12082        pub fn get_hour(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
12083        #[wasm_bindgen(method, setter = hour)]
12084        pub fn set_hour(this: &DateTimeFormatOptions, value: NumericFormat);
12085
12086        #[wasm_bindgen(method, getter = minute)]
12087        pub fn get_minute(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
12088        #[wasm_bindgen(method, setter = minute)]
12089        pub fn set_minute(this: &DateTimeFormatOptions, value: NumericFormat);
12090
12091        #[wasm_bindgen(method, getter = second)]
12092        pub fn get_second(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
12093        #[wasm_bindgen(method, setter = second)]
12094        pub fn set_second(this: &DateTimeFormatOptions, value: NumericFormat);
12095
12096        #[wasm_bindgen(method, getter = fractionalSecondDigits)]
12097        pub fn get_fractional_second_digits(this: &DateTimeFormatOptions) -> Option<u8>;
12098        #[wasm_bindgen(method, setter = fractionalSecondDigits)]
12099        pub fn set_fractional_second_digits(this: &DateTimeFormatOptions, value: u8);
12100
12101        #[wasm_bindgen(method, getter = timeZoneName)]
12102        pub fn get_time_zone_name(this: &DateTimeFormatOptions) -> Option<TimeZoneNameFormat>;
12103        #[wasm_bindgen(method, setter = timeZoneName)]
12104        pub fn set_time_zone_name(this: &DateTimeFormatOptions, value: TimeZoneNameFormat);
12105
12106        #[wasm_bindgen(method, getter = dayPeriod)]
12107        pub fn get_day_period(this: &DateTimeFormatOptions) -> Option<DayPeriodFormat>;
12108        #[wasm_bindgen(method, setter = dayPeriod)]
12109        pub fn set_day_period(this: &DateTimeFormatOptions, value: DayPeriodFormat);
12110    }
12111
12112    impl DateTimeFormatOptions {
12113        pub fn new() -> DateTimeFormatOptions {
12114            JsCast::unchecked_into(Object::new())
12115        }
12116    }
12117
12118    impl Default for DateTimeFormatOptions {
12119        fn default() -> Self {
12120            DateTimeFormatOptions::new()
12121        }
12122    }
12123
12124    // Intl.ResolvedDateTimeFormatOptions
12125    #[wasm_bindgen]
12126    extern "C" {
12127        /// Resolved options returned by `Intl.DateTimeFormat.prototype.resolvedOptions()`.
12128        ///
12129        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions)
12130        #[wasm_bindgen(extends = DateTimeFormatOptions)]
12131        #[derive(Clone, Debug)]
12132        pub type ResolvedDateTimeFormatOptions;
12133
12134        /// The resolved locale string.
12135        #[wasm_bindgen(method, getter = locale)]
12136        pub fn get_locale(this: &ResolvedDateTimeFormatOptions) -> JsString;
12137    }
12138
12139    // Intl.DateTimeFormatPart
12140    #[wasm_bindgen]
12141    extern "C" {
12142        /// A part of the formatted date returned by `formatToParts()`.
12143        ///
12144        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
12145        #[wasm_bindgen(extends = Object)]
12146        #[derive(Clone, Debug)]
12147        pub type DateTimeFormatPart;
12148
12149        /// The type of the part (e.g., "day", "month", "year", "literal", etc.)
12150        #[wasm_bindgen(method, getter = type)]
12151        pub fn type_(this: &DateTimeFormatPart) -> DateTimeFormatPartType;
12152
12153        /// The value of the part.
12154        #[wasm_bindgen(method, getter)]
12155        pub fn value(this: &DateTimeFormatPart) -> JsString;
12156    }
12157
12158    // Intl.DateTimeRangeFormatPart
12159    #[wasm_bindgen]
12160    extern "C" {
12161        /// A part of the formatted date range returned by `formatRangeToParts()`.
12162        ///
12163        /// Extends `DateTimeFormatPart` with a `source` property indicating whether
12164        /// the part is from the start date, end date, or shared between them.
12165        ///
12166        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
12167        #[wasm_bindgen(extends = DateTimeFormatPart)]
12168        #[derive(Clone, Debug)]
12169        pub type DateTimeRangeFormatPart;
12170
12171        /// The source of the part: "startRange", "endRange", or "shared".
12172        #[wasm_bindgen(method, getter)]
12173        pub fn source(this: &DateTimeRangeFormatPart) -> RangeSource;
12174    }
12175
12176    // Intl.DateTimeFormat
12177    #[wasm_bindgen]
12178    extern "C" {
12179        /// The `Intl.DateTimeFormat` object is a constructor for objects
12180        /// that enable language-sensitive date and time formatting.
12181        ///
12182        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
12183        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
12184        #[derive(Clone, Debug)]
12185        pub type DateTimeFormat;
12186
12187        /// The `Intl.DateTimeFormat` object is a constructor for objects
12188        /// that enable language-sensitive date and time formatting.
12189        ///
12190        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
12191        #[cfg(not(js_sys_unstable_apis))]
12192        #[wasm_bindgen(constructor, js_namespace = Intl)]
12193        pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
12194
12195        /// The `Intl.DateTimeFormat` object is a constructor for objects
12196        /// that enable language-sensitive date and time formatting.
12197        ///
12198        /// Throws a `RangeError` if locales contain invalid values.
12199        ///
12200        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
12201        #[cfg(js_sys_unstable_apis)]
12202        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12203        pub fn new(
12204            locales: &[JsString],
12205            options: &DateTimeFormatOptions,
12206        ) -> Result<DateTimeFormat, JsValue>;
12207
12208        /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
12209        /// formats a date according to the locale and formatting options of this
12210        /// Intl.DateTimeFormat object.
12211        ///
12212        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
12213        #[cfg(not(js_sys_unstable_apis))]
12214        #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
12215        pub fn format(this: &DateTimeFormat) -> Function;
12216
12217        /// Formats a date according to the locale and formatting options of this
12218        /// `Intl.DateTimeFormat` object.
12219        ///
12220        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format)
12221        #[cfg(js_sys_unstable_apis)]
12222        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat")]
12223        pub fn format(this: &DateTimeFormat, date: &Date) -> JsString;
12224
12225        /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
12226        /// formatting of strings produced by DateTimeFormat formatters.
12227        ///
12228        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
12229        #[cfg(not(js_sys_unstable_apis))]
12230        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
12231        pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
12232
12233        /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
12234        /// formatting of strings produced by DateTimeFormat formatters.
12235        ///
12236        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
12237        #[cfg(js_sys_unstable_apis)]
12238        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
12239        pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array<DateTimeFormatPart>;
12240
12241        /// The `Intl.DateTimeFormat.prototype.formatRange()` method formats a date range
12242        /// in the most concise way based on the locales and options provided when
12243        /// instantiating this `Intl.DateTimeFormat` object.
12244        ///
12245        /// Throws a `TypeError` if the dates are invalid.
12246        ///
12247        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange)
12248        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRange, catch)]
12249        pub fn format_range(
12250            this: &DateTimeFormat,
12251            start_date: &Date,
12252            end_date: &Date,
12253        ) -> Result<JsString, JsValue>;
12254
12255        /// The `Intl.DateTimeFormat.prototype.formatRangeToParts()` method returns an array
12256        /// of locale-specific tokens representing each part of the formatted date range
12257        /// produced by `Intl.DateTimeFormat` formatters.
12258        ///
12259        /// Throws a `TypeError` if the dates are invalid.
12260        ///
12261        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
12262        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRangeToParts, catch)]
12263        pub fn format_range_to_parts(
12264            this: &DateTimeFormat,
12265            start_date: &Date,
12266            end_date: &Date,
12267        ) -> Result<Array<DateTimeRangeFormatPart>, JsValue>;
12268
12269        /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
12270        /// object with properties reflecting the locale and date and time formatting
12271        /// options computed during initialization of this DateTimeFormat object.
12272        ///
12273        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
12274        #[cfg(not(js_sys_unstable_apis))]
12275        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12276        pub fn resolved_options(this: &DateTimeFormat) -> Object;
12277
12278        /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
12279        /// object with properties reflecting the locale and date and time formatting
12280        /// options computed during initialization of this DateTimeFormat object.
12281        ///
12282        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
12283        #[cfg(js_sys_unstable_apis)]
12284        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12285        pub fn resolved_options(this: &DateTimeFormat) -> ResolvedDateTimeFormatOptions;
12286
12287        /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
12288        /// containing those of the provided locales that are supported in date
12289        /// and time formatting without having to fall back to the runtime's default
12290        /// locale.
12291        ///
12292        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
12293        #[cfg(not(js_sys_unstable_apis))]
12294        #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
12295        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12296
12297        /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
12298        /// containing those of the provided locales that are supported in date
12299        /// and time formatting without having to fall back to the runtime's default
12300        /// locale.
12301        ///
12302        /// Throws a `RangeError` if locales contain invalid values.
12303        ///
12304        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
12305        #[cfg(js_sys_unstable_apis)]
12306        #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12307        pub fn supported_locales_of(
12308            locales: &[JsString],
12309            options: &LocaleMatcherOptions,
12310        ) -> Result<Array<JsString>, JsValue>;
12311    }
12312
12313    #[cfg(not(js_sys_unstable_apis))]
12314    impl Default for DateTimeFormat {
12315        fn default() -> Self {
12316            Self::new(
12317                &JsValue::UNDEFINED.unchecked_into(),
12318                &JsValue::UNDEFINED.unchecked_into(),
12319            )
12320        }
12321    }
12322
12323    #[cfg(js_sys_unstable_apis)]
12324    impl Default for DateTimeFormat {
12325        fn default() -> Self {
12326            Self::new(&[], &Default::default()).unwrap()
12327        }
12328    }
12329
12330    // Intl.NumberFormatOptions
12331    #[wasm_bindgen]
12332    extern "C" {
12333        /// Options for `Intl.NumberFormat` constructor.
12334        ///
12335        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options)
12336        #[wasm_bindgen(extends = Object)]
12337        #[derive(Clone, Debug)]
12338        pub type NumberFormatOptions;
12339
12340        // Locale matching
12341        #[wasm_bindgen(method, getter = localeMatcher)]
12342        pub fn get_locale_matcher(this: &NumberFormatOptions) -> Option<LocaleMatcher>;
12343        #[wasm_bindgen(method, setter = localeMatcher)]
12344        pub fn set_locale_matcher(this: &NumberFormatOptions, value: LocaleMatcher);
12345
12346        // Numbering system (free-form string)
12347        #[wasm_bindgen(method, getter = numberingSystem)]
12348        pub fn get_numbering_system(this: &NumberFormatOptions) -> Option<JsString>;
12349        #[wasm_bindgen(method, setter = numberingSystem)]
12350        pub fn set_numbering_system(this: &NumberFormatOptions, value: &str);
12351
12352        // Style
12353        #[wasm_bindgen(method, getter = style)]
12354        pub fn get_style(this: &NumberFormatOptions) -> Option<NumberFormatStyle>;
12355        #[wasm_bindgen(method, setter = style)]
12356        pub fn set_style(this: &NumberFormatOptions, value: NumberFormatStyle);
12357
12358        // Currency options (currency code is free-form ISO 4217 string)
12359        #[wasm_bindgen(method, getter = currency)]
12360        pub fn get_currency(this: &NumberFormatOptions) -> Option<JsString>;
12361        #[wasm_bindgen(method, setter = currency)]
12362        pub fn set_currency(this: &NumberFormatOptions, value: &str);
12363
12364        #[wasm_bindgen(method, getter = currencyDisplay)]
12365        pub fn get_currency_display(this: &NumberFormatOptions) -> Option<CurrencyDisplay>;
12366        #[wasm_bindgen(method, setter = currencyDisplay)]
12367        pub fn set_currency_display(this: &NumberFormatOptions, value: CurrencyDisplay);
12368
12369        #[wasm_bindgen(method, getter = currencySign)]
12370        pub fn get_currency_sign(this: &NumberFormatOptions) -> Option<CurrencySign>;
12371        #[wasm_bindgen(method, setter = currencySign)]
12372        pub fn set_currency_sign(this: &NumberFormatOptions, value: CurrencySign);
12373
12374        // Unit options (unit name is free-form string)
12375        #[wasm_bindgen(method, getter = unit)]
12376        pub fn get_unit(this: &NumberFormatOptions) -> Option<JsString>;
12377        #[wasm_bindgen(method, setter = unit)]
12378        pub fn set_unit(this: &NumberFormatOptions, value: &str);
12379
12380        #[wasm_bindgen(method, getter = unitDisplay)]
12381        pub fn get_unit_display(this: &NumberFormatOptions) -> Option<UnitDisplay>;
12382        #[wasm_bindgen(method, setter = unitDisplay)]
12383        pub fn set_unit_display(this: &NumberFormatOptions, value: UnitDisplay);
12384
12385        // Notation
12386        #[wasm_bindgen(method, getter = notation)]
12387        pub fn get_notation(this: &NumberFormatOptions) -> Option<NumberFormatNotation>;
12388        #[wasm_bindgen(method, setter = notation)]
12389        pub fn set_notation(this: &NumberFormatOptions, value: NumberFormatNotation);
12390
12391        #[wasm_bindgen(method, getter = compactDisplay)]
12392        pub fn get_compact_display(this: &NumberFormatOptions) -> Option<CompactDisplay>;
12393        #[wasm_bindgen(method, setter = compactDisplay)]
12394        pub fn set_compact_display(this: &NumberFormatOptions, value: CompactDisplay);
12395
12396        // Sign display
12397        #[wasm_bindgen(method, getter = signDisplay)]
12398        pub fn get_sign_display(this: &NumberFormatOptions) -> Option<SignDisplay>;
12399        #[wasm_bindgen(method, setter = signDisplay)]
12400        pub fn set_sign_display(this: &NumberFormatOptions, value: SignDisplay);
12401
12402        // Digit options
12403        #[wasm_bindgen(method, getter = minimumIntegerDigits)]
12404        pub fn get_minimum_integer_digits(this: &NumberFormatOptions) -> Option<u8>;
12405        #[wasm_bindgen(method, setter = minimumIntegerDigits)]
12406        pub fn set_minimum_integer_digits(this: &NumberFormatOptions, value: u8);
12407
12408        #[wasm_bindgen(method, getter = minimumFractionDigits)]
12409        pub fn get_minimum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
12410        #[wasm_bindgen(method, setter = minimumFractionDigits)]
12411        pub fn set_minimum_fraction_digits(this: &NumberFormatOptions, value: u8);
12412
12413        #[wasm_bindgen(method, getter = maximumFractionDigits)]
12414        pub fn get_maximum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
12415        #[wasm_bindgen(method, setter = maximumFractionDigits)]
12416        pub fn set_maximum_fraction_digits(this: &NumberFormatOptions, value: u8);
12417
12418        #[wasm_bindgen(method, getter = minimumSignificantDigits)]
12419        pub fn get_minimum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
12420        #[wasm_bindgen(method, setter = minimumSignificantDigits)]
12421        pub fn set_minimum_significant_digits(this: &NumberFormatOptions, value: u8);
12422
12423        #[wasm_bindgen(method, getter = maximumSignificantDigits)]
12424        pub fn get_maximum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
12425        #[wasm_bindgen(method, setter = maximumSignificantDigits)]
12426        pub fn set_maximum_significant_digits(this: &NumberFormatOptions, value: u8);
12427
12428        // Grouping
12429        #[wasm_bindgen(method, getter = useGrouping)]
12430        pub fn get_use_grouping(this: &NumberFormatOptions) -> Option<UseGrouping>;
12431        #[wasm_bindgen(method, setter = useGrouping)]
12432        pub fn set_use_grouping(this: &NumberFormatOptions, value: UseGrouping);
12433
12434        // Rounding
12435        #[wasm_bindgen(method, getter = roundingMode)]
12436        pub fn get_rounding_mode(this: &NumberFormatOptions) -> Option<RoundingMode>;
12437        #[wasm_bindgen(method, setter = roundingMode)]
12438        pub fn set_rounding_mode(this: &NumberFormatOptions, value: RoundingMode);
12439
12440        #[wasm_bindgen(method, getter = roundingPriority)]
12441        pub fn get_rounding_priority(this: &NumberFormatOptions) -> Option<RoundingPriority>;
12442        #[wasm_bindgen(method, setter = roundingPriority)]
12443        pub fn set_rounding_priority(this: &NumberFormatOptions, value: RoundingPriority);
12444
12445        #[wasm_bindgen(method, getter = roundingIncrement)]
12446        pub fn get_rounding_increment(this: &NumberFormatOptions) -> Option<u32>;
12447        #[wasm_bindgen(method, setter = roundingIncrement)]
12448        pub fn set_rounding_increment(this: &NumberFormatOptions, value: u32);
12449
12450        #[wasm_bindgen(method, getter = trailingZeroDisplay)]
12451        pub fn get_trailing_zero_display(this: &NumberFormatOptions)
12452            -> Option<TrailingZeroDisplay>;
12453        #[wasm_bindgen(method, setter = trailingZeroDisplay)]
12454        pub fn set_trailing_zero_display(this: &NumberFormatOptions, value: TrailingZeroDisplay);
12455    }
12456
12457    impl NumberFormatOptions {
12458        pub fn new() -> NumberFormatOptions {
12459            JsCast::unchecked_into(Object::new())
12460        }
12461    }
12462
12463    impl Default for NumberFormatOptions {
12464        fn default() -> Self {
12465            NumberFormatOptions::new()
12466        }
12467    }
12468
12469    // Intl.ResolvedNumberFormatOptions
12470    #[wasm_bindgen]
12471    extern "C" {
12472        /// Resolved options returned by `Intl.NumberFormat.prototype.resolvedOptions()`.
12473        ///
12474        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions)
12475        #[wasm_bindgen(extends = NumberFormatOptions)]
12476        #[derive(Clone, Debug)]
12477        pub type ResolvedNumberFormatOptions;
12478
12479        /// The resolved locale string.
12480        #[wasm_bindgen(method, getter = locale)]
12481        pub fn get_locale(this: &ResolvedNumberFormatOptions) -> JsString;
12482    }
12483
12484    // Intl.NumberFormatPart
12485    #[wasm_bindgen]
12486    extern "C" {
12487        /// A part of the formatted number returned by `formatToParts()`.
12488        ///
12489        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
12490        #[wasm_bindgen(extends = Object)]
12491        #[derive(Clone, Debug)]
12492        pub type NumberFormatPart;
12493
12494        /// The type of the part (e.g., "integer", "decimal", "fraction", "currency", etc.)
12495        #[wasm_bindgen(method, getter = type)]
12496        pub fn type_(this: &NumberFormatPart) -> NumberFormatPartType;
12497
12498        /// The value of the part.
12499        #[wasm_bindgen(method, getter)]
12500        pub fn value(this: &NumberFormatPart) -> JsString;
12501    }
12502
12503    // Intl.NumberRangeFormatPart
12504    #[wasm_bindgen]
12505    extern "C" {
12506        /// A part of the formatted number range returned by `formatRangeToParts()`.
12507        ///
12508        /// Extends `NumberFormatPart` with a `source` property indicating whether
12509        /// the part is from the start number, end number, or shared between them.
12510        ///
12511        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
12512        #[wasm_bindgen(extends = NumberFormatPart)]
12513        #[derive(Clone, Debug)]
12514        pub type NumberRangeFormatPart;
12515
12516        /// The source of the part: "startRange", "endRange", or "shared".
12517        #[wasm_bindgen(method, getter)]
12518        pub fn source(this: &NumberRangeFormatPart) -> RangeSource;
12519    }
12520
12521    // Intl.NumberFormat
12522    #[wasm_bindgen]
12523    extern "C" {
12524        /// The `Intl.NumberFormat` object is a constructor for objects
12525        /// that enable language sensitive number formatting.
12526        ///
12527        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
12528        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
12529        #[derive(Clone, Debug)]
12530        pub type NumberFormat;
12531
12532        /// The `Intl.NumberFormat` object is a constructor for objects
12533        /// that enable language sensitive number formatting.
12534        ///
12535        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
12536        #[cfg(not(js_sys_unstable_apis))]
12537        #[wasm_bindgen(constructor, js_namespace = Intl)]
12538        pub fn new(locales: &Array, options: &Object) -> NumberFormat;
12539
12540        /// The `Intl.NumberFormat` object is a constructor for objects
12541        /// that enable language sensitive number formatting.
12542        ///
12543        /// Throws a `RangeError` if locales contain invalid values.
12544        ///
12545        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
12546        #[cfg(js_sys_unstable_apis)]
12547        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12548        pub fn new(
12549            locales: &[JsString],
12550            options: &NumberFormatOptions,
12551        ) -> Result<NumberFormat, JsValue>;
12552
12553        /// The Intl.NumberFormat.prototype.format property returns a getter function that
12554        /// formats a number according to the locale and formatting options of this
12555        /// NumberFormat object.
12556        ///
12557        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
12558        #[cfg(not(js_sys_unstable_apis))]
12559        #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
12560        pub fn format(this: &NumberFormat) -> Function;
12561
12562        /// Formats a number according to the locale and formatting options of this
12563        /// `Intl.NumberFormat` object.
12564        ///
12565        /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
12566        /// or use E notation: `"1000000E-6"` → `"1"`).
12567        ///
12568        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format)
12569        #[cfg(js_sys_unstable_apis)]
12570        #[wasm_bindgen(method, js_class = "Intl.NumberFormat")]
12571        pub fn format(this: &NumberFormat, value: &JsString) -> JsString;
12572
12573        /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
12574        /// formatting of strings produced by NumberTimeFormat formatters.
12575        ///
12576        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
12577        #[cfg(not(js_sys_unstable_apis))]
12578        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
12579        pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
12580
12581        /// The `Intl.NumberFormat.prototype.formatToParts()` method allows locale-aware
12582        /// formatting of strings produced by `Intl.NumberFormat` formatters.
12583        ///
12584        /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
12585        /// or use E notation: `"1000000E-6"` → `"1"`).
12586        ///
12587        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
12588        #[cfg(js_sys_unstable_apis)]
12589        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
12590        pub fn format_to_parts(this: &NumberFormat, value: &JsString) -> Array<NumberFormatPart>;
12591
12592        /// Formats a range of numbers according to the locale and formatting options
12593        /// of this `Intl.NumberFormat` object.
12594        ///
12595        /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
12596        /// or use E notation: `"1000000E-6"` → `"1"`).
12597        ///
12598        /// Throws a `TypeError` if the values are invalid.
12599        ///
12600        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange)
12601        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRange, catch)]
12602        pub fn format_range(
12603            this: &NumberFormat,
12604            start: &JsString,
12605            end: &JsString,
12606        ) -> Result<JsString, JsValue>;
12607
12608        /// Returns an array of locale-specific tokens representing each part of
12609        /// the formatted number range.
12610        ///
12611        /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
12612        /// or use E notation: `"1000000E-6"` → `"1"`).
12613        ///
12614        /// Throws a `TypeError` if the values are invalid.
12615        ///
12616        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
12617        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRangeToParts, catch)]
12618        pub fn format_range_to_parts(
12619            this: &NumberFormat,
12620            start: &JsString,
12621            end: &JsString,
12622        ) -> Result<Array<NumberRangeFormatPart>, JsValue>;
12623
12624        /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
12625        /// object with properties reflecting the locale and number formatting
12626        /// options computed during initialization of this NumberFormat object.
12627        ///
12628        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
12629        #[cfg(not(js_sys_unstable_apis))]
12630        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12631        pub fn resolved_options(this: &NumberFormat) -> Object;
12632
12633        /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
12634        /// object with properties reflecting the locale and number formatting
12635        /// options computed during initialization of this NumberFormat object.
12636        ///
12637        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
12638        #[cfg(js_sys_unstable_apis)]
12639        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12640        pub fn resolved_options(this: &NumberFormat) -> ResolvedNumberFormatOptions;
12641
12642        /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
12643        /// containing those of the provided locales that are supported in number
12644        /// formatting without having to fall back to the runtime's default locale.
12645        ///
12646        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
12647        #[cfg(not(js_sys_unstable_apis))]
12648        #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
12649        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12650
12651        /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
12652        /// containing those of the provided locales that are supported in number
12653        /// formatting without having to fall back to the runtime's default locale.
12654        ///
12655        /// Throws a `RangeError` if locales contain invalid values.
12656        ///
12657        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
12658        #[cfg(js_sys_unstable_apis)]
12659        #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12660        pub fn supported_locales_of(
12661            locales: &[JsString],
12662            options: &LocaleMatcherOptions,
12663        ) -> Result<Array<JsString>, JsValue>;
12664    }
12665
12666    #[cfg(not(js_sys_unstable_apis))]
12667    impl Default for NumberFormat {
12668        fn default() -> Self {
12669            Self::new(
12670                &JsValue::UNDEFINED.unchecked_into(),
12671                &JsValue::UNDEFINED.unchecked_into(),
12672            )
12673        }
12674    }
12675
12676    #[cfg(js_sys_unstable_apis)]
12677    impl Default for NumberFormat {
12678        fn default() -> Self {
12679            Self::new(&[], &Default::default()).unwrap()
12680        }
12681    }
12682
12683    // Intl.PluralRulesOptions
12684    #[wasm_bindgen]
12685    extern "C" {
12686        /// Options for `Intl.PluralRules` constructor.
12687        ///
12688        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#options)
12689        #[wasm_bindgen(extends = Object)]
12690        #[derive(Clone, Debug)]
12691        pub type PluralRulesOptions;
12692
12693        #[wasm_bindgen(method, getter = localeMatcher)]
12694        pub fn get_locale_matcher(this: &PluralRulesOptions) -> Option<LocaleMatcher>;
12695        #[wasm_bindgen(method, setter = localeMatcher)]
12696        pub fn set_locale_matcher(this: &PluralRulesOptions, value: LocaleMatcher);
12697
12698        #[wasm_bindgen(method, getter = type)]
12699        pub fn get_type(this: &PluralRulesOptions) -> Option<PluralRulesType>;
12700        #[wasm_bindgen(method, setter = type)]
12701        pub fn set_type(this: &PluralRulesOptions, value: PluralRulesType);
12702
12703        #[wasm_bindgen(method, getter = minimumIntegerDigits)]
12704        pub fn get_minimum_integer_digits(this: &PluralRulesOptions) -> Option<u8>;
12705        #[wasm_bindgen(method, setter = minimumIntegerDigits)]
12706        pub fn set_minimum_integer_digits(this: &PluralRulesOptions, value: u8);
12707
12708        #[wasm_bindgen(method, getter = minimumFractionDigits)]
12709        pub fn get_minimum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
12710        #[wasm_bindgen(method, setter = minimumFractionDigits)]
12711        pub fn set_minimum_fraction_digits(this: &PluralRulesOptions, value: u8);
12712
12713        #[wasm_bindgen(method, getter = maximumFractionDigits)]
12714        pub fn get_maximum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
12715        #[wasm_bindgen(method, setter = maximumFractionDigits)]
12716        pub fn set_maximum_fraction_digits(this: &PluralRulesOptions, value: u8);
12717
12718        #[wasm_bindgen(method, getter = minimumSignificantDigits)]
12719        pub fn get_minimum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
12720        #[wasm_bindgen(method, setter = minimumSignificantDigits)]
12721        pub fn set_minimum_significant_digits(this: &PluralRulesOptions, value: u8);
12722
12723        #[wasm_bindgen(method, getter = maximumSignificantDigits)]
12724        pub fn get_maximum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
12725        #[wasm_bindgen(method, setter = maximumSignificantDigits)]
12726        pub fn set_maximum_significant_digits(this: &PluralRulesOptions, value: u8);
12727
12728        #[wasm_bindgen(method, getter = roundingPriority)]
12729        pub fn get_rounding_priority(this: &PluralRulesOptions) -> Option<RoundingPriority>;
12730        #[wasm_bindgen(method, setter = roundingPriority)]
12731        pub fn set_rounding_priority(this: &PluralRulesOptions, value: RoundingPriority);
12732
12733        #[wasm_bindgen(method, getter = roundingIncrement)]
12734        pub fn get_rounding_increment(this: &PluralRulesOptions) -> Option<u32>;
12735        #[wasm_bindgen(method, setter = roundingIncrement)]
12736        pub fn set_rounding_increment(this: &PluralRulesOptions, value: u32);
12737
12738        #[wasm_bindgen(method, getter = roundingMode)]
12739        pub fn get_rounding_mode(this: &PluralRulesOptions) -> Option<RoundingMode>;
12740        #[wasm_bindgen(method, setter = roundingMode)]
12741        pub fn set_rounding_mode(this: &PluralRulesOptions, value: RoundingMode);
12742
12743        #[wasm_bindgen(method, getter = trailingZeroDisplay)]
12744        pub fn get_trailing_zero_display(this: &PluralRulesOptions) -> Option<TrailingZeroDisplay>;
12745        #[wasm_bindgen(method, setter = trailingZeroDisplay)]
12746        pub fn set_trailing_zero_display(this: &PluralRulesOptions, value: TrailingZeroDisplay);
12747    }
12748
12749    impl PluralRulesOptions {
12750        pub fn new() -> PluralRulesOptions {
12751            JsCast::unchecked_into(Object::new())
12752        }
12753    }
12754
12755    impl Default for PluralRulesOptions {
12756        fn default() -> Self {
12757            PluralRulesOptions::new()
12758        }
12759    }
12760
12761    // Intl.ResolvedPluralRulesOptions
12762    #[wasm_bindgen]
12763    extern "C" {
12764        /// Resolved options returned by `Intl.PluralRules.prototype.resolvedOptions()`.
12765        ///
12766        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/resolvedOptions)
12767        #[wasm_bindgen(extends = PluralRulesOptions)]
12768        #[derive(Clone, Debug)]
12769        pub type ResolvedPluralRulesOptions;
12770
12771        /// The resolved locale string.
12772        #[wasm_bindgen(method, getter = locale)]
12773        pub fn get_locale(this: &ResolvedPluralRulesOptions) -> JsString;
12774
12775        /// The plural categories used by the locale.
12776        #[wasm_bindgen(method, getter = pluralCategories)]
12777        pub fn get_plural_categories(this: &ResolvedPluralRulesOptions) -> Array<JsString>;
12778    }
12779
12780    // Intl.PluralRules
12781    #[wasm_bindgen]
12782    extern "C" {
12783        /// The `Intl.PluralRules` object is a constructor for objects
12784        /// that enable plural sensitive formatting and plural language rules.
12785        ///
12786        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
12787        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
12788        #[derive(Clone, Debug)]
12789        pub type PluralRules;
12790
12791        /// The `Intl.PluralRules` object is a constructor for objects
12792        /// that enable plural sensitive formatting and plural language rules.
12793        ///
12794        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
12795        #[cfg(not(js_sys_unstable_apis))]
12796        #[wasm_bindgen(constructor, js_namespace = Intl)]
12797        pub fn new(locales: &Array, options: &Object) -> PluralRules;
12798
12799        /// The `Intl.PluralRules` object is a constructor for objects
12800        /// that enable plural sensitive formatting and plural language rules.
12801        ///
12802        /// Throws a `RangeError` if locales contain invalid values.
12803        ///
12804        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
12805        #[cfg(js_sys_unstable_apis)]
12806        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12807        pub fn new(
12808            locales: &[JsString],
12809            options: &PluralRulesOptions,
12810        ) -> Result<PluralRules, JsValue>;
12811
12812        /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
12813        /// object with properties reflecting the locale and plural formatting
12814        /// options computed during initialization of this PluralRules object.
12815        ///
12816        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
12817        #[cfg(not(js_sys_unstable_apis))]
12818        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12819        pub fn resolved_options(this: &PluralRules) -> Object;
12820
12821        /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
12822        /// object with properties reflecting the locale and plural formatting
12823        /// options computed during initialization of this PluralRules object.
12824        ///
12825        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
12826        #[cfg(js_sys_unstable_apis)]
12827        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12828        pub fn resolved_options(this: &PluralRules) -> ResolvedPluralRulesOptions;
12829
12830        /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
12831        /// which plural rule to use for locale-aware formatting.
12832        ///
12833        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
12834        #[cfg(not(js_sys_unstable_apis))]
12835        #[wasm_bindgen(method, js_namespace = Intl)]
12836        pub fn select(this: &PluralRules, number: f64) -> JsString;
12837
12838        /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
12839        /// which plural rule to use for locale-aware formatting.
12840        ///
12841        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
12842        #[cfg(js_sys_unstable_apis)]
12843        #[wasm_bindgen(method, js_namespace = Intl)]
12844        pub fn select(this: &PluralRules, number: f64) -> PluralCategory;
12845
12846        /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
12847        /// which plural rule to use for locale-aware formatting of a range of numbers.
12848        ///
12849        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
12850        #[cfg(not(js_sys_unstable_apis))]
12851        #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
12852        pub fn select_range(this: &PluralRules, start: f64, end: f64) -> JsString;
12853
12854        /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
12855        /// which plural rule to use for locale-aware formatting of a range of numbers.
12856        ///
12857        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
12858        #[cfg(js_sys_unstable_apis)]
12859        #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
12860        pub fn select_range(this: &PluralRules, start: f64, end: f64) -> PluralCategory;
12861
12862        /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
12863        /// containing those of the provided locales that are supported in plural
12864        /// formatting without having to fall back to the runtime's default locale.
12865        ///
12866        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
12867        #[cfg(not(js_sys_unstable_apis))]
12868        #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
12869        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12870
12871        /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
12872        /// containing those of the provided locales that are supported in plural
12873        /// formatting without having to fall back to the runtime's default locale.
12874        ///
12875        /// Throws a `RangeError` if locales contain invalid values.
12876        ///
12877        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
12878        #[cfg(js_sys_unstable_apis)]
12879        #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12880        pub fn supported_locales_of(
12881            locales: &[JsString],
12882            options: &LocaleMatcherOptions,
12883        ) -> Result<Array<JsString>, JsValue>;
12884    }
12885
12886    #[cfg(not(js_sys_unstable_apis))]
12887    impl Default for PluralRules {
12888        fn default() -> Self {
12889            Self::new(
12890                &JsValue::UNDEFINED.unchecked_into(),
12891                &JsValue::UNDEFINED.unchecked_into(),
12892            )
12893        }
12894    }
12895
12896    #[cfg(js_sys_unstable_apis)]
12897    impl Default for PluralRules {
12898        fn default() -> Self {
12899            Self::new(&[], &Default::default()).unwrap()
12900        }
12901    }
12902
12903    // Intl.RelativeTimeFormat
12904    #[wasm_bindgen]
12905    extern "C" {
12906        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
12907        /// that enable language-sensitive relative time formatting.
12908        ///
12909        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
12910        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
12911        #[derive(Clone, Debug)]
12912        pub type RelativeTimeFormat;
12913
12914        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
12915        /// that enable language-sensitive relative time formatting.
12916        ///
12917        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
12918        #[cfg(not(js_sys_unstable_apis))]
12919        #[wasm_bindgen(constructor, js_namespace = Intl)]
12920        pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
12921
12922        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
12923        /// that enable language-sensitive relative time formatting.
12924        ///
12925        /// Throws a `RangeError` if locales contain invalid values.
12926        ///
12927        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
12928        #[cfg(js_sys_unstable_apis)]
12929        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12930        pub fn new(locales: &[JsString]) -> Result<RelativeTimeFormat, JsValue>;
12931
12932        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
12933        /// that enable language-sensitive relative time formatting.
12934        ///
12935        /// Throws a `RangeError` if locales or options contain invalid values.
12936        ///
12937        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
12938        #[cfg(js_sys_unstable_apis)]
12939        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12940        pub fn new_with_options(
12941            locales: &[JsString],
12942            options: &RelativeTimeFormatOptions,
12943        ) -> Result<RelativeTimeFormat, JsValue>;
12944
12945        /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
12946        /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
12947        ///
12948        /// Throws a `RangeError` if unit is invalid.
12949        ///
12950        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
12951        #[cfg(not(js_sys_unstable_apis))]
12952        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
12953        pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
12954
12955        /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
12956        /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
12957        ///
12958        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
12959        #[cfg(js_sys_unstable_apis)]
12960        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
12961        pub fn format(
12962            this: &RelativeTimeFormat,
12963            value: f64,
12964            unit: RelativeTimeFormatUnit,
12965        ) -> JsString;
12966
12967        /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
12968        /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
12969        ///
12970        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
12971        #[cfg(not(js_sys_unstable_apis))]
12972        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
12973        pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
12974
12975        /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
12976        /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
12977        ///
12978        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
12979        #[cfg(js_sys_unstable_apis)]
12980        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
12981        pub fn format_to_parts(
12982            this: &RelativeTimeFormat,
12983            value: f64,
12984            unit: RelativeTimeFormatUnit,
12985        ) -> Array<RelativeTimeFormatPart>;
12986
12987        /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
12988        /// object with properties reflecting the locale and relative time formatting
12989        /// options computed during initialization of this RelativeTimeFormat object.
12990        ///
12991        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
12992        #[cfg(not(js_sys_unstable_apis))]
12993        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12994        pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
12995
12996        /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
12997        /// object with properties reflecting the locale and relative time formatting
12998        /// options computed during initialization of this RelativeTimeFormat object.
12999        ///
13000        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
13001        #[cfg(js_sys_unstable_apis)]
13002        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13003        pub fn resolved_options(this: &RelativeTimeFormat) -> ResolvedRelativeTimeFormatOptions;
13004
13005        /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
13006        /// containing those of the provided locales that are supported in date and time
13007        /// formatting without having to fall back to the runtime's default locale.
13008        ///
13009        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
13010        #[cfg(not(js_sys_unstable_apis))]
13011        #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
13012        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
13013
13014        /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
13015        /// containing those of the provided locales that are supported in date and time
13016        /// formatting without having to fall back to the runtime's default locale.
13017        ///
13018        /// Throws a `RangeError` if locales contain invalid values.
13019        ///
13020        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
13021        #[cfg(js_sys_unstable_apis)]
13022        #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13023        pub fn supported_locales_of(
13024            locales: &[JsString],
13025            options: &LocaleMatcherOptions,
13026        ) -> Result<Array<JsString>, JsValue>;
13027    }
13028
13029    #[cfg(not(js_sys_unstable_apis))]
13030    impl Default for RelativeTimeFormat {
13031        fn default() -> Self {
13032            Self::new(
13033                &JsValue::UNDEFINED.unchecked_into(),
13034                &JsValue::UNDEFINED.unchecked_into(),
13035            )
13036        }
13037    }
13038
13039    #[cfg(js_sys_unstable_apis)]
13040    impl Default for RelativeTimeFormat {
13041        fn default() -> Self {
13042            Self::new(&[]).unwrap()
13043        }
13044    }
13045
13046    // Intl.ListFormatOptions
13047    #[wasm_bindgen]
13048    extern "C" {
13049        /// Options for `Intl.ListFormat` constructor.
13050        ///
13051        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#options)
13052        #[wasm_bindgen(extends = Object)]
13053        #[derive(Clone, Debug)]
13054        pub type ListFormatOptions;
13055
13056        #[wasm_bindgen(method, getter = localeMatcher)]
13057        pub fn get_locale_matcher(this: &ListFormatOptions) -> Option<LocaleMatcher>;
13058        #[wasm_bindgen(method, setter = localeMatcher)]
13059        pub fn set_locale_matcher(this: &ListFormatOptions, value: LocaleMatcher);
13060
13061        #[wasm_bindgen(method, getter = type)]
13062        pub fn get_type(this: &ListFormatOptions) -> Option<ListFormatType>;
13063        #[wasm_bindgen(method, setter = type)]
13064        pub fn set_type(this: &ListFormatOptions, value: ListFormatType);
13065
13066        #[wasm_bindgen(method, getter = style)]
13067        pub fn get_style(this: &ListFormatOptions) -> Option<ListFormatStyle>;
13068        #[wasm_bindgen(method, setter = style)]
13069        pub fn set_style(this: &ListFormatOptions, value: ListFormatStyle);
13070    }
13071
13072    impl ListFormatOptions {
13073        pub fn new() -> ListFormatOptions {
13074            JsCast::unchecked_into(Object::new())
13075        }
13076    }
13077
13078    impl Default for ListFormatOptions {
13079        fn default() -> Self {
13080            ListFormatOptions::new()
13081        }
13082    }
13083
13084    // Intl.ResolvedListFormatOptions
13085    #[wasm_bindgen]
13086    extern "C" {
13087        /// Resolved options returned by `Intl.ListFormat.prototype.resolvedOptions()`.
13088        ///
13089        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
13090        #[wasm_bindgen(extends = ListFormatOptions)]
13091        #[derive(Clone, Debug)]
13092        pub type ResolvedListFormatOptions;
13093
13094        /// The resolved locale string.
13095        #[wasm_bindgen(method, getter = locale)]
13096        pub fn get_locale(this: &ResolvedListFormatOptions) -> JsString;
13097    }
13098
13099    // Intl.ListFormatPart
13100    #[wasm_bindgen]
13101    extern "C" {
13102        /// A part of the formatted list returned by `formatToParts()`.
13103        ///
13104        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
13105        #[wasm_bindgen(extends = Object)]
13106        #[derive(Clone, Debug)]
13107        pub type ListFormatPart;
13108
13109        /// The type of the part ("element" or "literal").
13110        #[wasm_bindgen(method, getter = type)]
13111        pub fn type_(this: &ListFormatPart) -> ListFormatPartType;
13112
13113        /// The value of the part.
13114        #[wasm_bindgen(method, getter)]
13115        pub fn value(this: &ListFormatPart) -> JsString;
13116    }
13117
13118    // Intl.ListFormat
13119    #[wasm_bindgen]
13120    extern "C" {
13121        /// The `Intl.ListFormat` object enables language-sensitive list formatting.
13122        ///
13123        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat)
13124        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.ListFormat")]
13125        #[derive(Clone, Debug)]
13126        pub type ListFormat;
13127
13128        /// Creates a new `Intl.ListFormat` object.
13129        ///
13130        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
13131        #[cfg(not(js_sys_unstable_apis))]
13132        #[wasm_bindgen(constructor, js_namespace = Intl)]
13133        pub fn new(locales: &Array, options: &Object) -> ListFormat;
13134
13135        /// Creates a new `Intl.ListFormat` object.
13136        ///
13137        /// Throws a `RangeError` if locales or options contain invalid values.
13138        ///
13139        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
13140        #[cfg(js_sys_unstable_apis)]
13141        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13142        pub fn new(
13143            locales: &[JsString],
13144            options: &ListFormatOptions,
13145        ) -> Result<ListFormat, JsValue>;
13146
13147        /// Formats a list of strings according to the locale and options.
13148        ///
13149        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
13150        #[cfg(not(js_sys_unstable_apis))]
13151        #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
13152        pub fn format(this: &ListFormat, list: &Array) -> JsString;
13153
13154        /// Formats a list of strings according to the locale and options.
13155        ///
13156        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
13157        #[cfg(js_sys_unstable_apis)]
13158        #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
13159        pub fn format(this: &ListFormat, list: &[JsString]) -> JsString;
13160
13161        /// Returns an array of objects representing the list in parts.
13162        ///
13163        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
13164        #[cfg(not(js_sys_unstable_apis))]
13165        #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
13166        pub fn format_to_parts(this: &ListFormat, list: &Array) -> Array;
13167
13168        /// Returns an array of objects representing the list in parts.
13169        ///
13170        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
13171        #[cfg(js_sys_unstable_apis)]
13172        #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
13173        pub fn format_to_parts(this: &ListFormat, list: &[JsString]) -> Array<ListFormatPart>;
13174
13175        /// Returns an object with properties reflecting the options used.
13176        ///
13177        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
13178        #[cfg(not(js_sys_unstable_apis))]
13179        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13180        pub fn resolved_options(this: &ListFormat) -> Object;
13181
13182        /// Returns an object with properties reflecting the options used.
13183        ///
13184        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
13185        #[cfg(js_sys_unstable_apis)]
13186        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13187        pub fn resolved_options(this: &ListFormat) -> ResolvedListFormatOptions;
13188
13189        /// Returns an array of supported locales.
13190        ///
13191        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
13192        #[cfg(not(js_sys_unstable_apis))]
13193        #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
13194        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
13195
13196        /// Returns an array of supported locales.
13197        ///
13198        /// Throws a `RangeError` if locales contain invalid values.
13199        ///
13200        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
13201        #[cfg(js_sys_unstable_apis)]
13202        #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13203        pub fn supported_locales_of(
13204            locales: &[JsString],
13205            options: &LocaleMatcherOptions,
13206        ) -> Result<Array<JsString>, JsValue>;
13207    }
13208
13209    #[cfg(not(js_sys_unstable_apis))]
13210    impl Default for ListFormat {
13211        fn default() -> Self {
13212            Self::new(
13213                &JsValue::UNDEFINED.unchecked_into(),
13214                &JsValue::UNDEFINED.unchecked_into(),
13215            )
13216        }
13217    }
13218
13219    #[cfg(js_sys_unstable_apis)]
13220    impl Default for ListFormat {
13221        fn default() -> Self {
13222            Self::new(&[], &Default::default()).unwrap()
13223        }
13224    }
13225
13226    // Intl.SegmenterOptions
13227    #[wasm_bindgen]
13228    extern "C" {
13229        /// Options for `Intl.Segmenter` constructor.
13230        ///
13231        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#options)
13232        #[wasm_bindgen(extends = Object)]
13233        #[derive(Clone, Debug)]
13234        pub type SegmenterOptions;
13235
13236        #[wasm_bindgen(method, getter = localeMatcher)]
13237        pub fn get_locale_matcher(this: &SegmenterOptions) -> Option<LocaleMatcher>;
13238        #[wasm_bindgen(method, setter = localeMatcher)]
13239        pub fn set_locale_matcher(this: &SegmenterOptions, value: LocaleMatcher);
13240
13241        #[wasm_bindgen(method, getter = granularity)]
13242        pub fn get_granularity(this: &SegmenterOptions) -> Option<SegmenterGranularity>;
13243        #[wasm_bindgen(method, setter = granularity)]
13244        pub fn set_granularity(this: &SegmenterOptions, value: SegmenterGranularity);
13245    }
13246
13247    impl SegmenterOptions {
13248        pub fn new() -> SegmenterOptions {
13249            JsCast::unchecked_into(Object::new())
13250        }
13251    }
13252
13253    impl Default for SegmenterOptions {
13254        fn default() -> Self {
13255            SegmenterOptions::new()
13256        }
13257    }
13258
13259    // Intl.ResolvedSegmenterOptions
13260    #[wasm_bindgen]
13261    extern "C" {
13262        /// Resolved options returned by `Intl.Segmenter.prototype.resolvedOptions()`.
13263        ///
13264        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
13265        #[wasm_bindgen(extends = SegmenterOptions)]
13266        #[derive(Clone, Debug)]
13267        pub type ResolvedSegmenterOptions;
13268
13269        /// The resolved locale string.
13270        #[wasm_bindgen(method, getter = locale)]
13271        pub fn get_locale(this: &ResolvedSegmenterOptions) -> JsString;
13272    }
13273
13274    // Intl.SegmentData
13275    #[wasm_bindgen]
13276    extern "C" {
13277        /// Data about a segment returned by the Segments iterator.
13278        ///
13279        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments#segment_data)
13280        #[wasm_bindgen(extends = Object)]
13281        #[derive(Clone, Debug)]
13282        pub type SegmentData;
13283
13284        /// The segment string.
13285        #[wasm_bindgen(method, getter)]
13286        pub fn segment(this: &SegmentData) -> JsString;
13287
13288        /// The index of the segment in the original string.
13289        #[wasm_bindgen(method, getter)]
13290        pub fn index(this: &SegmentData) -> u32;
13291
13292        /// The original input string.
13293        #[wasm_bindgen(method, getter)]
13294        pub fn input(this: &SegmentData) -> JsString;
13295
13296        /// Whether the segment is word-like (only for word granularity).
13297        #[wasm_bindgen(method, getter = isWordLike)]
13298        pub fn is_word_like(this: &SegmentData) -> Option<bool>;
13299    }
13300
13301    // Intl.Segments
13302    #[wasm_bindgen]
13303    extern "C" {
13304        /// The Segments object is an iterable collection of segments of a string.
13305        ///
13306        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments)
13307        #[wasm_bindgen(extends = Object)]
13308        #[derive(Clone, Debug)]
13309        pub type Segments;
13310
13311        /// Returns segment data for the segment containing the character at the given index.
13312        ///
13313        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments/containing)
13314        #[wasm_bindgen(method)]
13315        pub fn containing(this: &Segments, index: u32) -> Option<SegmentData>;
13316    }
13317
13318    // Intl.Segmenter
13319    #[wasm_bindgen]
13320    extern "C" {
13321        /// The `Intl.Segmenter` object enables locale-sensitive text segmentation.
13322        ///
13323        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter)
13324        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Segmenter")]
13325        #[derive(Clone, Debug)]
13326        pub type Segmenter;
13327
13328        /// Creates a new `Intl.Segmenter` object.
13329        ///
13330        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
13331        #[cfg(not(js_sys_unstable_apis))]
13332        #[wasm_bindgen(constructor, js_namespace = Intl)]
13333        pub fn new(locales: &Array, options: &Object) -> Segmenter;
13334
13335        /// Creates a new `Intl.Segmenter` object.
13336        ///
13337        /// Throws a `RangeError` if locales or options contain invalid values.
13338        ///
13339        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
13340        #[cfg(js_sys_unstable_apis)]
13341        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13342        pub fn new(locales: &[JsString], options: &SegmenterOptions) -> Result<Segmenter, JsValue>;
13343
13344        /// Returns a Segments object containing the segments of the input string.
13345        ///
13346        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment)
13347        #[wasm_bindgen(method, js_class = "Intl.Segmenter")]
13348        pub fn segment(this: &Segmenter, input: &str) -> Segments;
13349
13350        /// Returns an object with properties reflecting the options used.
13351        ///
13352        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
13353        #[cfg(not(js_sys_unstable_apis))]
13354        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13355        pub fn resolved_options(this: &Segmenter) -> Object;
13356
13357        /// Returns an object with properties reflecting the options used.
13358        ///
13359        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
13360        #[cfg(js_sys_unstable_apis)]
13361        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13362        pub fn resolved_options(this: &Segmenter) -> ResolvedSegmenterOptions;
13363
13364        /// Returns an array of supported locales.
13365        ///
13366        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
13367        #[cfg(not(js_sys_unstable_apis))]
13368        #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf)]
13369        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
13370
13371        /// Returns an array of supported locales.
13372        ///
13373        /// Throws a `RangeError` if locales contain invalid values.
13374        ///
13375        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
13376        #[cfg(js_sys_unstable_apis)]
13377        #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13378        pub fn supported_locales_of(
13379            locales: &[JsString],
13380            options: &LocaleMatcherOptions,
13381        ) -> Result<Array<JsString>, JsValue>;
13382    }
13383
13384    #[cfg(not(js_sys_unstable_apis))]
13385    impl Default for Segmenter {
13386        fn default() -> Self {
13387            Self::new(
13388                &JsValue::UNDEFINED.unchecked_into(),
13389                &JsValue::UNDEFINED.unchecked_into(),
13390            )
13391        }
13392    }
13393
13394    #[cfg(js_sys_unstable_apis)]
13395    impl Default for Segmenter {
13396        fn default() -> Self {
13397            Self::new(&[], &Default::default()).unwrap()
13398        }
13399    }
13400
13401    // Intl.DisplayNamesOptions
13402    #[wasm_bindgen]
13403    extern "C" {
13404        /// Options for `Intl.DisplayNames` constructor.
13405        ///
13406        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options)
13407        #[wasm_bindgen(extends = Object)]
13408        #[derive(Clone, Debug)]
13409        pub type DisplayNamesOptions;
13410
13411        #[wasm_bindgen(method, getter = localeMatcher)]
13412        pub fn get_locale_matcher(this: &DisplayNamesOptions) -> Option<LocaleMatcher>;
13413        #[wasm_bindgen(method, setter = localeMatcher)]
13414        pub fn set_locale_matcher(this: &DisplayNamesOptions, value: LocaleMatcher);
13415
13416        #[wasm_bindgen(method, getter = type)]
13417        pub fn get_type(this: &DisplayNamesOptions) -> Option<DisplayNamesType>;
13418        #[wasm_bindgen(method, setter = type)]
13419        pub fn set_type(this: &DisplayNamesOptions, value: DisplayNamesType);
13420
13421        #[wasm_bindgen(method, getter = style)]
13422        pub fn get_style(this: &DisplayNamesOptions) -> Option<DisplayNamesStyle>;
13423        #[wasm_bindgen(method, setter = style)]
13424        pub fn set_style(this: &DisplayNamesOptions, value: DisplayNamesStyle);
13425
13426        #[wasm_bindgen(method, getter = fallback)]
13427        pub fn get_fallback(this: &DisplayNamesOptions) -> Option<DisplayNamesFallback>;
13428        #[wasm_bindgen(method, setter = fallback)]
13429        pub fn set_fallback(this: &DisplayNamesOptions, value: DisplayNamesFallback);
13430
13431        #[wasm_bindgen(method, getter = languageDisplay)]
13432        pub fn get_language_display(
13433            this: &DisplayNamesOptions,
13434        ) -> Option<DisplayNamesLanguageDisplay>;
13435        #[wasm_bindgen(method, setter = languageDisplay)]
13436        pub fn set_language_display(this: &DisplayNamesOptions, value: DisplayNamesLanguageDisplay);
13437    }
13438
13439    impl DisplayNamesOptions {
13440        pub fn new() -> DisplayNamesOptions {
13441            JsCast::unchecked_into(Object::new())
13442        }
13443    }
13444
13445    impl Default for DisplayNamesOptions {
13446        fn default() -> Self {
13447            DisplayNamesOptions::new()
13448        }
13449    }
13450
13451    // Intl.ResolvedDisplayNamesOptions
13452    #[wasm_bindgen]
13453    extern "C" {
13454        /// Resolved options returned by `Intl.DisplayNames.prototype.resolvedOptions()`.
13455        ///
13456        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
13457        #[wasm_bindgen(extends = DisplayNamesOptions)]
13458        #[derive(Clone, Debug)]
13459        pub type ResolvedDisplayNamesOptions;
13460
13461        /// The resolved locale string.
13462        #[wasm_bindgen(method, getter = locale)]
13463        pub fn get_locale(this: &ResolvedDisplayNamesOptions) -> JsString;
13464    }
13465
13466    // Intl.DisplayNames
13467    #[wasm_bindgen]
13468    extern "C" {
13469        /// The `Intl.DisplayNames` object enables the consistent translation of
13470        /// language, region, and script display names.
13471        ///
13472        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
13473        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DisplayNames")]
13474        #[derive(Clone, Debug)]
13475        pub type DisplayNames;
13476
13477        /// Creates a new `Intl.DisplayNames` object.
13478        ///
13479        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
13480        #[cfg(not(js_sys_unstable_apis))]
13481        #[wasm_bindgen(constructor, js_namespace = Intl)]
13482        pub fn new(locales: &Array, options: &Object) -> DisplayNames;
13483
13484        /// Creates a new `Intl.DisplayNames` object.
13485        ///
13486        /// Throws a `RangeError` if locales or options contain invalid values.
13487        ///
13488        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
13489        #[cfg(js_sys_unstable_apis)]
13490        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13491        pub fn new(
13492            locales: &[JsString],
13493            options: &DisplayNamesOptions,
13494        ) -> Result<DisplayNames, JsValue>;
13495
13496        /// Returns the display name for the given code.
13497        ///
13498        /// Returns `undefined` if fallback is "none" and no name is available.
13499        ///
13500        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of)
13501        #[wasm_bindgen(method, js_class = "Intl.DisplayNames")]
13502        pub fn of(this: &DisplayNames, code: &str) -> Option<JsString>;
13503
13504        /// Returns an object with properties reflecting the options used.
13505        ///
13506        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
13507        #[cfg(not(js_sys_unstable_apis))]
13508        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13509        pub fn resolved_options(this: &DisplayNames) -> Object;
13510
13511        /// Returns an object with properties reflecting the options used.
13512        ///
13513        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
13514        #[cfg(js_sys_unstable_apis)]
13515        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13516        pub fn resolved_options(this: &DisplayNames) -> ResolvedDisplayNamesOptions;
13517
13518        /// Returns an array of supported locales.
13519        ///
13520        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
13521        #[cfg(not(js_sys_unstable_apis))]
13522        #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf)]
13523        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
13524
13525        /// Returns an array of supported locales.
13526        ///
13527        /// Throws a `RangeError` if locales contain invalid values.
13528        ///
13529        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
13530        #[cfg(js_sys_unstable_apis)]
13531        #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13532        pub fn supported_locales_of(
13533            locales: &[JsString],
13534            options: &LocaleMatcherOptions,
13535        ) -> Result<Array<JsString>, JsValue>;
13536    }
13537
13538    // Intl.Locale
13539    #[wasm_bindgen]
13540    extern "C" {
13541        /// The `Intl.Locale` object is a standard built-in property of the Intl object
13542        /// that represents a Unicode locale identifier.
13543        ///
13544        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
13545        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Locale")]
13546        #[derive(Clone, Debug)]
13547        pub type Locale;
13548
13549        /// Creates a new `Intl.Locale` object.
13550        ///
13551        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
13552        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13553        pub fn new(tag: &str) -> Result<Locale, JsValue>;
13554
13555        /// Creates a new `Intl.Locale` object with options.
13556        ///
13557        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
13558        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13559        pub fn new_with_options(tag: &str, options: &Object) -> Result<Locale, JsValue>;
13560
13561        /// The base name of the locale (language + region + script).
13562        ///
13563        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName)
13564        #[wasm_bindgen(method, getter = baseName)]
13565        pub fn base_name(this: &Locale) -> JsString;
13566
13567        /// The calendar type for the locale.
13568        ///
13569        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar)
13570        #[wasm_bindgen(method, getter)]
13571        pub fn calendar(this: &Locale) -> Option<JsString>;
13572
13573        /// The case first sorting option.
13574        ///
13575        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst)
13576        #[wasm_bindgen(method, getter = caseFirst)]
13577        pub fn case_first(this: &Locale) -> Option<JsString>;
13578
13579        /// The collation type for the locale.
13580        ///
13581        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation)
13582        #[wasm_bindgen(method, getter)]
13583        pub fn collation(this: &Locale) -> Option<JsString>;
13584
13585        /// The hour cycle for the locale.
13586        ///
13587        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle)
13588        #[wasm_bindgen(method, getter = hourCycle)]
13589        pub fn hour_cycle(this: &Locale) -> Option<JsString>;
13590
13591        /// The language code for the locale.
13592        ///
13593        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language)
13594        #[wasm_bindgen(method, getter)]
13595        pub fn language(this: &Locale) -> JsString;
13596
13597        /// The numbering system for the locale.
13598        ///
13599        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem)
13600        #[wasm_bindgen(method, getter = numberingSystem)]
13601        pub fn numbering_system(this: &Locale) -> Option<JsString>;
13602
13603        /// Whether the locale uses numeric collation.
13604        ///
13605        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric)
13606        #[wasm_bindgen(method, getter)]
13607        pub fn numeric(this: &Locale) -> bool;
13608
13609        /// The region code for the locale.
13610        ///
13611        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/region)
13612        #[wasm_bindgen(method, getter)]
13613        pub fn region(this: &Locale) -> Option<JsString>;
13614
13615        /// The script code for the locale.
13616        ///
13617        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/script)
13618        #[wasm_bindgen(method, getter)]
13619        pub fn script(this: &Locale) -> Option<JsString>;
13620
13621        /// The `firstDayOfWeek` accessor property returns the first day of
13622        /// the week for this locale, as a weekday code such as `"mon"`,
13623        /// when one was given via the `fw` extension or constructor option.
13624        ///
13625        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/firstDayOfWeek)
13626        #[wasm_bindgen(method, getter, js_namespace = Intl, js_name = firstDayOfWeek)]
13627        pub fn first_day_of_week(this: &Locale) -> Option<JsString>;
13628
13629        /// The `variants` accessor property returns the variant subtags of
13630        /// this locale, joined by `-`, if any.
13631        ///
13632        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/variants)
13633        #[wasm_bindgen(method, getter, js_namespace = Intl)]
13634        pub fn variants(this: &Locale) -> Option<JsString>;
13635
13636        /// Returns an array of available calendars for the locale.
13637        ///
13638        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars)
13639        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCalendars)]
13640        pub fn get_calendars(this: &Locale) -> Array<JsString>;
13641
13642        /// Returns an array of available collations for the locale.
13643        ///
13644        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations)
13645        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCollations)]
13646        pub fn get_collations(this: &Locale) -> Array<JsString>;
13647
13648        /// Returns an array of available hour cycles for the locale.
13649        ///
13650        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles)
13651        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getHourCycles)]
13652        pub fn get_hour_cycles(this: &Locale) -> Array<JsString>;
13653
13654        /// Returns an array of available numbering systems for the locale.
13655        ///
13656        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems)
13657        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getNumberingSystems)]
13658        pub fn get_numbering_systems(this: &Locale) -> Array<JsString>;
13659
13660        /// Returns an array of available time zones for the locale's region.
13661        ///
13662        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones)
13663        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTimeZones)]
13664        pub fn get_time_zones(this: &Locale) -> Option<Array<JsString>>;
13665
13666        /// Returns week information for the locale.
13667        ///
13668        /// May not be available in all environments.
13669        ///
13670        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
13671        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getWeekInfo, catch)]
13672        pub fn get_week_info(this: &Locale) -> Result<WeekInfo, JsValue>;
13673
13674        /// Returns text layout information for the locale.
13675        ///
13676        /// May not be available in all environments.
13677        ///
13678        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
13679        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTextInfo, catch)]
13680        pub fn get_text_info(this: &Locale) -> Result<TextInfo, JsValue>;
13681
13682        /// Returns a new Locale with the specified calendar.
13683        ///
13684        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize)
13685        #[wasm_bindgen(method, js_class = "Intl.Locale")]
13686        pub fn maximize(this: &Locale) -> Locale;
13687
13688        /// Returns a new Locale with the minimal subtags.
13689        ///
13690        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize)
13691        #[wasm_bindgen(method, js_class = "Intl.Locale")]
13692        pub fn minimize(this: &Locale) -> Locale;
13693    }
13694
13695    // Intl.Locale WeekInfo
13696    #[wasm_bindgen]
13697    extern "C" {
13698        /// Week information for a locale.
13699        ///
13700        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
13701        #[wasm_bindgen(extends = Object)]
13702        #[derive(Clone, Debug)]
13703        pub type WeekInfo;
13704
13705        /// The first day of the week (1 = Monday, 7 = Sunday).
13706        #[wasm_bindgen(method, getter = firstDay)]
13707        pub fn first_day(this: &WeekInfo) -> u8;
13708
13709        /// Array of weekend days.
13710        #[wasm_bindgen(method, getter)]
13711        pub fn weekend(this: &WeekInfo) -> Array<Number>;
13712
13713        /// Minimal days in the first week of the year.
13714        #[wasm_bindgen(method, getter = minimalDays)]
13715        pub fn minimal_days(this: &WeekInfo) -> u8;
13716    }
13717
13718    // Intl.Locale TextInfo
13719    #[wasm_bindgen]
13720    extern "C" {
13721        /// Text layout information for a locale.
13722        ///
13723        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
13724        #[wasm_bindgen(extends = Object)]
13725        #[derive(Clone, Debug)]
13726        pub type TextInfo;
13727
13728        /// The text direction ("ltr" or "rtl").
13729        #[wasm_bindgen(method, getter)]
13730        pub fn direction(this: &TextInfo) -> JsString;
13731    }
13732
13733    // Intl.DurationFormat enums
13734
13735    /// The style for duration formatting.
13736    ///
13737    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style)
13738    #[wasm_bindgen]
13739    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13740    pub enum DurationFormatStyle {
13741        Long = "long",
13742        Short = "short",
13743        Narrow = "narrow",
13744        Digital = "digital",
13745    }
13746
13747    /// The display style for individual duration units.
13748    ///
13749    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#years)
13750    #[wasm_bindgen]
13751    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13752    pub enum DurationUnitStyle {
13753        Long = "long",
13754        Short = "short",
13755        Narrow = "narrow",
13756    }
13757
13758    /// The display style for time duration units (hours, minutes, seconds).
13759    ///
13760    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#hours)
13761    #[wasm_bindgen]
13762    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13763    pub enum DurationTimeUnitStyle {
13764        Long = "long",
13765        Short = "short",
13766        Narrow = "narrow",
13767        Numeric = "numeric",
13768        #[wasm_bindgen(js_name = "2-digit")]
13769        TwoDigit = "2-digit",
13770    }
13771
13772    /// The display option for duration units.
13773    ///
13774    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#yearsdisplay)
13775    #[wasm_bindgen]
13776    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13777    pub enum DurationUnitDisplay {
13778        Auto = "auto",
13779        Always = "always",
13780    }
13781
13782    /// The type of a duration format part.
13783    ///
13784    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts#type)
13785    #[wasm_bindgen]
13786    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13787    pub enum DurationFormatPartType {
13788        Years = "years",
13789        Months = "months",
13790        Weeks = "weeks",
13791        Days = "days",
13792        Hours = "hours",
13793        Minutes = "minutes",
13794        Seconds = "seconds",
13795        Milliseconds = "milliseconds",
13796        Microseconds = "microseconds",
13797        Nanoseconds = "nanoseconds",
13798        Literal = "literal",
13799        Integer = "integer",
13800        Decimal = "decimal",
13801        Fraction = "fraction",
13802    }
13803
13804    // Intl.DurationFormatOptions
13805    #[wasm_bindgen]
13806    extern "C" {
13807        /// Options for `Intl.DurationFormat` constructor.
13808        ///
13809        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#options)
13810        #[wasm_bindgen(extends = Object)]
13811        #[derive(Clone, Debug)]
13812        pub type DurationFormatOptions;
13813
13814        #[wasm_bindgen(method, getter = localeMatcher)]
13815        pub fn get_locale_matcher(this: &DurationFormatOptions) -> Option<LocaleMatcher>;
13816        #[wasm_bindgen(method, setter = localeMatcher)]
13817        pub fn set_locale_matcher(this: &DurationFormatOptions, value: LocaleMatcher);
13818
13819        #[wasm_bindgen(method, getter = style)]
13820        pub fn get_style(this: &DurationFormatOptions) -> Option<DurationFormatStyle>;
13821        #[wasm_bindgen(method, setter = style)]
13822        pub fn set_style(this: &DurationFormatOptions, value: DurationFormatStyle);
13823
13824        #[wasm_bindgen(method, getter = years)]
13825        pub fn get_years(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13826        #[wasm_bindgen(method, setter = years)]
13827        pub fn set_years(this: &DurationFormatOptions, value: DurationUnitStyle);
13828
13829        #[wasm_bindgen(method, getter = yearsDisplay)]
13830        pub fn get_years_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13831        #[wasm_bindgen(method, setter = yearsDisplay)]
13832        pub fn set_years_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13833
13834        #[wasm_bindgen(method, getter = months)]
13835        pub fn get_months(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13836        #[wasm_bindgen(method, setter = months)]
13837        pub fn set_months(this: &DurationFormatOptions, value: DurationUnitStyle);
13838
13839        #[wasm_bindgen(method, getter = monthsDisplay)]
13840        pub fn get_months_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13841        #[wasm_bindgen(method, setter = monthsDisplay)]
13842        pub fn set_months_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13843
13844        #[wasm_bindgen(method, getter = weeks)]
13845        pub fn get_weeks(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13846        #[wasm_bindgen(method, setter = weeks)]
13847        pub fn set_weeks(this: &DurationFormatOptions, value: DurationUnitStyle);
13848
13849        #[wasm_bindgen(method, getter = weeksDisplay)]
13850        pub fn get_weeks_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13851        #[wasm_bindgen(method, setter = weeksDisplay)]
13852        pub fn set_weeks_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13853
13854        #[wasm_bindgen(method, getter = days)]
13855        pub fn get_days(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13856        #[wasm_bindgen(method, setter = days)]
13857        pub fn set_days(this: &DurationFormatOptions, value: DurationUnitStyle);
13858
13859        #[wasm_bindgen(method, getter = daysDisplay)]
13860        pub fn get_days_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13861        #[wasm_bindgen(method, setter = daysDisplay)]
13862        pub fn set_days_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13863
13864        #[wasm_bindgen(method, getter = hours)]
13865        pub fn get_hours(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
13866        #[wasm_bindgen(method, setter = hours)]
13867        pub fn set_hours(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
13868
13869        #[wasm_bindgen(method, getter = hoursDisplay)]
13870        pub fn get_hours_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13871        #[wasm_bindgen(method, setter = hoursDisplay)]
13872        pub fn set_hours_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13873
13874        #[wasm_bindgen(method, getter = minutes)]
13875        pub fn get_minutes(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
13876        #[wasm_bindgen(method, setter = minutes)]
13877        pub fn set_minutes(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
13878
13879        #[wasm_bindgen(method, getter = minutesDisplay)]
13880        pub fn get_minutes_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13881        #[wasm_bindgen(method, setter = minutesDisplay)]
13882        pub fn set_minutes_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13883
13884        #[wasm_bindgen(method, getter = seconds)]
13885        pub fn get_seconds(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
13886        #[wasm_bindgen(method, setter = seconds)]
13887        pub fn set_seconds(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
13888
13889        #[wasm_bindgen(method, getter = secondsDisplay)]
13890        pub fn get_seconds_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13891        #[wasm_bindgen(method, setter = secondsDisplay)]
13892        pub fn set_seconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13893
13894        #[wasm_bindgen(method, getter = milliseconds)]
13895        pub fn get_milliseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13896        #[wasm_bindgen(method, setter = milliseconds)]
13897        pub fn set_milliseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
13898
13899        #[wasm_bindgen(method, getter = millisecondsDisplay)]
13900        pub fn get_milliseconds_display(
13901            this: &DurationFormatOptions,
13902        ) -> Option<DurationUnitDisplay>;
13903        #[wasm_bindgen(method, setter = millisecondsDisplay)]
13904        pub fn set_milliseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13905
13906        #[wasm_bindgen(method, getter = microseconds)]
13907        pub fn get_microseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13908        #[wasm_bindgen(method, setter = microseconds)]
13909        pub fn set_microseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
13910
13911        #[wasm_bindgen(method, getter = microsecondsDisplay)]
13912        pub fn get_microseconds_display(
13913            this: &DurationFormatOptions,
13914        ) -> Option<DurationUnitDisplay>;
13915        #[wasm_bindgen(method, setter = microsecondsDisplay)]
13916        pub fn set_microseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13917
13918        #[wasm_bindgen(method, getter = nanoseconds)]
13919        pub fn get_nanoseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13920        #[wasm_bindgen(method, setter = nanoseconds)]
13921        pub fn set_nanoseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
13922
13923        #[wasm_bindgen(method, getter = nanosecondsDisplay)]
13924        pub fn get_nanoseconds_display(this: &DurationFormatOptions)
13925            -> Option<DurationUnitDisplay>;
13926        #[wasm_bindgen(method, setter = nanosecondsDisplay)]
13927        pub fn set_nanoseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13928
13929        #[wasm_bindgen(method, getter = fractionalDigits)]
13930        pub fn get_fractional_digits(this: &DurationFormatOptions) -> Option<u8>;
13931        #[wasm_bindgen(method, setter = fractionalDigits)]
13932        pub fn set_fractional_digits(this: &DurationFormatOptions, value: u8);
13933    }
13934
13935    impl DurationFormatOptions {
13936        pub fn new() -> DurationFormatOptions {
13937            JsCast::unchecked_into(Object::new())
13938        }
13939    }
13940
13941    impl Default for DurationFormatOptions {
13942        fn default() -> Self {
13943            DurationFormatOptions::new()
13944        }
13945    }
13946
13947    // Intl.ResolvedDurationFormatOptions
13948    #[wasm_bindgen]
13949    extern "C" {
13950        /// Resolved options returned by `Intl.DurationFormat.prototype.resolvedOptions()`.
13951        ///
13952        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
13953        #[wasm_bindgen(extends = DurationFormatOptions)]
13954        #[derive(Clone, Debug)]
13955        pub type ResolvedDurationFormatOptions;
13956
13957        /// The resolved locale string.
13958        #[wasm_bindgen(method, getter = locale)]
13959        pub fn get_locale(this: &ResolvedDurationFormatOptions) -> JsString;
13960
13961        /// The resolved numbering system.
13962        #[wasm_bindgen(method, getter = numberingSystem)]
13963        pub fn get_numbering_system(this: &ResolvedDurationFormatOptions) -> JsString;
13964    }
13965
13966    // Intl.Duration (input object for DurationFormat)
13967    #[wasm_bindgen]
13968    extern "C" {
13969        /// A duration object used as input to `Intl.DurationFormat.format()`.
13970        ///
13971        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration)
13972        #[wasm_bindgen(extends = Object)]
13973        #[derive(Clone, Debug)]
13974        pub type Duration;
13975
13976        #[wasm_bindgen(method, getter)]
13977        pub fn years(this: &Duration) -> Option<f64>;
13978        #[wasm_bindgen(method, setter)]
13979        pub fn set_years(this: &Duration, value: f64);
13980
13981        #[wasm_bindgen(method, getter)]
13982        pub fn months(this: &Duration) -> Option<f64>;
13983        #[wasm_bindgen(method, setter)]
13984        pub fn set_months(this: &Duration, value: f64);
13985
13986        #[wasm_bindgen(method, getter)]
13987        pub fn weeks(this: &Duration) -> Option<f64>;
13988        #[wasm_bindgen(method, setter)]
13989        pub fn set_weeks(this: &Duration, value: f64);
13990
13991        #[wasm_bindgen(method, getter)]
13992        pub fn days(this: &Duration) -> Option<f64>;
13993        #[wasm_bindgen(method, setter)]
13994        pub fn set_days(this: &Duration, value: f64);
13995
13996        #[wasm_bindgen(method, getter)]
13997        pub fn hours(this: &Duration) -> Option<f64>;
13998        #[wasm_bindgen(method, setter)]
13999        pub fn set_hours(this: &Duration, value: f64);
14000
14001        #[wasm_bindgen(method, getter)]
14002        pub fn minutes(this: &Duration) -> Option<f64>;
14003        #[wasm_bindgen(method, setter)]
14004        pub fn set_minutes(this: &Duration, value: f64);
14005
14006        #[wasm_bindgen(method, getter)]
14007        pub fn seconds(this: &Duration) -> Option<f64>;
14008        #[wasm_bindgen(method, setter)]
14009        pub fn set_seconds(this: &Duration, value: f64);
14010
14011        #[wasm_bindgen(method, getter)]
14012        pub fn milliseconds(this: &Duration) -> Option<f64>;
14013        #[wasm_bindgen(method, setter)]
14014        pub fn set_milliseconds(this: &Duration, value: f64);
14015
14016        #[wasm_bindgen(method, getter)]
14017        pub fn microseconds(this: &Duration) -> Option<f64>;
14018        #[wasm_bindgen(method, setter)]
14019        pub fn set_microseconds(this: &Duration, value: f64);
14020
14021        #[wasm_bindgen(method, getter)]
14022        pub fn nanoseconds(this: &Duration) -> Option<f64>;
14023        #[wasm_bindgen(method, setter)]
14024        pub fn set_nanoseconds(this: &Duration, value: f64);
14025    }
14026
14027    impl Duration {
14028        pub fn new() -> Duration {
14029            JsCast::unchecked_into(Object::new())
14030        }
14031    }
14032
14033    impl Default for Duration {
14034        fn default() -> Self {
14035            Duration::new()
14036        }
14037    }
14038
14039    // Intl.DurationFormatPart
14040    #[wasm_bindgen]
14041    extern "C" {
14042        /// A part of the formatted duration returned by `formatToParts()`.
14043        ///
14044        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
14045        #[wasm_bindgen(extends = Object)]
14046        #[derive(Clone, Debug)]
14047        pub type DurationFormatPart;
14048
14049        /// The type of the part.
14050        #[wasm_bindgen(method, getter = type)]
14051        pub fn type_(this: &DurationFormatPart) -> DurationFormatPartType;
14052
14053        /// The value of the part.
14054        #[wasm_bindgen(method, getter)]
14055        pub fn value(this: &DurationFormatPart) -> JsString;
14056
14057        /// The unit this part represents (if applicable).
14058        #[wasm_bindgen(method, getter)]
14059        pub fn unit(this: &DurationFormatPart) -> Option<JsString>;
14060    }
14061
14062    // Intl.DurationFormat
14063    #[wasm_bindgen]
14064    extern "C" {
14065        /// The `Intl.DurationFormat` object enables language-sensitive duration formatting.
14066        ///
14067        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat)
14068        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DurationFormat")]
14069        #[derive(Clone, Debug)]
14070        pub type DurationFormat;
14071
14072        /// Creates a new `Intl.DurationFormat` object.
14073        ///
14074        /// Throws a `RangeError` if locales or options contain invalid values.
14075        ///
14076        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat)
14077        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
14078        pub fn new(
14079            locales: &[JsString],
14080            options: &DurationFormatOptions,
14081        ) -> Result<DurationFormat, JsValue>;
14082
14083        /// Formats a duration according to the locale and formatting options.
14084        ///
14085        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format)
14086        #[wasm_bindgen(method, js_class = "Intl.DurationFormat")]
14087        pub fn format(this: &DurationFormat, duration: &Duration) -> JsString;
14088
14089        /// Returns an array of objects representing the formatted duration in parts.
14090        ///
14091        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
14092        #[wasm_bindgen(method, js_class = "Intl.DurationFormat", js_name = formatToParts)]
14093        pub fn format_to_parts(
14094            this: &DurationFormat,
14095            duration: &Duration,
14096        ) -> Array<DurationFormatPart>;
14097
14098        /// Returns an object with properties reflecting the options used.
14099        ///
14100        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
14101        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
14102        pub fn resolved_options(this: &DurationFormat) -> ResolvedDurationFormatOptions;
14103
14104        /// Returns an array of supported locales.
14105        ///
14106        /// Throws a `RangeError` if locales contain invalid values.
14107        ///
14108        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf)
14109        #[wasm_bindgen(static_method_of = DurationFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
14110        pub fn supported_locales_of(
14111            locales: &[JsString],
14112            options: &LocaleMatcherOptions,
14113        ) -> Result<Array<JsString>, JsValue>;
14114    }
14115
14116    impl Default for DurationFormat {
14117        fn default() -> Self {
14118            Self::new(&[], &Default::default()).unwrap()
14119        }
14120    }
14121}
14122
14123#[wasm_bindgen]
14124extern "C" {
14125    /// The `PromiseState` object represents the the status of the promise,
14126    /// as used in `allSettled`.
14127    ///
14128    /// `T` is the fulfilled value type and `E` the rejection reason type,
14129    /// both defaulting to `JsValue`.
14130    ///
14131    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
14132    #[must_use]
14133    #[wasm_bindgen(extends = Object, typescript_type = "any")]
14134    #[derive(Clone, Debug)]
14135    pub type PromiseState<T = JsValue, E = JsValue>;
14136
14137    /// A string, either "fulfilled" or "rejected", indicating the eventual state of the promise.
14138    #[wasm_bindgen(method, getter = status)]
14139    pub fn get_status<T, E>(this: &PromiseState<T, E>) -> String;
14140
14141    /// Only present if status is "fulfilled". The value that the promise was fulfilled with.
14142    #[wasm_bindgen(method, getter = value)]
14143    pub fn get_value<T, E>(this: &PromiseState<T, E>) -> Option<T>;
14144
14145    /// Only present if status is "rejected". The reason that the promise was rejected with.
14146    #[wasm_bindgen(method, getter = reason)]
14147    pub fn get_reason<T, E>(this: &PromiseState<T, E>) -> Option<E>;
14148}
14149
14150impl<T, E> PromiseState<T, E> {
14151    pub fn is_fulfilled(&self) -> bool {
14152        self.get_status() == "fulfilled"
14153    }
14154
14155    pub fn is_rejected(&self) -> bool {
14156        self.get_status() == "rejected"
14157    }
14158}
14159
14160/// Converts a `PromiseState<T, E>` into a `Result<T, E>`, matching the
14161/// spec invariant that exactly one of the fulfilled value or the rejection
14162/// reason is populated per slot.
14163impl<T: JsGeneric + FromWasmAbi, E: JsGeneric + FromWasmAbi> From<PromiseState<T, E>>
14164    for Result<T, E>
14165{
14166    fn from(state: PromiseState<T, E>) -> Result<T, E> {
14167        if state.is_fulfilled() {
14168            Ok(state.get_value().unwrap())
14169        } else {
14170            Err(state.get_reason().unwrap())
14171        }
14172    }
14173}
14174
14175// PromiseWithResolvers
14176#[wasm_bindgen]
14177extern "C" {
14178    /// The object returned by [`Promise::with_resolvers`], bundling a
14179    /// pending promise with the functions that settle it.
14180    ///
14181    /// `T` is the fulfilled value type and `E` the rejection reason type,
14182    /// both defaulting to `JsValue`. Unlike `Promise<T, E>` it is invariant
14183    /// in both: `resolve` and `reject` take a `T` and an `E`, so widening
14184    /// either would let the promise settle with a value its type rules out.
14185    ///
14186    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers)
14187    #[wasm_bindgen(extends = Object, no_upcast, typescript_type = "PromiseWithResolvers<any>")]
14188    #[derive(Clone, Debug, PartialEq, Eq)]
14189    pub type PromiseWithResolvers<T = JsValue, E = JsValue>;
14190
14191    /// The pending promise.
14192    #[wasm_bindgen(method, getter)]
14193    pub fn promise<T, E>(this: &PromiseWithResolvers<T, E>) -> Promise<T, E>;
14194
14195    /// The function that fulfills the promise with a value.
14196    #[wasm_bindgen(method, getter)]
14197    pub fn resolve<T, E>(this: &PromiseWithResolvers<T, E>) -> Function<fn(T) -> Undefined>;
14198
14199    /// The function that rejects the promise with a reason.
14200    #[wasm_bindgen(method, getter)]
14201    pub fn reject<T, E>(this: &PromiseWithResolvers<T, E>) -> Function<fn(E) -> Undefined>;
14202}
14203
14204// Invariant in `T` and `E`: only identity and the `Object` / `JsValue` supertypes.
14205impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for PromiseWithResolvers<T, E> {}
14206impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsOption<PromiseWithResolvers<T, E>> {}
14207impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsNullable<PromiseWithResolvers<T, E>> {}
14208impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsValue {}
14209impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsOption<JsValue> {}
14210impl<T, E, Target: UpcastFrom<PromiseWithResolvers<T, E>>> UpcastFrom<PromiseWithResolvers<T, E>>
14211    for Option<Target>
14212{
14213}
14214impl<T, E, Target: UpcastFrom<PromiseWithResolvers<T, E>>> UpcastFrom<PromiseWithResolvers<T, E>>
14215    for Nullable<Target>
14216{
14217}
14218impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsNullable<JsValue> {}
14219impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for Object {}
14220impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsOption<Object> {}
14221impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsNullable<Object> {}
14222
14223// Promise
14224#[wasm_bindgen]
14225extern "C" {
14226    /// The `Promise` object represents the eventual completion (or failure) of
14227    /// an asynchronous operation, and its resulting value.
14228    ///
14229    /// `T` is the type the promise fulfills with and `E` the type it rejects
14230    /// with, both defaulting to `JsValue`. Awaiting a `Promise<T, E>` yields a
14231    /// `Result<T, E>`. JS can reject with any value, so `E` is the same kind
14232    /// of unchecked assertion about the JS side as `T` is. A `Promise<T, E>`
14233    /// upcasts to `Promise<T2, E2>` whenever `T` upcasts to `T2` and `E` to
14234    /// `E2`, so a `Promise<T, TypeError>` can be passed where a
14235    /// `Promise<T, Error>` or `Promise<T>` is expected.
14236    ///
14237    /// `then` and `finally` with a plain handler keep `E` on the returned
14238    /// promise. Variants whose handler returns a `Result`, and so can reject
14239    /// on its own, widen the returned rejection to `JsValue`.
14240    ///
14241    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
14242    #[must_use]
14243    #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>", no_promising)]
14244    #[derive(Clone, Debug)]
14245    pub type Promise<T = JsValue, E = JsValue>;
14246
14247    /// Creates a new `Promise` with the provided executor `cb`
14248    ///
14249    /// The `cb` is a function that is passed with the arguments `resolve` and
14250    /// `reject`. The `cb` function is executed immediately by the `Promise`
14251    /// implementation, passing `resolve` and `reject` functions (the executor
14252    /// is called before the `Promise` constructor even returns the created
14253    /// object). The `resolve` and `reject` functions, when called, resolve or
14254    /// reject the promise, respectively. The executor normally initiates
14255    /// some asynchronous work, and then, once that completes, either calls
14256    /// the `resolve` function to resolve the promise or else rejects it if an
14257    /// error occurred.
14258    ///
14259    /// If an error is thrown in the executor function, the promise is rejected.
14260    /// The return value of the executor is ignored.
14261    ///
14262    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
14263    #[cfg(not(js_sys_unstable_apis))]
14264    #[wasm_bindgen(constructor)]
14265    pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
14266
14267    /// Creates a new `Promise` with the provided executor `cb`
14268    ///
14269    /// The `cb` is a function that is passed with the arguments `resolve` and
14270    /// `reject`. The `cb` function is executed immediately by the `Promise`
14271    /// implementation, passing `resolve` and `reject` functions (the executor
14272    /// is called before the `Promise` constructor even returns the created
14273    /// object). The `resolve` and `reject` functions, when called, resolve or
14274    /// reject the promise, respectively. The executor normally initiates
14275    /// some asynchronous work, and then, once that completes, either calls
14276    /// the `resolve` function to resolve the promise or else rejects it if an
14277    /// error occurred.
14278    ///
14279    /// If an error is thrown in the executor function, the promise is rejected.
14280    /// The return value of the executor is ignored.
14281    ///
14282    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
14283    #[cfg(js_sys_unstable_apis)]
14284    #[wasm_bindgen(constructor)]
14285    pub fn new<T, E>(
14286        cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(E) -> Undefined>),
14287    ) -> Promise<T, E>;
14288
14289    // Next major: deprecate
14290    /// Creates a new `Promise` with the provided executor `cb`
14291    ///
14292    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
14293    #[wasm_bindgen(constructor)]
14294    pub fn new_typed<T: Promising>(
14295        cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
14296    ) -> Promise<<T as Promising>::Resolution>;
14297
14298    /// The `Promise.all(iterable)` method returns a single `Promise` that
14299    /// resolves when all of the promises in the iterable argument have resolved
14300    /// or when the iterable argument contains no promises. It rejects with the
14301    /// reason of the first promise that rejects.
14302    ///
14303    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
14304    #[cfg(not(js_sys_unstable_apis))]
14305    #[wasm_bindgen(static_method_of = Promise)]
14306    pub fn all(obj: &JsValue) -> Promise;
14307
14308    /// The `Promise.all(iterable)` method returns a single `Promise` that
14309    /// resolves when all of the promises in the iterable argument have resolved
14310    /// or when the iterable argument contains no promises. It rejects with the
14311    /// reason of the first promise that rejects.
14312    ///
14313    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
14314    #[cfg(js_sys_unstable_apis)]
14315    #[wasm_bindgen(static_method_of = Promise, js_name = all)]
14316    pub fn all<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
14317    where
14318        I::Item: Promising;
14319
14320    // Next major: deprecate
14321    /// The `Promise.all(iterable)` method returns a single `Promise` that
14322    /// resolves when all of the promises in the iterable argument have resolved
14323    /// or when the iterable argument contains no promises. It rejects with the
14324    /// reason of the first promise that rejects.
14325    ///
14326    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
14327    #[wasm_bindgen(static_method_of = Promise, js_name = all)]
14328    pub fn all_iterable<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
14329    where
14330        I::Item: Promising;
14331
14332    /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
14333    /// resolves when all of the promises in the iterable argument have either
14334    /// fulfilled or rejected or when the iterable argument contains no promises.
14335    ///
14336    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
14337    #[cfg(not(js_sys_unstable_apis))]
14338    #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
14339    pub fn all_settled(obj: &JsValue) -> Promise;
14340
14341    /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
14342    /// resolves when all of the promises in the iterable argument have either
14343    /// fulfilled or rejected or when the iterable argument contains no promises.
14344    ///
14345    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
14346    #[cfg(js_sys_unstable_apis)]
14347    #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
14348    pub fn all_settled<I: Iterable>(
14349        obj: &I,
14350    ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
14351    where
14352        I::Item: Promising;
14353
14354    // Next major: deprecate
14355    /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
14356    /// resolves when all of the promises in the iterable argument have either
14357    /// fulfilled or rejected or when the iterable argument contains no promises.
14358    ///
14359    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
14360    #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
14361    pub fn all_settled_iterable<I: Iterable>(
14362        obj: &I,
14363    ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
14364    where
14365        I::Item: Promising;
14366
14367    /// The `Promise.any(iterable)` method returns a single `Promise` that
14368    /// resolves when any of the promises in the iterable argument have resolved
14369    /// or when the iterable argument contains no promises. It rejects with an
14370    /// `AggregateError` if all promises in the iterable rejected.
14371    ///
14372    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
14373    #[cfg(not(js_sys_unstable_apis))]
14374    #[wasm_bindgen(static_method_of = Promise)]
14375    pub fn any(obj: &JsValue) -> Promise;
14376
14377    /// The `Promise.any(iterable)` method returns a single `Promise` that
14378    /// resolves when any of the promises in the iterable argument have resolved
14379    /// or when the iterable argument contains no promises. It rejects with an
14380    /// `AggregateError` if all promises in the iterable rejected.
14381    ///
14382    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
14383    #[cfg(js_sys_unstable_apis)]
14384    #[wasm_bindgen(static_method_of = Promise, js_name = any)]
14385    pub fn any<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution, AggregateError>
14386    where
14387        I::Item: Promising;
14388
14389    // Next major: deprecate, and type the rejection as `AggregateError`
14390    /// The `Promise.any(iterable)` method returns a single `Promise` that
14391    /// resolves when any of the promises in the iterable argument have resolved
14392    /// or when the iterable argument contains no promises. It rejects with an
14393    /// `AggregateError` if all promises in the iterable rejected.
14394    ///
14395    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
14396    #[wasm_bindgen(static_method_of = Promise, js_name = any)]
14397    pub fn any_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
14398    where
14399        I::Item: Promising;
14400
14401    /// The `Promise.race(iterable)` method returns a promise that resolves or
14402    /// rejects as soon as one of the promises in the iterable resolves or
14403    /// rejects, with the value or reason from that promise.
14404    ///
14405    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
14406    #[cfg(not(js_sys_unstable_apis))]
14407    #[wasm_bindgen(static_method_of = Promise)]
14408    pub fn race(obj: &JsValue) -> Promise;
14409
14410    /// The `Promise.race(iterable)` method returns a promise that resolves or
14411    /// rejects as soon as one of the promises in the iterable resolves or
14412    /// rejects, with the value or reason from that promise.
14413    ///
14414    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
14415    #[cfg(js_sys_unstable_apis)]
14416    #[wasm_bindgen(static_method_of = Promise, js_name = race)]
14417    pub fn race<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
14418    where
14419        I::Item: Promising;
14420
14421    // Next major: deprecate
14422    /// The `Promise.race(iterable)` method returns a promise that resolves or
14423    /// rejects as soon as one of the promises in the iterable resolves or
14424    /// rejects, with the value or reason from that promise.
14425    ///
14426    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
14427    #[wasm_bindgen(static_method_of = Promise, js_name = race)]
14428    pub fn race_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
14429    where
14430        I::Item: Promising;
14431
14432    /// The `Promise.reject(reason)` method returns a `Promise` object that is
14433    /// rejected with the given reason.
14434    ///
14435    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
14436    #[cfg(not(js_sys_unstable_apis))]
14437    #[wasm_bindgen(static_method_of = Promise)]
14438    pub fn reject(obj: &JsValue) -> Promise;
14439
14440    /// The `Promise.reject(reason)` method returns a `Promise` object that is
14441    /// rejected with the given reason.
14442    ///
14443    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
14444    #[cfg(js_sys_unstable_apis)]
14445    #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
14446    pub fn reject<T, E: JsGeneric>(obj: &E) -> Promise<T, E>;
14447
14448    // Next major: deprecate
14449    /// The `Promise.reject(reason)` method returns a `Promise` object that is
14450    /// rejected with the given reason.
14451    ///
14452    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
14453    #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
14454    pub fn reject_typed<T>(obj: &JsValue) -> Promise<T>;
14455
14456    /// The `Promise.resolve(value)` method returns a `Promise` object that is
14457    /// resolved with the given value. If the value is a promise, that promise
14458    /// is returned; if the value is a thenable (i.e. has a "then" method), the
14459    /// returned promise will "follow" that thenable, adopting its eventual
14460    /// state; otherwise the returned promise will be fulfilled with the value.
14461    ///
14462    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
14463    #[wasm_bindgen(static_method_of = Promise, js_name = resolve)]
14464    pub fn resolve<U: Promising>(obj: &U) -> Promise<U::Resolution>;
14465
14466    /// The `catch()` method returns a `Promise` and deals with rejected cases
14467    /// only.  It behaves the same as calling `Promise.prototype.then(undefined,
14468    /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
14469    /// `obj.then(undefined, onRejected)`).
14470    ///
14471    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
14472    #[cfg(not(js_sys_unstable_apis))]
14473    #[wasm_bindgen(method)]
14474    pub fn catch<'a, T, E>(
14475        this: &Promise<T, E>,
14476        cb: &ScopedClosure<'a, dyn FnMut(E)>,
14477    ) -> Promise<JsValue>;
14478
14479    /// The `catch()` method returns a `Promise` and deals with rejected cases
14480    /// only.  It behaves the same as calling `Promise.prototype.then(undefined,
14481    /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
14482    /// `obj.then(undefined, onRejected)`).
14483    ///
14484    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
14485    #[cfg(js_sys_unstable_apis)]
14486    #[wasm_bindgen(method, js_name = catch)]
14487    pub fn catch<'a, T, E, R: Promising>(
14488        this: &Promise<T, E>,
14489        cb: &ScopedClosure<'a, dyn FnMut(E) -> Result<R, JsError>>,
14490    ) -> Promise<R::Resolution>;
14491
14492    // Next major: deprecate
14493    /// Same as `catch`, but returning a result to become the new Promise value.
14494    #[wasm_bindgen(method, js_name = catch)]
14495    pub fn catch_map<'a, T, E, R: Promising>(
14496        this: &Promise<T, E>,
14497        cb: &ScopedClosure<'a, dyn FnMut(E) -> Result<R, JsError>>,
14498    ) -> Promise<R::Resolution>;
14499
14500    /// The `then()` method returns a `Promise`. It takes up to two arguments:
14501    /// callback functions for the success and failure cases of the `Promise`.
14502    ///
14503    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
14504    #[cfg(not(js_sys_unstable_apis))]
14505    #[wasm_bindgen(method)]
14506    pub fn then<'a, T, E>(
14507        this: &Promise<T, E>,
14508        cb: &ScopedClosure<'a, dyn FnMut(T)>,
14509    ) -> Promise<JsValue, E>;
14510
14511    /// The `then()` method returns a `Promise`. It takes up to two arguments:
14512    /// callback functions for the success and failure cases of the `Promise`.
14513    ///
14514    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
14515    #[cfg(js_sys_unstable_apis)]
14516    #[wasm_bindgen(method, js_name = then)]
14517    pub fn then<'a, T, E, R: Promising>(
14518        this: &Promise<T, E>,
14519        cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
14520    ) -> Promise<R::Resolution>;
14521
14522    /// The `then()` method returns a `Promise`. It takes up to two arguments:
14523    /// callback functions for the success and failure cases of the `Promise`.
14524    ///
14525    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
14526    #[wasm_bindgen(method, js_name = then)]
14527    pub fn then_with_reject<'a, T, E, R: Promising>(
14528        this: &Promise<T, E>,
14529        resolve: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
14530        reject: &ScopedClosure<'a, dyn FnMut(E) -> Result<R, JsError>>,
14531    ) -> Promise<R::Resolution>;
14532
14533    // Next major: deprecate
14534    /// Alias for `then()` with a return value.
14535    /// The `then()` method returns a `Promise`. It takes up to two arguments:
14536    /// callback functions for the success and failure cases of the `Promise`.
14537    ///
14538    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
14539    #[wasm_bindgen(method, js_name = then)]
14540    pub fn then_map<'a, T, E, R: Promising>(
14541        this: &Promise<T, E>,
14542        cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
14543    ) -> Promise<R::Resolution>;
14544
14545    /// Same as `then`, only with both arguments provided.
14546    ///
14547    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
14548    #[wasm_bindgen(method, js_name = then)]
14549    pub fn then2(
14550        this: &Promise,
14551        resolve: &ScopedClosure<dyn FnMut(JsValue)>,
14552        reject: &ScopedClosure<dyn FnMut(JsValue)>,
14553    ) -> Promise;
14554
14555    /// The `finally()` method returns a `Promise`. When the promise is settled,
14556    /// whether fulfilled or rejected, the specified callback function is
14557    /// executed. This provides a way for code that must be executed once the
14558    /// `Promise` has been dealt with to be run whether the promise was
14559    /// fulfilled successfully or rejected.
14560    ///
14561    /// This lets you avoid duplicating code in both the promise's `then()` and
14562    /// `catch()` handlers.
14563    ///
14564    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
14565    // Next major: return `Promise<T, E>`, since `finally` passes the value through
14566    #[wasm_bindgen(method)]
14567    pub fn finally<T, E>(
14568        this: &Promise<T, E>,
14569        cb: &ScopedClosure<dyn FnMut()>,
14570    ) -> Promise<JsValue, E>;
14571
14572    /// The `Promise.try()` static method calls `cb` synchronously and
14573    /// wraps its outcome in a promise: a returned value or promise is
14574    /// adopted, and a thrown error becomes a rejection.
14575    ///
14576    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/try)
14577    #[wasm_bindgen(static_method_of = Promise, js_name = try)]
14578    pub fn try_<R: Promising>(cb: &mut dyn FnMut() -> Result<R, JsError>)
14579        -> Promise<R::Resolution>;
14580
14581    /// The `Promise.withResolvers()` static method returns a new promise
14582    /// together with its `resolve` and `reject` functions.
14583    ///
14584    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers)
14585    #[wasm_bindgen(static_method_of = Promise, js_name = withResolvers)]
14586    pub fn with_resolvers<T, E>() -> PromiseWithResolvers<T, E>;
14587}
14588
14589impl<T, E> Promising for Promise<T, E> {
14590    type Resolution = T;
14591}
14592
14593/// Internal: maps a tuple of `Promise<T_i, E>` to the result shapes of
14594/// [`Promise::all_tuple`] and [`Promise::all_settled_tuple`].
14595///
14596/// Implemented for every tuple arity 1..=8 of `Promise<T, E>`, for any `T`
14597/// and `E`. One rejection type `E` is shared across the tuple,
14598/// so upcast mixed rejection types to a common one first. The associated
14599/// `Joined` / `Settled` types pin down the [`ArrayTuple`] shape of the
14600/// result so the one [`JsCast::unchecked_into`] needed to reinterpret the
14601/// [`Array<JsValue>`] returned by `Promise.all` / `Promise.allSettled` is
14602/// encapsulated inside each impl — the caller sees a fully-typed
14603/// `Promise<ArrayTuple<...>, E>`.
14604///
14605/// The soundness of the `unchecked_into`s here rests on `Promise.all` and
14606/// `Promise.allSettled` preserving input order and arity, which they do by
14607/// spec.
14608///
14609/// You normally call [`Promise::all_tuple`] / [`Promise::all_settled_tuple`]
14610/// rather than using this trait directly.
14611#[doc(hidden)]
14612pub trait PromiseTuple {
14613    /// The typed `ArrayTuple` shape the joined promise resolves to.
14614    ///
14615    /// For a tuple `(Promise<T1, E>, Promise<T2, E>, ...)` this is
14616    /// `ArrayTuple<(T1, T2, ...)>`.
14617    type Joined;
14618
14619    /// The typed `ArrayTuple` shape the all-settled promise resolves to.
14620    ///
14621    /// For a tuple `(Promise<T1, E>, Promise<T2, E>, ...)` this is
14622    /// `ArrayTuple<(PromiseState<T1, E>, PromiseState<T2, E>, ...)>`.
14623    type Settled;
14624
14625    /// The rejection type shared by every promise in the tuple, which the
14626    /// joined promise rejects with.
14627    type Rejection;
14628
14629    /// Join via `Promise.all`, returning a typed `Promise`.
14630    fn all(self) -> Promise<Self::Joined, Self::Rejection>;
14631
14632    /// Settle via `Promise.allSettled`, returning a typed `Promise`.
14633    fn all_settled(self) -> Promise<Self::Settled>;
14634}
14635
14636macro_rules! impl_promise_tuple {
14637    ([$($T:ident)+] [$($idx:tt)+]) => {
14638        // Rust tuple of `Promise<T_i, E>`. Each element is a promise handle
14639        // whatever `T_i` is, so the `ArrayTuple` of promises is packed
14640        // directly rather than through `From<(..)>`, which would upcast
14641        // each `T_i`. Delegates to the `ArrayTuple` impl below.
14642        impl<$($T,)+ E> PromiseTuple for ($(Promise<$T, E>,)+) {
14643            type Joined = ArrayTuple<($($T,)+)>;
14644            type Settled = ArrayTuple<($(PromiseState<$T, E>,)+)>;
14645            type Rejection = E;
14646
14647            fn all(self) -> Promise<Self::Joined, E> {
14648                use wasm_bindgen::JsCast;
14649                let tuple: ArrayTuple<($(Promise<$T, E>,)+)> =
14650                    Array::of(&[$(JsValue::from(self.$idx)),+]).unchecked_into();
14651                tuple.all()
14652            }
14653
14654            fn all_settled(self) -> Promise<Self::Settled> {
14655                use wasm_bindgen::JsCast;
14656                let tuple: ArrayTuple<($(Promise<$T, E>,)+)> =
14657                    Array::of(&[$(JsValue::from(self.$idx)),+]).unchecked_into();
14658                tuple.all_settled()
14659            }
14660        }
14661
14662        // `ArrayTuple<(Promise<T_1, E>, ..., Promise<T_n, E>)>` — callers who
14663        // already have an `ArrayTuple` (e.g. from a binding that returns
14664        // one, or built via `.into()` earlier in a pipeline) can pass it
14665        // directly without unpacking into a Rust tuple.
14666        //
14667        // Hands the `ArrayTuple` straight to `Promise.all_iterable` /
14668        // `Promise.allSettled_iterable` and reinterprets the result
14669        // `Array<JsValue>` as the intended typed `ArrayTuple`. Safe because
14670        // `Promise.all` / `Promise.allSettled` preserve input order and
14671        // arity by spec, and `Promise.all` rejects with one of the inputs'
14672        // rejection reasons.
14673        impl<$($T,)+ E> PromiseTuple for ArrayTuple<($(Promise<$T, E>,)+)> {
14674            type Joined = ArrayTuple<($($T,)+)>;
14675            type Settled = ArrayTuple<($(PromiseState<$T, E>,)+)>;
14676            type Rejection = E;
14677
14678            fn all(self) -> Promise<Self::Joined, E> {
14679                use wasm_bindgen::JsCast;
14680                Promise::all_iterable(&self).unchecked_into()
14681            }
14682
14683            fn all_settled(self) -> Promise<Self::Settled> {
14684                use wasm_bindgen::JsCast;
14685                Promise::all_settled_iterable(&self).unchecked_into()
14686            }
14687        }
14688    };
14689}
14690
14691impl_promise_tuple!([T1][0]);
14692impl_promise_tuple!([T1 T2] [0 1]);
14693impl_promise_tuple!([T1 T2 T3] [0 1 2]);
14694impl_promise_tuple!([T1 T2 T3 T4] [0 1 2 3]);
14695impl_promise_tuple!([T1 T2 T3 T4 T5] [0 1 2 3 4]);
14696impl_promise_tuple!([T1 T2 T3 T4 T5 T6] [0 1 2 3 4 5]);
14697impl_promise_tuple!([T1 T2 T3 T4 T5 T6 T7] [0 1 2 3 4 5 6]);
14698impl_promise_tuple!([T1 T2 T3 T4 T5 T6 T7 T8] [0 1 2 3 4 5 6 7]);
14699
14700impl Promise {
14701    /// Heterogeneous counterpart to [`Promise::all_iterable`]: accepts a Rust
14702    /// tuple of `Promise<T_i, E>` and returns a single [`Promise`] resolving
14703    /// to a typed [`ArrayTuple<(T_1, T_2, ..., T_n)>`] and rejecting with the
14704    /// tuple's shared rejection type `E`.
14705    ///
14706    /// Destructure the awaited result via [`ArrayTuple::into_tuple`] to get
14707    /// the individual values back as a native Rust tuple. Implemented for
14708    /// arity 1..=8.
14709    ///
14710    /// Rejects with the first rejection, matching `Promise.all` semantics.
14711    ///
14712    /// # Example
14713    ///
14714    /// ```ignore
14715    /// use js_sys::Promise;
14716    ///
14717    /// let (response, buffer) = Promise::all_tuple((fetch_promise, buffer_promise))
14718    ///     .await?
14719    ///     .into_tuple();
14720    /// ```
14721    #[inline]
14722    pub fn all_tuple<T: PromiseTuple>(promises: T) -> Promise<T::Joined, T::Rejection> {
14723        promises.all()
14724    }
14725
14726    /// Heterogeneous counterpart to [`Promise::all_settled_iterable`]: accepts
14727    /// a Rust tuple of `Promise<T_i, E>` and returns a single [`Promise`]
14728    /// resolving to a typed
14729    /// `ArrayTuple<(PromiseState<T_1, E>, ..., PromiseState<T_n, E>)>`.
14730    ///
14731    /// Unlike [`Promise::all_tuple`], this never rejects early: every input
14732    /// settles (fulfills or rejects) and is reflected by its [`PromiseState`]
14733    /// slot in the result tuple. Implemented for arity 1..=8.
14734    ///
14735    /// # Example
14736    ///
14737    /// ```ignore
14738    /// use js_sys::Promise;
14739    ///
14740    /// let results = Promise::all_settled_tuple((fetch_promise, buffer_promise)).await?;
14741    /// let (response_state, buffer_state) = results.into_tuple();
14742    /// ```
14743    #[inline]
14744    pub fn all_settled_tuple<T: PromiseTuple>(promises: T) -> Promise<T::Settled> {
14745        promises.all_settled()
14746    }
14747}
14748
14749/// Returns a handle to the global scope object.
14750///
14751/// This allows access to the global properties and global names by accessing
14752/// the `Object` returned.
14753pub fn global() -> Object {
14754    use wasm_bindgen::__rt::LazyCell;
14755
14756    #[cfg_attr(target_feature = "atomics", thread_local)]
14757    static GLOBAL: LazyCell<Object> = LazyCell::new(get_global_object);
14758
14759    return GLOBAL.clone();
14760
14761    fn get_global_object() -> Object {
14762        // Accessing the global object is not an easy thing to do, and what we
14763        // basically want is `globalThis` but we can't rely on that existing
14764        // everywhere. In the meantime we've got the fallbacks mentioned in:
14765        //
14766        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
14767        //
14768        // Note that this is pretty heavy code-size wise but it at least gets
14769        // the job largely done for now and avoids the `Function` constructor at
14770        // the end which triggers CSP errors.
14771        #[wasm_bindgen]
14772        extern "C" {
14773            #[derive(Clone, Debug)]
14774            type Global;
14775
14776            #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
14777            static GLOBAL_THIS: Option<Object>;
14778
14779            #[wasm_bindgen(thread_local_v2, js_name = self)]
14780            static SELF: Option<Object>;
14781
14782            #[wasm_bindgen(thread_local_v2, js_name = window)]
14783            static WINDOW: Option<Object>;
14784
14785            #[wasm_bindgen(thread_local_v2, js_name = global)]
14786            static GLOBAL: Option<Object>;
14787        }
14788
14789        // The order is important: in Firefox Extension Content Scripts `globalThis`
14790        // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
14791        let static_object = SELF
14792            .with(Option::clone)
14793            .or_else(|| WINDOW.with(Option::clone))
14794            .or_else(|| GLOBAL_THIS.with(Option::clone))
14795            .or_else(|| GLOBAL.with(Option::clone));
14796        if let Some(obj) = static_object {
14797            if !obj.is_undefined() {
14798                return obj;
14799            }
14800        }
14801
14802        // Global object not found
14803        JsValue::undefined().unchecked_into()
14804    }
14805}
14806
14807// Float16Array
14808//
14809// Rust does not yet have a stable builtin `f16`, so the raw JS bindings live
14810// here and any Rust-side helper APIs use explicit `u16` / `f32` naming. The
14811// unsuffixed float APIs are reserved for a future native `f16` binding.
14812#[wasm_bindgen]
14813extern "C" {
14814    #[wasm_bindgen(extends = Object, typescript_type = "Float16Array")]
14815    #[derive(Clone, Debug)]
14816    pub type Float16Array;
14817
14818    /// The `Float16Array()` constructor creates a new array.
14819    ///
14820    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
14821    #[wasm_bindgen(constructor)]
14822    pub fn new(constructor_arg: &JsValue) -> Float16Array;
14823
14824    /// The `Float16Array()` constructor creates an array with an internal
14825    /// buffer large enough for `length` elements.
14826    ///
14827    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
14828    #[wasm_bindgen(constructor)]
14829    pub fn new_with_length(length: u32) -> Float16Array;
14830
14831    /// The `Float16Array()` constructor creates an array with the given
14832    /// buffer but is a view starting at `byte_offset`.
14833    ///
14834    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
14835    #[wasm_bindgen(constructor)]
14836    pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> Float16Array;
14837
14838    /// The `Float16Array()` constructor creates an array with the given
14839    /// buffer but is a view starting at `byte_offset` for `length` elements.
14840    ///
14841    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
14842    #[wasm_bindgen(constructor)]
14843    pub fn new_with_byte_offset_and_length(
14844        buffer: &JsValue,
14845        byte_offset: u32,
14846        length: u32,
14847    ) -> Float16Array;
14848
14849    /// The `fill()` method fills all elements from a start index to an end
14850    /// index with a static `f32` value.
14851    ///
14852    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
14853    #[wasm_bindgen(method, js_name = fill)]
14854    pub fn fill_with_f32(this: &Float16Array, value: f32, start: u32, end: u32) -> Float16Array;
14855
14856    /// The buffer accessor property represents the `ArrayBuffer` referenced
14857    /// by a `TypedArray` at construction time.
14858    #[wasm_bindgen(getter, method)]
14859    pub fn buffer(this: &Float16Array) -> ArrayBuffer;
14860
14861    /// The `subarray()` method returns a new `TypedArray` on the same
14862    /// `ArrayBuffer` store and with the same element types as this array.
14863    #[wasm_bindgen(method)]
14864    pub fn subarray(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
14865
14866    /// The `slice()` method returns a shallow copy of a portion of a typed
14867    /// array into a new typed array object.
14868    #[wasm_bindgen(method)]
14869    pub fn slice(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
14870
14871    /// The `forEach()` method executes a provided function once per array
14872    /// element, passing values as `f32`.
14873    #[wasm_bindgen(method, js_name = forEach)]
14874    pub fn for_each_as_f32(this: &Float16Array, callback: &mut dyn FnMut(f32, u32, Float16Array));
14875
14876    /// The `forEach()` method executes a provided function once per array
14877    /// element, passing values as `f32`.
14878    #[wasm_bindgen(method, js_name = forEach, catch)]
14879    pub fn try_for_each_as_f32(
14880        this: &Float16Array,
14881        callback: &mut dyn FnMut(f32, u32, Float16Array) -> Result<(), JsError>,
14882    ) -> Result<(), JsValue>;
14883
14884    /// The length accessor property represents the length (in elements) of a
14885    /// typed array.
14886    #[wasm_bindgen(method, getter)]
14887    pub fn length(this: &Float16Array) -> u32;
14888
14889    /// The byteLength accessor property represents the length (in bytes) of a
14890    /// typed array.
14891    #[wasm_bindgen(method, getter, js_name = byteLength)]
14892    pub fn byte_length(this: &Float16Array) -> u32;
14893
14894    /// The byteOffset accessor property represents the offset (in bytes) of a
14895    /// typed array from the start of its `ArrayBuffer`.
14896    #[wasm_bindgen(method, getter, js_name = byteOffset)]
14897    pub fn byte_offset(this: &Float16Array) -> u32;
14898
14899    /// The `set()` method stores multiple values in the typed array, reading
14900    /// input values from a specified array.
14901    #[wasm_bindgen(method)]
14902    pub fn set(this: &Float16Array, src: &JsValue, offset: u32);
14903
14904    /// Gets the value at `idx` as an `f32`, counting from the end if negative.
14905    #[wasm_bindgen(method, js_name = at)]
14906    pub fn at_as_f32(this: &Float16Array, idx: i32) -> Option<f32>;
14907
14908    /// The `copyWithin()` method shallow copies part of a typed array to another
14909    /// location in the same typed array and returns it, without modifying its size.
14910    ///
14911    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
14912    #[wasm_bindgen(method, js_name = copyWithin)]
14913    pub fn copy_within(this: &Float16Array, target: i32, start: i32, end: i32) -> Float16Array;
14914
14915    /// Gets the value at `idx` as an `f32`, equivalent to JavaScript
14916    /// `arr[idx]`.
14917    #[wasm_bindgen(method, indexing_getter)]
14918    pub fn get_index_as_f32(this: &Float16Array, idx: u32) -> f32;
14919
14920    /// Sets the value at `idx` from an `f32`, equivalent to JavaScript
14921    /// `arr[idx] = value`.
14922    #[wasm_bindgen(method, indexing_setter)]
14923    pub fn set_index_from_f32(this: &Float16Array, idx: u32, value: f32);
14924}
14925
14926impl Default for Float16Array {
14927    fn default() -> Self {
14928        Self::new(&JsValue::UNDEFINED.unchecked_into())
14929    }
14930}
14931
14932impl TypedArray for Float16Array {}
14933
14934impl Float16Array {
14935    fn as_uint16_view(&self) -> Uint16Array {
14936        let buffer = self.buffer();
14937        Uint16Array::new_with_byte_offset_and_length(
14938            buffer.as_ref(),
14939            self.byte_offset(),
14940            self.length(),
14941        )
14942    }
14943
14944    /// Creates an array from raw IEEE 754 binary16 bit patterns.
14945    ///
14946    /// This pairs naturally with the optional `half` crate:
14947    ///
14948    /// ```rust
14949    /// use half::f16;
14950    /// use js_sys::Float16Array;
14951    ///
14952    /// let values = [f16::from_f32(1.0), f16::from_f32(-2.0)];
14953    /// let bits = values.map(f16::to_bits);
14954    /// let array = Float16Array::new_from_u16_slice(&bits);
14955    /// ```
14956    pub fn new_from_u16_slice(slice: &[u16]) -> Float16Array {
14957        let array = Float16Array::new_with_length(slice.len() as u32);
14958        array.copy_from_u16_slice(slice);
14959        array
14960    }
14961
14962    /// Copy the raw IEEE 754 binary16 bit patterns from this JS typed array
14963    /// into the destination Rust slice.
14964    ///
14965    /// # Panics
14966    ///
14967    /// This function will panic if this typed array's length is different than
14968    /// the length of the provided `dst` array.
14969    ///
14970    /// Values copied into `dst` can be converted back into `half::f16` with
14971    /// `half::f16::from_bits`.
14972    pub fn copy_to_u16_slice(&self, dst: &mut [u16]) {
14973        self.as_uint16_view().copy_to(dst);
14974    }
14975
14976    /// Copy raw IEEE 754 binary16 bit patterns from the source Rust slice into
14977    /// this JS typed array.
14978    ///
14979    /// # Panics
14980    ///
14981    /// This function will panic if this typed array's length is different than
14982    /// the length of the provided `src` array.
14983    ///
14984    /// When using the optional `half` crate, populate `src` with
14985    /// `half::f16::to_bits()`.
14986    pub fn copy_from_u16_slice(&self, src: &[u16]) {
14987        self.as_uint16_view().copy_from(src);
14988    }
14989
14990    /// Efficiently copies the contents of this JS typed array into a new Vec of
14991    /// raw IEEE 754 binary16 bit patterns.
14992    ///
14993    /// This makes it easy to round-trip through the optional `half` crate:
14994    ///
14995    /// ```rust
14996    /// use half::f16;
14997    ///
14998    /// let bits = array.to_u16_vec();
14999    /// let values: Vec<f16> = bits.into_iter().map(f16::from_bits).collect();
15000    /// ```
15001    pub fn to_u16_vec(&self) -> Vec<u16> {
15002        self.as_uint16_view().to_vec()
15003    }
15004}
15005
15006macro_rules! arrays {
15007    ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
15008        #[wasm_bindgen]
15009        extern "C" {
15010            #[wasm_bindgen(extends = Object, typescript_type = $name)]
15011            #[derive(Clone, Debug)]
15012            pub type $name;
15013
15014            /// The
15015            #[doc = $ctor]
15016            /// constructor creates a new array.
15017            ///
15018            /// [MDN documentation](
15019            #[doc = $mdn]
15020            /// )
15021            #[wasm_bindgen(constructor)]
15022            pub fn new(constructor_arg: &JsValue) -> $name;
15023
15024            /// An
15025            #[doc = $ctor]
15026            /// which creates an array with an internal buffer large
15027            /// enough for `length` elements.
15028            ///
15029            /// [MDN documentation](
15030            #[doc = $mdn]
15031            /// )
15032            #[wasm_bindgen(constructor)]
15033            pub fn new_with_length(length: u32) -> $name;
15034
15035            /// An
15036            #[doc = $ctor]
15037            /// which creates an array from a Rust slice.
15038            ///
15039            /// [MDN documentation](
15040            #[doc = $mdn]
15041            /// )
15042            #[wasm_bindgen(constructor)]
15043            pub fn new_from_slice(slice: &[$ty]) -> $name;
15044
15045            /// An
15046            #[doc = $ctor]
15047            /// which creates an array with the given buffer but is a
15048            /// view starting at `byte_offset`.
15049            ///
15050            /// [MDN documentation](
15051            #[doc = $mdn]
15052            /// )
15053            #[wasm_bindgen(constructor)]
15054            pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
15055
15056            /// An
15057            #[doc = $ctor]
15058            /// which creates an array with the given buffer but is a
15059            /// view starting at `byte_offset` for `length` elements.
15060            ///
15061            /// [MDN documentation](
15062            #[doc = $mdn]
15063            /// )
15064            #[wasm_bindgen(constructor)]
15065            pub fn new_with_byte_offset_and_length(
15066                buffer: &JsValue,
15067                byte_offset: u32,
15068                length: u32,
15069            ) -> $name;
15070
15071            /// The `fill()` method fills all the elements of an array from a start index
15072            /// to an end index with a static value. The end index is not included.
15073            ///
15074            /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
15075            #[wasm_bindgen(method)]
15076            pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
15077
15078            /// The buffer accessor property represents the `ArrayBuffer` referenced
15079            /// by a `TypedArray` at construction time.
15080            #[wasm_bindgen(getter, method)]
15081            pub fn buffer(this: &$name) -> ArrayBuffer;
15082
15083            /// The `subarray()` method returns a new `TypedArray` on the same
15084            /// `ArrayBuffer` store and with the same element types as for this
15085            /// `TypedArray` object.
15086            #[wasm_bindgen(method)]
15087            pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
15088
15089            /// The `slice()` method returns a shallow copy of a portion of a typed
15090            /// array into a new typed array object. This method has the same algorithm
15091            /// as `Array.prototype.slice()`.
15092            #[wasm_bindgen(method)]
15093            pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
15094
15095            /// The `toReversed()` method returns a new typed array with the
15096            /// elements in reverse order, leaving this one unchanged.
15097            #[wasm_bindgen(method, js_name = toReversed)]
15098            pub fn to_reversed(this: &$name) -> $name;
15099
15100            /// The `toSorted()` method returns a new typed array with the
15101            /// elements sorted in ascending numeric order, leaving this one
15102            /// unchanged.
15103            #[wasm_bindgen(method, js_name = toSorted)]
15104            pub fn to_sorted(this: &$name) -> $name;
15105
15106            /// The `with()` method returns a new typed array with the element
15107            /// at `index` replaced by `value`, leaving this one unchanged.
15108            /// Throws a `RangeError` if `index` is out of bounds.
15109            #[wasm_bindgen(method, catch)]
15110            pub fn with(this: &$name, index: i32, value: $ty) -> Result<$name, JsValue>;
15111
15112            /// The `findLast()` method returns the last element for which
15113            /// `predicate` returns `true`, if any.
15114            #[wasm_bindgen(method, js_name = findLast)]
15115            pub fn find_last(this: &$name, predicate: &mut dyn FnMut($ty, u32, $name) -> bool) -> Option<$ty>;
15116
15117            /// The `findLastIndex()` method returns the index of the last
15118            /// element for which `predicate` returns `true`, or `-1`.
15119            #[wasm_bindgen(method, js_name = findLastIndex)]
15120            pub fn find_last_index(this: &$name, predicate: &mut dyn FnMut($ty, u32, $name) -> bool) -> i32;
15121
15122            /// The `includes()` method returns whether the typed array
15123            /// contains `value`, searching from `from_index`, which counts
15124            /// from the end when negative.
15125            #[wasm_bindgen(method)]
15126            pub fn includes(this: &$name, value: $ty, from_index: i32) -> bool;
15127
15128            /// The `indexOf()` method returns the first index at which
15129            /// `value` is found, searching from `from_index`, which counts
15130            /// from the end when negative, or `-1`.
15131            #[wasm_bindgen(method, js_name = indexOf)]
15132            pub fn index_of(this: &$name, value: $ty, from_index: i32) -> i32;
15133
15134            /// The `forEach()` method executes a provided function once per array
15135            /// element. This method has the same algorithm as
15136            /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
15137            /// types here.
15138            #[wasm_bindgen(method, js_name = forEach)]
15139            pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
15140
15141            /// The `forEach()` method executes a provided function once per array
15142            /// element. This method has the same algorithm as
15143            /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
15144            /// types here.
15145            #[wasm_bindgen(method, js_name = forEach, catch)]
15146            pub fn try_for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name) -> Result<(), JsError>) -> Result<(), JsValue>;
15147
15148            /// The length accessor property represents the length (in elements) of a
15149            /// typed array.
15150            #[wasm_bindgen(method, getter)]
15151            pub fn length(this: &$name) -> u32;
15152
15153            /// The byteLength accessor property represents the length (in bytes) of a
15154            /// typed array.
15155            #[wasm_bindgen(method, getter, js_name = byteLength)]
15156            pub fn byte_length(this: &$name) -> u32;
15157
15158            /// The byteOffset accessor property represents the offset (in bytes) of a
15159            /// typed array from the start of its `ArrayBuffer`.
15160            #[wasm_bindgen(method, getter, js_name = byteOffset)]
15161            pub fn byte_offset(this: &$name) -> u32;
15162
15163            /// The `set()` method stores multiple values in the typed array, reading
15164            /// input values from a specified array.
15165            #[wasm_bindgen(method)]
15166            pub fn set(this: &$name, src: &JsValue, offset: u32);
15167
15168            /// Gets the value at `idx`, counting from the end if negative.
15169            #[wasm_bindgen(method)]
15170            pub fn at(this: &$name, idx: i32) -> Option<$ty>;
15171
15172            /// The `copyWithin()` method shallow copies part of a typed array to another
15173            /// location in the same typed array and returns it, without modifying its size.
15174            ///
15175            /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
15176            #[wasm_bindgen(method, js_name = copyWithin)]
15177            pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
15178
15179            /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
15180            #[wasm_bindgen(method, indexing_getter)]
15181            pub fn get_index(this: &$name, idx: u32) -> $ty;
15182
15183            /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
15184            #[wasm_bindgen(method, indexing_setter)]
15185            pub fn set_index(this: &$name, idx: u32, value: $ty);
15186
15187            /// Copies the Rust slice's data to self.
15188            ///
15189            /// This method is not expected to be public. It requires the length of the
15190            /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
15191            #[wasm_bindgen(method, js_name = set)]
15192            fn copy_from_slice(this: &$name, slice: &[$ty]);
15193
15194            /// Copies this TypedArray's data to Rust slice;
15195            ///
15196            /// This method is not expected to be public. It requires the length of the
15197            /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
15198            ///
15199            /// # Workaround
15200            ///
15201            /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
15202            /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
15203            /// us to specify the `this` value inside the function.
15204            ///
15205            /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
15206            /// `slice.set(typed_array)`.
15207            #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
15208            fn copy_to_slice(slice: &mut [$ty], this: &$name);
15209        }
15210
15211        impl $name {
15212            /// Creates a JS typed array which is a view into wasm's linear
15213            /// memory at the slice specified.
15214            ///
15215            /// This function returns a new typed array which is a view into
15216            /// wasm's memory. This view does not copy the underlying data.
15217            ///
15218            /// # Safety
15219            ///
15220            /// Views into WebAssembly memory are only valid so long as the
15221            /// backing buffer isn't resized in JS. Once this function is called
15222            /// any future calls to `Box::new` (or malloc of any form) may cause
15223            /// the returned value here to be invalidated. Use with caution!
15224            ///
15225            /// Additionally the returned object can be safely mutated but the
15226            /// input slice isn't guaranteed to be mutable.
15227            ///
15228            /// Finally, the returned object is disconnected from the input
15229            /// slice's lifetime, so there's no guarantee that the data is read
15230            /// at the right time.
15231            pub unsafe fn view(rust: &[$ty]) -> $name {
15232                wasm_bindgen::__rt::wbg_cast(rust)
15233            }
15234
15235            /// Creates a JS typed array which is a view into wasm's linear
15236            /// memory at the specified pointer with specified length.
15237            ///
15238            /// This function returns a new typed array which is a view into
15239            /// wasm's memory. This view does not copy the underlying data.
15240            ///
15241            /// # Safety
15242            ///
15243            /// Views into WebAssembly memory are only valid so long as the
15244            /// backing buffer isn't resized in JS. Once this function is called
15245            /// any future calls to `Box::new` (or malloc of any form) may cause
15246            /// the returned value here to be invalidated. Use with caution!
15247            ///
15248            /// Additionally the returned object can be safely mutated,
15249            /// the changes are guaranteed to be reflected in the input array.
15250            pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
15251                let slice = core::slice::from_raw_parts_mut(ptr, length);
15252                Self::view(slice)
15253            }
15254
15255            /// Copy the contents of this JS typed array into the destination
15256            /// Rust pointer.
15257            ///
15258            /// This function will efficiently copy the memory from a typed
15259            /// array into this Wasm module's own linear memory, initializing
15260            /// the memory destination provided.
15261            ///
15262            /// # Safety
15263            ///
15264            /// This function requires `dst` to point to a buffer
15265            /// large enough to fit this array's contents.
15266            pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
15267                let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
15268                self.copy_to(slice);
15269            }
15270
15271            /// Copy the contents of this JS typed array into the destination
15272            /// Rust slice.
15273            ///
15274            /// This function will efficiently copy the memory from a typed
15275            /// array into this Wasm module's own linear memory, initializing
15276            /// the memory destination provided.
15277            ///
15278            /// # Panics
15279            ///
15280            /// This function will panic if this typed array's length is
15281            /// different than the length of the provided `dst` array.
15282            pub fn copy_to(&self, dst: &mut [$ty]) {
15283                core::assert_eq!(self.length() as usize, dst.len());
15284                $name::copy_to_slice(dst, self);
15285            }
15286
15287            /// Copy the contents of this JS typed array into the destination
15288            /// Rust slice.
15289            ///
15290            /// This function will efficiently copy the memory from a typed
15291            /// array into this Wasm module's own linear memory, initializing
15292            /// the memory destination provided.
15293            ///
15294            /// # Panics
15295            ///
15296            /// This function will panic if this typed array's length is
15297            /// different than the length of the provided `dst` array.
15298            pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
15299                core::assert_eq!(self.length() as usize, dst.len());
15300                let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
15301                self.copy_to(dst);
15302                dst
15303            }
15304
15305            /// Copy the contents of the source Rust slice into this
15306            /// JS typed array.
15307            ///
15308            /// This function will efficiently copy the memory from within
15309            /// the Wasm module's own linear memory to this typed array.
15310            ///
15311            /// # Panics
15312            ///
15313            /// This function will panic if this typed array's length is
15314            /// different than the length of the provided `src` array.
15315            pub fn copy_from(&self, src: &[$ty]) {
15316                core::assert_eq!(self.length() as usize, src.len());
15317                self.copy_from_slice(src);
15318            }
15319
15320            /// Efficiently copies the contents of this JS typed array into a new Vec.
15321            pub fn to_vec(&self) -> Vec<$ty> {
15322                let len = self.length() as usize;
15323                let mut output = Vec::with_capacity(len);
15324                // Safety: the capacity has been set
15325                unsafe {
15326                    self.raw_copy_to_ptr(output.as_mut_ptr());
15327                    output.set_len(len);
15328                }
15329                output
15330            }
15331        }
15332
15333        impl<'a> From<&'a [$ty]> for $name {
15334            #[inline]
15335            fn from(slice: &'a [$ty]) -> $name {
15336                // This is safe because the `new` function makes a copy if its argument is a TypedArray
15337                $name::new_from_slice(slice)
15338            }
15339        }
15340
15341        impl Default for $name {
15342            fn default() -> Self {
15343                Self::new(&JsValue::UNDEFINED.unchecked_into())
15344            }
15345        }
15346
15347        impl TypedArray for $name {}
15348
15349
15350    )*);
15351}
15352
15353arrays! {
15354    /// `Int8Array()`
15355    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
15356    Int8Array: i8,
15357
15358    /// `Int16Array()`
15359    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
15360    Int16Array: i16,
15361
15362    /// `Int32Array()`
15363    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
15364    Int32Array: i32,
15365
15366    /// `Uint8Array()`
15367    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
15368    Uint8Array: u8,
15369
15370    /// `Uint8ClampedArray()`
15371    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
15372    Uint8ClampedArray: u8,
15373
15374    /// `Uint16Array()`
15375    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
15376    Uint16Array: u16,
15377
15378    /// `Uint32Array()`
15379    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
15380    Uint32Array: u32,
15381
15382    /// `Float32Array()`
15383    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
15384    Float32Array: f32,
15385
15386    /// `Float64Array()`
15387    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
15388    Float64Array: f64,
15389
15390    /// `BigInt64Array()`
15391    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
15392    BigInt64Array: i64,
15393
15394    /// `BigUint64Array()`
15395    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
15396    BigUint64Array: u64,
15397}
15398
15399// Base64Options
15400#[wasm_bindgen]
15401extern "C" {
15402    /// Options for the `Uint8Array` base64 methods: `alphabet` is
15403    /// `"base64"` (default) or `"base64url"`; `lastChunkHandling`, for
15404    /// decoding, is `"loose"` (default), `"strict"` or
15405    /// `"stop-before-partial"`; `omitPadding`, for encoding, drops the
15406    /// trailing `=` characters.
15407    ///
15408    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64#options)
15409    #[wasm_bindgen(extends = Object, typescript_type = "object")]
15410    #[derive(Clone, Debug, PartialEq, Eq)]
15411    pub type Base64Options;
15412
15413    /// Sets the alphabet.
15414    #[wasm_bindgen(method, setter)]
15415    pub fn set_alphabet(this: &Base64Options, alphabet: Base64Alphabet);
15416
15417    /// The alphabet, if set.
15418    #[wasm_bindgen(method, getter, js_name = alphabet)]
15419    pub fn get_alphabet(this: &Base64Options) -> Option<Base64Alphabet>;
15420
15421    /// Sets how a trailing partial chunk is decoded.
15422    #[wasm_bindgen(method, setter, js_name = lastChunkHandling)]
15423    pub fn set_last_chunk_handling(
15424        this: &Base64Options,
15425        last_chunk_handling: Base64LastChunkHandling,
15426    );
15427
15428    /// How a trailing partial chunk is decoded, if set.
15429    #[wasm_bindgen(method, getter, js_name = lastChunkHandling)]
15430    pub fn get_last_chunk_handling(this: &Base64Options) -> Option<Base64LastChunkHandling>;
15431
15432    /// Sets whether encoding omits the trailing `=` padding.
15433    #[wasm_bindgen(method, setter, js_name = omitPadding)]
15434    pub fn set_omit_padding(this: &Base64Options, omit_padding: bool);
15435
15436    /// Whether encoding omits the trailing `=` padding, if set.
15437    #[wasm_bindgen(method, getter, js_name = omitPadding)]
15438    pub fn get_omit_padding(this: &Base64Options) -> Option<bool>;
15439}
15440
15441/// The `alphabet` option of the `Uint8Array` base64 methods.
15442#[wasm_bindgen]
15443#[derive(Clone, Copy, Debug, PartialEq, Eq)]
15444pub enum Base64Alphabet {
15445    /// The standard alphabet with `+` and `/`.
15446    Base64 = "base64",
15447    /// The URL-safe alphabet with `-` and `_`.
15448    Base64Url = "base64url",
15449}
15450
15451/// The `lastChunkHandling` option of the `Uint8Array` base64 decoders.
15452#[wasm_bindgen]
15453#[derive(Clone, Copy, Debug, PartialEq, Eq)]
15454pub enum Base64LastChunkHandling {
15455    /// A trailing partial chunk is decoded if it is well formed.
15456    Loose = "loose",
15457    /// A trailing partial chunk is a `SyntaxError`.
15458    Strict = "strict",
15459    /// A trailing partial chunk is left in the input.
15460    StopBeforePartial = "stop-before-partial",
15461}
15462
15463impl Base64Options {
15464    pub fn new() -> Base64Options {
15465        JsCast::unchecked_into::<Base64Options>(Object::<JsValue>::new())
15466    }
15467}
15468
15469impl Default for Base64Options {
15470    fn default() -> Self {
15471        Self::new()
15472    }
15473}
15474
15475// SetFromResult
15476#[wasm_bindgen]
15477extern "C" {
15478    /// The `{ read, written }` result of [`Uint8Array::set_from_base64`]
15479    /// and [`Uint8Array::set_from_hex`]: how many characters of the input
15480    /// were consumed and how many bytes were written.
15481    ///
15482    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/setFromBase64#return_value)
15483    #[wasm_bindgen(extends = Object, typescript_type = "object")]
15484    #[derive(Clone, Debug, PartialEq, Eq)]
15485    pub type SetFromResult;
15486
15487    /// The number of input characters consumed.
15488    #[wasm_bindgen(method, getter)]
15489    pub fn read(this: &SetFromResult) -> u32;
15490
15491    /// The number of bytes written into the array.
15492    #[wasm_bindgen(method, getter)]
15493    pub fn written(this: &SetFromResult) -> u32;
15494}
15495
15496// Uint8Array base64 / hex
15497#[wasm_bindgen]
15498extern "C" {
15499    /// The `Uint8Array.fromBase64()` static method decodes a base64 string
15500    /// into a new `Uint8Array`. Throws a `SyntaxError` on invalid input.
15501    ///
15502    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64)
15503    #[wasm_bindgen(static_method_of = Uint8Array, catch, js_name = fromBase64)]
15504    pub fn from_base64(text: &str) -> Result<Uint8Array, JsValue>;
15505
15506    /// The `Uint8Array.fromBase64()` static method decodes a base64 string
15507    /// into a new `Uint8Array`, with the given alphabet and last chunk
15508    /// handling. Throws a `SyntaxError` on invalid input.
15509    ///
15510    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64)
15511    #[wasm_bindgen(static_method_of = Uint8Array, catch, js_name = fromBase64)]
15512    pub fn from_base64_with_options(
15513        text: &str,
15514        options: &Base64Options,
15515    ) -> Result<Uint8Array, JsValue>;
15516
15517    /// The `Uint8Array.fromHex()` static method decodes a hex string into a
15518    /// new `Uint8Array`. Throws a `SyntaxError` on invalid input.
15519    ///
15520    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromHex)
15521    #[wasm_bindgen(static_method_of = Uint8Array, catch, js_name = fromHex)]
15522    pub fn from_hex(text: &str) -> Result<Uint8Array, JsValue>;
15523
15524    /// The `toBase64()` method encodes the bytes of this array as a base64
15525    /// string.
15526    ///
15527    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64)
15528    #[wasm_bindgen(method, js_name = toBase64)]
15529    pub fn to_base64(this: &Uint8Array) -> JsString;
15530
15531    /// The `toBase64()` method encodes the bytes of this array as a base64
15532    /// string, with the given alphabet and padding.
15533    ///
15534    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64)
15535    #[wasm_bindgen(method, js_name = toBase64)]
15536    pub fn to_base64_with_options(this: &Uint8Array, options: &Base64Options) -> JsString;
15537
15538    /// The `toHex()` method encodes the bytes of this array as a lowercase
15539    /// hex string.
15540    ///
15541    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex)
15542    #[wasm_bindgen(method, js_name = toHex)]
15543    pub fn to_hex(this: &Uint8Array) -> JsString;
15544
15545    /// The `setFromBase64()` method decodes a base64 string into this
15546    /// array in place, stopping when the array is full, and reports how
15547    /// much was read and written.
15548    ///
15549    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/setFromBase64)
15550    #[wasm_bindgen(method, catch, js_name = setFromBase64)]
15551    pub fn set_from_base64(this: &Uint8Array, text: &str) -> Result<SetFromResult, JsValue>;
15552
15553    /// The `setFromBase64()` method decodes a base64 string into this
15554    /// array in place with the given options, stopping when the array is
15555    /// full, and reports how much was read and written.
15556    ///
15557    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/setFromBase64)
15558    #[wasm_bindgen(method, catch, js_name = setFromBase64)]
15559    pub fn set_from_base64_with_options(
15560        this: &Uint8Array,
15561        text: &str,
15562        options: &Base64Options,
15563    ) -> Result<SetFromResult, JsValue>;
15564
15565    /// The `setFromHex()` method decodes a hex string into this array in
15566    /// place, stopping when the array is full, and reports how much was
15567    /// read and written.
15568    ///
15569    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/setFromHex)
15570    #[wasm_bindgen(method, catch, js_name = setFromHex)]
15571    pub fn set_from_hex(this: &Uint8Array, text: &str) -> Result<SetFromResult, JsValue>;
15572}
15573
15574/// Bridging between JavaScript `Promise`s and Rust `Future`s.
15575///
15576/// Enables `promise.await` directly on any [`Promise`].
15577/// This module is also re-exported by `wasm-bindgen-futures` for backwards compatibility.
15578pub mod futures;