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", no_from_js_value)]
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#[cfg(js_sys_unstable_apis)]
2361impl ArrayBuffer {
2362    /// Copies the buffer's bytes into a `Vec`.
2363    ///
2364    /// A detached buffer has no bytes, so this returns an empty `Vec`.
2365    pub fn to_vec(&self) -> Vec<u8> {
2366        // A detached buffer's `byteLength` is 0, and `new Uint8Array` throws
2367        // on it. `byteLength` is checked rather than `detached`, which is
2368        // newer.
2369        if self.byte_length() == 0 {
2370            return Vec::new();
2371        }
2372        Uint8Array::new(self).to_vec()
2373    }
2374}
2375
2376/// A fresh buffer holding a copy of the bytes.
2377#[cfg(js_sys_unstable_apis)]
2378impl From<&[u8]> for ArrayBuffer {
2379    fn from(bytes: &[u8]) -> ArrayBuffer {
2380        Uint8Array::new_from_slice(bytes).buffer()
2381    }
2382}
2383
2384#[cfg(js_sys_unstable_apis)]
2385impl From<Vec<u8>> for ArrayBuffer {
2386    fn from(bytes: Vec<u8>) -> ArrayBuffer {
2387        bytes.as_slice().into()
2388    }
2389}
2390
2391#[cfg(js_sys_unstable_apis)]
2392impl From<&ArrayBuffer> for Vec<u8> {
2393    fn from(buffer: &ArrayBuffer) -> Vec<u8> {
2394        buffer.to_vec()
2395    }
2396}
2397
2398#[cfg(js_sys_unstable_apis)]
2399impl From<ArrayBuffer> for Vec<u8> {
2400    fn from(buffer: ArrayBuffer) -> Vec<u8> {
2401        buffer.to_vec()
2402    }
2403}
2404
2405// SharedArrayBuffer
2406#[wasm_bindgen]
2407extern "C" {
2408    #[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
2409    #[derive(Clone, Debug)]
2410    pub type SharedArrayBuffer;
2411
2412    /// The `SharedArrayBuffer` object is used to represent a generic,
2413    /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2414    /// object, but in a way that they can be used to create views
2415    /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2416    /// cannot become detached.
2417    ///
2418    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2419    #[cfg(not(js_sys_unstable_apis))]
2420    #[wasm_bindgen(constructor)]
2421    pub fn new(length: u32) -> SharedArrayBuffer;
2422
2423    /// The `SharedArrayBuffer` object is used to represent a generic,
2424    /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2425    /// object, but in a way that they can be used to create views
2426    /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2427    /// cannot become detached.
2428    ///
2429    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2430    #[cfg(js_sys_unstable_apis)]
2431    #[wasm_bindgen(constructor)]
2432    pub fn new(length: usize) -> SharedArrayBuffer;
2433
2434    /// The `SharedArrayBuffer` object is used to represent a generic,
2435    /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2436    /// object, but in a way that they can be used to create views
2437    /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2438    /// cannot become detached.
2439    ///
2440    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2441    #[wasm_bindgen(constructor)]
2442    pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> SharedArrayBuffer;
2443
2444    /// The `byteLength` accessor property represents the length of
2445    /// an `SharedArrayBuffer` in bytes. This is established when
2446    /// the `SharedArrayBuffer` is constructed and cannot be changed.
2447    ///
2448    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2449    #[cfg(not(js_sys_unstable_apis))]
2450    #[wasm_bindgen(method, getter, js_name = byteLength)]
2451    pub fn byte_length(this: &SharedArrayBuffer) -> u32;
2452
2453    /// The `byteLength` accessor property represents the length of
2454    /// an `SharedArrayBuffer` in bytes. This is established when
2455    /// the `SharedArrayBuffer` is constructed and cannot be changed.
2456    ///
2457    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2458    #[cfg(js_sys_unstable_apis)]
2459    #[wasm_bindgen(method, getter, js_name = byteLength)]
2460    pub fn byte_length(this: &SharedArrayBuffer) -> usize;
2461
2462    /// The `growable` accessor property of `SharedArrayBuffer` instances returns whether
2463    /// this `SharedArrayBuffer` can be grown or not.
2464    ///
2465    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/growable)
2466    #[wasm_bindgen(method, getter)]
2467    pub fn growable(this: &SharedArrayBuffer) -> bool;
2468
2469    /// The `grow()` method of `SharedArrayBuffer` instances grows the
2470    /// `SharedArrayBuffer` to the specified size, in bytes.
2471    ///
2472    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/grow)
2473    #[wasm_bindgen(method, catch)]
2474    pub fn grow(this: &SharedArrayBuffer, new_byte_length: usize) -> Result<(), JsValue>;
2475
2476    /// The `maxByteLength` accessor property of `SharedArrayBuffer` instances returns the maximum
2477    /// length (in bytes) that this `SharedArrayBuffer` can be resized to.
2478    ///
2479    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/maxByteLength)
2480    #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2481    pub fn max_byte_length(this: &SharedArrayBuffer) -> usize;
2482
2483    /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2484    /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2485    /// up to end, exclusive.
2486    ///
2487    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2488    #[cfg(not(js_sys_unstable_apis))]
2489    #[wasm_bindgen(method)]
2490    pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer;
2491
2492    /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2493    /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2494    /// up to end, exclusive. Negative indices count from the end.
2495    ///
2496    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2497    #[cfg(js_sys_unstable_apis)]
2498    #[wasm_bindgen(method)]
2499    pub fn slice(this: &SharedArrayBuffer, begin: isize, end: isize) -> SharedArrayBuffer;
2500
2501    /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2502    /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2503    /// up to end, exclusive.
2504    ///
2505    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2506    #[cfg(not(js_sys_unstable_apis))]
2507    #[wasm_bindgen(method)]
2508    pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2509
2510    /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2511    /// are a copy of this `SharedArrayBuffer`'s bytes from begin to end.
2512    /// Negative indices count from the end.
2513    ///
2514    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2515    #[cfg(js_sys_unstable_apis)]
2516    #[wasm_bindgen(method)]
2517    pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2518
2519    // Next major: deprecate
2520    /// Like `slice()` but with the `end` argument.
2521    ///
2522    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2523    #[wasm_bindgen(method, js_name = slice)]
2524    pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer;
2525}
2526
2527// Array Iterator
2528#[wasm_bindgen]
2529extern "C" {
2530    /// The `keys()` method returns a new Array Iterator object that contains the
2531    /// keys for each index in the array.
2532    ///
2533    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys)
2534    #[wasm_bindgen(method)]
2535    pub fn keys<T>(this: &Array<T>) -> Iterator<T>;
2536
2537    /// The `entries()` method returns a new Array Iterator object that contains
2538    /// the key/value pairs for each index in the array.
2539    ///
2540    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2541    #[cfg(not(js_sys_unstable_apis))]
2542    #[wasm_bindgen(method)]
2543    #[deprecated(note = "recommended to use `Array::entries_typed` instead for typing")]
2544    #[allow(deprecated)]
2545    pub fn entries<T>(this: &Array<T>) -> Iterator<T>;
2546
2547    /// The `entries()` method returns a new Array Iterator object that contains
2548    /// the key/value pairs for each index in the array.
2549    ///
2550    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2551    #[cfg(js_sys_unstable_apis)]
2552    #[wasm_bindgen(method)]
2553    pub fn entries<T>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2554
2555    // Next major: deprecate
2556    /// The `entries()` method returns a new Array Iterator object that contains
2557    /// the key/value pairs for each index in the array.
2558    ///
2559    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2560    #[wasm_bindgen(method, js_name = entries)]
2561    pub fn entries_typed<T>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2562
2563    /// The `values()` method returns a new Array Iterator object that
2564    /// contains the values for each index in the array.
2565    ///
2566    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
2567    #[wasm_bindgen(method)]
2568    pub fn values<T>(this: &Array<T>) -> Iterator<T>;
2569}
2570
2571// FIXME(next-major): rename this trait to `ArrayBufferView`. The DOM/WebIDL
2572// spec name `ArrayBufferView` covers both `DataView` and the typed-array
2573// types, which more accurately reflects the set of types that implement this
2574// trait. The `TypedArray` name is kept for now to avoid a breaking change.
2575pub trait TypedArray: JsGeneric {}
2576
2577impl TypedArray for DataView {}
2578
2579// Next major: use usize/isize for indices
2580/// The `Atomics` object provides atomic operations as static methods.
2581/// They are used with `SharedArrayBuffer` objects.
2582///
2583/// The Atomic operations are installed on an `Atomics` module. Unlike
2584/// the other global objects, `Atomics` is not a constructor. You cannot
2585/// use it with a new operator or invoke the `Atomics` object as a
2586/// function. All properties and methods of `Atomics` are static
2587/// (as is the case with the Math object, for example).
2588/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
2589#[allow(non_snake_case)]
2590pub mod Atomics {
2591    use super::*;
2592
2593    #[wasm_bindgen]
2594    extern "C" {
2595        /// The static `Atomics.add()` method adds a given value at a given
2596        /// position in the array and returns the old value at that position.
2597        /// This atomic operation guarantees that no other write happens
2598        /// until the modified value is written back.
2599        ///
2600        /// You should use `add_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2601        ///
2602        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2603        #[wasm_bindgen(js_namespace = Atomics, catch)]
2604        pub fn add<T: TypedArray = Int32Array>(
2605            typed_array: &T,
2606            index: u32,
2607            value: i32,
2608        ) -> Result<i32, JsValue>;
2609
2610        /// The static `Atomics.add()` method adds a given value at a given
2611        /// position in the array and returns the old value at that position.
2612        /// This atomic operation guarantees that no other write happens
2613        /// until the modified value is written back.
2614        ///
2615        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2616        ///
2617        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2618        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = add)]
2619        pub fn add_bigint<T: TypedArray = Int32Array>(
2620            typed_array: &T,
2621            index: u32,
2622            value: i64,
2623        ) -> Result<i64, JsValue>;
2624
2625        /// The static `Atomics.and()` method computes a bitwise AND with a given
2626        /// value at a given position in the array, and returns the old value
2627        /// at that position.
2628        /// This atomic operation guarantees that no other write happens
2629        /// until the modified value is written back.
2630        ///
2631        /// You should use `and_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2632        ///
2633        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2634        #[wasm_bindgen(js_namespace = Atomics, catch)]
2635        pub fn and<T: TypedArray = Int32Array>(
2636            typed_array: &T,
2637            index: u32,
2638            value: i32,
2639        ) -> Result<i32, JsValue>;
2640
2641        /// The static `Atomics.and()` method computes a bitwise AND with a given
2642        /// value at a given position in the array, and returns the old value
2643        /// at that position.
2644        /// This atomic operation guarantees that no other write happens
2645        /// until the modified value is written back.
2646        ///
2647        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2648        ///
2649        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2650        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = and)]
2651        pub fn and_bigint<T: TypedArray = Int32Array>(
2652            typed_array: &T,
2653            index: u32,
2654            value: i64,
2655        ) -> Result<i64, JsValue>;
2656
2657        /// The static `Atomics.compareExchange()` method exchanges a given
2658        /// replacement value at a given position in the array, if a given expected
2659        /// value equals the old value. It returns the old value at that position
2660        /// whether it was equal to the expected value or not.
2661        /// This atomic operation guarantees that no other write happens
2662        /// until the modified value is written back.
2663        ///
2664        /// You should use `compare_exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2665        ///
2666        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2667        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2668        pub fn compare_exchange<T: TypedArray = Int32Array>(
2669            typed_array: &T,
2670            index: u32,
2671            expected_value: i32,
2672            replacement_value: i32,
2673        ) -> Result<i32, JsValue>;
2674
2675        /// The static `Atomics.compareExchange()` method exchanges a given
2676        /// replacement value at a given position in the array, if a given expected
2677        /// value equals the old value. It returns the old value at that position
2678        /// whether it was equal to the expected value or not.
2679        /// This atomic operation guarantees that no other write happens
2680        /// until the modified value is written back.
2681        ///
2682        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2683        ///
2684        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2685        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2686        pub fn compare_exchange_bigint<T: TypedArray = Int32Array>(
2687            typed_array: &T,
2688            index: u32,
2689            expected_value: i64,
2690            replacement_value: i64,
2691        ) -> Result<i64, JsValue>;
2692
2693        /// The static `Atomics.exchange()` method stores a given value at a given
2694        /// position in the array and returns the old value at that position.
2695        /// This atomic operation guarantees that no other write happens
2696        /// until the modified value is written back.
2697        ///
2698        /// You should use `exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2699        ///
2700        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2701        #[wasm_bindgen(js_namespace = Atomics, catch)]
2702        pub fn exchange<T: TypedArray = Int32Array>(
2703            typed_array: &T,
2704            index: u32,
2705            value: i32,
2706        ) -> Result<i32, JsValue>;
2707
2708        /// The static `Atomics.exchange()` method stores a given value at a given
2709        /// position in the array and returns the old value at that position.
2710        /// This atomic operation guarantees that no other write happens
2711        /// until the modified value is written back.
2712        ///
2713        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2714        ///
2715        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2716        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = exchange)]
2717        pub fn exchange_bigint<T: TypedArray = Int32Array>(
2718            typed_array: &T,
2719            index: u32,
2720            value: i64,
2721        ) -> Result<i64, JsValue>;
2722
2723        /// The static `Atomics.isLockFree()` method is used to determine
2724        /// whether to use locks or atomic operations. It returns true,
2725        /// if the given size is one of the `BYTES_PER_ELEMENT` property
2726        /// of integer `TypedArray` types.
2727        ///
2728        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree)
2729        #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)]
2730        pub fn is_lock_free(size: u32) -> bool;
2731
2732        /// The static `Atomics.load()` method returns a value at a given
2733        /// position in the array.
2734        ///
2735        /// You should use `load_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2736        ///
2737        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2738        #[wasm_bindgen(js_namespace = Atomics, catch)]
2739        pub fn load<T: TypedArray = Int32Array>(
2740            typed_array: &T,
2741            index: u32,
2742        ) -> Result<i32, JsValue>;
2743
2744        /// The static `Atomics.load()` method returns a value at a given
2745        /// position in the array.
2746        ///
2747        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2748        ///
2749        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2750        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = load)]
2751        pub fn load_bigint<T: TypedArray = Int32Array>(
2752            typed_array: &T,
2753            index: i64,
2754        ) -> Result<i64, JsValue>;
2755
2756        /// The static `Atomics.notify()` method notifies up some agents that
2757        /// are sleeping in the wait queue.
2758        /// Note: This operation works with a shared `Int32Array` only.
2759        /// If `count` is not provided, notifies all the agents in the queue.
2760        ///
2761        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2762        #[wasm_bindgen(js_namespace = Atomics, catch)]
2763        pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>;
2764
2765        /// The static `Atomics.notify()` method notifies up some agents that
2766        /// are sleeping in the wait queue.
2767        /// Note: This operation works with a shared `Int32Array` only.
2768        /// If `count` is not provided, notifies all the agents in the queue.
2769        ///
2770        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2771        #[wasm_bindgen(js_namespace = Atomics, catch)]
2772        pub fn notify_bigint(typed_array: &BigInt64Array, index: u32) -> Result<u32, JsValue>;
2773
2774        /// Notifies up to `count` agents in the wait queue.
2775        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2776        pub fn notify_with_count(
2777            typed_array: &Int32Array,
2778            index: u32,
2779            count: u32,
2780        ) -> Result<u32, JsValue>;
2781
2782        /// Notifies up to `count` agents in the wait queue.
2783        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2784        pub fn notify_bigint_with_count(
2785            typed_array: &BigInt64Array,
2786            index: u32,
2787            count: u32,
2788        ) -> Result<u32, JsValue>;
2789
2790        /// The static `Atomics.or()` method computes a bitwise OR with a given value
2791        /// at a given position in the array, and returns the old value at that position.
2792        /// This atomic operation guarantees that no other write happens
2793        /// until the modified value is written back.
2794        ///
2795        /// You should use `or_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2796        ///
2797        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2798        #[wasm_bindgen(js_namespace = Atomics, catch)]
2799        pub fn or<T: TypedArray = Int32Array>(
2800            typed_array: &T,
2801            index: u32,
2802            value: i32,
2803        ) -> Result<i32, JsValue>;
2804
2805        /// The static `Atomics.or()` method computes a bitwise OR with a given value
2806        /// at a given position in the array, and returns the old value at that position.
2807        /// This atomic operation guarantees that no other write happens
2808        /// until the modified value is written back.
2809        ///
2810        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2811        ///
2812        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2813        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = or)]
2814        pub fn or_bigint<T: TypedArray = Int32Array>(
2815            typed_array: &T,
2816            index: u32,
2817            value: i64,
2818        ) -> Result<i64, JsValue>;
2819
2820        /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2821        /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2822        /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2823        /// current thread.
2824        ///
2825        /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2826        /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2827        /// per Intel's optimization manual. It could be a no-op in certain platforms.
2828        ///
2829        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2830        ///
2831        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2832        #[wasm_bindgen(js_namespace = Atomics)]
2833        pub fn pause();
2834
2835        /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2836        /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2837        /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2838        /// current thread.
2839        ///
2840        /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2841        /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2842        /// per Intel's optimization manual. It could be a no-op in certain platforms.
2843        ///
2844        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2845        ///
2846        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2847        #[wasm_bindgen(js_namespace = Atomics)]
2848        pub fn pause_with_hint(duration_hint: u32);
2849
2850        /// The static `Atomics.store()` method stores a given value at the given
2851        /// position in the array and returns that value.
2852        ///
2853        /// You should use `store_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2854        ///
2855        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2856        #[wasm_bindgen(js_namespace = Atomics, catch)]
2857        pub fn store<T: TypedArray = Int32Array>(
2858            typed_array: &T,
2859            index: u32,
2860            value: i32,
2861        ) -> Result<i32, JsValue>;
2862
2863        /// The static `Atomics.store()` method stores a given value at the given
2864        /// position in the array and returns that value.
2865        ///
2866        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2867        ///
2868        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2869        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = store)]
2870        pub fn store_bigint<T: TypedArray = Int32Array>(
2871            typed_array: &T,
2872            index: u32,
2873            value: i64,
2874        ) -> Result<i64, JsValue>;
2875
2876        /// The static `Atomics.sub()` method subtracts a given value at a
2877        /// given position in the array and returns the old value at that position.
2878        /// This atomic operation guarantees that no other write happens
2879        /// until the modified value is written back.
2880        ///
2881        /// You should use `sub_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2882        ///
2883        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2884        #[wasm_bindgen(js_namespace = Atomics, catch)]
2885        pub fn sub<T: TypedArray = Int32Array>(
2886            typed_array: &T,
2887            index: u32,
2888            value: i32,
2889        ) -> Result<i32, JsValue>;
2890
2891        /// The static `Atomics.sub()` method subtracts a given value at a
2892        /// given position in the array and returns the old value at that position.
2893        /// This atomic operation guarantees that no other write happens
2894        /// until the modified value is written back.
2895        ///
2896        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2897        ///
2898        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2899        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = sub)]
2900        pub fn sub_bigint<T: TypedArray = Int32Array>(
2901            typed_array: &T,
2902            index: u32,
2903            value: i64,
2904        ) -> Result<i64, JsValue>;
2905
2906        /// The static `Atomics.wait()` method verifies that a given
2907        /// position in an `Int32Array` still contains a given value
2908        /// and if so sleeps, awaiting a wakeup or a timeout.
2909        /// It returns a string which is either "ok", "not-equal", or "timed-out".
2910        /// Note: This operation only works with a shared `Int32Array`
2911        /// and may not be allowed on the main thread.
2912        ///
2913        /// You should use `wait_bigint` to operate on a `BigInt64Array`.
2914        ///
2915        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2916        #[wasm_bindgen(js_namespace = Atomics, catch)]
2917        pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>;
2918
2919        /// The static `Atomics.wait()` method verifies that a given
2920        /// position in an `BigInt64Array` still contains a given value
2921        /// and if so sleeps, awaiting a wakeup or a timeout.
2922        /// It returns a string which is either "ok", "not-equal", or "timed-out".
2923        /// Note: This operation only works with a shared `BigInt64Array`
2924        /// and may not be allowed on the main thread.
2925        ///
2926        /// You should use `wait` to operate on a `Int32Array`.
2927        ///
2928        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2929        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2930        pub fn wait_bigint(
2931            typed_array: &BigInt64Array,
2932            index: u32,
2933            value: i64,
2934        ) -> Result<JsString, JsValue>;
2935
2936        /// Like `wait()`, but with timeout
2937        ///
2938        /// You should use `wait_with_timeout_bigint` to operate on a `BigInt64Array`.
2939        ///
2940        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2941        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2942        pub fn wait_with_timeout(
2943            typed_array: &Int32Array,
2944            index: u32,
2945            value: i32,
2946            timeout: f64,
2947        ) -> Result<JsString, JsValue>;
2948
2949        /// Like `wait()`, but with timeout
2950        ///
2951        /// You should use `wait_with_timeout` to operate on a `Int32Array`.
2952        ///
2953        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2954        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2955        pub fn wait_with_timeout_bigint(
2956            typed_array: &BigInt64Array,
2957            index: u32,
2958            value: i64,
2959            timeout: f64,
2960        ) -> Result<JsString, JsValue>;
2961
2962        /// The static `Atomics.waitAsync()` method verifies that a given position in an
2963        /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2964        /// wakeup or a timeout. It returns an object with two properties. The first
2965        /// property `async` is a boolean which if true indicates that the second
2966        /// property `value` is a promise. If `async` is false then value is a string
2967        /// whether equal to either "not-equal" or "timed-out".
2968        /// Note: This operation only works with a shared `Int32Array` and may be used
2969        /// on the main thread.
2970        ///
2971        /// You should use `wait_async_bigint` to operate on a `BigInt64Array`.
2972        ///
2973        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2974        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2975        pub fn wait_async(
2976            typed_array: &Int32Array,
2977            index: u32,
2978            value: i32,
2979        ) -> Result<Object, JsValue>;
2980
2981        /// The static `Atomics.waitAsync()` method verifies that a given position in an
2982        /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2983        /// wakeup or a timeout. It returns an object with two properties. The first
2984        /// property `async` is a boolean which if true indicates that the second
2985        /// property `value` is a promise. If `async` is false then value is a string
2986        /// whether equal to either "not-equal" or "timed-out".
2987        /// Note: This operation only works with a shared `BigInt64Array` and may be used
2988        /// on the main thread.
2989        ///
2990        /// You should use `wait_async` to operate on a `Int32Array`.
2991        ///
2992        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2993        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2994        pub fn wait_async_bigint(
2995            typed_array: &BigInt64Array,
2996            index: u32,
2997            value: i64,
2998        ) -> Result<Object, JsValue>;
2999
3000        /// Like `waitAsync()`, but with timeout
3001        ///
3002        /// You should use `wait_async_with_timeout_bigint` to operate on a `BigInt64Array`.
3003        ///
3004        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
3005        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
3006        pub fn wait_async_with_timeout(
3007            typed_array: &Int32Array,
3008            index: u32,
3009            value: i32,
3010            timeout: f64,
3011        ) -> Result<Object, JsValue>;
3012
3013        /// Like `waitAsync()`, but with timeout
3014        ///
3015        /// You should use `wait_async_with_timeout` to operate on a `Int32Array`.
3016        ///
3017        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
3018        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
3019        pub fn wait_async_with_timeout_bigint(
3020            typed_array: &BigInt64Array,
3021            index: u32,
3022            value: i64,
3023            timeout: f64,
3024        ) -> Result<Object, JsValue>;
3025
3026        /// The static `Atomics.xor()` method computes a bitwise XOR
3027        /// with a given value at a given position in the array,
3028        /// and returns the old value at that position.
3029        /// This atomic operation guarantees that no other write happens
3030        /// until the modified value is written back.
3031        ///
3032        /// You should use `xor_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
3033        ///
3034        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
3035        #[wasm_bindgen(js_namespace = Atomics, catch)]
3036        pub fn xor<T: TypedArray = Int32Array>(
3037            typed_array: &T,
3038            index: u32,
3039            value: i32,
3040        ) -> Result<i32, JsValue>;
3041
3042        /// The static `Atomics.xor()` method computes a bitwise XOR
3043        /// with a given value at a given position in the array,
3044        /// and returns the old value at that position.
3045        /// This atomic operation guarantees that no other write happens
3046        /// until the modified value is written back.
3047        ///
3048        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
3049        ///
3050        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
3051        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = xor)]
3052        pub fn xor_bigint<T: TypedArray = Int32Array>(
3053            typed_array: &T,
3054            index: u32,
3055            value: i64,
3056        ) -> Result<i64, JsValue>;
3057    }
3058}
3059
3060// BigInt
3061#[wasm_bindgen]
3062extern "C" {
3063    #[wasm_bindgen(extends = Object, is_type_of = |v| v.is_bigint(), typescript_type = "bigint")]
3064    #[derive(Clone, PartialEq, Eq)]
3065    pub type BigInt;
3066
3067    #[wasm_bindgen(catch, js_name = BigInt)]
3068    fn new_bigint(value: &JsValue) -> Result<BigInt, Error>;
3069
3070    #[wasm_bindgen(js_name = BigInt)]
3071    fn new_bigint_unchecked(value: &JsValue) -> BigInt;
3072
3073    /// Clamps a BigInt value to a signed integer value, and returns that value.
3074    ///
3075    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)
3076    #[wasm_bindgen(static_method_of = BigInt, js_name = asIntN)]
3077    pub fn as_int_n(bits: f64, bigint: &BigInt) -> BigInt;
3078
3079    /// Clamps a BigInt value to an unsigned integer value, and returns that value.
3080    ///
3081    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)
3082    #[wasm_bindgen(static_method_of = BigInt, js_name = asUintN)]
3083    pub fn as_uint_n(bits: f64, bigint: &BigInt) -> BigInt;
3084
3085    /// 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.
3086    ///
3087    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
3088    #[cfg(not(js_sys_unstable_apis))]
3089    #[wasm_bindgen(method, js_name = toLocaleString)]
3090    pub fn to_locale_string(this: &BigInt, locales: &JsValue, options: &JsValue) -> JsString;
3091
3092    /// 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.
3093    ///
3094    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
3095    #[cfg(js_sys_unstable_apis)]
3096    #[wasm_bindgen(method, js_name = toLocaleString)]
3097    pub fn to_locale_string(
3098        this: &BigInt,
3099        locales: &[JsString],
3100        options: &Intl::NumberFormatOptions,
3101    ) -> JsString;
3102
3103    // Next major: deprecate
3104    /// 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.
3105    ///
3106    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
3107    #[wasm_bindgen(catch, method, js_name = toString)]
3108    pub fn to_string(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
3109
3110    /// Returns a string representing this BigInt value in the specified radix (base).
3111    ///
3112    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
3113    #[cfg(js_sys_unstable_apis)]
3114    #[wasm_bindgen(catch, method, js_name = toString)]
3115    pub fn to_string_with_radix(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
3116
3117    #[wasm_bindgen(method, js_name = toString)]
3118    fn to_string_unchecked(this: &BigInt, radix: u8) -> String;
3119
3120    /// Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method.
3121    ///
3122    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)
3123    #[wasm_bindgen(method, js_name = valueOf)]
3124    pub fn value_of(this: &BigInt, radix: u8) -> BigInt;
3125}
3126
3127impl BigInt {
3128    /// Creates a new BigInt value.
3129    ///
3130    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)
3131    #[inline]
3132    pub fn new(value: &JsValue) -> Result<BigInt, Error> {
3133        new_bigint(value)
3134    }
3135
3136    /// Applies the binary `/` JS operator on two `BigInt`s, catching and returning any `RangeError` thrown.
3137    ///
3138    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division)
3139    pub fn checked_div(&self, rhs: &Self) -> Result<Self, RangeError> {
3140        let result = JsValue::as_ref(self).checked_div(JsValue::as_ref(rhs));
3141
3142        if result.is_instance_of::<RangeError>() {
3143            Err(result.unchecked_into())
3144        } else {
3145            Ok(result.unchecked_into())
3146        }
3147    }
3148
3149    /// Applies the binary `**` JS operator on the two `BigInt`s.
3150    ///
3151    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
3152    #[inline]
3153    pub fn pow(&self, rhs: &Self) -> Self {
3154        JsValue::as_ref(self)
3155            .pow(JsValue::as_ref(rhs))
3156            .unchecked_into()
3157    }
3158
3159    /// Returns a tuple of this [`BigInt`]'s absolute value along with a
3160    /// [`bool`] indicating whether the [`BigInt`] was negative.
3161    fn abs(&self) -> (Self, bool) {
3162        if self < &BigInt::from(0) {
3163            (-self, true)
3164        } else {
3165            (self.clone(), false)
3166        }
3167    }
3168}
3169
3170macro_rules! bigint_from {
3171    ($($x:ident)*) => ($(
3172        impl From<$x> for BigInt {
3173            #[inline]
3174            fn from(x: $x) -> BigInt {
3175                new_bigint_unchecked(&JsValue::from(x))
3176            }
3177        }
3178
3179        impl PartialEq<$x> for BigInt {
3180            #[inline]
3181            fn eq(&self, other: &$x) -> bool {
3182                JsValue::from(self) == JsValue::from(BigInt::from(*other))
3183            }
3184        }
3185    )*)
3186}
3187bigint_from!(i8 u8 i16 u16 i32 u32 isize usize);
3188
3189macro_rules! bigint_from_big {
3190    ($($x:ident)*) => ($(
3191        impl From<$x> for BigInt {
3192            #[inline]
3193            fn from(x: $x) -> BigInt {
3194                JsValue::from(x).unchecked_into()
3195            }
3196        }
3197
3198        impl PartialEq<$x> for BigInt {
3199            #[inline]
3200            fn eq(&self, other: &$x) -> bool {
3201                self == &BigInt::from(*other)
3202            }
3203        }
3204
3205        impl TryFrom<BigInt> for $x {
3206            type Error = BigInt;
3207
3208            #[inline]
3209            fn try_from(x: BigInt) -> Result<Self, BigInt> {
3210                Self::try_from(JsValue::from(x)).map_err(JsCast::unchecked_into)
3211            }
3212        }
3213    )*)
3214}
3215bigint_from_big!(i64 u64 i128 u128);
3216
3217impl PartialEq<Number> for BigInt {
3218    #[inline]
3219    fn eq(&self, other: &Number) -> bool {
3220        JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
3221    }
3222}
3223
3224impl Not for &BigInt {
3225    type Output = BigInt;
3226
3227    #[inline]
3228    fn not(self) -> Self::Output {
3229        JsValue::as_ref(self).bit_not().unchecked_into()
3230    }
3231}
3232
3233forward_deref_unop!(impl Not, not for BigInt);
3234forward_js_unop!(impl Neg, neg for BigInt);
3235forward_js_binop!(impl BitAnd, bitand for BigInt);
3236forward_js_binop!(impl BitOr, bitor for BigInt);
3237forward_js_binop!(impl BitXor, bitxor for BigInt);
3238forward_js_binop!(impl Shl, shl for BigInt);
3239forward_js_binop!(impl Shr, shr for BigInt);
3240forward_js_binop!(impl Add, add for BigInt);
3241forward_js_binop!(impl Sub, sub for BigInt);
3242forward_js_binop!(impl Div, div for BigInt);
3243forward_js_binop!(impl Mul, mul for BigInt);
3244forward_js_binop!(impl Rem, rem for BigInt);
3245sum_product!(BigInt);
3246
3247partialord_ord!(BigInt);
3248
3249impl Default for BigInt {
3250    fn default() -> Self {
3251        BigInt::from(i32::default())
3252    }
3253}
3254
3255impl FromStr for BigInt {
3256    type Err = Error;
3257
3258    #[inline]
3259    fn from_str(s: &str) -> Result<Self, Self::Err> {
3260        BigInt::new(&s.into())
3261    }
3262}
3263
3264impl fmt::Debug for BigInt {
3265    #[inline]
3266    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3267        fmt::Display::fmt(self, f)
3268    }
3269}
3270
3271impl fmt::Display for BigInt {
3272    #[inline]
3273    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3274        let (abs, is_neg) = self.abs();
3275        f.pad_integral(!is_neg, "", &abs.to_string_unchecked(10))
3276    }
3277}
3278
3279impl fmt::Binary for BigInt {
3280    #[inline]
3281    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3282        let (abs, is_neg) = self.abs();
3283        f.pad_integral(!is_neg, "0b", &abs.to_string_unchecked(2))
3284    }
3285}
3286
3287impl fmt::Octal for BigInt {
3288    #[inline]
3289    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3290        let (abs, is_neg) = self.abs();
3291        f.pad_integral(!is_neg, "0o", &abs.to_string_unchecked(8))
3292    }
3293}
3294
3295impl fmt::LowerHex for BigInt {
3296    #[inline]
3297    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3298        let (abs, is_neg) = self.abs();
3299        f.pad_integral(!is_neg, "0x", &abs.to_string_unchecked(16))
3300    }
3301}
3302
3303impl fmt::UpperHex for BigInt {
3304    #[inline]
3305    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3306        let (abs, is_neg) = self.abs();
3307        let mut s: String = abs.to_string_unchecked(16);
3308        s.make_ascii_uppercase();
3309        f.pad_integral(!is_neg, "0x", &s)
3310    }
3311}
3312
3313// Boolean
3314#[wasm_bindgen]
3315extern "C" {
3316    #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
3317    #[derive(Clone, PartialEq, Eq)]
3318    pub type Boolean;
3319
3320    /// The `Boolean()` constructor creates an object wrapper for a boolean value.
3321    ///
3322    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
3323    #[cfg(not(js_sys_unstable_apis))]
3324    #[wasm_bindgen(constructor)]
3325    #[deprecated(note = "recommended to use `Boolean::from` instead")]
3326    #[allow(deprecated)]
3327    pub fn new(value: &JsValue) -> Boolean;
3328
3329    /// The `valueOf()` method returns the primitive value of a `Boolean` object.
3330    ///
3331    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf)
3332    #[wasm_bindgen(method, js_name = valueOf)]
3333    pub fn value_of(this: &Boolean) -> bool;
3334}
3335
3336impl UpcastFrom<bool> for Boolean {}
3337impl UpcastFrom<Boolean> for bool {}
3338
3339impl Boolean {
3340    /// Typed Boolean true constant.
3341    pub const TRUE: Boolean = Self {
3342        obj: Object {
3343            obj: JsValue::TRUE,
3344            generics: PhantomData,
3345        },
3346    };
3347
3348    /// Typed Boolean false constant.
3349    pub const FALSE: Boolean = Self {
3350        obj: Object {
3351            obj: JsValue::FALSE,
3352            generics: PhantomData,
3353        },
3354    };
3355}
3356
3357impl From<bool> for Boolean {
3358    #[inline]
3359    fn from(b: bool) -> Boolean {
3360        Boolean::unchecked_from_js(JsValue::from(b))
3361    }
3362}
3363
3364impl From<Boolean> for bool {
3365    #[inline]
3366    fn from(b: Boolean) -> bool {
3367        b.value_of()
3368    }
3369}
3370
3371impl PartialEq<bool> for Boolean {
3372    #[inline]
3373    fn eq(&self, other: &bool) -> bool {
3374        self.value_of() == *other
3375    }
3376}
3377
3378impl fmt::Debug for Boolean {
3379    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3380        fmt::Debug::fmt(&self.value_of(), f)
3381    }
3382}
3383
3384impl fmt::Display for Boolean {
3385    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3386        fmt::Display::fmt(&self.value_of(), f)
3387    }
3388}
3389
3390impl Default for Boolean {
3391    fn default() -> Self {
3392        Self::from(bool::default())
3393    }
3394}
3395
3396impl Not for &Boolean {
3397    type Output = Boolean;
3398
3399    #[inline]
3400    fn not(self) -> Self::Output {
3401        (!JsValue::as_ref(self)).into()
3402    }
3403}
3404
3405forward_deref_unop!(impl Not, not for Boolean);
3406
3407partialord_ord!(Boolean);
3408
3409// DataView
3410#[wasm_bindgen]
3411extern "C" {
3412    #[wasm_bindgen(extends = Object, typescript_type = "DataView")]
3413    #[derive(Clone, Debug, PartialEq, Eq)]
3414    pub type DataView;
3415
3416    /// The `DataView` view provides a low-level interface for reading and
3417    /// writing multiple number types in an `ArrayBuffer` irrespective of the
3418    /// platform's endianness.
3419    ///
3420    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3421    #[wasm_bindgen(constructor)]
3422    pub fn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView;
3423
3424    /// The `DataView` view provides a low-level interface for reading and
3425    /// writing multiple number types in an `ArrayBuffer` irrespective of the
3426    /// platform's endianness.
3427    ///
3428    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3429    #[wasm_bindgen(constructor)]
3430    pub fn new_with_shared_array_buffer(
3431        buffer: &SharedArrayBuffer,
3432        byteOffset: usize,
3433        byteLength: usize,
3434    ) -> DataView;
3435
3436    /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
3437    ///
3438    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer)
3439    #[wasm_bindgen(method, getter)]
3440    pub fn buffer(this: &DataView) -> ArrayBuffer;
3441
3442    /// The length (in bytes) of this view from the start of its ArrayBuffer.
3443    /// Fixed at construction time and thus read only.
3444    ///
3445    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength)
3446    #[wasm_bindgen(method, getter, js_name = byteLength)]
3447    pub fn byte_length(this: &DataView) -> usize;
3448
3449    /// The offset (in bytes) of this view from the start of its ArrayBuffer.
3450    /// Fixed at construction time and thus read only.
3451    ///
3452    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset)
3453    #[wasm_bindgen(method, getter, js_name = byteOffset)]
3454    pub fn byte_offset(this: &DataView) -> usize;
3455
3456    /// The `getInt8()` method gets a signed 8-bit integer (byte) at the
3457    /// specified byte offset from the start of the DataView.
3458    ///
3459    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8)
3460    #[wasm_bindgen(method, js_name = getInt8)]
3461    pub fn get_int8(this: &DataView, byte_offset: usize) -> i8;
3462
3463    /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified
3464    /// byte offset from the start of the DataView.
3465    ///
3466    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8)
3467    #[wasm_bindgen(method, js_name = getUint8)]
3468    pub fn get_uint8(this: &DataView, byte_offset: usize) -> u8;
3469
3470    /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3471    /// byte offset from the start of the DataView.
3472    ///
3473    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3474    #[wasm_bindgen(method, js_name = getInt16)]
3475    pub fn get_int16(this: &DataView, byte_offset: usize) -> i16;
3476
3477    /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3478    /// byte offset from the start of the DataView.
3479    ///
3480    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3481    #[wasm_bindgen(method, js_name = getInt16)]
3482    pub fn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16;
3483
3484    /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3485    /// byte offset from the start of the view.
3486    ///
3487    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3488    #[wasm_bindgen(method, js_name = getUint16)]
3489    pub fn get_uint16(this: &DataView, byte_offset: usize) -> u16;
3490
3491    /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3492    /// byte offset from the start of the view.
3493    ///
3494    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3495    #[wasm_bindgen(method, js_name = getUint16)]
3496    pub fn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16;
3497
3498    /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3499    /// byte offset from the start of the DataView.
3500    ///
3501    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3502    #[wasm_bindgen(method, js_name = getInt32)]
3503    pub fn get_int32(this: &DataView, byte_offset: usize) -> i32;
3504
3505    /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3506    /// byte offset from the start of the DataView.
3507    ///
3508    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3509    #[wasm_bindgen(method, js_name = getInt32)]
3510    pub fn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32;
3511
3512    /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3513    /// byte offset from the start of the view.
3514    ///
3515    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3516    #[wasm_bindgen(method, js_name = getUint32)]
3517    pub fn get_uint32(this: &DataView, byte_offset: usize) -> u32;
3518
3519    /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3520    /// byte offset from the start of the view.
3521    ///
3522    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3523    #[wasm_bindgen(method, js_name = getUint32)]
3524    pub fn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32;
3525
3526    /// The `getFloat32()` method gets a signed 32-bit float (float) 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/getFloat32)
3530    #[wasm_bindgen(method, js_name = getFloat32)]
3531    pub fn get_float32(this: &DataView, byte_offset: usize) -> f32;
3532
3533    /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3534    /// 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/getFloat32)
3537    #[wasm_bindgen(method, js_name = getFloat32)]
3538    pub fn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32;
3539
3540    /// The `getFloat16()` method gets a signed 16-bit float at the specified
3541    /// byte offset from the start of the DataView as an `f32`.
3542    ///
3543    /// The unsuffixed `get_float16` name is reserved for a future native
3544    /// `f16` binding once Rust stabilizes the type.
3545    ///
3546    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16)
3547    #[wasm_bindgen(method, js_name = getFloat16)]
3548    pub fn get_float16_as_f32(this: &DataView, byte_offset: usize) -> f32;
3549
3550    /// The `getFloat16()` method gets a signed 16-bit float at the specified
3551    /// byte offset from the start of the DataView as an `f32`.
3552    ///
3553    /// The unsuffixed `get_float16_endian` name is reserved for a future
3554    /// native `f16` binding once Rust stabilizes the type.
3555    ///
3556    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16)
3557    #[wasm_bindgen(method, js_name = getFloat16)]
3558    pub fn get_float16_endian_as_f32(
3559        this: &DataView,
3560        byte_offset: usize,
3561        little_endian: bool,
3562    ) -> f32;
3563
3564    /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3565    /// byte offset from the start of the DataView.
3566    ///
3567    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3568    #[wasm_bindgen(method, js_name = getFloat64)]
3569    pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
3570
3571    /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3572    /// byte offset from the start of the DataView.
3573    ///
3574    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3575    #[wasm_bindgen(method, js_name = getFloat64)]
3576    pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
3577
3578    /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
3579    /// specified byte offset from the start of the DataView.
3580    ///
3581    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
3582    #[wasm_bindgen(method, js_name = setInt8)]
3583    pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
3584
3585    /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
3586    /// specified byte offset from the start of the DataView.
3587    ///
3588    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
3589    #[wasm_bindgen(method, js_name = setUint8)]
3590    pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
3591
3592    /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3593    /// specified byte offset from the start of the DataView.
3594    ///
3595    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3596    #[wasm_bindgen(method, js_name = setInt16)]
3597    pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
3598
3599    /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3600    /// specified byte offset from the start of the DataView.
3601    ///
3602    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3603    #[wasm_bindgen(method, js_name = setInt16)]
3604    pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
3605
3606    /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3607    /// specified byte offset from the start of the DataView.
3608    ///
3609    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3610    #[wasm_bindgen(method, js_name = setUint16)]
3611    pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
3612
3613    /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3614    /// specified byte offset from the start of the DataView.
3615    ///
3616    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3617    #[wasm_bindgen(method, js_name = setUint16)]
3618    pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
3619
3620    /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3621    /// specified byte offset from the start of the DataView.
3622    ///
3623    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3624    #[wasm_bindgen(method, js_name = setInt32)]
3625    pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
3626
3627    /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3628    /// specified byte offset from the start of the DataView.
3629    ///
3630    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3631    #[wasm_bindgen(method, js_name = setInt32)]
3632    pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
3633
3634    /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3635    /// specified byte offset from the start of the DataView.
3636    ///
3637    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3638    #[wasm_bindgen(method, js_name = setUint32)]
3639    pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
3640
3641    /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3642    /// specified byte offset from the start of the DataView.
3643    ///
3644    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3645    #[wasm_bindgen(method, js_name = setUint32)]
3646    pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
3647
3648    /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3649    /// specified byte offset from the start of the DataView.
3650    ///
3651    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3652    #[wasm_bindgen(method, js_name = setFloat32)]
3653    pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
3654
3655    /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3656    /// specified byte offset from the start of the DataView.
3657    ///
3658    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3659    #[wasm_bindgen(method, js_name = setFloat32)]
3660    pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
3661
3662    /// The `setFloat16()` method stores a signed 16-bit float value from an
3663    /// `f32` at the specified byte offset from the start of the DataView.
3664    ///
3665    /// The unsuffixed `set_float16` name is reserved for a future native
3666    /// `f16` binding once Rust stabilizes the type.
3667    ///
3668    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16)
3669    #[wasm_bindgen(method, js_name = setFloat16)]
3670    pub fn set_float16_from_f32(this: &DataView, byte_offset: usize, value: f32);
3671
3672    /// The `setFloat16()` method stores a signed 16-bit float value from an
3673    /// `f32` at the specified byte offset from the start of the DataView.
3674    ///
3675    /// The unsuffixed `set_float16_endian` name is reserved for a future
3676    /// native `f16` binding once Rust stabilizes the type.
3677    ///
3678    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16)
3679    #[wasm_bindgen(method, js_name = setFloat16)]
3680    pub fn set_float16_endian_from_f32(
3681        this: &DataView,
3682        byte_offset: usize,
3683        value: f32,
3684        little_endian: bool,
3685    );
3686
3687    /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3688    /// specified byte offset from the start of the DataView.
3689    ///
3690    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3691    #[wasm_bindgen(method, js_name = setFloat64)]
3692    pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
3693
3694    /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3695    /// specified byte offset from the start of the DataView.
3696    ///
3697    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3698    #[wasm_bindgen(method, js_name = setFloat64)]
3699    pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
3700}
3701
3702// DisposableStack
3703#[wasm_bindgen]
3704extern "C" {
3705    /// A `DisposableStack` aggregates disposable resources, disposing them
3706    /// in reverse order of registration when `dispose()` is called.
3707    ///
3708    /// Callbacks registered with `adopt()` and `defer()` run later, at
3709    /// disposal time, so they are taken as [`ScopedClosure`]s which must
3710    /// outlive the stack's disposal. A stack disposed within the scope its
3711    /// closures live in needs nothing more. One that outlives that scope,
3712    /// through `move()` or by being stored, needs `'static` [`Closure`]s
3713    /// handed to JS with [`Closure::forget`]; a disposer runs once, so
3714    /// [`Closure::once`] frees its captures as soon as it has run.
3715    ///
3716    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack)
3717    #[wasm_bindgen(extends = Object, typescript_type = "DisposableStack")]
3718    #[derive(Clone, Debug, PartialEq, Eq)]
3719    pub type DisposableStack;
3720
3721    /// Creates a new, empty `DisposableStack`.
3722    ///
3723    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/DisposableStack)
3724    #[wasm_bindgen(constructor)]
3725    pub fn new() -> DisposableStack;
3726
3727    /// The `disposed` accessor property returns whether this stack has
3728    /// already been disposed.
3729    ///
3730    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/disposed)
3731    #[wasm_bindgen(method, getter)]
3732    pub fn disposed(this: &DisposableStack) -> bool;
3733
3734    /// The `dispose()` method disposes every resource in the stack in
3735    /// reverse order of registration. Errors thrown by disposers are
3736    /// collected into a [`SuppressedError`] chain and rethrown.
3737    ///
3738    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/dispose)
3739    #[wasm_bindgen(method, catch)]
3740    pub fn dispose(this: &DisposableStack) -> Result<(), JsValue>;
3741
3742    /// The `use()` method registers a value implementing `Symbol.dispose`
3743    /// for disposal and returns it. Throws a `TypeError` if the value is
3744    /// not `null`, `undefined` or disposable.
3745    ///
3746    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/use)
3747    #[wasm_bindgen(method, catch, js_name = use)]
3748    pub fn use_<T>(this: &DisposableStack, value: &T) -> Result<T, JsValue>;
3749
3750    /// The `adopt()` method registers a non-disposable value together with
3751    /// a callback to dispose it, and returns the value.
3752    ///
3753    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/adopt)
3754    #[wasm_bindgen(method, catch)]
3755    pub fn adopt<'a, T>(
3756        this: &DisposableStack,
3757        value: &T,
3758        on_dispose: &ScopedClosure<'a, dyn FnMut(T)>,
3759    ) -> Result<T, JsValue>;
3760
3761    /// The `defer()` method registers a callback to run when the stack is
3762    /// disposed.
3763    ///
3764    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/defer)
3765    #[wasm_bindgen(method, catch)]
3766    pub fn defer(
3767        this: &DisposableStack,
3768        on_dispose: &ScopedClosure<dyn FnMut()>,
3769    ) -> Result<(), JsValue>;
3770
3771    /// The `move()` method transfers every resource into a new
3772    /// `DisposableStack`, marking this one as disposed.
3773    ///
3774    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DisposableStack/move)
3775    #[wasm_bindgen(method, catch, js_name = move)]
3776    pub fn move_(this: &DisposableStack) -> Result<DisposableStack, JsValue>;
3777}
3778
3779impl Default for DisposableStack {
3780    fn default() -> Self {
3781        Self::new()
3782    }
3783}
3784
3785// AsyncDisposableStack
3786#[wasm_bindgen]
3787extern "C" {
3788    /// An `AsyncDisposableStack` aggregates async-disposable resources,
3789    /// disposing them in reverse order of registration when
3790    /// `disposeAsync()` is called.
3791    ///
3792    /// Callbacks registered with `adopt()` and `defer()` run later, at
3793    /// disposal time, so they are taken as [`ScopedClosure`]s which must
3794    /// outlive the stack's disposal. A stack disposed within the scope its
3795    /// closures live in needs nothing more. One that outlives that scope,
3796    /// through `move()` or by being stored, needs `'static` [`Closure`]s
3797    /// handed to JS with [`Closure::forget`]; a disposer runs once, so
3798    /// [`Closure::once`] frees its captures as soon as it has run.
3799    ///
3800    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack)
3801    #[wasm_bindgen(extends = Object, typescript_type = "AsyncDisposableStack")]
3802    #[derive(Clone, Debug, PartialEq, Eq)]
3803    pub type AsyncDisposableStack;
3804
3805    /// Creates a new, empty `AsyncDisposableStack`.
3806    ///
3807    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/AsyncDisposableStack)
3808    #[wasm_bindgen(constructor)]
3809    pub fn new() -> AsyncDisposableStack;
3810
3811    /// The `disposed` accessor property returns whether this stack has
3812    /// already been disposed.
3813    ///
3814    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/disposed)
3815    #[wasm_bindgen(method, getter)]
3816    pub fn disposed(this: &AsyncDisposableStack) -> bool;
3817
3818    /// The `disposeAsync()` method disposes every resource in the stack in
3819    /// reverse order of registration, awaiting each, and returns a promise
3820    /// that settles once all have completed.
3821    ///
3822    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/disposeAsync)
3823    #[wasm_bindgen(method, js_name = disposeAsync)]
3824    pub fn dispose_async(this: &AsyncDisposableStack) -> Promise<Undefined>;
3825
3826    /// The `use()` method registers a value implementing `Symbol.asyncDispose`
3827    /// or `Symbol.dispose` for disposal and returns it.
3828    ///
3829    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/use)
3830    #[wasm_bindgen(method, catch, js_name = use)]
3831    pub fn use_<T>(this: &AsyncDisposableStack, value: &T) -> Result<T, JsValue>;
3832
3833    /// The `adopt()` method registers a non-disposable value together with
3834    /// an async callback to dispose it, and returns the value.
3835    ///
3836    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/adopt)
3837    #[wasm_bindgen(method, catch)]
3838    pub fn adopt<'a, T, R: Promising>(
3839        this: &AsyncDisposableStack,
3840        value: &T,
3841        on_dispose_async: &ScopedClosure<'a, dyn FnMut(T) -> R>,
3842    ) -> Result<T, JsValue>;
3843
3844    /// The `defer()` method registers an async callback to run when the
3845    /// stack is disposed.
3846    ///
3847    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/defer)
3848    #[wasm_bindgen(method, catch)]
3849    pub fn defer<'a, R: Promising>(
3850        this: &AsyncDisposableStack,
3851        on_dispose_async: &ScopedClosure<'a, dyn FnMut() -> R>,
3852    ) -> Result<(), JsValue>;
3853
3854    /// The `move()` method transfers every resource into a new
3855    /// `AsyncDisposableStack`, marking this one as disposed.
3856    ///
3857    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncDisposableStack/move)
3858    #[wasm_bindgen(method, catch, js_name = move)]
3859    pub fn move_(this: &AsyncDisposableStack) -> Result<AsyncDisposableStack, JsValue>;
3860}
3861
3862impl Default for AsyncDisposableStack {
3863    fn default() -> Self {
3864        Self::new()
3865    }
3866}
3867
3868// Error
3869#[wasm_bindgen]
3870extern "C" {
3871    #[wasm_bindgen(extends = Object, typescript_type = "Error", no_from_js_value)]
3872    #[derive(Clone, Debug, PartialEq, Eq)]
3873    pub type Error;
3874
3875    /// The Error constructor creates an error object.
3876    /// Instances of Error objects are thrown when runtime errors occur.
3877    /// The Error object can also be used as a base object for user-defined exceptions.
3878    /// See below for standard built-in error types.
3879    ///
3880    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
3881    #[wasm_bindgen(constructor)]
3882    pub fn new(message: &str) -> Error;
3883
3884    /// Creates a new `Error` with the given message and an untyped options
3885    /// object whose `cause` property indicates the original cause of the
3886    /// error.
3887    ///
3888    /// New code should prefer [`Error::new_with_error_options`], which takes
3889    /// a typed [`ErrorOptions`] dictionary.
3890    ///
3891    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
3892    #[wasm_bindgen(constructor)]
3893    pub fn new_with_options(message: &str, options: &Object) -> Error;
3894
3895    /// Creates a new `Error` with the given message and a typed
3896    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
3897    /// original cause of the error.
3898    ///
3899    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
3900    #[wasm_bindgen(constructor)]
3901    pub fn new_with_error_options(message: &str, options: &ErrorOptions) -> Error;
3902
3903    /// The cause property is the underlying cause of the error.
3904    /// Usually this is used to add context to re-thrown errors.
3905    ///
3906    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors)
3907    #[wasm_bindgen(method, getter)]
3908    pub fn cause(this: &Error) -> JsValue;
3909    #[wasm_bindgen(method, setter)]
3910    pub fn set_cause(this: &Error, cause: &JsValue);
3911
3912    /// The message property is a human-readable description of the error.
3913    ///
3914    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
3915    #[cfg(not(js_sys_unstable_apis))]
3916    #[wasm_bindgen(method, getter)]
3917    pub fn message(this: &Error) -> JsString;
3918
3919    /// The message property is a human-readable description of the error.
3920    ///
3921    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
3922    #[cfg(js_sys_unstable_apis)]
3923    #[wasm_bindgen(method, getter)]
3924    pub fn message(this: &Error) -> String;
3925    #[wasm_bindgen(method, setter)]
3926    pub fn set_message(this: &Error, message: &str);
3927
3928    /// The name property represents a name for the type of error. The initial value is "Error".
3929    ///
3930    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
3931    #[cfg(not(js_sys_unstable_apis))]
3932    #[wasm_bindgen(method, getter)]
3933    pub fn name(this: &Error) -> JsString;
3934
3935    /// The name property represents a name for the type of error. The initial value is "Error".
3936    ///
3937    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
3938    #[cfg(js_sys_unstable_apis)]
3939    #[wasm_bindgen(method, getter)]
3940    pub fn name(this: &Error) -> String;
3941    #[wasm_bindgen(method, setter)]
3942    pub fn set_name(this: &Error, name: &str);
3943
3944    /// The `toString()` method returns a string representing the specified Error object
3945    ///
3946    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
3947    #[cfg(not(js_sys_unstable_apis))]
3948    #[wasm_bindgen(method, js_name = toString)]
3949    pub fn to_string(this: &Error) -> JsString;
3950
3951    /// The `toString()` method returns a string representing the object.
3952    #[cfg(js_sys_unstable_apis)]
3953    #[wasm_bindgen(method, js_name = toString)]
3954    pub fn to_string(this: &Error) -> String;
3955
3956    /// The `Error.stackTraceLimit` property controls the number of stack
3957    /// frames collected by a stack trace.
3958    ///
3959    /// This is a non-standard V8/Node.js API.
3960    ///
3961    /// [V8 documentation](https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions)
3962    #[wasm_bindgen(static_method_of = Error, getter, js_name = stackTraceLimit)]
3963    pub fn stack_trace_limit() -> JsValue;
3964
3965    /// Set `Error.stackTraceLimit` to control the number of stack frames
3966    /// collected by a stack trace.
3967    ///
3968    /// This is a non-standard V8/Node.js API.
3969    ///
3970    /// [V8 documentation](https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions)
3971    #[wasm_bindgen(static_method_of = Error, setter, js_name = stackTraceLimit)]
3972    pub fn set_stack_trace_limit(value: &JsValue);
3973
3974    /// The `Error.isError()` static method determines whether the passed
3975    /// value is an `Error` instance, including across realms, by checking
3976    /// for the internal `[[ErrorData]]` slot rather than the prototype chain.
3977    ///
3978    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/isError)
3979    #[wasm_bindgen(static_method_of = Error, js_name = isError)]
3980    pub fn is_error(value: &JsValue) -> bool;
3981}
3982
3983#[cfg(js_sys_unstable_apis)]
3984#[wasm_bindgen]
3985extern "C" {
3986    #[wasm_bindgen(method, getter = message, catch)]
3987    fn message_value(this: &Error) -> Result<JsValue, JsValue>;
3988
3989    #[wasm_bindgen(method, getter = name, catch)]
3990    fn name_value(this: &Error) -> Result<JsValue, JsValue>;
3991}
3992
3993/// Whether `value` has the string `message` and `name` that the `Error`
3994/// getters read.
3995#[cfg(js_sys_unstable_apis)]
3996fn is_error_like(value: &JsValue) -> bool {
3997    let error: &Error = value.unchecked_ref();
3998    error
3999        .message_value()
4000        .is_ok_and(|message| message.is_string())
4001        && error.name_value().is_ok_and(|name| name.is_string())
4002}
4003
4004#[cfg(js_sys_unstable_apis)]
4005fn non_error_message(value: &JsValue) -> String {
4006    value.as_string().unwrap_or_else(|| {
4007        let debug = alloc::format!("{value:?}");
4008        match debug
4009            .strip_prefix("JsValue(")
4010            .and_then(|s| s.strip_suffix(')'))
4011        {
4012            Some(inner) => inner.into(),
4013            None => debug,
4014        }
4015    })
4016}
4017
4018// A caught exception or a promise rejection can be any JS value and reaches an
4019// error type through `From<JsValue>`, so under `js_sys_unstable_apis` a value
4020// that is not error-like is wrapped in a new error, with the value as its
4021// `cause`.
4022macro_rules! error_from_js_value {
4023    ($ty:ident) => {
4024        error_from_js_value!($ty, |message, options, _value| $ty::new_with_options(
4025            message, options
4026        ));
4027    };
4028    ($ty:ty, |$message:ident, $options:ident, $value:ident| $wrap:expr) => {
4029        impl From<JsValue> for $ty {
4030            #[inline]
4031            fn from(value: JsValue) -> Self {
4032                #[cfg(js_sys_unstable_apis)]
4033                if !is_error_like(&value) {
4034                    let $message = &non_error_message(&value);
4035                    let $options = &ErrorOptions::new(&value);
4036                    let $value = &value;
4037                    return $wrap;
4038                }
4039                value.unchecked_into()
4040            }
4041        }
4042    };
4043}
4044
4045error_from_js_value!(Error, |message, options, _value| {
4046    Error::new_with_error_options(message, options)
4047});
4048error_from_js_value!(AggregateError, |message, options, _value| {
4049    AggregateError::new_with_options(&[], message, options)
4050});
4051error_from_js_value!(SuppressedError, |message, options, value| {
4052    SuppressedError::new_with_message_and_error_options(
4053        value,
4054        &JsValue::UNDEFINED,
4055        message,
4056        options,
4057    )
4058});
4059error_from_js_value!(EvalError);
4060error_from_js_value!(RangeError);
4061error_from_js_value!(ReferenceError);
4062error_from_js_value!(SyntaxError);
4063error_from_js_value!(TypeError);
4064error_from_js_value!(UriError);
4065error_from_js_value!(WebAssembly::CompileError, |message, options, _value| {
4066    WebAssembly::CompileError::new_with_options(message, options)
4067});
4068error_from_js_value!(WebAssembly::LinkError, |message, options, _value| {
4069    WebAssembly::LinkError::new_with_options(message, options)
4070});
4071error_from_js_value!(WebAssembly::RuntimeError, |message, options, _value| {
4072    WebAssembly::RuntimeError::new_with_options(message, options)
4073});
4074
4075partialord_ord!(JsString);
4076
4077// EvalError
4078#[wasm_bindgen]
4079extern "C" {
4080    #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError", no_from_js_value)]
4081    #[derive(Clone, Debug, PartialEq, Eq)]
4082    pub type EvalError;
4083
4084    /// The `EvalError` object indicates an error regarding the global eval() function. This
4085    /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
4086    /// compatibility.
4087    ///
4088    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
4089    #[wasm_bindgen(constructor)]
4090    pub fn new(message: &str) -> EvalError;
4091
4092    /// Creates a new `EvalError` with the given message and a typed
4093    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
4094    /// original cause of the error.
4095    ///
4096    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError/EvalError)
4097    #[wasm_bindgen(constructor)]
4098    pub fn new_with_options(message: &str, options: &ErrorOptions) -> EvalError;
4099}
4100
4101#[wasm_bindgen]
4102extern "C" {
4103    #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, no_upcast, typescript_type = "Function")]
4104    #[derive(Clone, Debug, PartialEq, Eq)]
4105    /// `Function` represents any generic Function in JS, by treating all arguments as `JsValue`.
4106    ///
4107    /// It takes a generic parameter of phantom type `fn (Arg1, ..., Argn) -> Ret` which
4108    /// is used to type the JS function. For example, `Function<fn () -> Number>` represents
4109    /// a function taking no arguments that returns a number.
4110    ///
4111    /// The 8 generic argument parameters (`Arg1` through `Arg8`) are the argument
4112    /// types. Arguments not provided enable strict arity checking at compile time.
4113    ///
4114    /// A void function is represented by `fn (Arg) -> Undefined`, and **not** the `()` unit
4115    /// type. This is because generics must be based on JS values in the JS generic type system.
4116    ///
4117    /// _The default without any parameters is as a void function - no arguments, `Undefined` return._
4118    ///
4119    /// _The default generic for `Function` is `fn (JsValue, JsValue, ...) -> JsValue`,
4120    /// representing any function, since all functions safely upcast into this function._
4121    ///
4122    /// ### Arity Enforcement
4123    ///
4124    /// It is not possible to use `call4` or `bind4` on a function that does not have
4125    /// at least 4 arguments — the compiler will reject this because only arguments that
4126    /// are not `None` support the trait bound for `ErasableGeneric`.
4127    ///
4128    /// ### Examples
4129    ///
4130    /// ```ignore
4131    /// // A function taking no args, returning Number
4132    /// let f: Function<Number> = get_some_fn();
4133    ///
4134    /// // A function taking (String, Number) and returning Boolean
4135    /// let f: Function<Boolean, String, Number> = get_some_fn();
4136    ///
4137    /// ### Upcasting
4138    ///
4139    /// To pass a typed `Function` where a different generic Function is expected, `upcast()` may be used
4140    /// to convert into any generic `Function` at zero cost with type-safety.
4141    ///
4142    /// MDN documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
4143    pub type Function<
4144        T: JsFunction = fn(
4145            JsValue,
4146            JsValue,
4147            JsValue,
4148            JsValue,
4149            JsValue,
4150            JsValue,
4151            JsValue,
4152            JsValue,
4153        ) -> JsValue,
4154    >;
4155}
4156
4157#[wasm_bindgen]
4158extern "C" {
4159    /// The `Function` constructor creates a new `Function` object. Calling the
4160    /// constructor directly can create functions dynamically, but suffers from
4161    /// security and similar (but far less significant) performance issues
4162    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
4163    /// allows executing code in the global scope, prompting better programming
4164    /// habits and allowing for more efficient code minification.
4165    ///
4166    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
4167    #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
4168    #[wasm_bindgen(constructor)]
4169    pub fn new_with_args(args: &str, body: &str) -> Function;
4170
4171    /// The `Function` constructor creates a new `Function` object. Calling the
4172    /// constructor directly can create functions dynamically, but suffers from
4173    /// security and similar (but far less significant) performance issues
4174    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
4175    /// allows executing code in the global scope, prompting better programming
4176    /// habits and allowing for more efficient code minification.
4177    ///
4178    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
4179    #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
4180    #[wasm_bindgen(constructor)]
4181    pub fn new_with_args<T: JsFunction = fn() -> JsValue>(args: &str, body: &str) -> Function<T>;
4182
4183    // Next major: deprecate
4184    /// The `Function` constructor creates a new `Function` object. Calling the
4185    /// constructor directly can create functions dynamically, but suffers from
4186    /// security and similar (but far less significant) performance issues
4187    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
4188    /// allows executing code in the global scope, prompting better programming
4189    /// habits and allowing for more efficient code minification.
4190    ///
4191    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
4192    #[cfg(feature = "unsafe-eval")]
4193    #[wasm_bindgen(constructor)]
4194    pub fn new_with_args_typed<T: JsFunction = fn() -> JsValue>(
4195        args: &str,
4196        body: &str,
4197    ) -> Function<T>;
4198
4199    /// The `Function` constructor creates a new `Function` object. Calling the
4200    /// constructor directly can create functions dynamically, but suffers from
4201    /// security and similar (but far less significant) performance issues
4202    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
4203    /// allows executing code in the global scope, prompting better programming
4204    /// habits and allowing for more efficient code minification.
4205    ///
4206    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
4207    #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
4208    #[wasm_bindgen(constructor)]
4209    pub fn new_no_args(body: &str) -> Function;
4210
4211    /// The `Function` constructor creates a new `Function` object. Calling the
4212    /// constructor directly can create functions dynamically, but suffers from
4213    /// security and similar (but far less significant) performance issues
4214    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
4215    /// allows executing code in the global scope, prompting better programming
4216    /// habits and allowing for more efficient code minification.
4217    ///
4218    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
4219    #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
4220    #[wasm_bindgen(constructor)]
4221    pub fn new_no_args<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
4222
4223    // Next major: deprecate
4224    /// The `Function` constructor creates a new `Function` object.
4225    ///
4226    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
4227    #[cfg(feature = "unsafe-eval")]
4228    #[wasm_bindgen(constructor)]
4229    pub fn new_no_args_typed<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
4230
4231    /// The `apply()` method calls a function with a given this value, and arguments provided as an array
4232    /// (or an array-like object).
4233    ///
4234    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
4235    #[wasm_bindgen(method, catch)]
4236    pub fn apply<T: JsFunction = fn() -> JsValue>(
4237        this: &Function<T>,
4238        context: &JsValue,
4239        args: &Array,
4240    ) -> Result<<T as JsFunction>::Ret, JsValue>;
4241
4242    // Next major: Deprecate, and separately provide provide impl
4243    /// The `call()` method calls a function with a given this value and
4244    /// arguments provided individually.
4245    ///
4246    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4247    ///
4248    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4249    #[wasm_bindgen(method, catch, js_name = call)]
4250    pub fn call0<Ret: JsGeneric, F: JsFunction<Ret = Ret> = fn() -> JsValue>(
4251        this: &Function<F>,
4252        context: &JsValue,
4253    ) -> Result<Ret, JsValue>;
4254
4255    // Next major: Deprecate, and separately provide provide impl
4256    /// The `call()` method calls a function with a given this value and
4257    /// arguments provided individually.
4258    ///
4259    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4260    ///
4261    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4262    #[wasm_bindgen(method, catch, js_name = call)]
4263    pub fn call1<
4264        Ret: JsGeneric,
4265        Arg1: JsGeneric,
4266        F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> = fn(JsValue) -> JsValue,
4267    >(
4268        this: &Function<F>,
4269        context: &JsValue,
4270        arg1: &Arg1,
4271    ) -> Result<Ret, JsValue>;
4272
4273    // Next major: Deprecate, and separately provide provide impl
4274    /// The `call()` method calls a function with a given this value and
4275    /// arguments provided individually.
4276    ///
4277    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4278    ///
4279    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4280    #[wasm_bindgen(method, catch, js_name = call)]
4281    pub fn call2<
4282        Ret: JsGeneric,
4283        Arg1: JsGeneric,
4284        Arg2: JsGeneric,
4285        F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> + JsFunction2<Arg2 = Arg2> = fn(
4286            JsValue,
4287            JsValue,
4288        ) -> JsValue,
4289    >(
4290        this: &Function<F>,
4291        context: &JsValue,
4292        arg1: &Arg1,
4293        arg2: &Arg2,
4294    ) -> Result<Ret, JsValue>;
4295
4296    // Next major: Deprecate, and separately provide provide impl
4297    /// The `call()` method calls a function with a given this value and
4298    /// arguments provided individually.
4299    ///
4300    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4301    ///
4302    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4303    #[wasm_bindgen(method, catch, js_name = call)]
4304    pub fn call3<
4305        Ret: JsGeneric,
4306        Arg1: JsGeneric,
4307        Arg2: JsGeneric,
4308        Arg3: JsGeneric,
4309        F: JsFunction<Ret = Ret> + JsFunction3<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
4310            JsValue,
4311            JsValue,
4312            JsValue,
4313        ) -> JsValue,
4314    >(
4315        this: &Function<F>,
4316        context: &JsValue,
4317        arg1: &Arg1,
4318        arg2: &Arg2,
4319        arg3: &Arg3,
4320    ) -> Result<Ret, JsValue>;
4321
4322    // Next major: Deprecate, and separately provide provide impl
4323    /// The `call()` method calls a function with a given this value and
4324    /// arguments provided individually.
4325    ///
4326    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4327    ///
4328    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4329    #[wasm_bindgen(method, catch, js_name = call)]
4330    pub fn call4<
4331        Ret: JsGeneric,
4332        Arg1: JsGeneric,
4333        Arg2: JsGeneric,
4334        Arg3: JsGeneric,
4335        Arg4: JsGeneric,
4336        F: JsFunction<Ret = Ret> + JsFunction4<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
4337            JsValue,
4338            JsValue,
4339            JsValue,
4340            JsValue,
4341        ) -> JsValue,
4342    >(
4343        this: &Function<F>,
4344        context: &JsValue,
4345        arg1: &Arg1,
4346        arg2: &Arg2,
4347        arg3: &Arg3,
4348        arg4: &Arg4,
4349    ) -> Result<Ret, JsValue>;
4350
4351    // Next major: Deprecate, and separately provide provide impl
4352    /// The `call()` method calls a function with a given this value and
4353    /// arguments provided individually.
4354    ///
4355    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4356    ///
4357    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4358    #[wasm_bindgen(method, catch, js_name = call)]
4359    pub fn call5<
4360        Ret: JsGeneric,
4361        Arg1: JsGeneric,
4362        Arg2: JsGeneric,
4363        Arg3: JsGeneric,
4364        Arg4: JsGeneric,
4365        Arg5: JsGeneric,
4366        F: JsFunction<Ret = Ret>
4367            + JsFunction5<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4368            JsValue,
4369            JsValue,
4370            JsValue,
4371            JsValue,
4372            JsValue,
4373        ) -> JsValue,
4374    >(
4375        this: &Function<F>,
4376        context: &JsValue,
4377        arg1: &Arg1,
4378        arg2: &Arg2,
4379        arg3: &Arg3,
4380        arg4: &Arg4,
4381        arg5: &Arg5,
4382    ) -> Result<Ret, JsValue>;
4383
4384    // Next major: Deprecate, and separately provide provide impl
4385    /// The `call()` method calls a function with a given this value and
4386    /// arguments provided individually.
4387    ///
4388    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4389    ///
4390    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4391    #[wasm_bindgen(method, catch, js_name = call)]
4392    pub fn call6<
4393        Ret: JsGeneric,
4394        Arg1: JsGeneric,
4395        Arg2: JsGeneric,
4396        Arg3: JsGeneric,
4397        Arg4: JsGeneric,
4398        Arg5: JsGeneric,
4399        Arg6: JsGeneric,
4400        F: JsFunction<Ret = Ret>
4401            + JsFunction6<
4402                Arg1 = Arg1,
4403                Arg2 = Arg2,
4404                Arg3 = Arg3,
4405                Arg4 = Arg4,
4406                Arg5 = Arg5,
4407                Arg6 = Arg6,
4408            > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4409    >(
4410        this: &Function<F>,
4411        context: &JsValue,
4412        arg1: &Arg1,
4413        arg2: &Arg2,
4414        arg3: &Arg3,
4415        arg4: &Arg4,
4416        arg5: &Arg5,
4417        arg6: &Arg6,
4418    ) -> Result<Ret, JsValue>;
4419
4420    // Next major: Deprecate, and separately provide provide impl
4421    /// The `call()` method calls a function with a given this value and
4422    /// arguments provided individually.
4423    ///
4424    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4425    ///
4426    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4427    #[wasm_bindgen(method, catch, js_name = call)]
4428    pub fn call7<
4429        Ret: JsGeneric,
4430        Arg1: JsGeneric,
4431        Arg2: JsGeneric,
4432        Arg3: JsGeneric,
4433        Arg4: JsGeneric,
4434        Arg5: JsGeneric,
4435        Arg6: JsGeneric,
4436        Arg7: JsGeneric,
4437        F: JsFunction<Ret = Ret>
4438            + JsFunction7<
4439                Arg1 = Arg1,
4440                Arg2 = Arg2,
4441                Arg3 = Arg3,
4442                Arg4 = Arg4,
4443                Arg5 = Arg5,
4444                Arg6 = Arg6,
4445                Arg7 = Arg7,
4446            > = fn(
4447            JsValue,
4448            JsValue,
4449            JsValue,
4450            JsValue,
4451            JsValue,
4452            JsValue,
4453            JsValue,
4454        ) -> JsValue,
4455    >(
4456        this: &Function<F>,
4457        context: &JsValue,
4458        arg1: &Arg1,
4459        arg2: &Arg2,
4460        arg3: &Arg3,
4461        arg4: &Arg4,
4462        arg5: &Arg5,
4463        arg6: &Arg6,
4464        arg7: &Arg7,
4465    ) -> Result<Ret, JsValue>;
4466
4467    // Next major: Deprecate, and separately provide provide impl
4468    /// The `call()` method calls a function with a given this value and
4469    /// arguments provided individually.
4470    ///
4471    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4472    ///
4473    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4474    #[wasm_bindgen(method, catch, js_name = call)]
4475    pub fn call8<
4476        Ret: JsGeneric,
4477        Arg1: JsGeneric,
4478        Arg2: JsGeneric,
4479        Arg3: JsGeneric,
4480        Arg4: JsGeneric,
4481        Arg5: JsGeneric,
4482        Arg6: JsGeneric,
4483        Arg7: JsGeneric,
4484        Arg8: JsGeneric,
4485        F: JsFunction8<
4486            Ret = Ret,
4487            Arg1 = Arg1,
4488            Arg2 = Arg2,
4489            Arg3 = Arg3,
4490            Arg4 = Arg4,
4491            Arg5 = Arg5,
4492            Arg6 = Arg6,
4493            Arg7 = Arg7,
4494            Arg8 = Arg8,
4495        > = fn(
4496            JsValue,
4497            JsValue,
4498            JsValue,
4499            JsValue,
4500            JsValue,
4501            JsValue,
4502            JsValue,
4503            JsValue,
4504        ) -> JsValue,
4505    >(
4506        this: &Function<F>,
4507        context: &JsValue,
4508        arg1: &Arg1,
4509        arg2: &Arg2,
4510        arg3: &Arg3,
4511        arg4: &Arg4,
4512        arg5: &Arg5,
4513        arg6: &Arg6,
4514        arg7: &Arg7,
4515        arg8: &Arg8,
4516    ) -> Result<Ret, JsValue>;
4517
4518    /// The `call()` method calls a function with a given this value and
4519    /// arguments provided individually.
4520    ///
4521    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4522    ///
4523    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4524    #[deprecated]
4525    #[allow(deprecated)]
4526    #[wasm_bindgen(method, catch, js_name = call)]
4527    pub fn call9<
4528        Ret: JsGeneric,
4529        Arg1: JsGeneric,
4530        Arg2: JsGeneric,
4531        Arg3: JsGeneric,
4532        Arg4: JsGeneric,
4533        Arg5: JsGeneric,
4534        Arg6: JsGeneric,
4535        Arg7: JsGeneric,
4536        Arg8: JsGeneric,
4537        F: JsFunction8<
4538            Ret = Ret,
4539            Arg1 = Arg1,
4540            Arg2 = Arg2,
4541            Arg3 = Arg3,
4542            Arg4 = Arg4,
4543            Arg5 = Arg5,
4544            Arg6 = Arg6,
4545            Arg7 = Arg7,
4546            Arg8 = Arg8,
4547        > = fn(
4548            JsValue,
4549            JsValue,
4550            JsValue,
4551            JsValue,
4552            JsValue,
4553            JsValue,
4554            JsValue,
4555            JsValue,
4556        ) -> JsValue,
4557    >(
4558        this: &Function<F>,
4559        context: &JsValue,
4560        arg1: &Arg1,
4561        arg2: &Arg2,
4562        arg3: &Arg3,
4563        arg4: &Arg4,
4564        arg5: &Arg5,
4565        arg6: &Arg6,
4566        arg7: &Arg7,
4567        arg8: &Arg8,
4568        arg9: &JsValue,
4569    ) -> Result<Ret, JsValue>;
4570
4571    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4572    /// with a given sequence of arguments preceding any provided when the new function is called.
4573    ///
4574    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4575    #[cfg(not(js_sys_unstable_apis))]
4576    #[deprecated(note = "Use `Function::bind0` instead.")]
4577    #[allow(deprecated)]
4578    #[wasm_bindgen(method, js_name = bind)]
4579    pub fn bind<T: JsFunction = fn() -> JsValue>(
4580        this: &Function<T>,
4581        context: &JsValue,
4582    ) -> Function<T>;
4583
4584    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4585    /// with a given sequence of arguments preceding any provided when the new function is called.
4586    ///
4587    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4588    ///
4589    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4590    #[wasm_bindgen(method, js_name = bind)]
4591    pub fn bind0<T: JsFunction = fn() -> JsValue>(
4592        this: &Function<T>,
4593        context: &JsValue,
4594    ) -> Function<T>;
4595
4596    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4597    /// with a given sequence of arguments preceding any provided when the new function is called.
4598    ///
4599    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4600    ///
4601    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4602    #[wasm_bindgen(method, js_name = bind)]
4603    pub fn bind1<
4604        Ret: JsGeneric,
4605        Arg1: JsGeneric,
4606        F: JsFunction1<Ret = Ret, Arg1 = Arg1> = fn(JsValue) -> JsValue,
4607    >(
4608        this: &Function<F>,
4609        context: &JsValue,
4610        arg1: &Arg1,
4611    ) -> Function<<F as JsFunction1>::Bind1>;
4612
4613    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4614    /// with a given sequence of arguments preceding any provided when the new function is called.
4615    ///
4616    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4617    ///
4618    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4619    #[wasm_bindgen(method, js_name = bind)]
4620    pub fn bind2<
4621        Ret: JsGeneric,
4622        Arg1: JsGeneric,
4623        Arg2: JsGeneric,
4624        F: JsFunction2<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2> = fn(JsValue, JsValue) -> JsValue,
4625    >(
4626        this: &Function<F>,
4627        context: &JsValue,
4628        arg1: &Arg1,
4629        arg2: &Arg2,
4630    ) -> Function<<F as JsFunction2>::Bind2>;
4631
4632    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4633    /// with a given sequence of arguments preceding any provided when the new function is called.
4634    ///
4635    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4636    ///
4637    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4638    #[wasm_bindgen(method, js_name = bind)]
4639    pub fn bind3<
4640        Ret: JsGeneric,
4641        Arg1: JsGeneric,
4642        Arg2: JsGeneric,
4643        Arg3: JsGeneric,
4644        F: JsFunction3<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
4645            JsValue,
4646            JsValue,
4647            JsValue,
4648        ) -> JsValue,
4649    >(
4650        this: &Function<F>,
4651        context: &JsValue,
4652        arg1: &Arg1,
4653        arg2: &Arg2,
4654        arg3: &Arg3,
4655    ) -> Function<<F as JsFunction3>::Bind3>;
4656
4657    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4658    /// with a given sequence of arguments preceding any provided when the new function is called.
4659    ///
4660    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4661    ///
4662    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4663    #[wasm_bindgen(method, js_name = bind)]
4664    pub fn bind4<
4665        Ret: JsGeneric,
4666        Arg1: JsGeneric,
4667        Arg2: JsGeneric,
4668        Arg3: JsGeneric,
4669        Arg4: JsGeneric,
4670        F: JsFunction4<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
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    ) -> Function<<F as JsFunction4>::Bind4>;
4684
4685    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4686    /// with a given sequence of arguments preceding any provided when the new function is called.
4687    ///
4688    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4689    ///
4690    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4691    #[wasm_bindgen(method, js_name = bind)]
4692    pub fn bind5<
4693        Ret: JsGeneric,
4694        Arg1: JsGeneric,
4695        Arg2: JsGeneric,
4696        Arg3: JsGeneric,
4697        Arg4: JsGeneric,
4698        Arg5: JsGeneric,
4699        F: JsFunction5<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4700            JsValue,
4701            JsValue,
4702            JsValue,
4703            JsValue,
4704            JsValue,
4705        ) -> JsValue,
4706    >(
4707        this: &Function<F>,
4708        context: &JsValue,
4709        arg1: &Arg1,
4710        arg2: &Arg2,
4711        arg3: &Arg3,
4712        arg4: &Arg4,
4713        arg5: &Arg5,
4714    ) -> Function<<F as JsFunction5>::Bind5>;
4715
4716    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4717    /// with a given sequence of arguments preceding any provided when the new function is called.
4718    ///
4719    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4720    ///
4721    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4722    #[wasm_bindgen(method, js_name = bind)]
4723    pub fn bind6<
4724        Ret: JsGeneric,
4725        Arg1: JsGeneric,
4726        Arg2: JsGeneric,
4727        Arg3: JsGeneric,
4728        Arg4: JsGeneric,
4729        Arg5: JsGeneric,
4730        Arg6: JsGeneric,
4731        F: JsFunction6<
4732            Ret = Ret,
4733            Arg1 = Arg1,
4734            Arg2 = Arg2,
4735            Arg3 = Arg3,
4736            Arg4 = Arg4,
4737            Arg5 = Arg5,
4738            Arg6 = Arg6,
4739        > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4740    >(
4741        this: &Function<F>,
4742        context: &JsValue,
4743        arg1: &Arg1,
4744        arg2: &Arg2,
4745        arg3: &Arg3,
4746        arg4: &Arg4,
4747        arg5: &Arg5,
4748        arg6: &Arg6,
4749    ) -> Function<<F as JsFunction6>::Bind6>;
4750
4751    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4752    /// with a given sequence of arguments preceding any provided when the new function is called.
4753    ///
4754    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4755    ///
4756    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4757    #[wasm_bindgen(method, js_name = bind)]
4758    pub fn bind7<
4759        Ret: JsGeneric,
4760        Arg1: JsGeneric,
4761        Arg2: JsGeneric,
4762        Arg3: JsGeneric,
4763        Arg4: JsGeneric,
4764        Arg5: JsGeneric,
4765        Arg6: JsGeneric,
4766        Arg7: JsGeneric,
4767        F: JsFunction7<
4768            Ret = Ret,
4769            Arg1 = Arg1,
4770            Arg2 = Arg2,
4771            Arg3 = Arg3,
4772            Arg4 = Arg4,
4773            Arg5 = Arg5,
4774            Arg6 = Arg6,
4775            Arg7 = Arg7,
4776        > = fn(
4777            JsValue,
4778            JsValue,
4779            JsValue,
4780            JsValue,
4781            JsValue,
4782            JsValue,
4783            JsValue,
4784        ) -> JsValue,
4785    >(
4786        this: &Function<F>,
4787        context: &JsValue,
4788        arg1: &Arg1,
4789        arg2: &Arg2,
4790        arg3: &Arg3,
4791        arg4: &Arg4,
4792        arg5: &Arg5,
4793        arg6: &Arg6,
4794        arg7: &Arg7,
4795    ) -> Function<<F as JsFunction7>::Bind7>;
4796
4797    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4798    /// with a given sequence of arguments preceding any provided when the new function is called.
4799    ///
4800    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4801    ///
4802    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4803    #[wasm_bindgen(method, js_name = bind)]
4804    pub fn bind8<
4805        Ret: JsGeneric,
4806        Arg1: JsGeneric,
4807        Arg2: JsGeneric,
4808        Arg3: JsGeneric,
4809        Arg4: JsGeneric,
4810        Arg5: JsGeneric,
4811        Arg6: JsGeneric,
4812        Arg7: JsGeneric,
4813        Arg8: JsGeneric,
4814        F: JsFunction8<
4815            Ret = Ret,
4816            Arg1 = Arg1,
4817            Arg2 = Arg2,
4818            Arg3 = Arg3,
4819            Arg4 = Arg4,
4820            Arg5 = Arg5,
4821            Arg6 = Arg6,
4822            Arg7 = Arg7,
4823            Arg8 = Arg8,
4824        > = fn(
4825            JsValue,
4826            JsValue,
4827            JsValue,
4828            JsValue,
4829            JsValue,
4830            JsValue,
4831            JsValue,
4832            JsValue,
4833        ) -> JsValue,
4834    >(
4835        this: &Function<F>,
4836        context: &JsValue,
4837        arg1: &Arg1,
4838        arg2: &Arg2,
4839        arg3: &Arg3,
4840        arg4: &Arg4,
4841        arg5: &Arg5,
4842        arg6: &Arg6,
4843        arg7: &Arg7,
4844        arg8: &Arg8,
4845    ) -> Function<<F as JsFunction8>::Bind8>;
4846
4847    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4848    /// with a given sequence of arguments preceding any provided when the new function is called.
4849    ///
4850    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4851    ///
4852    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4853    #[deprecated]
4854    #[allow(deprecated)]
4855    #[wasm_bindgen(method, js_name = bind)]
4856    pub fn bind9<
4857        Ret: JsGeneric,
4858        Arg1: JsGeneric,
4859        Arg2: JsGeneric,
4860        Arg3: JsGeneric,
4861        Arg4: JsGeneric,
4862        Arg5: JsGeneric,
4863        Arg6: JsGeneric,
4864        Arg7: JsGeneric,
4865        Arg8: JsGeneric,
4866        F: JsFunction8<
4867            Ret = Ret,
4868            Arg1 = Arg1,
4869            Arg2 = Arg2,
4870            Arg3 = Arg3,
4871            Arg4 = Arg4,
4872            Arg5 = Arg5,
4873            Arg6 = Arg6,
4874            Arg7 = Arg7,
4875            Arg8 = Arg8,
4876        > = fn(
4877            JsValue,
4878            JsValue,
4879            JsValue,
4880            JsValue,
4881            JsValue,
4882            JsValue,
4883            JsValue,
4884            JsValue,
4885        ) -> JsValue,
4886    >(
4887        this: &Function<F>,
4888        context: &JsValue,
4889        arg1: &Arg1,
4890        arg2: &Arg2,
4891        arg3: &Arg3,
4892        arg4: &Arg4,
4893        arg5: &Arg5,
4894        arg6: &Arg6,
4895        arg7: &Arg7,
4896        arg8: &Arg8,
4897        arg9: &JsValue,
4898    ) -> Function<fn() -> Ret>;
4899
4900    /// The length property indicates the number of arguments expected by the function.
4901    ///
4902    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
4903    #[wasm_bindgen(method, getter)]
4904    pub fn length<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> u32;
4905
4906    /// A Function object's read-only name property indicates the function's
4907    /// name as specified when it was created or "anonymous" for functions
4908    /// created anonymously.
4909    ///
4910    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
4911    #[cfg(not(js_sys_unstable_apis))]
4912    #[wasm_bindgen(method, getter)]
4913    pub fn name<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4914
4915    /// A Function object's read-only name property.
4916    ///
4917    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
4918    #[cfg(js_sys_unstable_apis)]
4919    #[wasm_bindgen(method, getter)]
4920    pub fn name<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> String;
4921
4922    /// The `toString()` method returns a string representing the source code of the function.
4923    ///
4924    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
4925    #[cfg(not(js_sys_unstable_apis))]
4926    #[wasm_bindgen(method, js_name = toString)]
4927    pub fn to_string<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4928}
4929
4930// Basic UpcastFrom impls for Function<T>
4931impl<T: JsFunction> UpcastFrom<Function<T>> for JsValue {}
4932impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<JsValue> {}
4933impl<T: JsFunction, Target: UpcastFrom<Function<T>>> UpcastFrom<Function<T>> for Option<Target> {}
4934impl<T: JsFunction, Target: UpcastFrom<Function<T>>> UpcastFrom<Function<T>> for Nullable<Target> {}
4935impl<T: JsFunction> UpcastFrom<Function<T>> for JsNullable<JsValue> {}
4936impl<T: JsFunction> UpcastFrom<Function<T>> for Object {}
4937impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<Object> {}
4938impl<T: JsFunction> UpcastFrom<Function<T>> for JsNullable<Object> {}
4939
4940// Blanket trait for Function upcast
4941// Function<T> upcasts to Function<U> when the underlying fn type T upcasts to U.
4942// The fn signature UpcastFrom impls already encode correct variance (covariant return, contravariant args).
4943impl<T: JsFunction, U: JsFunction> UpcastFrom<Function<T>> for Function<U> where U: UpcastFrom<T> {}
4944
4945// len() method for Function<T> using JsFunction::ARITY
4946impl<T: JsFunction> Function<T> {
4947    /// Get the static arity of this function type.
4948    #[allow(clippy::len_without_is_empty)]
4949    pub fn len(&self) -> usize {
4950        T::ARITY
4951    }
4952
4953    /// Returns true if this is a zero-argument function.
4954    pub fn is_empty(&self) -> bool {
4955        T::ARITY == 0
4956    }
4957}
4958
4959/// The signature a `Function<T>` is typed with: a `fn(Args..) -> Ret` whose
4960/// slots name the JS types the function takes and returns.
4961///
4962/// A slot may be any Rust carrier of a JS type, a handle such as `JsString`
4963/// or a converted value such as `Nullable<JsString>` or `Option<Number>`, as
4964/// a `Promise<T>` or `Array<T>` type argument may. The `call*` and `bind*`
4965/// methods marshal through the erased `JsValue` representation and so bound
4966/// their slots to [`JsGeneric`] handles themselves.
4967pub trait JsFunction {
4968    type Ret;
4969    const ARITY: usize;
4970}
4971
4972pub trait JsFunction1: JsFunction {
4973    type Arg1;
4974    type Bind1: JsFunction;
4975}
4976pub trait JsFunction2: JsFunction1 {
4977    type Arg2;
4978    type Bind2: JsFunction;
4979}
4980pub trait JsFunction3: JsFunction2 {
4981    type Arg3;
4982    type Bind3: JsFunction;
4983}
4984pub trait JsFunction4: JsFunction3 {
4985    type Arg4;
4986    type Bind4: JsFunction;
4987}
4988pub trait JsFunction5: JsFunction4 {
4989    type Arg5;
4990    type Bind5: JsFunction;
4991}
4992pub trait JsFunction6: JsFunction5 {
4993    type Arg6;
4994    type Bind6: JsFunction;
4995}
4996pub trait JsFunction7: JsFunction6 {
4997    type Arg7;
4998    type Bind7: JsFunction;
4999}
5000pub trait JsFunction8: JsFunction7 {
5001    type Arg8;
5002    type Bind8: JsFunction;
5003}
5004
5005// Manual impl for fn() -> R
5006impl<Ret> JsFunction for fn() -> Ret {
5007    type Ret = Ret;
5008    const ARITY: usize = 0;
5009}
5010
5011macro_rules! impl_fn {
5012    () => {
5013        impl_fn!(@impl 1 [Arg1] [
5014            JsFunction1 Arg1 Bind1 {fn() -> Ret}
5015        ]);
5016        impl_fn!(@impl 2 [Arg1 Arg2] [
5017            JsFunction1 Arg1 Bind1 {fn(Arg2) -> Ret}
5018            JsFunction2 Arg2 Bind2 {fn() -> Ret}
5019        ]);
5020        impl_fn!(@impl 3 [Arg1 Arg2 Arg3] [
5021            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3) -> Ret}
5022            JsFunction2 Arg2 Bind2 {fn(Arg3) -> Ret}
5023            JsFunction3 Arg3 Bind3 {fn() -> Ret}
5024        ]);
5025        impl_fn!(@impl 4 [Arg1 Arg2 Arg3 Arg4] [
5026            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4) -> Ret}
5027            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4) -> Ret}
5028            JsFunction3 Arg3 Bind3 {fn(Arg4) -> Ret}
5029            JsFunction4 Arg4 Bind4 {fn() -> Ret}
5030        ]);
5031        impl_fn!(@impl 5 [Arg1 Arg2 Arg3 Arg4 Arg5] [
5032            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5) -> Ret}
5033            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5) -> Ret}
5034            JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5) -> Ret}
5035            JsFunction4 Arg4 Bind4 {fn(Arg5) -> Ret}
5036            JsFunction5 Arg5 Bind5 {fn() -> Ret}
5037        ]);
5038        impl_fn!(@impl 6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [
5039            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6) -> Ret}
5040            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6) -> Ret}
5041            JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6) -> Ret}
5042            JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6) -> Ret}
5043            JsFunction5 Arg5 Bind5 {fn(Arg6) -> Ret}
5044            JsFunction6 Arg6 Bind6 {fn() -> Ret}
5045        ]);
5046        impl_fn!(@impl 7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [
5047            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
5048            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
5049            JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7) -> Ret}
5050            JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7) -> Ret}
5051            JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7) -> Ret}
5052            JsFunction6 Arg6 Bind6 {fn(Arg7) -> Ret}
5053            JsFunction7 Arg7 Bind7 {fn() -> Ret}
5054        ]);
5055        impl_fn!(@impl 8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [
5056            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
5057            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
5058            JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
5059            JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7, Arg8) -> Ret}
5060            JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7, Arg8) -> Ret}
5061            JsFunction6 Arg6 Bind6 {fn(Arg7, Arg8) -> Ret}
5062            JsFunction7 Arg7 Bind7 {fn(Arg8) -> Ret}
5063            JsFunction8 Arg8 Bind8 {fn() -> Ret}
5064        ]);
5065    };
5066
5067    (@impl $arity:literal [$($A:ident)+] [$($trait:ident $arg:ident $bind:ident {$bind_ty:ty})+]) => {
5068        impl<Ret $(, $A)+> JsFunction for fn($($A),+) -> Ret {
5069            type Ret = Ret;
5070            const ARITY: usize = $arity;
5071        }
5072
5073        impl_fn!(@traits [$($A)+] [$($trait $arg $bind {$bind_ty})+]);
5074    };
5075
5076    (@traits [$($A:ident)+] []) => {};
5077
5078    (@traits [$($A:ident)+] [$trait:ident $arg:ident $bind:ident {$bind_ty:ty} $($rest:tt)*]) => {
5079        impl<Ret $(, $A)+> $trait for fn($($A),+) -> Ret {
5080            type $arg = $arg;
5081            type $bind = $bind_ty;
5082        }
5083
5084        impl_fn!(@traits [$($A)+] [$($rest)*]);
5085    };
5086}
5087
5088impl_fn!();
5089
5090/// Trait for argument tuples that can call or bind a `Function<T>`.
5091pub trait JsArgs<T: JsFunction> {
5092    type BindOutput;
5093    fn apply_call(self, func: &Function<T>, context: &JsValue) -> Result<T::Ret, JsValue>;
5094    fn apply_bind(self, func: &Function<T>, context: &JsValue) -> Self::BindOutput;
5095}
5096
5097// Manual impl for 0-arg
5098impl<Ret: JsGeneric, F: JsFunction<Ret = Ret>> JsArgs<F> for () {
5099    type BindOutput = Function<F>;
5100
5101    #[inline]
5102    fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
5103        func.call0(context)
5104    }
5105
5106    #[inline]
5107    fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
5108        func.bind0(context)
5109    }
5110}
5111
5112macro_rules! impl_js_args {
5113    ($arity:literal $trait:ident $bind_output:ident [$($A:ident)+] [$($idx:tt)+] $call:ident $bind:ident) => {
5114        impl<Ret: JsGeneric, $($A: JsGeneric,)+ F: $trait<Ret = Ret, $($A = $A,)*>> JsArgs<F> for ($(&$A,)+)
5115        {
5116            type BindOutput = Function<<F as $trait>::$bind_output>;
5117
5118            #[inline]
5119            fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
5120                func.$call(context, $(self.$idx),+)
5121            }
5122
5123            #[inline]
5124            fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
5125                func.$bind(context, $(self.$idx),+)
5126            }
5127        }
5128    };
5129}
5130
5131impl_js_args!(1 JsFunction1 Bind1 [Arg1] [0] call1 bind1);
5132impl_js_args!(2 JsFunction2 Bind2 [Arg1 Arg2] [0 1] call2 bind2);
5133impl_js_args!(3 JsFunction3 Bind3 [Arg1 Arg2 Arg3] [0 1 2] call3 bind3);
5134impl_js_args!(4 JsFunction4 Bind4 [Arg1 Arg2 Arg3 Arg4] [0 1 2 3] call4 bind4);
5135impl_js_args!(5 JsFunction5 Bind5 [Arg1 Arg2 Arg3 Arg4 Arg5] [0 1 2 3 4] call5 bind5);
5136impl_js_args!(6 JsFunction6 Bind6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [0 1 2 3 4 5] call6 bind6);
5137impl_js_args!(7 JsFunction7 Bind7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [0 1 2 3 4 5 6] call7 bind7);
5138impl_js_args!(8 JsFunction8 Bind8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [0 1 2 3 4 5 6 7] call8 bind8);
5139
5140impl<T: JsFunction> Function<T> {
5141    /// The `call()` method calls a function with a given `this` value and
5142    /// arguments provided as a tuple.
5143    ///
5144    /// This method accepts a tuple of references matching the function's
5145    /// argument types.
5146    ///
5147    /// # Example
5148    ///
5149    /// ```ignore
5150    /// // 0-arg function
5151    /// let f: Function<fn() -> Number> = get_fn();
5152    /// let result = f.call(&JsValue::NULL, ())?;
5153    ///
5154    /// // 1-arg function (note trailing comma for 1-tuple)
5155    /// let f: Function<fn(JsString) -> Number> = get_fn();
5156    /// let result = f.call(&JsValue::NULL, (&name,))?;
5157    ///
5158    /// // 2-arg function
5159    /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
5160    /// let result = f.call(&JsValue::NULL, (&name, &flag))?;
5161    /// ```
5162    ///
5163    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
5164    #[inline]
5165    pub fn call<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Result<T::Ret, JsValue> {
5166        args.apply_call(self, context)
5167    }
5168
5169    /// The `bind()` method creates a new function that, when called, has its
5170    /// `this` keyword set to the provided value, with a given sequence of
5171    /// arguments preceding any provided when the new function is called.
5172    ///
5173    /// This method accepts a tuple of references to bind.
5174    ///
5175    /// # Example
5176    ///
5177    /// ```ignore
5178    /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
5179    ///
5180    /// // Bind no args - same signature
5181    /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
5182    ///
5183    /// // Bind one arg (use 1-tuple of references)
5184    /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
5185    ///
5186    /// // Bind two args - becomes 0-arg function
5187    /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
5188    /// ```
5189    ///
5190    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
5191    #[inline]
5192    pub fn bindn<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
5193        args.apply_bind(self, context)
5194    }
5195
5196    /// The `bind()` method creates a new function that, when called, has its
5197    /// `this` keyword set to the provided value, with a given sequence of
5198    /// arguments preceding any provided when the new function is called.
5199    ///
5200    /// This method accepts a tuple of references to bind.
5201    ///
5202    /// # Example
5203    ///
5204    /// ```ignore
5205    /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
5206    ///
5207    /// // Bind no args - same signature
5208    /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
5209    ///
5210    /// // Bind one arg (use 1-tuple of references)
5211    /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
5212    ///
5213    /// // Bind two args - becomes 0-arg function
5214    /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
5215    /// ```
5216    ///
5217    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
5218    #[cfg(js_sys_unstable_apis)]
5219    #[inline]
5220    pub fn bind<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
5221        args.apply_bind(self, context)
5222    }
5223}
5224
5225pub trait FunctionIntoClosure: JsFunction {
5226    type ClosureTypeMut: WasmClosure + ?Sized;
5227}
5228
5229macro_rules! impl_function_into_closure {
5230    ( $(($($var:ident)*))* ) => {$(
5231        impl<$($var: FromWasmAbi,)* R: IntoWasmAbi> FunctionIntoClosure for fn($($var),*) -> R {
5232            type ClosureTypeMut = dyn FnMut($($var),*) -> R;
5233        }
5234    )*};
5235}
5236
5237impl_function_into_closure! {
5238    ()
5239    (A)
5240    (A B)
5241    (A B C)
5242    (A B C D)
5243    (A B C D E)
5244    (A B C D E F)
5245    (A B C D E F G)
5246    (A B C D E F G H)
5247}
5248
5249impl<F: JsFunction> Function<F> {
5250    /// Convert a borrowed `ScopedClosure` into a typed JavaScript Function reference.
5251    ///
5252    /// The conversion is a direct type-safe conversion and upcast of a
5253    /// closure into its corresponding typed JavaScript Function,
5254    /// based on covariance and contravariance [`Upcast`] trait hierarchy.
5255    ///
5256    /// For transferring ownership to JS, use [`Function::from_closure`].
5257    #[inline]
5258    pub fn closure_ref<'a, C>(closure: &'a ScopedClosure<'_, C>) -> &'a Self
5259    where
5260        F: FunctionIntoClosure,
5261        C: WasmClosure + ?Sized,
5262        <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
5263    {
5264        closure.as_js_value().unchecked_ref()
5265    }
5266
5267    /// Convert a Rust closure into a typed JavaScript Function.
5268    ///
5269    /// This function releases ownership of the closure to JS, and provides
5270    /// an owned function handle for the same closure.
5271    ///
5272    /// The conversion is a direct type-safe conversion and upcast of a
5273    /// closure into its corresponding typed JavaScript Function,
5274    /// based on covariance and contravariance [`Upcast`] trait hierarchy.
5275    ///
5276    /// This method is only supported for static closures which do not have
5277    /// borrowed lifetime data, and thus can be released into JS.
5278    ///
5279    /// For borrowed closures, which cannot cede ownership to JS,
5280    /// instead use [`Function::closure_ref`].
5281    #[inline]
5282    pub fn from_closure<C>(closure: ScopedClosure<'static, C>) -> Self
5283    where
5284        F: FunctionIntoClosure,
5285        C: WasmClosure + ?Sized,
5286        <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
5287    {
5288        closure.into_js_value().unchecked_into()
5289    }
5290}
5291
5292#[cfg(not(js_sys_unstable_apis))]
5293impl Function {
5294    /// Returns the `Function` value of this JS value if it's an instance of a
5295    /// function.
5296    ///
5297    /// If this JS value is not an instance of a function then this returns
5298    /// `None`.
5299    #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
5300    pub fn try_from(val: &JsValue) -> Option<&Function> {
5301        val.dyn_ref()
5302    }
5303}
5304
5305#[cfg(feature = "unsafe-eval")]
5306impl Default for Function {
5307    fn default() -> Self {
5308        Self::new_no_args("")
5309    }
5310}
5311
5312// FinalizationRegistry
5313#[wasm_bindgen]
5314extern "C" {
5315    /// The `FinalizationRegistry` object lets you request a callback when an
5316    /// object is garbage-collected.
5317    ///
5318    /// `FinalizationRegistry` provides a way to request that a cleanup
5319    /// callback get called at some point when an object registered with the
5320    /// registry has been reclaimed (garbage-collected). Cleanup callbacks
5321    /// are sometimes called *finalizers*.
5322    ///
5323    /// Avoid where possible: cleanup callbacks should not be relied upon for
5324    /// anything essential. They are best used to reduce memory usage over the
5325    /// course of a program for objects that benefit from cleanup. Whether,
5326    /// when, and in what order callbacks fire is implementation-defined.
5327    ///
5328    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry)
5329    #[wasm_bindgen(extends = Object, typescript_type = "FinalizationRegistry<any>")]
5330    #[derive(Clone, Debug, PartialEq, Eq)]
5331    pub type FinalizationRegistry;
5332
5333    /// Creates a new `FinalizationRegistry` with the given cleanup callback.
5334    ///
5335    /// The cleanup callback is invoked, at some point after a registered
5336    /// target is garbage-collected, with the `held_value` that was passed to
5337    /// [`FinalizationRegistry::register`]. Because callbacks may be deferred
5338    /// or skipped entirely, the callback should normally outlive the
5339    /// `FinalizationRegistry` (for example by being created via
5340    /// [`Function::from_closure`]).
5341    ///
5342    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/FinalizationRegistry)
5343    #[wasm_bindgen(constructor)]
5344    pub fn new(cleanup_callback: &Function<fn(JsValue) -> Undefined>) -> FinalizationRegistry;
5345
5346    /// Registers `target` with this `FinalizationRegistry`. When `target` is
5347    /// reclaimed by the garbage collector the cleanup callback may be called
5348    /// with `held_value`.
5349    ///
5350    /// `target` must be an object (or a non-registered symbol).
5351    ///
5352    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/register)
5353    #[wasm_bindgen(method)]
5354    pub fn register(this: &FinalizationRegistry, target: &JsValue, held_value: &JsValue);
5355
5356    /// Registers `target` with this `FinalizationRegistry`, with an
5357    /// `unregister_token` that can later be passed to
5358    /// [`FinalizationRegistry::unregister`] to remove the registration.
5359    ///
5360    /// `target` and `unregister_token` must be objects (or non-registered
5361    /// symbols), and the same value may be passed for both.
5362    ///
5363    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/register)
5364    #[wasm_bindgen(method, js_name = register)]
5365    pub fn register_with_token(
5366        this: &FinalizationRegistry,
5367        target: &JsValue,
5368        held_value: &JsValue,
5369        unregister_token: &JsValue,
5370    );
5371
5372    /// Unregisters all entries registered with this `FinalizationRegistry`
5373    /// using `unregister_token`. Returns `true` if any cells were removed.
5374    ///
5375    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/unregister)
5376    #[wasm_bindgen(method)]
5377    pub fn unregister(this: &FinalizationRegistry, unregister_token: &JsValue) -> bool;
5378}
5379
5380// Generator
5381#[wasm_bindgen]
5382extern "C" {
5383    #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
5384    #[derive(Clone, Debug, PartialEq, Eq)]
5385    pub type Generator<T = JsValue>;
5386
5387    /// The `next()` method returns an object with two properties done and value.
5388    /// You can also provide a parameter to the next method to send a value to the generator.
5389    ///
5390    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5391    #[cfg(not(js_sys_unstable_apis))]
5392    #[wasm_bindgen(method, catch)]
5393    pub fn next<T>(this: &Generator<T>, value: &T) -> Result<JsValue, JsValue>;
5394
5395    /// The `next()` method returns an object with two properties done and value.
5396    /// You can also provide a parameter to the next method to send a value to the generator.
5397    ///
5398    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5399    #[cfg(js_sys_unstable_apis)]
5400    #[wasm_bindgen(method, catch, js_name = next)]
5401    pub fn next<T: FromWasmAbi>(this: &Generator<T>, value: &T)
5402        -> Result<IteratorNext<T>, JsValue>;
5403
5404    // Next major: deprecate
5405    /// The `next()` method returns an object with two properties done and value.
5406    /// You can also provide a parameter to the next method to send a value to the generator.
5407    ///
5408    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5409    #[wasm_bindgen(method, catch)]
5410    pub fn next_iterator<T: FromWasmAbi>(
5411        this: &Generator<T>,
5412        value: &T,
5413    ) -> Result<IteratorNext<T>, JsValue>;
5414
5415    /// The `return()` method returns the given value and finishes the generator.
5416    ///
5417    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5418    #[cfg(not(js_sys_unstable_apis))]
5419    #[wasm_bindgen(method, js_name = "return")]
5420    pub fn return_<T>(this: &Generator<T>, value: &T) -> JsValue;
5421
5422    /// The `return()` method returns the given value and finishes the generator.
5423    ///
5424    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5425    #[cfg(js_sys_unstable_apis)]
5426    #[wasm_bindgen(method, catch, js_name = "return")]
5427    pub fn return_<T: FromWasmAbi>(
5428        this: &Generator<T>,
5429        value: &T,
5430    ) -> Result<IteratorNext<T>, JsValue>;
5431
5432    // Next major: deprecate
5433    /// The `return()` method returns the given value and finishes the generator.
5434    ///
5435    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5436    #[wasm_bindgen(method, catch, js_name = "return")]
5437    pub fn try_return<T: FromWasmAbi>(
5438        this: &Generator<T>,
5439        value: &T,
5440    ) -> Result<IteratorNext<T>, JsValue>;
5441
5442    /// The `throw()` method resumes the execution of a generator by throwing an error into it
5443    /// and returns an object with two properties done and value.
5444    ///
5445    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5446    #[cfg(not(js_sys_unstable_apis))]
5447    #[wasm_bindgen(method, catch)]
5448    pub fn throw<T>(this: &Generator<T>, error: &Error) -> Result<JsValue, JsValue>;
5449
5450    /// The `throw()` method resumes the execution of a generator by throwing an error into it
5451    /// and returns an object with two properties done and value.
5452    ///
5453    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5454    #[cfg(js_sys_unstable_apis)]
5455    #[wasm_bindgen(method, catch, js_name = throw)]
5456    pub fn throw<T: FromWasmAbi>(
5457        this: &Generator<T>,
5458        error: &JsValue,
5459    ) -> Result<IteratorNext<T>, JsValue>;
5460
5461    // Next major: deprecate
5462    /// The `throw()` method resumes the execution of a generator by throwing an error into it
5463    /// and returns an object with two properties done and value.
5464    ///
5465    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5466    #[wasm_bindgen(method, catch, js_name = throw)]
5467    pub fn throw_value<T: FromWasmAbi>(
5468        this: &Generator<T>,
5469        error: &JsValue,
5470    ) -> Result<IteratorNext<T>, JsValue>;
5471}
5472
5473impl<T: FromWasmAbi> Iterable for Generator<T> {
5474    type Item = T;
5475}
5476
5477// AsyncGenerator
5478#[wasm_bindgen]
5479extern "C" {
5480    #[wasm_bindgen(extends = Object, typescript_type = "AsyncGenerator<any, any, any>")]
5481    #[derive(Clone, Debug, PartialEq, Eq)]
5482    pub type AsyncGenerator<T = JsValue>;
5483
5484    /// The `next()` method returns an object with two properties done and value.
5485    /// You can also provide a parameter to the next method to send a value to the generator.
5486    ///
5487    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/next)
5488    #[wasm_bindgen(method, catch)]
5489    pub fn next<T>(
5490        this: &AsyncGenerator<T>,
5491        value: &T,
5492    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5493
5494    /// The `return()` method returns the given value and finishes the generator.
5495    ///
5496    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/return)
5497    #[wasm_bindgen(method, js_name = "return", catch)]
5498    pub fn return_<T>(
5499        this: &AsyncGenerator<T>,
5500        value: &T,
5501    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5502
5503    /// The `throw()` method resumes the execution of a generator by throwing an error into it
5504    /// and returns an object with two properties done and value.
5505    ///
5506    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/throw)
5507    #[wasm_bindgen(method, catch)]
5508    pub fn throw<T>(
5509        this: &AsyncGenerator<T>,
5510        error: &JsValue,
5511    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5512}
5513
5514impl<T: FromWasmAbi> AsyncIterable for AsyncGenerator<T> {
5515    type Item = T;
5516}
5517
5518// Map
5519#[wasm_bindgen]
5520extern "C" {
5521    #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
5522    #[derive(Clone, Debug, PartialEq, Eq)]
5523    pub type Map<K = JsValue, V = JsValue>;
5524
5525    /// The Map object holds key-value pairs. Any value (both objects and
5526    /// primitive values) maybe used as either a key or a value.
5527    ///
5528    /// **Note:** Consider using [`Map::new_typed`] for typing support.
5529    ///
5530    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5531    #[cfg(not(js_sys_unstable_apis))]
5532    #[wasm_bindgen(constructor)]
5533    pub fn new() -> Map;
5534
5535    /// The Map object holds key-value pairs. Any value (both objects and
5536    /// primitive values) maybe used as either a key or a value.
5537    ///
5538    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5539    #[cfg(js_sys_unstable_apis)]
5540    #[wasm_bindgen(constructor)]
5541    pub fn new<K, V>() -> Map<K, V>;
5542
5543    // Next major: deprecate
5544    /// The Map object holds key-value pairs. Any value (both objects and
5545    /// primitive values) maybe used as either a key or a value.
5546    ///
5547    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5548    #[wasm_bindgen(constructor)]
5549    pub fn new_typed<K, V>() -> Map<K, V>;
5550
5551    /// The Map object holds key-value pairs. Any value (both objects and
5552    /// primitive values) maybe used as either a key or a value.
5553    ///
5554    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5555    #[wasm_bindgen(constructor, js_name = new)]
5556    pub fn new_from_entries<K, V, I: Iterable<Item = ArrayTuple<(K, V)>>>(entries: &I)
5557        -> Map<K, V>;
5558
5559    /// The `clear()` method removes all elements from a Map object.
5560    ///
5561    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
5562    #[wasm_bindgen(method)]
5563    pub fn clear<K, V>(this: &Map<K, V>);
5564
5565    /// The `delete()` method removes the specified element from a Map object.
5566    ///
5567    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
5568    #[wasm_bindgen(method)]
5569    pub fn delete<K, V>(this: &Map<K, V>, key: &K) -> bool;
5570
5571    /// The `forEach()` method executes a provided function once per each
5572    /// key/value pair in the Map object, in insertion order.
5573    /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
5574    /// # Examples
5575    /// ```
5576    /// let js_map = Map::new();
5577    /// js_map.for_each(&mut |value, key| {
5578    ///     // Do something here...
5579    /// })
5580    /// ```
5581    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
5582    #[wasm_bindgen(method, js_name = forEach)]
5583    pub fn for_each<K, V>(this: &Map<K, V>, callback: &mut dyn FnMut(V, K));
5584
5585    /// The `forEach()` method executes a provided function once per each
5586    /// key/value pair in the Map object, in insertion order. _(Fallible variation)_
5587    /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
5588    /// # Examples
5589    /// ```
5590    /// let js_map = Map::new();
5591    /// js_map.for_each(&mut |value, key| {
5592    ///     // Do something here...
5593    /// })
5594    /// ```
5595    ///
5596    /// **Note:** Consider using [`Map::try_for_each`] if the callback might throw an error.
5597    ///
5598    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
5599    #[wasm_bindgen(method, js_name = forEach, catch)]
5600    pub fn try_for_each<K, V>(
5601        this: &Map<K, V>,
5602        callback: &mut dyn FnMut(V, K) -> Result<(), JsError>,
5603    ) -> Result<(), JsValue>;
5604
5605    /// The `get()` method returns a specified element from a Map object.
5606    /// Returns `undefined` if the key is not found.
5607    ///
5608    /// **Note:** Consider using [`Map::get_checked`] to get an `Option<V>` instead.
5609    ///
5610    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5611    #[cfg(not(js_sys_unstable_apis))]
5612    #[wasm_bindgen(method)]
5613    pub fn get<K, V>(this: &Map<K, V>, key: &K) -> V;
5614
5615    /// The `get()` method returns a specified element from a Map object.
5616    /// Returns `None` if the key is not found.
5617    ///
5618    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5619    #[cfg(js_sys_unstable_apis)]
5620    #[wasm_bindgen(method)]
5621    pub fn get<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
5622
5623    /// The `get()` method returns a specified element from a Map object.
5624    /// Returns `None` if the key is not found.
5625    ///
5626    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5627    #[wasm_bindgen(method, js_name = get)]
5628    pub fn get_checked<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
5629
5630    /// The `has()` method returns a boolean indicating whether an element with
5631    /// the specified key exists or not.
5632    ///
5633    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
5634    #[wasm_bindgen(method)]
5635    pub fn has<K, V>(this: &Map<K, V>, key: &K) -> bool;
5636
5637    /// The `set()` method adds or updates an element with a specified key
5638    /// and value to a Map object.
5639    ///
5640    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
5641    #[wasm_bindgen(method)]
5642    pub fn set<K, V>(this: &Map<K, V>, key: &K, value: &V) -> Map<K, V>;
5643
5644    /// The value of size is an integer representing how many entries
5645    /// the Map object has. A set accessor function for size is undefined;
5646    /// you can not change this property.
5647    ///
5648    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
5649    #[wasm_bindgen(method, getter)]
5650    pub fn size<K, V>(this: &Map<K, V>) -> u32;
5651
5652    /// The `getOrInsert()` method returns the value for `key`, first
5653    /// inserting `default_value` under it if the key is absent.
5654    ///
5655    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/getOrInsert)
5656    #[wasm_bindgen(method, js_name = getOrInsert)]
5657    pub fn get_or_insert<K, V>(this: &Map<K, V>, key: &K, default_value: &V) -> V;
5658
5659    /// The `getOrInsertComputed()` method returns the value for `key`,
5660    /// first inserting the result of `callback(key)` under it if the key
5661    /// is absent.
5662    ///
5663    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/getOrInsertComputed)
5664    #[wasm_bindgen(method, js_name = getOrInsertComputed)]
5665    pub fn get_or_insert_computed<K, V>(
5666        this: &Map<K, V>,
5667        key: &K,
5668        callback: &mut dyn FnMut(K) -> V,
5669    ) -> V;
5670
5671    /// The `Map.groupBy()` static method groups the values of an iterable
5672    /// into a `Map` keyed by the result of `callback`, which may be any
5673    /// value, compared with SameValueZero.
5674    ///
5675    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/groupBy)
5676    #[wasm_bindgen(static_method_of = Map, catch, js_name = groupBy)]
5677    pub fn group_by<T, K, I: Iterable<Item = T>>(
5678        items: &I,
5679        callback: &mut dyn FnMut(T, u32) -> K,
5680    ) -> Result<Map<K, Array<T>>, JsValue>;
5681}
5682
5683impl Default for Map<JsValue, JsValue> {
5684    fn default() -> Self {
5685        Self::new()
5686    }
5687}
5688
5689// Map Iterator
5690#[wasm_bindgen]
5691extern "C" {
5692    /// The `entries()` method returns a new Iterator object that contains
5693    /// the [key, value] pairs for each element in the Map object in
5694    /// insertion order.
5695    ///
5696    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5697    #[cfg(not(js_sys_unstable_apis))]
5698    #[wasm_bindgen(method)]
5699    pub fn entries<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator;
5700
5701    /// The `entries()` method returns a new Iterator object that contains
5702    /// the [key, value] pairs for each element in the Map object in
5703    /// insertion order.
5704    ///
5705    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5706    #[cfg(js_sys_unstable_apis)]
5707    #[wasm_bindgen(method, js_name = entries)]
5708    pub fn entries<K, V>(this: &Map<K, V>) -> Iterator<ArrayTuple<(K, V)>>;
5709
5710    // Next major: deprecate
5711    /// The `entries()` method returns a new Iterator object that contains
5712    /// the [key, value] pairs for each element in the Map object in
5713    /// insertion order.
5714    ///
5715    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5716    #[wasm_bindgen(method, js_name = entries)]
5717    pub fn entries_typed<K, V>(this: &Map<K, V>) -> Iterator<ArrayTuple<(K, V)>>;
5718
5719    /// The `keys()` method returns a new Iterator object that contains the
5720    /// keys for each element in the Map object in insertion order.
5721    ///
5722    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
5723    #[wasm_bindgen(method)]
5724    pub fn keys<K: FromWasmAbi, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<K>;
5725
5726    /// The `values()` method returns a new Iterator object that contains the
5727    /// values for each element in the Map object in insertion order.
5728    ///
5729    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values)
5730    #[wasm_bindgen(method)]
5731    pub fn values<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<V>;
5732}
5733
5734impl<K, V> Iterable for Map<K, V> {
5735    type Item = ArrayTuple<(K, V)>;
5736}
5737
5738// Iterator
5739#[wasm_bindgen]
5740extern "C" {
5741    /// Any object that conforms to the JS iterator protocol. For example,
5742    /// something returned by `myArray[Symbol.iterator]()`.
5743    ///
5744    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5745    #[derive(Clone, Debug)]
5746    #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
5747    pub type Iterator<T = JsValue>;
5748
5749    /// The `next()` method always has to return an object with appropriate
5750    /// properties including done and value. If a non-object value gets returned
5751    /// (such as false or undefined), a TypeError ("iterator.next() returned a
5752    /// non-object value") will be thrown.
5753    #[wasm_bindgen(catch, method)]
5754    pub fn next<T: FromWasmAbi>(this: &Iterator<T>) -> Result<IteratorNext<T>, JsValue>;
5755
5756    /// The `Iterator.from()` static method wraps any iterable or
5757    /// iterator-like object in an `Iterator` inheriting from
5758    /// `Iterator.prototype`. Named `from_iterable` as `from` is taken by
5759    /// `From<JsValue>`.
5760    ///
5761    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/from)
5762    #[wasm_bindgen(static_method_of = Iterator, js_name = from)]
5763    pub fn from_iterable<I: Iterable>(obj: &I) -> Iterator<I::Item>;
5764
5765    /// The `Iterator.concat()` static method returns an iterator yielding
5766    /// the values of each given iterable in turn.
5767    ///
5768    /// # Errors
5769    /// Throws a `TypeError` for an `Iterator<T>` that is a bare `{ next }`
5770    /// object, as those have no `Symbol.iterator`.
5771    ///
5772    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/concat)
5773    #[wasm_bindgen(static_method_of = Iterator, catch, variadic)]
5774    pub fn concat<I: Iterable>(iterables: &[I]) -> Result<Iterator<I::Item>, JsValue>;
5775
5776    /// The `map()` method returns a new iterator helper that yields each
5777    /// value of this iterator transformed by `mapper`.
5778    ///
5779    /// The mapper runs lazily, as the returned iterator is consumed, so it
5780    /// is taken as a [`ScopedClosure`] which must outlive that consumption.
5781    ///
5782    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/map)
5783    #[wasm_bindgen(method, final)]
5784    pub fn map<'a, T, U>(
5785        this: &Iterator<T>,
5786        mapper: &ScopedClosure<'a, dyn FnMut(T, u32) -> U>,
5787    ) -> Iterator<U>;
5788
5789    /// The `filter()` method returns a new iterator helper that yields only
5790    /// the values of this iterator for which `predicate` returns `true`.
5791    ///
5792    /// The predicate runs lazily, as the returned iterator is consumed, so
5793    /// it is taken as a [`ScopedClosure`] which must outlive that
5794    /// consumption.
5795    ///
5796    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/filter)
5797    #[wasm_bindgen(method, final)]
5798    pub fn filter<'a, T>(
5799        this: &Iterator<T>,
5800        predicate: &ScopedClosure<'a, dyn FnMut(T, u32) -> bool>,
5801    ) -> Iterator<T>;
5802
5803    /// The `take()` method returns a new iterator helper that yields at
5804    /// most `limit` values of this iterator.
5805    ///
5806    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/take)
5807    #[wasm_bindgen(method, final)]
5808    pub fn take<T>(this: &Iterator<T>, limit: u32) -> Iterator<T>;
5809
5810    /// The `drop()` method returns a new iterator helper that skips the
5811    /// first `limit` values of this iterator and yields the rest.
5812    ///
5813    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/drop)
5814    #[wasm_bindgen(method, final)]
5815    pub fn drop<T>(this: &Iterator<T>, limit: u32) -> Iterator<T>;
5816
5817    /// The `flatMap()` method returns a new iterator helper that yields the
5818    /// values of each iterable or iterator returned by `mapper`.
5819    ///
5820    /// The mapper runs lazily, as the returned iterator is consumed, so it
5821    /// is taken as a [`ScopedClosure`] which must outlive that consumption.
5822    ///
5823    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/flatMap)
5824    #[wasm_bindgen(method, final, js_name = flatMap)]
5825    pub fn flat_map<'a, T, I: Iterable>(
5826        this: &Iterator<T>,
5827        mapper: &ScopedClosure<'a, dyn FnMut(T, u32) -> I>,
5828    ) -> Iterator<I::Item>;
5829
5830    /// The `reduce()` method consumes this iterator, folding every value
5831    /// into an accumulator starting from `initial_value`.
5832    ///
5833    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/reduce)
5834    #[wasm_bindgen(method, final, catch)]
5835    pub fn reduce<T, A>(
5836        this: &Iterator<T>,
5837        reducer: &mut dyn FnMut(A, T, u32) -> A,
5838        initial_value: &A,
5839    ) -> Result<A, JsValue>;
5840
5841    /// The `toArray()` method consumes this iterator, collecting its values
5842    /// into an `Array`.
5843    ///
5844    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/toArray)
5845    #[wasm_bindgen(method, final, catch, js_name = toArray)]
5846    pub fn to_array<T>(this: &Iterator<T>) -> Result<Array<T>, JsValue>;
5847
5848    /// The `forEach()` method consumes this iterator, calling `callback`
5849    /// with each value and its index.
5850    ///
5851    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/forEach)
5852    #[wasm_bindgen(method, final, catch, js_name = forEach)]
5853    pub fn for_each<T>(this: &Iterator<T>, callback: &mut dyn FnMut(T, u32))
5854        -> Result<(), JsValue>;
5855
5856    /// The `some()` method consumes this iterator until `predicate` returns
5857    /// `true` for a value, returning whether it did.
5858    ///
5859    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/some)
5860    #[wasm_bindgen(method, final, catch)]
5861    pub fn some<T>(
5862        this: &Iterator<T>,
5863        predicate: &mut dyn FnMut(T, u32) -> bool,
5864    ) -> Result<bool, JsValue>;
5865
5866    /// The `every()` method consumes this iterator until `predicate` returns
5867    /// `false` for a value, returning whether it never did.
5868    ///
5869    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/every)
5870    #[wasm_bindgen(method, final, catch)]
5871    pub fn every<T>(
5872        this: &Iterator<T>,
5873        predicate: &mut dyn FnMut(T, u32) -> bool,
5874    ) -> Result<bool, JsValue>;
5875
5876    /// The `find()` method consumes this iterator until `predicate` returns
5877    /// `true` for a value, returning that value if any.
5878    ///
5879    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/find)
5880    #[wasm_bindgen(method, final, catch)]
5881    pub fn find<T>(
5882        this: &Iterator<T>,
5883        predicate: &mut dyn FnMut(T, u32) -> bool,
5884    ) -> Result<Option<T>, JsValue>;
5885}
5886
5887impl<T> UpcastFrom<Iterator<T>> for Object {}
5888
5889impl Iterator {
5890    fn looks_like_iterator(it: &JsValue) -> bool {
5891        #[wasm_bindgen]
5892        extern "C" {
5893            #[derive(Clone, Debug)]
5894            type MaybeIterator;
5895
5896            #[wasm_bindgen(method, getter)]
5897            fn next(this: &MaybeIterator) -> JsValue;
5898        }
5899
5900        if !it.is_object() {
5901            return false;
5902        }
5903
5904        let it = it.unchecked_ref::<MaybeIterator>();
5905
5906        it.next().is_function()
5907    }
5908}
5909
5910// iterators in JS are themselves iterable
5911impl<T> Iterable for Iterator<T> {
5912    type Item = T;
5913}
5914
5915// Async Iterator
5916#[wasm_bindgen]
5917extern "C" {
5918    /// Any object that conforms to the JS async iterator protocol. For example,
5919    /// something returned by `myObject[Symbol.asyncIterator]()`.
5920    ///
5921    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
5922    #[derive(Clone, Debug)]
5923    #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>")]
5924    pub type AsyncIterator<T = JsValue>;
5925
5926    /// The `next()` method always has to return a Promise which resolves to an object
5927    /// with appropriate properties including done and value. If a non-object value
5928    /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5929    /// returned a non-object value") will be thrown.
5930    #[cfg(not(js_sys_unstable_apis))]
5931    #[wasm_bindgen(catch, method)]
5932    pub fn next<T>(this: &AsyncIterator<T>) -> Result<Promise, JsValue>;
5933
5934    /// The `next()` method always has to return a Promise which resolves to an object
5935    /// with appropriate properties including done and value. If a non-object value
5936    /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5937    /// returned a non-object value") will be thrown.
5938    #[cfg(js_sys_unstable_apis)]
5939    #[wasm_bindgen(catch, method, js_name = next)]
5940    pub fn next<T: FromWasmAbi>(
5941        this: &AsyncIterator<T>,
5942    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5943
5944    // Next major: deprecate
5945    /// The `next()` method always has to return a Promise which resolves to an object
5946    /// with appropriate properties including done and value. If a non-object value
5947    /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5948    /// returned a non-object value") will be thrown.
5949    #[wasm_bindgen(catch, method, js_name = next)]
5950    pub fn next_iterator<T: FromWasmAbi>(
5951        this: &AsyncIterator<T>,
5952    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5953}
5954
5955impl<T> UpcastFrom<AsyncIterator<T>> for Object {}
5956
5957// iterators in JS are themselves iterable
5958impl<T> AsyncIterable for AsyncIterator<T> {
5959    type Item = T;
5960}
5961
5962/// An iterator over the JS `Symbol.iterator` iteration protocol.
5963///
5964/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
5965pub struct Iter<'a, T = JsValue> {
5966    js: &'a Iterator<T>,
5967    state: IterState,
5968}
5969
5970/// An iterator over the JS `Symbol.iterator` iteration protocol.
5971///
5972/// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
5973pub struct IntoIter<T = JsValue> {
5974    js: Iterator<T>,
5975    state: IterState,
5976}
5977
5978struct IterState {
5979    done: bool,
5980}
5981
5982impl<'a, T: FromWasmAbi + JsGeneric> IntoIterator for &'a Iterator<T> {
5983    type Item = Result<T, JsValue>;
5984    type IntoIter = Iter<'a, T>;
5985
5986    fn into_iter(self) -> Iter<'a, T> {
5987        Iter {
5988            js: self,
5989            state: IterState::new(),
5990        }
5991    }
5992}
5993
5994impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for Iter<'_, T> {
5995    type Item = Result<T, JsValue>;
5996
5997    fn next(&mut self) -> Option<Self::Item> {
5998        self.state.next(self.js)
5999    }
6000}
6001
6002impl<T: FromWasmAbi + JsGeneric> IntoIterator for Iterator<T> {
6003    type Item = Result<T, JsValue>;
6004    type IntoIter = IntoIter<T>;
6005
6006    fn into_iter(self) -> IntoIter<T> {
6007        IntoIter {
6008            js: self,
6009            state: IterState::new(),
6010        }
6011    }
6012}
6013
6014impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for IntoIter<T> {
6015    type Item = Result<T, JsValue>;
6016
6017    fn next(&mut self) -> Option<Self::Item> {
6018        self.state.next(&self.js)
6019    }
6020}
6021
6022impl IterState {
6023    fn new() -> IterState {
6024        IterState { done: false }
6025    }
6026
6027    fn next<T: FromWasmAbi + JsGeneric>(&mut self, js: &Iterator<T>) -> Option<Result<T, JsValue>> {
6028        if self.done {
6029            return None;
6030        }
6031        let next = match js.next() {
6032            Ok(val) => val,
6033            Err(e) => {
6034                self.done = true;
6035                return Some(Err(e));
6036            }
6037        };
6038        if next.done() {
6039            self.done = true;
6040            None
6041        } else {
6042            Some(Ok(next.value()))
6043        }
6044    }
6045}
6046
6047/// Create an iterator over `val` using the JS iteration protocol and
6048/// `Symbol.iterator`.
6049// #[cfg(not(js_sys_unstable_apis))]
6050pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter<JsValue>>, JsValue> {
6051    let iter_sym = Symbol::iterator();
6052
6053    let iter_fn = Reflect::get_symbol::<Object>(val.unchecked_ref(), iter_sym.as_ref())?;
6054    let iter_fn: Function = match iter_fn.dyn_into() {
6055        Ok(iter_fn) => iter_fn,
6056        Err(_) => return Ok(None),
6057    };
6058
6059    let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
6060        Ok(it) => it,
6061        Err(_) => return Ok(None),
6062    };
6063
6064    Ok(Some(it.into_iter()))
6065}
6066
6067/// Trait for JavaScript types that implement the iterable protocol via `Symbol.iterator`.
6068///
6069/// Types implementing this trait can be iterated over using JavaScript's iteration
6070/// protocol. The `Item` associated type specifies the type of values yielded.
6071///
6072/// ## Built-in Iterables
6073///
6074/// Many `js-sys` collection types implement `Iterable` out of the box:
6075///
6076/// ```ignore
6077/// use js_sys::{Array, Map, Set};
6078///
6079/// // Array<T> yields T
6080/// let arr: Array<Number> = get_numbers();
6081/// for value in arr.iter() {
6082///     let num: Number = value?;
6083/// }
6084///
6085/// // Map<K, V> yields Array (key-value pairs)
6086/// let map: Map<JsString, Number> = get_map();
6087/// for entry in map.iter() {
6088///     let pair: Array = entry?;
6089/// }
6090///
6091/// // Set<T> yields T
6092/// let set: Set<JsString> = get_set();
6093/// for value in set.iter() {
6094///     let s: JsString = value?;
6095/// }
6096/// ```
6097///
6098/// ## Typing Foreign Iterators
6099///
6100/// If you have a JavaScript value that implements the iterator protocol (has a `next()`
6101/// method) but isn't a built-in type, you can use [`JsCast`] to cast it to [`Iterator<T>`]:
6102///
6103/// ```ignore
6104/// use js_sys::Iterator;
6105/// use wasm_bindgen::JsCast;
6106///
6107/// // For a value you know implements the iterator protocol
6108/// fn process_iterator(js_iter: JsValue) {
6109///     // Checked cast - returns None if not an iterator
6110///     if let Some(iter) = js_iter.dyn_ref::<Iterator<Number>>() {
6111///         for value in iter.into_iter() {
6112///             let num: Number = value.unwrap();
6113///             // ...
6114///         }
6115///     }
6116/// }
6117///
6118/// // Or with unchecked cast when you're certain of the type
6119/// fn process_known_iterator(js_iter: JsValue) {
6120///     let iter: &Iterator<JsString> = js_iter.unchecked_ref();
6121///     for value in iter.into_iter() {
6122///         let s: JsString = value.unwrap();
6123///         // ...
6124///     }
6125/// }
6126/// ```
6127///
6128/// ## Using with `JsValue`
6129///
6130/// For dynamic or unknown iterables, use [`try_iter`] which returns an untyped iterator:
6131///
6132/// ```ignore
6133/// fn iterate_unknown(val: &JsValue) -> Result<(), JsValue> {
6134///     if let Some(iter) = js_sys::try_iter(val)? {
6135///         for item in iter {
6136///             let value: JsValue = item?;
6137///             // Handle dynamically...
6138///         }
6139///     }
6140///     Ok(())
6141/// }
6142/// ```
6143///
6144/// [`JsCast`]: wasm_bindgen::JsCast
6145/// [`Iterator<T>`]: Iterator
6146/// [`try_iter`]: crate::try_iter
6147pub trait Iterable {
6148    /// The type of values yielded by this iterable.
6149    type Item;
6150}
6151
6152impl<T: Iterable> Iterable for &T {
6153    type Item = T::Item;
6154}
6155
6156/// Trait for types known to implement the iterator protocol on Symbol.asyncIterator
6157pub trait AsyncIterable {
6158    type Item;
6159}
6160
6161impl<T: AsyncIterable> AsyncIterable for &T {
6162    type Item = T::Item;
6163}
6164
6165impl AsyncIterable for JsValue {
6166    type Item = JsValue;
6167}
6168
6169// IteratorNext
6170#[wasm_bindgen]
6171extern "C" {
6172    /// The result of calling `next()` on a JS iterator.
6173    ///
6174    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
6175    #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
6176    #[derive(Clone, Debug, PartialEq, Eq)]
6177    pub type IteratorNext<T = JsValue>;
6178
6179    /// Has the value `true` if the iterator is past the end of the iterated
6180    /// sequence. In this case value optionally specifies the return value of
6181    /// the iterator.
6182    ///
6183    /// Has the value `false` if the iterator was able to produce the next value
6184    /// in the sequence. This is equivalent of not specifying the done property
6185    /// altogether.
6186    #[wasm_bindgen(method, getter)]
6187    pub fn done<T>(this: &IteratorNext<T>) -> bool;
6188
6189    /// Any JavaScript value returned by the iterator. Can be omitted when done
6190    /// is true.
6191    #[wasm_bindgen(method, getter)]
6192    pub fn value<T>(this: &IteratorNext<T>) -> T;
6193}
6194
6195#[allow(non_snake_case)]
6196pub mod Math {
6197    use super::*;
6198
6199    // Math
6200    #[wasm_bindgen]
6201    extern "C" {
6202        /// The `Math.abs()` function returns the absolute value of a number, that is
6203        /// Math.abs(x) = |x|
6204        ///
6205        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
6206        #[wasm_bindgen(js_namespace = Math)]
6207        pub fn abs(x: f64) -> f64;
6208
6209        /// The `Math.acos()` function returns the arccosine (in radians) of a
6210        /// number, that is ∀x∊[-1;1]
6211        /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
6212        ///
6213        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
6214        #[wasm_bindgen(js_namespace = Math)]
6215        pub fn acos(x: f64) -> f64;
6216
6217        /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
6218        /// number, that is ∀x ≥ 1
6219        /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
6220        ///
6221        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
6222        #[wasm_bindgen(js_namespace = Math)]
6223        pub fn acosh(x: f64) -> f64;
6224
6225        /// The `Math.asin()` function returns the arcsine (in radians) of a
6226        /// number, that is ∀x ∊ [-1;1]
6227        /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
6228        ///
6229        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
6230        #[wasm_bindgen(js_namespace = Math)]
6231        pub fn asin(x: f64) -> f64;
6232
6233        /// The `Math.asinh()` function returns the hyperbolic arcsine of a
6234        /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
6235        ///
6236        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
6237        #[wasm_bindgen(js_namespace = Math)]
6238        pub fn asinh(x: f64) -> f64;
6239
6240        /// The `Math.atan()` function returns the arctangent (in radians) of a
6241        /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
6242        /// tan(y) = x
6243        #[wasm_bindgen(js_namespace = Math)]
6244        pub fn atan(x: f64) -> f64;
6245
6246        /// The `Math.atan2()` function returns the arctangent of the quotient of
6247        /// its arguments.
6248        ///
6249        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
6250        #[wasm_bindgen(js_namespace = Math)]
6251        pub fn atan2(y: f64, x: f64) -> f64;
6252
6253        /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
6254        /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
6255        /// tanh(y) = x
6256        ///
6257        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
6258        #[wasm_bindgen(js_namespace = Math)]
6259        pub fn atanh(x: f64) -> f64;
6260
6261        /// The `Math.cbrt() `function returns the cube root of a number, that is
6262        /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
6263        ///
6264        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
6265        #[wasm_bindgen(js_namespace = Math)]
6266        pub fn cbrt(x: f64) -> f64;
6267
6268        /// The `Math.ceil()` function returns the smallest integer greater than
6269        /// or equal to a given number.
6270        ///
6271        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
6272        #[wasm_bindgen(js_namespace = Math)]
6273        pub fn ceil(x: f64) -> f64;
6274
6275        /// The `Math.clz32()` function returns the number of leading zero bits in
6276        /// the 32-bit binary representation of a number.
6277        ///
6278        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
6279        #[wasm_bindgen(js_namespace = Math)]
6280        pub fn clz32(x: i32) -> u32;
6281
6282        /// The `Math.cos()` static function returns the cosine of the specified angle,
6283        /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
6284        ///
6285        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
6286        #[wasm_bindgen(js_namespace = Math)]
6287        pub fn cos(x: f64) -> f64;
6288
6289        /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
6290        /// that can be expressed using the constant e.
6291        ///
6292        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
6293        #[wasm_bindgen(js_namespace = Math)]
6294        pub fn cosh(x: f64) -> f64;
6295
6296        /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
6297        /// (also known as Napier's constant), the base of the natural logarithms.
6298        ///
6299        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
6300        #[wasm_bindgen(js_namespace = Math)]
6301        pub fn exp(x: f64) -> f64;
6302
6303        /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
6304        /// natural logarithms.
6305        ///
6306        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
6307        #[wasm_bindgen(js_namespace = Math)]
6308        pub fn expm1(x: f64) -> f64;
6309
6310        /// The `Math.floor()` function returns the largest integer less than or
6311        /// equal to a given number.
6312        ///
6313        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
6314        #[wasm_bindgen(js_namespace = Math)]
6315        pub fn floor(x: f64) -> f64;
6316
6317        /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
6318        /// of a Number.
6319        ///
6320        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
6321        #[wasm_bindgen(js_namespace = Math)]
6322        pub fn fround(x: f64) -> f32;
6323
6324        /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
6325        ///
6326        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
6327        #[wasm_bindgen(js_namespace = Math)]
6328        pub fn hypot(x: f64, y: f64) -> f64;
6329
6330        /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
6331        /// two parameters.
6332        ///
6333        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
6334        #[wasm_bindgen(js_namespace = Math)]
6335        pub fn imul(x: i32, y: i32) -> i32;
6336
6337        /// The `Math.log()` function returns the natural logarithm (base e) of a number.
6338        /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
6339        ///
6340        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
6341        #[wasm_bindgen(js_namespace = Math)]
6342        pub fn log(x: f64) -> f64;
6343
6344        /// The `Math.log10()` function returns the base 10 logarithm of a number.
6345        ///
6346        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
6347        #[wasm_bindgen(js_namespace = Math)]
6348        pub fn log10(x: f64) -> f64;
6349
6350        /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
6351        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
6352        #[wasm_bindgen(js_namespace = Math)]
6353        pub fn log1p(x: f64) -> f64;
6354
6355        /// The `Math.log2()` function returns the base 2 logarithm of a number.
6356        ///
6357        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
6358        #[wasm_bindgen(js_namespace = Math)]
6359        pub fn log2(x: f64) -> f64;
6360
6361        /// The `Math.max()` function returns the largest of two numbers.
6362        ///
6363        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
6364        #[wasm_bindgen(js_namespace = Math)]
6365        pub fn max(x: f64, y: f64) -> f64;
6366
6367        /// The static function `Math.min()` returns the lowest-valued number passed into it.
6368        ///
6369        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
6370        #[wasm_bindgen(js_namespace = Math)]
6371        pub fn min(x: f64, y: f64) -> f64;
6372
6373        /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
6374        ///
6375        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
6376        #[wasm_bindgen(js_namespace = Math)]
6377        pub fn pow(base: f64, exponent: f64) -> f64;
6378
6379        /// The `Math.random()` function returns a floating-point, pseudo-random number
6380        /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
6381        /// over that range — which you can then scale to your desired range.
6382        /// The implementation selects the initial seed to the random number generation algorithm;
6383        /// it cannot be chosen or reset by the user.
6384        ///
6385        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
6386        #[wasm_bindgen(js_namespace = Math)]
6387        pub fn random() -> f64;
6388
6389        /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
6390        ///
6391        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
6392        #[wasm_bindgen(js_namespace = Math)]
6393        pub fn round(x: f64) -> f64;
6394
6395        /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
6396        /// positive, negative or zero.
6397        ///
6398        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
6399        #[wasm_bindgen(js_namespace = Math)]
6400        pub fn sign(x: f64) -> f64;
6401
6402        /// The `Math.sin()` function returns the sine of a number.
6403        ///
6404        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
6405        #[wasm_bindgen(js_namespace = Math)]
6406        pub fn sin(x: f64) -> f64;
6407
6408        /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
6409        /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
6410        ///
6411        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
6412        #[wasm_bindgen(js_namespace = Math)]
6413        pub fn sinh(x: f64) -> f64;
6414
6415        /// The `Math.sqrt()` function returns the square root of a number, that is
6416        /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
6417        ///
6418        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
6419        #[wasm_bindgen(js_namespace = Math)]
6420        pub fn sqrt(x: f64) -> f64;
6421
6422        /// The `Math.tan()` function returns the tangent of a number.
6423        ///
6424        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
6425        #[wasm_bindgen(js_namespace = Math)]
6426        pub fn tan(x: f64) -> f64;
6427
6428        /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
6429        /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
6430        ///
6431        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
6432        #[wasm_bindgen(js_namespace = Math)]
6433        pub fn tanh(x: f64) -> f64;
6434
6435        /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
6436        /// digits.
6437        ///
6438        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
6439        #[wasm_bindgen(js_namespace = Math)]
6440        pub fn trunc(x: f64) -> f64;
6441
6442        /// The `Math.f16round()` function returns the nearest 16-bit half
6443        /// precision float representation of a number.
6444        ///
6445        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/f16round)
6446        #[wasm_bindgen(js_namespace = Math)]
6447        pub fn f16round(x: f64) -> f64;
6448
6449        /// The `Math.sumPrecise()` function takes an iterable of numbers and
6450        /// returns their sum, computed as if with infinite precision and
6451        /// rounded once at the end, so it is more accurate than a naive
6452        /// running sum.
6453        ///
6454        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sumPrecise)
6455        #[wasm_bindgen(js_namespace = Math, js_name = sumPrecise, catch)]
6456        pub fn sum_precise<I: Iterable>(values: &I) -> Result<f64, JsValue>;
6457
6458        /// The `Math.PI` property represents the ratio of the circumference of a circle to its diameter,
6459        /// approximately 3.14159.
6460        ///
6461        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI)
6462        #[wasm_bindgen(thread_local_v2, js_namespace = Math)]
6463        pub static PI: f64;
6464    }
6465}
6466
6467// Number.
6468#[wasm_bindgen]
6469extern "C" {
6470    #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
6471    #[derive(Clone, PartialEq)]
6472    pub type Number;
6473
6474    /// The `Number.isFinite()` method determines whether the passed value is a finite number.
6475    ///
6476    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
6477    #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
6478    pub fn is_finite(value: &JsValue) -> bool;
6479
6480    /// The `Number.isInteger()` method determines whether the passed value is an integer.
6481    ///
6482    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
6483    #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
6484    pub fn is_integer(value: &JsValue) -> bool;
6485
6486    /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
6487    /// It is a more robust version of the original, global isNaN().
6488    ///
6489    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
6490    #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
6491    pub fn is_nan(value: &JsValue) -> bool;
6492
6493    /// The `Number.isSafeInteger()` method determines whether the provided value is a number
6494    /// that is a safe integer.
6495    ///
6496    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
6497    #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
6498    pub fn is_safe_integer(value: &JsValue) -> bool;
6499
6500    /// The `Number` JavaScript object is a wrapper object allowing
6501    /// you to work with numerical values. A `Number` object is
6502    /// created using the `Number()` constructor.
6503    ///
6504    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
6505    #[cfg(not(js_sys_unstable_apis))]
6506    #[wasm_bindgen(constructor)]
6507    #[deprecated(note = "recommended to use `Number::from` instead")]
6508    #[allow(deprecated)]
6509    pub fn new(value: &JsValue) -> Number;
6510
6511    #[wasm_bindgen(constructor)]
6512    fn new_from_str(value: &str) -> Number;
6513
6514    /// The `Number.parseInt()` method parses a string argument and returns an
6515    /// integer of the specified radix or base.
6516    ///
6517    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
6518    #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
6519    pub fn parse_int(text: &str, radix: u8) -> f64;
6520
6521    /// The `Number.parseFloat()` method parses a string argument and returns a
6522    /// floating point number.
6523    ///
6524    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
6525    #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
6526    pub fn parse_float(text: &str) -> f64;
6527
6528    /// The `toLocaleString()` method returns a string with a language sensitive
6529    /// representation of this number.
6530    ///
6531    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
6532    #[cfg(not(js_sys_unstable_apis))]
6533    #[wasm_bindgen(method, js_name = toLocaleString)]
6534    pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
6535
6536    /// The `toLocaleString()` method returns a string with a language sensitive
6537    /// representation of this number.
6538    ///
6539    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
6540    #[cfg(js_sys_unstable_apis)]
6541    #[wasm_bindgen(method, js_name = toLocaleString)]
6542    pub fn to_locale_string(
6543        this: &Number,
6544        locales: &[JsString],
6545        options: &Intl::NumberFormatOptions,
6546    ) -> JsString;
6547
6548    /// The `toPrecision()` method returns a string representing the Number
6549    /// object to the specified precision.
6550    ///
6551    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
6552    #[cfg(not(js_sys_unstable_apis))]
6553    #[wasm_bindgen(catch, method, js_name = toPrecision)]
6554    pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
6555
6556    /// The `toPrecision()` method returns a string representing the Number
6557    /// object to the specified precision.
6558    ///
6559    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
6560    #[cfg(js_sys_unstable_apis)]
6561    #[wasm_bindgen(catch, method, js_name = toPrecision)]
6562    pub fn to_precision(this: &Number, precision: u8) -> Result<String, JsValue>;
6563
6564    /// The `toFixed()` method returns a string representing the Number
6565    /// object using fixed-point notation.
6566    ///
6567    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
6568    #[cfg(not(js_sys_unstable_apis))]
6569    #[wasm_bindgen(catch, method, js_name = toFixed)]
6570    pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
6571
6572    /// The `toFixed()` method returns a string representing the Number
6573    /// object using fixed-point notation.
6574    ///
6575    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
6576    #[cfg(js_sys_unstable_apis)]
6577    #[wasm_bindgen(catch, method, js_name = toFixed)]
6578    pub fn to_fixed(this: &Number, digits: u8) -> Result<String, JsValue>;
6579
6580    /// The `toExponential()` method returns a string representing the Number
6581    /// object in exponential notation.
6582    ///
6583    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
6584    #[cfg(not(js_sys_unstable_apis))]
6585    #[wasm_bindgen(catch, method, js_name = toExponential)]
6586    pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
6587
6588    /// The `toExponential()` method returns a string representing the Number
6589    /// object in exponential notation.
6590    ///
6591    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
6592    #[cfg(js_sys_unstable_apis)]
6593    #[wasm_bindgen(catch, method, js_name = toExponential)]
6594    pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<String, JsValue>;
6595
6596    /// The `toString()` method returns a string representing the
6597    /// specified Number object.
6598    ///
6599    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
6600    #[cfg(not(js_sys_unstable_apis))]
6601    #[deprecated(note = "Use `Number::to_string_with_radix` instead.")]
6602    #[allow(deprecated)]
6603    #[wasm_bindgen(catch, method, js_name = toString)]
6604    pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
6605
6606    /// The `toString()` method returns a string representing the
6607    /// specified Number object.
6608    ///
6609    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
6610    #[cfg(not(js_sys_unstable_apis))]
6611    #[wasm_bindgen(catch, method, js_name = toString)]
6612    pub fn to_string_with_radix(this: &Number, radix: u8) -> Result<JsString, JsValue>;
6613
6614    /// The `toString()` method returns a string representing the
6615    /// specified Number object.
6616    ///
6617    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
6618    #[cfg(js_sys_unstable_apis)]
6619    #[wasm_bindgen(catch, method, js_name = toString)]
6620    pub fn to_string_with_radix(this: &Number, radix: u8) -> Result<String, JsValue>;
6621
6622    /// The `valueOf()` method returns the wrapped primitive value of
6623    /// a Number object.
6624    ///
6625    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
6626    #[wasm_bindgen(method, js_name = valueOf)]
6627    pub fn value_of(this: &Number) -> f64;
6628}
6629
6630impl Number {
6631    /// The smallest interval between two representable numbers.
6632    ///
6633    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
6634    pub const EPSILON: f64 = f64::EPSILON;
6635    /// The maximum safe integer in JavaScript (2^53 - 1).
6636    ///
6637    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
6638    pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
6639    /// The largest positive representable number.
6640    ///
6641    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
6642    pub const MAX_VALUE: f64 = f64::MAX;
6643    /// The minimum safe integer in JavaScript (-(2^53 - 1)).
6644    ///
6645    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
6646    pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
6647    /// The smallest positive representable number—that is, the positive number closest to zero
6648    /// (without actually being zero).
6649    ///
6650    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
6651    // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number.
6652    pub const MIN_VALUE: f64 = 5E-324;
6653    /// Special "Not a Number" value.
6654    ///
6655    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
6656    pub const NAN: f64 = f64::NAN;
6657    /// Special value representing negative infinity. Returned on overflow.
6658    ///
6659    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
6660    pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
6661    /// Special value representing infinity. Returned on overflow.
6662    ///
6663    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
6664    pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
6665
6666    /// Applies the binary `**` JS operator on the two `Number`s.
6667    ///
6668    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
6669    #[inline]
6670    pub fn pow(&self, rhs: &Self) -> Self {
6671        JsValue::as_ref(self)
6672            .pow(JsValue::as_ref(rhs))
6673            .unchecked_into()
6674    }
6675
6676    /// Applies the binary `>>>` JS operator on the two `Number`s.
6677    ///
6678    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
6679    #[inline]
6680    pub fn unsigned_shr(&self, rhs: &Self) -> Self {
6681        Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs)))
6682    }
6683}
6684
6685macro_rules! number_from {
6686    ($($x:ident)*) => ($(
6687        impl From<$x> for Number {
6688            #[inline]
6689            fn from(x: $x) -> Number {
6690                Number::unchecked_from_js(JsValue::from(x))
6691            }
6692        }
6693
6694        impl PartialEq<$x> for Number {
6695            #[inline]
6696            fn eq(&self, other: &$x) -> bool {
6697                self.value_of() == f64::from(*other)
6698            }
6699        }
6700
6701        impl UpcastFrom<$x> for Number {}
6702    )*)
6703}
6704number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
6705
6706// The only guarantee for a JS number
6707impl UpcastFrom<Number> for f64 {}
6708
6709/// The error type returned when a checked integral type conversion fails.
6710#[derive(Debug, Copy, Clone, PartialEq, Eq)]
6711pub struct TryFromIntError(());
6712
6713impl fmt::Display for TryFromIntError {
6714    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
6715        fmt.write_str("out of range integral type conversion attempted")
6716    }
6717}
6718
6719#[cfg(feature = "std")]
6720impl std::error::Error for TryFromIntError {}
6721
6722macro_rules! number_try_from {
6723    ($($x:ident)*) => ($(
6724        impl TryFrom<$x> for Number {
6725            type Error = TryFromIntError;
6726
6727            #[inline]
6728            fn try_from(x: $x) -> Result<Number, Self::Error> {
6729                let x_f64 = x as f64;
6730                if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) {
6731                    Ok(Number::from(x_f64))
6732                } else {
6733                    Err(TryFromIntError(()))
6734                }
6735            }
6736        }
6737    )*)
6738}
6739number_try_from!(i64 u64 i128 u128);
6740
6741impl From<&Number> for f64 {
6742    #[inline]
6743    fn from(n: &Number) -> f64 {
6744        n.value_of()
6745    }
6746}
6747
6748impl From<Number> for f64 {
6749    #[inline]
6750    fn from(n: Number) -> f64 {
6751        <f64 as From<&'_ Number>>::from(&n)
6752    }
6753}
6754
6755impl fmt::Debug for Number {
6756    #[inline]
6757    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6758        fmt::Debug::fmt(&self.value_of(), f)
6759    }
6760}
6761
6762impl fmt::Display for Number {
6763    #[inline]
6764    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6765        fmt::Display::fmt(&self.value_of(), f)
6766    }
6767}
6768
6769impl Default for Number {
6770    fn default() -> Self {
6771        Self::from(f64::default())
6772    }
6773}
6774
6775impl PartialEq<BigInt> for Number {
6776    #[inline]
6777    fn eq(&self, other: &BigInt) -> bool {
6778        JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
6779    }
6780}
6781
6782impl Not for &Number {
6783    type Output = BigInt;
6784
6785    #[inline]
6786    fn not(self) -> Self::Output {
6787        JsValue::as_ref(self).bit_not().unchecked_into()
6788    }
6789}
6790
6791forward_deref_unop!(impl Not, not for Number);
6792forward_js_unop!(impl Neg, neg for Number);
6793forward_js_binop!(impl BitAnd, bitand for Number);
6794forward_js_binop!(impl BitOr, bitor for Number);
6795forward_js_binop!(impl BitXor, bitxor for Number);
6796forward_js_binop!(impl Shl, shl for Number);
6797forward_js_binop!(impl Shr, shr for Number);
6798forward_js_binop!(impl Add, add for Number);
6799forward_js_binop!(impl Sub, sub for Number);
6800forward_js_binop!(impl Div, div for Number);
6801forward_js_binop!(impl Mul, mul for Number);
6802forward_js_binop!(impl Rem, rem for Number);
6803
6804sum_product!(Number);
6805
6806impl PartialOrd for Number {
6807    #[inline]
6808    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
6809        if Number::is_nan(self) || Number::is_nan(other) {
6810            None
6811        } else if self == other {
6812            Some(Ordering::Equal)
6813        } else if self.lt(other) {
6814            Some(Ordering::Less)
6815        } else {
6816            Some(Ordering::Greater)
6817        }
6818    }
6819
6820    #[inline]
6821    fn lt(&self, other: &Self) -> bool {
6822        JsValue::as_ref(self).lt(JsValue::as_ref(other))
6823    }
6824
6825    #[inline]
6826    fn le(&self, other: &Self) -> bool {
6827        JsValue::as_ref(self).le(JsValue::as_ref(other))
6828    }
6829
6830    #[inline]
6831    fn ge(&self, other: &Self) -> bool {
6832        JsValue::as_ref(self).ge(JsValue::as_ref(other))
6833    }
6834
6835    #[inline]
6836    fn gt(&self, other: &Self) -> bool {
6837        JsValue::as_ref(self).gt(JsValue::as_ref(other))
6838    }
6839}
6840
6841#[cfg(not(js_sys_unstable_apis))]
6842impl FromStr for Number {
6843    type Err = Infallible;
6844
6845    #[allow(deprecated)]
6846    #[inline]
6847    fn from_str(s: &str) -> Result<Self, Self::Err> {
6848        Ok(Number::new_from_str(s))
6849    }
6850}
6851
6852// Date.
6853#[wasm_bindgen]
6854extern "C" {
6855    #[wasm_bindgen(extends = Object, typescript_type = "Date")]
6856    #[derive(Clone, Debug, PartialEq, Eq)]
6857    pub type Date;
6858
6859    /// The `getDate()` method returns the day of the month for the
6860    /// specified date according to local time.
6861    ///
6862    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
6863    #[wasm_bindgen(method, js_name = getDate)]
6864    pub fn get_date(this: &Date) -> u32;
6865
6866    /// The `getDay()` method returns the day of the week for the specified date according to local time,
6867    /// where 0 represents Sunday. For the day of the month see getDate().
6868    ///
6869    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
6870    #[wasm_bindgen(method, js_name = getDay)]
6871    pub fn get_day(this: &Date) -> u32;
6872
6873    /// The `getFullYear()` method returns the year of the specified date according to local time.
6874    ///
6875    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
6876    #[wasm_bindgen(method, js_name = getFullYear)]
6877    pub fn get_full_year(this: &Date) -> u32;
6878
6879    /// The `getHours()` method returns the hour for the specified date, according to local time.
6880    ///
6881    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
6882    #[wasm_bindgen(method, js_name = getHours)]
6883    pub fn get_hours(this: &Date) -> u32;
6884
6885    /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
6886    ///
6887    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
6888    #[wasm_bindgen(method, js_name = getMilliseconds)]
6889    pub fn get_milliseconds(this: &Date) -> u32;
6890
6891    /// The `getMinutes()` method returns the minutes in the specified date according to local time.
6892    ///
6893    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
6894    #[wasm_bindgen(method, js_name = getMinutes)]
6895    pub fn get_minutes(this: &Date) -> u32;
6896
6897    /// The `getMonth()` method returns the month in the specified date according to local time,
6898    /// as a zero-based value (where zero indicates the first month of the year).
6899    ///
6900    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
6901    #[wasm_bindgen(method, js_name = getMonth)]
6902    pub fn get_month(this: &Date) -> u32;
6903
6904    /// The `getSeconds()` method returns the seconds in the specified date according to local time.
6905    ///
6906    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
6907    #[wasm_bindgen(method, js_name = getSeconds)]
6908    pub fn get_seconds(this: &Date) -> u32;
6909
6910    /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
6911    /// according to universal time.
6912    ///
6913    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
6914    #[wasm_bindgen(method, js_name = getTime)]
6915    pub fn get_time(this: &Date) -> f64;
6916
6917    /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
6918    /// from current locale (host system settings) to UTC.
6919    ///
6920    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
6921    #[wasm_bindgen(method, js_name = getTimezoneOffset)]
6922    pub fn get_timezone_offset(this: &Date) -> f64;
6923
6924    /// The `getUTCDate()` method returns the day (date) of the month in the specified date
6925    /// according to universal time.
6926    ///
6927    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
6928    #[wasm_bindgen(method, js_name = getUTCDate)]
6929    pub fn get_utc_date(this: &Date) -> u32;
6930
6931    /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
6932    /// where 0 represents Sunday.
6933    ///
6934    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
6935    #[wasm_bindgen(method, js_name = getUTCDay)]
6936    pub fn get_utc_day(this: &Date) -> u32;
6937
6938    /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
6939    ///
6940    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
6941    #[wasm_bindgen(method, js_name = getUTCFullYear)]
6942    pub fn get_utc_full_year(this: &Date) -> u32;
6943
6944    /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
6945    ///
6946    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
6947    #[wasm_bindgen(method, js_name = getUTCHours)]
6948    pub fn get_utc_hours(this: &Date) -> u32;
6949
6950    /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date
6951    /// according to universal time.
6952    ///
6953    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds)
6954    #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
6955    pub fn get_utc_milliseconds(this: &Date) -> u32;
6956
6957    /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
6958    ///
6959    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
6960    #[wasm_bindgen(method, js_name = getUTCMinutes)]
6961    pub fn get_utc_minutes(this: &Date) -> u32;
6962
6963    /// The `getUTCMonth()` returns the month of the specified date according to universal time,
6964    /// as a zero-based value (where zero indicates the first month of the year).
6965    ///
6966    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
6967    #[wasm_bindgen(method, js_name = getUTCMonth)]
6968    pub fn get_utc_month(this: &Date) -> u32;
6969
6970    /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time.
6971    ///
6972    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds)
6973    #[wasm_bindgen(method, js_name = getUTCSeconds)]
6974    pub fn get_utc_seconds(this: &Date) -> u32;
6975
6976    /// Creates a JavaScript `Date` instance that represents
6977    /// a single moment in time. `Date` objects are based on a time value that is
6978    /// the number of milliseconds since 1 January 1970 UTC.
6979    ///
6980    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6981    #[wasm_bindgen(constructor)]
6982    pub fn new(init: &JsValue) -> Date;
6983
6984    /// Creates a JavaScript `Date` from a time value in milliseconds since
6985    /// 1 January 1970 UTC, or from a date string: `Date::new_with_value(0.0)`,
6986    /// `Date::new_with_value("2020-01-01")`.
6987    ///
6988    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date)
6989    #[cfg(js_sys_unstable_apis)]
6990    #[wasm_bindgen(constructor, js_class = "Date", experimental_generic_mono)]
6991    pub fn new_with_value(value: impl JsNumberOrStringLike) -> Date;
6992
6993    /// Creates a JavaScript `Date` instance that represents the current moment in
6994    /// time.
6995    ///
6996    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6997    #[wasm_bindgen(constructor)]
6998    pub fn new_0() -> Date;
6999
7000    /// Creates a JavaScript `Date` instance that represents
7001    /// a single moment in time. `Date` objects are based on a time value that is
7002    /// the number of milliseconds since 1 January 1970 UTC.
7003    ///
7004    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
7005    #[wasm_bindgen(constructor)]
7006    pub fn new_with_year_month(year: u32, month: i32) -> Date;
7007
7008    /// Creates a JavaScript `Date` instance that represents
7009    /// a single moment in time. `Date` objects are based on a time value that is
7010    /// the number of milliseconds since 1 January 1970 UTC.
7011    ///
7012    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
7013    #[wasm_bindgen(constructor)]
7014    pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
7015
7016    /// Creates a JavaScript `Date` instance that represents
7017    /// a single moment in time. `Date` objects are based on a time value that is
7018    /// the number of milliseconds since 1 January 1970 UTC.
7019    ///
7020    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
7021    #[wasm_bindgen(constructor)]
7022    pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
7023
7024    /// Creates a JavaScript `Date` instance that represents
7025    /// a single moment in time. `Date` objects are based on a time value that is
7026    /// the number of milliseconds since 1 January 1970 UTC.
7027    ///
7028    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
7029    #[wasm_bindgen(constructor)]
7030    pub fn new_with_year_month_day_hr_min(
7031        year: u32,
7032        month: i32,
7033        day: i32,
7034        hr: i32,
7035        min: i32,
7036    ) -> Date;
7037
7038    /// Creates a JavaScript `Date` instance that represents
7039    /// a single moment in time. `Date` objects are based on a time value that is
7040    /// the number of milliseconds since 1 January 1970 UTC.
7041    ///
7042    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
7043    #[wasm_bindgen(constructor)]
7044    pub fn new_with_year_month_day_hr_min_sec(
7045        year: u32,
7046        month: i32,
7047        day: i32,
7048        hr: i32,
7049        min: i32,
7050        sec: i32,
7051    ) -> Date;
7052
7053    /// Creates a JavaScript `Date` instance that represents
7054    /// a single moment in time. `Date` objects are based on a time value that is
7055    /// the number of milliseconds since 1 January 1970 UTC.
7056    ///
7057    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
7058    #[wasm_bindgen(constructor)]
7059    pub fn new_with_year_month_day_hr_min_sec_milli(
7060        year: u32,
7061        month: i32,
7062        day: i32,
7063        hr: i32,
7064        min: i32,
7065        sec: i32,
7066        milli: i32,
7067    ) -> Date;
7068
7069    /// The `Date.now()` method returns the number of milliseconds
7070    /// elapsed since January 1, 1970 00:00:00 UTC.
7071    ///
7072    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
7073    #[wasm_bindgen(static_method_of = Date)]
7074    pub fn now() -> f64;
7075
7076    /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
7077    /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
7078    /// contains illegal date values (e.g. 2015-02-31).
7079    ///
7080    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
7081    #[wasm_bindgen(static_method_of = Date)]
7082    pub fn parse(date: &str) -> f64;
7083
7084    /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
7085    ///
7086    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
7087    #[wasm_bindgen(method, js_name = setDate)]
7088    pub fn set_date(this: &Date, day: u32) -> f64;
7089
7090    /// The `setFullYear()` method sets the full year for a specified date according to local time.
7091    /// Returns new timestamp.
7092    ///
7093    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
7094    #[wasm_bindgen(method, js_name = setFullYear)]
7095    pub fn set_full_year(this: &Date, year: u32) -> f64;
7096
7097    /// The `setFullYear()` method sets the full year for a specified date according to local time.
7098    /// Returns new timestamp.
7099    ///
7100    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
7101    #[wasm_bindgen(method, js_name = setFullYear)]
7102    pub fn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
7103
7104    /// The `setFullYear()` method sets the full year for a specified date according to local time.
7105    /// Returns new timestamp.
7106    ///
7107    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
7108    #[wasm_bindgen(method, js_name = setFullYear)]
7109    pub fn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
7110
7111    /// The `setHours()` method sets the hours for a specified date according to local time,
7112    /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
7113    /// by the updated Date instance.
7114    ///
7115    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
7116    #[wasm_bindgen(method, js_name = setHours)]
7117    pub fn set_hours(this: &Date, hours: u32) -> f64;
7118
7119    /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
7120    ///
7121    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
7122    #[wasm_bindgen(method, js_name = setMilliseconds)]
7123    pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
7124
7125    /// The `setMinutes()` method sets the minutes for a specified date according to local time.
7126    ///
7127    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
7128    #[wasm_bindgen(method, js_name = setMinutes)]
7129    pub fn set_minutes(this: &Date, minutes: u32) -> f64;
7130
7131    /// The `setMonth()` method sets the month for a specified date according to the currently set year.
7132    ///
7133    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
7134    #[wasm_bindgen(method, js_name = setMonth)]
7135    pub fn set_month(this: &Date, month: u32) -> f64;
7136
7137    /// The `setSeconds()` method sets the seconds for a specified date according to local time.
7138    ///
7139    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
7140    #[wasm_bindgen(method, js_name = setSeconds)]
7141    pub fn set_seconds(this: &Date, seconds: u32) -> f64;
7142
7143    /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
7144    /// since January 1, 1970, 00:00:00 UTC.
7145    ///
7146    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
7147    #[wasm_bindgen(method, js_name = setTime)]
7148    pub fn set_time(this: &Date, time: f64) -> f64;
7149
7150    /// The `setUTCDate()` method sets the day of the month for a specified date
7151    /// according to universal time.
7152    ///
7153    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
7154    #[wasm_bindgen(method, js_name = setUTCDate)]
7155    pub fn set_utc_date(this: &Date, day: u32) -> f64;
7156
7157    /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
7158    ///
7159    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
7160    #[wasm_bindgen(method, js_name = setUTCFullYear)]
7161    pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
7162
7163    /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
7164    ///
7165    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
7166    #[wasm_bindgen(method, js_name = setUTCFullYear)]
7167    pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
7168
7169    /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
7170    ///
7171    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
7172    #[wasm_bindgen(method, js_name = setUTCFullYear)]
7173    pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
7174
7175    /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
7176    /// and returns the number of milliseconds since  January 1, 1970 00:00:00 UTC until the time
7177    /// represented by the updated Date instance.
7178    ///
7179    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
7180    #[wasm_bindgen(method, js_name = setUTCHours)]
7181    pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
7182
7183    /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
7184    /// according to universal time.
7185    ///
7186    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
7187    #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
7188    pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
7189
7190    /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
7191    ///
7192    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
7193    #[wasm_bindgen(method, js_name = setUTCMinutes)]
7194    pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
7195
7196    /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
7197    ///
7198    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
7199    #[wasm_bindgen(method, js_name = setUTCMonth)]
7200    pub fn set_utc_month(this: &Date, month: u32) -> f64;
7201
7202    /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
7203    ///
7204    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
7205    #[wasm_bindgen(method, js_name = setUTCSeconds)]
7206    pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
7207
7208    /// The `toDateString()` method returns the date portion of a Date object
7209    /// in human readable form in American English.
7210    ///
7211    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
7212    #[cfg(not(js_sys_unstable_apis))]
7213    #[wasm_bindgen(method, js_name = toDateString)]
7214    pub fn to_date_string(this: &Date) -> JsString;
7215
7216    /// The `toDateString()` method returns the date portion of a Date object
7217    /// in human readable form in American English.
7218    ///
7219    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
7220    #[cfg(js_sys_unstable_apis)]
7221    #[wasm_bindgen(method, js_name = toDateString)]
7222    pub fn to_date_string(this: &Date) -> String;
7223
7224    /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
7225    /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
7226    /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
7227    /// as denoted by the suffix "Z"
7228    ///
7229    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
7230    #[cfg(not(js_sys_unstable_apis))]
7231    #[wasm_bindgen(method, js_name = toISOString)]
7232    pub fn to_iso_string(this: &Date) -> JsString;
7233
7234    /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
7235    /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
7236    /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
7237    /// as denoted by the suffix "Z"
7238    ///
7239    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
7240    #[cfg(js_sys_unstable_apis)]
7241    #[wasm_bindgen(method, js_name = toISOString)]
7242    pub fn to_iso_string(this: &Date) -> String;
7243
7244    /// The `toJSON()` method returns a string representation of the Date object.
7245    ///
7246    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
7247    #[cfg(not(js_sys_unstable_apis))]
7248    #[wasm_bindgen(method, js_name = toJSON)]
7249    pub fn to_json(this: &Date) -> JsString;
7250
7251    /// The `toJSON()` method returns a string representation of the Date object,
7252    /// or `None` for an invalid date, for which JS returns `null`.
7253    ///
7254    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
7255    #[cfg(js_sys_unstable_apis)]
7256    #[wasm_bindgen(method, js_name = toJSON)]
7257    pub fn to_json(this: &Date) -> Option<String>;
7258
7259    /// The `toLocaleDateString()` method returns a string with a language sensitive
7260    /// representation of the date portion of this date. The new locales and options
7261    /// arguments let applications specify the language whose formatting conventions
7262    /// should be used and allow to customize the behavior of the function.
7263    /// In older implementations, which ignore the locales and options arguments,
7264    /// the locale used and the form of the string
7265    /// returned are entirely implementation dependent.
7266    ///
7267    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
7268    #[cfg(not(js_sys_unstable_apis))]
7269    #[wasm_bindgen(method, js_name = toLocaleDateString)]
7270    pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
7271
7272    /// The `toLocaleDateString()` method returns a string with a language sensitive
7273    /// representation of the date portion of this date.
7274    ///
7275    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
7276    #[cfg(js_sys_unstable_apis)]
7277    #[wasm_bindgen(method, js_name = toLocaleDateString)]
7278    pub fn to_locale_date_string(
7279        this: &Date,
7280        locales: &[JsString],
7281        options: &Intl::DateTimeFormatOptions,
7282    ) -> JsString;
7283
7284    /// The `toLocaleString()` method returns a string with a language sensitive
7285    /// representation of this date. The new locales and options arguments
7286    /// let applications specify the language whose formatting conventions
7287    /// should be used and customize the behavior of the function.
7288    /// In older implementations, which ignore the locales
7289    /// and options arguments, the locale used and the form of the string
7290    /// returned are entirely implementation dependent.
7291    ///
7292    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
7293    #[cfg(not(js_sys_unstable_apis))]
7294    #[wasm_bindgen(method, js_name = toLocaleString)]
7295    pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
7296
7297    /// The `toLocaleString()` method returns a string with a language sensitive
7298    /// representation of this date.
7299    ///
7300    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
7301    #[cfg(js_sys_unstable_apis)]
7302    #[wasm_bindgen(method, js_name = toLocaleString)]
7303    pub fn to_locale_string(
7304        this: &Date,
7305        locales: &[JsString],
7306        options: &Intl::DateTimeFormatOptions,
7307    ) -> JsString;
7308
7309    /// The `toLocaleTimeString()` method returns a string with a language sensitive
7310    /// representation of the time portion of this date. The new locales and options
7311    /// arguments let applications specify the language whose formatting conventions should be
7312    /// used and customize the behavior of the function. In older implementations, which ignore
7313    /// the locales and options arguments, the locale used and the form of the string
7314    /// returned are entirely implementation dependent.
7315    ///
7316    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
7317    #[cfg(not(js_sys_unstable_apis))]
7318    #[wasm_bindgen(method, js_name = toLocaleTimeString)]
7319    pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
7320
7321    /// The `toLocaleTimeString()` method returns a string with a language sensitive
7322    /// representation of the time portion of this date.
7323    ///
7324    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
7325    #[cfg(js_sys_unstable_apis)]
7326    #[wasm_bindgen(method, js_name = toLocaleTimeString)]
7327    pub fn to_locale_time_string(
7328        this: &Date,
7329        locales: &[JsString],
7330        options: &Intl::DateTimeFormatOptions,
7331    ) -> JsString;
7332
7333    #[cfg(not(js_sys_unstable_apis))]
7334    #[wasm_bindgen(method, js_name = toLocaleTimeString)]
7335    pub fn to_locale_time_string_with_options(
7336        this: &Date,
7337        locale: &str,
7338        options: &JsValue,
7339    ) -> JsString;
7340
7341    /// The `toString()` method returns a string representing
7342    /// the specified Date object.
7343    ///
7344    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
7345    #[cfg(not(js_sys_unstable_apis))]
7346    #[wasm_bindgen(method, js_name = toString)]
7347    pub fn to_string(this: &Date) -> JsString;
7348
7349    /// The `toString()` method returns a string representing the object.
7350    #[cfg(js_sys_unstable_apis)]
7351    #[wasm_bindgen(method, js_name = toString)]
7352    pub fn to_string(this: &Date) -> String;
7353
7354    /// The `toTimeString()` method returns the time portion of a Date object in human
7355    /// readable form in American English.
7356    ///
7357    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
7358    #[cfg(not(js_sys_unstable_apis))]
7359    #[wasm_bindgen(method, js_name = toTimeString)]
7360    pub fn to_time_string(this: &Date) -> JsString;
7361
7362    /// The `toTimeString()` method returns the time portion of a Date object in human
7363    /// readable form in American English.
7364    ///
7365    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
7366    #[cfg(js_sys_unstable_apis)]
7367    #[wasm_bindgen(method, js_name = toTimeString)]
7368    pub fn to_time_string(this: &Date) -> String;
7369
7370    /// The `toUTCString()` method converts a date to a string,
7371    /// using the UTC time zone.
7372    ///
7373    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
7374    #[cfg(not(js_sys_unstable_apis))]
7375    #[wasm_bindgen(method, js_name = toUTCString)]
7376    pub fn to_utc_string(this: &Date) -> JsString;
7377
7378    /// The `toUTCString()` method converts a date to a string,
7379    /// using the UTC time zone.
7380    ///
7381    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
7382    #[cfg(js_sys_unstable_apis)]
7383    #[wasm_bindgen(method, js_name = toUTCString)]
7384    pub fn to_utc_string(this: &Date) -> String;
7385
7386    /// The `Date.UTC()` method accepts the same parameters as the
7387    /// longest form of the constructor, and returns the number of
7388    /// milliseconds in a `Date` object since January 1, 1970,
7389    /// 00:00:00, universal time.
7390    ///
7391    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
7392    #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
7393    pub fn utc(year: f64, month: f64) -> f64;
7394
7395    /// The `valueOf()` method  returns the primitive value of
7396    /// a Date object.
7397    ///
7398    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
7399    #[wasm_bindgen(method, js_name = valueOf)]
7400    pub fn value_of(this: &Date) -> f64;
7401
7402    /// The `toTemporalInstant()` method converts this `Date` to a
7403    /// `Temporal.Instant` representing the same moment in time.
7404    ///
7405    /// # Errors
7406    /// Throws a `RangeError` if this is an invalid date.
7407    ///
7408    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTemporalInstant)
7409    #[cfg(feature = "temporal")]
7410    #[wasm_bindgen(method, js_name = toTemporalInstant, catch)]
7411    pub fn to_temporal_instant(this: &Date) -> Result<Temporal::Instant, RangeError>;
7412}
7413
7414// Property Descriptor.
7415#[wasm_bindgen]
7416extern "C" {
7417    #[wasm_bindgen(extends = Object)]
7418    #[derive(Clone, Debug)]
7419    pub type PropertyDescriptor<T = JsValue>;
7420
7421    #[wasm_bindgen(method, getter = writable)]
7422    pub fn get_writable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
7423
7424    #[wasm_bindgen(method, setter = writable)]
7425    pub fn set_writable<T>(this: &PropertyDescriptor<T>, writable: bool);
7426
7427    #[wasm_bindgen(method, getter = enumerable)]
7428    pub fn get_enumerable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
7429
7430    #[wasm_bindgen(method, setter = enumerable)]
7431    pub fn set_enumerable<T>(this: &PropertyDescriptor<T>, enumerable: bool);
7432
7433    #[wasm_bindgen(method, getter = configurable)]
7434    pub fn get_configurable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
7435
7436    #[wasm_bindgen(method, setter = configurable)]
7437    pub fn set_configurable<T>(this: &PropertyDescriptor<T>, configurable: bool);
7438
7439    #[wasm_bindgen(method, getter = get)]
7440    pub fn get_get<T>(this: &PropertyDescriptor<T>) -> Option<Function<fn() -> T>>;
7441
7442    #[wasm_bindgen(method, setter = get)]
7443    pub fn set_get<T>(this: &PropertyDescriptor<T>, get: Function<fn() -> T>);
7444
7445    #[wasm_bindgen(method, getter = set)]
7446    pub fn get_set<T>(this: &PropertyDescriptor<T>) -> Option<Function<fn(T) -> JsValue>>;
7447
7448    #[wasm_bindgen(method, setter = set)]
7449    pub fn set_set<T>(this: &PropertyDescriptor<T>, set: Function<fn(T) -> JsValue>);
7450
7451    #[wasm_bindgen(method, getter = value)]
7452    pub fn get_value<T>(this: &PropertyDescriptor<T>) -> Option<T>;
7453
7454    #[wasm_bindgen(method, setter = value)]
7455    pub fn set_value<T>(this: &PropertyDescriptor<T>, value: &T);
7456}
7457
7458impl PropertyDescriptor {
7459    #[cfg(not(js_sys_unstable_apis))]
7460    pub fn new<T>() -> PropertyDescriptor<T> {
7461        JsCast::unchecked_into(Object::new())
7462    }
7463
7464    #[cfg(js_sys_unstable_apis)]
7465    pub fn new<T>() -> PropertyDescriptor<T> {
7466        JsCast::unchecked_into(Object::<JsValue>::new())
7467    }
7468
7469    #[cfg(not(js_sys_unstable_apis))]
7470    pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
7471        let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::new());
7472        desc.set_value(value);
7473        desc
7474    }
7475
7476    #[cfg(js_sys_unstable_apis)]
7477    pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
7478        let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::<JsValue>::new());
7479        desc.set_value(value);
7480        desc
7481    }
7482}
7483
7484impl Default for PropertyDescriptor {
7485    fn default() -> Self {
7486        PropertyDescriptor::new()
7487    }
7488}
7489
7490// Object.
7491#[wasm_bindgen]
7492extern "C" {
7493    #[wasm_bindgen(typescript_type = "object")]
7494    #[derive(Clone, Debug)]
7495    pub type Object<T = JsValue>;
7496
7497    // Next major: deprecate
7498    /// The `Object.assign()` method is used to copy the values of all enumerable
7499    /// own properties from one or more source objects to a target object. It
7500    /// will return the target object.
7501    ///
7502    /// **Note:** Consider using [`Object::try_assign`] to support error handling.
7503    ///
7504    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
7505    #[wasm_bindgen(static_method_of = Object)]
7506    pub fn assign<T>(target: &Object<T>, source: &Object<T>) -> Object<T>;
7507
7508    // Next major: deprecate
7509    /// The `Object.assign()` method is used to copy the values of all enumerable
7510    /// own properties from one or more source objects to a target object. It
7511    /// will return the target object.
7512    ///
7513    /// **Note:** Consider using [`Object::try_assign`] to support error handling.
7514    ///
7515    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
7516    #[wasm_bindgen(static_method_of = Object, js_name = assign, catch)]
7517    pub fn try_assign<T>(target: &Object<T>, source: &Object<T>) -> Result<Object<T>, JsValue>;
7518
7519    /// The `Object.assign()` method is used to copy the values of all enumerable
7520    /// own properties from one or more source objects to a target object. It
7521    /// will return the target object.
7522    ///
7523    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
7524    #[cfg(not(js_sys_unstable_apis))]
7525    #[wasm_bindgen(static_method_of = Object, js_name = assign)]
7526    #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
7527    #[allow(deprecated)]
7528    pub fn assign2<T>(target: &Object<T>, source1: &Object<T>, source2: &Object<T>) -> Object<T>;
7529
7530    /// The `Object.assign()` method is used to copy the values of all enumerable
7531    /// own properties from one or more source objects to a target object. It
7532    /// will return the target object.
7533    ///
7534    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
7535    #[cfg(not(js_sys_unstable_apis))]
7536    #[wasm_bindgen(static_method_of = Object, js_name = assign)]
7537    #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
7538    #[allow(deprecated)]
7539    pub fn assign3<T>(
7540        target: &Object<T>,
7541        source1: &Object<T>,
7542        source2: &Object<T>,
7543        source3: &Object<T>,
7544    ) -> Object<T>;
7545
7546    /// The `Object.assign()` method is used to copy the values of all enumerable
7547    /// own properties from one or more source objects to a target object. It
7548    /// will return the target object.
7549    ///
7550    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
7551    #[wasm_bindgen(static_method_of = Object, js_name = assign, catch, variadic)]
7552    pub fn assign_many<T>(target: &Object<T>, sources: &[Object<T>]) -> Result<Object<T>, JsValue>;
7553
7554    /// The constructor property returns a reference to the `Object` constructor
7555    /// function that created the instance object.
7556    ///
7557    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
7558    #[wasm_bindgen(method, getter)]
7559    pub fn constructor<T>(this: &Object<T>) -> Function;
7560
7561    // Next major: `prototype: Nullable<&Object<T>>`
7562    /// The `Object.create()` method creates a new object, using an existing
7563    /// object to provide the newly created object's prototype.
7564    ///
7565    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
7566    #[wasm_bindgen(static_method_of = Object)]
7567    pub fn create<T>(prototype: &Object<T>) -> Object<T>;
7568
7569    /// The static method `Object.defineProperty()` defines a new
7570    /// property directly on an object, or modifies an existing
7571    /// property on an object, and returns the object.
7572    ///
7573    /// **Note:** Consider using [`Object::define_property_str`] to support typing and error handling.
7574    ///
7575    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
7576    #[cfg(not(js_sys_unstable_apis))]
7577    #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
7578    pub fn define_property<T>(obj: &Object<T>, prop: &JsValue, descriptor: &Object) -> Object<T>;
7579
7580    // Stable `_key`-suffixed variants of the generic `K: PropertyKey` property
7581    // operations can be added if `PropertyKey` stabilizes first.
7582    /// The static method `Object.defineProperty()` defines a new
7583    /// property directly on an object, or modifies an existing
7584    /// property on an object, and returns the object.
7585    ///
7586    /// The property key may be any JavaScript property-key representation
7587    /// (string, number, or symbol).
7588    ///
7589    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
7590    #[cfg(js_sys_unstable_apis)]
7591    #[wasm_bindgen(
7592        static_method_of = Object,
7593        js_name = defineProperty,
7594        catch,
7595        experimental_generic_mono
7596    )]
7597    pub fn define_property<T, K: PropertyKey>(
7598        obj: &Object<T>,
7599        prop: K,
7600        descriptor: &PropertyDescriptor<T>,
7601    ) -> Result<Object<T>, JsValue>;
7602
7603    // Next major: deprecate
7604    /// The static method `Object.defineProperty()` defines a new
7605    /// property directly on an object, or modifies an existing
7606    /// property on an object, and returns the object.
7607    ///
7608    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
7609    #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
7610    pub fn define_property_str<T>(
7611        obj: &Object<T>,
7612        prop: &JsString,
7613        descriptor: &PropertyDescriptor<T>,
7614    ) -> Result<Object<T>, JsValue>;
7615
7616    /// The static method `Object.defineProperty()` defines a new
7617    /// property directly on an object, or modifies an existing
7618    /// property on an object, and returns the object.
7619    ///
7620    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
7621    #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
7622    pub fn define_property_symbol<T>(
7623        obj: &Object<T>,
7624        prop: &Symbol,
7625        descriptor: &PropertyDescriptor<JsValue>,
7626    ) -> Result<Object<T>, JsValue>;
7627
7628    /// The `Object.defineProperties()` method defines new or modifies
7629    /// existing properties directly on an object, returning the
7630    /// object.
7631    ///
7632    /// **Note:** Consider using [`Object::try_define_properties`] to support typing and error handling.
7633    ///
7634    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
7635    #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
7636    pub fn define_properties<T>(obj: &Object<T>, props: &Object) -> Object<T>;
7637
7638    /// The `Object.defineProperties()` method defines new or modifies
7639    /// existing properties directly on an object, returning the
7640    /// object.
7641    ///
7642    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
7643    #[cfg(js_sys_unstable_apis)]
7644    #[wasm_bindgen(static_method_of = Object, js_name = defineProperties, catch)]
7645    pub fn try_define_properties<T>(
7646        obj: &Object<T>,
7647        props: &Object<PropertyDescriptor<T>>,
7648    ) -> Result<Object<T>, JsValue>;
7649
7650    /// The `Object.entries()` method returns an array of a given
7651    /// object's own enumerable property [key, value] pairs, in the
7652    /// same order as that provided by a for...in loop (the difference
7653    /// being that a for-in loop enumerates properties in the
7654    /// prototype chain as well).
7655    ///
7656    /// **Note:** Consider using [`Object::entries_typed`] to support typing and error handling.
7657    ///
7658    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7659    #[cfg(not(js_sys_unstable_apis))]
7660    #[wasm_bindgen(static_method_of = Object)]
7661    pub fn entries(object: &Object) -> Array;
7662
7663    /// The `Object.entries()` method returns an array of a given
7664    /// object's own enumerable property [key, value] pairs, in the
7665    /// same order as that provided by a for...in loop (the difference
7666    /// being that a for-in loop enumerates properties in the
7667    /// prototype chain as well).
7668    ///
7669    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7670    #[cfg(js_sys_unstable_apis)]
7671    #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
7672    pub fn entries<T>(object: &Object<T>) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
7673
7674    // Next major: deprecate
7675    /// The `Object.entries()` method returns an array of a given
7676    /// object's own enumerable property [key, value] pairs, in the
7677    /// same order as that provided by a for...in loop (the difference
7678    /// being that a for-in loop enumerates properties in the
7679    /// prototype chain as well).
7680    ///
7681    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7682    #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
7683    pub fn entries_typed<T>(
7684        object: &Object<T>,
7685    ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
7686
7687    /// The `Object.groupBy()` static method groups the values of an
7688    /// iterable into a null-prototype object keyed by the property key
7689    /// returned by `callback`.
7690    ///
7691    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy)
7692    #[wasm_bindgen(static_method_of = Object, catch, js_name = groupBy)]
7693    pub fn group_by<T, K, I: Iterable<Item = T>>(
7694        items: &I,
7695        callback: &mut dyn FnMut(T, u32) -> K,
7696    ) -> Result<Object<Array<T>>, JsValue>;
7697
7698    /// The `Object.freeze()` method freezes an object: that is, prevents new
7699    /// properties from being added to it; prevents existing properties from
7700    /// being removed; and prevents existing properties, or their enumerability,
7701    /// configurability, or writability, from being changed, it also prevents
7702    /// the prototype from being changed. The method returns the passed object.
7703    ///
7704    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
7705    #[wasm_bindgen(static_method_of = Object)]
7706    pub fn freeze<T>(value: &Object<T>) -> Object<T>;
7707
7708    /// The `Object.fromEntries()` method transforms a list of key-value pairs
7709    /// into an object.
7710    ///
7711    /// **Note:** Consider using [`Object::from_entries_typed`] to support typing and error handling.
7712    ///
7713    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7714    #[cfg(not(js_sys_unstable_apis))]
7715    #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7716    pub fn from_entries(entries: &JsValue) -> Result<Object, JsValue>;
7717
7718    /// The `Object.fromEntries()` method transforms a list of key-value pairs
7719    /// into an object.
7720    ///
7721    /// Entry keys may use any JavaScript property-key representation
7722    /// (string, number, or symbol).
7723    ///
7724    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7725    #[cfg(js_sys_unstable_apis)]
7726    #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7727    pub fn from_entries<K: PropertyKey, T, I: Iterable<Item = ArrayTuple<(K, T)>>>(
7728        entries: &I,
7729    ) -> Result<Object<T>, JsValue>;
7730
7731    // Next major: deprecate
7732    /// The `Object.fromEntries()` method transforms a list of key-value pairs
7733    /// into an object.
7734    ///
7735    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7736    #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7737    pub fn from_entries_typed<T, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
7738        entries: &I,
7739    ) -> Result<Object<T>, JsValue>;
7740
7741    /// The `Object.getOwnPropertyDescriptor()` method returns a
7742    /// property descriptor for an own property (that is, one directly
7743    /// present on an object and not in the object's prototype chain)
7744    /// of a given object.
7745    ///
7746    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7747    #[cfg(not(js_sys_unstable_apis))]
7748    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
7749    pub fn get_own_property_descriptor<T>(obj: &Object<T>, prop: &JsValue) -> JsValue;
7750
7751    /// The `Object.getOwnPropertyDescriptor()` method returns a
7752    /// property descriptor for an own property (that is, one directly
7753    /// present on an object and not in the object's prototype chain)
7754    /// of a given object.
7755    ///
7756    /// The property key may be any JavaScript property-key representation
7757    /// (string, number, or symbol).
7758    ///
7759    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7760    #[cfg(js_sys_unstable_apis)]
7761    #[wasm_bindgen(
7762        static_method_of = Object,
7763        js_name = getOwnPropertyDescriptor,
7764        catch,
7765        experimental_generic_mono
7766    )]
7767    pub fn get_own_property_descriptor<T, K: PropertyKey>(
7768        obj: &Object<T>,
7769        prop: K,
7770    ) -> Result<Option<PropertyDescriptor<T>>, JsValue>;
7771
7772    // Next major: deprecate
7773    /// The `Object.getOwnPropertyDescriptor()` method returns a
7774    /// property descriptor for an own property (that is, one directly
7775    /// present on an object and not in the object's prototype chain)
7776    /// of a given object.
7777    ///
7778    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7779    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
7780    pub fn get_own_property_descriptor_str<T>(
7781        obj: &Object<T>,
7782        prop: &JsString,
7783    ) -> Result<PropertyDescriptor<T>, JsValue>;
7784
7785    /// The `Object.getOwnPropertyDescriptor()` method returns a
7786    /// property descriptor for an own property (that is, one directly
7787    /// present on an object and not in the object's prototype chain)
7788    /// of a given object.
7789    ///
7790    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7791    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
7792    pub fn get_own_property_descriptor_symbol<T>(
7793        obj: &Object<T>,
7794        prop: &Symbol,
7795    ) -> Result<PropertyDescriptor<JsValue>, JsValue>;
7796
7797    /// The `Object.getOwnPropertyDescriptors()` method returns all own
7798    /// property descriptors of a given object.
7799    ///
7800    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
7801    #[cfg(not(js_sys_unstable_apis))]
7802    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
7803    pub fn get_own_property_descriptors<T>(obj: &Object<T>) -> JsValue;
7804
7805    /// The `Object.getOwnPropertyDescriptors()` method returns all own
7806    /// property descriptors of a given object.
7807    ///
7808    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
7809    #[cfg(js_sys_unstable_apis)]
7810    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors, catch)]
7811    pub fn get_own_property_descriptors<T>(
7812        obj: &Object<T>,
7813    ) -> Result<Object<PropertyDescriptor<T>>, JsValue>;
7814
7815    /// The `Object.getOwnPropertyNames()` method returns an array of
7816    /// all properties (including non-enumerable properties except for
7817    /// those which use Symbol) found directly upon a given object.
7818    ///
7819    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
7820    #[cfg(not(js_sys_unstable_apis))]
7821    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
7822    pub fn get_own_property_names<T>(obj: &Object<T>) -> Array;
7823
7824    /// The `Object.getOwnPropertyNames()` method returns an array of
7825    /// all properties (including non-enumerable properties except for
7826    /// those which use Symbol) found directly upon a given object.
7827    ///
7828    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
7829    #[cfg(js_sys_unstable_apis)]
7830    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames, catch)]
7831    pub fn get_own_property_names<T>(obj: &Object<T>) -> Result<Array<JsString>, JsValue>;
7832
7833    /// The `Object.getOwnPropertySymbols()` method returns an array of
7834    /// all symbol properties found directly upon a given object.
7835    ///
7836    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
7837    #[cfg(not(js_sys_unstable_apis))]
7838    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
7839    pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Array;
7840
7841    /// The `Object.getOwnPropertySymbols()` method returns an array of
7842    /// all symbol properties found directly upon a given object.
7843    ///
7844    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
7845    #[cfg(js_sys_unstable_apis)]
7846    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols, catch)]
7847    pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Result<Array<Symbol>, JsValue>;
7848
7849    // Next major: `-> Nullable<Object>`
7850    /// The `Object.getPrototypeOf()` method returns the prototype
7851    /// (i.e. the value of the internal [[Prototype]] property) of the
7852    /// specified object.
7853    ///
7854    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
7855    #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
7856    pub fn get_prototype_of(obj: &JsValue) -> Object;
7857
7858    /// The `hasOwnProperty()` method returns a boolean indicating whether the
7859    /// object has the specified property as its own property (as opposed to
7860    /// inheriting it).
7861    ///
7862    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
7863    #[deprecated(note = "Use `Object::hasOwn` instead.")]
7864    #[allow(deprecated)]
7865    #[wasm_bindgen(method, js_name = hasOwnProperty)]
7866    pub fn has_own_property<T>(this: &Object<T>, property: &JsValue) -> bool;
7867
7868    /// The `Object.hasOwn()` method returns a boolean indicating whether the
7869    /// object passed in has the specified property as its own property (as
7870    /// opposed to inheriting it).
7871    ///
7872    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7873    #[cfg(not(js_sys_unstable_apis))]
7874    #[wasm_bindgen(static_method_of = Object, js_name = hasOwn)]
7875    pub fn has_own<T>(instance: &Object<T>, property: &JsValue) -> bool;
7876
7877    /// The `Object.hasOwn()` method returns a boolean indicating whether the
7878    /// object passed in has the specified property as its own property (as
7879    /// opposed to inheriting it).
7880    ///
7881    /// The property key may be any JavaScript property-key representation
7882    /// (string, number, or symbol).
7883    ///
7884    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7885    #[cfg(js_sys_unstable_apis)]
7886    #[wasm_bindgen(
7887        static_method_of = Object,
7888        js_name = hasOwn,
7889        catch,
7890        experimental_generic_mono
7891    )]
7892    pub fn has_own<T, K: PropertyKey>(instance: &Object<T>, property: K) -> Result<bool, JsValue>;
7893
7894    // Next major: deprecate
7895    /// The `Object.hasOwn()` method returns a boolean indicating whether the
7896    /// object passed in has the specified property as its own property (as
7897    /// opposed to inheriting it).
7898    ///
7899    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7900    #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7901    pub fn has_own_str<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
7902
7903    /// The `Object.hasOwn()` method returns a boolean indicating whether the
7904    /// object passed in has the specified property as its own property (as
7905    /// opposed to inheriting it).
7906    ///
7907    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7908    #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7909    pub fn has_own_symbol<T>(instance: &Object<T>, property: &Symbol) -> Result<bool, JsValue>;
7910
7911    /// The `Object.is()` method determines whether two values are the same value.
7912    ///
7913    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
7914    #[wasm_bindgen(static_method_of = Object)]
7915    pub fn is(value1: &JsValue, value_2: &JsValue) -> bool;
7916
7917    /// The `Object.isExtensible()` method determines if an object is extensible
7918    /// (whether it can have new properties added to it).
7919    ///
7920    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
7921    #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
7922    pub fn is_extensible<T>(object: &Object<T>) -> bool;
7923
7924    /// The `Object.isFrozen()` determines if an object is frozen.
7925    ///
7926    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
7927    #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
7928    pub fn is_frozen<T>(object: &Object<T>) -> bool;
7929
7930    /// The `Object.isSealed()` method determines if an object is sealed.
7931    ///
7932    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
7933    #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
7934    pub fn is_sealed<T>(object: &Object<T>) -> bool;
7935
7936    /// The `isPrototypeOf()` method checks if an object exists in another
7937    /// object's prototype chain.
7938    ///
7939    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
7940    #[wasm_bindgen(method, js_name = isPrototypeOf)]
7941    pub fn is_prototype_of<T>(this: &Object<T>, value: &JsValue) -> bool;
7942
7943    /// The `Object.keys()` method returns an array of a given object's property
7944    /// names, in the same order as we get with a normal loop.
7945    ///
7946    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7947    #[cfg(not(js_sys_unstable_apis))]
7948    #[wasm_bindgen(static_method_of = Object)]
7949    pub fn keys<T>(object: &Object<T>) -> Array;
7950
7951    /// The `Object.keys()` method returns an array of a given object's property
7952    /// names, in the same order as we get with a normal loop.
7953    ///
7954    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7955    #[cfg(js_sys_unstable_apis)]
7956    #[wasm_bindgen(static_method_of = Object)]
7957    pub fn keys<T>(object: &Object<T>) -> Array<JsString>;
7958
7959    /// The [`Object`] constructor creates an object wrapper.
7960    ///
7961    /// **Note:** Consider using [`Object::new_typed`] for typed object records.
7962    ///
7963    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7964    #[wasm_bindgen(constructor)]
7965    pub fn new() -> Object;
7966
7967    // Next major: deprecate
7968    /// The [`Object`] constructor creates an object wrapper.
7969    ///
7970    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7971    #[wasm_bindgen(constructor)]
7972    pub fn new_typed<T>() -> Object<T>;
7973
7974    /// The `Object.preventExtensions()` method prevents new properties from
7975    /// ever being added to an object (i.e. prevents future extensions to the
7976    /// object).
7977    ///
7978    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
7979    #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
7980    pub fn prevent_extensions<T>(object: &Object<T>);
7981
7982    /// The `propertyIsEnumerable()` method returns a Boolean indicating
7983    /// whether the specified property is enumerable.
7984    ///
7985    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7986    #[cfg(not(js_sys_unstable_apis))]
7987    #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
7988    pub fn property_is_enumerable<T>(this: &Object<T>, property: &JsValue) -> bool;
7989
7990    /// The `propertyIsEnumerable()` method returns whether the specified
7991    /// property is both an own property and enumerable.
7992    ///
7993    /// The property key may be any JavaScript property-key representation
7994    /// (string, number, or symbol).
7995    ///
7996    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7997    #[cfg(js_sys_unstable_apis)]
7998    #[wasm_bindgen(
7999        method,
8000        js_name = propertyIsEnumerable,
8001        experimental_generic_mono
8002    )]
8003    pub fn property_is_enumerable<T, K: PropertyKey>(this: &Object<T>, property: K) -> bool;
8004
8005    /// The `Object.seal()` method seals an object, preventing new properties
8006    /// from being added to it and marking all existing properties as
8007    /// non-configurable.  Values of present properties can still be changed as
8008    /// long as they are writable.
8009    ///
8010    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
8011    #[wasm_bindgen(static_method_of = Object)]
8012    pub fn seal<T>(value: &Object<T>) -> Object<T>;
8013
8014    // Next major: `prototype: Nullable<&Object>`
8015    /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
8016    /// internal `[[Prototype]]` property) of a specified object to another
8017    /// object or `null`.
8018    ///
8019    /// **Note:** Consider using [`Object::try_set_prototype_of`] to support errors.
8020    ///
8021    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
8022    #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
8023    pub fn set_prototype_of<T>(object: &Object<T>, prototype: &Object) -> Object<T>;
8024
8025    /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
8026    /// internal `[[Prototype]]` property) of a specified object to another
8027    /// object or `null`.
8028    ///
8029    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
8030    #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf, catch)]
8031    pub fn try_set_prototype_of<T>(
8032        object: &Object<T>,
8033        prototype: &Object,
8034    ) -> Result<Object<T>, JsValue>;
8035
8036    /// The `toLocaleString()` method returns a string representing the object.
8037    /// This method is meant to be overridden by derived objects for
8038    /// locale-specific purposes.
8039    ///
8040    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
8041    #[wasm_bindgen(method, js_name = toLocaleString)]
8042    pub fn to_locale_string<T>(this: &Object<T>) -> JsString;
8043
8044    // Next major: deprecate
8045    /// The `toString()` method returns a string representing the object.
8046    ///
8047    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
8048    #[wasm_bindgen(method, js_name = toString)]
8049    pub fn to_string<T>(this: &Object<T>) -> JsString;
8050
8051    /// The `toString()` method returns a string representing the object.
8052    ///
8053    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
8054    #[wasm_bindgen(method, js_name = toString)]
8055    pub fn to_js_string<T>(this: &Object<T>) -> JsString;
8056
8057    /// The `valueOf()` method returns the primitive value of the
8058    /// specified object.
8059    ///
8060    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
8061    #[wasm_bindgen(method, js_name = valueOf)]
8062    pub fn value_of<T>(this: &Object<T>) -> Object;
8063
8064    /// The `Object.values()` method returns an array of a given object's own
8065    /// enumerable property values, in the same order as that provided by a
8066    /// `for...in` loop (the difference being that a for-in loop enumerates
8067    /// properties in the prototype chain as well).
8068    ///
8069    /// **Note:** Consider using [`Object::try_values`] to support errors.
8070    ///
8071    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
8072    #[cfg(not(js_sys_unstable_apis))]
8073    #[wasm_bindgen(static_method_of = Object)]
8074    pub fn values<T>(object: &Object<T>) -> Array<T>;
8075
8076    /// The `Object.values()` method returns an array of a given object's own
8077    /// enumerable property values, in the same order as that provided by a
8078    /// `for...in` loop (the difference being that a for-in loop enumerates
8079    /// properties in the prototype chain as well).
8080    ///
8081    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
8082    #[cfg(js_sys_unstable_apis)]
8083    #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
8084    pub fn values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
8085
8086    // Next major: deprecate
8087    /// The `Object.values()` method returns an array of a given object's own
8088    /// enumerable property values, in the same order as that provided by a
8089    /// `for...in` loop (the difference being that a for-in loop enumerates
8090    /// properties in the prototype chain as well).
8091    ///
8092    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
8093    #[cfg(not(js_sys_unstable_apis))]
8094    #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
8095    pub fn try_values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
8096}
8097
8098impl Object {
8099    /// Returns the `Object` value of this JS value if it's an instance of an
8100    /// object.
8101    ///
8102    /// If this JS value is not an instance of an object then this returns
8103    /// `None`.
8104    pub fn try_from(val: &JsValue) -> Option<&Object> {
8105        if val.is_object() {
8106            Some(val.unchecked_ref())
8107        } else {
8108            None
8109        }
8110    }
8111}
8112
8113// `Object.is`, not the derived `===`: subclasses like `Number` can hold
8114// `NaN`, for which `===` is not reflexive as `Eq` requires. Next major: add
8115// a reference-value base type excluding primitives, move `Number` onto
8116// `JsValue`, and derive.
8117impl<T> PartialEq for Object<T> {
8118    #[inline]
8119    fn eq(&self, other: &Object<T>) -> bool {
8120        Object::is(self.as_ref(), other.as_ref())
8121    }
8122}
8123
8124impl<T> Eq for Object<T> {}
8125
8126impl Default for Object<JsValue> {
8127    fn default() -> Self {
8128        Self::new()
8129    }
8130}
8131
8132// Proxy
8133#[wasm_bindgen]
8134extern "C" {
8135    #[wasm_bindgen(typescript_type = "ProxyConstructor")]
8136    #[derive(Clone, Debug)]
8137    pub type Proxy;
8138
8139    /// The [`Proxy`] object is used to define custom behavior for fundamental
8140    /// operations (e.g. property lookup, assignment, enumeration, function
8141    /// invocation, etc).
8142    ///
8143    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
8144    #[wasm_bindgen(constructor)]
8145    pub fn new(target: &JsValue, handler: &Object) -> Proxy;
8146
8147    /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
8148    /// object.
8149    ///
8150    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
8151    #[wasm_bindgen(static_method_of = Proxy)]
8152    pub fn revocable(target: &JsValue, handler: &Object) -> Object;
8153}
8154
8155// RangeError
8156#[wasm_bindgen]
8157extern "C" {
8158    /// The `RangeError` object indicates an error when a value is not in the set
8159    /// or range of allowed values.
8160    ///
8161    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
8162    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError", no_from_js_value)]
8163    #[derive(Clone, Debug, PartialEq, Eq)]
8164    pub type RangeError;
8165
8166    /// The `RangeError` object indicates an error when a value is not in the set
8167    /// or range of allowed values.
8168    ///
8169    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
8170    #[wasm_bindgen(constructor)]
8171    pub fn new(message: &str) -> RangeError;
8172
8173    /// Creates a new `RangeError` with the given message and a typed
8174    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8175    /// original cause of the error.
8176    ///
8177    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError/RangeError)
8178    #[wasm_bindgen(constructor)]
8179    pub fn new_with_options(message: &str, options: &ErrorOptions) -> RangeError;
8180}
8181
8182// ReferenceError
8183#[wasm_bindgen]
8184extern "C" {
8185    /// The `ReferenceError` object represents an error when a non-existent
8186    /// variable is referenced.
8187    ///
8188    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
8189    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError", no_from_js_value)]
8190    #[derive(Clone, Debug, PartialEq, Eq)]
8191    pub type ReferenceError;
8192
8193    /// The `ReferenceError` object represents an error when a non-existent
8194    /// variable is referenced.
8195    ///
8196    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
8197    #[wasm_bindgen(constructor)]
8198    pub fn new(message: &str) -> ReferenceError;
8199
8200    /// Creates a new `ReferenceError` with the given message and a typed
8201    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8202    /// original cause of the error.
8203    ///
8204    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError/ReferenceError)
8205    #[wasm_bindgen(constructor)]
8206    pub fn new_with_options(message: &str, options: &ErrorOptions) -> ReferenceError;
8207}
8208
8209#[allow(non_snake_case)]
8210pub mod Reflect {
8211    use super::*;
8212
8213    // Reflect
8214    #[wasm_bindgen]
8215    extern "C" {
8216        /// The static `Reflect.apply()` method calls a target function with
8217        /// arguments as specified.
8218        ///
8219        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
8220        #[wasm_bindgen(js_namespace = Reflect, catch)]
8221        pub fn apply<T: JsFunction = fn() -> JsValue>(
8222            target: &Function<T>,
8223            this_argument: &JsValue,
8224            arguments_list: &Array,
8225        ) -> Result<<T as JsFunction>::Ret, JsValue>;
8226
8227        /// The static `Reflect.construct()` method acts like the new operator, but
8228        /// as a function.  It is equivalent to calling `new target(...args)`. It
8229        /// gives also the added option to specify a different prototype.
8230        ///
8231        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
8232        #[cfg(not(js_sys_unstable_apis))]
8233        #[wasm_bindgen(js_namespace = Reflect, catch)]
8234        pub fn construct<T: JsFunction = fn() -> JsValue>(
8235            target: &Function<T>,
8236            arguments_list: &Array,
8237        ) -> Result<JsValue, JsValue>;
8238
8239        /// The static `Reflect.construct()` method acts like the new operator, but
8240        /// as a function.  It is equivalent to calling `new target(...args)`. It
8241        /// gives also the added option to specify a different prototype.
8242        ///
8243        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
8244        #[cfg(js_sys_unstable_apis)]
8245        #[wasm_bindgen(js_namespace = Reflect, catch)]
8246        pub fn construct<T: JsFunction = fn() -> JsValue>(
8247            target: &Function<T>,
8248            arguments_list: &ArrayTuple, // DOTO: <A1, A2, A3, A4, A5, A6, A7, A8>,
8249        ) -> Result<JsValue, JsValue>;
8250
8251        /// The static `Reflect.construct()` method acts like the new operator, but
8252        /// as a function.  It is equivalent to calling `new target(...args)`. It
8253        /// gives also the added option to specify a different prototype.
8254        ///
8255        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
8256        #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
8257        pub fn construct_with_new_target(
8258            target: &Function,
8259            arguments_list: &Array,
8260            new_target: &Function,
8261        ) -> Result<JsValue, JsValue>;
8262
8263        /// The static `Reflect.defineProperty()` method is like
8264        /// `Object.defineProperty()` but returns a `Boolean`.
8265        ///
8266        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
8267        #[cfg(not(js_sys_unstable_apis))]
8268        #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
8269        pub fn define_property<T>(
8270            target: &Object<T>,
8271            property_key: &JsValue,
8272            attributes: &Object,
8273        ) -> Result<bool, JsValue>;
8274
8275        /// The static `Reflect.defineProperty()` method is like
8276        /// `Object.defineProperty()` but returns a `Boolean`.
8277        ///
8278        /// The property key may be any JavaScript property-key representation
8279        /// (string, number, or symbol).
8280        ///
8281        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
8282        #[cfg(js_sys_unstable_apis)]
8283        #[wasm_bindgen(
8284            js_namespace = Reflect,
8285            js_name = defineProperty,
8286            catch,
8287            experimental_generic_mono
8288        )]
8289        pub fn define_property<T, K: PropertyKey>(
8290            target: &Object<T>,
8291            property_key: K,
8292            attributes: &PropertyDescriptor<T>,
8293        ) -> Result<bool, JsValue>;
8294
8295        /// The static `Reflect.defineProperty()` method is like
8296        /// `Object.defineProperty()` but returns a `Boolean`.
8297        ///
8298        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
8299        #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
8300        pub fn define_property_str<T>(
8301            target: &Object<T>,
8302            property_key: &JsString,
8303            attributes: &PropertyDescriptor<T>,
8304        ) -> Result<bool, JsValue>;
8305
8306        /// The static `Reflect.deleteProperty()` method allows to delete
8307        /// properties.  It is like the `delete` operator as a function.
8308        ///
8309        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
8310        #[cfg(not(js_sys_unstable_apis))]
8311        #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
8312        pub fn delete_property<T>(target: &Object<T>, key: &JsValue) -> Result<bool, JsValue>;
8313
8314        /// The static `Reflect.deleteProperty()` method allows to delete
8315        /// properties.  It is like the `delete` operator as a function.
8316        ///
8317        /// The property key may be any JavaScript property-key representation
8318        /// (string, number, or symbol).
8319        ///
8320        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
8321        #[cfg(js_sys_unstable_apis)]
8322        #[wasm_bindgen(
8323            js_namespace = Reflect,
8324            js_name = deleteProperty,
8325            catch,
8326            experimental_generic_mono
8327        )]
8328        pub fn delete_property<T, K: PropertyKey>(
8329            target: &Object<T>,
8330            key: K,
8331        ) -> Result<bool, JsValue>;
8332
8333        /// The static `Reflect.deleteProperty()` method allows to delete
8334        /// properties.  It is like the `delete` operator as a function.
8335        ///
8336        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
8337        #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
8338        pub fn delete_property_str<T>(target: &Object<T>, key: &JsString) -> Result<bool, JsValue>;
8339
8340        /// The static `Reflect.get()` method works like getting a property from
8341        /// an object (`target[propertyKey]`) as a function.
8342        ///
8343        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
8344        #[cfg(not(js_sys_unstable_apis))]
8345        #[wasm_bindgen(js_namespace = Reflect, catch)]
8346        pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
8347
8348        /// The static `Reflect.get()` method works like getting a property from
8349        /// an object (`target[propertyKey]`) as a function.
8350        ///
8351        /// The property key may be any JavaScript property-key representation
8352        /// (string, number, or symbol).
8353        ///
8354        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
8355        #[cfg(js_sys_unstable_apis)]
8356        #[wasm_bindgen(js_namespace = Reflect, catch, experimental_generic_mono)]
8357        pub fn get<T, K: PropertyKey>(target: &Object<T>, key: K) -> Result<Option<T>, JsValue>
8358        where
8359            Option<T>: FromWasmAbi;
8360
8361        /// The static `Reflect.get()` method works like getting a property from
8362        /// an object (`target[propertyKey]`) as a function.
8363        ///
8364        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
8365        #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
8366        pub fn get_str<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
8367
8368        /// The static `Reflect.get()` method works like getting a property from
8369        /// an object (`target[propertyKey]`) as a function.
8370        ///
8371        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
8372        #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
8373        pub fn get_symbol<T>(target: &Object<T>, key: &Symbol) -> Result<JsValue, JsValue>;
8374
8375        /// The same as [`get`](fn.get.html)
8376        /// except the key is an `f64`, which is slightly faster.
8377        #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
8378        pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
8379
8380        /// The same as [`get`](fn.get.html)
8381        /// except the key is a `u32`, which is slightly faster.
8382        #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
8383        pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
8384
8385        /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
8386        /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
8387        /// of the given property if it exists on the object, `undefined` otherwise.
8388        ///
8389        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
8390        #[cfg(not(js_sys_unstable_apis))]
8391        #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
8392        pub fn get_own_property_descriptor<T>(
8393            target: &Object<T>,
8394            property_key: &JsValue,
8395        ) -> Result<JsValue, JsValue>;
8396
8397        /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
8398        /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
8399        /// of the given property if it exists on the object, `undefined` otherwise.
8400        ///
8401        /// The property key may be any JavaScript property-key representation
8402        /// (string, number, or symbol).
8403        ///
8404        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
8405        #[cfg(js_sys_unstable_apis)]
8406        #[wasm_bindgen(
8407            js_namespace = Reflect,
8408            js_name = getOwnPropertyDescriptor,
8409            catch,
8410            experimental_generic_mono
8411        )]
8412        pub fn get_own_property_descriptor<T, K: PropertyKey>(
8413            target: &Object<T>,
8414            property_key: K,
8415        ) -> Result<Option<PropertyDescriptor<T>>, JsValue>;
8416
8417        /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
8418        /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
8419        /// of the given property if it exists on the object, `undefined` otherwise.
8420        ///
8421        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
8422        #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
8423        pub fn get_own_property_descriptor_str<T>(
8424            target: &Object<T>,
8425            property_key: &JsString,
8426        ) -> Result<PropertyDescriptor<T>, JsValue>;
8427
8428        // Next major: `-> Result<Nullable<Object>, JsValue>`
8429        /// The static `Reflect.getPrototypeOf()` method is almost the same
8430        /// method as `Object.getPrototypeOf()`. It returns the prototype
8431        /// (i.e. the value of the internal `[[Prototype]]` property) of
8432        /// the specified object.
8433        ///
8434        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
8435        #[cfg(not(js_sys_unstable_apis))]
8436        #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
8437        pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
8438
8439        // Next major: `-> Result<Nullable<Object>, JsValue>`
8440        /// The static `Reflect.getPrototypeOf()` method is almost the same
8441        /// method as `Object.getPrototypeOf()`. It returns the prototype
8442        /// (i.e. the value of the internal `[[Prototype]]` property) of
8443        /// the specified object.
8444        ///
8445        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
8446        #[cfg(js_sys_unstable_apis)]
8447        #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
8448        pub fn get_prototype_of(target: &Object) -> Result<Object, JsValue>;
8449
8450        /// The static `Reflect.has()` method works like the in operator as a
8451        /// function.
8452        ///
8453        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
8454        #[cfg(not(js_sys_unstable_apis))]
8455        #[wasm_bindgen(js_namespace = Reflect, catch)]
8456        pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
8457
8458        /// The static `Reflect.has()` method works like the in operator as a
8459        /// function.
8460        ///
8461        /// The property key may be any JavaScript property-key representation
8462        /// (string, number, or symbol).
8463        ///
8464        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
8465        #[cfg(js_sys_unstable_apis)]
8466        #[wasm_bindgen(js_namespace = Reflect, catch, experimental_generic_mono)]
8467        pub fn has<T, K: PropertyKey>(target: &Object<T>, property_key: K)
8468            -> Result<bool, JsValue>;
8469
8470        // Next major: deprecate
8471        /// The static `Reflect.has()` method works like the in operator as a
8472        /// function.
8473        ///
8474        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
8475        #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
8476        pub fn has_str<T>(target: &Object<T>, property_key: &JsString) -> Result<bool, JsValue>;
8477
8478        /// The static `Reflect.has()` method works like the in operator as a
8479        /// function.
8480        ///
8481        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
8482        #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
8483        pub fn has_symbol<T>(target: &Object<T>, property_key: &Symbol) -> Result<bool, JsValue>;
8484
8485        /// The static `Reflect.isExtensible()` method determines if an object is
8486        /// extensible (whether it can have new properties added to it). It is
8487        /// similar to `Object.isExtensible()`, but with some differences.
8488        ///
8489        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
8490        #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
8491        pub fn is_extensible<T>(target: &Object<T>) -> Result<bool, JsValue>;
8492
8493        /// The static `Reflect.ownKeys()` method returns an array of the
8494        /// target object's own property keys.
8495        ///
8496        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
8497        #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
8498        pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
8499
8500        /// The static `Reflect.preventExtensions()` method prevents new
8501        /// properties from ever being added to an object (i.e. prevents
8502        /// future extensions to the object). It is similar to
8503        /// `Object.preventExtensions()`, but with some differences.
8504        ///
8505        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
8506        #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
8507        pub fn prevent_extensions<T>(target: &Object<T>) -> Result<bool, JsValue>;
8508
8509        /// The static `Reflect.set()` method works like setting a
8510        /// property on an object.
8511        ///
8512        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
8513        #[cfg(not(js_sys_unstable_apis))]
8514        #[wasm_bindgen(js_namespace = Reflect, catch)]
8515        pub fn set(
8516            target: &JsValue,
8517            property_key: &JsValue,
8518            value: &JsValue,
8519        ) -> Result<bool, JsValue>;
8520
8521        /// The static `Reflect.set()` method works like setting a
8522        /// property on an object.
8523        ///
8524        /// The property key may be any JavaScript property-key representation
8525        /// (string, number, or symbol).
8526        ///
8527        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
8528        #[cfg(js_sys_unstable_apis)]
8529        #[wasm_bindgen(js_namespace = Reflect, catch, experimental_generic_mono)]
8530        pub fn set<T, K: PropertyKey>(
8531            target: &Object<T>,
8532            property_key: K,
8533            value: &T,
8534        ) -> Result<bool, JsValue>
8535        where
8536            T: wasm_bindgen::convert::RefIntoWasmAbi;
8537
8538        /// The static `Reflect.set()` method works like setting a
8539        /// property on an object.
8540        ///
8541        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
8542        #[cfg(js_sys_unstable_apis)]
8543        #[wasm_bindgen(js_namespace = Reflect, catch)]
8544        pub fn set_symbol<T>(
8545            target: &Object<T>,
8546            property_key: &Symbol,
8547            value: &JsValue,
8548        ) -> Result<bool, JsValue>;
8549
8550        // Next major: deprecate
8551        /// The static `Reflect.set()` method works like setting a
8552        /// property on an object.
8553        ///
8554        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
8555        #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
8556        pub fn set_str<T>(
8557            target: &Object<T>,
8558            property_key: &JsString,
8559            value: &T,
8560        ) -> Result<bool, JsValue>;
8561
8562        /// The same as [`set`](fn.set.html)
8563        /// except the key is an `f64`, which is slightly faster.
8564        #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
8565        pub fn set_f64(
8566            target: &JsValue,
8567            property_key: f64,
8568            value: &JsValue,
8569        ) -> Result<bool, JsValue>;
8570
8571        /// The same as [`set`](fn.set.html)
8572        /// except the key is a `u32`, which is slightly faster.
8573        #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
8574        pub fn set_u32(
8575            target: &JsValue,
8576            property_key: u32,
8577            value: &JsValue,
8578        ) -> Result<bool, JsValue>;
8579
8580        /// The static `Reflect.set()` method works like setting a
8581        /// property on an object.
8582        ///
8583        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
8584        #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
8585        pub fn set_with_receiver(
8586            target: &JsValue,
8587            property_key: &JsValue,
8588            value: &JsValue,
8589            receiver: &JsValue,
8590        ) -> Result<bool, JsValue>;
8591
8592        // Next major: `prototype: Nullable<&Object>`
8593        /// The static `Reflect.setPrototypeOf()` method is the same
8594        /// method as `Object.setPrototypeOf()`. It sets the prototype
8595        /// (i.e., the internal `[[Prototype]]` property) of a specified
8596        /// object to another object or to null.
8597        ///
8598        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
8599        #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
8600        pub fn set_prototype_of<T>(
8601            target: &Object<T>,
8602            prototype: &JsValue,
8603        ) -> Result<bool, JsValue>;
8604    }
8605}
8606
8607// RegExp
8608#[wasm_bindgen]
8609extern "C" {
8610    #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
8611    #[derive(Clone, Debug, PartialEq, Eq)]
8612    pub type RegExp;
8613
8614    /// The `exec()` method executes a search for a match in a specified
8615    /// string. Returns a result array, or null.
8616    ///
8617    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
8618    #[cfg(not(js_sys_unstable_apis))]
8619    #[wasm_bindgen(method)]
8620    pub fn exec(this: &RegExp, text: &str) -> Option<Array<JsString>>;
8621
8622    /// The `exec()` method executes a search for a match in a specified
8623    /// string. Returns a result array, or null.
8624    ///
8625    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
8626    #[cfg(js_sys_unstable_apis)]
8627    #[wasm_bindgen(method)]
8628    pub fn exec(this: &RegExp, text: &str) -> Nullable<RegExpMatchArray>;
8629
8630    /// The flags property returns a string consisting of the flags of
8631    /// the current regular expression object.
8632    ///
8633    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
8634    #[cfg(not(js_sys_unstable_apis))]
8635    #[wasm_bindgen(method, getter)]
8636    pub fn flags(this: &RegExp) -> JsString;
8637
8638    /// The flags property returns a string consisting of the flags of
8639    /// the current regular expression object.
8640    ///
8641    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
8642    #[cfg(js_sys_unstable_apis)]
8643    #[wasm_bindgen(method, getter)]
8644    pub fn flags(this: &RegExp) -> String;
8645
8646    /// The global property indicates whether or not the "g" flag is
8647    /// used with the regular expression. global is a read-only
8648    /// property of an individual regular expression instance.
8649    ///
8650    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
8651    #[wasm_bindgen(method, getter)]
8652    pub fn global(this: &RegExp) -> bool;
8653
8654    /// The ignoreCase property indicates whether or not the "i" flag
8655    /// is used with the regular expression. ignoreCase is a read-only
8656    /// property of an individual regular expression instance.
8657    ///
8658    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
8659    #[wasm_bindgen(method, getter, js_name = ignoreCase)]
8660    pub fn ignore_case(this: &RegExp) -> bool;
8661
8662    /// The non-standard input property is a static property of
8663    /// regular expressions that contains the string against which a
8664    /// regular expression is matched. RegExp.$_ is an alias for this
8665    /// property.
8666    ///
8667    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
8668    #[wasm_bindgen(static_method_of = RegExp, getter)]
8669    pub fn input() -> JsString;
8670
8671    /// The lastIndex is a read/write integer property of regular expression
8672    /// instances that specifies the index at which to start the next match.
8673    ///
8674    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
8675    #[wasm_bindgen(structural, getter = lastIndex, method)]
8676    pub fn last_index(this: &RegExp) -> u32;
8677
8678    /// The lastIndex is a read/write integer property of regular expression
8679    /// instances that specifies the index at which to start the next match.
8680    ///
8681    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
8682    #[wasm_bindgen(structural, setter = lastIndex, method)]
8683    pub fn set_last_index(this: &RegExp, index: u32);
8684
8685    /// The non-standard lastMatch property is a static and read-only
8686    /// property of regular expressions that contains the last matched
8687    /// characters. `RegExp.$&` is an alias for this property.
8688    ///
8689    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
8690    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
8691    pub fn last_match() -> JsString;
8692
8693    /// The non-standard lastParen property is a static and read-only
8694    /// property of regular expressions that contains the last
8695    /// parenthesized substring match, if any. `RegExp.$+` is an alias
8696    /// for this property.
8697    ///
8698    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
8699    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
8700    pub fn last_paren() -> JsString;
8701
8702    /// The non-standard leftContext property is a static and
8703    /// read-only property of regular expressions that contains the
8704    /// substring preceding the most recent match. `RegExp.$`` is an
8705    /// alias for this property.
8706    ///
8707    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
8708    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
8709    pub fn left_context() -> JsString;
8710
8711    /// The multiline property indicates whether or not the "m" flag
8712    /// is used with the regular expression. multiline is a read-only
8713    /// property of an individual regular expression instance.
8714    ///
8715    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
8716    #[wasm_bindgen(method, getter)]
8717    pub fn multiline(this: &RegExp) -> bool;
8718
8719    /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
8720    /// are static and read-only properties of regular expressions
8721    /// that contain parenthesized substring matches.
8722    ///
8723    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
8724    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
8725    pub fn n1() -> JsString;
8726    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
8727    pub fn n2() -> JsString;
8728    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
8729    pub fn n3() -> JsString;
8730    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
8731    pub fn n4() -> JsString;
8732    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
8733    pub fn n5() -> JsString;
8734    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
8735    pub fn n6() -> JsString;
8736    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
8737    pub fn n7() -> JsString;
8738    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
8739    pub fn n8() -> JsString;
8740    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
8741    pub fn n9() -> JsString;
8742
8743    /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
8744    ///
8745    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
8746    #[wasm_bindgen(constructor)]
8747    pub fn new(pattern: &str, flags: &str) -> RegExp;
8748    #[wasm_bindgen(constructor)]
8749    pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
8750
8751    /// The non-standard rightContext property is a static and
8752    /// read-only property of regular expressions that contains the
8753    /// substring following the most recent match. `RegExp.$'` is an
8754    /// alias for this property.
8755    ///
8756    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
8757    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
8758    pub fn right_context() -> JsString;
8759
8760    /// The source property returns a String containing the source
8761    /// text of the regexp object, and it doesn't contain the two
8762    /// forward slashes on both sides and any flags.
8763    ///
8764    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
8765    #[cfg(not(js_sys_unstable_apis))]
8766    #[wasm_bindgen(method, getter)]
8767    pub fn source(this: &RegExp) -> JsString;
8768
8769    /// The source property returns a String containing the source
8770    /// text of the regexp object, and it doesn't contain the two
8771    /// forward slashes on both sides and any flags.
8772    ///
8773    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
8774    #[cfg(js_sys_unstable_apis)]
8775    #[wasm_bindgen(method, getter)]
8776    pub fn source(this: &RegExp) -> String;
8777
8778    /// The sticky property reflects whether or not the search is
8779    /// sticky (searches in strings only from the index indicated by
8780    /// the lastIndex property of this regular expression). sticky is
8781    /// a read-only property of an individual regular expression
8782    /// object.
8783    ///
8784    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
8785    #[wasm_bindgen(method, getter)]
8786    pub fn sticky(this: &RegExp) -> bool;
8787
8788    /// The `test()` method executes a search for a match between a
8789    /// regular expression and a specified string. Returns true or
8790    /// false.
8791    ///
8792    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
8793    #[wasm_bindgen(method)]
8794    pub fn test(this: &RegExp, text: &str) -> bool;
8795
8796    /// The `toString()` method returns a string representing the
8797    /// regular expression.
8798    ///
8799    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
8800    #[cfg(not(js_sys_unstable_apis))]
8801    #[wasm_bindgen(method, js_name = toString)]
8802    pub fn to_string(this: &RegExp) -> JsString;
8803
8804    /// The `toString()` method returns a string representing the object.
8805    #[cfg(js_sys_unstable_apis)]
8806    #[wasm_bindgen(method, js_name = toString)]
8807    pub fn to_string(this: &RegExp) -> String;
8808
8809    /// The unicode property indicates whether or not the "u" flag is
8810    /// used with a regular expression. unicode is a read-only
8811    /// property of an individual regular expression instance.
8812    ///
8813    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
8814    #[wasm_bindgen(method, getter)]
8815    pub fn unicode(this: &RegExp) -> bool;
8816
8817    /// The `dotAll` property indicates whether the `s` flag is set, making
8818    /// `.` match line terminators too.
8819    ///
8820    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/dotAll)
8821    #[wasm_bindgen(method, getter, js_name = dotAll)]
8822    pub fn dot_all(this: &RegExp) -> bool;
8823
8824    /// The `hasIndices` property indicates whether the `d` flag is set,
8825    /// recording capture group start and end indices on match results.
8826    ///
8827    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices)
8828    #[wasm_bindgen(method, getter, js_name = hasIndices)]
8829    pub fn has_indices(this: &RegExp) -> bool;
8830
8831    /// The `unicodeSets` property indicates whether the `v` flag is set,
8832    /// enabling set notation and string properties in character classes.
8833    ///
8834    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets)
8835    #[wasm_bindgen(method, getter, js_name = unicodeSets)]
8836    pub fn unicode_sets(this: &RegExp) -> bool;
8837
8838    /// The `RegExp.escape()` static method escapes any characters with
8839    /// special meaning in a regular expression so the result matches the
8840    /// input literally when used as a pattern.
8841    ///
8842    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/escape)
8843    #[wasm_bindgen(static_method_of = RegExp)]
8844    pub fn escape(text: &str) -> JsString;
8845}
8846
8847// RegExpMatchArray
8848#[wasm_bindgen]
8849extern "C" {
8850    /// The result array from `RegExp.exec()` or `String.matchAll()`.
8851    ///
8852    /// This is an array of strings with additional properties `index`, `input`, and `groups`.
8853    ///
8854    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#return_value)
8855    #[wasm_bindgen(extends = Object, extends = Array, typescript_type = "RegExpMatchArray")]
8856    #[derive(Clone, Debug, PartialEq, Eq)]
8857    pub type RegExpMatchArray;
8858
8859    /// The 0-based index of the match in the string.
8860    #[wasm_bindgen(method, getter)]
8861    pub fn index(this: &RegExpMatchArray) -> u32;
8862
8863    /// The original string that was matched against.
8864    #[wasm_bindgen(method, getter)]
8865    pub fn input(this: &RegExpMatchArray) -> JsString;
8866
8867    /// An object of named capturing groups whose keys are the names and valuestype Array
8868    /// are the capturing groups, or `undefined` if no named capturing groups were defined.
8869    #[wasm_bindgen(method, getter)]
8870    pub fn groups(this: &RegExpMatchArray) -> Option<Object>;
8871
8872    /// The number of elements in the match array (full match + capture groups).
8873    #[wasm_bindgen(method, getter)]
8874    pub fn length(this: &RegExpMatchArray) -> u32;
8875
8876    /// Gets the matched string or capture group at the given index.
8877    /// Index 0 is the full match, indices 1+ are capture groups.
8878    #[wasm_bindgen(method, indexing_getter)]
8879    pub fn get(this: &RegExpMatchArray, index: u32) -> Option<JsString>;
8880}
8881
8882// Set
8883#[wasm_bindgen]
8884extern "C" {
8885    #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
8886    #[derive(Clone, Debug, PartialEq, Eq)]
8887    pub type Set<T = JsValue>;
8888
8889    /// The [`Set`] object lets you store unique values of any type, whether
8890    /// primitive values or object references.
8891    ///
8892    /// **Note:** Consider using [`Set::new_typed`] to support typing.
8893    ///
8894    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8895    #[cfg(not(js_sys_unstable_apis))]
8896    #[wasm_bindgen(constructor)]
8897    pub fn new(init: &JsValue) -> Set;
8898
8899    /// The [`Set`] object lets you store unique values of any type, whether
8900    /// primitive values or object references.
8901    ///
8902    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8903    #[cfg(js_sys_unstable_apis)]
8904    #[wasm_bindgen(constructor)]
8905    pub fn new<T>() -> Set<T>;
8906
8907    // Next major: deprecate
8908    /// The [`Set`] object lets you store unique values of any type, whether
8909    /// primitive values or object references.
8910    ///
8911    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8912    #[wasm_bindgen(constructor)]
8913    pub fn new_typed<T>() -> Set<T>;
8914
8915    /// The [`Set`] object lets you store unique values of any type, whether
8916    /// primitive values or object references.
8917    ///
8918    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8919    #[wasm_bindgen(constructor, js_name = new)]
8920    pub fn new_empty<T>() -> Set<T>;
8921
8922    /// The [`Set`] object lets you store unique values of any type, whether
8923    /// primitive values or object references.
8924    ///
8925    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8926    #[wasm_bindgen(constructor, js_name = new)]
8927    pub fn new_from_items<T>(items: &[T]) -> Set<T>;
8928
8929    /// The [`Set`] object lets you store unique values of any type, whether
8930    /// primitive values or object references.
8931    ///
8932    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8933    #[wasm_bindgen(constructor, js_name = new, catch)]
8934    pub fn new_from_iterable<T, I: Iterable<Item = T>>(iterable: I) -> Result<Set<T>, JsValue>;
8935
8936    /// The `add()` method appends a new element with a specified value to the
8937    /// end of a [`Set`] object.
8938    ///
8939    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
8940    #[wasm_bindgen(method)]
8941    pub fn add<T>(this: &Set<T>, value: &T) -> Set<T>;
8942
8943    /// The `clear()` method removes all elements from a [`Set`] object.
8944    ///
8945    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
8946    #[wasm_bindgen(method)]
8947    pub fn clear<T>(this: &Set<T>);
8948
8949    /// The `delete()` method removes the specified element from a [`Set`]
8950    /// object.
8951    ///
8952    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
8953    #[wasm_bindgen(method)]
8954    pub fn delete<T>(this: &Set<T>, value: &T) -> bool;
8955
8956    /// The `forEach()` method executes a provided function once for each value
8957    /// in the Set object, in insertion order.
8958    ///
8959    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8960    #[cfg(not(js_sys_unstable_apis))]
8961    #[wasm_bindgen(method, js_name = forEach)]
8962    pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T, T, Set<T>));
8963
8964    /// The `forEach()` method executes a provided function once for each value
8965    /// in the Set object, in insertion order.
8966    ///
8967    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8968    #[cfg(js_sys_unstable_apis)]
8969    #[wasm_bindgen(method, js_name = forEach)]
8970    pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T));
8971
8972    /// The `forEach()` method executes a provided function once for each value
8973    /// in the Set object, in insertion order.
8974    ///
8975    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8976    #[wasm_bindgen(method, js_name = forEach, catch)]
8977    pub fn try_for_each<T>(
8978        this: &Set<T>,
8979        callback: &mut dyn FnMut(T) -> Result<(), JsError>,
8980    ) -> Result<(), JsValue>;
8981
8982    /// The `has()` method returns a boolean indicating whether an element with
8983    /// the specified value exists in a [`Set`] object or not.
8984    ///
8985    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
8986    #[wasm_bindgen(method)]
8987    pub fn has<T>(this: &Set<T>, value: &T) -> bool;
8988
8989    /// The size accessor property returns the number of elements in a [`Set`]
8990    /// object.
8991    ///
8992    /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
8993    #[wasm_bindgen(method, getter)]
8994    pub fn size<T>(this: &Set<T>) -> u32;
8995
8996    /// The `union()` method returns a new set containing elements which are in
8997    /// either or both of this set and the given set.
8998    ///
8999    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union)
9000    #[wasm_bindgen(method)]
9001    pub fn union<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
9002
9003    /// The `intersection()` method returns a new set containing elements which are
9004    /// in both this set and the given set.
9005    ///
9006    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection)
9007    #[wasm_bindgen(method)]
9008    pub fn intersection<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
9009
9010    /// The `difference()` method returns a new set containing elements which are
9011    /// in this set but not in the given set.
9012    ///
9013    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference)
9014    #[wasm_bindgen(method)]
9015    pub fn difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
9016
9017    /// The `symmetricDifference()` method returns a new set containing elements
9018    /// which are in either this set or the given set, but not in both.
9019    ///
9020    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)
9021    #[wasm_bindgen(method, js_name = symmetricDifference)]
9022    pub fn symmetric_difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
9023
9024    /// The `isSubsetOf()` method returns a boolean indicating whether all elements
9025    /// of this set are in the given set.
9026    ///
9027    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSubsetOf)
9028    #[wasm_bindgen(method, js_name = isSubsetOf)]
9029    pub fn is_subset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
9030
9031    /// The `isSupersetOf()` method returns a boolean indicating whether all elements
9032    /// of the given set are in this set.
9033    ///
9034    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSupersetOf)
9035    #[wasm_bindgen(method, js_name = isSupersetOf)]
9036    pub fn is_superset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
9037
9038    /// The `isDisjointFrom()` method returns a boolean indicating whether this set
9039    /// has no elements in common with the given set.
9040    ///
9041    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom)
9042    #[wasm_bindgen(method, js_name = isDisjointFrom)]
9043    pub fn is_disjoint_from<T>(this: &Set<T>, other: &Set<T>) -> bool;
9044}
9045
9046impl Default for Set<JsValue> {
9047    fn default() -> Self {
9048        Self::new_typed()
9049    }
9050}
9051
9052impl<T> Iterable for Set<T> {
9053    type Item = T;
9054}
9055
9056// SetIterator
9057#[wasm_bindgen]
9058extern "C" {
9059    /// The `entries()` method returns a new Iterator object that contains an
9060    /// array of [value, value] for each element in the Set object, in insertion
9061    /// order. For Set objects there is no key like in Map objects. However, to
9062    /// keep the API similar to the Map object, each entry has the same value
9063    /// for its key and value here, so that an array [value, value] is returned.
9064    ///
9065    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
9066    #[cfg(not(js_sys_unstable_apis))]
9067    #[wasm_bindgen(method)]
9068    pub fn entries<T>(set: &Set<T>) -> Iterator;
9069
9070    /// The `entries()` method returns a new Iterator object that contains an
9071    /// array of [value, value] for each element in the Set object, in insertion
9072    /// order. For Set objects there is no key like in Map objects. However, to
9073    /// keep the API similar to the Map object, each entry has the same value
9074    /// for its key and value here, so that an array [value, value] is returned.
9075    ///
9076    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
9077    #[cfg(js_sys_unstable_apis)]
9078    #[wasm_bindgen(method, js_name = entries)]
9079    pub fn entries<T>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
9080
9081    // Next major: deprecate
9082    /// The `entries()` method returns a new Iterator object that contains an
9083    /// array of [value, value] for each element in the Set object, in insertion
9084    /// order. For Set objects there is no key like in Map objects. However, to
9085    /// keep the API similar to the Map object, each entry has the same value
9086    /// for its key and value here, so that an array [value, value] is returned.
9087    ///
9088    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
9089    #[wasm_bindgen(method, js_name = entries)]
9090    pub fn entries_typed<T>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
9091
9092    /// The `keys()` method is an alias for this method (for similarity with
9093    /// Map objects); it behaves exactly the same and returns values
9094    /// of Set elements.
9095    ///
9096    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
9097    #[wasm_bindgen(method)]
9098    pub fn keys<T>(set: &Set<T>) -> Iterator<T>;
9099
9100    /// The `values()` method returns a new Iterator object that contains the
9101    /// values for each element in the Set object in insertion order.
9102    ///
9103    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
9104    #[wasm_bindgen(method)]
9105    pub fn values<T>(set: &Set<T>) -> Iterator<T>;
9106}
9107
9108// SuppressedError
9109#[wasm_bindgen]
9110extern "C" {
9111    /// A `SuppressedError` is thrown when disposing a [`DisposableStack`]
9112    /// and one disposer's error masks another; `error` is the newer error
9113    /// and `suppressed` the one it hid.
9114    ///
9115    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SuppressedError)
9116    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SuppressedError", no_from_js_value)]
9117    #[derive(Clone, Debug, PartialEq, Eq)]
9118    pub type SuppressedError;
9119
9120    /// Creates a new `SuppressedError` wrapping `error` and `suppressed`.
9121    ///
9122    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SuppressedError/SuppressedError)
9123    #[wasm_bindgen(constructor)]
9124    pub fn new(error: &JsValue, suppressed: &JsValue) -> SuppressedError;
9125
9126    /// Creates a new `SuppressedError` with a message.
9127    #[wasm_bindgen(constructor)]
9128    pub fn new_with_message(
9129        error: &JsValue,
9130        suppressed: &JsValue,
9131        message: &str,
9132    ) -> SuppressedError;
9133
9134    /// Creates a new `SuppressedError` with a message and options such as `cause`.
9135    #[wasm_bindgen(constructor)]
9136    pub fn new_with_message_and_error_options(
9137        error: &JsValue,
9138        suppressed: &JsValue,
9139        message: &str,
9140        options: &ErrorOptions,
9141    ) -> SuppressedError;
9142
9143    /// The error that was thrown most recently.
9144    ///
9145    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SuppressedError/error)
9146    #[wasm_bindgen(method, getter)]
9147    pub fn error(this: &SuppressedError) -> JsValue;
9148
9149    /// The error that was suppressed by `error`.
9150    ///
9151    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SuppressedError/suppressed)
9152    #[wasm_bindgen(method, getter)]
9153    pub fn suppressed(this: &SuppressedError) -> JsValue;
9154}
9155
9156// SyntaxError
9157#[wasm_bindgen]
9158extern "C" {
9159    /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
9160    /// token order that does not conform to the syntax of the language when
9161    /// parsing code.
9162    ///
9163    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
9164    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError", no_from_js_value)]
9165    #[derive(Clone, Debug, PartialEq, Eq)]
9166    pub type SyntaxError;
9167
9168    /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
9169    /// token order that does not conform to the syntax of the language when
9170    /// parsing code.
9171    ///
9172    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
9173    #[wasm_bindgen(constructor)]
9174    pub fn new(message: &str) -> SyntaxError;
9175
9176    /// Creates a new `SyntaxError` with the given message and a typed
9177    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
9178    /// original cause of the error.
9179    ///
9180    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError/SyntaxError)
9181    #[wasm_bindgen(constructor)]
9182    pub fn new_with_options(message: &str, options: &ErrorOptions) -> SyntaxError;
9183}
9184
9185// TypeError
9186#[wasm_bindgen]
9187extern "C" {
9188    /// The `TypeError` object represents an error when a value is not of the
9189    /// expected type.
9190    ///
9191    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
9192    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError", no_from_js_value)]
9193    #[derive(Clone, Debug, PartialEq, Eq)]
9194    pub type TypeError;
9195
9196    /// The `TypeError` object represents an error when a value is not of the
9197    /// expected type.
9198    ///
9199    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
9200    #[wasm_bindgen(constructor)]
9201    pub fn new(message: &str) -> TypeError;
9202
9203    /// Creates a new `TypeError` with the given message and a typed
9204    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
9205    /// original cause of the error.
9206    ///
9207    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError/TypeError)
9208    #[wasm_bindgen(constructor)]
9209    pub fn new_with_options(message: &str, options: &ErrorOptions) -> TypeError;
9210}
9211
9212// URIError
9213#[wasm_bindgen]
9214extern "C" {
9215    /// The `URIError` object represents an error when a global URI handling
9216    /// function was used in a wrong way.
9217    ///
9218    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
9219    #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError", no_from_js_value)]
9220    #[derive(Clone, Debug, PartialEq, Eq)]
9221    pub type UriError;
9222
9223    /// The `URIError` object represents an error when a global URI handling
9224    /// function was used in a wrong way.
9225    ///
9226    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
9227    #[wasm_bindgen(constructor, js_class = "URIError")]
9228    pub fn new(message: &str) -> UriError;
9229
9230    /// Creates a new `URIError` with the given message and a typed
9231    /// [`ErrorOptions`] dictionary whose `cause` property indicates the
9232    /// original cause of the error.
9233    ///
9234    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError/URIError)
9235    #[wasm_bindgen(constructor, js_class = "URIError")]
9236    pub fn new_with_options(message: &str, options: &ErrorOptions) -> UriError;
9237}
9238
9239// WeakMap
9240#[wasm_bindgen]
9241extern "C" {
9242    #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
9243    #[derive(Clone, Debug, PartialEq, Eq)]
9244    pub type WeakMap<K = Object, V = JsValue>;
9245
9246    /// The [`WeakMap`] object is a collection of key/value pairs in which the
9247    /// keys are weakly referenced.  The keys must be objects and the values can
9248    /// be arbitrary values.
9249    ///
9250    /// **Note:** Consider using [`WeakMap::new_typed`] to support typing.
9251    ///
9252    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
9253    #[cfg(not(js_sys_unstable_apis))]
9254    #[wasm_bindgen(constructor)]
9255    pub fn new() -> WeakMap;
9256
9257    /// The [`WeakMap`] object is a collection of key/value pairs in which the
9258    /// keys are weakly referenced.  The keys must be objects and the values can
9259    /// be arbitrary values.
9260    ///
9261    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
9262    #[cfg(js_sys_unstable_apis)]
9263    #[wasm_bindgen(constructor)]
9264    pub fn new<K = Object, V = Object>() -> WeakMap<K, V>;
9265
9266    // Next major: deprecate
9267    /// The [`WeakMap`] object is a collection of key/value pairs in which the
9268    /// keys are weakly referenced.  The keys must be objects and the values can
9269    /// be arbitrary values.
9270    ///
9271    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
9272    #[wasm_bindgen(constructor)]
9273    pub fn new_typed<K = Object, V = Object>() -> WeakMap<K, V>;
9274
9275    /// The `set()` method sets the value for the key in the [`WeakMap`] object.
9276    /// Returns the [`WeakMap`] object.
9277    ///
9278    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
9279    #[wasm_bindgen(method, js_class = "WeakMap")]
9280    pub fn set<K, V>(this: &WeakMap<K, V>, key: &K, value: &V) -> WeakMap<K, V>;
9281
9282    /// The `get()` method returns a specified by key element
9283    /// from a [`WeakMap`] object. Returns `undefined` if the key is not found.
9284    ///
9285    /// **Note:** Consider using [`WeakMap::get_checked`] to get an `Option<V>` instead.
9286    ///
9287    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
9288    #[cfg(not(js_sys_unstable_apis))]
9289    #[wasm_bindgen(method)]
9290    pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> V;
9291
9292    /// The `get()` method returns a specified by key element
9293    /// from a [`WeakMap`] object. Returns `None` if the key is not found.
9294    ///
9295    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
9296    #[cfg(js_sys_unstable_apis)]
9297    #[wasm_bindgen(method)]
9298    pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
9299
9300    /// The `get()` method returns a specified by key element
9301    /// from a [`WeakMap`] object. Returns `None` if the key is not found.
9302    ///
9303    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
9304    #[wasm_bindgen(method, js_name = get)]
9305    pub fn get_checked<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
9306
9307    /// The `has()` method returns a boolean indicating whether an element with
9308    /// the specified key exists in the [`WeakMap`] object or not.
9309    ///
9310    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
9311    #[wasm_bindgen(method)]
9312    pub fn has<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
9313
9314    /// The `delete()` method removes the specified element from a [`WeakMap`]
9315    /// object.
9316    ///
9317    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
9318    #[wasm_bindgen(method)]
9319    pub fn delete<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
9320
9321    /// The `getOrInsert()` method returns the value for `key`, first
9322    /// inserting `default_value` under it if the key is absent.
9323    ///
9324    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/getOrInsert)
9325    #[wasm_bindgen(method, catch, js_name = getOrInsert)]
9326    pub fn get_or_insert<K, V>(
9327        this: &WeakMap<K, V>,
9328        key: &K,
9329        default_value: &V,
9330    ) -> Result<V, JsValue>;
9331
9332    /// The `getOrInsertComputed()` method returns the value for `key`,
9333    /// first inserting the result of `callback(key)` under it if the key
9334    /// is absent.
9335    ///
9336    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/getOrInsertComputed)
9337    #[wasm_bindgen(method, catch, js_name = getOrInsertComputed)]
9338    pub fn get_or_insert_computed<K, V>(
9339        this: &WeakMap<K, V>,
9340        key: &K,
9341        callback: &mut dyn FnMut(K) -> V,
9342    ) -> Result<V, JsValue>;
9343}
9344
9345impl Default for WeakMap {
9346    fn default() -> Self {
9347        Self::new()
9348    }
9349}
9350
9351// WeakSet
9352#[wasm_bindgen]
9353extern "C" {
9354    #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
9355    #[derive(Clone, Debug, PartialEq, Eq)]
9356    pub type WeakSet<T = Object>;
9357
9358    /// The `WeakSet` object lets you store weakly held objects in a collection.
9359    ///
9360    /// **Note:** Consider using [`WeakSet::new_typed`] for typed sets.
9361    ///
9362    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
9363    #[cfg(not(js_sys_unstable_apis))]
9364    #[wasm_bindgen(constructor)]
9365    pub fn new() -> WeakSet;
9366
9367    /// The `WeakSet` object lets you store weakly held objects in a collection.
9368    ///
9369    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
9370    #[cfg(js_sys_unstable_apis)]
9371    #[wasm_bindgen(constructor)]
9372    pub fn new<T = Object>() -> WeakSet<T>;
9373
9374    // Next major: deprecate
9375    /// The `WeakSet` object lets you store weakly held objects in a collection.
9376    ///
9377    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
9378    #[wasm_bindgen(constructor)]
9379    pub fn new_typed<T = Object>() -> WeakSet<T>;
9380
9381    /// The `has()` method returns a boolean indicating whether an object exists
9382    /// in a WeakSet or not.
9383    ///
9384    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
9385    #[wasm_bindgen(method)]
9386    pub fn has<T>(this: &WeakSet<T>, value: &T) -> bool;
9387
9388    /// The `add()` method appends a new object to the end of a WeakSet object.
9389    ///
9390    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
9391    #[wasm_bindgen(method)]
9392    pub fn add<T>(this: &WeakSet<T>, value: &T) -> WeakSet<T>;
9393
9394    /// The `delete()` method removes the specified element from a WeakSet
9395    /// object.
9396    ///
9397    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
9398    #[wasm_bindgen(method)]
9399    pub fn delete<T>(this: &WeakSet<T>, value: &T) -> bool;
9400}
9401
9402impl Default for WeakSet {
9403    fn default() -> Self {
9404        Self::new()
9405    }
9406}
9407
9408// WeakRef
9409#[wasm_bindgen]
9410extern "C" {
9411    #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
9412    #[derive(Clone, Debug, PartialEq, Eq)]
9413    pub type WeakRef<T = Object>;
9414
9415    /// The `WeakRef` object contains a weak reference to an object. A weak
9416    /// reference to an object is a reference that does not prevent the object
9417    /// from being reclaimed by the garbage collector.
9418    ///
9419    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
9420    #[wasm_bindgen(constructor)]
9421    pub fn new<T = Object>(target: &T) -> WeakRef<T>;
9422
9423    /// Returns the `Object` this `WeakRef` points to, or `None` if the
9424    /// object has been garbage collected.
9425    ///
9426    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
9427    #[wasm_bindgen(method)]
9428    pub fn deref<T>(this: &WeakRef<T>) -> Option<T>;
9429}
9430
9431#[cfg(feature = "temporal")]
9432#[allow(non_snake_case)]
9433pub mod Temporal;
9434
9435#[allow(non_snake_case)]
9436pub mod WebAssembly {
9437    use super::*;
9438
9439    // WebAssembly
9440    #[wasm_bindgen]
9441    extern "C" {
9442        /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
9443        /// from WebAssembly binary code.  This function is useful if it is
9444        /// necessary to a compile a module before it can be instantiated
9445        /// (otherwise, the `WebAssembly.instantiate()` function should be used).
9446        ///
9447        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
9448        #[cfg(not(js_sys_unstable_apis))]
9449        #[wasm_bindgen(js_namespace = WebAssembly)]
9450        pub fn compile(buffer_source: &JsValue) -> Promise<JsValue>;
9451
9452        /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
9453        /// from WebAssembly binary code.  This function is useful if it is
9454        /// necessary to a compile a module before it can be instantiated
9455        /// (otherwise, the `WebAssembly.instantiate()` function should be used).
9456        ///
9457        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
9458        #[cfg(js_sys_unstable_apis)]
9459        #[wasm_bindgen(js_namespace = WebAssembly)]
9460        pub fn compile(buffer_source: &JsValue) -> Promise<Module>;
9461
9462        /// The `WebAssembly.compileStreaming()` function compiles a
9463        /// `WebAssembly.Module` module directly from a streamed underlying
9464        /// source. This function is useful if it is necessary to a compile a
9465        /// module before it can be instantiated (otherwise, the
9466        /// `WebAssembly.instantiateStreaming()` function should be used).
9467        ///
9468        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
9469        #[cfg(not(js_sys_unstable_apis))]
9470        #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
9471        pub fn compile_streaming(response: &Promise) -> Promise<JsValue>;
9472
9473        /// The `WebAssembly.compileStreaming()` function compiles a
9474        /// `WebAssembly.Module` module directly from a streamed underlying
9475        /// source. This function is useful if it is necessary to a compile a
9476        /// module before it can be instantiated (otherwise, the
9477        /// `WebAssembly.instantiateStreaming()` function should be used).
9478        ///
9479        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
9480        #[cfg(js_sys_unstable_apis)]
9481        #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
9482        pub fn compile_streaming(response: &Promise) -> Promise<Module>;
9483
9484        /// The `WebAssembly.instantiate()` function allows you to compile and
9485        /// instantiate WebAssembly code.
9486        ///
9487        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
9488        #[cfg(not(js_sys_unstable_apis))]
9489        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
9490        pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<JsValue>;
9491
9492        /// The `WebAssembly.instantiate()` function allows you to compile and
9493        /// instantiate WebAssembly code.
9494        ///
9495        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
9496        #[cfg(js_sys_unstable_apis)]
9497        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
9498        pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<Instance>;
9499
9500        /// The `WebAssembly.instantiate()` function allows you to compile and
9501        /// instantiate WebAssembly code.
9502        ///
9503        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
9504        #[cfg(not(js_sys_unstable_apis))]
9505        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
9506        pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<JsValue>;
9507
9508        /// The `WebAssembly.instantiate()` function allows you to compile and
9509        /// instantiate WebAssembly code.
9510        ///
9511        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
9512        #[cfg(js_sys_unstable_apis)]
9513        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
9514        pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<Instance>;
9515
9516        /// The `WebAssembly.instantiateStreaming()` function compiles and
9517        /// instantiates a WebAssembly module directly from a streamed
9518        /// underlying source. This is the most efficient, optimized way to load
9519        /// Wasm code.
9520        ///
9521        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
9522        #[cfg(not(js_sys_unstable_apis))]
9523        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
9524        pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<JsValue>;
9525
9526        /// The `WebAssembly.instantiateStreaming()` function compiles and
9527        /// instantiates a WebAssembly module directly from a streamed
9528        /// underlying source. This is the most efficient, optimized way to load
9529        /// Wasm code.
9530        ///
9531        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
9532        #[cfg(js_sys_unstable_apis)]
9533        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
9534        pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<Instance>;
9535
9536        /// The `WebAssembly.validate()` function validates a given typed
9537        /// array of WebAssembly binary code, returning whether the bytes
9538        /// form a valid Wasm module (`true`) or not (`false`).
9539        ///
9540        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
9541        #[wasm_bindgen(js_namespace = WebAssembly, catch)]
9542        pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
9543
9544        /// The `WebAssembly.validate()` function validates the given bytes
9545        /// under the given compile options.
9546        ///
9547        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
9548        #[wasm_bindgen(js_namespace = WebAssembly, js_name = validate, catch)]
9549        pub fn validate_with_options(
9550            buffer_source: &JsValue,
9551            options: &CompileOptions,
9552        ) -> Result<bool, JsValue>;
9553
9554        /// The `WebAssembly.compile()` function compiles the given bytes
9555        /// under the given compile options.
9556        ///
9557        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
9558        #[wasm_bindgen(js_namespace = WebAssembly, js_name = compile)]
9559        pub fn compile_with_options(
9560            buffer_source: &JsValue,
9561            options: &CompileOptions,
9562        ) -> Promise<Module>;
9563
9564        /// The `WebAssembly.compileStreaming()` function compiles a module
9565        /// from a streamed `Response` under the given compile options.
9566        ///
9567        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
9568        #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
9569        pub fn compile_streaming_with_options(
9570            response: &Promise,
9571            options: &CompileOptions,
9572        ) -> Promise<Module>;
9573
9574        /// The `WebAssembly.instantiate()` function compiles and instantiates
9575        /// the given bytes under the given compile options, resolving to an
9576        /// [`InstantiatedSource`] holding both the module and the instance.
9577        ///
9578        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
9579        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
9580        pub fn instantiate_buffer_with_options(
9581            buffer: &[u8],
9582            imports: &Object,
9583            options: &CompileOptions,
9584        ) -> Promise<InstantiatedSource>;
9585
9586        /// The `WebAssembly.instantiateStreaming()` function compiles and
9587        /// instantiates a module from a streamed `Response` under the given
9588        /// compile options, resolving to an [`InstantiatedSource`].
9589        ///
9590        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
9591        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
9592        pub fn instantiate_streaming_with_options(
9593            response: &JsValue,
9594            imports: &Object,
9595            options: &CompileOptions,
9596        ) -> Promise<InstantiatedSource>;
9597
9598        /// The `WebAssembly.JSTag` property is the [`Tag`] under which
9599        /// JavaScript exceptions are thrown into and caught from Wasm code.
9600        ///
9601        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/JSTag)
9602        #[wasm_bindgen(thread_local_v2, js_namespace = WebAssembly, js_name = JSTag)]
9603        pub static JS_TAG: Tag;
9604    }
9605
9606    // WebAssembly.InstantiatedSource
9607    // CompileOptions
9608    #[wasm_bindgen]
9609    extern "C" {
9610        /// The compile options accepted by `WebAssembly.validate()`,
9611        /// `compile()`, `instantiate()`, their streaming forms and the
9612        /// `Module` constructor: the JS builtins to enable and the import
9613        /// module name for imported string constants.
9614        ///
9615        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile#compileoptions)
9616        #[wasm_bindgen(extends = Object)]
9617        #[derive(Clone, Debug)]
9618        pub type CompileOptions;
9619
9620        /// The enabled builtin sets, such as `"js-string"`, if set.
9621        #[wasm_bindgen(method, getter, js_name = builtins)]
9622        pub fn get_builtins(this: &CompileOptions) -> Option<Array<JsString>>;
9623        /// Sets the builtin sets to enable, such as `"js-string"`.
9624        #[wasm_bindgen(method, setter)]
9625        pub fn set_builtins(this: &CompileOptions, builtins: &[JsString]);
9626
9627        /// The import module name for imported string constants, if set.
9628        #[wasm_bindgen(method, getter, js_name = importedStringConstants)]
9629        pub fn get_imported_string_constants(this: &CompileOptions) -> Option<JsString>;
9630        /// Sets the import module name for imported string constants.
9631        #[wasm_bindgen(method, setter, js_name = importedStringConstants)]
9632        pub fn set_imported_string_constants(this: &CompileOptions, name: &str);
9633    }
9634
9635    impl CompileOptions {
9636        /// Creates empty `CompileOptions`.
9637        pub fn new() -> CompileOptions {
9638            JsCast::unchecked_into::<CompileOptions>(Object::<JsValue>::new())
9639        }
9640    }
9641
9642    impl Default for CompileOptions {
9643        fn default() -> Self {
9644            Self::new()
9645        }
9646    }
9647
9648    #[wasm_bindgen]
9649    extern "C" {
9650        /// The `{ module, instance }` pair that `WebAssembly.instantiate()`
9651        /// and `WebAssembly.instantiateStreaming()` resolve to when given
9652        /// bytes rather than a compiled `Module`.
9653        ///
9654        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate#return_value)
9655        #[wasm_bindgen(extends = Object, typescript_type = "WebAssembly.WebAssemblyInstantiatedSource")]
9656        #[derive(Clone, Debug, PartialEq, Eq)]
9657        pub type InstantiatedSource;
9658
9659        /// The compiled module.
9660        #[wasm_bindgen(method, getter)]
9661        pub fn module(this: &InstantiatedSource) -> Module;
9662
9663        /// The instance of that module.
9664        #[wasm_bindgen(method, getter)]
9665        pub fn instance(this: &InstantiatedSource) -> Instance;
9666    }
9667
9668    // WebAssembly.CompileError
9669    #[wasm_bindgen]
9670    extern "C" {
9671        /// The `WebAssembly.CompileError()` constructor creates a new
9672        /// WebAssembly `CompileError` object, which indicates an error during
9673        /// WebAssembly decoding or validation.
9674        ///
9675        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
9676        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError", no_from_js_value)]
9677        #[derive(Clone, Debug, PartialEq, Eq)]
9678        pub type CompileError;
9679
9680        /// The `WebAssembly.CompileError()` constructor creates a new
9681        /// WebAssembly `CompileError` object, which indicates an error during
9682        /// WebAssembly decoding or validation.
9683        ///
9684        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
9685        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9686        pub fn new(message: &str) -> CompileError;
9687
9688        /// Creates a new `WebAssembly.CompileError` with the given message and
9689        /// a typed [`ErrorOptions`] dictionary whose `cause` property
9690        /// indicates the original cause of the error.
9691        ///
9692        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError/CompileError)
9693        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9694        pub fn new_with_options(message: &str, options: &ErrorOptions) -> CompileError;
9695    }
9696
9697    // WebAssembly.Instance
9698    #[wasm_bindgen]
9699    extern "C" {
9700        /// A `WebAssembly.Instance` object is a stateful, executable instance
9701        /// of a `WebAssembly.Module`. Instance objects contain all the exported
9702        /// WebAssembly functions that allow calling into WebAssembly code from
9703        /// JavaScript.
9704        ///
9705        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
9706        #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
9707        #[derive(Clone, Debug, PartialEq, Eq)]
9708        pub type Instance;
9709
9710        /// The `WebAssembly.Instance()` constructor function can be called to
9711        /// synchronously instantiate a given `WebAssembly.Module`
9712        /// object. However, the primary way to get an `Instance` is through the
9713        /// asynchronous `WebAssembly.instantiateStreaming()` function.
9714        ///
9715        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
9716        #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
9717        pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
9718
9719        /// The `exports` readonly property of the `WebAssembly.Instance` object
9720        /// prototype returns an object containing as its members all the
9721        /// functions exported from the WebAssembly module instance, to allow
9722        /// them to be accessed and used by JavaScript.
9723        ///
9724        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
9725        #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
9726        pub fn exports(this: &Instance) -> Object;
9727    }
9728
9729    // WebAssembly.LinkError
9730    #[wasm_bindgen]
9731    extern "C" {
9732        /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
9733        /// LinkError object, which indicates an error during module
9734        /// instantiation (besides traps from the start function).
9735        ///
9736        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
9737        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError", no_from_js_value)]
9738        #[derive(Clone, Debug, PartialEq, Eq)]
9739        pub type LinkError;
9740
9741        /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
9742        /// LinkError object, which indicates an error during module
9743        /// instantiation (besides traps from the start function).
9744        ///
9745        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
9746        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9747        pub fn new(message: &str) -> LinkError;
9748
9749        /// Creates a new `WebAssembly.LinkError` with the given message and a
9750        /// typed [`ErrorOptions`] dictionary whose `cause` property indicates
9751        /// the original cause of the error.
9752        ///
9753        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError/LinkError)
9754        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9755        pub fn new_with_options(message: &str, options: &ErrorOptions) -> LinkError;
9756    }
9757
9758    // WebAssembly.RuntimeError
9759    #[wasm_bindgen]
9760    extern "C" {
9761        /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
9762        /// `RuntimeError` object — the type that is thrown whenever WebAssembly
9763        /// specifies a trap.
9764        ///
9765        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
9766        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError", no_from_js_value)]
9767        #[derive(Clone, Debug, PartialEq, Eq)]
9768        pub type RuntimeError;
9769
9770        /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
9771        /// `RuntimeError` object — the type that is thrown whenever WebAssembly
9772        /// specifies a trap.
9773        ///
9774        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
9775        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9776        pub fn new(message: &str) -> RuntimeError;
9777
9778        /// Creates a new `WebAssembly.RuntimeError` with the given message
9779        /// and a typed [`ErrorOptions`] dictionary whose `cause` property
9780        /// indicates the original cause of the error.
9781        ///
9782        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError/RuntimeError)
9783        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9784        pub fn new_with_options(message: &str, options: &ErrorOptions) -> RuntimeError;
9785    }
9786
9787    // WebAssembly.Module
9788    #[wasm_bindgen]
9789    extern "C" {
9790        /// A `WebAssembly.Module` object contains stateless WebAssembly code
9791        /// that has already been compiled by the browser and can be
9792        /// efficiently shared with Workers, and instantiated multiple times.
9793        ///
9794        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
9795        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
9796        #[derive(Clone, Debug, PartialEq, Eq)]
9797        pub type Module;
9798
9799        /// A `WebAssembly.Module` object contains stateless WebAssembly code
9800        /// that has already been compiled by the browser and can be
9801        /// efficiently shared with Workers, and instantiated multiple times.
9802        ///
9803        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
9804        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9805        pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
9806
9807        /// The `WebAssembly.Module()` constructor compiles the given bytes
9808        /// synchronously under the given compile options.
9809        ///
9810        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/Module)
9811        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9812        pub fn new_with_options(
9813            buffer_source: &JsValue,
9814            options: &CompileOptions,
9815        ) -> Result<Module, JsValue>;
9816
9817        /// The `WebAssembly.customSections()` function returns a copy of the
9818        /// contents of all custom sections in the given module with the given
9819        /// string name.
9820        ///
9821        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
9822        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
9823        pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
9824
9825        /// The `WebAssembly.exports()` function returns an array containing
9826        /// descriptions of all the declared exports of the given `Module`.
9827        ///
9828        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
9829        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
9830        pub fn exports(module: &Module) -> Array;
9831
9832        /// The `WebAssembly.imports()` function returns an array containing
9833        /// descriptions of all the declared imports of the given `Module`.
9834        ///
9835        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
9836        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
9837        pub fn imports(module: &Module) -> Array;
9838    }
9839
9840    // WebAssembly.Table
9841    #[wasm_bindgen]
9842    extern "C" {
9843        /// The `WebAssembly.Table()` constructor creates a new `Table` object
9844        /// of the given size and element type.
9845        ///
9846        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
9847        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
9848        #[derive(Clone, Debug, PartialEq, Eq)]
9849        pub type Table;
9850
9851        /// The `WebAssembly.Table()` constructor creates a new `Table` object
9852        /// of the given size and element type.
9853        ///
9854        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
9855        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9856        pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
9857
9858        /// The `WebAssembly.Table()` constructor creates a new `Table` object
9859        /// of the given size and element type.
9860        ///
9861        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
9862        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9863        pub fn new_with_value(table_descriptor: &Object, value: JsValue) -> Result<Table, JsValue>;
9864
9865        /// The length prototype property of the `WebAssembly.Table` object
9866        /// returns the length of the table, i.e. the number of elements in the
9867        /// table.
9868        ///
9869        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
9870        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
9871        pub fn length(this: &Table) -> u32;
9872
9873        /// The `get()` prototype method of the `WebAssembly.Table()` object
9874        /// retrieves a function reference stored at a given index.
9875        ///
9876        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
9877        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
9878        pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
9879
9880        /// The `get()` prototype method of the `WebAssembly.Table()` object
9881        /// retrieves a function reference stored at a given index.
9882        ///
9883        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
9884        #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = get)]
9885        pub fn get_raw(this: &Table, index: u32) -> Result<JsValue, JsValue>;
9886
9887        /// The `grow()` prototype method of the `WebAssembly.Table` object
9888        /// increases the size of the `Table` instance by a specified number of
9889        /// elements.
9890        ///
9891        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
9892        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
9893        pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
9894
9895        /// The `grow()` prototype method of the `WebAssembly.Table` object
9896        /// increases the size of the `Table` instance by a specified number of
9897        /// elements.
9898        ///
9899        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
9900        #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = grow)]
9901        pub fn grow_with_value(
9902            this: &Table,
9903            additional_capacity: u32,
9904            value: JsValue,
9905        ) -> Result<u32, JsValue>;
9906
9907        /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
9908        /// reference stored at a given index to a different value.
9909        ///
9910        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
9911        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
9912        pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
9913
9914        /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
9915        /// reference stored at a given index to a different value.
9916        ///
9917        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
9918        #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = set)]
9919        pub fn set_raw(this: &Table, index: u32, value: &JsValue) -> Result<(), JsValue>;
9920    }
9921
9922    // WebAssembly.Tag
9923    #[wasm_bindgen]
9924    extern "C" {
9925        /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
9926        ///
9927        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
9928        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
9929        #[derive(Clone, Debug, PartialEq, Eq)]
9930        pub type Tag;
9931
9932        /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
9933        ///
9934        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
9935        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9936        pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
9937    }
9938
9939    // WebAssembly.Exception
9940    #[wasm_bindgen]
9941    extern "C" {
9942        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
9943        ///
9944        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
9945        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
9946        #[derive(Clone, Debug, PartialEq, Eq)]
9947        pub type Exception;
9948
9949        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
9950        ///
9951        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
9952        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9953        pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
9954
9955        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
9956        ///
9957        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
9958        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9959        pub fn new_with_options(
9960            tag: &Tag,
9961            payload: &Array,
9962            options: &Object,
9963        ) -> Result<Exception, JsValue>;
9964
9965        /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
9966        /// test if the Exception matches a given tag.
9967        ///
9968        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
9969        #[wasm_bindgen(method, js_namespace = WebAssembly)]
9970        pub fn is(this: &Exception, tag: &Tag) -> bool;
9971
9972        /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
9973        /// to get the value of a specified item in the exception's data arguments
9974        ///
9975        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
9976        #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
9977        pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
9978
9979        /// The `stack` property holds a stack trace when the exception was
9980        /// created with `{ traceStack: true }`, and is `undefined`
9981        /// otherwise.
9982        ///
9983        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/stack)
9984        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
9985        pub fn stack(this: &Exception) -> Option<JsString>;
9986    }
9987
9988    // WebAssembly.Global
9989    #[wasm_bindgen]
9990    extern "C" {
9991        /// The `WebAssembly.Global()` constructor creates a new `Global` object
9992        /// of the given type and value.
9993        ///
9994        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
9995        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
9996        #[derive(Clone, Debug, PartialEq, Eq)]
9997        pub type Global;
9998
9999        /// The `WebAssembly.Global()` constructor creates a new `Global` object
10000        /// of the given type and value.
10001        ///
10002        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
10003        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
10004        pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
10005
10006        /// The value prototype property of the `WebAssembly.Global` object
10007        /// returns the value of the global.
10008        ///
10009        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
10010        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
10011        pub fn value(this: &Global) -> JsValue;
10012        #[wasm_bindgen(method, setter = value, js_namespace = WebAssembly)]
10013        pub fn set_value(this: &Global, value: &JsValue);
10014
10015        /// The `valueOf()` method returns the global's current value.
10016        ///
10017        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/valueOf)
10018        #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = valueOf)]
10019        pub fn value_of(this: &Global) -> JsValue;
10020    }
10021
10022    // WebAssembly.Memory
10023    #[wasm_bindgen]
10024    extern "C" {
10025        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
10026        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
10027        #[derive(Clone, Debug, PartialEq, Eq)]
10028        pub type Memory;
10029
10030        /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
10031        /// which is a resizable `ArrayBuffer` that holds the raw bytes of
10032        /// memory accessed by a WebAssembly `Instance`.
10033        ///
10034        /// A memory created by JavaScript or in WebAssembly code will be
10035        /// accessible and mutable from both JavaScript and WebAssembly.
10036        ///
10037        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
10038        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
10039        pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
10040
10041        /// An accessor property that returns the buffer contained in the
10042        /// memory.
10043        ///
10044        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
10045        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
10046        pub fn buffer(this: &Memory) -> JsValue;
10047
10048        /// The `grow()` prototype method of the `Memory` object increases the
10049        /// size of the memory instance by a specified number of WebAssembly
10050        /// pages.
10051        ///
10052        /// Takes the number of pages to grow (64KiB in size) and returns the
10053        /// previous size of memory, in pages.
10054        ///
10055        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
10056        #[wasm_bindgen(method, js_namespace = WebAssembly)]
10057        pub fn grow(this: &Memory, pages: u32) -> u32;
10058
10059        /// The `toResizableBuffer()` method makes `buffer` a resizable
10060        /// `ArrayBuffer` (or growable `SharedArrayBuffer`) that tracks the
10061        /// memory as it grows, and returns it. Throws a `TypeError` if the
10062        /// memory has no maximum size.
10063        ///
10064        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/toResizableBuffer)
10065        #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = toResizableBuffer, catch)]
10066        pub fn to_resizable_buffer(this: &Memory) -> Result<JsValue, JsValue>;
10067
10068        /// The `toFixedLengthBuffer()` method makes `buffer` a fixed-length
10069        /// `ArrayBuffer` (or `SharedArrayBuffer`) again, detaching the
10070        /// previous one, and returns it.
10071        ///
10072        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/toFixedLengthBuffer)
10073        #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = toFixedLengthBuffer, catch)]
10074        pub fn to_fixed_length_buffer(this: &Memory) -> Result<JsValue, JsValue>;
10075    }
10076
10077    // WebAssembly.Suspending / WebAssembly.promising (JSPI — JS Promise Integration)
10078    #[wasm_bindgen]
10079    extern "C" {
10080        /// A `WebAssembly.Suspending` object wraps a JavaScript async function
10081        /// so it can be used as a WebAssembly import under
10082        /// [JSPI (JS Promise Integration)][jspi].
10083        ///
10084        /// When WASM calls a `Suspending`-wrapped import that returns a
10085        /// `Promise`, the WASM fiber suspends until the promise settles; the
10086        /// resolved value is then returned to WASM as if the call had returned
10087        /// synchronously.  The browser's event loop is **not** blocked.
10088        ///
10089        /// [jspi]: https://github.com/WebAssembly/js-promise-integration
10090        ///
10091        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Suspending)
10092        #[wasm_bindgen(
10093            js_namespace = WebAssembly,
10094            extends = Object,
10095            typescript_type = "WebAssembly.Suspending"
10096        )]
10097        #[derive(Clone, Debug, PartialEq, Eq)]
10098        pub type Suspending;
10099
10100        /// Wraps `func` (an async function) in a `WebAssembly.Suspending` object.
10101        ///
10102        /// Pass the returned object as a WASM import.  Every call to that
10103        /// import from WASM will suspend the current fiber and resume it with
10104        /// the resolved value once `func`'s returned `Promise` settles.
10105        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
10106        pub fn new(func: &Function) -> Suspending;
10107
10108        /// Wraps a WebAssembly exported `Function` so that calling it returns a
10109        /// `Promise` and enables JSPI suspension inside.
10110        ///
10111        /// Use `WebAssembly.promising` to obtain a "promising" wrapper around a
10112        /// raw WASM export; any JSPI suspensions that occur while the function
10113        /// executes will resolve the returned `Promise` when the fiber finishes.
10114        ///
10115        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/promising)
10116        #[wasm_bindgen(js_namespace = WebAssembly)]
10117        pub fn promising(func: &Function) -> Function;
10118    }
10119}
10120
10121/// The `JSON` object contains methods for parsing [JavaScript Object
10122/// Notation (JSON)](https://json.org/) and converting values to JSON. It
10123/// can't be called or constructed, and aside from its two method
10124/// properties, it has no interesting functionality of its own.
10125#[allow(non_snake_case)]
10126pub mod JSON {
10127    use super::*;
10128
10129    // JSON
10130    #[wasm_bindgen]
10131    extern "C" {
10132        /// The `JSON.parse()` method parses a JSON string, constructing the
10133        /// JavaScript value or object described by the string.
10134        ///
10135        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
10136        #[wasm_bindgen(catch, js_namespace = JSON)]
10137        pub fn parse(text: &str) -> Result<JsValue, JsValue>;
10138
10139        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
10140        ///
10141        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
10142        #[cfg(not(js_sys_unstable_apis))]
10143        #[wasm_bindgen(catch, js_namespace = JSON)]
10144        pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
10145
10146        /// The `JSON.rawJSON()` method creates a raw JSON object whose text
10147        /// is emitted verbatim by `JSON.stringify()`, allowing values such
10148        /// as large integers to round-trip without precision loss. Throws
10149        /// a `SyntaxError` unless `text` is valid JSON for a primitive.
10150        ///
10151        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/rawJSON)
10152        #[wasm_bindgen(catch, js_namespace = JSON, js_name = rawJSON)]
10153        pub fn raw_json(text: &str) -> Result<Object, JsValue>;
10154
10155        /// The `JSON.isRawJSON()` method returns whether a value is a raw
10156        /// JSON object created by `JSON.rawJSON()`.
10157        ///
10158        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/isRawJSON)
10159        #[wasm_bindgen(js_namespace = JSON, js_name = isRawJSON)]
10160        pub fn is_raw_json(value: &JsValue) -> bool;
10161
10162        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
10163        ///
10164        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
10165        ///
10166        /// `None` when `obj` has no JSON form (`undefined`, a function, a
10167        /// symbol).
10168        #[cfg(js_sys_unstable_apis)]
10169        #[wasm_bindgen(catch, js_namespace = JSON)]
10170        pub fn stringify(obj: &JsValue) -> Result<Option<String>, JsValue>;
10171
10172        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
10173        ///
10174        /// The `replacer` argument is a function that alters the behavior of the stringification
10175        /// process, or an array of String and Number objects that serve as a whitelist
10176        /// for selecting/filtering the properties of the value object to be included
10177        /// in the JSON string. If this value is null or not provided, all properties
10178        /// of the object are included in the resulting JSON string.
10179        ///
10180        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
10181        #[cfg(not(js_sys_unstable_apis))]
10182        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
10183        pub fn stringify_with_replacer(
10184            obj: &JsValue,
10185            replacer: &JsValue,
10186        ) -> Result<JsString, JsValue>;
10187
10188        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
10189        ///
10190        /// The `replacer` argument is a function that alters the behavior of the stringification
10191        /// process, or an array of String and Number objects that serve as a whitelist
10192        /// for selecting/filtering the properties of the value object to be included
10193        /// in the JSON string. If this value is null or not provided, all properties
10194        /// of the object are included in the resulting JSON string.
10195        ///
10196        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
10197        #[cfg(js_sys_unstable_apis)]
10198        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
10199        pub fn stringify_with_replacer<'a>(
10200            obj: &JsValue,
10201            replacer: &mut dyn FnMut(String, JsValue) -> Result<Option<JsValue>, JsError>,
10202            space: Option<u32>,
10203        ) -> Result<Option<String>, JsValue>;
10204
10205        // Next major: deprecate
10206        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
10207        ///
10208        /// The `replacer` argument is a function that alters the behavior of the stringification
10209        /// process, or an array of String and Number objects that serve as a whitelist
10210        /// for selecting/filtering the properties of the value object to be included
10211        /// in the JSON string. If this value is null or not provided, all properties
10212        /// of the object are included in the resulting JSON string.
10213        ///
10214        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
10215        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
10216        pub fn stringify_with_replacer_func<'a>(
10217            obj: &JsValue,
10218            replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
10219            space: Option<u32>,
10220        ) -> Result<JsString, JsValue>;
10221
10222        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
10223        ///
10224        /// The `replacer` argument is a function that alters the behavior of the stringification
10225        /// process, or an array of String and Number objects that serve as a whitelist
10226        /// for selecting/filtering the properties of the value object to be included
10227        /// in the JSON string. If this value is null or not provided, all properties
10228        /// of the object are included in the resulting JSON string.
10229        ///
10230        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
10231        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
10232        pub fn stringify_with_replacer_list(
10233            obj: &JsValue,
10234            replacer: Vec<String>,
10235            space: Option<u32>,
10236        ) -> Result<JsString, JsValue>;
10237
10238        // Next major: deprecate
10239        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
10240        ///
10241        /// The `replacer` argument is a function that alters the behavior of the stringification
10242        /// process, or an array of String and Number objects that serve as a whitelist
10243        /// for selecting/filtering the properties of the value object to be included
10244        /// in the JSON string. If this value is null or not provided, all properties
10245        /// of the object are included in the resulting JSON string.
10246        ///
10247        /// The `space` argument is a String or Number object that's used to insert white space into
10248        /// the output JSON string for readability purposes. If this is a Number, it
10249        /// indicates the number of space characters to use as white space; this number
10250        /// is capped at 10 (if it is greater, the value is just 10). Values less than
10251        /// 1 indicate that no space should be used. If this is a String, the string
10252        /// (or the first 10 characters of the string, if it's longer than that) is
10253        /// used as white space. If this parameter is not provided (or is null), no
10254        /// white space is used.
10255        ///
10256        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
10257        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
10258        pub fn stringify_with_replacer_and_space(
10259            obj: &JsValue,
10260            replacer: &JsValue,
10261            space: &JsValue,
10262        ) -> Result<JsString, JsValue>;
10263    }
10264}
10265// JsString
10266#[wasm_bindgen]
10267extern "C" {
10268    #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
10269    #[derive(Clone, PartialEq, Eq)]
10270    pub type JsString;
10271
10272    /// The length property of a String object indicates the length of a string,
10273    /// in UTF-16 code units.
10274    ///
10275    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
10276    #[wasm_bindgen(method, getter)]
10277    pub fn length(this: &JsString) -> u32;
10278
10279    /// The 'at()' method returns a new string consisting of the single UTF-16
10280    /// code unit located at the specified offset into the string, counting from
10281    /// the end if it's negative.
10282    ///
10283    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
10284    #[wasm_bindgen(method, js_class = "String")]
10285    pub fn at(this: &JsString, index: i32) -> Option<JsString>;
10286
10287    /// The String object's `charAt()` method returns a new string consisting of
10288    /// the single UTF-16 code unit located at the specified offset into the
10289    /// string.
10290    ///
10291    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
10292    #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
10293    pub fn char_at(this: &JsString, index: u32) -> JsString;
10294
10295    /// The `charCodeAt()` method returns an integer between 0 and 65535
10296    /// representing the UTF-16 code unit at the given index (the UTF-16 code
10297    /// unit matches the Unicode code point for code points representable in a
10298    /// single UTF-16 code unit, but might also be the first code unit of a
10299    /// surrogate pair for code points not representable in a single UTF-16 code
10300    /// unit, e.g. Unicode code points > 0x10000).  If you want the entire code
10301    /// point value, use `codePointAt()`.
10302    ///
10303    /// Returns `NaN` if index is out of range.
10304    ///
10305    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
10306    #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
10307    pub fn char_code_at(this: &JsString, index: u32) -> f64;
10308
10309    /// The `codePointAt()` method returns a non-negative integer that is the
10310    /// Unicode code point value.
10311    ///
10312    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
10313    #[cfg(not(js_sys_unstable_apis))]
10314    #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
10315    pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
10316
10317    /// The `codePointAt()` method returns a non-negative integer that is the
10318    /// Unicode code point value.
10319    ///
10320    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
10321    #[cfg(js_sys_unstable_apis)]
10322    #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
10323    pub fn code_point_at(this: &JsString, pos: u32) -> Option<u32>;
10324
10325    // Next major: deprecate
10326    /// The `codePointAt()` method returns a non-negative integer that is the
10327    /// Unicode code point value.
10328    ///
10329    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
10330    #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
10331    pub fn try_code_point_at(this: &JsString, pos: u32) -> Option<u16>;
10332
10333    /// The `concat()` method concatenates the string arguments to the calling
10334    /// string and returns a new string.
10335    ///
10336    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
10337    #[cfg(not(js_sys_unstable_apis))]
10338    #[wasm_bindgen(method, js_class = "String")]
10339    pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
10340
10341    /// The `concat()` method concatenates the string arguments to the calling
10342    /// string and returns a new string.
10343    ///
10344    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
10345    #[cfg(js_sys_unstable_apis)]
10346    #[wasm_bindgen(method, js_class = "String")]
10347    pub fn concat(this: &JsString, string: &JsString) -> JsString;
10348
10349    /// The `concat()` method concatenates the string arguments to the calling
10350    /// string and returns a new string.
10351    ///
10352    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
10353    #[wasm_bindgen(method, js_class = "String")]
10354    pub fn concat_many(this: &JsString, strings: &[JsString]) -> JsString;
10355
10356    /// The `endsWith()` method determines whether a string ends with the characters of a
10357    /// specified string, returning true or false as appropriate.
10358    ///
10359    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
10360    #[cfg(not(js_sys_unstable_apis))]
10361    #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
10362    pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
10363
10364    /// The `endsWith()` method determines whether a string ends with the characters of a
10365    /// specified string, returning true or false as appropriate.
10366    ///
10367    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
10368    #[cfg(js_sys_unstable_apis)]
10369    #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
10370    pub fn ends_with(this: &JsString, search_string: &str) -> bool;
10371
10372    /// The static `String.fromCharCode()` method returns a string created from
10373    /// the specified sequence of UTF-16 code units.
10374    ///
10375    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10376    ///
10377    /// # Notes
10378    ///
10379    /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
10380    /// with different arities.
10381    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
10382    pub fn from_char_code(char_codes: &[u16]) -> JsString;
10383
10384    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10385    #[cfg(not(js_sys_unstable_apis))]
10386    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10387    pub fn from_char_code1(a: u32) -> JsString;
10388
10389    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10390    #[cfg(js_sys_unstable_apis)]
10391    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10392    pub fn from_char_code1(a: u16) -> JsString;
10393
10394    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10395    #[cfg(not(js_sys_unstable_apis))]
10396    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10397    pub fn from_char_code2(a: u32, b: u32) -> JsString;
10398
10399    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10400    #[cfg(js_sys_unstable_apis)]
10401    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10402    pub fn from_char_code2(a: u16, b: u16) -> JsString;
10403
10404    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10405    #[cfg(not(js_sys_unstable_apis))]
10406    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10407    pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
10408
10409    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10410    #[cfg(js_sys_unstable_apis)]
10411    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10412    pub fn from_char_code3(a: u16, b: u16, c: u16) -> JsString;
10413
10414    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10415    #[cfg(not(js_sys_unstable_apis))]
10416    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10417    pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
10418
10419    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10420    #[cfg(js_sys_unstable_apis)]
10421    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10422    pub fn from_char_code4(a: u16, b: u16, c: u16, d: u16) -> JsString;
10423
10424    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10425    #[cfg(not(js_sys_unstable_apis))]
10426    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10427    pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
10428
10429    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
10430    #[cfg(js_sys_unstable_apis)]
10431    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
10432    pub fn from_char_code5(a: u16, b: u16, c: u16, d: u16, e: u16) -> JsString;
10433
10434    /// The static `String.fromCodePoint()` method returns a string created by
10435    /// using the specified sequence of code points.
10436    ///
10437    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
10438    ///
10439    /// # Exceptions
10440    ///
10441    /// A RangeError is thrown if an invalid Unicode code point is given
10442    ///
10443    /// # Notes
10444    ///
10445    /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
10446    /// with different arities.
10447    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
10448    pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
10449
10450    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
10451    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
10452    pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
10453
10454    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
10455    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
10456    pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
10457
10458    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
10459    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
10460    pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
10461
10462    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
10463    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
10464    pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
10465
10466    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
10467    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
10468    pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
10469
10470    /// The `includes()` method determines whether one string may be found
10471    /// within another string, returning true or false as appropriate.
10472    ///
10473    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
10474    #[wasm_bindgen(method, js_class = "String")]
10475    pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
10476
10477    /// The `indexOf()` method returns the index within the calling String
10478    /// object of the first occurrence of the specified value, starting the
10479    /// search at fromIndex.  Returns -1 if the value is not found.
10480    ///
10481    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
10482    #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
10483    pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
10484
10485    /// The `lastIndexOf()` method returns the index within the calling String
10486    /// object of the last occurrence of the specified value, searching
10487    /// backwards from fromIndex.  Returns -1 if the value is not found.
10488    ///
10489    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
10490    #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
10491    pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
10492
10493    /// The `localeCompare()` method returns a number indicating whether
10494    /// a reference string comes before or after or is the same as
10495    /// the given string in sort order.
10496    ///
10497    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
10498    #[cfg(not(js_sys_unstable_apis))]
10499    #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
10500    pub fn locale_compare(
10501        this: &JsString,
10502        compare_string: &str,
10503        locales: &Array,
10504        options: &Object,
10505    ) -> i32;
10506
10507    /// The `localeCompare()` method returns a number indicating whether
10508    /// a reference string comes before or after or is the same as
10509    /// the given string in sort order.
10510    ///
10511    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
10512    #[cfg(js_sys_unstable_apis)]
10513    #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
10514    pub fn locale_compare(
10515        this: &JsString,
10516        compare_string: &str,
10517        locales: &[JsString],
10518        options: &Intl::CollatorOptions,
10519    ) -> i32;
10520
10521    /// The `match()` method retrieves the matches when matching a string against a regular expression.
10522    /// Returns a result array, or null.
10523    ///
10524    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
10525    #[cfg(not(js_sys_unstable_apis))]
10526    #[wasm_bindgen(method, js_class = "String", js_name = match)]
10527    pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
10528    /// The `match()` method retrieves the matches when matching a string against a regular expression.
10529    /// Returns a result array, or null.
10530    ///
10531    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
10532    #[cfg(js_sys_unstable_apis)]
10533    #[wasm_bindgen(method, js_class = "String", js_name = match)]
10534    pub fn match_(this: &JsString, pattern: &RegExp) -> Nullable<Object>;
10535
10536    /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
10537    ///
10538    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
10539    #[cfg(not(js_sys_unstable_apis))]
10540    #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
10541    pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
10542
10543    /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
10544    ///
10545    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
10546    #[cfg(js_sys_unstable_apis)]
10547    #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
10548    pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator<RegExpMatchArray>;
10549
10550    /// The `normalize()` method returns the Unicode Normalization Form
10551    /// of a given string (if the value isn't a string, it will be converted to one first).
10552    ///
10553    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
10554    #[wasm_bindgen(method, js_class = "String")]
10555    pub fn normalize(this: &JsString, form: &str) -> JsString;
10556
10557    /// The `padEnd()` method pads the current string with a given string
10558    /// (repeated, if needed) so that the resulting string reaches a given
10559    /// length. The padding is applied from the end (right) of the current
10560    /// string.
10561    ///
10562    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
10563    #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
10564    pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
10565
10566    /// The `padStart()` method pads the current string with another string
10567    /// (repeated, if needed) so that the resulting string reaches the given
10568    /// length. The padding is applied from the start (left) of the current
10569    /// string.
10570    ///
10571    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
10572    #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
10573    pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
10574
10575    /// The `repeat()` method constructs and returns a new string which contains the specified
10576    /// number of copies of the string on which it was called, concatenated together.
10577    ///
10578    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
10579    #[wasm_bindgen(method, js_class = "String")]
10580    pub fn repeat(this: &JsString, count: i32) -> JsString;
10581
10582    /// The `replace()` method returns a new string with some or all matches of a pattern
10583    /// replaced by a replacement. The pattern can be a string or a RegExp, and
10584    /// the replacement can be a string or a function to be called for each match.
10585    ///
10586    /// Note: The original string will remain unchanged.
10587    ///
10588    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
10589    #[wasm_bindgen(method, js_class = "String")]
10590    pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
10591
10592    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
10593    #[cfg(not(js_sys_unstable_apis))]
10594    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
10595    pub fn replace_with_function(
10596        this: &JsString,
10597        pattern: &str,
10598        replacement: &Function,
10599    ) -> JsString;
10600
10601    /// The replacer function signature is `(match, offset, string) -> replacement`
10602    /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
10603    /// when capture groups are present.
10604    ///
10605    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
10606    #[cfg(js_sys_unstable_apis)]
10607    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
10608    pub fn replace_with_function(
10609        this: &JsString,
10610        pattern: &str,
10611        replacement: &Function<fn(JsString) -> JsString>,
10612    ) -> JsString;
10613
10614    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
10615    pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
10616
10617    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
10618    #[cfg(not(js_sys_unstable_apis))]
10619    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
10620    pub fn replace_by_pattern_with_function(
10621        this: &JsString,
10622        pattern: &RegExp,
10623        replacement: &Function,
10624    ) -> JsString;
10625
10626    /// The replacer function signature is `(match, offset, string) -> replacement`
10627    /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
10628    /// when capture groups are present.
10629    ///
10630    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
10631    #[cfg(js_sys_unstable_apis)]
10632    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
10633    pub fn replace_by_pattern_with_function(
10634        this: &JsString,
10635        pattern: &RegExp,
10636        replacement: &Function<fn(JsString) -> JsString>,
10637    ) -> JsString;
10638
10639    /// The `replace_all()` method returns a new string with all matches of a pattern
10640    /// replaced by a replacement. The pattern can be a string or a global RegExp, and
10641    /// the replacement can be a string or a function to be called for each match.
10642    ///
10643    /// Note: The original string will remain unchanged.
10644    ///
10645    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
10646    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
10647    pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
10648
10649    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
10650    #[cfg(not(js_sys_unstable_apis))]
10651    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
10652    pub fn replace_all_with_function(
10653        this: &JsString,
10654        pattern: &str,
10655        replacement: &Function,
10656    ) -> JsString;
10657
10658    /// The replacer function signature is `(match, offset, string) -> replacement`
10659    /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
10660    /// when capture groups are present.
10661    ///
10662    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
10663    #[cfg(js_sys_unstable_apis)]
10664    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
10665    pub fn replace_all_with_function(
10666        this: &JsString,
10667        pattern: &str,
10668        replacement: &Function<fn(JsString) -> JsString>,
10669    ) -> JsString;
10670
10671    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
10672    pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
10673        -> JsString;
10674
10675    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
10676    #[cfg(not(js_sys_unstable_apis))]
10677    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
10678    pub fn replace_all_by_pattern_with_function(
10679        this: &JsString,
10680        pattern: &RegExp,
10681        replacement: &Function,
10682    ) -> JsString;
10683
10684    /// The replacer function signature is `(match, offset, string) -> replacement`
10685    /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
10686    /// when capture groups are present.
10687    ///
10688    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
10689    #[cfg(js_sys_unstable_apis)]
10690    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
10691    pub fn replace_all_by_pattern_with_function(
10692        this: &JsString,
10693        pattern: &RegExp,
10694        replacement: &Function<fn(JsString) -> JsString>,
10695    ) -> JsString;
10696
10697    /// The `search()` method executes a search for a match between
10698    /// a regular expression and this String object.
10699    ///
10700    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
10701    #[wasm_bindgen(method, js_class = "String")]
10702    pub fn search(this: &JsString, pattern: &RegExp) -> i32;
10703
10704    /// The `slice()` method extracts a section of a string and returns it as a
10705    /// new string, without modifying the original string.
10706    ///
10707    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
10708    #[wasm_bindgen(method, js_class = "String")]
10709    pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
10710
10711    /// The `split()` method splits a String object into an array of strings by separating the string
10712    /// into substrings, using a specified separator string to determine where to make each split.
10713    ///
10714    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
10715    #[wasm_bindgen(method, js_class = "String")]
10716    pub fn split(this: &JsString, separator: &str) -> Array;
10717
10718    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
10719    #[wasm_bindgen(method, js_class = "String", js_name = split)]
10720    pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
10721
10722    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
10723    #[wasm_bindgen(method, js_class = "String", js_name = split)]
10724    pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
10725
10726    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
10727    #[wasm_bindgen(method, js_class = "String", js_name = split)]
10728    pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
10729
10730    /// The `startsWith()` method determines whether a string begins with the
10731    /// characters of a specified string, returning true or false as
10732    /// appropriate.
10733    ///
10734    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
10735    #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
10736    pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
10737
10738    /// The `substring()` method returns the part of the string between the
10739    /// start and end indexes, or to the end of the string.
10740    ///
10741    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
10742    #[wasm_bindgen(method, js_class = "String")]
10743    pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
10744
10745    /// The `substr()` method returns the part of a string between
10746    /// the start index and a number of characters after it.
10747    ///
10748    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
10749    #[wasm_bindgen(method, js_class = "String")]
10750    pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
10751
10752    /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
10753    /// according to any locale-specific case mappings.
10754    ///
10755    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
10756    #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
10757    pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
10758
10759    /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
10760    /// according to any locale-specific case mappings.
10761    ///
10762    /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
10763    #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
10764    pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
10765
10766    /// The `toLowerCase()` method returns the calling string value
10767    /// converted to lower case.
10768    ///
10769    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
10770    #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
10771    pub fn to_lower_case(this: &JsString) -> JsString;
10772
10773    /// The `toString()` method returns a string representing the specified
10774    /// object.
10775    ///
10776    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
10777    #[cfg(not(js_sys_unstable_apis))]
10778    #[wasm_bindgen(method, js_class = "String", js_name = toString)]
10779    pub fn to_string(this: &JsString) -> JsString;
10780
10781    /// The `toUpperCase()` method returns the calling string value converted to
10782    /// uppercase (the value will be converted to a string if it isn't one).
10783    ///
10784    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
10785    #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
10786    pub fn to_upper_case(this: &JsString) -> JsString;
10787
10788    /// The `trim()` method removes whitespace from both ends of a string.
10789    /// Whitespace in this context is all the whitespace characters (space, tab,
10790    /// no-break space, etc.) and all the line terminator characters (LF, CR,
10791    /// etc.).
10792    ///
10793    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
10794    #[wasm_bindgen(method, js_class = "String")]
10795    pub fn trim(this: &JsString) -> JsString;
10796
10797    /// The `isWellFormed()` method returns whether this string contains no
10798    /// lone surrogates.
10799    ///
10800    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/isWellFormed)
10801    #[wasm_bindgen(method, js_class = "String", js_name = isWellFormed)]
10802    pub fn is_well_formed(this: &JsString) -> bool;
10803
10804    /// The `toWellFormed()` method returns a copy of this string with every
10805    /// lone surrogate replaced by U+FFFD.
10806    ///
10807    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toWellFormed)
10808    #[wasm_bindgen(method, js_class = "String", js_name = toWellFormed)]
10809    pub fn to_well_formed(this: &JsString) -> JsString;
10810
10811    /// The `trimEnd()` method removes whitespace from the end of a string.
10812    /// `trimRight()` is an alias of this method.
10813    ///
10814    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
10815    #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
10816    pub fn trim_end(this: &JsString) -> JsString;
10817
10818    /// The `trimEnd()` method removes whitespace from the end of a string.
10819    /// `trimRight()` is an alias of this method.
10820    ///
10821    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
10822    #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
10823    pub fn trim_right(this: &JsString) -> JsString;
10824
10825    /// The `trimStart()` method removes whitespace from the beginning of a
10826    /// string. `trimLeft()` is an alias of this method.
10827    ///
10828    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
10829    #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
10830    pub fn trim_start(this: &JsString) -> JsString;
10831
10832    /// The `trimStart()` method removes whitespace from the beginning of a
10833    /// string. `trimLeft()` is an alias of this method.
10834    ///
10835    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
10836    #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
10837    pub fn trim_left(this: &JsString) -> JsString;
10838
10839    /// The `valueOf()` method returns the primitive value of a `String` object.
10840    ///
10841    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
10842    #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
10843    pub fn value_of(this: &JsString) -> JsString;
10844
10845    /// The static `raw()` method is a tag function of template literals,
10846    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10847    ///
10848    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10849    #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
10850    pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
10851
10852    /// The static `raw()` method is a tag function of template literals,
10853    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10854    ///
10855    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10856    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10857    pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
10858
10859    /// The static `raw()` method is a tag function of template literals,
10860    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10861    ///
10862    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10863    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10864    pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
10865
10866    /// The static `raw()` method is a tag function of template literals,
10867    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10868    ///
10869    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10870    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10871    pub fn raw_2(
10872        call_site: &Object,
10873        substitutions1: &str,
10874        substitutions2: &str,
10875    ) -> Result<JsString, JsValue>;
10876
10877    /// The static `raw()` method is a tag function of template literals,
10878    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10879    ///
10880    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10881    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10882    pub fn raw_3(
10883        call_site: &Object,
10884        substitutions1: &str,
10885        substitutions2: &str,
10886        substitutions3: &str,
10887    ) -> Result<JsString, JsValue>;
10888
10889    /// The static `raw()` method is a tag function of template literals,
10890    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10891    ///
10892    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10893    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10894    pub fn raw_4(
10895        call_site: &Object,
10896        substitutions1: &str,
10897        substitutions2: &str,
10898        substitutions3: &str,
10899        substitutions4: &str,
10900    ) -> Result<JsString, JsValue>;
10901
10902    /// The static `raw()` method is a tag function of template literals,
10903    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10904    ///
10905    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10906    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10907    pub fn raw_5(
10908        call_site: &Object,
10909        substitutions1: &str,
10910        substitutions2: &str,
10911        substitutions3: &str,
10912        substitutions4: &str,
10913        substitutions5: &str,
10914    ) -> Result<JsString, JsValue>;
10915
10916    /// The static `raw()` method is a tag function of template literals,
10917    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10918    ///
10919    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10920    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10921    pub fn raw_6(
10922        call_site: &Object,
10923        substitutions1: &str,
10924        substitutions2: &str,
10925        substitutions3: &str,
10926        substitutions4: &str,
10927        substitutions5: &str,
10928        substitutions6: &str,
10929    ) -> Result<JsString, JsValue>;
10930
10931    /// The static `raw()` method is a tag function of template literals,
10932    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
10933    ///
10934    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
10935    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
10936    pub fn raw_7(
10937        call_site: &Object,
10938        substitutions1: &str,
10939        substitutions2: &str,
10940        substitutions3: &str,
10941        substitutions4: &str,
10942        substitutions5: &str,
10943        substitutions6: &str,
10944        substitutions7: &str,
10945    ) -> Result<JsString, JsValue>;
10946}
10947
10948// These upcasts are non-castable due to the constraints on the function
10949// but the UpcastFrom covariance must still extend through closure types.
10950// (impl UpcastFrom really just means CovariantGeneric relation)
10951impl UpcastFrom<String> for JsString {}
10952impl UpcastFrom<JsString> for String {}
10953
10954impl UpcastFrom<&str> for JsString {}
10955impl UpcastFrom<JsString> for &str {}
10956
10957impl UpcastFrom<char> for JsString {}
10958impl UpcastFrom<JsString> for char {}
10959
10960impl wasm_bindgen::__rt::marker::JsStringLikeSealed for JsString {}
10961impl wasm_bindgen::__rt::marker::JsStringLikeSealed for &JsString {}
10962impl wasm_bindgen::JsStringLike for JsString {}
10963impl wasm_bindgen::JsStringLike for &JsString {}
10964
10965// Each cell is the borrowed handle, which JS reads back without taking it.
10966wasm_bindgen::__wbindgen_encoded_sequence!(&JsString, |s| (*s).into_abi(), [ref_into]);
10967
10968impl JsString {
10969    /// Returns the `JsString` value of this JS value if it's an instance of a
10970    /// string.
10971    ///
10972    /// If this JS value is not an instance of a string then this returns
10973    /// `None`.
10974    #[cfg(not(js_sys_unstable_apis))]
10975    #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
10976    pub fn try_from(val: &JsValue) -> Option<&JsString> {
10977        val.dyn_ref()
10978    }
10979
10980    /// Returns whether this string is a valid UTF-16 string.
10981    ///
10982    /// This is useful for learning whether `String::from(..)` will return a
10983    /// lossless representation of the JS string. If this string contains
10984    /// unpaired surrogates then `String::from` will succeed but it will be a
10985    /// lossy representation of the JS string because unpaired surrogates will
10986    /// become replacement characters.
10987    ///
10988    /// If this function returns `false` then to get a lossless representation
10989    /// of the string you'll need to manually use the `iter` method (or the
10990    /// `char_code_at` accessor) to view the raw character codes.
10991    ///
10992    /// For more information, see the documentation on [JS strings vs Rust
10993    /// strings][docs]
10994    ///
10995    /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
10996    pub fn is_valid_utf16(&self) -> bool {
10997        core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
10998    }
10999
11000    /// Returns an iterator over the `u16` character codes that make up this JS
11001    /// string.
11002    ///
11003    /// This method will call `char_code_at` for each code in this JS string,
11004    /// returning an iterator of the codes in sequence.
11005    pub fn iter(
11006        &self,
11007    ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
11008        (0..self.length()).map(move |i| self.char_code_at(i) as u16)
11009    }
11010
11011    /// If this string consists of a single Unicode code point, then this method
11012    /// converts it into a Rust `char` without doing any allocations.
11013    ///
11014    /// If this JS value is not a valid UTF-8 or consists of more than a single
11015    /// codepoint, then this returns `None`.
11016    ///
11017    /// Note that a single Unicode code point might be represented as more than
11018    /// one code unit on the JavaScript side. For example, a JavaScript string
11019    /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
11020    /// corresponds to a character '𐐷'.
11021    pub fn as_char(&self) -> Option<char> {
11022        let len = self.length();
11023
11024        if len == 0 || len > 2 {
11025            return None;
11026        }
11027
11028        #[cfg(not(js_sys_unstable_apis))]
11029        let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
11030        #[cfg(js_sys_unstable_apis)]
11031        let cp = self.code_point_at(0)?;
11032
11033        let c = core::char::from_u32(cp)?;
11034
11035        if c.len_utf16() as u32 == len {
11036            Some(c)
11037        } else {
11038            None
11039        }
11040    }
11041}
11042
11043impl PartialEq<str> for JsString {
11044    #[allow(clippy::cmp_owned)] // prevent infinite recursion
11045    fn eq(&self, other: &str) -> bool {
11046        String::from(self) == other
11047    }
11048}
11049
11050impl<'a> PartialEq<&'a str> for JsString {
11051    fn eq(&self, other: &&'a str) -> bool {
11052        <JsString as PartialEq<str>>::eq(self, other)
11053    }
11054}
11055
11056impl PartialEq<String> for JsString {
11057    fn eq(&self, other: &String) -> bool {
11058        <JsString as PartialEq<str>>::eq(self, other)
11059    }
11060}
11061
11062impl<'a> PartialEq<&'a String> for JsString {
11063    fn eq(&self, other: &&'a String) -> bool {
11064        <JsString as PartialEq<str>>::eq(self, other)
11065    }
11066}
11067
11068impl Default for JsString {
11069    fn default() -> Self {
11070        Self::from("")
11071    }
11072}
11073
11074impl<'a> From<&'a str> for JsString {
11075    fn from(s: &'a str) -> Self {
11076        JsString::unchecked_from_js(JsValue::from_str(s))
11077    }
11078}
11079
11080impl From<String> for JsString {
11081    fn from(s: String) -> Self {
11082        From::from(&*s)
11083    }
11084}
11085
11086impl From<char> for JsString {
11087    #[inline]
11088    fn from(c: char) -> Self {
11089        JsString::from_code_point1(c as u32).unwrap_throw()
11090    }
11091}
11092
11093impl<'a> From<&'a JsString> for String {
11094    fn from(s: &'a JsString) -> Self {
11095        s.obj.as_string().unwrap_throw()
11096    }
11097}
11098
11099impl From<JsString> for String {
11100    fn from(s: JsString) -> Self {
11101        From::from(&s)
11102    }
11103}
11104
11105impl fmt::Debug for JsString {
11106    #[inline]
11107    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11108        fmt::Debug::fmt(&String::from(self), f)
11109    }
11110}
11111
11112impl fmt::Display for JsString {
11113    #[inline]
11114    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11115        fmt::Display::fmt(&String::from(self), f)
11116    }
11117}
11118
11119impl str::FromStr for JsString {
11120    type Err = convert::Infallible;
11121    fn from_str(s: &str) -> Result<Self, Self::Err> {
11122        Ok(JsString::from(s))
11123    }
11124}
11125
11126// Symbol
11127#[wasm_bindgen]
11128extern "C" {
11129    #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
11130    #[derive(Clone, Debug)]
11131    pub type Symbol;
11132
11133    /// The `Symbol.hasInstance` well-known symbol is used to determine
11134    /// if a constructor object recognizes an object as its instance.
11135    /// The `instanceof` operator's behavior can be customized by this symbol.
11136    ///
11137    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
11138    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = hasInstance)]
11139    pub fn has_instance() -> Symbol;
11140
11141    /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
11142    /// if an object should be flattened to its array elements when using the
11143    /// `Array.prototype.concat()` method.
11144    ///
11145    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
11146    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = isConcatSpreadable)]
11147    pub fn is_concat_spreadable() -> Symbol;
11148
11149    /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
11150    /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
11151    ///
11152    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
11153    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncIterator)]
11154    pub fn async_iterator() -> Symbol;
11155
11156    /// The `Symbol.dispose` well-known symbol names the method that
11157    /// disposes a resource, as used by [`DisposableStack`] and `using`.
11158    ///
11159    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/dispose)
11160    #[wasm_bindgen(static_method_of = Symbol, getter)]
11161    pub fn dispose() -> Symbol;
11162
11163    /// The `Symbol.asyncDispose` well-known symbol names the method that
11164    /// asynchronously disposes a resource, as used by
11165    /// [`AsyncDisposableStack`] and `await using`.
11166    ///
11167    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncDispose)
11168    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncDispose)]
11169    pub fn async_dispose() -> Symbol;
11170
11171    /// The `Symbol.iterator` well-known symbol specifies the default iterator
11172    /// for an object.  Used by `for...of`.
11173    ///
11174    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
11175    #[wasm_bindgen(static_method_of = Symbol, getter)]
11176    pub fn iterator() -> Symbol;
11177
11178    /// The `Symbol.match` well-known symbol specifies the matching of a regular
11179    /// expression against a string. This function is called by the
11180    /// `String.prototype.match()` method.
11181    ///
11182    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
11183    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = match)]
11184    pub fn match_() -> Symbol;
11185
11186    /// The `Symbol.replace` well-known symbol specifies the method that
11187    /// replaces matched substrings of a string.  This function is called by the
11188    /// `String.prototype.replace()` method.
11189    ///
11190    /// For more information, see `RegExp.prototype[@@replace]()` and
11191    /// `String.prototype.replace()`.
11192    ///
11193    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
11194    #[wasm_bindgen(static_method_of = Symbol, getter)]
11195    pub fn replace() -> Symbol;
11196
11197    /// The `Symbol.search` well-known symbol specifies the method that returns
11198    /// the index within a string that matches the regular expression.  This
11199    /// function is called by the `String.prototype.search()` method.
11200    ///
11201    /// For more information, see `RegExp.prototype[@@search]()` and
11202    /// `String.prototype.search()`.
11203    ///
11204    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
11205    #[wasm_bindgen(static_method_of = Symbol, getter)]
11206    pub fn search() -> Symbol;
11207
11208    /// The well-known symbol `Symbol.species` specifies a function-valued
11209    /// property that the constructor function uses to create derived objects.
11210    ///
11211    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
11212    #[wasm_bindgen(static_method_of = Symbol, getter)]
11213    pub fn species() -> Symbol;
11214
11215    /// The `Symbol.split` well-known symbol specifies the method that splits a
11216    /// string at the indices that match a regular expression.  This function is
11217    /// called by the `String.prototype.split()` method.
11218    ///
11219    /// For more information, see `RegExp.prototype[@@split]()` and
11220    /// `String.prototype.split()`.
11221    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
11222    #[wasm_bindgen(static_method_of = Symbol, getter)]
11223    pub fn split() -> Symbol;
11224
11225    /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
11226    /// property that is called to convert an object to a corresponding
11227    /// primitive value.
11228    ///
11229    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
11230    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toPrimitive)]
11231    pub fn to_primitive() -> Symbol;
11232
11233    /// The `Symbol.toStringTag` well-known symbol is a string valued property
11234    /// that is used in the creation of the default string description of an
11235    /// object.  It is accessed internally by the `Object.prototype.toString()`
11236    /// method.
11237    ///
11238    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
11239    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toStringTag)]
11240    pub fn to_string_tag() -> Symbol;
11241
11242    /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
11243    /// the given key and returns it if found.
11244    /// Otherwise a new symbol gets created in the global symbol registry with this key.
11245    ///
11246    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
11247    #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
11248    pub fn for_(key: &str) -> Symbol;
11249
11250    /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
11251    ///
11252    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
11253    #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
11254    pub fn key_for(sym: &Symbol) -> JsValue;
11255
11256    // Next major: deprecate
11257    /// The `toString()` method returns a string representing the specified Symbol object.
11258    ///
11259    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
11260    #[cfg(not(js_sys_unstable_apis))]
11261    #[wasm_bindgen(method, js_name = toString)]
11262    pub fn to_string(this: &Symbol) -> JsString;
11263
11264    /// The `toString()` method returns a string representing the specified Symbol object.
11265    ///
11266    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
11267    #[cfg(js_sys_unstable_apis)]
11268    #[wasm_bindgen(method, js_name = toString)]
11269    pub fn to_string(this: &Symbol) -> String;
11270
11271    /// The `toString()` method returns a string representing the specified Symbol object.
11272    ///
11273    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
11274    #[wasm_bindgen(method, js_name = toString)]
11275    pub fn to_js_string(this: &Symbol) -> JsString;
11276
11277    /// The `Symbol.unscopables` well-known symbol is used to specify an object
11278    /// value of whose own and inherited property names are excluded from the
11279    /// with environment bindings of the associated object.
11280    ///
11281    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
11282    #[wasm_bindgen(static_method_of = Symbol, getter)]
11283    pub fn unscopables() -> Symbol;
11284
11285    /// The `valueOf()` method returns the primitive value of a Symbol object.
11286    ///
11287    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
11288    #[wasm_bindgen(method, js_name = valueOf)]
11289    pub fn value_of(this: &Symbol) -> Symbol;
11290
11291    /// The `description` accessor property returns the optional description
11292    /// this symbol was created with.
11293    ///
11294    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/description)
11295    #[wasm_bindgen(method, getter)]
11296    pub fn description(this: &Symbol) -> Option<JsString>;
11297}
11298
11299mod primitive_union_sealed {
11300    /// Seal for the TypeScript primitive-union marker traits.
11301    pub trait Sealed {}
11302}
11303
11304macro_rules! impl_primitive_union_category {
11305    ($trait:path, bigint) => {
11306        impl $trait for i64 {}
11307        impl $trait for u64 {}
11308        impl $trait for i128 {}
11309        impl $trait for u128 {}
11310        impl $trait for BigInt {}
11311        impl $trait for &BigInt {}
11312    };
11313    ($trait:path, boolean) => {
11314        impl $trait for bool {}
11315        impl $trait for Boolean {}
11316        impl $trait for &Boolean {}
11317    };
11318    ($trait:path, number) => {
11319        impl $trait for i8 {}
11320        impl $trait for u8 {}
11321        impl $trait for i16 {}
11322        impl $trait for u16 {}
11323        impl $trait for i32 {}
11324        impl $trait for u32 {}
11325        impl $trait for isize {}
11326        impl $trait for usize {}
11327        impl $trait for f32 {}
11328        impl $trait for f64 {}
11329        impl $trait for Number {}
11330        impl $trait for &Number {}
11331    };
11332    // Mirrors the sealed `wasm_bindgen::JsStringLike` implementations. A
11333    // blanket `impl<T: JsStringLike>` would overlap with the concrete impls
11334    // below, since coherence cannot rule out a foreign trait being implemented
11335    // for `i32` and friends.
11336    ($trait:path, string) => {
11337        impl $trait for String {}
11338        impl $trait for &str {}
11339        impl $trait for &String {}
11340        impl $trait for &alloc::boxed::Box<str> {}
11341        impl $trait for &alloc::borrow::Cow<'_, str> {}
11342        impl $trait for JsString {}
11343        impl $trait for &JsString {}
11344    };
11345    ($trait:path, symbol) => {
11346        impl $trait for Symbol {}
11347        impl $trait for &Symbol {}
11348    };
11349}
11350
11351impl_primitive_union_category!(primitive_union_sealed::Sealed, bigint);
11352impl_primitive_union_category!(primitive_union_sealed::Sealed, boolean);
11353impl_primitive_union_category!(primitive_union_sealed::Sealed, number);
11354impl_primitive_union_category!(primitive_union_sealed::Sealed, string);
11355impl_primitive_union_category!(primitive_union_sealed::Sealed, symbol);
11356
11357macro_rules! primitive_union_category_doc {
11358    (bigint) => {
11359        "- `bigint`: `i64`, `u64`, `i128`, `u128`, [`BigInt`], and `&BigInt`\n"
11360    };
11361    (boolean) => {
11362        "- `boolean`: `bool`, [`Boolean`], and `&Boolean`\n"
11363    };
11364    (number) => {
11365        "- `number`: `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `isize`, `usize`, `f32`, `f64`, [`Number`], and `&Number`\n"
11366    };
11367    (string) => {
11368        "- `string`: `String`, `&str`, `&String`, `&Box<str>`, `&Cow<str>`, \
11369         [`JsString`], and `&JsString` (the \
11370         [`JsStringLike`](wasm_bindgen::JsStringLike) types)\n"
11371    };
11372    (symbol) => {
11373        "- `symbol`: [`Symbol`] and `&Symbol`\n"
11374    };
11375}
11376
11377macro_rules! define_primitive_union_traits {
11378    ($(($(#[$attr:meta])* $name:ident, $typescript:literal, [$($supertrait:ident),*], [$($category:ident),+])),* $(,)?) => {
11379        $(
11380            $(#[$attr])*
11381            #[doc = concat!(
11382                "Marker for Rust parameter types represented by the TypeScript union `",
11383                $typescript,
11384                "`.\n\n",
11385                "Use this trait as a bound on an `experimental_generic_mono` ",
11386                "JavaScript import. Each monomorphisation retains its concrete ",
11387                "ABI representation; this marker only restricts which Rust types ",
11388                "may instantiate the parameter.\n\n",
11389                "The union's primitive categories use these Rust representations:\n\n",
11390                $(primitive_union_category_doc!($category),)+
11391                "\nThis trait is experimental and may change or be removed as ",
11392                "`experimental_generic_mono` evolves."
11393            )]
11394            pub trait $name: IntoWasmAbi + wasm_bindgen::convert::NullableIntoWasmAbi + primitive_union_sealed::Sealed $(+ $supertrait)* {}
11395
11396            $(impl_primitive_union_category!($name, $category);)+
11397        )*
11398    };
11399}
11400
11401// The catalog covers every union of two or more of the primitive categories
11402// with a Rust-native ABI representation (`bigint`, `boolean`, `number`, and
11403// `string`). `symbol` crosses the boundary as an ordinary JS handle, so unions
11404// containing it are better expressed with a `&Symbol` overload; the one
11405// exception is `PropertyKey`, where `symbol` carries semantic identity.
11406define_primitive_union_traits! {
11407    (
11408        JsBigIntOrBooleanOrNumberOrStringLike,
11409        "bigint | boolean | number | string",
11410        [],
11411        [bigint, boolean, number, string]
11412    ),
11413    (
11414        JsBigIntOrBooleanOrNumberLike,
11415        "bigint | boolean | number",
11416        [JsBigIntOrBooleanOrNumberOrStringLike],
11417        [bigint, boolean, number]
11418    ),
11419    (
11420        JsBigIntOrBooleanOrStringLike,
11421        "bigint | boolean | string",
11422        [JsBigIntOrBooleanOrNumberOrStringLike],
11423        [bigint, boolean, string]
11424    ),
11425    (
11426        JsBigIntOrNumberOrStringLike,
11427        "bigint | number | string",
11428        [JsBigIntOrBooleanOrNumberOrStringLike],
11429        [bigint, number, string]
11430    ),
11431    (
11432        JsBooleanOrNumberOrStringLike,
11433        "boolean | number | string",
11434        [JsBigIntOrBooleanOrNumberOrStringLike],
11435        [boolean, number, string]
11436    ),
11437    (
11438        JsBigIntOrBooleanLike,
11439        "bigint | boolean",
11440        [JsBigIntOrBooleanOrNumberLike, JsBigIntOrBooleanOrStringLike],
11441        [bigint, boolean]
11442    ),
11443    (
11444        JsBigIntOrNumberLike,
11445        "bigint | number",
11446        [JsBigIntOrBooleanOrNumberLike, JsBigIntOrNumberOrStringLike],
11447        [bigint, number]
11448    ),
11449    (
11450        JsBigIntOrStringLike,
11451        "bigint | string",
11452        [JsBigIntOrBooleanOrStringLike, JsBigIntOrNumberOrStringLike],
11453        [bigint, string]
11454    ),
11455    (
11456        JsBooleanOrNumberLike,
11457        "boolean | number",
11458        [JsBigIntOrBooleanOrNumberLike, JsBooleanOrNumberOrStringLike],
11459        [boolean, number]
11460    ),
11461    (
11462        JsBooleanOrStringLike,
11463        "boolean | string",
11464        [JsBigIntOrBooleanOrStringLike, JsBooleanOrNumberOrStringLike],
11465        [boolean, string]
11466    ),
11467    (
11468        JsNumberOrStringLike,
11469        "number | string",
11470        [
11471            JsBigIntOrNumberOrStringLike,
11472            JsBooleanOrNumberOrStringLike,
11473            PropertyKey
11474        ],
11475        [number, string]
11476    ),
11477    (
11478        /// TypeScript's `PropertyKey`: the key types accepted by JavaScript
11479        /// property operations and by TypeScript's `Record`.
11480        ///
11481        PropertyKey,
11482        "number | string | symbol",
11483        [],
11484        [number, string, symbol]
11485    ),
11486}
11487
11488#[allow(non_snake_case)]
11489pub mod Intl {
11490    use super::*;
11491
11492    // Intl
11493    #[wasm_bindgen]
11494    extern "C" {
11495        /// The `Intl.getCanonicalLocales()` method returns an array containing
11496        /// the canonical locale names. Duplicates will be omitted and elements
11497        /// will be validated as structurally valid language tags.
11498        ///
11499        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
11500        #[cfg(not(js_sys_unstable_apis))]
11501        #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
11502        pub fn get_canonical_locales(s: &JsValue) -> Array;
11503
11504        /// The `Intl.getCanonicalLocales()` method returns an array containing
11505        /// the canonical locale names. Duplicates will be omitted and elements
11506        /// will be validated as structurally valid language tags.
11507        ///
11508        /// Throws a `RangeError` if any of the strings are not valid locale identifiers.
11509        ///
11510        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
11511        #[cfg(js_sys_unstable_apis)]
11512        #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl, catch)]
11513        pub fn get_canonical_locales(s: &[JsString]) -> Result<Array<JsString>, JsValue>;
11514
11515        /// The `Intl.supportedValuesOf()` method returns an array containing the
11516        /// supported calendar, collation, currency, numbering system, or unit values
11517        /// supported by the implementation.
11518        ///
11519        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
11520        #[wasm_bindgen(js_name = supportedValuesOf, js_namespace = Intl)]
11521        pub fn supported_values_of(key: SupportedValuesKey) -> Array<JsString>;
11522    }
11523
11524    // Intl string enums
11525
11526    /// Key for `Intl.supportedValuesOf()`.
11527    #[wasm_bindgen]
11528    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11529    pub enum SupportedValuesKey {
11530        Calendar = "calendar",
11531        Collation = "collation",
11532        Currency = "currency",
11533        NumberingSystem = "numberingSystem",
11534        TimeZone = "timeZone",
11535        Unit = "unit",
11536    }
11537
11538    /// Locale matching algorithm for Intl constructors.
11539    #[wasm_bindgen]
11540    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11541    pub enum LocaleMatcher {
11542        Lookup = "lookup",
11543        BestFit = "best fit",
11544    }
11545
11546    /// Usage for `Intl.Collator`.
11547    #[wasm_bindgen]
11548    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11549    pub enum CollatorUsage {
11550        Sort = "sort",
11551        Search = "search",
11552    }
11553
11554    /// Sensitivity for `Intl.Collator`.
11555    #[wasm_bindgen]
11556    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11557    pub enum CollatorSensitivity {
11558        Base = "base",
11559        Accent = "accent",
11560        Case = "case",
11561        Variant = "variant",
11562    }
11563
11564    /// Case first option for `Intl.Collator`.
11565    #[wasm_bindgen]
11566    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11567    pub enum CollatorCaseFirst {
11568        Upper = "upper",
11569        Lower = "lower",
11570        False = "false",
11571    }
11572
11573    /// Style for `Intl.NumberFormat`.
11574    #[wasm_bindgen]
11575    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11576    pub enum NumberFormatStyle {
11577        Decimal = "decimal",
11578        Currency = "currency",
11579        Percent = "percent",
11580        Unit = "unit",
11581    }
11582
11583    /// Currency display for `Intl.NumberFormat`.
11584    #[wasm_bindgen]
11585    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11586    pub enum CurrencyDisplay {
11587        Code = "code",
11588        Symbol = "symbol",
11589        NarrowSymbol = "narrowSymbol",
11590        Name = "name",
11591    }
11592
11593    /// Currency sign for `Intl.NumberFormat`.
11594    #[wasm_bindgen]
11595    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11596    pub enum CurrencySign {
11597        Standard = "standard",
11598        Accounting = "accounting",
11599    }
11600
11601    /// Unit display for `Intl.NumberFormat`.
11602    #[wasm_bindgen]
11603    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11604    pub enum UnitDisplay {
11605        Short = "short",
11606        Narrow = "narrow",
11607        Long = "long",
11608    }
11609
11610    /// Notation for `Intl.NumberFormat`.
11611    #[wasm_bindgen]
11612    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11613    pub enum NumberFormatNotation {
11614        Standard = "standard",
11615        Scientific = "scientific",
11616        Engineering = "engineering",
11617        Compact = "compact",
11618    }
11619
11620    /// Compact display for `Intl.NumberFormat`.
11621    #[wasm_bindgen]
11622    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11623    pub enum CompactDisplay {
11624        Short = "short",
11625        Long = "long",
11626    }
11627
11628    /// Sign display for `Intl.NumberFormat`.
11629    #[wasm_bindgen]
11630    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11631    pub enum SignDisplay {
11632        Auto = "auto",
11633        Never = "never",
11634        Always = "always",
11635        ExceptZero = "exceptZero",
11636    }
11637
11638    /// Rounding mode for `Intl.NumberFormat`.
11639    #[wasm_bindgen]
11640    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11641    pub enum RoundingMode {
11642        Ceil = "ceil",
11643        Floor = "floor",
11644        Expand = "expand",
11645        Trunc = "trunc",
11646        HalfCeil = "halfCeil",
11647        HalfFloor = "halfFloor",
11648        HalfExpand = "halfExpand",
11649        HalfTrunc = "halfTrunc",
11650        HalfEven = "halfEven",
11651    }
11652
11653    /// Rounding priority for `Intl.NumberFormat`.
11654    #[wasm_bindgen]
11655    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11656    pub enum RoundingPriority {
11657        Auto = "auto",
11658        MorePrecision = "morePrecision",
11659        LessPrecision = "lessPrecision",
11660    }
11661
11662    /// Trailing zero display for `Intl.NumberFormat`.
11663    #[wasm_bindgen]
11664    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11665    pub enum TrailingZeroDisplay {
11666        Auto = "auto",
11667        StripIfInteger = "stripIfInteger",
11668    }
11669
11670    /// Use grouping option for `Intl.NumberFormat`.
11671    ///
11672    /// Determines whether to use grouping separators, such as thousands
11673    /// separators or thousand/lakh/crore separators.
11674    ///
11675    /// The default is `Min2` if notation is "compact", and `Auto` otherwise.
11676    ///
11677    /// Note: The string values `"true"` and `"false"` are accepted by JavaScript
11678    /// but are always converted to the default value. Use `True` and `False`
11679    /// variants for the boolean behavior.
11680    ///
11681    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#usegrouping)
11682    #[wasm_bindgen]
11683    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11684    pub enum UseGrouping {
11685        /// Display grouping separators even if the locale prefers otherwise.
11686        Always = "always",
11687        /// Display grouping separators based on the locale preference,
11688        /// which may also be dependent on the currency.
11689        Auto = "auto",
11690        /// Display grouping separators when there are at least 2 digits in a group.
11691        Min2 = "min2",
11692        /// Same as `Always`. Display grouping separators even if the locale prefers otherwise.
11693        True = "true",
11694        /// Display no grouping separators.
11695        False = "false",
11696    }
11697
11698    /// Date/time style for `Intl.DateTimeFormat`.
11699    #[wasm_bindgen]
11700    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11701    pub enum DateTimeStyle {
11702        Full = "full",
11703        Long = "long",
11704        Medium = "medium",
11705        Short = "short",
11706    }
11707
11708    /// Hour cycle for `Intl.DateTimeFormat`.
11709    #[wasm_bindgen]
11710    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11711    pub enum HourCycle {
11712        H11 = "h11",
11713        H12 = "h12",
11714        H23 = "h23",
11715        H24 = "h24",
11716    }
11717
11718    /// Weekday format for `Intl.DateTimeFormat`.
11719    #[wasm_bindgen]
11720    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11721    pub enum WeekdayFormat {
11722        Narrow = "narrow",
11723        Short = "short",
11724        Long = "long",
11725    }
11726
11727    /// Era format for `Intl.DateTimeFormat`.
11728    #[wasm_bindgen]
11729    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11730    pub enum EraFormat {
11731        Narrow = "narrow",
11732        Short = "short",
11733        Long = "long",
11734    }
11735
11736    /// Year format for `Intl.DateTimeFormat`.
11737    #[wasm_bindgen]
11738    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11739    pub enum YearFormat {
11740        Numeric = "numeric",
11741        TwoDigit = "2-digit",
11742    }
11743
11744    /// Month format for `Intl.DateTimeFormat`.
11745    #[wasm_bindgen]
11746    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11747    pub enum MonthFormat {
11748        #[wasm_bindgen]
11749        Numeric = "numeric",
11750        #[wasm_bindgen]
11751        TwoDigit = "2-digit",
11752        #[wasm_bindgen]
11753        Narrow = "narrow",
11754        #[wasm_bindgen]
11755        Short = "short",
11756        #[wasm_bindgen]
11757        Long = "long",
11758    }
11759
11760    /// Day format for `Intl.DateTimeFormat`.
11761    #[wasm_bindgen]
11762    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11763    pub enum DayFormat {
11764        #[wasm_bindgen]
11765        Numeric = "numeric",
11766        #[wasm_bindgen]
11767        TwoDigit = "2-digit",
11768    }
11769
11770    /// Hour/minute/second format for `Intl.DateTimeFormat`.
11771    #[wasm_bindgen]
11772    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11773    pub enum NumericFormat {
11774        #[wasm_bindgen]
11775        Numeric = "numeric",
11776        #[wasm_bindgen]
11777        TwoDigit = "2-digit",
11778    }
11779
11780    /// Time zone name format for `Intl.DateTimeFormat`.
11781    #[wasm_bindgen]
11782    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11783    pub enum TimeZoneNameFormat {
11784        Short = "short",
11785        Long = "long",
11786        ShortOffset = "shortOffset",
11787        LongOffset = "longOffset",
11788        ShortGeneric = "shortGeneric",
11789        LongGeneric = "longGeneric",
11790    }
11791
11792    /// Day period format for `Intl.DateTimeFormat`.
11793    #[wasm_bindgen]
11794    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11795    pub enum DayPeriodFormat {
11796        Narrow = "narrow",
11797        Short = "short",
11798        Long = "long",
11799    }
11800
11801    /// Part type for `DateTimeFormat.formatToParts()`.
11802    #[wasm_bindgen]
11803    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11804    pub enum DateTimeFormatPartType {
11805        Day = "day",
11806        DayPeriod = "dayPeriod",
11807        Era = "era",
11808        FractionalSecond = "fractionalSecond",
11809        Hour = "hour",
11810        Literal = "literal",
11811        Minute = "minute",
11812        Month = "month",
11813        RelatedYear = "relatedYear",
11814        Second = "second",
11815        TimeZoneName = "timeZoneName",
11816        Weekday = "weekday",
11817        Year = "year",
11818        YearName = "yearName",
11819    }
11820
11821    /// Part type for `NumberFormat.formatToParts()`.
11822    #[wasm_bindgen]
11823    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11824    pub enum NumberFormatPartType {
11825        Compact = "compact",
11826        Currency = "currency",
11827        Decimal = "decimal",
11828        ExponentInteger = "exponentInteger",
11829        ExponentMinusSign = "exponentMinusSign",
11830        ExponentSeparator = "exponentSeparator",
11831        Fraction = "fraction",
11832        Group = "group",
11833        Infinity = "infinity",
11834        Integer = "integer",
11835        Literal = "literal",
11836        MinusSign = "minusSign",
11837        Nan = "nan",
11838        PercentSign = "percentSign",
11839        PlusSign = "plusSign",
11840        Unit = "unit",
11841        Unknown = "unknown",
11842    }
11843
11844    /// Type for `Intl.PluralRules` (cardinal or ordinal).
11845    #[wasm_bindgen]
11846    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11847    pub enum PluralRulesType {
11848        Cardinal = "cardinal",
11849        Ordinal = "ordinal",
11850    }
11851
11852    /// Plural category returned by `PluralRules.select()`.
11853    #[wasm_bindgen]
11854    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11855    pub enum PluralCategory {
11856        Zero = "zero",
11857        One = "one",
11858        Two = "two",
11859        Few = "few",
11860        Many = "many",
11861        Other = "other",
11862    }
11863
11864    /// Numeric option for `Intl.RelativeTimeFormat`.
11865    #[wasm_bindgen]
11866    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11867    pub enum RelativeTimeFormatNumeric {
11868        Always = "always",
11869        Auto = "auto",
11870    }
11871
11872    /// Style for `Intl.RelativeTimeFormat`.
11873    #[wasm_bindgen]
11874    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11875    pub enum RelativeTimeFormatStyle {
11876        Long = "long",
11877        Short = "short",
11878        Narrow = "narrow",
11879    }
11880
11881    /// Unit for `RelativeTimeFormat.format()`.
11882    #[wasm_bindgen]
11883    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11884    pub enum RelativeTimeFormatUnit {
11885        Year = "year",
11886        Years = "years",
11887        Quarter = "quarter",
11888        Quarters = "quarters",
11889        Month = "month",
11890        Months = "months",
11891        Week = "week",
11892        Weeks = "weeks",
11893        Day = "day",
11894        Days = "days",
11895        Hour = "hour",
11896        Hours = "hours",
11897        Minute = "minute",
11898        Minutes = "minutes",
11899        Second = "second",
11900        Seconds = "seconds",
11901    }
11902
11903    /// Part type for `RelativeTimeFormat.formatToParts()`.
11904    #[wasm_bindgen]
11905    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11906    pub enum RelativeTimeFormatPartType {
11907        Literal = "literal",
11908        Integer = "integer",
11909        Decimal = "decimal",
11910        Fraction = "fraction",
11911    }
11912
11913    /// Source indicator for range format parts.
11914    ///
11915    /// Indicates which part of the range (start, end, or shared) a formatted
11916    /// part belongs to when using `formatRangeToParts()`.
11917    ///
11918    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts#description)
11919    #[wasm_bindgen]
11920    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11921    pub enum RangeSource {
11922        /// The part is from the start of the range.
11923        StartRange = "startRange",
11924        /// The part is from the end of the range.
11925        EndRange = "endRange",
11926        /// The part is shared between start and end (e.g., a separator or common element).
11927        Shared = "shared",
11928    }
11929
11930    /// Type for `Intl.ListFormat`.
11931    #[wasm_bindgen]
11932    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11933    pub enum ListFormatType {
11934        /// For lists of standalone items (default).
11935        Conjunction = "conjunction",
11936        /// For lists representing alternatives.
11937        Disjunction = "disjunction",
11938        /// For lists of values with units.
11939        Unit = "unit",
11940    }
11941
11942    /// Style for `Intl.ListFormat`.
11943    #[wasm_bindgen]
11944    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11945    pub enum ListFormatStyle {
11946        /// "A, B, and C" (default).
11947        Long = "long",
11948        /// "A, B, C".
11949        Short = "short",
11950        /// "A B C".
11951        Narrow = "narrow",
11952    }
11953
11954    /// Part type for `Intl.ListFormat.formatToParts()`.
11955    #[wasm_bindgen]
11956    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11957    pub enum ListFormatPartType {
11958        /// A value from the list.
11959        Element = "element",
11960        /// A linguistic construct (e.g., ", ", " and ").
11961        Literal = "literal",
11962    }
11963
11964    /// Type for `Intl.Segmenter`.
11965    #[wasm_bindgen]
11966    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11967    pub enum SegmenterGranularity {
11968        /// Segment by grapheme clusters (user-perceived characters).
11969        Grapheme = "grapheme",
11970        /// Segment by words.
11971        Word = "word",
11972        /// Segment by sentences.
11973        Sentence = "sentence",
11974    }
11975
11976    /// Type for `Intl.DisplayNames`.
11977    #[wasm_bindgen]
11978    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11979    pub enum DisplayNamesType {
11980        /// Language display names.
11981        Language = "language",
11982        /// Region display names.
11983        Region = "region",
11984        /// Script display names.
11985        Script = "script",
11986        /// Currency display names.
11987        Currency = "currency",
11988        /// Calendar display names.
11989        Calendar = "calendar",
11990        /// Date/time field display names.
11991        DateTimeField = "dateTimeField",
11992    }
11993
11994    /// Style for `Intl.DisplayNames`.
11995    #[wasm_bindgen]
11996    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11997    pub enum DisplayNamesStyle {
11998        /// Full display name (default).
11999        Long = "long",
12000        /// Abbreviated display name.
12001        Short = "short",
12002        /// Minimal display name.
12003        Narrow = "narrow",
12004    }
12005
12006    /// Fallback for `Intl.DisplayNames`.
12007    #[wasm_bindgen]
12008    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12009    pub enum DisplayNamesFallback {
12010        /// Return the input code if no display name is available (default).
12011        Code = "code",
12012        /// Return undefined if no display name is available.
12013        None = "none",
12014    }
12015
12016    /// Language display for `Intl.DisplayNames`.
12017    #[wasm_bindgen]
12018    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12019    pub enum DisplayNamesLanguageDisplay {
12020        /// Use dialect names (e.g., "British English").
12021        Dialect = "dialect",
12022        /// Use standard names (e.g., "English (United Kingdom)").
12023        Standard = "standard",
12024    }
12025
12026    // Intl.RelativeTimeFormatOptions
12027    #[wasm_bindgen]
12028    extern "C" {
12029        /// Options for `Intl.RelativeTimeFormat` constructor.
12030        ///
12031        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#options)
12032        #[wasm_bindgen(extends = Object)]
12033        #[derive(Clone, Debug)]
12034        pub type RelativeTimeFormatOptions;
12035
12036        #[wasm_bindgen(method, getter = localeMatcher)]
12037        pub fn get_locale_matcher(this: &RelativeTimeFormatOptions) -> Option<LocaleMatcher>;
12038        #[wasm_bindgen(method, setter = localeMatcher)]
12039        pub fn set_locale_matcher(this: &RelativeTimeFormatOptions, value: LocaleMatcher);
12040
12041        #[wasm_bindgen(method, getter = numeric)]
12042        pub fn get_numeric(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatNumeric>;
12043        #[wasm_bindgen(method, setter = numeric)]
12044        pub fn set_numeric(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatNumeric);
12045
12046        #[wasm_bindgen(method, getter = style)]
12047        pub fn get_style(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatStyle>;
12048        #[wasm_bindgen(method, setter = style)]
12049        pub fn set_style(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatStyle);
12050    }
12051
12052    impl RelativeTimeFormatOptions {
12053        pub fn new() -> RelativeTimeFormatOptions {
12054            JsCast::unchecked_into(Object::new())
12055        }
12056    }
12057
12058    impl Default for RelativeTimeFormatOptions {
12059        fn default() -> Self {
12060            RelativeTimeFormatOptions::new()
12061        }
12062    }
12063
12064    // Intl.ResolvedRelativeTimeFormatOptions
12065    #[wasm_bindgen]
12066    extern "C" {
12067        /// Resolved options returned by `Intl.RelativeTimeFormat.prototype.resolvedOptions()`.
12068        ///
12069        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
12070        #[wasm_bindgen(extends = RelativeTimeFormatOptions)]
12071        #[derive(Clone, Debug)]
12072        pub type ResolvedRelativeTimeFormatOptions;
12073
12074        /// The resolved locale string.
12075        #[cfg(not(js_sys_unstable_apis))]
12076        #[wasm_bindgen(method, getter = locale)]
12077        pub fn get_locale(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
12078
12079        /// The resolved locale string.
12080        #[cfg(js_sys_unstable_apis)]
12081        #[wasm_bindgen(method, getter = locale)]
12082        pub fn get_locale(this: &ResolvedRelativeTimeFormatOptions) -> String;
12083
12084        /// The numbering system used.
12085        #[cfg(not(js_sys_unstable_apis))]
12086        #[wasm_bindgen(method, getter = numberingSystem)]
12087        pub fn get_numbering_system(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
12088
12089        /// The numbering system used.
12090        #[cfg(js_sys_unstable_apis)]
12091        #[wasm_bindgen(method, getter = numberingSystem)]
12092        pub fn get_numbering_system(this: &ResolvedRelativeTimeFormatOptions) -> String;
12093    }
12094
12095    // Intl.RelativeTimeFormatPart
12096    #[wasm_bindgen]
12097    extern "C" {
12098        /// A part of the formatted relative time returned by `formatToParts()`.
12099        ///
12100        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
12101        #[wasm_bindgen(extends = Object)]
12102        #[derive(Clone, Debug)]
12103        pub type RelativeTimeFormatPart;
12104
12105        /// The type of this part.
12106        #[wasm_bindgen(method, getter = type)]
12107        pub fn type_(this: &RelativeTimeFormatPart) -> RelativeTimeFormatPartType;
12108
12109        /// The string value of this part.
12110        #[cfg(not(js_sys_unstable_apis))]
12111        #[wasm_bindgen(method, getter = value)]
12112        pub fn value(this: &RelativeTimeFormatPart) -> JsString;
12113
12114        /// The string value of this part.
12115        #[cfg(js_sys_unstable_apis)]
12116        #[wasm_bindgen(method, getter = value)]
12117        pub fn value(this: &RelativeTimeFormatPart) -> String;
12118
12119        /// The unit used in this part (only for integer parts).
12120        #[wasm_bindgen(method, getter = unit)]
12121        pub fn unit(this: &RelativeTimeFormatPart) -> Option<JsString>;
12122    }
12123
12124    // Intl.LocaleMatcherOptions
12125    #[wasm_bindgen]
12126    extern "C" {
12127        /// Options for `supportedLocalesOf` methods.
12128        #[wasm_bindgen(extends = Object)]
12129        #[derive(Clone, Debug)]
12130        pub type LocaleMatcherOptions;
12131
12132        #[wasm_bindgen(method, getter = localeMatcher)]
12133        pub fn get_locale_matcher(this: &LocaleMatcherOptions) -> Option<LocaleMatcher>;
12134
12135        #[wasm_bindgen(method, setter = localeMatcher)]
12136        pub fn set_locale_matcher(this: &LocaleMatcherOptions, value: LocaleMatcher);
12137    }
12138
12139    impl LocaleMatcherOptions {
12140        pub fn new() -> LocaleMatcherOptions {
12141            JsCast::unchecked_into(Object::new())
12142        }
12143    }
12144
12145    impl Default for LocaleMatcherOptions {
12146        fn default() -> Self {
12147            LocaleMatcherOptions::new()
12148        }
12149    }
12150
12151    // Intl.Collator Options
12152    #[wasm_bindgen]
12153    extern "C" {
12154        /// Options for `Intl.Collator` and `String.prototype.localeCompare`.
12155        ///
12156        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options)
12157        #[wasm_bindgen(extends = Object)]
12158        #[derive(Clone, Debug)]
12159        pub type CollatorOptions;
12160
12161        #[wasm_bindgen(method, getter = localeMatcher)]
12162        pub fn get_locale_matcher(this: &CollatorOptions) -> Option<LocaleMatcher>;
12163        #[wasm_bindgen(method, setter = localeMatcher)]
12164        pub fn set_locale_matcher(this: &CollatorOptions, value: LocaleMatcher);
12165
12166        #[wasm_bindgen(method, getter = usage)]
12167        pub fn get_usage(this: &CollatorOptions) -> Option<CollatorUsage>;
12168        #[wasm_bindgen(method, setter = usage)]
12169        pub fn set_usage(this: &CollatorOptions, value: CollatorUsage);
12170
12171        #[wasm_bindgen(method, getter = sensitivity)]
12172        pub fn get_sensitivity(this: &CollatorOptions) -> Option<CollatorSensitivity>;
12173        #[wasm_bindgen(method, setter = sensitivity)]
12174        pub fn set_sensitivity(this: &CollatorOptions, value: CollatorSensitivity);
12175
12176        #[wasm_bindgen(method, getter = ignorePunctuation)]
12177        pub fn get_ignore_punctuation(this: &CollatorOptions) -> Option<bool>;
12178        #[wasm_bindgen(method, setter = ignorePunctuation)]
12179        pub fn set_ignore_punctuation(this: &CollatorOptions, value: bool);
12180
12181        #[wasm_bindgen(method, getter = numeric)]
12182        pub fn get_numeric(this: &CollatorOptions) -> Option<bool>;
12183        #[wasm_bindgen(method, setter = numeric)]
12184        pub fn set_numeric(this: &CollatorOptions, value: bool);
12185
12186        #[wasm_bindgen(method, getter = caseFirst)]
12187        pub fn get_case_first(this: &CollatorOptions) -> Option<CollatorCaseFirst>;
12188        #[wasm_bindgen(method, setter = caseFirst)]
12189        pub fn set_case_first(this: &CollatorOptions, value: CollatorCaseFirst);
12190    }
12191    impl CollatorOptions {
12192        pub fn new() -> CollatorOptions {
12193            JsCast::unchecked_into(Object::new())
12194        }
12195    }
12196    impl Default for CollatorOptions {
12197        fn default() -> Self {
12198            CollatorOptions::new()
12199        }
12200    }
12201
12202    // Intl.Collator ResolvedCollatorOptions
12203    #[wasm_bindgen]
12204    extern "C" {
12205        #[wasm_bindgen(extends = CollatorOptions)]
12206        #[derive(Clone, Debug)]
12207        pub type ResolvedCollatorOptions;
12208
12209        #[cfg(not(js_sys_unstable_apis))]
12210        #[wasm_bindgen(method, getter = locale)]
12211        pub fn get_locale(this: &ResolvedCollatorOptions) -> JsString; // not Option, always present
12212        #[cfg(js_sys_unstable_apis)]
12213        #[wasm_bindgen(method, getter = locale)]
12214        pub fn get_locale(this: &ResolvedCollatorOptions) -> String;
12215        #[cfg(not(js_sys_unstable_apis))]
12216        #[wasm_bindgen(method, getter = collation)]
12217        pub fn get_collation(this: &ResolvedCollatorOptions) -> JsString;
12218        #[cfg(js_sys_unstable_apis)]
12219        #[wasm_bindgen(method, getter = collation)]
12220        pub fn get_collation(this: &ResolvedCollatorOptions) -> String;
12221    }
12222
12223    // Intl.Collator
12224    #[wasm_bindgen]
12225    extern "C" {
12226        /// The `Intl.Collator` object is a constructor for collators, objects
12227        /// that enable language sensitive string comparison.
12228        ///
12229        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
12230        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
12231        #[derive(Clone, Debug)]
12232        pub type Collator;
12233
12234        /// The `Intl.Collator` object is a constructor for collators, objects
12235        /// that enable language sensitive string comparison.
12236        ///
12237        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
12238        #[cfg(not(js_sys_unstable_apis))]
12239        #[wasm_bindgen(constructor, js_namespace = Intl)]
12240        pub fn new(locales: &Array, options: &Object) -> Collator;
12241
12242        /// The `Intl.Collator` object is a constructor for collators, objects
12243        /// that enable language sensitive string comparison.
12244        ///
12245        /// Throws a `RangeError` if locales contain invalid values.
12246        ///
12247        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
12248        #[cfg(js_sys_unstable_apis)]
12249        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12250        pub fn new(locales: &[JsString], options: &CollatorOptions) -> Result<Collator, JsValue>;
12251
12252        /// The Intl.Collator.prototype.compare property returns a function that
12253        /// compares two strings according to the sort order of this Collator
12254        /// object.
12255        ///
12256        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
12257        #[cfg(not(js_sys_unstable_apis))]
12258        #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
12259        pub fn compare(this: &Collator) -> Function;
12260
12261        /// Compares two strings according to the sort order of this Collator.
12262        ///
12263        /// Returns a negative value if `a` comes before `b`, positive if `a` comes
12264        /// after `b`, and zero if they are equal.
12265        ///
12266        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare)
12267        #[cfg(js_sys_unstable_apis)]
12268        #[wasm_bindgen(method, js_class = "Intl.Collator")]
12269        pub fn compare(this: &Collator, a: &str, b: &str) -> i32;
12270
12271        /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
12272        /// object with properties reflecting the locale and collation options
12273        /// computed during initialization of this Collator object.
12274        ///
12275        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
12276        #[cfg(not(js_sys_unstable_apis))]
12277        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12278        pub fn resolved_options(this: &Collator) -> Object;
12279
12280        /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
12281        /// object with properties reflecting the locale and collation options
12282        /// computed during initialization of this Collator object.
12283        ///
12284        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
12285        #[cfg(js_sys_unstable_apis)]
12286        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12287        pub fn resolved_options(this: &Collator) -> ResolvedCollatorOptions;
12288
12289        /// The `Intl.Collator.supportedLocalesOf()` method returns an array
12290        /// containing those of the provided locales that are supported in
12291        /// collation without having to fall back to the runtime's default
12292        /// locale.
12293        ///
12294        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
12295        #[cfg(not(js_sys_unstable_apis))]
12296        #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
12297        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12298
12299        /// The `Intl.Collator.supportedLocalesOf()` method returns an array
12300        /// containing those of the provided locales that are supported in
12301        /// collation without having to fall back to the runtime's default
12302        /// locale.
12303        ///
12304        /// Throws a `RangeError` if locales contain invalid values.
12305        ///
12306        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
12307        #[cfg(js_sys_unstable_apis)]
12308        #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12309        pub fn supported_locales_of(
12310            locales: &[JsString],
12311            options: &LocaleMatcherOptions,
12312        ) -> Result<Array<JsString>, JsValue>;
12313    }
12314
12315    #[cfg(not(js_sys_unstable_apis))]
12316    impl Default for Collator {
12317        fn default() -> Self {
12318            Self::new(
12319                &JsValue::UNDEFINED.unchecked_into(),
12320                &JsValue::UNDEFINED.unchecked_into(),
12321            )
12322        }
12323    }
12324
12325    #[cfg(js_sys_unstable_apis)]
12326    impl Default for Collator {
12327        fn default() -> Self {
12328            Self::new(&[], &Default::default()).unwrap()
12329        }
12330    }
12331
12332    // Intl.DateTimeFormatOptions
12333    #[wasm_bindgen]
12334    extern "C" {
12335        /// Options for `Intl.DateTimeFormat` constructor.
12336        ///
12337        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)
12338        #[wasm_bindgen(extends = Object)]
12339        #[derive(Clone, Debug)]
12340        pub type DateTimeFormatOptions;
12341
12342        // Locale matching
12343        #[wasm_bindgen(method, getter = localeMatcher)]
12344        pub fn get_locale_matcher(this: &DateTimeFormatOptions) -> Option<LocaleMatcher>;
12345        #[wasm_bindgen(method, setter = localeMatcher)]
12346        pub fn set_locale_matcher(this: &DateTimeFormatOptions, value: LocaleMatcher);
12347
12348        // Calendar/numbering (free-form strings, no enum)
12349        #[wasm_bindgen(method, getter = calendar)]
12350        pub fn get_calendar(this: &DateTimeFormatOptions) -> Option<JsString>;
12351        #[wasm_bindgen(method, setter = calendar)]
12352        pub fn set_calendar(this: &DateTimeFormatOptions, value: &str);
12353
12354        #[wasm_bindgen(method, getter = numberingSystem)]
12355        pub fn get_numbering_system(this: &DateTimeFormatOptions) -> Option<JsString>;
12356        #[wasm_bindgen(method, setter = numberingSystem)]
12357        pub fn set_numbering_system(this: &DateTimeFormatOptions, value: &str);
12358
12359        // Timezone (free-form string)
12360        #[wasm_bindgen(method, getter = timeZone)]
12361        pub fn get_time_zone(this: &DateTimeFormatOptions) -> Option<JsString>;
12362        #[wasm_bindgen(method, setter = timeZone)]
12363        pub fn set_time_zone(this: &DateTimeFormatOptions, value: &str);
12364
12365        // Hour cycle
12366        #[wasm_bindgen(method, getter = hour12)]
12367        pub fn get_hour12(this: &DateTimeFormatOptions) -> Option<bool>;
12368        #[wasm_bindgen(method, setter = hour12)]
12369        pub fn set_hour12(this: &DateTimeFormatOptions, value: bool);
12370
12371        #[wasm_bindgen(method, getter = hourCycle)]
12372        pub fn get_hour_cycle(this: &DateTimeFormatOptions) -> Option<HourCycle>;
12373        #[wasm_bindgen(method, setter = hourCycle)]
12374        pub fn set_hour_cycle(this: &DateTimeFormatOptions, value: HourCycle);
12375
12376        // Style shortcuts
12377        #[wasm_bindgen(method, getter = dateStyle)]
12378        pub fn get_date_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
12379        #[wasm_bindgen(method, setter = dateStyle)]
12380        pub fn set_date_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
12381
12382        #[wasm_bindgen(method, getter = timeStyle)]
12383        pub fn get_time_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
12384        #[wasm_bindgen(method, setter = timeStyle)]
12385        pub fn set_time_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
12386
12387        // Component options
12388        #[wasm_bindgen(method, getter = weekday)]
12389        pub fn get_weekday(this: &DateTimeFormatOptions) -> Option<WeekdayFormat>;
12390        #[wasm_bindgen(method, setter = weekday)]
12391        pub fn set_weekday(this: &DateTimeFormatOptions, value: WeekdayFormat);
12392
12393        #[wasm_bindgen(method, getter = era)]
12394        pub fn get_era(this: &DateTimeFormatOptions) -> Option<EraFormat>;
12395        #[wasm_bindgen(method, setter = era)]
12396        pub fn set_era(this: &DateTimeFormatOptions, value: EraFormat);
12397
12398        #[wasm_bindgen(method, getter = year)]
12399        pub fn get_year(this: &DateTimeFormatOptions) -> Option<YearFormat>;
12400        #[wasm_bindgen(method, setter = year)]
12401        pub fn set_year(this: &DateTimeFormatOptions, value: YearFormat);
12402
12403        #[wasm_bindgen(method, getter = month)]
12404        pub fn get_month(this: &DateTimeFormatOptions) -> Option<MonthFormat>;
12405        #[wasm_bindgen(method, setter = month)]
12406        pub fn set_month(this: &DateTimeFormatOptions, value: MonthFormat);
12407
12408        #[wasm_bindgen(method, getter = day)]
12409        pub fn get_day(this: &DateTimeFormatOptions) -> Option<DayFormat>;
12410        #[wasm_bindgen(method, setter = day)]
12411        pub fn set_day(this: &DateTimeFormatOptions, value: DayFormat);
12412
12413        #[wasm_bindgen(method, getter = hour)]
12414        pub fn get_hour(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
12415        #[wasm_bindgen(method, setter = hour)]
12416        pub fn set_hour(this: &DateTimeFormatOptions, value: NumericFormat);
12417
12418        #[wasm_bindgen(method, getter = minute)]
12419        pub fn get_minute(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
12420        #[wasm_bindgen(method, setter = minute)]
12421        pub fn set_minute(this: &DateTimeFormatOptions, value: NumericFormat);
12422
12423        #[wasm_bindgen(method, getter = second)]
12424        pub fn get_second(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
12425        #[wasm_bindgen(method, setter = second)]
12426        pub fn set_second(this: &DateTimeFormatOptions, value: NumericFormat);
12427
12428        #[wasm_bindgen(method, getter = fractionalSecondDigits)]
12429        pub fn get_fractional_second_digits(this: &DateTimeFormatOptions) -> Option<u8>;
12430        #[wasm_bindgen(method, setter = fractionalSecondDigits)]
12431        pub fn set_fractional_second_digits(this: &DateTimeFormatOptions, value: u8);
12432
12433        #[wasm_bindgen(method, getter = timeZoneName)]
12434        pub fn get_time_zone_name(this: &DateTimeFormatOptions) -> Option<TimeZoneNameFormat>;
12435        #[wasm_bindgen(method, setter = timeZoneName)]
12436        pub fn set_time_zone_name(this: &DateTimeFormatOptions, value: TimeZoneNameFormat);
12437
12438        #[wasm_bindgen(method, getter = dayPeriod)]
12439        pub fn get_day_period(this: &DateTimeFormatOptions) -> Option<DayPeriodFormat>;
12440        #[wasm_bindgen(method, setter = dayPeriod)]
12441        pub fn set_day_period(this: &DateTimeFormatOptions, value: DayPeriodFormat);
12442    }
12443
12444    impl DateTimeFormatOptions {
12445        pub fn new() -> DateTimeFormatOptions {
12446            JsCast::unchecked_into(Object::new())
12447        }
12448    }
12449
12450    impl Default for DateTimeFormatOptions {
12451        fn default() -> Self {
12452            DateTimeFormatOptions::new()
12453        }
12454    }
12455
12456    // Intl.ResolvedDateTimeFormatOptions
12457    #[wasm_bindgen]
12458    extern "C" {
12459        /// Resolved options returned by `Intl.DateTimeFormat.prototype.resolvedOptions()`.
12460        ///
12461        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions)
12462        #[wasm_bindgen(extends = DateTimeFormatOptions)]
12463        #[derive(Clone, Debug)]
12464        pub type ResolvedDateTimeFormatOptions;
12465
12466        /// The resolved locale string.
12467        #[cfg(not(js_sys_unstable_apis))]
12468        #[wasm_bindgen(method, getter = locale)]
12469        pub fn get_locale(this: &ResolvedDateTimeFormatOptions) -> JsString;
12470
12471        /// The resolved locale string.
12472        #[cfg(js_sys_unstable_apis)]
12473        #[wasm_bindgen(method, getter = locale)]
12474        pub fn get_locale(this: &ResolvedDateTimeFormatOptions) -> String;
12475    }
12476
12477    // Intl.DateTimeFormatPart
12478    #[wasm_bindgen]
12479    extern "C" {
12480        /// A part of the formatted date returned by `formatToParts()`.
12481        ///
12482        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
12483        #[wasm_bindgen(extends = Object)]
12484        #[derive(Clone, Debug)]
12485        pub type DateTimeFormatPart;
12486
12487        /// The type of the part (e.g., "day", "month", "year", "literal", etc.)
12488        #[wasm_bindgen(method, getter = type)]
12489        pub fn type_(this: &DateTimeFormatPart) -> DateTimeFormatPartType;
12490
12491        /// The value of the part.
12492        #[cfg(not(js_sys_unstable_apis))]
12493        #[wasm_bindgen(method, getter)]
12494        pub fn value(this: &DateTimeFormatPart) -> JsString;
12495
12496        /// The value of the part.
12497        #[cfg(js_sys_unstable_apis)]
12498        #[wasm_bindgen(method, getter)]
12499        pub fn value(this: &DateTimeFormatPart) -> String;
12500    }
12501
12502    // Intl.DateTimeRangeFormatPart
12503    #[wasm_bindgen]
12504    extern "C" {
12505        /// A part of the formatted date range returned by `formatRangeToParts()`.
12506        ///
12507        /// Extends `DateTimeFormatPart` with a `source` property indicating whether
12508        /// the part is from the start date, end date, or shared between them.
12509        ///
12510        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
12511        #[wasm_bindgen(extends = DateTimeFormatPart)]
12512        #[derive(Clone, Debug)]
12513        pub type DateTimeRangeFormatPart;
12514
12515        /// The source of the part: "startRange", "endRange", or "shared".
12516        #[wasm_bindgen(method, getter)]
12517        pub fn source(this: &DateTimeRangeFormatPart) -> RangeSource;
12518    }
12519
12520    // Intl.DateTimeFormat
12521    #[wasm_bindgen]
12522    extern "C" {
12523        /// The `Intl.DateTimeFormat` object is a constructor for objects
12524        /// that enable language-sensitive date and time formatting.
12525        ///
12526        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
12527        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
12528        #[derive(Clone, Debug)]
12529        pub type DateTimeFormat;
12530
12531        /// The `Intl.DateTimeFormat` object is a constructor for objects
12532        /// that enable language-sensitive date and time formatting.
12533        ///
12534        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
12535        #[cfg(not(js_sys_unstable_apis))]
12536        #[wasm_bindgen(constructor, js_namespace = Intl)]
12537        pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
12538
12539        /// The `Intl.DateTimeFormat` object is a constructor for objects
12540        /// that enable language-sensitive date and time formatting.
12541        ///
12542        /// Throws a `RangeError` if locales contain invalid values.
12543        ///
12544        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
12545        #[cfg(js_sys_unstable_apis)]
12546        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12547        pub fn new(
12548            locales: &[JsString],
12549            options: &DateTimeFormatOptions,
12550        ) -> Result<DateTimeFormat, JsValue>;
12551
12552        /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
12553        /// formats a date according to the locale and formatting options of this
12554        /// Intl.DateTimeFormat object.
12555        ///
12556        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
12557        #[cfg(not(js_sys_unstable_apis))]
12558        #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
12559        pub fn format(this: &DateTimeFormat) -> Function;
12560
12561        /// Formats a date according to the locale and formatting options of this
12562        /// `Intl.DateTimeFormat` object.
12563        ///
12564        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format)
12565        #[cfg(js_sys_unstable_apis)]
12566        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat")]
12567        pub fn format(this: &DateTimeFormat, date: &Date) -> String;
12568
12569        /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
12570        /// formatting of strings produced by DateTimeFormat formatters.
12571        ///
12572        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
12573        #[cfg(not(js_sys_unstable_apis))]
12574        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
12575        pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
12576
12577        /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
12578        /// formatting of strings produced by DateTimeFormat formatters.
12579        ///
12580        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
12581        #[cfg(js_sys_unstable_apis)]
12582        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
12583        pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array<DateTimeFormatPart>;
12584
12585        /// The `Intl.DateTimeFormat.prototype.formatRange()` method formats a date range
12586        /// in the most concise way based on the locales and options provided when
12587        /// instantiating this `Intl.DateTimeFormat` object.
12588        ///
12589        /// Throws a `TypeError` if the dates are invalid.
12590        ///
12591        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange)
12592        #[cfg(not(js_sys_unstable_apis))]
12593        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRange, catch)]
12594        pub fn format_range(
12595            this: &DateTimeFormat,
12596            start_date: &Date,
12597            end_date: &Date,
12598        ) -> Result<JsString, JsValue>;
12599
12600        /// The `Intl.DateTimeFormat.prototype.formatRange()` method formats a date range
12601        /// in the most concise way based on the locales and options provided when
12602        /// instantiating this `Intl.DateTimeFormat` object.
12603        ///
12604        /// Throws a `TypeError` if the dates are invalid.
12605        ///
12606        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange)
12607        #[cfg(js_sys_unstable_apis)]
12608        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRange, catch)]
12609        pub fn format_range(
12610            this: &DateTimeFormat,
12611            start_date: &Date,
12612            end_date: &Date,
12613        ) -> Result<String, JsValue>;
12614
12615        /// The `Intl.DateTimeFormat.prototype.formatRangeToParts()` method returns an array
12616        /// of locale-specific tokens representing each part of the formatted date range
12617        /// produced by `Intl.DateTimeFormat` formatters.
12618        ///
12619        /// Throws a `TypeError` if the dates are invalid.
12620        ///
12621        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
12622        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRangeToParts, catch)]
12623        pub fn format_range_to_parts(
12624            this: &DateTimeFormat,
12625            start_date: &Date,
12626            end_date: &Date,
12627        ) -> Result<Array<DateTimeRangeFormatPart>, JsValue>;
12628
12629        /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
12630        /// object with properties reflecting the locale and date and time formatting
12631        /// options computed during initialization of this DateTimeFormat object.
12632        ///
12633        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
12634        #[cfg(not(js_sys_unstable_apis))]
12635        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12636        pub fn resolved_options(this: &DateTimeFormat) -> Object;
12637
12638        /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
12639        /// object with properties reflecting the locale and date and time formatting
12640        /// options computed during initialization of this DateTimeFormat object.
12641        ///
12642        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
12643        #[cfg(js_sys_unstable_apis)]
12644        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12645        pub fn resolved_options(this: &DateTimeFormat) -> ResolvedDateTimeFormatOptions;
12646
12647        /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
12648        /// containing those of the provided locales that are supported in date
12649        /// and time formatting without having to fall back to the runtime's default
12650        /// locale.
12651        ///
12652        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
12653        #[cfg(not(js_sys_unstable_apis))]
12654        #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
12655        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12656
12657        /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
12658        /// containing those of the provided locales that are supported in date
12659        /// and time formatting without having to fall back to the runtime's default
12660        /// locale.
12661        ///
12662        /// Throws a `RangeError` if locales contain invalid values.
12663        ///
12664        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
12665        #[cfg(js_sys_unstable_apis)]
12666        #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12667        pub fn supported_locales_of(
12668            locales: &[JsString],
12669            options: &LocaleMatcherOptions,
12670        ) -> Result<Array<JsString>, JsValue>;
12671    }
12672
12673    #[cfg(not(js_sys_unstable_apis))]
12674    impl Default for DateTimeFormat {
12675        fn default() -> Self {
12676            Self::new(
12677                &JsValue::UNDEFINED.unchecked_into(),
12678                &JsValue::UNDEFINED.unchecked_into(),
12679            )
12680        }
12681    }
12682
12683    #[cfg(js_sys_unstable_apis)]
12684    impl Default for DateTimeFormat {
12685        fn default() -> Self {
12686            Self::new(&[], &Default::default()).unwrap()
12687        }
12688    }
12689
12690    // Intl.NumberFormatOptions
12691    #[wasm_bindgen]
12692    extern "C" {
12693        /// Options for `Intl.NumberFormat` constructor.
12694        ///
12695        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options)
12696        #[wasm_bindgen(extends = Object)]
12697        #[derive(Clone, Debug)]
12698        pub type NumberFormatOptions;
12699
12700        // Locale matching
12701        #[wasm_bindgen(method, getter = localeMatcher)]
12702        pub fn get_locale_matcher(this: &NumberFormatOptions) -> Option<LocaleMatcher>;
12703        #[wasm_bindgen(method, setter = localeMatcher)]
12704        pub fn set_locale_matcher(this: &NumberFormatOptions, value: LocaleMatcher);
12705
12706        // Numbering system (free-form string)
12707        #[wasm_bindgen(method, getter = numberingSystem)]
12708        pub fn get_numbering_system(this: &NumberFormatOptions) -> Option<JsString>;
12709        #[wasm_bindgen(method, setter = numberingSystem)]
12710        pub fn set_numbering_system(this: &NumberFormatOptions, value: &str);
12711
12712        // Style
12713        #[wasm_bindgen(method, getter = style)]
12714        pub fn get_style(this: &NumberFormatOptions) -> Option<NumberFormatStyle>;
12715        #[wasm_bindgen(method, setter = style)]
12716        pub fn set_style(this: &NumberFormatOptions, value: NumberFormatStyle);
12717
12718        // Currency options (currency code is free-form ISO 4217 string)
12719        #[wasm_bindgen(method, getter = currency)]
12720        pub fn get_currency(this: &NumberFormatOptions) -> Option<JsString>;
12721        #[wasm_bindgen(method, setter = currency)]
12722        pub fn set_currency(this: &NumberFormatOptions, value: &str);
12723
12724        #[wasm_bindgen(method, getter = currencyDisplay)]
12725        pub fn get_currency_display(this: &NumberFormatOptions) -> Option<CurrencyDisplay>;
12726        #[wasm_bindgen(method, setter = currencyDisplay)]
12727        pub fn set_currency_display(this: &NumberFormatOptions, value: CurrencyDisplay);
12728
12729        #[wasm_bindgen(method, getter = currencySign)]
12730        pub fn get_currency_sign(this: &NumberFormatOptions) -> Option<CurrencySign>;
12731        #[wasm_bindgen(method, setter = currencySign)]
12732        pub fn set_currency_sign(this: &NumberFormatOptions, value: CurrencySign);
12733
12734        // Unit options (unit name is free-form string)
12735        #[wasm_bindgen(method, getter = unit)]
12736        pub fn get_unit(this: &NumberFormatOptions) -> Option<JsString>;
12737        #[wasm_bindgen(method, setter = unit)]
12738        pub fn set_unit(this: &NumberFormatOptions, value: &str);
12739
12740        #[wasm_bindgen(method, getter = unitDisplay)]
12741        pub fn get_unit_display(this: &NumberFormatOptions) -> Option<UnitDisplay>;
12742        #[wasm_bindgen(method, setter = unitDisplay)]
12743        pub fn set_unit_display(this: &NumberFormatOptions, value: UnitDisplay);
12744
12745        // Notation
12746        #[wasm_bindgen(method, getter = notation)]
12747        pub fn get_notation(this: &NumberFormatOptions) -> Option<NumberFormatNotation>;
12748        #[wasm_bindgen(method, setter = notation)]
12749        pub fn set_notation(this: &NumberFormatOptions, value: NumberFormatNotation);
12750
12751        #[wasm_bindgen(method, getter = compactDisplay)]
12752        pub fn get_compact_display(this: &NumberFormatOptions) -> Option<CompactDisplay>;
12753        #[wasm_bindgen(method, setter = compactDisplay)]
12754        pub fn set_compact_display(this: &NumberFormatOptions, value: CompactDisplay);
12755
12756        // Sign display
12757        #[wasm_bindgen(method, getter = signDisplay)]
12758        pub fn get_sign_display(this: &NumberFormatOptions) -> Option<SignDisplay>;
12759        #[wasm_bindgen(method, setter = signDisplay)]
12760        pub fn set_sign_display(this: &NumberFormatOptions, value: SignDisplay);
12761
12762        // Digit options
12763        #[wasm_bindgen(method, getter = minimumIntegerDigits)]
12764        pub fn get_minimum_integer_digits(this: &NumberFormatOptions) -> Option<u8>;
12765        #[wasm_bindgen(method, setter = minimumIntegerDigits)]
12766        pub fn set_minimum_integer_digits(this: &NumberFormatOptions, value: u8);
12767
12768        #[wasm_bindgen(method, getter = minimumFractionDigits)]
12769        pub fn get_minimum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
12770        #[wasm_bindgen(method, setter = minimumFractionDigits)]
12771        pub fn set_minimum_fraction_digits(this: &NumberFormatOptions, value: u8);
12772
12773        #[wasm_bindgen(method, getter = maximumFractionDigits)]
12774        pub fn get_maximum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
12775        #[wasm_bindgen(method, setter = maximumFractionDigits)]
12776        pub fn set_maximum_fraction_digits(this: &NumberFormatOptions, value: u8);
12777
12778        #[wasm_bindgen(method, getter = minimumSignificantDigits)]
12779        pub fn get_minimum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
12780        #[wasm_bindgen(method, setter = minimumSignificantDigits)]
12781        pub fn set_minimum_significant_digits(this: &NumberFormatOptions, value: u8);
12782
12783        #[wasm_bindgen(method, getter = maximumSignificantDigits)]
12784        pub fn get_maximum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
12785        #[wasm_bindgen(method, setter = maximumSignificantDigits)]
12786        pub fn set_maximum_significant_digits(this: &NumberFormatOptions, value: u8);
12787
12788        // Grouping
12789        #[wasm_bindgen(method, getter = useGrouping)]
12790        pub fn get_use_grouping(this: &NumberFormatOptions) -> Option<UseGrouping>;
12791        #[wasm_bindgen(method, setter = useGrouping)]
12792        pub fn set_use_grouping(this: &NumberFormatOptions, value: UseGrouping);
12793
12794        // Rounding
12795        #[wasm_bindgen(method, getter = roundingMode)]
12796        pub fn get_rounding_mode(this: &NumberFormatOptions) -> Option<RoundingMode>;
12797        #[wasm_bindgen(method, setter = roundingMode)]
12798        pub fn set_rounding_mode(this: &NumberFormatOptions, value: RoundingMode);
12799
12800        #[wasm_bindgen(method, getter = roundingPriority)]
12801        pub fn get_rounding_priority(this: &NumberFormatOptions) -> Option<RoundingPriority>;
12802        #[wasm_bindgen(method, setter = roundingPriority)]
12803        pub fn set_rounding_priority(this: &NumberFormatOptions, value: RoundingPriority);
12804
12805        #[wasm_bindgen(method, getter = roundingIncrement)]
12806        pub fn get_rounding_increment(this: &NumberFormatOptions) -> Option<u32>;
12807        #[wasm_bindgen(method, setter = roundingIncrement)]
12808        pub fn set_rounding_increment(this: &NumberFormatOptions, value: u32);
12809
12810        #[wasm_bindgen(method, getter = trailingZeroDisplay)]
12811        pub fn get_trailing_zero_display(this: &NumberFormatOptions)
12812            -> Option<TrailingZeroDisplay>;
12813        #[wasm_bindgen(method, setter = trailingZeroDisplay)]
12814        pub fn set_trailing_zero_display(this: &NumberFormatOptions, value: TrailingZeroDisplay);
12815    }
12816
12817    impl NumberFormatOptions {
12818        pub fn new() -> NumberFormatOptions {
12819            JsCast::unchecked_into(Object::new())
12820        }
12821    }
12822
12823    impl Default for NumberFormatOptions {
12824        fn default() -> Self {
12825            NumberFormatOptions::new()
12826        }
12827    }
12828
12829    // Intl.ResolvedNumberFormatOptions
12830    #[wasm_bindgen]
12831    extern "C" {
12832        /// Resolved options returned by `Intl.NumberFormat.prototype.resolvedOptions()`.
12833        ///
12834        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions)
12835        #[wasm_bindgen(extends = NumberFormatOptions)]
12836        #[derive(Clone, Debug)]
12837        pub type ResolvedNumberFormatOptions;
12838
12839        /// The resolved locale string.
12840        #[cfg(not(js_sys_unstable_apis))]
12841        #[wasm_bindgen(method, getter = locale)]
12842        pub fn get_locale(this: &ResolvedNumberFormatOptions) -> JsString;
12843
12844        /// The resolved locale string.
12845        #[cfg(js_sys_unstable_apis)]
12846        #[wasm_bindgen(method, getter = locale)]
12847        pub fn get_locale(this: &ResolvedNumberFormatOptions) -> String;
12848    }
12849
12850    // Intl.NumberFormatPart
12851    #[wasm_bindgen]
12852    extern "C" {
12853        /// A part of the formatted number returned by `formatToParts()`.
12854        ///
12855        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
12856        #[wasm_bindgen(extends = Object)]
12857        #[derive(Clone, Debug)]
12858        pub type NumberFormatPart;
12859
12860        /// The type of the part (e.g., "integer", "decimal", "fraction", "currency", etc.)
12861        #[wasm_bindgen(method, getter = type)]
12862        pub fn type_(this: &NumberFormatPart) -> NumberFormatPartType;
12863
12864        /// The value of the part.
12865        #[cfg(not(js_sys_unstable_apis))]
12866        #[wasm_bindgen(method, getter)]
12867        pub fn value(this: &NumberFormatPart) -> JsString;
12868
12869        /// The value of the part.
12870        #[cfg(js_sys_unstable_apis)]
12871        #[wasm_bindgen(method, getter)]
12872        pub fn value(this: &NumberFormatPart) -> String;
12873    }
12874
12875    // Intl.NumberRangeFormatPart
12876    #[wasm_bindgen]
12877    extern "C" {
12878        /// A part of the formatted number range returned by `formatRangeToParts()`.
12879        ///
12880        /// Extends `NumberFormatPart` with a `source` property indicating whether
12881        /// the part is from the start number, end number, or shared between them.
12882        ///
12883        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
12884        #[wasm_bindgen(extends = NumberFormatPart)]
12885        #[derive(Clone, Debug)]
12886        pub type NumberRangeFormatPart;
12887
12888        /// The source of the part: "startRange", "endRange", or "shared".
12889        #[wasm_bindgen(method, getter)]
12890        pub fn source(this: &NumberRangeFormatPart) -> RangeSource;
12891    }
12892
12893    // Intl.NumberFormat
12894    #[wasm_bindgen]
12895    extern "C" {
12896        /// The `Intl.NumberFormat` object is a constructor for objects
12897        /// that enable language sensitive number formatting.
12898        ///
12899        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
12900        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
12901        #[derive(Clone, Debug)]
12902        pub type NumberFormat;
12903
12904        /// The `Intl.NumberFormat` object is a constructor for objects
12905        /// that enable language sensitive number formatting.
12906        ///
12907        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
12908        #[cfg(not(js_sys_unstable_apis))]
12909        #[wasm_bindgen(constructor, js_namespace = Intl)]
12910        pub fn new(locales: &Array, options: &Object) -> NumberFormat;
12911
12912        /// The `Intl.NumberFormat` object is a constructor for objects
12913        /// that enable language sensitive number formatting.
12914        ///
12915        /// Throws a `RangeError` if locales contain invalid values.
12916        ///
12917        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
12918        #[cfg(js_sys_unstable_apis)]
12919        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12920        pub fn new(
12921            locales: &[JsString],
12922            options: &NumberFormatOptions,
12923        ) -> Result<NumberFormat, JsValue>;
12924
12925        /// The Intl.NumberFormat.prototype.format property returns a getter function that
12926        /// formats a number according to the locale and formatting options of this
12927        /// NumberFormat object.
12928        ///
12929        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
12930        #[cfg(not(js_sys_unstable_apis))]
12931        #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
12932        pub fn format(this: &NumberFormat) -> Function;
12933
12934        /// Formats a number according to the locale and formatting options of this
12935        /// `Intl.NumberFormat` object.
12936        ///
12937        /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
12938        /// or use E notation: `"1000000E-6"` → `"1"`).
12939        ///
12940        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format)
12941        #[cfg(js_sys_unstable_apis)]
12942        #[wasm_bindgen(method, js_class = "Intl.NumberFormat")]
12943        pub fn format(this: &NumberFormat, value: &JsString) -> String;
12944
12945        /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
12946        /// formatting of strings produced by NumberTimeFormat formatters.
12947        ///
12948        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
12949        #[cfg(not(js_sys_unstable_apis))]
12950        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
12951        pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
12952
12953        /// The `Intl.NumberFormat.prototype.formatToParts()` method allows locale-aware
12954        /// formatting of strings produced by `Intl.NumberFormat` formatters.
12955        ///
12956        /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
12957        /// or use E notation: `"1000000E-6"` → `"1"`).
12958        ///
12959        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
12960        #[cfg(js_sys_unstable_apis)]
12961        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
12962        pub fn format_to_parts(this: &NumberFormat, value: &JsString) -> Array<NumberFormatPart>;
12963
12964        /// Formats a range of numbers according to the locale and formatting options
12965        /// of this `Intl.NumberFormat` object.
12966        ///
12967        /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
12968        /// or use E notation: `"1000000E-6"` → `"1"`).
12969        ///
12970        /// Throws a `TypeError` if the values are invalid.
12971        ///
12972        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange)
12973        #[cfg(not(js_sys_unstable_apis))]
12974        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRange, catch)]
12975        pub fn format_range(
12976            this: &NumberFormat,
12977            start: &JsString,
12978            end: &JsString,
12979        ) -> Result<JsString, JsValue>;
12980
12981        /// Formats a range of numbers according to the locale and formatting options
12982        /// of this `Intl.NumberFormat` object.
12983        ///
12984        /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
12985        /// or use E notation: `"1000000E-6"` → `"1"`).
12986        ///
12987        /// Throws a `TypeError` if the values are invalid.
12988        ///
12989        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange)
12990        #[cfg(js_sys_unstable_apis)]
12991        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRange, catch)]
12992        pub fn format_range(
12993            this: &NumberFormat,
12994            start: &JsString,
12995            end: &JsString,
12996        ) -> Result<String, JsValue>;
12997
12998        /// Returns an array of locale-specific tokens representing each part of
12999        /// the formatted number range.
13000        ///
13001        /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
13002        /// or use E notation: `"1000000E-6"` → `"1"`).
13003        ///
13004        /// Throws a `TypeError` if the values are invalid.
13005        ///
13006        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
13007        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRangeToParts, catch)]
13008        pub fn format_range_to_parts(
13009            this: &NumberFormat,
13010            start: &JsString,
13011            end: &JsString,
13012        ) -> Result<Array<NumberRangeFormatPart>, JsValue>;
13013
13014        /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
13015        /// object with properties reflecting the locale and number formatting
13016        /// options computed during initialization of this NumberFormat object.
13017        ///
13018        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
13019        #[cfg(not(js_sys_unstable_apis))]
13020        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13021        pub fn resolved_options(this: &NumberFormat) -> Object;
13022
13023        /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
13024        /// object with properties reflecting the locale and number formatting
13025        /// options computed during initialization of this NumberFormat object.
13026        ///
13027        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
13028        #[cfg(js_sys_unstable_apis)]
13029        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13030        pub fn resolved_options(this: &NumberFormat) -> ResolvedNumberFormatOptions;
13031
13032        /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
13033        /// containing those of the provided locales that are supported in number
13034        /// formatting without having to fall back to the runtime's default locale.
13035        ///
13036        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
13037        #[cfg(not(js_sys_unstable_apis))]
13038        #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
13039        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
13040
13041        /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
13042        /// containing those of the provided locales that are supported in number
13043        /// formatting without having to fall back to the runtime's default locale.
13044        ///
13045        /// Throws a `RangeError` if locales contain invalid values.
13046        ///
13047        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
13048        #[cfg(js_sys_unstable_apis)]
13049        #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13050        pub fn supported_locales_of(
13051            locales: &[JsString],
13052            options: &LocaleMatcherOptions,
13053        ) -> Result<Array<JsString>, JsValue>;
13054    }
13055
13056    #[cfg(not(js_sys_unstable_apis))]
13057    impl Default for NumberFormat {
13058        fn default() -> Self {
13059            Self::new(
13060                &JsValue::UNDEFINED.unchecked_into(),
13061                &JsValue::UNDEFINED.unchecked_into(),
13062            )
13063        }
13064    }
13065
13066    #[cfg(js_sys_unstable_apis)]
13067    impl Default for NumberFormat {
13068        fn default() -> Self {
13069            Self::new(&[], &Default::default()).unwrap()
13070        }
13071    }
13072
13073    // Intl.PluralRulesOptions
13074    #[wasm_bindgen]
13075    extern "C" {
13076        /// Options for `Intl.PluralRules` constructor.
13077        ///
13078        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#options)
13079        #[wasm_bindgen(extends = Object)]
13080        #[derive(Clone, Debug)]
13081        pub type PluralRulesOptions;
13082
13083        #[wasm_bindgen(method, getter = localeMatcher)]
13084        pub fn get_locale_matcher(this: &PluralRulesOptions) -> Option<LocaleMatcher>;
13085        #[wasm_bindgen(method, setter = localeMatcher)]
13086        pub fn set_locale_matcher(this: &PluralRulesOptions, value: LocaleMatcher);
13087
13088        #[wasm_bindgen(method, getter = type)]
13089        pub fn get_type(this: &PluralRulesOptions) -> Option<PluralRulesType>;
13090        #[wasm_bindgen(method, setter = type)]
13091        pub fn set_type(this: &PluralRulesOptions, value: PluralRulesType);
13092
13093        #[wasm_bindgen(method, getter = minimumIntegerDigits)]
13094        pub fn get_minimum_integer_digits(this: &PluralRulesOptions) -> Option<u8>;
13095        #[wasm_bindgen(method, setter = minimumIntegerDigits)]
13096        pub fn set_minimum_integer_digits(this: &PluralRulesOptions, value: u8);
13097
13098        #[wasm_bindgen(method, getter = minimumFractionDigits)]
13099        pub fn get_minimum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
13100        #[wasm_bindgen(method, setter = minimumFractionDigits)]
13101        pub fn set_minimum_fraction_digits(this: &PluralRulesOptions, value: u8);
13102
13103        #[wasm_bindgen(method, getter = maximumFractionDigits)]
13104        pub fn get_maximum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
13105        #[wasm_bindgen(method, setter = maximumFractionDigits)]
13106        pub fn set_maximum_fraction_digits(this: &PluralRulesOptions, value: u8);
13107
13108        #[wasm_bindgen(method, getter = minimumSignificantDigits)]
13109        pub fn get_minimum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
13110        #[wasm_bindgen(method, setter = minimumSignificantDigits)]
13111        pub fn set_minimum_significant_digits(this: &PluralRulesOptions, value: u8);
13112
13113        #[wasm_bindgen(method, getter = maximumSignificantDigits)]
13114        pub fn get_maximum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
13115        #[wasm_bindgen(method, setter = maximumSignificantDigits)]
13116        pub fn set_maximum_significant_digits(this: &PluralRulesOptions, value: u8);
13117
13118        #[wasm_bindgen(method, getter = roundingPriority)]
13119        pub fn get_rounding_priority(this: &PluralRulesOptions) -> Option<RoundingPriority>;
13120        #[wasm_bindgen(method, setter = roundingPriority)]
13121        pub fn set_rounding_priority(this: &PluralRulesOptions, value: RoundingPriority);
13122
13123        #[wasm_bindgen(method, getter = roundingIncrement)]
13124        pub fn get_rounding_increment(this: &PluralRulesOptions) -> Option<u32>;
13125        #[wasm_bindgen(method, setter = roundingIncrement)]
13126        pub fn set_rounding_increment(this: &PluralRulesOptions, value: u32);
13127
13128        #[wasm_bindgen(method, getter = roundingMode)]
13129        pub fn get_rounding_mode(this: &PluralRulesOptions) -> Option<RoundingMode>;
13130        #[wasm_bindgen(method, setter = roundingMode)]
13131        pub fn set_rounding_mode(this: &PluralRulesOptions, value: RoundingMode);
13132
13133        #[wasm_bindgen(method, getter = trailingZeroDisplay)]
13134        pub fn get_trailing_zero_display(this: &PluralRulesOptions) -> Option<TrailingZeroDisplay>;
13135        #[wasm_bindgen(method, setter = trailingZeroDisplay)]
13136        pub fn set_trailing_zero_display(this: &PluralRulesOptions, value: TrailingZeroDisplay);
13137    }
13138
13139    impl PluralRulesOptions {
13140        pub fn new() -> PluralRulesOptions {
13141            JsCast::unchecked_into(Object::new())
13142        }
13143    }
13144
13145    impl Default for PluralRulesOptions {
13146        fn default() -> Self {
13147            PluralRulesOptions::new()
13148        }
13149    }
13150
13151    // Intl.ResolvedPluralRulesOptions
13152    #[wasm_bindgen]
13153    extern "C" {
13154        /// Resolved options returned by `Intl.PluralRules.prototype.resolvedOptions()`.
13155        ///
13156        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/resolvedOptions)
13157        #[wasm_bindgen(extends = PluralRulesOptions)]
13158        #[derive(Clone, Debug)]
13159        pub type ResolvedPluralRulesOptions;
13160
13161        /// The resolved locale string.
13162        #[cfg(not(js_sys_unstable_apis))]
13163        #[wasm_bindgen(method, getter = locale)]
13164        pub fn get_locale(this: &ResolvedPluralRulesOptions) -> JsString;
13165
13166        /// The resolved locale string.
13167        #[cfg(js_sys_unstable_apis)]
13168        #[wasm_bindgen(method, getter = locale)]
13169        pub fn get_locale(this: &ResolvedPluralRulesOptions) -> String;
13170
13171        /// The plural categories used by the locale.
13172        #[wasm_bindgen(method, getter = pluralCategories)]
13173        pub fn get_plural_categories(this: &ResolvedPluralRulesOptions) -> Array<JsString>;
13174    }
13175
13176    // Intl.PluralRules
13177    #[wasm_bindgen]
13178    extern "C" {
13179        /// The `Intl.PluralRules` object is a constructor for objects
13180        /// that enable plural sensitive formatting and plural language rules.
13181        ///
13182        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
13183        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
13184        #[derive(Clone, Debug)]
13185        pub type PluralRules;
13186
13187        /// The `Intl.PluralRules` object is a constructor for objects
13188        /// that enable plural sensitive formatting and plural language rules.
13189        ///
13190        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
13191        #[cfg(not(js_sys_unstable_apis))]
13192        #[wasm_bindgen(constructor, js_namespace = Intl)]
13193        pub fn new(locales: &Array, options: &Object) -> PluralRules;
13194
13195        /// The `Intl.PluralRules` object is a constructor for objects
13196        /// that enable plural sensitive formatting and plural language rules.
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/PluralRules)
13201        #[cfg(js_sys_unstable_apis)]
13202        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13203        pub fn new(
13204            locales: &[JsString],
13205            options: &PluralRulesOptions,
13206        ) -> Result<PluralRules, JsValue>;
13207
13208        /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
13209        /// object with properties reflecting the locale and plural formatting
13210        /// options computed during initialization of this PluralRules object.
13211        ///
13212        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
13213        #[cfg(not(js_sys_unstable_apis))]
13214        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13215        pub fn resolved_options(this: &PluralRules) -> Object;
13216
13217        /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
13218        /// object with properties reflecting the locale and plural formatting
13219        /// options computed during initialization of this PluralRules object.
13220        ///
13221        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
13222        #[cfg(js_sys_unstable_apis)]
13223        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13224        pub fn resolved_options(this: &PluralRules) -> ResolvedPluralRulesOptions;
13225
13226        /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
13227        /// which plural rule to use for locale-aware formatting.
13228        ///
13229        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
13230        #[cfg(not(js_sys_unstable_apis))]
13231        #[wasm_bindgen(method, js_namespace = Intl)]
13232        pub fn select(this: &PluralRules, number: f64) -> JsString;
13233
13234        /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
13235        /// which plural rule to use for locale-aware formatting.
13236        ///
13237        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
13238        #[cfg(js_sys_unstable_apis)]
13239        #[wasm_bindgen(method, js_namespace = Intl)]
13240        pub fn select(this: &PluralRules, number: f64) -> PluralCategory;
13241
13242        /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
13243        /// which plural rule to use for locale-aware formatting of a range of numbers.
13244        ///
13245        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
13246        #[cfg(not(js_sys_unstable_apis))]
13247        #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
13248        pub fn select_range(this: &PluralRules, start: f64, end: f64) -> JsString;
13249
13250        /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
13251        /// which plural rule to use for locale-aware formatting of a range of numbers.
13252        ///
13253        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
13254        #[cfg(js_sys_unstable_apis)]
13255        #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
13256        pub fn select_range(this: &PluralRules, start: f64, end: f64) -> PluralCategory;
13257
13258        /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
13259        /// containing those of the provided locales that are supported in plural
13260        /// formatting without having to fall back to the runtime's default locale.
13261        ///
13262        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
13263        #[cfg(not(js_sys_unstable_apis))]
13264        #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
13265        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
13266
13267        /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
13268        /// containing those of the provided locales that are supported in plural
13269        /// formatting without having to fall back to the runtime's default locale.
13270        ///
13271        /// Throws a `RangeError` if locales contain invalid values.
13272        ///
13273        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
13274        #[cfg(js_sys_unstable_apis)]
13275        #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13276        pub fn supported_locales_of(
13277            locales: &[JsString],
13278            options: &LocaleMatcherOptions,
13279        ) -> Result<Array<JsString>, JsValue>;
13280    }
13281
13282    #[cfg(not(js_sys_unstable_apis))]
13283    impl Default for PluralRules {
13284        fn default() -> Self {
13285            Self::new(
13286                &JsValue::UNDEFINED.unchecked_into(),
13287                &JsValue::UNDEFINED.unchecked_into(),
13288            )
13289        }
13290    }
13291
13292    #[cfg(js_sys_unstable_apis)]
13293    impl Default for PluralRules {
13294        fn default() -> Self {
13295            Self::new(&[], &Default::default()).unwrap()
13296        }
13297    }
13298
13299    // Intl.RelativeTimeFormat
13300    #[wasm_bindgen]
13301    extern "C" {
13302        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
13303        /// that enable language-sensitive relative time formatting.
13304        ///
13305        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
13306        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
13307        #[derive(Clone, Debug)]
13308        pub type RelativeTimeFormat;
13309
13310        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
13311        /// that enable language-sensitive relative time formatting.
13312        ///
13313        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
13314        #[cfg(not(js_sys_unstable_apis))]
13315        #[wasm_bindgen(constructor, js_namespace = Intl)]
13316        pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
13317
13318        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
13319        /// that enable language-sensitive relative time formatting.
13320        ///
13321        /// Throws a `RangeError` if locales contain invalid values.
13322        ///
13323        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
13324        #[cfg(js_sys_unstable_apis)]
13325        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13326        pub fn new(locales: &[JsString]) -> Result<RelativeTimeFormat, JsValue>;
13327
13328        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
13329        /// that enable language-sensitive relative time formatting.
13330        ///
13331        /// Throws a `RangeError` if locales or options contain invalid values.
13332        ///
13333        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
13334        #[cfg(js_sys_unstable_apis)]
13335        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13336        pub fn new_with_options(
13337            locales: &[JsString],
13338            options: &RelativeTimeFormatOptions,
13339        ) -> Result<RelativeTimeFormat, JsValue>;
13340
13341        /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
13342        /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
13343        ///
13344        /// Throws a `RangeError` if unit is invalid.
13345        ///
13346        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
13347        #[cfg(not(js_sys_unstable_apis))]
13348        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
13349        pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
13350
13351        /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
13352        /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
13353        ///
13354        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
13355        #[cfg(js_sys_unstable_apis)]
13356        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
13357        pub fn format(
13358            this: &RelativeTimeFormat,
13359            value: f64,
13360            unit: RelativeTimeFormatUnit,
13361        ) -> String;
13362
13363        /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
13364        /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
13365        ///
13366        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
13367        #[cfg(not(js_sys_unstable_apis))]
13368        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
13369        pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
13370
13371        /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
13372        /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
13373        ///
13374        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
13375        #[cfg(js_sys_unstable_apis)]
13376        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
13377        pub fn format_to_parts(
13378            this: &RelativeTimeFormat,
13379            value: f64,
13380            unit: RelativeTimeFormatUnit,
13381        ) -> Array<RelativeTimeFormatPart>;
13382
13383        /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
13384        /// object with properties reflecting the locale and relative time formatting
13385        /// options computed during initialization of this RelativeTimeFormat object.
13386        ///
13387        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
13388        #[cfg(not(js_sys_unstable_apis))]
13389        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13390        pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
13391
13392        /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
13393        /// object with properties reflecting the locale and relative time formatting
13394        /// options computed during initialization of this RelativeTimeFormat object.
13395        ///
13396        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
13397        #[cfg(js_sys_unstable_apis)]
13398        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13399        pub fn resolved_options(this: &RelativeTimeFormat) -> ResolvedRelativeTimeFormatOptions;
13400
13401        /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
13402        /// containing those of the provided locales that are supported in date and time
13403        /// formatting without having to fall back to the runtime's default locale.
13404        ///
13405        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
13406        #[cfg(not(js_sys_unstable_apis))]
13407        #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
13408        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
13409
13410        /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
13411        /// containing those of the provided locales that are supported in date and time
13412        /// formatting without having to fall back to the runtime's default locale.
13413        ///
13414        /// Throws a `RangeError` if locales contain invalid values.
13415        ///
13416        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
13417        #[cfg(js_sys_unstable_apis)]
13418        #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13419        pub fn supported_locales_of(
13420            locales: &[JsString],
13421            options: &LocaleMatcherOptions,
13422        ) -> Result<Array<JsString>, JsValue>;
13423    }
13424
13425    #[cfg(not(js_sys_unstable_apis))]
13426    impl Default for RelativeTimeFormat {
13427        fn default() -> Self {
13428            Self::new(
13429                &JsValue::UNDEFINED.unchecked_into(),
13430                &JsValue::UNDEFINED.unchecked_into(),
13431            )
13432        }
13433    }
13434
13435    #[cfg(js_sys_unstable_apis)]
13436    impl Default for RelativeTimeFormat {
13437        fn default() -> Self {
13438            Self::new(&[]).unwrap()
13439        }
13440    }
13441
13442    // Intl.ListFormatOptions
13443    #[wasm_bindgen]
13444    extern "C" {
13445        /// Options for `Intl.ListFormat` constructor.
13446        ///
13447        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#options)
13448        #[wasm_bindgen(extends = Object)]
13449        #[derive(Clone, Debug)]
13450        pub type ListFormatOptions;
13451
13452        #[wasm_bindgen(method, getter = localeMatcher)]
13453        pub fn get_locale_matcher(this: &ListFormatOptions) -> Option<LocaleMatcher>;
13454        #[wasm_bindgen(method, setter = localeMatcher)]
13455        pub fn set_locale_matcher(this: &ListFormatOptions, value: LocaleMatcher);
13456
13457        #[wasm_bindgen(method, getter = type)]
13458        pub fn get_type(this: &ListFormatOptions) -> Option<ListFormatType>;
13459        #[wasm_bindgen(method, setter = type)]
13460        pub fn set_type(this: &ListFormatOptions, value: ListFormatType);
13461
13462        #[wasm_bindgen(method, getter = style)]
13463        pub fn get_style(this: &ListFormatOptions) -> Option<ListFormatStyle>;
13464        #[wasm_bindgen(method, setter = style)]
13465        pub fn set_style(this: &ListFormatOptions, value: ListFormatStyle);
13466    }
13467
13468    impl ListFormatOptions {
13469        pub fn new() -> ListFormatOptions {
13470            JsCast::unchecked_into(Object::new())
13471        }
13472    }
13473
13474    impl Default for ListFormatOptions {
13475        fn default() -> Self {
13476            ListFormatOptions::new()
13477        }
13478    }
13479
13480    // Intl.ResolvedListFormatOptions
13481    #[wasm_bindgen]
13482    extern "C" {
13483        /// Resolved options returned by `Intl.ListFormat.prototype.resolvedOptions()`.
13484        ///
13485        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
13486        #[wasm_bindgen(extends = ListFormatOptions)]
13487        #[derive(Clone, Debug)]
13488        pub type ResolvedListFormatOptions;
13489
13490        /// The resolved locale string.
13491        #[cfg(not(js_sys_unstable_apis))]
13492        #[wasm_bindgen(method, getter = locale)]
13493        pub fn get_locale(this: &ResolvedListFormatOptions) -> JsString;
13494
13495        /// The resolved locale string.
13496        #[cfg(js_sys_unstable_apis)]
13497        #[wasm_bindgen(method, getter = locale)]
13498        pub fn get_locale(this: &ResolvedListFormatOptions) -> String;
13499    }
13500
13501    // Intl.ListFormatPart
13502    #[wasm_bindgen]
13503    extern "C" {
13504        /// A part of the formatted list returned by `formatToParts()`.
13505        ///
13506        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
13507        #[wasm_bindgen(extends = Object)]
13508        #[derive(Clone, Debug)]
13509        pub type ListFormatPart;
13510
13511        /// The type of the part ("element" or "literal").
13512        #[wasm_bindgen(method, getter = type)]
13513        pub fn type_(this: &ListFormatPart) -> ListFormatPartType;
13514
13515        /// The value of the part.
13516        #[cfg(not(js_sys_unstable_apis))]
13517        #[wasm_bindgen(method, getter)]
13518        pub fn value(this: &ListFormatPart) -> JsString;
13519
13520        /// The value of the part.
13521        #[cfg(js_sys_unstable_apis)]
13522        #[wasm_bindgen(method, getter)]
13523        pub fn value(this: &ListFormatPart) -> String;
13524    }
13525
13526    // Intl.ListFormat
13527    #[wasm_bindgen]
13528    extern "C" {
13529        /// The `Intl.ListFormat` object enables language-sensitive list formatting.
13530        ///
13531        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat)
13532        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.ListFormat")]
13533        #[derive(Clone, Debug)]
13534        pub type ListFormat;
13535
13536        /// Creates a new `Intl.ListFormat` object.
13537        ///
13538        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
13539        #[cfg(not(js_sys_unstable_apis))]
13540        #[wasm_bindgen(constructor, js_namespace = Intl)]
13541        pub fn new(locales: &Array, options: &Object) -> ListFormat;
13542
13543        /// Creates a new `Intl.ListFormat` object.
13544        ///
13545        /// Throws a `RangeError` if locales or options contain invalid values.
13546        ///
13547        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
13548        #[cfg(js_sys_unstable_apis)]
13549        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13550        pub fn new(
13551            locales: &[JsString],
13552            options: &ListFormatOptions,
13553        ) -> Result<ListFormat, JsValue>;
13554
13555        /// Formats a list of strings according to the locale and options.
13556        ///
13557        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
13558        #[cfg(not(js_sys_unstable_apis))]
13559        #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
13560        pub fn format(this: &ListFormat, list: &Array) -> JsString;
13561
13562        /// Formats a list of strings according to the locale and options.
13563        ///
13564        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
13565        #[cfg(js_sys_unstable_apis)]
13566        #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
13567        pub fn format(this: &ListFormat, list: &[JsString]) -> String;
13568
13569        /// Returns an array of objects representing the list in parts.
13570        ///
13571        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
13572        #[cfg(not(js_sys_unstable_apis))]
13573        #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
13574        pub fn format_to_parts(this: &ListFormat, list: &Array) -> Array;
13575
13576        /// Returns an array of objects representing the list in parts.
13577        ///
13578        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
13579        #[cfg(js_sys_unstable_apis)]
13580        #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
13581        pub fn format_to_parts(this: &ListFormat, list: &[JsString]) -> Array<ListFormatPart>;
13582
13583        /// Returns an object with properties reflecting the options used.
13584        ///
13585        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
13586        #[cfg(not(js_sys_unstable_apis))]
13587        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13588        pub fn resolved_options(this: &ListFormat) -> Object;
13589
13590        /// Returns an object with properties reflecting the options used.
13591        ///
13592        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
13593        #[cfg(js_sys_unstable_apis)]
13594        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13595        pub fn resolved_options(this: &ListFormat) -> ResolvedListFormatOptions;
13596
13597        /// Returns an array of supported locales.
13598        ///
13599        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
13600        #[cfg(not(js_sys_unstable_apis))]
13601        #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
13602        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
13603
13604        /// Returns an array of supported locales.
13605        ///
13606        /// Throws a `RangeError` if locales contain invalid values.
13607        ///
13608        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
13609        #[cfg(js_sys_unstable_apis)]
13610        #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13611        pub fn supported_locales_of(
13612            locales: &[JsString],
13613            options: &LocaleMatcherOptions,
13614        ) -> Result<Array<JsString>, JsValue>;
13615    }
13616
13617    #[cfg(not(js_sys_unstable_apis))]
13618    impl Default for ListFormat {
13619        fn default() -> Self {
13620            Self::new(
13621                &JsValue::UNDEFINED.unchecked_into(),
13622                &JsValue::UNDEFINED.unchecked_into(),
13623            )
13624        }
13625    }
13626
13627    #[cfg(js_sys_unstable_apis)]
13628    impl Default for ListFormat {
13629        fn default() -> Self {
13630            Self::new(&[], &Default::default()).unwrap()
13631        }
13632    }
13633
13634    // Intl.SegmenterOptions
13635    #[wasm_bindgen]
13636    extern "C" {
13637        /// Options for `Intl.Segmenter` constructor.
13638        ///
13639        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#options)
13640        #[wasm_bindgen(extends = Object)]
13641        #[derive(Clone, Debug)]
13642        pub type SegmenterOptions;
13643
13644        #[wasm_bindgen(method, getter = localeMatcher)]
13645        pub fn get_locale_matcher(this: &SegmenterOptions) -> Option<LocaleMatcher>;
13646        #[wasm_bindgen(method, setter = localeMatcher)]
13647        pub fn set_locale_matcher(this: &SegmenterOptions, value: LocaleMatcher);
13648
13649        #[wasm_bindgen(method, getter = granularity)]
13650        pub fn get_granularity(this: &SegmenterOptions) -> Option<SegmenterGranularity>;
13651        #[wasm_bindgen(method, setter = granularity)]
13652        pub fn set_granularity(this: &SegmenterOptions, value: SegmenterGranularity);
13653    }
13654
13655    impl SegmenterOptions {
13656        pub fn new() -> SegmenterOptions {
13657            JsCast::unchecked_into(Object::new())
13658        }
13659    }
13660
13661    impl Default for SegmenterOptions {
13662        fn default() -> Self {
13663            SegmenterOptions::new()
13664        }
13665    }
13666
13667    // Intl.ResolvedSegmenterOptions
13668    #[wasm_bindgen]
13669    extern "C" {
13670        /// Resolved options returned by `Intl.Segmenter.prototype.resolvedOptions()`.
13671        ///
13672        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
13673        #[wasm_bindgen(extends = SegmenterOptions)]
13674        #[derive(Clone, Debug)]
13675        pub type ResolvedSegmenterOptions;
13676
13677        /// The resolved locale string.
13678        #[cfg(not(js_sys_unstable_apis))]
13679        #[wasm_bindgen(method, getter = locale)]
13680        pub fn get_locale(this: &ResolvedSegmenterOptions) -> JsString;
13681
13682        /// The resolved locale string.
13683        #[cfg(js_sys_unstable_apis)]
13684        #[wasm_bindgen(method, getter = locale)]
13685        pub fn get_locale(this: &ResolvedSegmenterOptions) -> String;
13686    }
13687
13688    // Intl.SegmentData
13689    #[wasm_bindgen]
13690    extern "C" {
13691        /// Data about a segment returned by the Segments iterator.
13692        ///
13693        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments#segment_data)
13694        #[wasm_bindgen(extends = Object)]
13695        #[derive(Clone, Debug)]
13696        pub type SegmentData;
13697
13698        /// The segment string.
13699        #[cfg(not(js_sys_unstable_apis))]
13700        #[wasm_bindgen(method, getter)]
13701        pub fn segment(this: &SegmentData) -> JsString;
13702
13703        /// The segment string.
13704        #[cfg(js_sys_unstable_apis)]
13705        #[wasm_bindgen(method, getter)]
13706        pub fn segment(this: &SegmentData) -> String;
13707
13708        /// The index of the segment in the original string.
13709        #[wasm_bindgen(method, getter)]
13710        pub fn index(this: &SegmentData) -> u32;
13711
13712        /// The original input string.
13713        #[wasm_bindgen(method, getter)]
13714        pub fn input(this: &SegmentData) -> JsString;
13715
13716        /// Whether the segment is word-like (only for word granularity).
13717        #[wasm_bindgen(method, getter = isWordLike)]
13718        pub fn is_word_like(this: &SegmentData) -> Option<bool>;
13719    }
13720
13721    // Intl.Segments
13722    #[wasm_bindgen]
13723    extern "C" {
13724        /// The Segments object is an iterable collection of segments of a string.
13725        ///
13726        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments)
13727        #[wasm_bindgen(extends = Object)]
13728        #[derive(Clone, Debug)]
13729        pub type Segments;
13730
13731        /// Returns segment data for the segment containing the character at the given index.
13732        ///
13733        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments/containing)
13734        #[wasm_bindgen(method)]
13735        pub fn containing(this: &Segments, index: u32) -> Option<SegmentData>;
13736    }
13737
13738    // Intl.Segmenter
13739    #[wasm_bindgen]
13740    extern "C" {
13741        /// The `Intl.Segmenter` object enables locale-sensitive text segmentation.
13742        ///
13743        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter)
13744        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Segmenter")]
13745        #[derive(Clone, Debug)]
13746        pub type Segmenter;
13747
13748        /// Creates a new `Intl.Segmenter` object.
13749        ///
13750        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
13751        #[cfg(not(js_sys_unstable_apis))]
13752        #[wasm_bindgen(constructor, js_namespace = Intl)]
13753        pub fn new(locales: &Array, options: &Object) -> Segmenter;
13754
13755        /// Creates a new `Intl.Segmenter` object.
13756        ///
13757        /// Throws a `RangeError` if locales or options contain invalid values.
13758        ///
13759        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
13760        #[cfg(js_sys_unstable_apis)]
13761        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13762        pub fn new(locales: &[JsString], options: &SegmenterOptions) -> Result<Segmenter, JsValue>;
13763
13764        /// Returns a Segments object containing the segments of the input string.
13765        ///
13766        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment)
13767        #[wasm_bindgen(method, js_class = "Intl.Segmenter")]
13768        pub fn segment(this: &Segmenter, input: &str) -> Segments;
13769
13770        /// Returns an object with properties reflecting the options used.
13771        ///
13772        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
13773        #[cfg(not(js_sys_unstable_apis))]
13774        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13775        pub fn resolved_options(this: &Segmenter) -> Object;
13776
13777        /// Returns an object with properties reflecting the options used.
13778        ///
13779        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
13780        #[cfg(js_sys_unstable_apis)]
13781        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13782        pub fn resolved_options(this: &Segmenter) -> ResolvedSegmenterOptions;
13783
13784        /// Returns an array of supported locales.
13785        ///
13786        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
13787        #[cfg(not(js_sys_unstable_apis))]
13788        #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf)]
13789        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
13790
13791        /// Returns an array of supported locales.
13792        ///
13793        /// Throws a `RangeError` if locales contain invalid values.
13794        ///
13795        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
13796        #[cfg(js_sys_unstable_apis)]
13797        #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13798        pub fn supported_locales_of(
13799            locales: &[JsString],
13800            options: &LocaleMatcherOptions,
13801        ) -> Result<Array<JsString>, JsValue>;
13802    }
13803
13804    #[cfg(not(js_sys_unstable_apis))]
13805    impl Default for Segmenter {
13806        fn default() -> Self {
13807            Self::new(
13808                &JsValue::UNDEFINED.unchecked_into(),
13809                &JsValue::UNDEFINED.unchecked_into(),
13810            )
13811        }
13812    }
13813
13814    #[cfg(js_sys_unstable_apis)]
13815    impl Default for Segmenter {
13816        fn default() -> Self {
13817            Self::new(&[], &Default::default()).unwrap()
13818        }
13819    }
13820
13821    // Intl.DisplayNamesOptions
13822    #[wasm_bindgen]
13823    extern "C" {
13824        /// Options for `Intl.DisplayNames` constructor.
13825        ///
13826        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options)
13827        #[wasm_bindgen(extends = Object)]
13828        #[derive(Clone, Debug)]
13829        pub type DisplayNamesOptions;
13830
13831        #[wasm_bindgen(method, getter = localeMatcher)]
13832        pub fn get_locale_matcher(this: &DisplayNamesOptions) -> Option<LocaleMatcher>;
13833        #[wasm_bindgen(method, setter = localeMatcher)]
13834        pub fn set_locale_matcher(this: &DisplayNamesOptions, value: LocaleMatcher);
13835
13836        #[wasm_bindgen(method, getter = type)]
13837        pub fn get_type(this: &DisplayNamesOptions) -> Option<DisplayNamesType>;
13838        #[wasm_bindgen(method, setter = type)]
13839        pub fn set_type(this: &DisplayNamesOptions, value: DisplayNamesType);
13840
13841        #[wasm_bindgen(method, getter = style)]
13842        pub fn get_style(this: &DisplayNamesOptions) -> Option<DisplayNamesStyle>;
13843        #[wasm_bindgen(method, setter = style)]
13844        pub fn set_style(this: &DisplayNamesOptions, value: DisplayNamesStyle);
13845
13846        #[wasm_bindgen(method, getter = fallback)]
13847        pub fn get_fallback(this: &DisplayNamesOptions) -> Option<DisplayNamesFallback>;
13848        #[wasm_bindgen(method, setter = fallback)]
13849        pub fn set_fallback(this: &DisplayNamesOptions, value: DisplayNamesFallback);
13850
13851        #[wasm_bindgen(method, getter = languageDisplay)]
13852        pub fn get_language_display(
13853            this: &DisplayNamesOptions,
13854        ) -> Option<DisplayNamesLanguageDisplay>;
13855        #[wasm_bindgen(method, setter = languageDisplay)]
13856        pub fn set_language_display(this: &DisplayNamesOptions, value: DisplayNamesLanguageDisplay);
13857    }
13858
13859    impl DisplayNamesOptions {
13860        pub fn new() -> DisplayNamesOptions {
13861            JsCast::unchecked_into(Object::new())
13862        }
13863    }
13864
13865    impl Default for DisplayNamesOptions {
13866        fn default() -> Self {
13867            DisplayNamesOptions::new()
13868        }
13869    }
13870
13871    // Intl.ResolvedDisplayNamesOptions
13872    #[wasm_bindgen]
13873    extern "C" {
13874        /// Resolved options returned by `Intl.DisplayNames.prototype.resolvedOptions()`.
13875        ///
13876        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
13877        #[wasm_bindgen(extends = DisplayNamesOptions)]
13878        #[derive(Clone, Debug)]
13879        pub type ResolvedDisplayNamesOptions;
13880
13881        /// The resolved locale string.
13882        #[cfg(not(js_sys_unstable_apis))]
13883        #[wasm_bindgen(method, getter = locale)]
13884        pub fn get_locale(this: &ResolvedDisplayNamesOptions) -> JsString;
13885
13886        /// The resolved locale string.
13887        #[cfg(js_sys_unstable_apis)]
13888        #[wasm_bindgen(method, getter = locale)]
13889        pub fn get_locale(this: &ResolvedDisplayNamesOptions) -> String;
13890    }
13891
13892    // Intl.DisplayNames
13893    #[wasm_bindgen]
13894    extern "C" {
13895        /// The `Intl.DisplayNames` object enables the consistent translation of
13896        /// language, region, and script display names.
13897        ///
13898        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
13899        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DisplayNames")]
13900        #[derive(Clone, Debug)]
13901        pub type DisplayNames;
13902
13903        /// Creates a new `Intl.DisplayNames` object.
13904        ///
13905        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
13906        #[cfg(not(js_sys_unstable_apis))]
13907        #[wasm_bindgen(constructor, js_namespace = Intl)]
13908        pub fn new(locales: &Array, options: &Object) -> DisplayNames;
13909
13910        /// Creates a new `Intl.DisplayNames` object.
13911        ///
13912        /// Throws a `RangeError` if locales or options contain invalid values.
13913        ///
13914        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
13915        #[cfg(js_sys_unstable_apis)]
13916        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13917        pub fn new(
13918            locales: &[JsString],
13919            options: &DisplayNamesOptions,
13920        ) -> Result<DisplayNames, JsValue>;
13921
13922        /// Returns the display name for the given code.
13923        ///
13924        /// Returns `undefined` if fallback is "none" and no name is available.
13925        ///
13926        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of)
13927        #[wasm_bindgen(method, js_class = "Intl.DisplayNames")]
13928        pub fn of(this: &DisplayNames, code: &str) -> Option<JsString>;
13929
13930        /// Returns an object with properties reflecting the options used.
13931        ///
13932        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
13933        #[cfg(not(js_sys_unstable_apis))]
13934        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13935        pub fn resolved_options(this: &DisplayNames) -> Object;
13936
13937        /// Returns an object with properties reflecting the options used.
13938        ///
13939        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
13940        #[cfg(js_sys_unstable_apis)]
13941        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13942        pub fn resolved_options(this: &DisplayNames) -> ResolvedDisplayNamesOptions;
13943
13944        /// Returns an array of supported locales.
13945        ///
13946        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
13947        #[cfg(not(js_sys_unstable_apis))]
13948        #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf)]
13949        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
13950
13951        /// Returns an array of supported locales.
13952        ///
13953        /// Throws a `RangeError` if locales contain invalid values.
13954        ///
13955        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
13956        #[cfg(js_sys_unstable_apis)]
13957        #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13958        pub fn supported_locales_of(
13959            locales: &[JsString],
13960            options: &LocaleMatcherOptions,
13961        ) -> Result<Array<JsString>, JsValue>;
13962    }
13963
13964    // Intl.Locale
13965    #[wasm_bindgen]
13966    extern "C" {
13967        /// The `Intl.Locale` object is a standard built-in property of the Intl object
13968        /// that represents a Unicode locale identifier.
13969        ///
13970        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
13971        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Locale")]
13972        #[derive(Clone, Debug)]
13973        pub type Locale;
13974
13975        /// Creates a new `Intl.Locale` object.
13976        ///
13977        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
13978        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13979        pub fn new(tag: &str) -> Result<Locale, JsValue>;
13980
13981        /// Creates a new `Intl.Locale` object with options.
13982        ///
13983        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
13984        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13985        pub fn new_with_options(tag: &str, options: &Object) -> Result<Locale, JsValue>;
13986
13987        /// The base name of the locale (language + region + script).
13988        ///
13989        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName)
13990        #[cfg(not(js_sys_unstable_apis))]
13991        #[wasm_bindgen(method, getter = baseName)]
13992        pub fn base_name(this: &Locale) -> JsString;
13993
13994        /// The base name of the locale (language + region + script).
13995        ///
13996        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName)
13997        #[cfg(js_sys_unstable_apis)]
13998        #[wasm_bindgen(method, getter = baseName)]
13999        pub fn base_name(this: &Locale) -> String;
14000
14001        /// The calendar type for the locale.
14002        ///
14003        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar)
14004        #[wasm_bindgen(method, getter)]
14005        pub fn calendar(this: &Locale) -> Option<JsString>;
14006
14007        /// The case first sorting option.
14008        ///
14009        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst)
14010        #[wasm_bindgen(method, getter = caseFirst)]
14011        pub fn case_first(this: &Locale) -> Option<JsString>;
14012
14013        /// The collation type for the locale.
14014        ///
14015        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation)
14016        #[wasm_bindgen(method, getter)]
14017        pub fn collation(this: &Locale) -> Option<JsString>;
14018
14019        /// The hour cycle for the locale.
14020        ///
14021        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle)
14022        #[wasm_bindgen(method, getter = hourCycle)]
14023        pub fn hour_cycle(this: &Locale) -> Option<JsString>;
14024
14025        /// The language code for the locale.
14026        ///
14027        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language)
14028        #[cfg(not(js_sys_unstable_apis))]
14029        #[wasm_bindgen(method, getter)]
14030        pub fn language(this: &Locale) -> JsString;
14031
14032        /// The language code for the locale.
14033        ///
14034        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language)
14035        #[cfg(js_sys_unstable_apis)]
14036        #[wasm_bindgen(method, getter)]
14037        pub fn language(this: &Locale) -> String;
14038
14039        /// The numbering system for the locale.
14040        ///
14041        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem)
14042        #[wasm_bindgen(method, getter = numberingSystem)]
14043        pub fn numbering_system(this: &Locale) -> Option<JsString>;
14044
14045        /// Whether the locale uses numeric collation.
14046        ///
14047        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric)
14048        #[wasm_bindgen(method, getter)]
14049        pub fn numeric(this: &Locale) -> bool;
14050
14051        /// The region code for the locale.
14052        ///
14053        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/region)
14054        #[wasm_bindgen(method, getter)]
14055        pub fn region(this: &Locale) -> Option<JsString>;
14056
14057        /// The script code for the locale.
14058        ///
14059        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/script)
14060        #[wasm_bindgen(method, getter)]
14061        pub fn script(this: &Locale) -> Option<JsString>;
14062
14063        /// The `firstDayOfWeek` accessor property returns the first day of
14064        /// the week for this locale, as a weekday code such as `"mon"`,
14065        /// when one was given via the `fw` extension or constructor option.
14066        ///
14067        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/firstDayOfWeek)
14068        #[wasm_bindgen(method, getter, js_namespace = Intl, js_name = firstDayOfWeek)]
14069        pub fn first_day_of_week(this: &Locale) -> Option<JsString>;
14070
14071        /// The `variants` accessor property returns the variant subtags of
14072        /// this locale, joined by `-`, if any.
14073        ///
14074        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/variants)
14075        #[wasm_bindgen(method, getter, js_namespace = Intl)]
14076        pub fn variants(this: &Locale) -> Option<JsString>;
14077
14078        /// Returns an array of available calendars for the locale.
14079        ///
14080        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars)
14081        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCalendars)]
14082        pub fn get_calendars(this: &Locale) -> Array<JsString>;
14083
14084        /// Returns an array of available collations for the locale.
14085        ///
14086        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations)
14087        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCollations)]
14088        pub fn get_collations(this: &Locale) -> Array<JsString>;
14089
14090        /// Returns an array of available hour cycles for the locale.
14091        ///
14092        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles)
14093        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getHourCycles)]
14094        pub fn get_hour_cycles(this: &Locale) -> Array<JsString>;
14095
14096        /// Returns an array of available numbering systems for the locale.
14097        ///
14098        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems)
14099        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getNumberingSystems)]
14100        pub fn get_numbering_systems(this: &Locale) -> Array<JsString>;
14101
14102        /// Returns an array of available time zones for the locale's region.
14103        ///
14104        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones)
14105        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTimeZones)]
14106        pub fn get_time_zones(this: &Locale) -> Option<Array<JsString>>;
14107
14108        /// Returns week information for the locale.
14109        ///
14110        /// May not be available in all environments.
14111        ///
14112        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
14113        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getWeekInfo, catch)]
14114        pub fn get_week_info(this: &Locale) -> Result<WeekInfo, JsValue>;
14115
14116        /// Returns text layout information for the locale.
14117        ///
14118        /// May not be available in all environments.
14119        ///
14120        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
14121        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTextInfo, catch)]
14122        pub fn get_text_info(this: &Locale) -> Result<TextInfo, JsValue>;
14123
14124        /// Returns a new Locale with the specified calendar.
14125        ///
14126        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize)
14127        #[wasm_bindgen(method, js_class = "Intl.Locale")]
14128        pub fn maximize(this: &Locale) -> Locale;
14129
14130        /// Returns a new Locale with the minimal subtags.
14131        ///
14132        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize)
14133        #[wasm_bindgen(method, js_class = "Intl.Locale")]
14134        pub fn minimize(this: &Locale) -> Locale;
14135    }
14136
14137    // Intl.Locale WeekInfo
14138    #[wasm_bindgen]
14139    extern "C" {
14140        /// Week information for a locale.
14141        ///
14142        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
14143        #[wasm_bindgen(extends = Object)]
14144        #[derive(Clone, Debug)]
14145        pub type WeekInfo;
14146
14147        /// The first day of the week (1 = Monday, 7 = Sunday).
14148        #[wasm_bindgen(method, getter = firstDay)]
14149        pub fn first_day(this: &WeekInfo) -> u8;
14150
14151        /// Array of weekend days.
14152        #[wasm_bindgen(method, getter)]
14153        pub fn weekend(this: &WeekInfo) -> Array<Number>;
14154
14155        /// Minimal days in the first week of the year.
14156        #[wasm_bindgen(method, getter = minimalDays)]
14157        pub fn minimal_days(this: &WeekInfo) -> u8;
14158    }
14159
14160    // Intl.Locale TextInfo
14161    #[wasm_bindgen]
14162    extern "C" {
14163        /// Text layout information for a locale.
14164        ///
14165        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
14166        #[wasm_bindgen(extends = Object)]
14167        #[derive(Clone, Debug)]
14168        pub type TextInfo;
14169
14170        /// The text direction ("ltr" or "rtl").
14171        #[cfg(not(js_sys_unstable_apis))]
14172        #[wasm_bindgen(method, getter)]
14173        pub fn direction(this: &TextInfo) -> JsString;
14174
14175        /// The text direction ("ltr" or "rtl").
14176        #[cfg(js_sys_unstable_apis)]
14177        #[wasm_bindgen(method, getter)]
14178        pub fn direction(this: &TextInfo) -> String;
14179    }
14180
14181    // Intl.DurationFormat enums
14182
14183    /// The style for duration formatting.
14184    ///
14185    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style)
14186    #[wasm_bindgen]
14187    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
14188    pub enum DurationFormatStyle {
14189        Long = "long",
14190        Short = "short",
14191        Narrow = "narrow",
14192        Digital = "digital",
14193    }
14194
14195    /// The display style for individual duration units.
14196    ///
14197    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#years)
14198    #[wasm_bindgen]
14199    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
14200    pub enum DurationUnitStyle {
14201        Long = "long",
14202        Short = "short",
14203        Narrow = "narrow",
14204    }
14205
14206    /// The display style for time duration units (hours, minutes, seconds).
14207    ///
14208    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#hours)
14209    #[wasm_bindgen]
14210    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
14211    pub enum DurationTimeUnitStyle {
14212        Long = "long",
14213        Short = "short",
14214        Narrow = "narrow",
14215        Numeric = "numeric",
14216        #[wasm_bindgen(js_name = "2-digit")]
14217        TwoDigit = "2-digit",
14218    }
14219
14220    /// The display option for duration units.
14221    ///
14222    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#yearsdisplay)
14223    #[wasm_bindgen]
14224    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
14225    pub enum DurationUnitDisplay {
14226        Auto = "auto",
14227        Always = "always",
14228    }
14229
14230    /// The type of a duration format part.
14231    ///
14232    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts#type)
14233    #[wasm_bindgen]
14234    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
14235    pub enum DurationFormatPartType {
14236        Years = "years",
14237        Months = "months",
14238        Weeks = "weeks",
14239        Days = "days",
14240        Hours = "hours",
14241        Minutes = "minutes",
14242        Seconds = "seconds",
14243        Milliseconds = "milliseconds",
14244        Microseconds = "microseconds",
14245        Nanoseconds = "nanoseconds",
14246        Literal = "literal",
14247        Integer = "integer",
14248        Decimal = "decimal",
14249        Fraction = "fraction",
14250    }
14251
14252    // Intl.DurationFormatOptions
14253    #[wasm_bindgen]
14254    extern "C" {
14255        /// Options for `Intl.DurationFormat` constructor.
14256        ///
14257        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#options)
14258        #[wasm_bindgen(extends = Object)]
14259        #[derive(Clone, Debug)]
14260        pub type DurationFormatOptions;
14261
14262        #[wasm_bindgen(method, getter = localeMatcher)]
14263        pub fn get_locale_matcher(this: &DurationFormatOptions) -> Option<LocaleMatcher>;
14264        #[wasm_bindgen(method, setter = localeMatcher)]
14265        pub fn set_locale_matcher(this: &DurationFormatOptions, value: LocaleMatcher);
14266
14267        #[wasm_bindgen(method, getter = style)]
14268        pub fn get_style(this: &DurationFormatOptions) -> Option<DurationFormatStyle>;
14269        #[wasm_bindgen(method, setter = style)]
14270        pub fn set_style(this: &DurationFormatOptions, value: DurationFormatStyle);
14271
14272        #[wasm_bindgen(method, getter = years)]
14273        pub fn get_years(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
14274        #[wasm_bindgen(method, setter = years)]
14275        pub fn set_years(this: &DurationFormatOptions, value: DurationUnitStyle);
14276
14277        #[wasm_bindgen(method, getter = yearsDisplay)]
14278        pub fn get_years_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
14279        #[wasm_bindgen(method, setter = yearsDisplay)]
14280        pub fn set_years_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
14281
14282        #[wasm_bindgen(method, getter = months)]
14283        pub fn get_months(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
14284        #[wasm_bindgen(method, setter = months)]
14285        pub fn set_months(this: &DurationFormatOptions, value: DurationUnitStyle);
14286
14287        #[wasm_bindgen(method, getter = monthsDisplay)]
14288        pub fn get_months_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
14289        #[wasm_bindgen(method, setter = monthsDisplay)]
14290        pub fn set_months_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
14291
14292        #[wasm_bindgen(method, getter = weeks)]
14293        pub fn get_weeks(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
14294        #[wasm_bindgen(method, setter = weeks)]
14295        pub fn set_weeks(this: &DurationFormatOptions, value: DurationUnitStyle);
14296
14297        #[wasm_bindgen(method, getter = weeksDisplay)]
14298        pub fn get_weeks_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
14299        #[wasm_bindgen(method, setter = weeksDisplay)]
14300        pub fn set_weeks_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
14301
14302        #[wasm_bindgen(method, getter = days)]
14303        pub fn get_days(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
14304        #[wasm_bindgen(method, setter = days)]
14305        pub fn set_days(this: &DurationFormatOptions, value: DurationUnitStyle);
14306
14307        #[wasm_bindgen(method, getter = daysDisplay)]
14308        pub fn get_days_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
14309        #[wasm_bindgen(method, setter = daysDisplay)]
14310        pub fn set_days_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
14311
14312        #[wasm_bindgen(method, getter = hours)]
14313        pub fn get_hours(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
14314        #[wasm_bindgen(method, setter = hours)]
14315        pub fn set_hours(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
14316
14317        #[wasm_bindgen(method, getter = hoursDisplay)]
14318        pub fn get_hours_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
14319        #[wasm_bindgen(method, setter = hoursDisplay)]
14320        pub fn set_hours_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
14321
14322        #[wasm_bindgen(method, getter = minutes)]
14323        pub fn get_minutes(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
14324        #[wasm_bindgen(method, setter = minutes)]
14325        pub fn set_minutes(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
14326
14327        #[wasm_bindgen(method, getter = minutesDisplay)]
14328        pub fn get_minutes_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
14329        #[wasm_bindgen(method, setter = minutesDisplay)]
14330        pub fn set_minutes_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
14331
14332        #[wasm_bindgen(method, getter = seconds)]
14333        pub fn get_seconds(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
14334        #[wasm_bindgen(method, setter = seconds)]
14335        pub fn set_seconds(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
14336
14337        #[wasm_bindgen(method, getter = secondsDisplay)]
14338        pub fn get_seconds_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
14339        #[wasm_bindgen(method, setter = secondsDisplay)]
14340        pub fn set_seconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
14341
14342        #[wasm_bindgen(method, getter = milliseconds)]
14343        pub fn get_milliseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
14344        #[wasm_bindgen(method, setter = milliseconds)]
14345        pub fn set_milliseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
14346
14347        #[wasm_bindgen(method, getter = millisecondsDisplay)]
14348        pub fn get_milliseconds_display(
14349            this: &DurationFormatOptions,
14350        ) -> Option<DurationUnitDisplay>;
14351        #[wasm_bindgen(method, setter = millisecondsDisplay)]
14352        pub fn set_milliseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
14353
14354        #[wasm_bindgen(method, getter = microseconds)]
14355        pub fn get_microseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
14356        #[wasm_bindgen(method, setter = microseconds)]
14357        pub fn set_microseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
14358
14359        #[wasm_bindgen(method, getter = microsecondsDisplay)]
14360        pub fn get_microseconds_display(
14361            this: &DurationFormatOptions,
14362        ) -> Option<DurationUnitDisplay>;
14363        #[wasm_bindgen(method, setter = microsecondsDisplay)]
14364        pub fn set_microseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
14365
14366        #[wasm_bindgen(method, getter = nanoseconds)]
14367        pub fn get_nanoseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
14368        #[wasm_bindgen(method, setter = nanoseconds)]
14369        pub fn set_nanoseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
14370
14371        #[wasm_bindgen(method, getter = nanosecondsDisplay)]
14372        pub fn get_nanoseconds_display(this: &DurationFormatOptions)
14373            -> Option<DurationUnitDisplay>;
14374        #[wasm_bindgen(method, setter = nanosecondsDisplay)]
14375        pub fn set_nanoseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
14376
14377        #[wasm_bindgen(method, getter = fractionalDigits)]
14378        pub fn get_fractional_digits(this: &DurationFormatOptions) -> Option<u8>;
14379        #[wasm_bindgen(method, setter = fractionalDigits)]
14380        pub fn set_fractional_digits(this: &DurationFormatOptions, value: u8);
14381    }
14382
14383    impl DurationFormatOptions {
14384        pub fn new() -> DurationFormatOptions {
14385            JsCast::unchecked_into(Object::new())
14386        }
14387    }
14388
14389    impl Default for DurationFormatOptions {
14390        fn default() -> Self {
14391            DurationFormatOptions::new()
14392        }
14393    }
14394
14395    // Intl.ResolvedDurationFormatOptions
14396    #[wasm_bindgen]
14397    extern "C" {
14398        /// Resolved options returned by `Intl.DurationFormat.prototype.resolvedOptions()`.
14399        ///
14400        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
14401        #[wasm_bindgen(extends = DurationFormatOptions)]
14402        #[derive(Clone, Debug)]
14403        pub type ResolvedDurationFormatOptions;
14404
14405        /// The resolved locale string.
14406        #[cfg(not(js_sys_unstable_apis))]
14407        #[wasm_bindgen(method, getter = locale)]
14408        pub fn get_locale(this: &ResolvedDurationFormatOptions) -> JsString;
14409
14410        /// The resolved locale string.
14411        #[cfg(js_sys_unstable_apis)]
14412        #[wasm_bindgen(method, getter = locale)]
14413        pub fn get_locale(this: &ResolvedDurationFormatOptions) -> String;
14414
14415        /// The resolved numbering system.
14416        #[cfg(not(js_sys_unstable_apis))]
14417        #[wasm_bindgen(method, getter = numberingSystem)]
14418        pub fn get_numbering_system(this: &ResolvedDurationFormatOptions) -> JsString;
14419
14420        /// The resolved numbering system.
14421        #[cfg(js_sys_unstable_apis)]
14422        #[wasm_bindgen(method, getter = numberingSystem)]
14423        pub fn get_numbering_system(this: &ResolvedDurationFormatOptions) -> String;
14424    }
14425
14426    // Intl.Duration (input object for DurationFormat)
14427    #[wasm_bindgen]
14428    extern "C" {
14429        /// A duration object used as input to `Intl.DurationFormat.format()`.
14430        ///
14431        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration)
14432        #[wasm_bindgen(extends = Object)]
14433        #[derive(Clone, Debug)]
14434        pub type Duration;
14435
14436        #[wasm_bindgen(method, getter)]
14437        pub fn years(this: &Duration) -> Option<f64>;
14438        #[wasm_bindgen(method, setter)]
14439        pub fn set_years(this: &Duration, value: f64);
14440
14441        #[wasm_bindgen(method, getter)]
14442        pub fn months(this: &Duration) -> Option<f64>;
14443        #[wasm_bindgen(method, setter)]
14444        pub fn set_months(this: &Duration, value: f64);
14445
14446        #[wasm_bindgen(method, getter)]
14447        pub fn weeks(this: &Duration) -> Option<f64>;
14448        #[wasm_bindgen(method, setter)]
14449        pub fn set_weeks(this: &Duration, value: f64);
14450
14451        #[wasm_bindgen(method, getter)]
14452        pub fn days(this: &Duration) -> Option<f64>;
14453        #[wasm_bindgen(method, setter)]
14454        pub fn set_days(this: &Duration, value: f64);
14455
14456        #[wasm_bindgen(method, getter)]
14457        pub fn hours(this: &Duration) -> Option<f64>;
14458        #[wasm_bindgen(method, setter)]
14459        pub fn set_hours(this: &Duration, value: f64);
14460
14461        #[wasm_bindgen(method, getter)]
14462        pub fn minutes(this: &Duration) -> Option<f64>;
14463        #[wasm_bindgen(method, setter)]
14464        pub fn set_minutes(this: &Duration, value: f64);
14465
14466        #[wasm_bindgen(method, getter)]
14467        pub fn seconds(this: &Duration) -> Option<f64>;
14468        #[wasm_bindgen(method, setter)]
14469        pub fn set_seconds(this: &Duration, value: f64);
14470
14471        #[wasm_bindgen(method, getter)]
14472        pub fn milliseconds(this: &Duration) -> Option<f64>;
14473        #[wasm_bindgen(method, setter)]
14474        pub fn set_milliseconds(this: &Duration, value: f64);
14475
14476        #[wasm_bindgen(method, getter)]
14477        pub fn microseconds(this: &Duration) -> Option<f64>;
14478        #[wasm_bindgen(method, setter)]
14479        pub fn set_microseconds(this: &Duration, value: f64);
14480
14481        #[wasm_bindgen(method, getter)]
14482        pub fn nanoseconds(this: &Duration) -> Option<f64>;
14483        #[wasm_bindgen(method, setter)]
14484        pub fn set_nanoseconds(this: &Duration, value: f64);
14485    }
14486
14487    impl Duration {
14488        pub fn new() -> Duration {
14489            JsCast::unchecked_into(Object::new())
14490        }
14491    }
14492
14493    impl Default for Duration {
14494        fn default() -> Self {
14495            Duration::new()
14496        }
14497    }
14498
14499    // Intl.DurationFormatPart
14500    #[wasm_bindgen]
14501    extern "C" {
14502        /// A part of the formatted duration returned by `formatToParts()`.
14503        ///
14504        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
14505        #[wasm_bindgen(extends = Object)]
14506        #[derive(Clone, Debug)]
14507        pub type DurationFormatPart;
14508
14509        /// The type of the part.
14510        #[wasm_bindgen(method, getter = type)]
14511        pub fn type_(this: &DurationFormatPart) -> DurationFormatPartType;
14512
14513        /// The value of the part.
14514        #[cfg(not(js_sys_unstable_apis))]
14515        #[wasm_bindgen(method, getter)]
14516        pub fn value(this: &DurationFormatPart) -> JsString;
14517
14518        /// The value of the part.
14519        #[cfg(js_sys_unstable_apis)]
14520        #[wasm_bindgen(method, getter)]
14521        pub fn value(this: &DurationFormatPart) -> String;
14522
14523        /// The unit this part represents (if applicable).
14524        #[wasm_bindgen(method, getter)]
14525        pub fn unit(this: &DurationFormatPart) -> Option<JsString>;
14526    }
14527
14528    // Intl.DurationFormat
14529    #[wasm_bindgen]
14530    extern "C" {
14531        /// The `Intl.DurationFormat` object enables language-sensitive duration formatting.
14532        ///
14533        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat)
14534        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DurationFormat")]
14535        #[derive(Clone, Debug)]
14536        pub type DurationFormat;
14537
14538        /// Creates a new `Intl.DurationFormat` object.
14539        ///
14540        /// Throws a `RangeError` if locales or options contain invalid values.
14541        ///
14542        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat)
14543        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
14544        pub fn new(
14545            locales: &[JsString],
14546            options: &DurationFormatOptions,
14547        ) -> Result<DurationFormat, JsValue>;
14548
14549        /// Formats a duration according to the locale and formatting options.
14550        ///
14551        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format)
14552        #[cfg(not(js_sys_unstable_apis))]
14553        #[wasm_bindgen(method, js_class = "Intl.DurationFormat")]
14554        pub fn format(this: &DurationFormat, duration: &Duration) -> JsString;
14555
14556        /// Formats a duration according to the locale and formatting options.
14557        ///
14558        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format)
14559        #[cfg(js_sys_unstable_apis)]
14560        #[wasm_bindgen(method, js_class = "Intl.DurationFormat")]
14561        pub fn format(this: &DurationFormat, duration: &Duration) -> String;
14562
14563        /// Returns an array of objects representing the formatted duration in parts.
14564        ///
14565        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
14566        #[wasm_bindgen(method, js_class = "Intl.DurationFormat", js_name = formatToParts)]
14567        pub fn format_to_parts(
14568            this: &DurationFormat,
14569            duration: &Duration,
14570        ) -> Array<DurationFormatPart>;
14571
14572        /// Returns an object with properties reflecting the options used.
14573        ///
14574        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
14575        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
14576        pub fn resolved_options(this: &DurationFormat) -> ResolvedDurationFormatOptions;
14577
14578        /// Returns an array of supported locales.
14579        ///
14580        /// Throws a `RangeError` if locales contain invalid values.
14581        ///
14582        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf)
14583        #[wasm_bindgen(static_method_of = DurationFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
14584        pub fn supported_locales_of(
14585            locales: &[JsString],
14586            options: &LocaleMatcherOptions,
14587        ) -> Result<Array<JsString>, JsValue>;
14588    }
14589
14590    impl Default for DurationFormat {
14591        fn default() -> Self {
14592            Self::new(&[], &Default::default()).unwrap()
14593        }
14594    }
14595}
14596
14597#[wasm_bindgen]
14598extern "C" {
14599    /// The `PromiseState` object represents the the status of the promise,
14600    /// as used in `allSettled`.
14601    ///
14602    /// `T` is the fulfilled value type and `E` the rejection reason type,
14603    /// both defaulting to `JsValue`.
14604    ///
14605    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
14606    #[must_use]
14607    #[wasm_bindgen(extends = Object, typescript_type = "any")]
14608    #[derive(Clone, Debug)]
14609    pub type PromiseState<T = JsValue, E = JsValue>;
14610
14611    /// A string, either "fulfilled" or "rejected", indicating the eventual state of the promise.
14612    #[wasm_bindgen(method, getter = status)]
14613    pub fn get_status<T, E>(this: &PromiseState<T, E>) -> String;
14614
14615    /// Only present if status is "fulfilled". The value that the promise was fulfilled with.
14616    #[wasm_bindgen(method, getter = value)]
14617    pub fn get_value<T, E>(this: &PromiseState<T, E>) -> Option<T>;
14618
14619    /// Only present if status is "rejected". The reason that the promise was rejected with.
14620    #[wasm_bindgen(method, getter = reason)]
14621    pub fn get_reason<T, E>(this: &PromiseState<T, E>) -> Option<E>;
14622}
14623
14624impl<T, E> PromiseState<T, E> {
14625    pub fn is_fulfilled(&self) -> bool {
14626        self.get_status() == "fulfilled"
14627    }
14628
14629    pub fn is_rejected(&self) -> bool {
14630        self.get_status() == "rejected"
14631    }
14632}
14633
14634/// Converts a `PromiseState<T, E>` into a `Result<T, E>`, matching the
14635/// spec invariant that exactly one of the fulfilled value or the rejection
14636/// reason is populated per slot.
14637impl<T: JsGeneric + FromWasmAbi, E: JsGeneric + FromWasmAbi> From<PromiseState<T, E>>
14638    for Result<T, E>
14639{
14640    fn from(state: PromiseState<T, E>) -> Result<T, E> {
14641        if state.is_fulfilled() {
14642            Ok(state.get_value().unwrap())
14643        } else {
14644            Err(state.get_reason().unwrap())
14645        }
14646    }
14647}
14648
14649// PromiseWithResolvers
14650#[wasm_bindgen]
14651extern "C" {
14652    /// The object returned by [`Promise::with_resolvers`], bundling a
14653    /// pending promise with the functions that settle it.
14654    ///
14655    /// `T` is the fulfilled value type and `E` the rejection reason type,
14656    /// both defaulting to `JsValue`. Unlike `Promise<T, E>` it is invariant
14657    /// in both: `resolve` and `reject` take a `T` and an `E`, so widening
14658    /// either would let the promise settle with a value its type rules out.
14659    ///
14660    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers)
14661    #[wasm_bindgen(extends = Object, no_upcast, typescript_type = "PromiseWithResolvers<any>")]
14662    #[derive(Clone, Debug, PartialEq, Eq)]
14663    pub type PromiseWithResolvers<T = JsValue, E = JsValue>;
14664
14665    /// The pending promise.
14666    #[wasm_bindgen(method, getter)]
14667    pub fn promise<T, E>(this: &PromiseWithResolvers<T, E>) -> Promise<T, E>;
14668
14669    /// The function that fulfills the promise with a value.
14670    #[wasm_bindgen(method, getter)]
14671    pub fn resolve<T, E>(this: &PromiseWithResolvers<T, E>) -> Function<fn(T) -> Undefined>;
14672
14673    /// The function that rejects the promise with a reason.
14674    #[wasm_bindgen(method, getter)]
14675    pub fn reject<T, E>(this: &PromiseWithResolvers<T, E>) -> Function<fn(E) -> Undefined>;
14676}
14677
14678// Invariant in `T` and `E`: only identity and the `Object` / `JsValue` supertypes.
14679impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for PromiseWithResolvers<T, E> {}
14680impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsOption<PromiseWithResolvers<T, E>> {}
14681impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsNullable<PromiseWithResolvers<T, E>> {}
14682impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsValue {}
14683impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsOption<JsValue> {}
14684impl<T, E, Target: UpcastFrom<PromiseWithResolvers<T, E>>> UpcastFrom<PromiseWithResolvers<T, E>>
14685    for Option<Target>
14686{
14687}
14688impl<T, E, Target: UpcastFrom<PromiseWithResolvers<T, E>>> UpcastFrom<PromiseWithResolvers<T, E>>
14689    for Nullable<Target>
14690{
14691}
14692impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsNullable<JsValue> {}
14693impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for Object {}
14694impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsOption<Object> {}
14695impl<T, E> UpcastFrom<PromiseWithResolvers<T, E>> for JsNullable<Object> {}
14696
14697// Promise
14698#[wasm_bindgen]
14699extern "C" {
14700    /// The `Promise` object represents the eventual completion (or failure) of
14701    /// an asynchronous operation, and its resulting value.
14702    ///
14703    /// `T` is the type the promise fulfills with and `E` the type it rejects
14704    /// with, both defaulting to `JsValue`. Awaiting a `Promise<T, E>` yields a
14705    /// `Result<T, E>`. JS can reject with any value, so `E` is the same kind
14706    /// of unchecked assertion about the JS side as `T` is. A `Promise<T, E>`
14707    /// upcasts to `Promise<T2, E2>` whenever `T` upcasts to `T2` and `E` to
14708    /// `E2`, so a `Promise<T, TypeError>` can be passed where a
14709    /// `Promise<T, Error>` or `Promise<T>` is expected.
14710    ///
14711    /// `then` and `finally` with a plain handler keep `E` on the returned
14712    /// promise. Variants whose handler returns a `Result`, and so can reject
14713    /// on its own, widen the returned rejection to `JsValue`.
14714    ///
14715    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
14716    #[must_use]
14717    #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>", no_promising)]
14718    #[derive(Clone, Debug)]
14719    pub type Promise<T = JsValue, E = JsValue>;
14720
14721    /// Creates a new `Promise` with the provided executor `cb`
14722    ///
14723    /// The `cb` is a function that is passed with the arguments `resolve` and
14724    /// `reject`. The `cb` function is executed immediately by the `Promise`
14725    /// implementation, passing `resolve` and `reject` functions (the executor
14726    /// is called before the `Promise` constructor even returns the created
14727    /// object). The `resolve` and `reject` functions, when called, resolve or
14728    /// reject the promise, respectively. The executor normally initiates
14729    /// some asynchronous work, and then, once that completes, either calls
14730    /// the `resolve` function to resolve the promise or else rejects it if an
14731    /// error occurred.
14732    ///
14733    /// If an error is thrown in the executor function, the promise is rejected.
14734    /// The return value of the executor is ignored.
14735    ///
14736    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
14737    #[cfg(not(js_sys_unstable_apis))]
14738    #[wasm_bindgen(constructor)]
14739    pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
14740
14741    /// Creates a new `Promise` with the provided executor `cb`
14742    ///
14743    /// The `cb` is a function that is passed with the arguments `resolve` and
14744    /// `reject`. The `cb` function is executed immediately by the `Promise`
14745    /// implementation, passing `resolve` and `reject` functions (the executor
14746    /// is called before the `Promise` constructor even returns the created
14747    /// object). The `resolve` and `reject` functions, when called, resolve or
14748    /// reject the promise, respectively. The executor normally initiates
14749    /// some asynchronous work, and then, once that completes, either calls
14750    /// the `resolve` function to resolve the promise or else rejects it if an
14751    /// error occurred.
14752    ///
14753    /// If an error is thrown in the executor function, the promise is rejected.
14754    /// The return value of the executor is ignored.
14755    ///
14756    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
14757    #[cfg(js_sys_unstable_apis)]
14758    #[wasm_bindgen(constructor)]
14759    pub fn new<T, E>(
14760        cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(E) -> Undefined>),
14761    ) -> Promise<T, E>;
14762
14763    // Next major: deprecate
14764    /// Creates a new `Promise` with the provided executor `cb`
14765    ///
14766    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
14767    #[wasm_bindgen(constructor)]
14768    pub fn new_typed<T: Promising>(
14769        cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
14770    ) -> Promise<<T as Promising>::Resolution>;
14771
14772    /// The `Promise.all(iterable)` method returns a single `Promise` that
14773    /// resolves when all of the promises in the iterable argument have resolved
14774    /// or when the iterable argument contains no promises. It rejects with the
14775    /// reason of the first promise that rejects.
14776    ///
14777    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
14778    #[cfg(not(js_sys_unstable_apis))]
14779    #[wasm_bindgen(static_method_of = Promise)]
14780    pub fn all(obj: &JsValue) -> Promise;
14781
14782    /// The `Promise.all(iterable)` method returns a single `Promise` that
14783    /// resolves when all of the promises in the iterable argument have resolved
14784    /// or when the iterable argument contains no promises. It rejects with the
14785    /// reason of the first promise that rejects.
14786    ///
14787    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
14788    #[cfg(js_sys_unstable_apis)]
14789    #[wasm_bindgen(static_method_of = Promise, js_name = all)]
14790    pub fn all<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
14791    where
14792        I::Item: Promising;
14793
14794    // Next major: deprecate
14795    /// The `Promise.all(iterable)` method returns a single `Promise` that
14796    /// resolves when all of the promises in the iterable argument have resolved
14797    /// or when the iterable argument contains no promises. It rejects with the
14798    /// reason of the first promise that rejects.
14799    ///
14800    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
14801    #[wasm_bindgen(static_method_of = Promise, js_name = all)]
14802    pub fn all_iterable<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
14803    where
14804        I::Item: Promising;
14805
14806    /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
14807    /// resolves when all of the promises in the iterable argument have either
14808    /// fulfilled or rejected or when the iterable argument contains no promises.
14809    ///
14810    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
14811    #[cfg(not(js_sys_unstable_apis))]
14812    #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
14813    pub fn all_settled(obj: &JsValue) -> Promise;
14814
14815    /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
14816    /// resolves when all of the promises in the iterable argument have either
14817    /// fulfilled or rejected or when the iterable argument contains no promises.
14818    ///
14819    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
14820    #[cfg(js_sys_unstable_apis)]
14821    #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
14822    pub fn all_settled<I: Iterable>(
14823        obj: &I,
14824    ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
14825    where
14826        I::Item: Promising;
14827
14828    // Next major: deprecate
14829    /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
14830    /// resolves when all of the promises in the iterable argument have either
14831    /// fulfilled or rejected or when the iterable argument contains no promises.
14832    ///
14833    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
14834    #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
14835    pub fn all_settled_iterable<I: Iterable>(
14836        obj: &I,
14837    ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
14838    where
14839        I::Item: Promising;
14840
14841    /// The `Promise.any(iterable)` method returns a single `Promise` that
14842    /// resolves when any of the promises in the iterable argument have resolved
14843    /// or when the iterable argument contains no promises. It rejects with an
14844    /// `AggregateError` if all promises in the iterable rejected.
14845    ///
14846    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
14847    #[cfg(not(js_sys_unstable_apis))]
14848    #[wasm_bindgen(static_method_of = Promise)]
14849    pub fn any(obj: &JsValue) -> Promise;
14850
14851    /// The `Promise.any(iterable)` method returns a single `Promise` that
14852    /// resolves when any of the promises in the iterable argument have resolved
14853    /// or when the iterable argument contains no promises. It rejects with an
14854    /// `AggregateError` if all promises in the iterable rejected.
14855    ///
14856    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
14857    #[cfg(js_sys_unstable_apis)]
14858    #[wasm_bindgen(static_method_of = Promise, js_name = any)]
14859    pub fn any<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution, AggregateError>
14860    where
14861        I::Item: Promising;
14862
14863    // Next major: deprecate, and type the rejection as `AggregateError`
14864    /// The `Promise.any(iterable)` method returns a single `Promise` that
14865    /// resolves when any of the promises in the iterable argument have resolved
14866    /// or when the iterable argument contains no promises. It rejects with an
14867    /// `AggregateError` if all promises in the iterable rejected.
14868    ///
14869    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
14870    #[wasm_bindgen(static_method_of = Promise, js_name = any)]
14871    pub fn any_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
14872    where
14873        I::Item: Promising;
14874
14875    /// The `Promise.race(iterable)` method returns a promise that resolves or
14876    /// rejects as soon as one of the promises in the iterable resolves or
14877    /// rejects, with the value or reason from that promise.
14878    ///
14879    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
14880    #[cfg(not(js_sys_unstable_apis))]
14881    #[wasm_bindgen(static_method_of = Promise)]
14882    pub fn race(obj: &JsValue) -> Promise;
14883
14884    /// The `Promise.race(iterable)` method returns a promise that resolves or
14885    /// rejects as soon as one of the promises in the iterable resolves or
14886    /// rejects, with the value or reason from that promise.
14887    ///
14888    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
14889    #[cfg(js_sys_unstable_apis)]
14890    #[wasm_bindgen(static_method_of = Promise, js_name = race)]
14891    pub fn race<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
14892    where
14893        I::Item: Promising;
14894
14895    // Next major: deprecate
14896    /// The `Promise.race(iterable)` method returns a promise that resolves or
14897    /// rejects as soon as one of the promises in the iterable resolves or
14898    /// rejects, with the value or reason from that promise.
14899    ///
14900    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
14901    #[wasm_bindgen(static_method_of = Promise, js_name = race)]
14902    pub fn race_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
14903    where
14904        I::Item: Promising;
14905
14906    /// The `Promise.reject(reason)` method returns a `Promise` object that is
14907    /// rejected with the given reason.
14908    ///
14909    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
14910    #[cfg(not(js_sys_unstable_apis))]
14911    #[wasm_bindgen(static_method_of = Promise)]
14912    pub fn reject(obj: &JsValue) -> Promise;
14913
14914    /// The `Promise.reject(reason)` method returns a `Promise` object that is
14915    /// rejected with the given reason.
14916    ///
14917    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
14918    #[cfg(js_sys_unstable_apis)]
14919    #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
14920    pub fn reject<T, E: JsGeneric>(obj: &E) -> Promise<T, E>;
14921
14922    // Next major: deprecate
14923    /// The `Promise.reject(reason)` method returns a `Promise` object that is
14924    /// rejected with the given reason.
14925    ///
14926    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
14927    #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
14928    pub fn reject_typed<T>(obj: &JsValue) -> Promise<T>;
14929
14930    /// The `Promise.resolve(value)` method returns a `Promise` object that is
14931    /// resolved with the given value. If the value is a promise, that promise
14932    /// is returned; if the value is a thenable (i.e. has a "then" method), the
14933    /// returned promise will "follow" that thenable, adopting its eventual
14934    /// state; otherwise the returned promise will be fulfilled with the value.
14935    ///
14936    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
14937    #[wasm_bindgen(static_method_of = Promise, js_name = resolve)]
14938    pub fn resolve<U: Promising>(obj: &U) -> Promise<U::Resolution>;
14939
14940    /// The `catch()` method returns a `Promise` and deals with rejected cases
14941    /// only.  It behaves the same as calling `Promise.prototype.then(undefined,
14942    /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
14943    /// `obj.then(undefined, onRejected)`).
14944    ///
14945    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
14946    #[cfg(not(js_sys_unstable_apis))]
14947    #[wasm_bindgen(method)]
14948    pub fn catch<'a, T, E>(
14949        this: &Promise<T, E>,
14950        cb: &ScopedClosure<'a, dyn FnMut(E)>,
14951    ) -> Promise<JsValue>;
14952
14953    /// The `catch()` method returns a `Promise` and deals with rejected cases
14954    /// only.  It behaves the same as calling `Promise.prototype.then(undefined,
14955    /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
14956    /// `obj.then(undefined, onRejected)`).
14957    ///
14958    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
14959    #[cfg(js_sys_unstable_apis)]
14960    #[wasm_bindgen(method, js_name = catch)]
14961    pub fn catch<'a, T, E, R: Promising>(
14962        this: &Promise<T, E>,
14963        cb: &ScopedClosure<'a, dyn FnMut(E) -> Result<R, JsError>>,
14964    ) -> Promise<R::Resolution>;
14965
14966    // Next major: deprecate
14967    /// Same as `catch`, but returning a result to become the new Promise value.
14968    #[wasm_bindgen(method, js_name = catch)]
14969    pub fn catch_map<'a, T, E, R: Promising>(
14970        this: &Promise<T, E>,
14971        cb: &ScopedClosure<'a, dyn FnMut(E) -> Result<R, JsError>>,
14972    ) -> Promise<R::Resolution>;
14973
14974    /// The `then()` method returns a `Promise`. It takes up to two arguments:
14975    /// callback functions for the success and failure cases of the `Promise`.
14976    ///
14977    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
14978    #[cfg(not(js_sys_unstable_apis))]
14979    #[wasm_bindgen(method)]
14980    pub fn then<'a, T, E>(
14981        this: &Promise<T, E>,
14982        cb: &ScopedClosure<'a, dyn FnMut(T)>,
14983    ) -> Promise<JsValue, E>;
14984
14985    /// The `then()` method returns a `Promise`. It takes up to two arguments:
14986    /// callback functions for the success and failure cases of the `Promise`.
14987    ///
14988    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
14989    #[cfg(js_sys_unstable_apis)]
14990    #[wasm_bindgen(method, js_name = then)]
14991    pub fn then<'a, T, E, R: Promising>(
14992        this: &Promise<T, E>,
14993        cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
14994    ) -> Promise<R::Resolution>;
14995
14996    /// The `then()` method returns a `Promise`. It takes up to two arguments:
14997    /// callback functions for the success and failure cases of the `Promise`.
14998    ///
14999    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
15000    #[wasm_bindgen(method, js_name = then)]
15001    pub fn then_with_reject<'a, T, E, R: Promising>(
15002        this: &Promise<T, E>,
15003        resolve: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
15004        reject: &ScopedClosure<'a, dyn FnMut(E) -> Result<R, JsError>>,
15005    ) -> Promise<R::Resolution>;
15006
15007    // Next major: deprecate
15008    /// Alias for `then()` with a return value.
15009    /// The `then()` method returns a `Promise`. It takes up to two arguments:
15010    /// callback functions for the success and failure cases of the `Promise`.
15011    ///
15012    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
15013    #[wasm_bindgen(method, js_name = then)]
15014    pub fn then_map<'a, T, E, R: Promising>(
15015        this: &Promise<T, E>,
15016        cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
15017    ) -> Promise<R::Resolution>;
15018
15019    /// Same as `then`, only with both arguments provided.
15020    ///
15021    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
15022    #[wasm_bindgen(method, js_name = then)]
15023    pub fn then2(
15024        this: &Promise,
15025        resolve: &ScopedClosure<dyn FnMut(JsValue)>,
15026        reject: &ScopedClosure<dyn FnMut(JsValue)>,
15027    ) -> Promise;
15028
15029    /// The `finally()` method returns a `Promise`. When the promise is settled,
15030    /// whether fulfilled or rejected, the specified callback function is
15031    /// executed. This provides a way for code that must be executed once the
15032    /// `Promise` has been dealt with to be run whether the promise was
15033    /// fulfilled successfully or rejected.
15034    ///
15035    /// This lets you avoid duplicating code in both the promise's `then()` and
15036    /// `catch()` handlers.
15037    ///
15038    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
15039    // Next major: return `Promise<T, E>`, since `finally` passes the value through
15040    #[wasm_bindgen(method)]
15041    pub fn finally<T, E>(
15042        this: &Promise<T, E>,
15043        cb: &ScopedClosure<dyn FnMut()>,
15044    ) -> Promise<JsValue, E>;
15045
15046    /// The `Promise.try()` static method calls `cb` synchronously and
15047    /// wraps its outcome in a promise: a returned value or promise is
15048    /// adopted, and a thrown error becomes a rejection.
15049    ///
15050    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/try)
15051    #[wasm_bindgen(static_method_of = Promise, js_name = try)]
15052    pub fn try_<R: Promising>(cb: &mut dyn FnMut() -> Result<R, JsError>)
15053        -> Promise<R::Resolution>;
15054
15055    /// The `Promise.withResolvers()` static method returns a new promise
15056    /// together with its `resolve` and `reject` functions.
15057    ///
15058    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers)
15059    #[wasm_bindgen(static_method_of = Promise, js_name = withResolvers)]
15060    pub fn with_resolvers<T, E>() -> PromiseWithResolvers<T, E>;
15061}
15062
15063impl<T, E> Promising for Promise<T, E> {
15064    type Resolution = T;
15065}
15066
15067/// A `catch` import returning `Promise<T, E>` returns a synchronous throw as
15068/// a rejected promise.
15069impl<T, E> wasm_bindgen::convert::FromCaughtException for Promise<T, E> {
15070    fn from_caught_exception(e: JsValue) -> Self {
15071        Promise::<T>::reject_typed(&e).unchecked_into()
15072    }
15073}
15074
15075/// Internal: maps a tuple of `Promise<T_i, E>` to the result shapes of
15076/// [`Promise::all_tuple`] and [`Promise::all_settled_tuple`].
15077///
15078/// Implemented for every tuple arity 1..=8 of `Promise<T, E>`, for any `T`
15079/// and `E`. One rejection type `E` is shared across the tuple,
15080/// so upcast mixed rejection types to a common one first. The associated
15081/// `Joined` / `Settled` types pin down the [`ArrayTuple`] shape of the
15082/// result so the one [`JsCast::unchecked_into`] needed to reinterpret the
15083/// [`Array<JsValue>`] returned by `Promise.all` / `Promise.allSettled` is
15084/// encapsulated inside each impl — the caller sees a fully-typed
15085/// `Promise<ArrayTuple<...>, E>`.
15086///
15087/// The soundness of the `unchecked_into`s here rests on `Promise.all` and
15088/// `Promise.allSettled` preserving input order and arity, which they do by
15089/// spec.
15090///
15091/// You normally call [`Promise::all_tuple`] / [`Promise::all_settled_tuple`]
15092/// rather than using this trait directly.
15093#[doc(hidden)]
15094pub trait PromiseTuple {
15095    /// The typed `ArrayTuple` shape the joined promise resolves to.
15096    ///
15097    /// For a tuple `(Promise<T1, E>, Promise<T2, E>, ...)` this is
15098    /// `ArrayTuple<(T1, T2, ...)>`.
15099    type Joined;
15100
15101    /// The typed `ArrayTuple` shape the all-settled promise resolves to.
15102    ///
15103    /// For a tuple `(Promise<T1, E>, Promise<T2, E>, ...)` this is
15104    /// `ArrayTuple<(PromiseState<T1, E>, PromiseState<T2, E>, ...)>`.
15105    type Settled;
15106
15107    /// The rejection type shared by every promise in the tuple, which the
15108    /// joined promise rejects with.
15109    type Rejection;
15110
15111    /// Join via `Promise.all`, returning a typed `Promise`.
15112    fn all(self) -> Promise<Self::Joined, Self::Rejection>;
15113
15114    /// Settle via `Promise.allSettled`, returning a typed `Promise`.
15115    fn all_settled(self) -> Promise<Self::Settled>;
15116}
15117
15118macro_rules! impl_promise_tuple {
15119    ([$($T:ident)+] [$($idx:tt)+]) => {
15120        // Rust tuple of `Promise<T_i, E>`. Each element is a promise handle
15121        // whatever `T_i` is, so the `ArrayTuple` of promises is packed
15122        // directly rather than through `From<(..)>`, which would upcast
15123        // each `T_i`. Delegates to the `ArrayTuple` impl below.
15124        impl<$($T,)+ E> PromiseTuple for ($(Promise<$T, E>,)+) {
15125            type Joined = ArrayTuple<($($T,)+)>;
15126            type Settled = ArrayTuple<($(PromiseState<$T, E>,)+)>;
15127            type Rejection = E;
15128
15129            fn all(self) -> Promise<Self::Joined, E> {
15130                use wasm_bindgen::JsCast;
15131                let tuple: ArrayTuple<($(Promise<$T, E>,)+)> =
15132                    Array::of(&[$(JsValue::from(self.$idx)),+]).unchecked_into();
15133                tuple.all()
15134            }
15135
15136            fn all_settled(self) -> Promise<Self::Settled> {
15137                use wasm_bindgen::JsCast;
15138                let tuple: ArrayTuple<($(Promise<$T, E>,)+)> =
15139                    Array::of(&[$(JsValue::from(self.$idx)),+]).unchecked_into();
15140                tuple.all_settled()
15141            }
15142        }
15143
15144        // `ArrayTuple<(Promise<T_1, E>, ..., Promise<T_n, E>)>` — callers who
15145        // already have an `ArrayTuple` (e.g. from a binding that returns
15146        // one, or built via `.into()` earlier in a pipeline) can pass it
15147        // directly without unpacking into a Rust tuple.
15148        //
15149        // Hands the `ArrayTuple` straight to `Promise.all_iterable` /
15150        // `Promise.allSettled_iterable` and reinterprets the result
15151        // `Array<JsValue>` as the intended typed `ArrayTuple`. Safe because
15152        // `Promise.all` / `Promise.allSettled` preserve input order and
15153        // arity by spec, and `Promise.all` rejects with one of the inputs'
15154        // rejection reasons.
15155        impl<$($T,)+ E> PromiseTuple for ArrayTuple<($(Promise<$T, E>,)+)> {
15156            type Joined = ArrayTuple<($($T,)+)>;
15157            type Settled = ArrayTuple<($(PromiseState<$T, E>,)+)>;
15158            type Rejection = E;
15159
15160            fn all(self) -> Promise<Self::Joined, E> {
15161                use wasm_bindgen::JsCast;
15162                Promise::all_iterable(&self).unchecked_into()
15163            }
15164
15165            fn all_settled(self) -> Promise<Self::Settled> {
15166                use wasm_bindgen::JsCast;
15167                Promise::all_settled_iterable(&self).unchecked_into()
15168            }
15169        }
15170    };
15171}
15172
15173impl_promise_tuple!([T1][0]);
15174impl_promise_tuple!([T1 T2] [0 1]);
15175impl_promise_tuple!([T1 T2 T3] [0 1 2]);
15176impl_promise_tuple!([T1 T2 T3 T4] [0 1 2 3]);
15177impl_promise_tuple!([T1 T2 T3 T4 T5] [0 1 2 3 4]);
15178impl_promise_tuple!([T1 T2 T3 T4 T5 T6] [0 1 2 3 4 5]);
15179impl_promise_tuple!([T1 T2 T3 T4 T5 T6 T7] [0 1 2 3 4 5 6]);
15180impl_promise_tuple!([T1 T2 T3 T4 T5 T6 T7 T8] [0 1 2 3 4 5 6 7]);
15181
15182impl Promise {
15183    /// Heterogeneous counterpart to [`Promise::all_iterable`]: accepts a Rust
15184    /// tuple of `Promise<T_i, E>` and returns a single [`Promise`] resolving
15185    /// to a typed [`ArrayTuple<(T_1, T_2, ..., T_n)>`] and rejecting with the
15186    /// tuple's shared rejection type `E`.
15187    ///
15188    /// Destructure the awaited result via [`ArrayTuple::into_tuple`] to get
15189    /// the individual values back as a native Rust tuple. Implemented for
15190    /// arity 1..=8.
15191    ///
15192    /// Rejects with the first rejection, matching `Promise.all` semantics.
15193    ///
15194    /// # Example
15195    ///
15196    /// ```ignore
15197    /// use js_sys::Promise;
15198    ///
15199    /// let (response, buffer) = Promise::all_tuple((fetch_promise, buffer_promise))
15200    ///     .await?
15201    ///     .into_tuple();
15202    /// ```
15203    #[inline]
15204    pub fn all_tuple<T: PromiseTuple>(promises: T) -> Promise<T::Joined, T::Rejection> {
15205        promises.all()
15206    }
15207
15208    /// Heterogeneous counterpart to [`Promise::all_settled_iterable`]: accepts
15209    /// a Rust tuple of `Promise<T_i, E>` and returns a single [`Promise`]
15210    /// resolving to a typed
15211    /// `ArrayTuple<(PromiseState<T_1, E>, ..., PromiseState<T_n, E>)>`.
15212    ///
15213    /// Unlike [`Promise::all_tuple`], this never rejects early: every input
15214    /// settles (fulfills or rejects) and is reflected by its [`PromiseState`]
15215    /// slot in the result tuple. Implemented for arity 1..=8.
15216    ///
15217    /// # Example
15218    ///
15219    /// ```ignore
15220    /// use js_sys::Promise;
15221    ///
15222    /// let results = Promise::all_settled_tuple((fetch_promise, buffer_promise)).await?;
15223    /// let (response_state, buffer_state) = results.into_tuple();
15224    /// ```
15225    #[inline]
15226    pub fn all_settled_tuple<T: PromiseTuple>(promises: T) -> Promise<T::Settled> {
15227        promises.all_settled()
15228    }
15229}
15230
15231/// Returns a handle to the global scope object.
15232///
15233/// This allows access to the global properties and global names by accessing
15234/// the `Object` returned.
15235pub fn global() -> Object {
15236    use wasm_bindgen::__rt::LazyCell;
15237
15238    #[cfg_attr(target_feature = "atomics", thread_local)]
15239    static GLOBAL: LazyCell<Object> = LazyCell::new(get_global_object);
15240
15241    return GLOBAL.clone();
15242
15243    fn get_global_object() -> Object {
15244        // Accessing the global object is not an easy thing to do, and what we
15245        // basically want is `globalThis` but we can't rely on that existing
15246        // everywhere. In the meantime we've got the fallbacks mentioned in:
15247        //
15248        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
15249        //
15250        // Note that this is pretty heavy code-size wise but it at least gets
15251        // the job largely done for now and avoids the `Function` constructor at
15252        // the end which triggers CSP errors.
15253        #[wasm_bindgen]
15254        extern "C" {
15255            #[derive(Clone, Debug)]
15256            type Global;
15257
15258            #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
15259            static GLOBAL_THIS: Option<Object>;
15260
15261            #[wasm_bindgen(thread_local_v2, js_name = self)]
15262            static SELF: Option<Object>;
15263
15264            #[wasm_bindgen(thread_local_v2, js_name = window)]
15265            static WINDOW: Option<Object>;
15266
15267            #[wasm_bindgen(thread_local_v2, js_name = global)]
15268            static GLOBAL: Option<Object>;
15269        }
15270
15271        // The order is important: in Firefox Extension Content Scripts `globalThis`
15272        // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
15273        let static_object = SELF
15274            .with(Option::clone)
15275            .or_else(|| WINDOW.with(Option::clone))
15276            .or_else(|| GLOBAL_THIS.with(Option::clone))
15277            .or_else(|| GLOBAL.with(Option::clone));
15278        if let Some(obj) = static_object {
15279            if !obj.is_undefined() {
15280                return obj;
15281            }
15282        }
15283
15284        // Global object not found
15285        JsValue::undefined().unchecked_into()
15286    }
15287}
15288
15289// Float16Array
15290//
15291// Rust does not yet have a stable builtin `f16`, so the raw JS bindings live
15292// here and any Rust-side helper APIs use explicit `u16` / `f32` naming. The
15293// unsuffixed float APIs are reserved for a future native `f16` binding.
15294#[wasm_bindgen]
15295extern "C" {
15296    #[wasm_bindgen(extends = Object, typescript_type = "Float16Array")]
15297    #[derive(Clone, Debug)]
15298    pub type Float16Array;
15299
15300    /// The `Float16Array()` constructor creates a new array.
15301    ///
15302    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
15303    #[wasm_bindgen(constructor)]
15304    pub fn new(constructor_arg: &JsValue) -> Float16Array;
15305
15306    /// The `Float16Array()` constructor creates an array with an internal
15307    /// buffer large enough for `length` elements.
15308    ///
15309    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
15310    #[wasm_bindgen(constructor)]
15311    pub fn new_with_length(length: u32) -> Float16Array;
15312
15313    /// The `Float16Array()` constructor creates an array with the given
15314    /// buffer but is a view starting at `byte_offset`.
15315    ///
15316    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
15317    #[wasm_bindgen(constructor)]
15318    pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> Float16Array;
15319
15320    /// The `Float16Array()` constructor creates an array with the given
15321    /// buffer but is a view starting at `byte_offset` for `length` elements.
15322    ///
15323    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
15324    #[wasm_bindgen(constructor)]
15325    pub fn new_with_byte_offset_and_length(
15326        buffer: &JsValue,
15327        byte_offset: u32,
15328        length: u32,
15329    ) -> Float16Array;
15330
15331    /// The `fill()` method fills all elements from a start index to an end
15332    /// index with a static `f32` value.
15333    ///
15334    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
15335    #[wasm_bindgen(method, js_name = fill)]
15336    pub fn fill_with_f32(this: &Float16Array, value: f32, start: u32, end: u32) -> Float16Array;
15337
15338    /// The buffer accessor property represents the `ArrayBuffer` referenced
15339    /// by a `TypedArray` at construction time.
15340    #[wasm_bindgen(getter, method)]
15341    pub fn buffer(this: &Float16Array) -> ArrayBuffer;
15342
15343    /// The `subarray()` method returns a new `TypedArray` on the same
15344    /// `ArrayBuffer` store and with the same element types as this array.
15345    #[wasm_bindgen(method)]
15346    pub fn subarray(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
15347
15348    /// The `slice()` method returns a shallow copy of a portion of a typed
15349    /// array into a new typed array object.
15350    #[wasm_bindgen(method)]
15351    pub fn slice(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
15352
15353    /// The `forEach()` method executes a provided function once per array
15354    /// element, passing values as `f32`.
15355    #[wasm_bindgen(method, js_name = forEach)]
15356    pub fn for_each_as_f32(this: &Float16Array, callback: &mut dyn FnMut(f32, u32, Float16Array));
15357
15358    /// The `forEach()` method executes a provided function once per array
15359    /// element, passing values as `f32`.
15360    #[wasm_bindgen(method, js_name = forEach, catch)]
15361    pub fn try_for_each_as_f32(
15362        this: &Float16Array,
15363        callback: &mut dyn FnMut(f32, u32, Float16Array) -> Result<(), JsError>,
15364    ) -> Result<(), JsValue>;
15365
15366    /// The length accessor property represents the length (in elements) of a
15367    /// typed array.
15368    #[wasm_bindgen(method, getter)]
15369    pub fn length(this: &Float16Array) -> u32;
15370
15371    /// The byteLength accessor property represents the length (in bytes) of a
15372    /// typed array.
15373    #[wasm_bindgen(method, getter, js_name = byteLength)]
15374    pub fn byte_length(this: &Float16Array) -> u32;
15375
15376    /// The byteOffset accessor property represents the offset (in bytes) of a
15377    /// typed array from the start of its `ArrayBuffer`.
15378    #[wasm_bindgen(method, getter, js_name = byteOffset)]
15379    pub fn byte_offset(this: &Float16Array) -> u32;
15380
15381    /// The `set()` method stores multiple values in the typed array, reading
15382    /// input values from a specified array.
15383    #[wasm_bindgen(method)]
15384    pub fn set(this: &Float16Array, src: &JsValue, offset: u32);
15385
15386    /// Gets the value at `idx` as an `f32`, counting from the end if negative.
15387    #[wasm_bindgen(method, js_name = at)]
15388    pub fn at_as_f32(this: &Float16Array, idx: i32) -> Option<f32>;
15389
15390    /// The `copyWithin()` method shallow copies part of a typed array to another
15391    /// location in the same typed array and returns it, without modifying its size.
15392    ///
15393    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
15394    #[wasm_bindgen(method, js_name = copyWithin)]
15395    pub fn copy_within(this: &Float16Array, target: i32, start: i32, end: i32) -> Float16Array;
15396
15397    /// Gets the value at `idx` as an `f32`, equivalent to JavaScript
15398    /// `arr[idx]`.
15399    #[wasm_bindgen(method, indexing_getter)]
15400    pub fn get_index_as_f32(this: &Float16Array, idx: u32) -> f32;
15401
15402    /// Sets the value at `idx` from an `f32`, equivalent to JavaScript
15403    /// `arr[idx] = value`.
15404    #[wasm_bindgen(method, indexing_setter)]
15405    pub fn set_index_from_f32(this: &Float16Array, idx: u32, value: f32);
15406}
15407
15408impl Default for Float16Array {
15409    fn default() -> Self {
15410        Self::new(&JsValue::UNDEFINED.unchecked_into())
15411    }
15412}
15413
15414impl TypedArray for Float16Array {}
15415
15416impl Float16Array {
15417    fn as_uint16_view(&self) -> Uint16Array {
15418        let buffer = self.buffer();
15419        Uint16Array::new_with_byte_offset_and_length(
15420            buffer.as_ref(),
15421            self.byte_offset(),
15422            self.length(),
15423        )
15424    }
15425
15426    /// Creates an array from raw IEEE 754 binary16 bit patterns.
15427    ///
15428    /// This pairs naturally with the optional `half` crate:
15429    ///
15430    /// ```rust
15431    /// use half::f16;
15432    /// use js_sys::Float16Array;
15433    ///
15434    /// let values = [f16::from_f32(1.0), f16::from_f32(-2.0)];
15435    /// let bits = values.map(f16::to_bits);
15436    /// let array = Float16Array::new_from_u16_slice(&bits);
15437    /// ```
15438    pub fn new_from_u16_slice(slice: &[u16]) -> Float16Array {
15439        let array = Float16Array::new_with_length(slice.len() as u32);
15440        array.copy_from_u16_slice(slice);
15441        array
15442    }
15443
15444    /// Copy the raw IEEE 754 binary16 bit patterns from this JS typed array
15445    /// into the destination Rust slice.
15446    ///
15447    /// # Panics
15448    ///
15449    /// This function will panic if this typed array's length is different than
15450    /// the length of the provided `dst` array.
15451    ///
15452    /// Values copied into `dst` can be converted back into `half::f16` with
15453    /// `half::f16::from_bits`.
15454    pub fn copy_to_u16_slice(&self, dst: &mut [u16]) {
15455        self.as_uint16_view().copy_to(dst);
15456    }
15457
15458    /// Copy raw IEEE 754 binary16 bit patterns from the source Rust slice into
15459    /// this JS typed array.
15460    ///
15461    /// # Panics
15462    ///
15463    /// This function will panic if this typed array's length is different than
15464    /// the length of the provided `src` array.
15465    ///
15466    /// When using the optional `half` crate, populate `src` with
15467    /// `half::f16::to_bits()`.
15468    pub fn copy_from_u16_slice(&self, src: &[u16]) {
15469        self.as_uint16_view().copy_from(src);
15470    }
15471
15472    /// Efficiently copies the contents of this JS typed array into a new Vec of
15473    /// raw IEEE 754 binary16 bit patterns.
15474    ///
15475    /// This makes it easy to round-trip through the optional `half` crate:
15476    ///
15477    /// ```rust
15478    /// use half::f16;
15479    ///
15480    /// let bits = array.to_u16_vec();
15481    /// let values: Vec<f16> = bits.into_iter().map(f16::from_bits).collect();
15482    /// ```
15483    pub fn to_u16_vec(&self) -> Vec<u16> {
15484        self.as_uint16_view().to_vec()
15485    }
15486}
15487
15488macro_rules! arrays {
15489    ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
15490        #[wasm_bindgen]
15491        extern "C" {
15492            #[wasm_bindgen(extends = Object, typescript_type = $name)]
15493            #[derive(Clone, Debug)]
15494            pub type $name;
15495
15496            /// The
15497            #[doc = $ctor]
15498            /// constructor creates a new array.
15499            ///
15500            /// [MDN documentation](
15501            #[doc = $mdn]
15502            /// )
15503            #[wasm_bindgen(constructor)]
15504            pub fn new(constructor_arg: &JsValue) -> $name;
15505
15506            /// An
15507            #[doc = $ctor]
15508            /// which creates an array with an internal buffer large
15509            /// enough for `length` elements.
15510            ///
15511            /// [MDN documentation](
15512            #[doc = $mdn]
15513            /// )
15514            #[wasm_bindgen(constructor)]
15515            pub fn new_with_length(length: u32) -> $name;
15516
15517            /// An
15518            #[doc = $ctor]
15519            /// which creates an array from a Rust slice.
15520            ///
15521            /// [MDN documentation](
15522            #[doc = $mdn]
15523            /// )
15524            #[wasm_bindgen(constructor)]
15525            pub fn new_from_slice(slice: &[$ty]) -> $name;
15526
15527            /// An
15528            #[doc = $ctor]
15529            /// which creates an array with the given buffer but is a
15530            /// view starting at `byte_offset`.
15531            ///
15532            /// [MDN documentation](
15533            #[doc = $mdn]
15534            /// )
15535            #[wasm_bindgen(constructor)]
15536            pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
15537
15538            /// An
15539            #[doc = $ctor]
15540            /// which creates an array with the given buffer but is a
15541            /// view starting at `byte_offset` for `length` elements.
15542            ///
15543            /// [MDN documentation](
15544            #[doc = $mdn]
15545            /// )
15546            #[wasm_bindgen(constructor)]
15547            pub fn new_with_byte_offset_and_length(
15548                buffer: &JsValue,
15549                byte_offset: u32,
15550                length: u32,
15551            ) -> $name;
15552
15553            /// The `fill()` method fills all the elements of an array from a start index
15554            /// to an end index with a static value. The end index is not included.
15555            ///
15556            /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
15557            #[wasm_bindgen(method)]
15558            pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
15559
15560            /// The buffer accessor property represents the `ArrayBuffer` referenced
15561            /// by a `TypedArray` at construction time.
15562            #[wasm_bindgen(getter, method)]
15563            pub fn buffer(this: &$name) -> ArrayBuffer;
15564
15565            /// The `subarray()` method returns a new `TypedArray` on the same
15566            /// `ArrayBuffer` store and with the same element types as for this
15567            /// `TypedArray` object.
15568            #[wasm_bindgen(method)]
15569            pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
15570
15571            /// The `slice()` method returns a shallow copy of a portion of a typed
15572            /// array into a new typed array object. This method has the same algorithm
15573            /// as `Array.prototype.slice()`.
15574            #[wasm_bindgen(method)]
15575            pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
15576
15577            /// The `toReversed()` method returns a new typed array with the
15578            /// elements in reverse order, leaving this one unchanged.
15579            #[wasm_bindgen(method, js_name = toReversed)]
15580            pub fn to_reversed(this: &$name) -> $name;
15581
15582            /// The `toSorted()` method returns a new typed array with the
15583            /// elements sorted in ascending numeric order, leaving this one
15584            /// unchanged.
15585            #[wasm_bindgen(method, js_name = toSorted)]
15586            pub fn to_sorted(this: &$name) -> $name;
15587
15588            /// The `with()` method returns a new typed array with the element
15589            /// at `index` replaced by `value`, leaving this one unchanged.
15590            /// Throws a `RangeError` if `index` is out of bounds.
15591            #[wasm_bindgen(method, catch)]
15592            pub fn with(this: &$name, index: i32, value: $ty) -> Result<$name, JsValue>;
15593
15594            /// The `findLast()` method returns the last element for which
15595            /// `predicate` returns `true`, if any.
15596            #[wasm_bindgen(method, js_name = findLast)]
15597            pub fn find_last(this: &$name, predicate: &mut dyn FnMut($ty, u32, $name) -> bool) -> Option<$ty>;
15598
15599            /// The `findLastIndex()` method returns the index of the last
15600            /// element for which `predicate` returns `true`, or `-1`.
15601            #[wasm_bindgen(method, js_name = findLastIndex)]
15602            pub fn find_last_index(this: &$name, predicate: &mut dyn FnMut($ty, u32, $name) -> bool) -> i32;
15603
15604            /// The `includes()` method returns whether the typed array
15605            /// contains `value`, searching from `from_index`, which counts
15606            /// from the end when negative.
15607            #[wasm_bindgen(method)]
15608            pub fn includes(this: &$name, value: $ty, from_index: i32) -> bool;
15609
15610            /// The `indexOf()` method returns the first index at which
15611            /// `value` is found, searching from `from_index`, which counts
15612            /// from the end when negative, or `-1`.
15613            #[wasm_bindgen(method, js_name = indexOf)]
15614            pub fn index_of(this: &$name, value: $ty, from_index: i32) -> i32;
15615
15616            /// The `forEach()` method executes a provided function once per array
15617            /// element. This method has the same algorithm as
15618            /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
15619            /// types here.
15620            #[wasm_bindgen(method, js_name = forEach)]
15621            pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
15622
15623            /// The `forEach()` method executes a provided function once per array
15624            /// element. This method has the same algorithm as
15625            /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
15626            /// types here.
15627            #[wasm_bindgen(method, js_name = forEach, catch)]
15628            pub fn try_for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name) -> Result<(), JsError>) -> Result<(), JsValue>;
15629
15630            /// The length accessor property represents the length (in elements) of a
15631            /// typed array.
15632            #[wasm_bindgen(method, getter)]
15633            pub fn length(this: &$name) -> u32;
15634
15635            /// The byteLength accessor property represents the length (in bytes) of a
15636            /// typed array.
15637            #[wasm_bindgen(method, getter, js_name = byteLength)]
15638            pub fn byte_length(this: &$name) -> u32;
15639
15640            /// The byteOffset accessor property represents the offset (in bytes) of a
15641            /// typed array from the start of its `ArrayBuffer`.
15642            #[wasm_bindgen(method, getter, js_name = byteOffset)]
15643            pub fn byte_offset(this: &$name) -> u32;
15644
15645            /// The `set()` method stores multiple values in the typed array, reading
15646            /// input values from a specified array.
15647            #[wasm_bindgen(method)]
15648            pub fn set(this: &$name, src: &JsValue, offset: u32);
15649
15650            /// Gets the value at `idx`, counting from the end if negative.
15651            #[wasm_bindgen(method)]
15652            pub fn at(this: &$name, idx: i32) -> Option<$ty>;
15653
15654            /// The `copyWithin()` method shallow copies part of a typed array to another
15655            /// location in the same typed array and returns it, without modifying its size.
15656            ///
15657            /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
15658            #[wasm_bindgen(method, js_name = copyWithin)]
15659            pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
15660
15661            /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
15662            #[wasm_bindgen(method, indexing_getter)]
15663            pub fn get_index(this: &$name, idx: u32) -> $ty;
15664
15665            /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
15666            #[wasm_bindgen(method, indexing_setter)]
15667            pub fn set_index(this: &$name, idx: u32, value: $ty);
15668
15669            /// Copies the Rust slice's data to self.
15670            ///
15671            /// This method is not expected to be public. It requires the length of the
15672            /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
15673            #[wasm_bindgen(method, js_name = set)]
15674            fn copy_from_slice(this: &$name, slice: &[$ty]);
15675
15676            /// Copies this TypedArray's data to Rust slice;
15677            ///
15678            /// This method is not expected to be public. It requires the length of the
15679            /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
15680            ///
15681            /// # Workaround
15682            ///
15683            /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
15684            /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
15685            /// us to specify the `this` value inside the function.
15686            ///
15687            /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
15688            /// `slice.set(typed_array)`.
15689            #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
15690            fn copy_to_slice(slice: &mut [$ty], this: &$name);
15691        }
15692
15693        impl $name {
15694            /// Creates a JS typed array which is a view into wasm's linear
15695            /// memory at the slice specified.
15696            ///
15697            /// This function returns a new typed array which is a view into
15698            /// wasm's memory. This view does not copy the underlying data.
15699            ///
15700            /// # Safety
15701            ///
15702            /// Views into WebAssembly memory are only valid so long as the
15703            /// backing buffer isn't resized in JS. Once this function is called
15704            /// any future calls to `Box::new` (or malloc of any form) may cause
15705            /// the returned value here to be invalidated. Use with caution!
15706            ///
15707            /// Additionally the returned object can be safely mutated but the
15708            /// input slice isn't guaranteed to be mutable.
15709            ///
15710            /// Finally, the returned object is disconnected from the input
15711            /// slice's lifetime, so there's no guarantee that the data is read
15712            /// at the right time.
15713            pub unsafe fn view(rust: &[$ty]) -> $name {
15714                wasm_bindgen::__rt::wbg_cast(rust)
15715            }
15716
15717            /// Creates a JS typed array which is a view into wasm's linear
15718            /// memory at the specified pointer with specified length.
15719            ///
15720            /// This function returns a new typed array which is a view into
15721            /// wasm's memory. This view does not copy the underlying data.
15722            ///
15723            /// # Safety
15724            ///
15725            /// Views into WebAssembly memory are only valid so long as the
15726            /// backing buffer isn't resized in JS. Once this function is called
15727            /// any future calls to `Box::new` (or malloc of any form) may cause
15728            /// the returned value here to be invalidated. Use with caution!
15729            ///
15730            /// Additionally the returned object can be safely mutated,
15731            /// the changes are guaranteed to be reflected in the input array.
15732            pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
15733                let slice = core::slice::from_raw_parts_mut(ptr, length);
15734                Self::view(slice)
15735            }
15736
15737            /// Copy the contents of this JS typed array into the destination
15738            /// Rust pointer.
15739            ///
15740            /// This function will efficiently copy the memory from a typed
15741            /// array into this Wasm module's own linear memory, initializing
15742            /// the memory destination provided.
15743            ///
15744            /// # Safety
15745            ///
15746            /// This function requires `dst` to point to a buffer
15747            /// large enough to fit this array's contents.
15748            pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
15749                let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
15750                self.copy_to(slice);
15751            }
15752
15753            /// Copy the contents of this JS typed array into the destination
15754            /// Rust slice.
15755            ///
15756            /// This function will efficiently copy the memory from a typed
15757            /// array into this Wasm module's own linear memory, initializing
15758            /// the memory destination provided.
15759            ///
15760            /// # Panics
15761            ///
15762            /// This function will panic if this typed array's length is
15763            /// different than the length of the provided `dst` array.
15764            pub fn copy_to(&self, dst: &mut [$ty]) {
15765                core::assert_eq!(self.length() as usize, dst.len());
15766                $name::copy_to_slice(dst, self);
15767            }
15768
15769            /// Copy the contents of this JS typed array into the destination
15770            /// Rust slice.
15771            ///
15772            /// This function will efficiently copy the memory from a typed
15773            /// array into this Wasm module's own linear memory, initializing
15774            /// the memory destination provided.
15775            ///
15776            /// # Panics
15777            ///
15778            /// This function will panic if this typed array's length is
15779            /// different than the length of the provided `dst` array.
15780            pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
15781                core::assert_eq!(self.length() as usize, dst.len());
15782                let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
15783                self.copy_to(dst);
15784                dst
15785            }
15786
15787            /// Copy the contents of the source Rust slice into this
15788            /// JS typed array.
15789            ///
15790            /// This function will efficiently copy the memory from within
15791            /// the Wasm module's own linear memory to this typed array.
15792            ///
15793            /// # Panics
15794            ///
15795            /// This function will panic if this typed array's length is
15796            /// different than the length of the provided `src` array.
15797            pub fn copy_from(&self, src: &[$ty]) {
15798                core::assert_eq!(self.length() as usize, src.len());
15799                self.copy_from_slice(src);
15800            }
15801
15802            /// Efficiently copies the contents of this JS typed array into a new Vec.
15803            pub fn to_vec(&self) -> Vec<$ty> {
15804                let len = self.length() as usize;
15805                let mut output = Vec::with_capacity(len);
15806                // Safety: the capacity has been set
15807                unsafe {
15808                    self.raw_copy_to_ptr(output.as_mut_ptr());
15809                    output.set_len(len);
15810                }
15811                output
15812            }
15813        }
15814
15815        impl<'a> From<&'a [$ty]> for $name {
15816            #[inline]
15817            fn from(slice: &'a [$ty]) -> $name {
15818                // This is safe because the `new` function makes a copy if its argument is a TypedArray
15819                $name::new_from_slice(slice)
15820            }
15821        }
15822
15823        impl Default for $name {
15824            fn default() -> Self {
15825                Self::new(&JsValue::UNDEFINED.unchecked_into())
15826            }
15827        }
15828
15829        impl TypedArray for $name {}
15830
15831
15832    )*);
15833}
15834
15835arrays! {
15836    /// `Int8Array()`
15837    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
15838    Int8Array: i8,
15839
15840    /// `Int16Array()`
15841    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
15842    Int16Array: i16,
15843
15844    /// `Int32Array()`
15845    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
15846    Int32Array: i32,
15847
15848    /// `Uint8Array()`
15849    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
15850    Uint8Array: u8,
15851
15852    /// `Uint8ClampedArray()`
15853    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
15854    Uint8ClampedArray: u8,
15855
15856    /// `Uint16Array()`
15857    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
15858    Uint16Array: u16,
15859
15860    /// `Uint32Array()`
15861    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
15862    Uint32Array: u32,
15863
15864    /// `Float32Array()`
15865    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
15866    Float32Array: f32,
15867
15868    /// `Float64Array()`
15869    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
15870    Float64Array: f64,
15871
15872    /// `BigInt64Array()`
15873    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
15874    BigInt64Array: i64,
15875
15876    /// `BigUint64Array()`
15877    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
15878    BigUint64Array: u64,
15879}
15880
15881// Base64Options
15882#[wasm_bindgen]
15883extern "C" {
15884    /// Options for the `Uint8Array` base64 methods: `alphabet` is
15885    /// `"base64"` (default) or `"base64url"`; `lastChunkHandling`, for
15886    /// decoding, is `"loose"` (default), `"strict"` or
15887    /// `"stop-before-partial"`; `omitPadding`, for encoding, drops the
15888    /// trailing `=` characters.
15889    ///
15890    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64#options)
15891    #[wasm_bindgen(extends = Object, typescript_type = "object")]
15892    #[derive(Clone, Debug, PartialEq, Eq)]
15893    pub type Base64Options;
15894
15895    /// Sets the alphabet.
15896    #[wasm_bindgen(method, setter)]
15897    pub fn set_alphabet(this: &Base64Options, alphabet: Base64Alphabet);
15898
15899    /// The alphabet, if set.
15900    #[wasm_bindgen(method, getter, js_name = alphabet)]
15901    pub fn get_alphabet(this: &Base64Options) -> Option<Base64Alphabet>;
15902
15903    /// Sets how a trailing partial chunk is decoded.
15904    #[wasm_bindgen(method, setter, js_name = lastChunkHandling)]
15905    pub fn set_last_chunk_handling(
15906        this: &Base64Options,
15907        last_chunk_handling: Base64LastChunkHandling,
15908    );
15909
15910    /// How a trailing partial chunk is decoded, if set.
15911    #[wasm_bindgen(method, getter, js_name = lastChunkHandling)]
15912    pub fn get_last_chunk_handling(this: &Base64Options) -> Option<Base64LastChunkHandling>;
15913
15914    /// Sets whether encoding omits the trailing `=` padding.
15915    #[wasm_bindgen(method, setter, js_name = omitPadding)]
15916    pub fn set_omit_padding(this: &Base64Options, omit_padding: bool);
15917
15918    /// Whether encoding omits the trailing `=` padding, if set.
15919    #[wasm_bindgen(method, getter, js_name = omitPadding)]
15920    pub fn get_omit_padding(this: &Base64Options) -> Option<bool>;
15921}
15922
15923/// The `alphabet` option of the `Uint8Array` base64 methods.
15924#[wasm_bindgen]
15925#[derive(Clone, Copy, Debug, PartialEq, Eq)]
15926pub enum Base64Alphabet {
15927    /// The standard alphabet with `+` and `/`.
15928    Base64 = "base64",
15929    /// The URL-safe alphabet with `-` and `_`.
15930    Base64Url = "base64url",
15931}
15932
15933/// The `lastChunkHandling` option of the `Uint8Array` base64 decoders.
15934#[wasm_bindgen]
15935#[derive(Clone, Copy, Debug, PartialEq, Eq)]
15936pub enum Base64LastChunkHandling {
15937    /// A trailing partial chunk is decoded if it is well formed.
15938    Loose = "loose",
15939    /// A trailing partial chunk is a `SyntaxError`.
15940    Strict = "strict",
15941    /// A trailing partial chunk is left in the input.
15942    StopBeforePartial = "stop-before-partial",
15943}
15944
15945impl Base64Options {
15946    pub fn new() -> Base64Options {
15947        JsCast::unchecked_into::<Base64Options>(Object::<JsValue>::new())
15948    }
15949}
15950
15951impl Default for Base64Options {
15952    fn default() -> Self {
15953        Self::new()
15954    }
15955}
15956
15957// SetFromResult
15958#[wasm_bindgen]
15959extern "C" {
15960    /// The `{ read, written }` result of [`Uint8Array::set_from_base64`]
15961    /// and [`Uint8Array::set_from_hex`]: how many characters of the input
15962    /// were consumed and how many bytes were written.
15963    ///
15964    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/setFromBase64#return_value)
15965    #[wasm_bindgen(extends = Object, typescript_type = "object")]
15966    #[derive(Clone, Debug, PartialEq, Eq)]
15967    pub type SetFromResult;
15968
15969    /// The number of input characters consumed.
15970    #[wasm_bindgen(method, getter)]
15971    pub fn read(this: &SetFromResult) -> u32;
15972
15973    /// The number of bytes written into the array.
15974    #[wasm_bindgen(method, getter)]
15975    pub fn written(this: &SetFromResult) -> u32;
15976}
15977
15978// Uint8Array base64 / hex
15979#[wasm_bindgen]
15980extern "C" {
15981    /// The `Uint8Array.fromBase64()` static method decodes a base64 string
15982    /// into a new `Uint8Array`. Throws a `SyntaxError` on invalid input.
15983    ///
15984    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64)
15985    #[wasm_bindgen(static_method_of = Uint8Array, catch, js_name = fromBase64)]
15986    pub fn from_base64(text: &str) -> Result<Uint8Array, JsValue>;
15987
15988    /// The `Uint8Array.fromBase64()` static method decodes a base64 string
15989    /// into a new `Uint8Array`, with the given alphabet and last chunk
15990    /// handling. Throws a `SyntaxError` on invalid input.
15991    ///
15992    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64)
15993    #[wasm_bindgen(static_method_of = Uint8Array, catch, js_name = fromBase64)]
15994    pub fn from_base64_with_options(
15995        text: &str,
15996        options: &Base64Options,
15997    ) -> Result<Uint8Array, JsValue>;
15998
15999    /// The `Uint8Array.fromHex()` static method decodes a hex string into a
16000    /// new `Uint8Array`. Throws a `SyntaxError` on invalid input.
16001    ///
16002    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromHex)
16003    #[wasm_bindgen(static_method_of = Uint8Array, catch, js_name = fromHex)]
16004    pub fn from_hex(text: &str) -> Result<Uint8Array, JsValue>;
16005
16006    /// The `toBase64()` method encodes the bytes of this array as a base64
16007    /// string.
16008    ///
16009    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64)
16010    #[wasm_bindgen(method, js_name = toBase64)]
16011    pub fn to_base64(this: &Uint8Array) -> JsString;
16012
16013    /// The `toBase64()` method encodes the bytes of this array as a base64
16014    /// string, with the given alphabet and padding.
16015    ///
16016    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64)
16017    #[wasm_bindgen(method, js_name = toBase64)]
16018    pub fn to_base64_with_options(this: &Uint8Array, options: &Base64Options) -> JsString;
16019
16020    /// The `toHex()` method encodes the bytes of this array as a lowercase
16021    /// hex string.
16022    ///
16023    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex)
16024    #[wasm_bindgen(method, js_name = toHex)]
16025    pub fn to_hex(this: &Uint8Array) -> JsString;
16026
16027    /// The `setFromBase64()` method decodes a base64 string into this
16028    /// array in place, stopping when the array is full, and reports how
16029    /// much was read and written.
16030    ///
16031    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/setFromBase64)
16032    #[wasm_bindgen(method, catch, js_name = setFromBase64)]
16033    pub fn set_from_base64(this: &Uint8Array, text: &str) -> Result<SetFromResult, JsValue>;
16034
16035    /// The `setFromBase64()` method decodes a base64 string into this
16036    /// array in place with the given options, stopping when the array is
16037    /// full, and reports how much was read and written.
16038    ///
16039    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/setFromBase64)
16040    #[wasm_bindgen(method, catch, js_name = setFromBase64)]
16041    pub fn set_from_base64_with_options(
16042        this: &Uint8Array,
16043        text: &str,
16044        options: &Base64Options,
16045    ) -> Result<SetFromResult, JsValue>;
16046
16047    /// The `setFromHex()` method decodes a hex string into this array in
16048    /// place, stopping when the array is full, and reports how much was
16049    /// read and written.
16050    ///
16051    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/setFromHex)
16052    #[wasm_bindgen(method, catch, js_name = setFromHex)]
16053    pub fn set_from_hex(this: &Uint8Array, text: &str) -> Result<SetFromResult, JsValue>;
16054}
16055
16056/// Bridging between JavaScript `Promise`s and Rust `Future`s.
16057///
16058/// Enables `promise.await` directly on any [`Promise`].
16059/// This module is also re-exported by `wasm-bindgen-futures` for backwards compatibility.
16060pub mod futures;