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
31extern crate alloc;
32
33use alloc::string::String;
34use alloc::vec::Vec;
35use core::cmp::Ordering;
36#[cfg(not(js_sys_unstable_apis))]
37use core::convert::Infallible;
38use core::convert::{self, TryFrom};
39use core::f64;
40use core::fmt;
41use core::iter::{self, Product, Sum};
42use core::mem::MaybeUninit;
43use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub};
44use core::str;
45use core::str::FromStr;
46pub use wasm_bindgen;
47use wasm_bindgen::closure::{ScopedClosure, WasmClosure};
48use wasm_bindgen::convert::{FromWasmAbi, IntoWasmAbi, Upcast, UpcastFrom};
49use wasm_bindgen::prelude::*;
50use wasm_bindgen::JsError;
51
52// Re-export sys types as js-sys types
53pub use wasm_bindgen::sys::{JsOption, Null, Promising, Undefined};
54pub use wasm_bindgen::JsGeneric;
55
56// When adding new imports:
57//
58// * Keep imports in alphabetical order.
59//
60// * Rename imports with `js_name = ...` according to the note about `camelCase`
61//   and `snake_case` in the module's documentation above.
62//
63// * Include the one sentence summary of the import from the MDN link in the
64//   module's documentation above, and the MDN link itself.
65//
66// * If a function or method can throw an exception, make it catchable by adding
67//   `#[wasm_bindgen(catch)]`.
68//
69// * Add a new `#[test]` into the appropriate file in the
70//   `crates/js-sys/tests/wasm/` directory. If the imported function or method
71//   can throw an exception, make sure to also add test coverage for that case.
72//
73// * Arguments that are `JsValue`s or imported JavaScript types should be taken
74//   by reference.
75//
76// * Name JavaScript's `toString()` method as `to_js_string()` to avoid conflict
77//   with Rust's `ToString` trait.
78
79macro_rules! forward_deref_unop {
80    (impl $imp:ident, $method:ident for $t:ty) => {
81        impl $imp for $t {
82            type Output = <&'static $t as $imp>::Output;
83
84            #[inline]
85            fn $method(self) -> Self::Output {
86                $imp::$method(&self)
87            }
88        }
89    };
90    (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
91        impl<$($gen),+> $imp for $t {
92            type Output = <&'static $t as $imp>::Output;
93
94            #[inline]
95            fn $method(self) -> Self::Output {
96                $imp::$method(&self)
97            }
98        }
99    };
100}
101
102macro_rules! forward_deref_binop {
103    (impl $imp:ident, $method:ident for $t:ty) => {
104        impl<'a> $imp<$t> for &'a $t {
105            type Output = <&'static $t as $imp<&'static $t>>::Output;
106
107            #[inline]
108            fn $method(self, other: $t) -> Self::Output {
109                $imp::$method(self, &other)
110            }
111        }
112
113        impl $imp<&$t> for $t {
114            type Output = <&'static $t as $imp<&'static $t>>::Output;
115
116            #[inline]
117            fn $method(self, other: &$t) -> Self::Output {
118                $imp::$method(&self, other)
119            }
120        }
121
122        impl $imp<$t> for $t {
123            type Output = <&'static $t as $imp<&'static $t>>::Output;
124
125            #[inline]
126            fn $method(self, other: $t) -> Self::Output {
127                $imp::$method(&self, &other)
128            }
129        }
130    };
131    (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
132        impl<'a, $($gen),+> $imp<$t> for &'a $t {
133            type Output = <&'static $t as $imp<&'static $t>>::Output;
134
135            #[inline]
136            fn $method(self, other: $t) -> Self::Output {
137                $imp::$method(self, &other)
138            }
139        }
140
141        impl<$($gen),+> $imp<&$t> for $t {
142            type Output = <&'static $t as $imp<&'static $t>>::Output;
143
144            #[inline]
145            fn $method(self, other: &$t) -> Self::Output {
146                $imp::$method(&self, other)
147            }
148        }
149
150        impl<$($gen),+> $imp<$t> for $t {
151            type Output = <&'static $t as $imp<&'static $t>>::Output;
152
153            #[inline]
154            fn $method(self, other: $t) -> Self::Output {
155                $imp::$method(&self, &other)
156            }
157        }
158    };
159}
160
161macro_rules! forward_js_unop {
162    (impl $imp:ident, $method:ident for $t:ty) => {
163        impl $imp for &$t {
164            type Output = $t;
165
166            #[inline]
167            fn $method(self) -> Self::Output {
168                $imp::$method(JsValue::as_ref(self)).unchecked_into()
169            }
170        }
171
172        forward_deref_unop!(impl $imp, $method for $t);
173    };
174    (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
175        impl<$($gen),+> $imp for &$t {
176            type Output = $t;
177
178            #[inline]
179            fn $method(self) -> Self::Output {
180                $imp::$method(JsValue::as_ref(self)).unchecked_into()
181            }
182        }
183
184        forward_deref_unop!(impl<$($gen),+> $imp, $method for $t);
185    };
186}
187
188macro_rules! forward_js_binop {
189    (impl $imp:ident, $method:ident for $t:ty) => {
190        impl $imp<&$t> for &$t {
191            type Output = $t;
192
193            #[inline]
194            fn $method(self, other: &$t) -> Self::Output {
195                $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
196            }
197        }
198
199        forward_deref_binop!(impl $imp, $method for $t);
200    };
201    (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
202        impl<$($gen),+> $imp<&$t> for &$t {
203            type Output = $t;
204
205            #[inline]
206            fn $method(self, other: &$t) -> Self::Output {
207                $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
208            }
209        }
210
211        forward_deref_binop!(impl<$($gen),+> $imp, $method for $t);
212    };
213}
214
215macro_rules! sum_product {
216    ($($a:ident)*) => ($(
217        impl Sum for $a {
218            #[inline]
219            fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
220                iter.fold(
221                    $a::from(0),
222                    |a, b| a + b,
223                )
224            }
225        }
226
227        impl Product for $a {
228            #[inline]
229            fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
230                iter.fold(
231                    $a::from(1),
232                    |a, b| a * b,
233                )
234            }
235        }
236
237        impl<'a> Sum<&'a $a> for $a {
238            fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
239                iter.fold(
240                    $a::from(0),
241                    |a, b| a + b,
242                )
243            }
244        }
245
246        impl<'a> Product<&'a $a> for $a {
247            #[inline]
248            fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
249                iter.fold(
250                    $a::from(1),
251                    |a, b| a * b,
252                )
253            }
254        }
255    )*);
256    // Generic variant: impl<T> for Type<T>
257    (impl<$gen:ident> $a:ident<$g2:ident>) => {
258        impl<$gen> Sum for $a<$g2>
259        where
260            $a<$g2>: From<$gen>,
261            $g2: From<u32>
262        {
263            #[inline]
264            fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
265                iter.fold(
266                    $a::from($g2::from(0)),
267                    |a, b| a + b,
268                )
269            }
270        }
271
272        impl<$gen> Product for $a<$g2>
273        where
274            $a<$g2>: From<$gen>,
275            $g2: From<u32>
276        {
277            #[inline]
278            fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
279                iter.fold(
280                    $a::from($g2::from(1)),
281                    |a, b| a * b,
282                )
283            }
284        }
285
286        impl<'a, $gen> Sum<&'a $a<$g2>> for $a<$g2>
287        where
288            $a<$g2>: From<$gen>,
289            $g2: From<u32>
290        {
291            fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
292                iter.fold(
293                    $a::from($g2::from(0)),
294                    |a, b| a + b,
295                )
296            }
297        }
298
299        impl<'a, $gen> Product<&'a $a<$g2>> for $a<$g2>
300        where
301            $a<$g2>: From<$gen>,
302            $g2: From<u32>
303        {
304            #[inline]
305            fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
306                iter.fold(
307                    $a::from($g2::from(1)),
308                    |a, b| a * b,
309                )
310            }
311        }
312    };
313}
314
315macro_rules! partialord_ord {
316    ($t:ident) => {
317        impl PartialOrd for $t {
318            #[inline]
319            fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
320                Some(self.cmp(other))
321            }
322
323            #[inline]
324            fn lt(&self, other: &Self) -> bool {
325                JsValue::as_ref(self).lt(JsValue::as_ref(other))
326            }
327
328            #[inline]
329            fn le(&self, other: &Self) -> bool {
330                JsValue::as_ref(self).le(JsValue::as_ref(other))
331            }
332
333            #[inline]
334            fn ge(&self, other: &Self) -> bool {
335                JsValue::as_ref(self).ge(JsValue::as_ref(other))
336            }
337
338            #[inline]
339            fn gt(&self, other: &Self) -> bool {
340                JsValue::as_ref(self).gt(JsValue::as_ref(other))
341            }
342        }
343
344        impl Ord for $t {
345            #[inline]
346            fn cmp(&self, other: &Self) -> Ordering {
347                if self == other {
348                    Ordering::Equal
349                } else if self.lt(other) {
350                    Ordering::Less
351                } else {
352                    Ordering::Greater
353                }
354            }
355        }
356    };
357}
358
359#[wasm_bindgen]
360extern "C" {
361    /// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
362    /// previously created by `encodeURI` or by a similar routine.
363    ///
364    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI)
365    #[wasm_bindgen(catch, js_name = decodeURI)]
366    pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
367
368    /// The `decodeURIComponent()` function decodes a Uniform Resource Identifier (URI) component
369    /// previously created by `encodeURIComponent` or by a similar routine.
370    ///
371    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
372    #[wasm_bindgen(catch, js_name = decodeURIComponent)]
373    pub fn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>;
374
375    /// The `encodeURI()` function encodes a Uniform Resource Identifier (URI)
376    /// by replacing each instance of certain characters by one, two, three, or
377    /// four escape sequences representing the UTF-8 encoding of the character
378    /// (will only be four escape sequences for characters composed of two
379    /// "surrogate" characters).
380    ///
381    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
382    #[wasm_bindgen(js_name = encodeURI)]
383    pub fn encode_uri(decoded: &str) -> JsString;
384
385    /// The `encodeURIComponent()` function encodes a Uniform Resource Identifier (URI) component
386    /// by replacing each instance of certain characters by one, two, three, or four escape sequences
387    /// representing the UTF-8 encoding of the character
388    /// (will only be four escape sequences for characters composed of two "surrogate" characters).
389    ///
390    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
391    #[wasm_bindgen(js_name = encodeURIComponent)]
392    pub fn encode_uri_component(decoded: &str) -> JsString;
393
394    /// The `eval()` function evaluates JavaScript code represented as a string.
395    ///
396    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)
397    #[cfg(feature = "unsafe-eval")]
398    #[wasm_bindgen(catch)]
399    pub fn eval(js_source_text: &str) -> Result<JsValue, JsValue>;
400
401    /// The global `isFinite()` function determines whether the passed value is a finite number.
402    /// If needed, the parameter is first converted to a number.
403    ///
404    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
405    #[wasm_bindgen(js_name = isFinite)]
406    pub fn is_finite(value: &JsValue) -> bool;
407
408    /// The `parseInt()` function parses a string argument and returns an integer
409    /// of the specified radix (the base in mathematical numeral systems), or NaN on error.
410    ///
411    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
412    #[wasm_bindgen(js_name = parseInt)]
413    pub fn parse_int(text: &str, radix: u8) -> f64;
414
415    /// The `parseFloat()` function parses an argument and returns a floating point number,
416    /// or NaN on error.
417    ///
418    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
419    #[wasm_bindgen(js_name = parseFloat)]
420    pub fn parse_float(text: &str) -> f64;
421
422    /// The `escape()` function computes a new string in which certain characters have been
423    /// replaced by a hexadecimal escape sequence.
424    ///
425    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape)
426    #[wasm_bindgen]
427    pub fn escape(string: &str) -> JsString;
428
429    /// The `unescape()` function computes a new string in which hexadecimal escape
430    /// sequences are replaced with the character that it represents. The escape sequences might
431    /// be introduced by a function like `escape`. Usually, `decodeURI` or `decodeURIComponent`
432    /// are preferred over `unescape`.
433    ///
434    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape)
435    #[wasm_bindgen]
436    pub fn unescape(string: &str) -> JsString;
437}
438
439// Array
440#[wasm_bindgen]
441extern "C" {
442    #[wasm_bindgen(extends = Object, is_type_of = Array::is_array, typescript_type = "Array<any>")]
443    #[derive(Clone, Debug, PartialEq, Eq)]
444    pub type Array<T = JsValue>;
445
446    /// Creates a new empty array.
447    ///
448    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
449    #[cfg(not(js_sys_unstable_apis))]
450    #[wasm_bindgen(constructor)]
451    pub fn new() -> Array;
452
453    /// Creates a new empty array.
454    ///
455    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
456    #[cfg(js_sys_unstable_apis)]
457    #[wasm_bindgen(constructor)]
458    pub fn new<T>() -> Array<T>;
459
460    // Next major: deprecate
461    /// Creates a new empty array.
462    ///
463    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
464    #[wasm_bindgen(constructor)]
465    pub fn new_typed<T>() -> Array<T>;
466
467    /// Creates a new array with the specified length (elements are initialized to `undefined`).
468    ///
469    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
470    #[cfg(not(js_sys_unstable_apis))]
471    #[wasm_bindgen(constructor)]
472    pub fn new_with_length(len: u32) -> Array;
473
474    /// Creates a new array with the specified length (elements are initialized to `undefined`).
475    ///
476    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
477    #[cfg(js_sys_unstable_apis)]
478    #[wasm_bindgen(constructor)]
479    pub fn new_with_length<T>(len: u32) -> Array<T>;
480
481    // Next major: deprecate
482    /// Creates a new array with the specified length (elements are initialized to `undefined`).
483    ///
484    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
485    #[wasm_bindgen(constructor)]
486    pub fn new_with_length_typed<T>(len: u32) -> Array<T>;
487
488    /// Retrieves the element at the index, counting from the end if negative
489    /// (returns `undefined` if the index is out of range).
490    ///
491    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
492    #[cfg(not(js_sys_unstable_apis))]
493    #[wasm_bindgen(method)]
494    pub fn at<T>(this: &Array<T>, index: i32) -> T;
495
496    /// Retrieves the element at the index, counting from the end if negative
497    /// (returns `None` if the index is out of range).
498    ///
499    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
500    #[cfg(js_sys_unstable_apis)]
501    #[wasm_bindgen(method)]
502    pub fn at<T>(this: &Array<T>, index: i32) -> Option<T>;
503
504    /// Retrieves the element at the index (returns `undefined` if the index is out of range).
505    ///
506    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
507    #[cfg(not(js_sys_unstable_apis))]
508    #[wasm_bindgen(method, indexing_getter)]
509    pub fn get<T>(this: &Array<T>, index: u32) -> T;
510
511    /// Retrieves the element at the index (returns `None` if the index is out of range).
512    ///
513    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
514    #[cfg(js_sys_unstable_apis)]
515    #[wasm_bindgen(method, indexing_getter)]
516    pub fn get<T>(this: &Array<T>, index: u32) -> Option<T>;
517
518    /// Retrieves the element at the index (returns `undefined` if the index is out of range).
519    ///
520    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
521    #[wasm_bindgen(method, indexing_getter)]
522    pub fn get_unchecked<T>(this: &Array<T>, index: u32) -> T;
523
524    // Next major: deprecate
525    /// Retrieves the element at the index (returns `None` if the index is out of range,
526    /// or if the element is explicitly `undefined`).
527    #[wasm_bindgen(method, indexing_getter)]
528    pub fn get_checked<T>(this: &Array<T>, index: u32) -> Option<T>;
529
530    /// Sets the element at the index (auto-enlarges the array if the index is out of range).
531    #[cfg(not(js_sys_unstable_apis))]
532    #[wasm_bindgen(method, indexing_setter)]
533    pub fn set<T>(this: &Array<T>, index: u32, value: T);
534
535    /// Sets the element at the index (auto-enlarges the array if the index is out of range).
536    #[cfg(js_sys_unstable_apis)]
537    #[wasm_bindgen(method, indexing_setter)]
538    pub fn set<T>(this: &Array<T>, index: u32, value: &T);
539
540    // Next major: deprecate
541    /// Sets the element at the index (auto-enlarges the array if the index is out of range).
542    #[wasm_bindgen(method, indexing_setter)]
543    pub fn set_ref<T>(this: &Array<T>, index: u32, value: &T);
544
545    /// Deletes the element at the index (does nothing if the index is out of range).
546    ///
547    /// The element at the index is set to `undefined`.
548    ///
549    /// This does not resize the array, the array will still be the same length.
550    #[wasm_bindgen(method, indexing_deleter)]
551    pub fn delete<T>(this: &Array<T>, index: u32);
552
553    /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
554    /// from an array-like or iterable object.
555    ///
556    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
557    #[cfg(not(js_sys_unstable_apis))]
558    #[wasm_bindgen(static_method_of = Array)]
559    pub fn from(val: &JsValue) -> Array;
560
561    /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
562    /// from an array-like or iterable object.
563    ///
564    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
565    #[cfg(js_sys_unstable_apis)]
566    #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
567    pub fn from<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
568
569    // Next major: deprecate
570    /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
571    /// from an array-like or iterable object.
572    ///
573    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
574    #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
575    pub fn from_iterable<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
576
577    /// The `Array.from()` static method with a map function creates a new, shallow-copied
578    /// `Array` instance from an array-like or iterable object, applying the map function
579    /// to each value.
580    ///
581    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
582    #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
583    pub fn from_iterable_map<'a, I: Iterable, U>(
584        val: &I,
585        map: &ImmediateClosure<'a, dyn FnMut(I::Item, u32) -> Result<U, JsError> + 'a>,
586    ) -> Result<Array<U>, JsValue>;
587
588    /// The `Array.fromAsync()` static method creates a new, shallow-copied `Array` instance
589    /// from an async iterable, iterable or array-like object.
590    ///
591    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
592    #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
593    pub fn from_async<I: AsyncIterable>(val: &I) -> Result<Promise<Array<I::Item>>, JsValue>;
594
595    /// The `Array.fromAsync()` static method with a map function creates a new, shallow-copied
596    /// `Array` instance from an async iterable, iterable or array-like object, applying the map
597    /// function to each value.
598    ///
599    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
600    #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
601    pub fn from_async_map<'a, I: AsyncIterable, R: Promising>(
602        val: &I,
603        map: &ScopedClosure<'a, dyn FnMut(I::Item, u32) -> Result<R, JsError>>,
604    ) -> Result<Promise<Array<R::Resolution>>, JsValue>;
605
606    /// The `copyWithin()` method shallow copies part of an array to another
607    /// location in the same array and returns it, without modifying its size.
608    ///
609    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)
610    #[wasm_bindgen(method, js_name = copyWithin)]
611    pub fn copy_within<T>(this: &Array<T>, target: i32, start: i32, end: i32) -> Array<T>;
612
613    /// The `concat()` method is used to merge two or more arrays. This method
614    /// does not change the existing arrays, but instead returns a new array.
615    ///
616    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
617    #[wasm_bindgen(method)]
618    pub fn concat<T, U: Upcast<T>>(this: &Array<T>, array: &Array<U>) -> Array<T>;
619
620    /// The `concat()` method is used to merge two or more arrays. This method
621    /// does not change the existing arrays, but instead returns a new array.
622    ///
623    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
624    #[wasm_bindgen(method)]
625    pub fn concat_many<T, U: Upcast<T>>(this: &Array<T>, array: &[Array<U>]) -> Array<T>;
626
627    /// The `every()` method tests whether all elements in the array pass the test
628    /// implemented by the provided function.
629    ///
630    /// **Note:** Consider using [`Array::try_every`] if the predicate might throw an error.
631    ///
632    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
633    #[wasm_bindgen(method)]
634    pub fn every<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> bool;
635
636    /// The `every()` method tests whether all elements in the array pass the test
637    /// implemented by the provided function. _(Fallible variation)_
638    ///
639    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
640    #[wasm_bindgen(method, js_name = every, catch)]
641    pub fn try_every<'a, T>(
642        this: &Array<T>,
643        predicate: &ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<bool, JsError> + 'a>,
644    ) -> Result<bool, JsValue>;
645
646    /// The `fill()` method fills all the elements of an array from a start index
647    /// to an end index with a static value. The end index is not included.
648    ///
649    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
650    #[wasm_bindgen(method)]
651    pub fn fill<T>(this: &Array<T>, value: &T, start: u32, end: u32) -> Array<T>;
652
653    /// The `filter()` method creates a new array with all elements that pass the
654    /// test implemented by the provided function.
655    ///
656    /// **Note:** Consider using [`Array::try_filter`] if the predicate might throw an error.
657    ///
658    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
659    #[wasm_bindgen(method)]
660    pub fn filter<T>(
661        this: &Array<T>,
662        predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
663    ) -> Array<T>;
664
665    /// The `filter()` method creates a new array with all elements that pass the
666    /// test implemented by the provided function. _(Fallible variation)_
667    ///
668    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
669    #[wasm_bindgen(method, js_name = filter, catch)]
670    pub fn try_filter<'a, T>(
671        this: &Array<T>,
672        predicate: &ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<bool, JsError> + 'a>,
673    ) -> Result<Array<T>, JsValue>;
674
675    /// The `find()` method returns the value of the first element in the array that satisfies
676    /// the provided testing function. Otherwise `undefined` is returned.
677    ///
678    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
679    #[cfg(not(js_sys_unstable_apis))]
680    #[wasm_bindgen(method)]
681    pub fn find<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
682
683    /// The `find()` method returns the value of the first element in the array that satisfies
684    /// the provided testing function. Returns `None` if no element matches.
685    ///
686    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
687    #[cfg(js_sys_unstable_apis)]
688    #[wasm_bindgen(method)]
689    pub fn find<'a, T>(
690        this: &Array<T>,
691        predicate: &ImmediateClosure<'a, dyn FnMut(T, u32, Array<T>) -> bool + 'a>,
692    ) -> Option<T>;
693
694    /// The `find()` method returns the value of the first element in the array that satisfies
695    ///  the provided testing function. Otherwise `undefined` is returned. _(Fallible variation)_
696    ///
697    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
698    #[wasm_bindgen(method, js_name = find, catch)]
699    pub fn try_find<'a, T>(
700        this: &Array<T>,
701        predicate: &ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<bool, JsError> + 'a>,
702    ) -> Result<Option<T>, JsValue>;
703
704    /// The `findIndex()` method returns the index of the first element in the array that
705    /// satisfies the provided testing function. Otherwise -1 is returned.
706    ///
707    /// **Note:** Consider using [`Array::try_find_index`] if the predicate might throw an error.
708    ///
709    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
710    #[wasm_bindgen(method, js_name = findIndex)]
711    pub fn find_index<T>(
712        this: &Array<T>,
713        predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
714    ) -> i32;
715
716    /// The `findIndex()` method returns the index of the first element in the array that
717    /// satisfies the provided testing function. Otherwise -1 is returned. _(Fallible variation)_
718    ///
719    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
720    #[wasm_bindgen(method, js_name = findIndex, catch)]
721    pub fn try_find_index<'a, T>(
722        this: &Array<T>,
723        predicate: &ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<bool, JsError> + 'a>,
724    ) -> Result<i32, JsValue>;
725
726    /// The `findLast()` method of Array instances iterates the array in reverse order
727    /// and returns the value of the first element that satisfies the provided testing function.
728    /// If no elements satisfy the testing function, undefined is returned.
729    ///
730    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
731    #[cfg(not(js_sys_unstable_apis))]
732    #[wasm_bindgen(method, js_name = findLast)]
733    pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
734
735    /// The `findLast()` method of Array instances iterates the array in reverse order
736    /// and returns the value of the first element that satisfies the provided testing function.
737    /// Returns `None` if no element matches.
738    ///
739    /// **Note:** Consider using [`Array::try_find_last`] if the predicate might throw an error.
740    ///
741    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
742    #[cfg(js_sys_unstable_apis)]
743    #[wasm_bindgen(method, js_name = findLast)]
744    pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32) -> bool) -> Option<T>;
745
746    /// The `findLast()` method of Array instances iterates the array in reverse order
747    /// and returns the value of the first element that satisfies the provided testing function.
748    /// If no elements satisfy the testing function, undefined is returned. _(Fallible variation)_
749    ///
750    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
751    #[wasm_bindgen(method, js_name = findLast, catch)]
752    pub fn try_find_last<'a, T>(
753        this: &Array<T>,
754        predicate: &ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<bool, JsError> + 'a>,
755    ) -> Result<Option<T>, JsValue>;
756
757    /// The `findLastIndex()` method of Array instances iterates the array in reverse order
758    /// and returns the index of the first element that satisfies the provided testing function.
759    /// If no elements satisfy the testing function, -1 is returned.
760    ///
761    /// **Note:** Consider using [`Array::try_find_last_index`] if the predicate might throw an error.
762    ///
763    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
764    #[wasm_bindgen(method, js_name = findLastIndex)]
765    pub fn find_last_index<T>(
766        this: &Array<T>,
767        predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
768    ) -> i32;
769
770    /// The `findLastIndex()` method of Array instances iterates the array in reverse order
771    /// and returns the index of the first element that satisfies the provided testing function.
772    /// If no elements satisfy the testing function, -1 is returned. _(Fallible variation)_
773    ///
774    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
775    #[wasm_bindgen(method, js_name = findLastIndex, catch)]
776    pub fn try_find_last_index<'a, T>(
777        this: &Array<T>,
778        predicate: &ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<bool, JsError> + 'a>,
779    ) -> Result<i32, JsValue>;
780
781    /// The `flat()` method creates a new array with all sub-array elements concatenated into it
782    /// recursively up to the specified depth.
783    ///
784    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
785    #[wasm_bindgen(method)]
786    pub fn flat<T>(this: &Array<T>, depth: i32) -> Array<JsValue>;
787
788    /// The `flatMap()` method first maps each element using a mapping function, then flattens
789    /// the result into a new array.
790    ///
791    /// **Note:** Consider using [`Array::try_flat_map`] for safer fallible handling.
792    ///
793    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
794    #[wasm_bindgen(method, js_name = flatMap)]
795    pub fn flat_map<T, U>(
796        this: &Array<T>,
797        callback: &mut dyn FnMut(T, u32, Array<T>) -> Vec<U>,
798    ) -> Array<U>;
799
800    /// The `flatMap()` method first maps each element using a mapping function, then flattens
801    /// the result into a new array.
802    ///
803    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
804    #[wasm_bindgen(method, js_name = flatMap, catch)]
805    pub fn try_flat_map<'a, T, U>(
806        this: &Array<T>,
807        callback: &ImmediateClosure<'a, dyn FnMut(T, u32) -> Vec<U> + 'a>,
808    ) -> Result<Array<U>, JsValue>;
809
810    /// The `forEach()` method executes a provided function once for each array element.
811    ///
812    /// **Note:** Consider using [`Array::try_for_each`] if the callback might throw an error.
813    ///
814    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
815    #[wasm_bindgen(method, js_name = forEach)]
816    pub fn for_each<T: JsGeneric>(this: &Array<T>, callback: &mut dyn FnMut(T, u32, Array<T>));
817
818    /// The `forEach()` method executes a provided function once for each array element. _(Fallible variation)_
819    ///
820    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
821    #[wasm_bindgen(method, js_name = forEach, catch)]
822    pub fn try_for_each<'a, T>(
823        this: &Array<T>,
824        callback: &ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<(), JsError> + 'a>,
825    ) -> Result<(), JsValue>;
826
827    /// The `includes()` method determines whether an array includes a certain
828    /// element, returning true or false as appropriate.
829    ///
830    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
831    #[wasm_bindgen(method)]
832    pub fn includes<T>(this: &Array<T>, value: &T, from_index: i32) -> bool;
833
834    /// The `indexOf()` method returns the first index at which a given element
835    /// can be found in the array, or -1 if it is not present.
836    ///
837    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
838    #[wasm_bindgen(method, js_name = indexOf)]
839    pub fn index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
840
841    /// The `Array.isArray()` method determines whether the passed value is an Array.
842    ///
843    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)
844    #[wasm_bindgen(static_method_of = Array, js_name = isArray)]
845    pub fn is_array(value: &JsValue) -> bool;
846
847    /// The `join()` method joins all elements of an array (or an array-like object)
848    /// into a string and returns this string.
849    ///
850    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
851    #[wasm_bindgen(method)]
852    pub fn join<T>(this: &Array<T>, delimiter: &str) -> JsString;
853
854    /// The `lastIndexOf()` method returns the last index at which a given element
855    /// can be found in the array, or -1 if it is not present. The array is
856    /// searched backwards, starting at fromIndex.
857    ///
858    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
859    #[wasm_bindgen(method, js_name = lastIndexOf)]
860    pub fn last_index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
861
862    /// The length property of an object which is an instance of type Array
863    /// sets or returns the number of elements in that array. The value is an
864    /// unsigned, 32-bit integer that is always numerically greater than the
865    /// highest index in the array.
866    ///
867    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
868    #[wasm_bindgen(method, getter)]
869    pub fn length<T>(this: &Array<T>) -> u32;
870
871    /// Sets the length of the array.
872    ///
873    /// If it is set to less than the current length of the array, it will
874    /// shrink the array.
875    ///
876    /// If it is set to more than the current length of the array, it will
877    /// increase the length of the array, filling the new space with empty
878    /// slots.
879    ///
880    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
881    #[wasm_bindgen(method, setter)]
882    pub fn set_length<T>(this: &Array<T>, value: u32);
883
884    /// `map()` calls a provided callback function once for each element in an array,
885    /// in order, and constructs a new array from the results. callback is invoked
886    /// only for indexes of the array which have assigned values, including undefined.
887    /// It is not called for missing elements of the array (that is, indexes that have
888    /// never been set, which have been deleted or which have never been assigned a value).
889    ///
890    /// **Note:** Consider using [`Array::try_map`] for safer fallible handling.
891    ///
892    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
893    #[wasm_bindgen(method)]
894    pub fn map<T, U>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> U)
895        -> Array<U>;
896
897    /// `map()` calls a provided callback function once for each element in an array,
898    /// in order, and constructs a new array from the results. callback is invoked
899    /// only for indexes of the array which have assigned values, including undefined.
900    /// It is not called for missing elements of the array (that is, indexes that have
901    /// never been set, which have been deleted or which have never been assigned a value).
902    /// _(Fallible variation)_
903    ///
904    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
905    #[wasm_bindgen(method, js_name = map, catch)]
906    pub fn try_map<'a, T, U>(
907        this: &Array<T>,
908        predicate: &ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<U, JsError> + 'a>,
909    ) -> Result<Array<U>, JsValue>;
910
911    /// The `Array.of()` method creates a new Array instance with a variable
912    /// number of arguments, regardless of number or type of the arguments.
913    ///
914    /// The difference between `Array.of()` and the `Array` constructor is in the
915    /// handling of integer arguments: `Array.of(7)` creates an array with a single
916    /// element, `7`, whereas `Array(7)` creates an empty array with a `length`
917    /// property of `7` (Note: this implies an array of 7 empty slots, not slots
918    /// with actual undefined values).
919    ///
920    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
921    #[wasm_bindgen(static_method_of = Array, js_name = of, variadic)]
922    pub fn of<T>(values: &[T]) -> Array<T>;
923
924    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
925    #[wasm_bindgen(static_method_of = Array, js_name = of)]
926    pub fn of1<T>(a: &T) -> Array<T>;
927
928    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
929    #[wasm_bindgen(static_method_of = Array, js_name = of)]
930    pub fn of2<T>(a: &T, b: &T) -> Array<T>;
931
932    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
933    #[wasm_bindgen(static_method_of = Array, js_name = of)]
934    pub fn of3<T>(a: &T, b: &T, c: &T) -> Array<T>;
935
936    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
937    #[wasm_bindgen(static_method_of = Array, js_name = of)]
938    pub fn of4<T>(a: &T, b: &T, c: &T, d: &T) -> Array<T>;
939
940    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
941    #[wasm_bindgen(static_method_of = Array, js_name = of)]
942    pub fn of5<T>(a: &T, b: &T, c: &T, d: &T, e: &T) -> Array<T>;
943
944    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
945    #[wasm_bindgen(static_method_of = Array, js_name = of)]
946    pub fn of6<T>(a: &T, b: &T, c: &T, d: &T, e: &T, f: &T) -> Array<T>;
947
948    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
949    #[wasm_bindgen(static_method_of = Array, js_name = of)]
950    pub fn of7<T>(a: &T, b: &T, c: &T, d: &T, e: &T, f: &T, g: &T) -> Array<T>;
951
952    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
953    #[wasm_bindgen(static_method_of = Array, js_name = of)]
954    pub fn of8<T>(a: &T, b: &T, c: &T, d: &T, e: &T, f: &T, g: &T, h: &T) -> Array<T>;
955
956    /// The `pop()` method removes the last element from an array and returns that
957    /// element. This method changes the length of the array.
958    ///
959    /// **Note:** Consider using [`Array::pop_checked`] for handling empty arrays.
960    ///
961    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
962    #[cfg(not(js_sys_unstable_apis))]
963    #[wasm_bindgen(method)]
964    pub fn pop<T>(this: &Array<T>) -> T;
965
966    /// The `pop()` method removes the last element from an array and returns that
967    /// element. This method changes the length of the array.
968    /// Returns `None` if the array is empty.
969    ///
970    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
971    #[cfg(js_sys_unstable_apis)]
972    #[wasm_bindgen(method)]
973    pub fn pop<T>(this: &Array<T>) -> Option<T>;
974
975    // Next major: deprecate
976    /// The `pop()` method removes the last element from an array and returns that
977    /// element. This method changes the length of the array.
978    ///
979    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
980    #[wasm_bindgen(method, js_name = pop)]
981    pub fn pop_checked<T>(this: &Array<T>) -> Option<T>;
982
983    /// The `push()` method adds one element to the end of an array and
984    /// returns the new length of the array.
985    ///
986    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
987    #[wasm_bindgen(method)]
988    pub fn push<T>(this: &Array<T>, value: &T) -> u32;
989
990    /// The `push()` method adds one or more elements to the end of an array and
991    /// returns the new length of the array.
992    ///
993    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
994    #[wasm_bindgen(method, js_name = push, variadic)]
995    pub fn push_many<T>(this: &Array<T>, values: &[T]) -> u32;
996
997    /// The `reduce()` method applies a function against an accumulator and each element in
998    /// the array (from left to right) to reduce it to a single value.
999    ///
1000    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1001    #[cfg(not(js_sys_unstable_apis))]
1002    #[wasm_bindgen(method)]
1003    pub fn reduce<T>(
1004        this: &Array<T>,
1005        predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
1006        initial_value: &JsValue,
1007    ) -> JsValue;
1008
1009    /// The `reduce()` method applies a function against an accumulator and each element in
1010    /// the array (from left to right) to reduce it to a single value.
1011    ///
1012    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1013    #[cfg(js_sys_unstable_apis)]
1014    #[wasm_bindgen(method)]
1015    pub fn reduce<'a, T, A>(
1016        this: &Array<T>,
1017        predicate: &ImmediateClosure<'a, dyn FnMut(A, T, u32, Array<T>) -> A + 'a>,
1018        initial_value: &A,
1019    ) -> A;
1020
1021    /// The `reduce()` method applies a function against an accumulator and each element in
1022    /// the array (from left to right) to reduce it to a single value. _(Fallible variation)_
1023    ///
1024    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1025    #[wasm_bindgen(method, js_name = reduce, catch)]
1026    pub fn try_reduce<'a, T, A>(
1027        this: &Array<T>,
1028        predicate: &ImmediateClosure<'a, dyn FnMut(A, T, u32) -> Result<A, JsError> + 'a>,
1029        initial_value: &A,
1030    ) -> Result<A, JsValue>;
1031
1032    /// The `reduceRight()` method applies a function against an accumulator and each value
1033    /// of the array (from right-to-left) to reduce it to a single value.
1034    ///
1035    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1036    #[cfg(not(js_sys_unstable_apis))]
1037    #[wasm_bindgen(method, js_name = reduceRight)]
1038    pub fn reduce_right<T>(
1039        this: &Array<T>,
1040        predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
1041        initial_value: &JsValue,
1042    ) -> JsValue;
1043
1044    /// The `reduceRight()` method applies a function against an accumulator and each value
1045    /// of the array (from right-to-left) to reduce it to a single value.
1046    ///
1047    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1048    #[cfg(js_sys_unstable_apis)]
1049    #[wasm_bindgen(method, js_name = reduceRight)]
1050    pub fn reduce_right<'a, T, A>(
1051        this: &Array<T>,
1052        predicate: &ImmediateClosure<'a, dyn FnMut(A, T, u32, Array<T>) -> A + 'a>,
1053        initial_value: &A,
1054    ) -> A;
1055
1056    /// The `reduceRight()` method applies a function against an accumulator and each value
1057    /// of the array (from right-to-left) to reduce it to a single value. _(Fallible variation)_
1058    ///
1059    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1060    #[wasm_bindgen(method, js_name = reduceRight, catch)]
1061    pub fn try_reduce_right<'a, T, A>(
1062        this: &Array<T>,
1063        predicate: &ImmediateClosure<'a, dyn FnMut(JsValue, T, u32) -> Result<A, JsError> + 'a>,
1064        initial_value: &A,
1065    ) -> Result<A, JsValue>;
1066
1067    /// The `reverse()` method reverses an array in place. The first array
1068    /// element becomes the last, and the last array element becomes the first.
1069    ///
1070    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
1071    #[wasm_bindgen(method)]
1072    pub fn reverse<T>(this: &Array<T>) -> Array<T>;
1073
1074    /// The `shift()` method removes the first element from an array and returns
1075    /// that removed element. This method changes the length of the array.
1076    ///
1077    /// **Note:** Consider using [`Array::shift_checked`] for handling empty arrays.
1078    ///
1079    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1080    #[cfg(not(js_sys_unstable_apis))]
1081    #[wasm_bindgen(method)]
1082    pub fn shift<T>(this: &Array<T>) -> T;
1083
1084    /// The `shift()` method removes the first element from an array and returns
1085    /// that removed element. This method changes the length of the array.
1086    /// Returns `None` if the array is empty.
1087    ///
1088    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1089    #[cfg(js_sys_unstable_apis)]
1090    #[wasm_bindgen(method)]
1091    pub fn shift<T>(this: &Array<T>) -> Option<T>;
1092
1093    // Next major: deprecate
1094    /// The `shift()` method removes the first element from an array and returns
1095    /// that removed element. This method changes the length of the array.
1096    ///
1097    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1098    #[wasm_bindgen(method, js_name = shift)]
1099    pub fn shift_checked<T>(this: &Array<T>) -> Option<T>;
1100
1101    /// The `slice()` method returns a shallow copy of a portion of an array into
1102    /// a new array object selected from begin to end (end not included).
1103    /// The original array will not be modified.
1104    ///
1105    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1106    #[cfg(not(js_sys_unstable_apis))]
1107    #[wasm_bindgen(method)]
1108    pub fn slice<T>(this: &Array<T>, start: u32, end: u32) -> Array<T>;
1109
1110    /// The `slice()` method returns a shallow copy of a portion of an array into
1111    /// a new array object selected from begin to end (end not included).
1112    /// The original array will not be modified. Negative indices count from the end.
1113    ///
1114    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1115    #[cfg(js_sys_unstable_apis)]
1116    #[wasm_bindgen(method)]
1117    pub fn slice<T>(this: &Array<T>, start: i32, end: i32) -> Array<T>;
1118
1119    /// The `slice()` method returns a shallow copy of a portion of an array into
1120    /// a new array object selected from the given index to the end.
1121    /// The original array will not be modified.
1122    ///
1123    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1124    #[cfg(not(js_sys_unstable_apis))]
1125    #[wasm_bindgen(method, js_name = slice)]
1126    pub fn slice_from<T>(this: &Array<T>, start: u32) -> Array<T>;
1127
1128    /// The `slice()` method returns a shallow copy of a portion of an array into
1129    /// a new array object selected from the given index to the end.
1130    /// The original array will not be modified. Negative indices count from the end.
1131    ///
1132    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1133    #[cfg(js_sys_unstable_apis)]
1134    #[wasm_bindgen(method, js_name = slice)]
1135    pub fn slice_from<T>(this: &Array<T>, start: i32) -> Array<T>;
1136
1137    /// The `some()` method tests whether at least one element in the array passes the test implemented
1138    /// by the provided function.
1139    /// Note: This method returns false for any condition put on an empty array.
1140    ///
1141    /// **Note:** Consider using [`Array::try_some`] if the predicate might throw an error.
1142    ///
1143    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1144    #[wasm_bindgen(method)]
1145    pub fn some<T>(this: &Array<T>, predicate: &mut dyn FnMut(T) -> bool) -> bool;
1146
1147    /// The `some()` method tests whether at least one element in the array passes the test implemented
1148    /// by the provided function. _(Fallible variation)_
1149    /// Note: This method returns false for any condition put on an empty array.
1150    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1151    #[wasm_bindgen(method, js_name = some, catch)]
1152    pub fn try_some<'a, T>(
1153        this: &Array<T>,
1154        predicate: &ImmediateClosure<'a, dyn FnMut(T) -> Result<bool, JsError> + 'a>,
1155    ) -> Result<bool, JsValue>;
1156
1157    /// The `sort()` method sorts the elements of an array in place and returns
1158    /// the array. The sort is not necessarily stable. The default sort
1159    /// order is according to string Unicode code points.
1160    ///
1161    /// The time and space complexity of the sort cannot be guaranteed as it
1162    /// is implementation dependent.
1163    ///
1164    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1165    #[wasm_bindgen(method)]
1166    pub fn sort<T>(this: &Array<T>) -> Array<T>;
1167
1168    /// The `sort()` method with a custom compare function.
1169    ///
1170    /// **Note:** Consider using [`Array::try_sort_by`] if the predicate might throw an error.
1171    ///
1172    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1173    #[wasm_bindgen(method, js_name = sort)]
1174    pub fn sort_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1175
1176    /// The `sort()` method with a custom compare function. _(Fallible variation)_
1177    ///
1178    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1179    #[wasm_bindgen(method, js_name = sort, catch)]
1180    pub fn try_sort_by<'a, T>(
1181        this: &Array<T>,
1182        compare_fn: &ImmediateClosure<'a, dyn FnMut(T, T) -> Result<i32, JsError> + 'a>,
1183    ) -> Result<Array<T>, JsValue>;
1184
1185    /// The `splice()` method changes the contents of an array by removing existing elements and/or
1186    /// adding new elements.
1187    ///
1188    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1189    #[wasm_bindgen(method)]
1190    pub fn splice<T>(this: &Array<T>, start: u32, delete_count: u32, item: &T) -> Array<T>;
1191
1192    /// The `splice()` method changes the contents of an array by removing existing elements and/or
1193    /// adding new elements.
1194    ///
1195    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1196    #[wasm_bindgen(method, js_name = splice, variadic)]
1197    pub fn splice_many<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1198
1199    /// The `toLocaleString()` method returns a string representing the elements of the array.
1200    /// The elements are converted to Strings using their toLocaleString methods and these
1201    /// Strings are separated by a locale-specific String (such as a comma ",").
1202    ///
1203    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1204    #[cfg(not(js_sys_unstable_apis))]
1205    #[wasm_bindgen(method, js_name = toLocaleString)]
1206    pub fn to_locale_string<T>(this: &Array<T>, locales: &JsValue, options: &JsValue) -> JsString;
1207
1208    /// The `toLocaleString()` method returns a string representing the elements of the array.
1209    /// The elements are converted to Strings using their toLocaleString methods and these
1210    /// Strings are separated by a locale-specific String (such as a comma ",").
1211    ///
1212    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1213    #[cfg(js_sys_unstable_apis)]
1214    #[wasm_bindgen(method, js_name = toLocaleString)]
1215    pub fn to_locale_string<T>(
1216        this: &Array<T>,
1217        locales: &[JsString],
1218        options: &Intl::NumberFormatOptions,
1219    ) -> JsString;
1220
1221    /// The `toReversed()` method returns a new array with the elements in reversed order,
1222    /// without modifying the original array.
1223    ///
1224    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed)
1225    #[wasm_bindgen(method, js_name = toReversed)]
1226    pub fn to_reversed<T>(this: &Array<T>) -> Array<T>;
1227
1228    /// The `toSorted()` method returns a new array with the elements sorted in ascending order,
1229    /// without modifying the original array.
1230    ///
1231    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1232    #[wasm_bindgen(method, js_name = toSorted)]
1233    pub fn to_sorted<T>(this: &Array<T>) -> Array<T>;
1234
1235    /// The `toSorted()` method with a custom compare function.
1236    ///
1237    /// **Note:** Consider using [`Array::try_to_sorted_by`] if the predicate might throw an error.
1238    ///
1239    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1240    #[wasm_bindgen(method, js_name = toSorted)]
1241    pub fn to_sorted_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1242
1243    /// The `toSorted()` method with a custom compare function. _(Fallible variation)_
1244    ///
1245    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1246    #[wasm_bindgen(method, js_name = toSorted, catch)]
1247    pub fn try_to_sorted_by<'a, T>(
1248        this: &Array<T>,
1249        compare_fn: &ImmediateClosure<'a, dyn FnMut(T, T) -> Result<i32, JsError> + 'a>,
1250    ) -> Result<Array<T>, JsValue>;
1251
1252    /// The `toSpliced()` method returns a new array with some elements removed and/or
1253    /// replaced at a given index, without modifying the original array.
1254    ///
1255    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced)
1256    #[wasm_bindgen(method, js_name = toSpliced, variadic)]
1257    pub fn to_spliced<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1258
1259    /// The `toString()` method returns a string representing the specified array
1260    /// and its elements.
1261    ///
1262    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)
1263    #[cfg(not(js_sys_unstable_apis))]
1264    #[wasm_bindgen(method, js_name = toString)]
1265    pub fn to_string<T>(this: &Array<T>) -> JsString;
1266
1267    /// Converts the Array into a Vector.
1268    #[wasm_bindgen(method, js_name = slice)]
1269    pub fn to_vec<T>(this: &Array<T>) -> Vec<T>;
1270
1271    /// The `unshift()` method adds one element to the beginning of an
1272    /// array and returns the new length of the array.
1273    ///
1274    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1275    #[wasm_bindgen(method)]
1276    pub fn unshift<T>(this: &Array<T>, value: &T) -> u32;
1277
1278    /// The `unshift()` method adds one or more elements to the beginning of an
1279    /// array and returns the new length of the array.
1280    ///
1281    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1282    #[wasm_bindgen(method, js_name = unshift, variadic)]
1283    pub fn unshift_many<T>(this: &Array<T>, values: &[T]) -> u32;
1284
1285    /// The `with()` method returns a new array with the element at the given index
1286    /// replaced with the given value, without modifying the original array.
1287    ///
1288    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/with)
1289    #[wasm_bindgen(method, js_name = with)]
1290    pub fn with<T>(this: &Array<T>, index: u32, value: &T) -> Array<T>;
1291}
1292
1293// Tuples as a typed array variant
1294#[wasm_bindgen]
1295extern "C" {
1296    #[wasm_bindgen(extends = Object, js_name = Array, is_type_of = Array::is_array, no_upcast, typescript_type = "Array<any>")]
1297    #[derive(Clone, Debug)]
1298    pub type ArrayTuple<T: JsTuple = (JsValue,)>;
1299
1300    /// Creates a new JS array typed as a 1-tuple.
1301    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1302    pub fn new1<T1>(t1: &T1) -> ArrayTuple<(T1,)>;
1303
1304    /// Creates a new JS array typed as a 2-tuple.
1305    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1306    pub fn new2<T1, T2>(t1: &T1, t2: &T2) -> ArrayTuple<(T1, T2)>;
1307
1308    /// Creates a new JS array typed as a 3-tuple.
1309    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1310    pub fn new3<T1, T2, T3>(t1: &T1, t2: &T2, t3: &T3) -> ArrayTuple<(T1, T2, T3)>;
1311
1312    /// Creates a new JS array typed as a 4-tuple.
1313    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1314    pub fn new4<T1, T2, T3, T4>(t1: &T1, t2: &T2, t3: &T3, t4: &T4)
1315        -> ArrayTuple<(T1, T2, T3, T4)>;
1316
1317    /// Creates a new JS array typed as a 5-tuple.
1318    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1319    pub fn new5<T1, T2, T3, T4, T5>(
1320        t1: &T1,
1321        t2: &T2,
1322        t3: &T3,
1323        t4: &T4,
1324        t5: &T5,
1325    ) -> ArrayTuple<(T1, T2, T3, T4, T5)>;
1326
1327    /// Creates a new JS array typed as a 6-tuple.
1328    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1329    pub fn new6<T1, T2, T3, T4, T5, T6>(
1330        t1: &T1,
1331        t2: &T2,
1332        t3: &T3,
1333        t4: &T4,
1334        t5: &T5,
1335        t6: &T6,
1336    ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6)>;
1337
1338    /// Creates a new JS array typed as a 7-tuple.
1339    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1340    pub fn new7<T1, T2, T3, T4, T5, T6, T7>(
1341        t1: &T1,
1342        t2: &T2,
1343        t3: &T3,
1344        t4: &T4,
1345        t5: &T5,
1346        t6: &T6,
1347        t7: &T7,
1348    ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7)>;
1349
1350    /// Creates a new JS array typed as a 8-tuple.
1351    #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1352    pub fn new8<T1, T2, T3, T4, T5, T6, T7, T8>(
1353        t1: &T1,
1354        t2: &T2,
1355        t3: &T3,
1356        t4: &T4,
1357        t5: &T5,
1358        t6: &T6,
1359        t7: &T7,
1360        t8: &T8,
1361    ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7, T8)>;
1362
1363    /// Gets the 1st item
1364    #[wasm_bindgen(
1365        method,
1366        js_class = Array,
1367        getter,
1368        js_name = "0"
1369    )]
1370    pub fn get0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>) -> <T as JsTuple1>::T1;
1371
1372    /// Gets the 2nd item
1373    #[wasm_bindgen(
1374        method,
1375        js_class = Array,
1376        getter,
1377        js_name = "1"
1378    )]
1379    pub fn get1<T: JsTuple2 = (JsValue, JsValue)>(this: &ArrayTuple<T>) -> <T as JsTuple2>::T2;
1380
1381    /// Gets the 3rd item
1382    #[wasm_bindgen(
1383        method,
1384        js_class = Array,
1385        getter,
1386        js_name = "2"
1387    )]
1388    pub fn get2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1389        this: &ArrayTuple<T>,
1390    ) -> <T as JsTuple3>::T3;
1391
1392    /// Gets the 4th item
1393    #[wasm_bindgen(
1394        method,
1395        js_class = Array,
1396        getter,
1397        js_name = "3"
1398    )]
1399    pub fn get3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1400        this: &ArrayTuple<T>,
1401    ) -> <T as JsTuple4>::T4;
1402
1403    /// Gets the 5th item
1404    #[wasm_bindgen(
1405        method,
1406        js_class = Array,
1407        getter,
1408        js_name = "4"
1409    )]
1410    pub fn get4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1411        this: &ArrayTuple<T>,
1412    ) -> <T as JsTuple5>::T5;
1413
1414    /// Gets the 6th item
1415    #[wasm_bindgen(
1416        method,
1417        js_class = Array,
1418        getter,
1419        js_name = "5"
1420    )]
1421    pub fn get5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1422        this: &ArrayTuple<T>,
1423    ) -> <T as JsTuple6>::T6;
1424
1425    /// Gets the 7th item
1426    #[wasm_bindgen(
1427        method,
1428        js_class = Array,
1429        getter,
1430        js_name = "6"
1431    )]
1432    pub fn get6<
1433        T: JsTuple7 = (
1434            JsValue,
1435            JsValue,
1436            JsValue,
1437            JsValue,
1438            JsValue,
1439            JsValue,
1440            JsValue,
1441        ),
1442    >(
1443        this: &ArrayTuple<T>,
1444    ) -> <T as JsTuple7>::T7;
1445
1446    /// Gets the 8th item
1447    #[wasm_bindgen(
1448        method,
1449        js_class = Array,
1450        getter,
1451        js_name = "7"
1452    )]
1453    pub fn get7<
1454        T: JsTuple8 = (
1455            JsValue,
1456            JsValue,
1457            JsValue,
1458            JsValue,
1459            JsValue,
1460            JsValue,
1461            JsValue,
1462            JsValue,
1463        ),
1464    >(
1465        this: &ArrayTuple<T>,
1466    ) -> <T as JsTuple8>::T8;
1467
1468    /// Sets the 1st item
1469    #[wasm_bindgen(
1470        method,
1471        js_class = Array,
1472        setter,
1473        js_name = "0"
1474    )]
1475    pub fn set0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>, value: &<T as JsTuple1>::T1);
1476
1477    /// Sets the 2nd item
1478    #[wasm_bindgen(
1479        method,
1480        js_class = Array,
1481        setter,
1482        js_name = "1"
1483    )]
1484    pub fn set1<T: JsTuple2 = (JsValue, JsValue)>(
1485        this: &ArrayTuple<T>,
1486        value: &<T as JsTuple2>::T2,
1487    );
1488
1489    /// Sets the 3rd item
1490    #[wasm_bindgen(
1491        method,
1492        js_class = Array,
1493        setter,
1494        js_name = "2"
1495    )]
1496    pub fn set2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1497        this: &ArrayTuple<T>,
1498        value: &<T as JsTuple3>::T3,
1499    );
1500
1501    /// Sets the 4th item
1502    #[wasm_bindgen(
1503        method,
1504        js_class = Array,
1505        setter,
1506        js_name = "3"
1507    )]
1508    pub fn set3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1509        this: &ArrayTuple<T>,
1510        value: &<T as JsTuple4>::T4,
1511    );
1512
1513    /// Sets the 5th item
1514    #[wasm_bindgen(
1515        method,
1516        js_class = Array,
1517        setter,
1518        js_name = "4"
1519    )]
1520    pub fn set4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1521        this: &ArrayTuple<T>,
1522        value: &<T as JsTuple5>::T5,
1523    );
1524
1525    /// Sets the 6th item
1526    #[wasm_bindgen(
1527        method,
1528        js_class = Array,
1529        setter,
1530        js_name = "5"
1531    )]
1532    pub fn set5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1533        this: &ArrayTuple<T>,
1534        value: &<T as JsTuple6>::T6,
1535    );
1536
1537    /// Sets the 7th item
1538    #[wasm_bindgen(
1539        method,
1540        js_class = Array,
1541        setter,
1542        js_name = "6"
1543    )]
1544    pub fn set6<
1545        T: JsTuple7 = (
1546            JsValue,
1547            JsValue,
1548            JsValue,
1549            JsValue,
1550            JsValue,
1551            JsValue,
1552            JsValue,
1553        ),
1554    >(
1555        this: &ArrayTuple<T>,
1556        value: &<T as JsTuple7>::T7,
1557    );
1558
1559    /// Sets the 8th item
1560    #[wasm_bindgen(
1561        method,
1562        js_class = Array,
1563        setter,
1564        js_name = "7"
1565    )]
1566    pub fn set7<
1567        T: JsTuple8 = (
1568            JsValue,
1569            JsValue,
1570            JsValue,
1571            JsValue,
1572            JsValue,
1573            JsValue,
1574            JsValue,
1575            JsValue,
1576        ),
1577    >(
1578        this: &ArrayTuple<T>,
1579        value: &<T as JsTuple8>::T8,
1580    );
1581}
1582
1583/// Base trait for tuple types.
1584pub trait JsTuple {
1585    const ARITY: usize;
1586}
1587
1588macro_rules! impl_tuple_traits {
1589    // Base case: first trait has no parent (besides JsTuple)
1590    ($name:ident $ty:tt) => {
1591        pub trait $name: JsTuple {
1592            type $ty;
1593        }
1594    };
1595
1596    // Recursive case: define trait with parent, then recurse
1597    ($name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1598        pub trait $name: JsTuple {
1599            type $ty;
1600        }
1601
1602        impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1603    };
1604
1605    // Internal: traits that have a parent
1606    (@with_parent $trait:ident $name:ident $ty:tt) => {
1607        pub trait $name: $trait {
1608            type $ty;
1609        }
1610    };
1611
1612    (@with_parent $trait:ident $name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1613        pub trait $name: $trait {
1614            type $ty;
1615        }
1616
1617        impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1618    };
1619}
1620
1621macro_rules! impl_parent_traits {
1622    ([$($types:tt),+] [] []) => {};
1623
1624    ([$($types:tt),+] [$trait:ident $($rest_traits:ident)*] [$ty:tt $($rest_tys:tt)*]) => {
1625        impl<$($types),+> $trait for ($($types),+,) {
1626            type $ty = $ty;
1627        }
1628
1629        impl_parent_traits!([$($types),+] [$($rest_traits)*] [$($rest_tys)*]);
1630    };
1631}
1632
1633// Define the trait hierarchy once
1634impl_tuple_traits!(
1635    JsTuple1 T1
1636    JsTuple2 T2
1637    JsTuple3 T3
1638    JsTuple4 T4
1639    JsTuple5 T5
1640    JsTuple6 T6
1641    JsTuple7 T7
1642    JsTuple8 T8
1643);
1644
1645impl<T: JsTuple> ArrayTuple<T> {
1646    /// Get the static arity of the ArrayTuple type.
1647    #[allow(clippy::len_without_is_empty)]
1648    pub fn len(&self) -> usize {
1649        <T as JsTuple>::ARITY
1650    }
1651}
1652
1653macro_rules! impl_tuple {
1654    ($arity:literal [$($traits:ident)*] [$($T:tt)+] [$($vars:tt)+] $new:ident $last:ident $last_ty:tt) => {
1655        impl<$($T),+> JsTuple for ($($T),+,) {
1656            const ARITY: usize = $arity;
1657        }
1658
1659        impl_parent_traits!([$($T),+] [$($traits)*] [$($T)*]);
1660
1661        impl<$($T: JsGeneric),+> From<($($T,)+)> for ArrayTuple<($($T),+,)> {
1662            fn from(($($vars,)+): ($($T,)+)) -> Self {
1663                let arr = [$(
1664                    unsafe { core::mem::transmute_copy::<$T, JsValue>(&$vars) }
1665                ),+];
1666                core::mem::forget(($($vars,)+));
1667                Array::of(&arr).unchecked_into()
1668            }
1669        }
1670
1671        impl<$($T: JsGeneric + Default),+> Default for ArrayTuple<($($T),+,)> {
1672            fn default() -> Self {
1673                $(
1674                    let $vars: $T = Default::default();
1675                )+
1676                let arr = [$(
1677                    unsafe { core::mem::transmute_copy::<$T, JsValue>(&$vars) }
1678                ),+];
1679                core::mem::forget(($($vars,)+));
1680                Array::of(&arr).unchecked_into()
1681            }
1682        }
1683
1684        impl<$($T: JsGeneric),+> ArrayTuple<($($T),+,)> {
1685            /// Get the first element of the ArrayTuple
1686            pub fn first(&self) -> T1 {
1687                self.get0()
1688            }
1689
1690            /// Get the last element of the ArrayTuple
1691            pub fn last(&self) -> $last_ty {
1692                self.$last()
1693            }
1694
1695            /// Convert the ArrayTuple into its corresponding Rust tuple
1696            pub fn into_parts(self) -> ($($T,)+) {
1697                ($(self.$vars(),)+)
1698            }
1699
1700            /// Create a new ArrayTuple from the corresponding parts.
1701            ///
1702            /// # Example
1703            ///
1704            /// ```
1705            /// use js_sys::{ArrayTuple, JsString};
1706            ///
1707            /// let tuple = ArrayTuple::<JsString, JsString>::new(&"a".into(), &"b".into());
1708            /// ```
1709            ///
1710            /// Note: You must specify the T using `::<...>` syntax on `ArrayTuple`.
1711            /// Alternatively, use `new1`, `new2`, etc. for type inference from the left-hand side.
1712            pub fn new($($vars: &$T),+) -> ArrayTuple<($($T),+,)> {
1713                ArrayTuple::$new($($vars),+)
1714            }
1715        }
1716    };
1717}
1718
1719// Implement for each tuple size
1720impl_tuple!(1 [JsTuple1] [T1] [get0] new1 get0 T1);
1721impl_tuple!(2 [JsTuple1 JsTuple2] [T1 T2] [get0 get1] new2 get1 T2);
1722impl_tuple!(3 [JsTuple1 JsTuple2 JsTuple3] [T1 T2 T3] [get0 get1 get2] new3 get2 T3);
1723impl_tuple!(4 [JsTuple1 JsTuple2 JsTuple3 JsTuple4] [T1 T2 T3 T4] [get0 get1 get2 get3] new4 get3 T4);
1724impl_tuple!(5 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5] [T1 T2 T3 T4 T5] [get0 get1 get2 get3 get4] new5 get4 T5);
1725impl_tuple!(6 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5 JsTuple6] [T1 T2 T3 T4 T5 T6] [get0 get1 get2 get3 get4 get5] new6 get5 T6);
1726impl_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);
1727impl_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);
1728
1729// Macro to generate structural covariance impls for each arity
1730macro_rules! impl_tuple_covariance {
1731    ([$($T:ident)+] [$($Target:ident)+] [$($Ts:ident)+]) => {
1732        // ArrayTuple -> Array
1733        // Allows (T1, T2, ...) to be used where (Target) is expected
1734        // when all T1, T2, ... are covariant to Target
1735        impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for Array<Target>
1736        where
1737            $(Target: UpcastFrom<$T>,)+
1738        {
1739        }
1740        impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for JsOption<Array<Target>>
1741        where
1742            $(Target: UpcastFrom<$T>,)+
1743        {}
1744        // Array<T> -> ArrayTuple<T, ...>
1745        impl<T> UpcastFrom<Array<T>> for ArrayTuple<($($Ts,)+)> {}
1746        impl<T: JsGeneric> UpcastFrom<Array<T>> for ArrayTuple<($(JsOption<$Ts>,)+)> {}
1747    };
1748}
1749
1750impl_tuple_covariance!([T1][Target1][T]);
1751impl_tuple_covariance!([T1 T2] [Target1 Target2] [T T]);
1752impl_tuple_covariance!([T1 T2 T3] [Target1 Target2 Target3] [T T T]);
1753impl_tuple_covariance!([T1 T2 T3 T4] [Target1 Target2 Target3 Target4] [T T T T]);
1754impl_tuple_covariance!([T1 T2 T3 T4 T5] [Target1 Target2 Target3 Target4 Target5] [T T T T T]);
1755impl_tuple_covariance!([T1 T2 T3 T4 T5 T6] [Target1 Target2 Target3 Target4 Target5 Target6] [T T T T T T]);
1756impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7] [Target1 Target2 Target3 Target4 Target5 Target6 Target7] [T T T T T T T]);
1757impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7 T8] [Target1 Target2 Target3 Target4 Target5 Target6 Target7 Target8] [T T T T T T T T]);
1758
1759// Tuple casting is implemented in core
1760impl<T: JsTuple, U: JsTuple> UpcastFrom<ArrayTuple<T>> for ArrayTuple<U> where U: UpcastFrom<T> {}
1761impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsValue {}
1762impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsOption<JsValue> {}
1763
1764/// Iterator returned by `Array::into_iter`
1765#[derive(Debug, Clone)]
1766pub struct ArrayIntoIter<T: JsGeneric> {
1767    range: core::ops::Range<u32>,
1768    array: Array<T>,
1769}
1770
1771#[cfg(not(js_sys_unstable_apis))]
1772impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1773    type Item = T;
1774
1775    fn next(&mut self) -> Option<Self::Item> {
1776        let index = self.range.next()?;
1777        Some(self.array.get(index))
1778    }
1779
1780    #[inline]
1781    fn size_hint(&self) -> (usize, Option<usize>) {
1782        self.range.size_hint()
1783    }
1784
1785    #[inline]
1786    fn count(self) -> usize
1787    where
1788        Self: Sized,
1789    {
1790        self.range.count()
1791    }
1792
1793    #[inline]
1794    fn last(self) -> Option<Self::Item>
1795    where
1796        Self: Sized,
1797    {
1798        let Self { range, array } = self;
1799        range.last().map(|index| array.get(index))
1800    }
1801
1802    #[inline]
1803    fn nth(&mut self, n: usize) -> Option<Self::Item> {
1804        self.range.nth(n).map(|index| self.array.get(index))
1805    }
1806}
1807
1808#[cfg(js_sys_unstable_apis)]
1809impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1810    type Item = T;
1811
1812    fn next(&mut self) -> Option<Self::Item> {
1813        let index = self.range.next()?;
1814        self.array.get(index)
1815    }
1816
1817    #[inline]
1818    fn size_hint(&self) -> (usize, Option<usize>) {
1819        self.range.size_hint()
1820    }
1821
1822    #[inline]
1823    fn count(self) -> usize
1824    where
1825        Self: Sized,
1826    {
1827        self.range.count()
1828    }
1829
1830    #[inline]
1831    fn last(self) -> Option<Self::Item>
1832    where
1833        Self: Sized,
1834    {
1835        let Self { range, array } = self;
1836        range.last().and_then(|index| array.get(index))
1837    }
1838
1839    #[inline]
1840    fn nth(&mut self, n: usize) -> Option<Self::Item> {
1841        self.range.nth(n).and_then(|index| self.array.get(index))
1842    }
1843}
1844
1845#[cfg(not(js_sys_unstable_apis))]
1846impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1847    fn next_back(&mut self) -> Option<Self::Item> {
1848        let index = self.range.next_back()?;
1849        Some(self.array.get(index))
1850    }
1851
1852    fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1853        self.range.nth_back(n).map(|index| self.array.get(index))
1854    }
1855}
1856
1857#[cfg(js_sys_unstable_apis)]
1858impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1859    fn next_back(&mut self) -> Option<Self::Item> {
1860        let index = self.range.next_back()?;
1861        self.array.get(index)
1862    }
1863
1864    fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1865        self.range
1866            .nth_back(n)
1867            .and_then(|index| self.array.get(index))
1868    }
1869}
1870
1871impl<T: JsGeneric> core::iter::FusedIterator for ArrayIntoIter<T> {}
1872
1873impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIntoIter<T> {}
1874
1875/// Iterator returned by `Array::iter`
1876#[derive(Debug, Clone)]
1877pub struct ArrayIter<'a, T: JsGeneric> {
1878    range: core::ops::Range<u32>,
1879    array: &'a Array<T>,
1880}
1881
1882impl<T: JsGeneric> core::iter::Iterator for ArrayIter<'_, T> {
1883    type Item = T;
1884
1885    fn next(&mut self) -> Option<Self::Item> {
1886        let index = self.range.next()?;
1887        Some(self.array.get_unchecked(index))
1888    }
1889
1890    #[inline]
1891    fn size_hint(&self) -> (usize, Option<usize>) {
1892        self.range.size_hint()
1893    }
1894
1895    #[inline]
1896    fn count(self) -> usize
1897    where
1898        Self: Sized,
1899    {
1900        self.range.count()
1901    }
1902
1903    #[inline]
1904    fn last(self) -> Option<Self::Item>
1905    where
1906        Self: Sized,
1907    {
1908        let Self { range, array } = self;
1909        range.last().map(|index| array.get_unchecked(index))
1910    }
1911
1912    #[inline]
1913    fn nth(&mut self, n: usize) -> Option<Self::Item> {
1914        self.range
1915            .nth(n)
1916            .map(|index| self.array.get_unchecked(index))
1917    }
1918}
1919
1920impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIter<'_, T> {
1921    fn next_back(&mut self) -> Option<Self::Item> {
1922        let index = self.range.next_back()?;
1923        Some(self.array.get_unchecked(index))
1924    }
1925
1926    fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1927        self.range
1928            .nth_back(n)
1929            .map(|index| self.array.get_unchecked(index))
1930    }
1931}
1932
1933impl<T: JsGeneric> core::iter::FusedIterator for ArrayIter<'_, T> {}
1934
1935impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIter<'_, T> {}
1936
1937impl<T: JsGeneric> Array<T> {
1938    /// Returns an iterator over the values of the JS array.
1939    pub fn iter(&self) -> ArrayIter<'_, T> {
1940        ArrayIter {
1941            range: 0..self.length(),
1942            array: self,
1943        }
1944    }
1945}
1946
1947impl<T: JsGeneric> core::iter::IntoIterator for Array<T> {
1948    type Item = T;
1949    type IntoIter = ArrayIntoIter<T>;
1950
1951    fn into_iter(self) -> Self::IntoIter {
1952        ArrayIntoIter {
1953            range: 0..self.length(),
1954            array: self,
1955        }
1956    }
1957}
1958
1959#[cfg(not(js_sys_unstable_apis))]
1960impl<A, T: JsGeneric> core::iter::FromIterator<A> for Array<T>
1961where
1962    A: AsRef<T>,
1963{
1964    fn from_iter<I>(iter: I) -> Array<T>
1965    where
1966        I: IntoIterator<Item = A>,
1967    {
1968        let iter = iter.into_iter();
1969        let mut out = Array::new_typed();
1970        out.extend(iter);
1971        out
1972    }
1973}
1974
1975#[cfg(js_sys_unstable_apis)]
1976impl<A, T: JsGeneric> core::iter::FromIterator<A> for Array<T>
1977where
1978    A: AsRef<T>,
1979{
1980    fn from_iter<I>(iter: I) -> Array<T>
1981    where
1982        I: IntoIterator<Item = A>,
1983    {
1984        let iter = iter.into_iter();
1985        let (lower, upper) = iter.size_hint();
1986        let capacity = upper.unwrap_or(lower);
1987        let out = Array::new_with_length_typed(capacity as u32);
1988        let mut i = 0;
1989        for value in iter {
1990            out.set(i, value.as_ref());
1991            i += 1;
1992        }
1993        out
1994    }
1995}
1996
1997impl<A, T: JsGeneric> core::iter::Extend<A> for Array<T>
1998where
1999    A: AsRef<T>,
2000{
2001    fn extend<I>(&mut self, iter: I)
2002    where
2003        I: IntoIterator<Item = A>,
2004    {
2005        for value in iter {
2006            self.push(value.as_ref());
2007        }
2008    }
2009}
2010
2011impl Default for Array<JsValue> {
2012    fn default() -> Self {
2013        Self::new()
2014    }
2015}
2016
2017impl<T> Iterable for Array<T> {
2018    type Item = T;
2019}
2020
2021impl<T: JsTuple> Iterable for ArrayTuple<T> {
2022    type Item = JsValue;
2023}
2024
2025// ArrayBufferOptions
2026#[wasm_bindgen]
2027extern "C" {
2028    #[wasm_bindgen(extends = Object, typescript_type = "ArrayBufferOptions")]
2029    #[derive(Clone, Debug, PartialEq, Eq)]
2030    pub type ArrayBufferOptions;
2031
2032    /// The maximum size, in bytes, that the array buffer can be resized to.
2033    #[wasm_bindgen(method, setter, js_name = maxByteLength)]
2034    pub fn set_max_byte_length(this: &ArrayBufferOptions, max_byte_length: usize);
2035
2036    /// The maximum size, in bytes, that the array buffer can be resized to.
2037    #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2038    pub fn get_max_byte_length(this: &ArrayBufferOptions) -> usize;
2039}
2040
2041impl ArrayBufferOptions {
2042    #[cfg(not(js_sys_unstable_apis))]
2043    pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2044        let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::new());
2045        options.set_max_byte_length(max_byte_length);
2046        options
2047    }
2048
2049    #[cfg(js_sys_unstable_apis)]
2050    pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2051        let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::<JsValue>::new());
2052        options.set_max_byte_length(max_byte_length);
2053        options
2054    }
2055}
2056
2057// ArrayBuffer
2058#[wasm_bindgen]
2059extern "C" {
2060    #[wasm_bindgen(extends = Object, typescript_type = "ArrayBuffer")]
2061    #[derive(Clone, Debug, PartialEq, Eq)]
2062    pub type ArrayBuffer;
2063
2064    /// The `ArrayBuffer` object is used to represent a generic,
2065    /// fixed-length raw binary data buffer. You cannot directly
2066    /// manipulate the contents of an `ArrayBuffer`; instead, you
2067    /// create one of the typed array objects or a `DataView` object
2068    /// which represents the buffer in a specific format, and use that
2069    /// to read and write the contents of the buffer.
2070    ///
2071    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2072    #[cfg(not(js_sys_unstable_apis))]
2073    #[wasm_bindgen(constructor)]
2074    pub fn new(length: u32) -> ArrayBuffer;
2075
2076    /// The `ArrayBuffer` object is used to represent a generic,
2077    /// fixed-length raw binary data buffer. You cannot directly
2078    /// manipulate the contents of an `ArrayBuffer`; instead, you
2079    /// create one of the typed array objects or a `DataView` object
2080    /// which represents the buffer in a specific format, and use that
2081    /// to read and write the contents of the buffer.
2082    ///
2083    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2084    #[cfg(js_sys_unstable_apis)]
2085    #[wasm_bindgen(constructor)]
2086    pub fn new(length: usize) -> ArrayBuffer;
2087
2088    /// The `ArrayBuffer` object is used to represent a generic,
2089    /// fixed-length raw binary data buffer. You cannot directly
2090    /// manipulate the contents of an `ArrayBuffer`; instead, you
2091    /// create one of the typed array objects or a `DataView` object
2092    /// which represents the buffer in a specific format, and use that
2093    /// to read and write the contents of the buffer.
2094    ///
2095    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2096    #[wasm_bindgen(constructor)]
2097    pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> ArrayBuffer;
2098
2099    /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2100    /// it's an accessor property whose set accessor function is undefined,
2101    /// meaning that you can only read this property.
2102    /// The value is established when the array is constructed and cannot be changed.
2103    /// This property returns 0 if this ArrayBuffer has been detached.
2104    ///
2105    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2106    #[cfg(not(js_sys_unstable_apis))]
2107    #[wasm_bindgen(method, getter, js_name = byteLength)]
2108    pub fn byte_length(this: &ArrayBuffer) -> u32;
2109
2110    /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2111    /// it's an accessor property whose set accessor function is undefined,
2112    /// meaning that you can only read this property.
2113    /// The value is established when the array is constructed and cannot be changed.
2114    /// This property returns 0 if this ArrayBuffer has been detached.
2115    ///
2116    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2117    #[cfg(js_sys_unstable_apis)]
2118    #[wasm_bindgen(method, getter, js_name = byteLength)]
2119    pub fn byte_length(this: &ArrayBuffer) -> usize;
2120
2121    /// The `detached` accessor property of `ArrayBuffer` instances returns a boolean indicating
2122    /// whether or not this buffer has been detached (transferred).
2123    ///
2124    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/detached)
2125    #[wasm_bindgen(method, getter)]
2126    pub fn detached(this: &ArrayBuffer) -> bool;
2127
2128    /// The `isView()` method returns true if arg is one of the `ArrayBuffer`
2129    /// views, such as typed array objects or a DataView; false otherwise.
2130    ///
2131    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView)
2132    #[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
2133    pub fn is_view(value: &JsValue) -> bool;
2134
2135    /// The `maxByteLength` accessor property of ArrayBuffer instances returns the maximum
2136    /// length (in bytes) that this array buffer can be resized to.
2137    ///
2138    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/maxByteLength)
2139    #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2140    pub fn max_byte_length(this: &ArrayBuffer) -> usize;
2141
2142    /// The `resizable` accessor property of `ArrayBuffer` instances returns whether this array buffer
2143    /// can be resized or not.
2144    ///
2145    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resizable)
2146    #[wasm_bindgen(method, getter)]
2147    pub fn resizable(this: &ArrayBuffer) -> bool;
2148
2149    /// The `resize()` method of ArrayBuffer instances resizes the ArrayBuffer to the
2150    /// specified size, in bytes.
2151    ///
2152    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resize)
2153    #[wasm_bindgen(method, catch)]
2154    pub fn resize(this: &ArrayBuffer, new_len: usize) -> Result<(), JsValue>;
2155
2156    /// The `slice()` method returns a new `ArrayBuffer` whose contents
2157    /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2158    /// up to end, exclusive.
2159    ///
2160    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2161    #[cfg(not(js_sys_unstable_apis))]
2162    #[wasm_bindgen(method)]
2163    pub fn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer;
2164
2165    /// The `slice()` method returns a new `ArrayBuffer` whose contents
2166    /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2167    /// up to end, exclusive. Negative indices count from the end.
2168    ///
2169    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2170    #[cfg(js_sys_unstable_apis)]
2171    #[wasm_bindgen(method)]
2172    pub fn slice(this: &ArrayBuffer, begin: isize, end: isize) -> ArrayBuffer;
2173
2174    /// The `slice()` method returns a new `ArrayBuffer` whose contents
2175    /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2176    /// up to end, exclusive.
2177    ///
2178    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2179    #[cfg(not(js_sys_unstable_apis))]
2180    #[wasm_bindgen(method, js_name = slice)]
2181    pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2182
2183    /// The `slice()` method returns a new `ArrayBuffer` whose contents
2184    /// are a copy of this `ArrayBuffer`'s bytes from begin to the end.
2185    /// Negative indices count from the end.
2186    ///
2187    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2188    #[cfg(js_sys_unstable_apis)]
2189    #[wasm_bindgen(method, js_name = slice)]
2190    pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2191
2192    // Next major: deprecate
2193    /// Like `slice()` but with the `end` argument.
2194    ///
2195    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2196    #[wasm_bindgen(method, js_name = slice)]
2197    pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer;
2198
2199    /// The `transfer()` method of ArrayBuffer instances creates a new `ArrayBuffer`
2200    /// with the same byte content as this buffer, then detaches this buffer.
2201    ///
2202    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2203    #[wasm_bindgen(method, catch)]
2204    pub fn transfer(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2205
2206    /// The `transfer()` method of `ArrayBuffer` instances creates a new `ArrayBuffer`
2207    /// with the same byte content as this buffer, then detaches this buffer.
2208    ///
2209    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2210    #[wasm_bindgen(method, catch, js_name = transfer)]
2211    pub fn transfer_with_length(
2212        this: &ArrayBuffer,
2213        new_byte_length: usize,
2214    ) -> Result<ArrayBuffer, JsValue>;
2215
2216    /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2217    /// ArrayBuffer with the same byte content as this buffer, then detaches this buffer.
2218    ///
2219    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2220    #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2221    pub fn transfer_to_fixed_length(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2222
2223    /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2224    /// `ArrayBuffer` with the same byte content as this buffer, then detaches this buffer.
2225    ///
2226    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2227    #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2228    pub fn transfer_to_fixed_length_with_length(
2229        this: &ArrayBuffer,
2230        new_byte_length: usize,
2231    ) -> Result<ArrayBuffer, JsValue>;
2232}
2233
2234impl UpcastFrom<&[u8]> for ArrayBuffer {}
2235
2236// SharedArrayBuffer
2237#[wasm_bindgen]
2238extern "C" {
2239    #[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
2240    #[derive(Clone, Debug)]
2241    pub type SharedArrayBuffer;
2242
2243    /// The `SharedArrayBuffer` object is used to represent a generic,
2244    /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2245    /// object, but in a way that they can be used to create views
2246    /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2247    /// cannot become detached.
2248    ///
2249    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2250    #[cfg(not(js_sys_unstable_apis))]
2251    #[wasm_bindgen(constructor)]
2252    pub fn new(length: u32) -> SharedArrayBuffer;
2253
2254    /// The `SharedArrayBuffer` object is used to represent a generic,
2255    /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2256    /// object, but in a way that they can be used to create views
2257    /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2258    /// cannot become detached.
2259    ///
2260    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2261    #[cfg(js_sys_unstable_apis)]
2262    #[wasm_bindgen(constructor)]
2263    pub fn new(length: usize) -> SharedArrayBuffer;
2264
2265    /// The `SharedArrayBuffer` object is used to represent a generic,
2266    /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2267    /// object, but in a way that they can be used to create views
2268    /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2269    /// cannot become detached.
2270    ///
2271    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2272    #[wasm_bindgen(constructor)]
2273    pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> SharedArrayBuffer;
2274
2275    /// The `byteLength` accessor property represents the length of
2276    /// an `SharedArrayBuffer` in bytes. This is established when
2277    /// the `SharedArrayBuffer` is constructed and cannot be changed.
2278    ///
2279    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2280    #[cfg(not(js_sys_unstable_apis))]
2281    #[wasm_bindgen(method, getter, js_name = byteLength)]
2282    pub fn byte_length(this: &SharedArrayBuffer) -> u32;
2283
2284    /// The `byteLength` accessor property represents the length of
2285    /// an `SharedArrayBuffer` in bytes. This is established when
2286    /// the `SharedArrayBuffer` is constructed and cannot be changed.
2287    ///
2288    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2289    #[cfg(js_sys_unstable_apis)]
2290    #[wasm_bindgen(method, getter, js_name = byteLength)]
2291    pub fn byte_length(this: &SharedArrayBuffer) -> usize;
2292
2293    /// The `growable` accessor property of `SharedArrayBuffer` instances returns whether
2294    /// this `SharedArrayBuffer` can be grown or not.
2295    ///
2296    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/growable)
2297    #[wasm_bindgen(method, getter)]
2298    pub fn growable(this: &SharedArrayBuffer) -> bool;
2299
2300    /// The `grow()` method of `SharedArrayBuffer` instances grows the
2301    /// `SharedArrayBuffer` to the specified size, in bytes.
2302    ///
2303    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/grow)
2304    #[wasm_bindgen(method, catch)]
2305    pub fn grow(this: &SharedArrayBuffer, new_byte_length: usize) -> Result<(), JsValue>;
2306
2307    /// The `maxByteLength` accessor property of `SharedArrayBuffer` instances returns the maximum
2308    /// length (in bytes) that this `SharedArrayBuffer` can be resized to.
2309    ///
2310    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/maxByteLength)
2311    #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2312    pub fn max_byte_length(this: &SharedArrayBuffer) -> usize;
2313
2314    /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2315    /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2316    /// up to end, exclusive.
2317    ///
2318    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2319    #[cfg(not(js_sys_unstable_apis))]
2320    #[wasm_bindgen(method)]
2321    pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer;
2322
2323    /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2324    /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2325    /// up to end, exclusive. Negative indices count from the end.
2326    ///
2327    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2328    #[cfg(js_sys_unstable_apis)]
2329    #[wasm_bindgen(method)]
2330    pub fn slice(this: &SharedArrayBuffer, begin: isize, end: isize) -> SharedArrayBuffer;
2331
2332    /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2333    /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2334    /// up to end, exclusive.
2335    ///
2336    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2337    #[cfg(not(js_sys_unstable_apis))]
2338    #[wasm_bindgen(method)]
2339    pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2340
2341    /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2342    /// are a copy of this `SharedArrayBuffer`'s bytes from begin to end.
2343    /// Negative indices count from the end.
2344    ///
2345    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2346    #[cfg(js_sys_unstable_apis)]
2347    #[wasm_bindgen(method)]
2348    pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2349
2350    // Next major: deprecate
2351    /// Like `slice()` but with the `end` argument.
2352    ///
2353    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2354    #[wasm_bindgen(method, js_name = slice)]
2355    pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer;
2356}
2357
2358// Array Iterator
2359#[wasm_bindgen]
2360extern "C" {
2361    /// The `keys()` method returns a new Array Iterator object that contains the
2362    /// keys for each index in the array.
2363    ///
2364    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys)
2365    #[wasm_bindgen(method)]
2366    pub fn keys<T>(this: &Array<T>) -> Iterator<T>;
2367
2368    /// The `entries()` method returns a new Array Iterator object that contains
2369    /// the key/value pairs for each index in the array.
2370    ///
2371    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2372    #[cfg(not(js_sys_unstable_apis))]
2373    #[wasm_bindgen(method)]
2374    #[deprecated(note = "recommended to use `Array::entries_typed` instead for typing")]
2375    #[allow(deprecated)]
2376    pub fn entries<T>(this: &Array<T>) -> Iterator<T>;
2377
2378    /// The `entries()` method returns a new Array Iterator object that contains
2379    /// the key/value pairs for each index in the array.
2380    ///
2381    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2382    #[cfg(js_sys_unstable_apis)]
2383    #[wasm_bindgen(method)]
2384    pub fn entries<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2385
2386    // Next major: deprecate
2387    /// The `entries()` method returns a new Array Iterator object that contains
2388    /// the key/value pairs for each index in the array.
2389    ///
2390    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2391    #[wasm_bindgen(method, js_name = entries)]
2392    pub fn entries_typed<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2393
2394    /// The `values()` method returns a new Array Iterator object that
2395    /// contains the values for each index in the array.
2396    ///
2397    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
2398    #[wasm_bindgen(method)]
2399    pub fn values<T>(this: &Array<T>) -> Iterator<T>;
2400}
2401
2402pub trait TypedArray: JsGeneric {}
2403
2404// Next major: use usize/isize for indices
2405/// The `Atomics` object provides atomic operations as static methods.
2406/// They are used with `SharedArrayBuffer` objects.
2407///
2408/// The Atomic operations are installed on an `Atomics` module. Unlike
2409/// the other global objects, `Atomics` is not a constructor. You cannot
2410/// use it with a new operator or invoke the `Atomics` object as a
2411/// function. All properties and methods of `Atomics` are static
2412/// (as is the case with the Math object, for example).
2413/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
2414#[allow(non_snake_case)]
2415pub mod Atomics {
2416    use super::*;
2417
2418    #[wasm_bindgen]
2419    extern "C" {
2420        /// The static `Atomics.add()` method adds a given value at a given
2421        /// position in the array and returns the old value at that position.
2422        /// This atomic operation guarantees that no other write happens
2423        /// until the modified value is written back.
2424        ///
2425        /// You should use `add_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2426        ///
2427        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2428        #[wasm_bindgen(js_namespace = Atomics, catch)]
2429        pub fn add<T: TypedArray = Int32Array>(
2430            typed_array: &T,
2431            index: u32,
2432            value: i32,
2433        ) -> Result<i32, JsValue>;
2434
2435        /// The static `Atomics.add()` method adds a given value at a given
2436        /// position in the array and returns the old value at that position.
2437        /// This atomic operation guarantees that no other write happens
2438        /// until the modified value is written back.
2439        ///
2440        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2441        ///
2442        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2443        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = add)]
2444        pub fn add_bigint<T: TypedArray = Int32Array>(
2445            typed_array: &T,
2446            index: u32,
2447            value: i64,
2448        ) -> Result<i64, JsValue>;
2449
2450        /// The static `Atomics.and()` method computes a bitwise AND with a given
2451        /// value at a given position in the array, and returns the old value
2452        /// at that position.
2453        /// This atomic operation guarantees that no other write happens
2454        /// until the modified value is written back.
2455        ///
2456        /// You should use `and_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2457        ///
2458        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2459        #[wasm_bindgen(js_namespace = Atomics, catch)]
2460        pub fn and<T: TypedArray = Int32Array>(
2461            typed_array: &T,
2462            index: u32,
2463            value: i32,
2464        ) -> Result<i32, JsValue>;
2465
2466        /// The static `Atomics.and()` method computes a bitwise AND with a given
2467        /// value at a given position in the array, and returns the old value
2468        /// at that position.
2469        /// This atomic operation guarantees that no other write happens
2470        /// until the modified value is written back.
2471        ///
2472        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2473        ///
2474        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2475        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = and)]
2476        pub fn and_bigint<T: TypedArray = Int32Array>(
2477            typed_array: &T,
2478            index: u32,
2479            value: i64,
2480        ) -> Result<i64, JsValue>;
2481
2482        /// The static `Atomics.compareExchange()` method exchanges a given
2483        /// replacement value at a given position in the array, if a given expected
2484        /// value equals the old value. It returns the old value at that position
2485        /// whether it was equal to the expected value or not.
2486        /// This atomic operation guarantees that no other write happens
2487        /// until the modified value is written back.
2488        ///
2489        /// You should use `compare_exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2490        ///
2491        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2492        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2493        pub fn compare_exchange<T: TypedArray = Int32Array>(
2494            typed_array: &T,
2495            index: u32,
2496            expected_value: i32,
2497            replacement_value: i32,
2498        ) -> Result<i32, JsValue>;
2499
2500        /// The static `Atomics.compareExchange()` method exchanges a given
2501        /// replacement value at a given position in the array, if a given expected
2502        /// value equals the old value. It returns the old value at that position
2503        /// whether it was equal to the expected value or not.
2504        /// This atomic operation guarantees that no other write happens
2505        /// until the modified value is written back.
2506        ///
2507        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2508        ///
2509        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2510        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2511        pub fn compare_exchange_bigint<T: TypedArray = Int32Array>(
2512            typed_array: &T,
2513            index: u32,
2514            expected_value: i64,
2515            replacement_value: i64,
2516        ) -> Result<i64, JsValue>;
2517
2518        /// The static `Atomics.exchange()` method stores a given value at a given
2519        /// position in the array and returns the old value at that position.
2520        /// This atomic operation guarantees that no other write happens
2521        /// until the modified value is written back.
2522        ///
2523        /// You should use `exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2524        ///
2525        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2526        #[wasm_bindgen(js_namespace = Atomics, catch)]
2527        pub fn exchange<T: TypedArray = Int32Array>(
2528            typed_array: &T,
2529            index: u32,
2530            value: i32,
2531        ) -> Result<i32, JsValue>;
2532
2533        /// The static `Atomics.exchange()` method stores a given value at a given
2534        /// position in the array and returns the old value at that position.
2535        /// This atomic operation guarantees that no other write happens
2536        /// until the modified value is written back.
2537        ///
2538        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2539        ///
2540        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2541        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = exchange)]
2542        pub fn exchange_bigint<T: TypedArray = Int32Array>(
2543            typed_array: &T,
2544            index: u32,
2545            value: i64,
2546        ) -> Result<i64, JsValue>;
2547
2548        /// The static `Atomics.isLockFree()` method is used to determine
2549        /// whether to use locks or atomic operations. It returns true,
2550        /// if the given size is one of the `BYTES_PER_ELEMENT` property
2551        /// of integer `TypedArray` types.
2552        ///
2553        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree)
2554        #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)]
2555        pub fn is_lock_free(size: u32) -> bool;
2556
2557        /// The static `Atomics.load()` method returns a value at a given
2558        /// position in the array.
2559        ///
2560        /// You should use `load_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2561        ///
2562        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2563        #[wasm_bindgen(js_namespace = Atomics, catch)]
2564        pub fn load<T: TypedArray = Int32Array>(
2565            typed_array: &T,
2566            index: u32,
2567        ) -> Result<i32, JsValue>;
2568
2569        /// The static `Atomics.load()` method returns a value at a given
2570        /// position in the array.
2571        ///
2572        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2573        ///
2574        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2575        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = load)]
2576        pub fn load_bigint<T: TypedArray = Int32Array>(
2577            typed_array: &T,
2578            index: i64,
2579        ) -> Result<i64, JsValue>;
2580
2581        /// The static `Atomics.notify()` method notifies up some agents that
2582        /// are sleeping in the wait queue.
2583        /// Note: This operation works with a shared `Int32Array` only.
2584        /// If `count` is not provided, notifies all the agents in the queue.
2585        ///
2586        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2587        #[wasm_bindgen(js_namespace = Atomics, catch)]
2588        pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>;
2589
2590        /// The static `Atomics.notify()` method notifies up some agents that
2591        /// are sleeping in the wait queue.
2592        /// Note: This operation works with a shared `Int32Array` only.
2593        /// If `count` is not provided, notifies all the agents in the queue.
2594        ///
2595        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2596        #[wasm_bindgen(js_namespace = Atomics, catch)]
2597        pub fn notify_bigint(typed_array: &BigInt64Array, index: u32) -> Result<u32, JsValue>;
2598
2599        /// Notifies up to `count` agents in the wait queue.
2600        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2601        pub fn notify_with_count(
2602            typed_array: &Int32Array,
2603            index: u32,
2604            count: u32,
2605        ) -> Result<u32, JsValue>;
2606
2607        /// Notifies up to `count` agents in the wait queue.
2608        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2609        pub fn notify_bigint_with_count(
2610            typed_array: &BigInt64Array,
2611            index: u32,
2612            count: u32,
2613        ) -> Result<u32, JsValue>;
2614
2615        /// The static `Atomics.or()` method computes a bitwise OR with a given value
2616        /// at a given position in the array, and returns the old value at that position.
2617        /// This atomic operation guarantees that no other write happens
2618        /// until the modified value is written back.
2619        ///
2620        /// You should use `or_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2621        ///
2622        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2623        #[wasm_bindgen(js_namespace = Atomics, catch)]
2624        pub fn or<T: TypedArray = Int32Array>(
2625            typed_array: &T,
2626            index: u32,
2627            value: i32,
2628        ) -> Result<i32, JsValue>;
2629
2630        /// The static `Atomics.or()` method computes a bitwise OR with a given value
2631        /// at a given position in the array, and returns the old value at that position.
2632        /// This atomic operation guarantees that no other write happens
2633        /// until the modified value is written back.
2634        ///
2635        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2636        ///
2637        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2638        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = or)]
2639        pub fn or_bigint<T: TypedArray = Int32Array>(
2640            typed_array: &T,
2641            index: u32,
2642            value: i64,
2643        ) -> Result<i64, JsValue>;
2644
2645        /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2646        /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2647        /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2648        /// current thread.
2649        ///
2650        /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2651        /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2652        /// per Intel's optimization manual. It could be a no-op in certain platforms.
2653        ///
2654        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2655        ///
2656        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2657        #[wasm_bindgen(js_namespace = Atomics)]
2658        pub fn pause();
2659
2660        /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2661        /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2662        /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2663        /// current thread.
2664        ///
2665        /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2666        /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2667        /// per Intel's optimization manual. It could be a no-op in certain platforms.
2668        ///
2669        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2670        ///
2671        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2672        #[wasm_bindgen(js_namespace = Atomics)]
2673        pub fn pause_with_hint(duration_hint: u32);
2674
2675        /// The static `Atomics.store()` method stores a given value at the given
2676        /// position in the array and returns that value.
2677        ///
2678        /// You should use `store_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2679        ///
2680        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2681        #[wasm_bindgen(js_namespace = Atomics, catch)]
2682        pub fn store<T: TypedArray = Int32Array>(
2683            typed_array: &T,
2684            index: u32,
2685            value: i32,
2686        ) -> Result<i32, JsValue>;
2687
2688        /// The static `Atomics.store()` method stores a given value at the given
2689        /// position in the array and returns that value.
2690        ///
2691        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2692        ///
2693        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2694        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = store)]
2695        pub fn store_bigint<T: TypedArray = Int32Array>(
2696            typed_array: &T,
2697            index: u32,
2698            value: i64,
2699        ) -> Result<i64, JsValue>;
2700
2701        /// The static `Atomics.sub()` method subtracts a given value at a
2702        /// given position in the array and returns the old value at that position.
2703        /// This atomic operation guarantees that no other write happens
2704        /// until the modified value is written back.
2705        ///
2706        /// You should use `sub_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2707        ///
2708        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2709        #[wasm_bindgen(js_namespace = Atomics, catch)]
2710        pub fn sub<T: TypedArray = Int32Array>(
2711            typed_array: &T,
2712            index: u32,
2713            value: i32,
2714        ) -> Result<i32, JsValue>;
2715
2716        /// The static `Atomics.sub()` method subtracts a given value at a
2717        /// given position in the array and returns the old value at that position.
2718        /// This atomic operation guarantees that no other write happens
2719        /// until the modified value is written back.
2720        ///
2721        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2722        ///
2723        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2724        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = sub)]
2725        pub fn sub_bigint<T: TypedArray = Int32Array>(
2726            typed_array: &T,
2727            index: u32,
2728            value: i64,
2729        ) -> Result<i64, JsValue>;
2730
2731        /// The static `Atomics.wait()` method verifies that a given
2732        /// position in an `Int32Array` still contains a given value
2733        /// and if so sleeps, awaiting a wakeup or a timeout.
2734        /// It returns a string which is either "ok", "not-equal", or "timed-out".
2735        /// Note: This operation only works with a shared `Int32Array`
2736        /// and may not be allowed on the main thread.
2737        ///
2738        /// You should use `wait_bigint` to operate on a `BigInt64Array`.
2739        ///
2740        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2741        #[wasm_bindgen(js_namespace = Atomics, catch)]
2742        pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>;
2743
2744        /// The static `Atomics.wait()` method verifies that a given
2745        /// position in an `BigInt64Array` still contains a given value
2746        /// and if so sleeps, awaiting a wakeup or a timeout.
2747        /// It returns a string which is either "ok", "not-equal", or "timed-out".
2748        /// Note: This operation only works with a shared `BigInt64Array`
2749        /// and may not be allowed on the main thread.
2750        ///
2751        /// You should use `wait` to operate on a `Int32Array`.
2752        ///
2753        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2754        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2755        pub fn wait_bigint(
2756            typed_array: &BigInt64Array,
2757            index: u32,
2758            value: i64,
2759        ) -> Result<JsString, JsValue>;
2760
2761        /// Like `wait()`, but with timeout
2762        ///
2763        /// You should use `wait_with_timeout_bigint` to operate on a `BigInt64Array`.
2764        ///
2765        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2766        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2767        pub fn wait_with_timeout(
2768            typed_array: &Int32Array,
2769            index: u32,
2770            value: i32,
2771            timeout: f64,
2772        ) -> Result<JsString, JsValue>;
2773
2774        /// Like `wait()`, but with timeout
2775        ///
2776        /// You should use `wait_with_timeout` to operate on a `Int32Array`.
2777        ///
2778        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2779        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2780        pub fn wait_with_timeout_bigint(
2781            typed_array: &BigInt64Array,
2782            index: u32,
2783            value: i64,
2784            timeout: f64,
2785        ) -> Result<JsString, JsValue>;
2786
2787        /// The static `Atomics.waitAsync()` method verifies that a given position in an
2788        /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2789        /// wakeup or a timeout. It returns an object with two properties. The first
2790        /// property `async` is a boolean which if true indicates that the second
2791        /// property `value` is a promise. If `async` is false then value is a string
2792        /// whether equal to either "not-equal" or "timed-out".
2793        /// Note: This operation only works with a shared `Int32Array` and may be used
2794        /// on the main thread.
2795        ///
2796        /// You should use `wait_async_bigint` to operate on a `BigInt64Array`.
2797        ///
2798        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2799        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2800        pub fn wait_async(
2801            typed_array: &Int32Array,
2802            index: u32,
2803            value: i32,
2804        ) -> Result<Object, JsValue>;
2805
2806        /// The static `Atomics.waitAsync()` method verifies that a given position in an
2807        /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2808        /// wakeup or a timeout. It returns an object with two properties. The first
2809        /// property `async` is a boolean which if true indicates that the second
2810        /// property `value` is a promise. If `async` is false then value is a string
2811        /// whether equal to either "not-equal" or "timed-out".
2812        /// Note: This operation only works with a shared `BigInt64Array` and may be used
2813        /// on the main thread.
2814        ///
2815        /// You should use `wait_async` to operate on a `Int32Array`.
2816        ///
2817        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2818        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2819        pub fn wait_async_bigint(
2820            typed_array: &BigInt64Array,
2821            index: u32,
2822            value: i64,
2823        ) -> Result<Object, JsValue>;
2824
2825        /// Like `waitAsync()`, but with timeout
2826        ///
2827        /// You should use `wait_async_with_timeout_bigint` to operate on a `BigInt64Array`.
2828        ///
2829        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2830        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2831        pub fn wait_async_with_timeout(
2832            typed_array: &Int32Array,
2833            index: u32,
2834            value: i32,
2835            timeout: f64,
2836        ) -> Result<Object, JsValue>;
2837
2838        /// Like `waitAsync()`, but with timeout
2839        ///
2840        /// You should use `wait_async_with_timeout` to operate on a `Int32Array`.
2841        ///
2842        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2843        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2844        pub fn wait_async_with_timeout_bigint(
2845            typed_array: &BigInt64Array,
2846            index: u32,
2847            value: i64,
2848            timeout: f64,
2849        ) -> Result<Object, JsValue>;
2850
2851        /// The static `Atomics.xor()` method computes a bitwise XOR
2852        /// with a given value at a given position in the array,
2853        /// and returns the old value at that position.
2854        /// This atomic operation guarantees that no other write happens
2855        /// until the modified value is written back.
2856        ///
2857        /// You should use `xor_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2858        ///
2859        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2860        #[wasm_bindgen(js_namespace = Atomics, catch)]
2861        pub fn xor<T: TypedArray = Int32Array>(
2862            typed_array: &T,
2863            index: u32,
2864            value: i32,
2865        ) -> Result<i32, JsValue>;
2866
2867        /// The static `Atomics.xor()` method computes a bitwise XOR
2868        /// with a given value at a given position in the array,
2869        /// and returns the old value at that position.
2870        /// This atomic operation guarantees that no other write happens
2871        /// until the modified value is written back.
2872        ///
2873        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2874        ///
2875        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2876        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = xor)]
2877        pub fn xor_bigint<T: TypedArray = Int32Array>(
2878            typed_array: &T,
2879            index: u32,
2880            value: i64,
2881        ) -> Result<i64, JsValue>;
2882    }
2883}
2884
2885// BigInt
2886#[wasm_bindgen]
2887extern "C" {
2888    #[wasm_bindgen(extends = Object, is_type_of = |v| v.is_bigint(), typescript_type = "bigint")]
2889    #[derive(Clone, PartialEq, Eq)]
2890    pub type BigInt;
2891
2892    #[wasm_bindgen(catch, js_name = BigInt)]
2893    fn new_bigint(value: &JsValue) -> Result<BigInt, Error>;
2894
2895    #[wasm_bindgen(js_name = BigInt)]
2896    fn new_bigint_unchecked(value: &JsValue) -> BigInt;
2897
2898    /// Clamps a BigInt value to a signed integer value, and returns that value.
2899    ///
2900    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)
2901    #[wasm_bindgen(static_method_of = BigInt, js_name = asIntN)]
2902    pub fn as_int_n(bits: f64, bigint: &BigInt) -> BigInt;
2903
2904    /// Clamps a BigInt value to an unsigned integer value, and returns that value.
2905    ///
2906    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)
2907    #[wasm_bindgen(static_method_of = BigInt, js_name = asUintN)]
2908    pub fn as_uint_n(bits: f64, bigint: &BigInt) -> BigInt;
2909
2910    /// 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.
2911    ///
2912    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
2913    #[cfg(not(js_sys_unstable_apis))]
2914    #[wasm_bindgen(method, js_name = toLocaleString)]
2915    pub fn to_locale_string(this: &BigInt, locales: &JsValue, options: &JsValue) -> JsString;
2916
2917    /// 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.
2918    ///
2919    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
2920    #[cfg(js_sys_unstable_apis)]
2921    #[wasm_bindgen(method, js_name = toLocaleString)]
2922    pub fn to_locale_string(
2923        this: &BigInt,
2924        locales: &[JsString],
2925        options: &Intl::NumberFormatOptions,
2926    ) -> JsString;
2927
2928    // Next major: deprecate
2929    /// 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.
2930    ///
2931    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
2932    #[wasm_bindgen(catch, method, js_name = toString)]
2933    pub fn to_string(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
2934
2935    /// Returns a string representing this BigInt value in the specified radix (base).
2936    ///
2937    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
2938    #[cfg(js_sys_unstable_apis)]
2939    #[wasm_bindgen(catch, method, js_name = toString)]
2940    pub fn to_string_with_radix(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
2941
2942    #[wasm_bindgen(method, js_name = toString)]
2943    fn to_string_unchecked(this: &BigInt, radix: u8) -> String;
2944
2945    /// Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method.
2946    ///
2947    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)
2948    #[wasm_bindgen(method, js_name = valueOf)]
2949    pub fn value_of(this: &BigInt, radix: u8) -> BigInt;
2950}
2951
2952impl BigInt {
2953    /// Creates a new BigInt value.
2954    ///
2955    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)
2956    #[inline]
2957    pub fn new(value: &JsValue) -> Result<BigInt, Error> {
2958        new_bigint(value)
2959    }
2960
2961    /// Applies the binary `/` JS operator on two `BigInt`s, catching and returning any `RangeError` thrown.
2962    ///
2963    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division)
2964    pub fn checked_div(&self, rhs: &Self) -> Result<Self, RangeError> {
2965        let result = JsValue::as_ref(self).checked_div(JsValue::as_ref(rhs));
2966
2967        if result.is_instance_of::<RangeError>() {
2968            Err(result.unchecked_into())
2969        } else {
2970            Ok(result.unchecked_into())
2971        }
2972    }
2973
2974    /// Applies the binary `**` JS operator on the two `BigInt`s.
2975    ///
2976    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
2977    #[inline]
2978    pub fn pow(&self, rhs: &Self) -> Self {
2979        JsValue::as_ref(self)
2980            .pow(JsValue::as_ref(rhs))
2981            .unchecked_into()
2982    }
2983
2984    /// Returns a tuple of this [`BigInt`]'s absolute value along with a
2985    /// [`bool`] indicating whether the [`BigInt`] was negative.
2986    fn abs(&self) -> (Self, bool) {
2987        if self < &BigInt::from(0) {
2988            (-self, true)
2989        } else {
2990            (self.clone(), false)
2991        }
2992    }
2993}
2994
2995macro_rules! bigint_from {
2996    ($($x:ident)*) => ($(
2997        impl From<$x> for BigInt {
2998            #[inline]
2999            fn from(x: $x) -> BigInt {
3000                new_bigint_unchecked(&JsValue::from(x))
3001            }
3002        }
3003
3004        impl PartialEq<$x> for BigInt {
3005            #[inline]
3006            fn eq(&self, other: &$x) -> bool {
3007                JsValue::from(self) == JsValue::from(BigInt::from(*other))
3008            }
3009        }
3010    )*)
3011}
3012bigint_from!(i8 u8 i16 u16 i32 u32 isize usize);
3013
3014macro_rules! bigint_from_big {
3015    ($($x:ident)*) => ($(
3016        impl From<$x> for BigInt {
3017            #[inline]
3018            fn from(x: $x) -> BigInt {
3019                JsValue::from(x).unchecked_into()
3020            }
3021        }
3022
3023        impl PartialEq<$x> for BigInt {
3024            #[inline]
3025            fn eq(&self, other: &$x) -> bool {
3026                self == &BigInt::from(*other)
3027            }
3028        }
3029
3030        impl TryFrom<BigInt> for $x {
3031            type Error = BigInt;
3032
3033            #[inline]
3034            fn try_from(x: BigInt) -> Result<Self, BigInt> {
3035                Self::try_from(JsValue::from(x)).map_err(JsCast::unchecked_into)
3036            }
3037        }
3038    )*)
3039}
3040bigint_from_big!(i64 u64 i128 u128);
3041
3042impl PartialEq<Number> for BigInt {
3043    #[inline]
3044    fn eq(&self, other: &Number) -> bool {
3045        JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
3046    }
3047}
3048
3049impl Not for &BigInt {
3050    type Output = BigInt;
3051
3052    #[inline]
3053    fn not(self) -> Self::Output {
3054        JsValue::as_ref(self).bit_not().unchecked_into()
3055    }
3056}
3057
3058forward_deref_unop!(impl Not, not for BigInt);
3059forward_js_unop!(impl Neg, neg for BigInt);
3060forward_js_binop!(impl BitAnd, bitand for BigInt);
3061forward_js_binop!(impl BitOr, bitor for BigInt);
3062forward_js_binop!(impl BitXor, bitxor for BigInt);
3063forward_js_binop!(impl Shl, shl for BigInt);
3064forward_js_binop!(impl Shr, shr for BigInt);
3065forward_js_binop!(impl Add, add for BigInt);
3066forward_js_binop!(impl Sub, sub for BigInt);
3067forward_js_binop!(impl Div, div for BigInt);
3068forward_js_binop!(impl Mul, mul for BigInt);
3069forward_js_binop!(impl Rem, rem for BigInt);
3070sum_product!(BigInt);
3071
3072partialord_ord!(BigInt);
3073
3074impl Default for BigInt {
3075    fn default() -> Self {
3076        BigInt::from(i32::default())
3077    }
3078}
3079
3080impl FromStr for BigInt {
3081    type Err = Error;
3082
3083    #[inline]
3084    fn from_str(s: &str) -> Result<Self, Self::Err> {
3085        BigInt::new(&s.into())
3086    }
3087}
3088
3089impl fmt::Debug for BigInt {
3090    #[inline]
3091    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3092        fmt::Display::fmt(self, f)
3093    }
3094}
3095
3096impl fmt::Display for BigInt {
3097    #[inline]
3098    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3099        let (abs, is_neg) = self.abs();
3100        f.pad_integral(!is_neg, "", &abs.to_string_unchecked(10))
3101    }
3102}
3103
3104impl fmt::Binary for BigInt {
3105    #[inline]
3106    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3107        let (abs, is_neg) = self.abs();
3108        f.pad_integral(!is_neg, "0b", &abs.to_string_unchecked(2))
3109    }
3110}
3111
3112impl fmt::Octal for BigInt {
3113    #[inline]
3114    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3115        let (abs, is_neg) = self.abs();
3116        f.pad_integral(!is_neg, "0o", &abs.to_string_unchecked(8))
3117    }
3118}
3119
3120impl fmt::LowerHex for BigInt {
3121    #[inline]
3122    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3123        let (abs, is_neg) = self.abs();
3124        f.pad_integral(!is_neg, "0x", &abs.to_string_unchecked(16))
3125    }
3126}
3127
3128impl fmt::UpperHex for BigInt {
3129    #[inline]
3130    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3131        let (abs, is_neg) = self.abs();
3132        let mut s: String = abs.to_string_unchecked(16);
3133        s.make_ascii_uppercase();
3134        f.pad_integral(!is_neg, "0x", &s)
3135    }
3136}
3137
3138// Boolean
3139#[wasm_bindgen]
3140extern "C" {
3141    #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
3142    #[derive(Clone, PartialEq, Eq)]
3143    pub type Boolean;
3144
3145    /// The `Boolean()` constructor creates an object wrapper for a boolean value.
3146    ///
3147    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
3148    #[cfg(not(js_sys_unstable_apis))]
3149    #[wasm_bindgen(constructor)]
3150    #[deprecated(note = "recommended to use `Boolean::from` instead")]
3151    #[allow(deprecated)]
3152    pub fn new(value: &JsValue) -> Boolean;
3153
3154    /// The `valueOf()` method returns the primitive value of a `Boolean` object.
3155    ///
3156    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf)
3157    #[wasm_bindgen(method, js_name = valueOf)]
3158    pub fn value_of(this: &Boolean) -> bool;
3159}
3160
3161impl UpcastFrom<bool> for Boolean {}
3162impl UpcastFrom<Boolean> for bool {}
3163
3164impl Boolean {
3165    /// Typed Boolean true constant.
3166    pub const TRUE: Boolean = unsafe { core::mem::transmute(JsValue::TRUE) };
3167
3168    /// Typed Boolean false constant.
3169    pub const FALSE: Boolean = unsafe { core::mem::transmute(JsValue::FALSE) };
3170}
3171
3172impl From<bool> for Boolean {
3173    #[inline]
3174    fn from(b: bool) -> Boolean {
3175        Boolean::unchecked_from_js(JsValue::from(b))
3176    }
3177}
3178
3179impl From<Boolean> for bool {
3180    #[inline]
3181    fn from(b: Boolean) -> bool {
3182        b.value_of()
3183    }
3184}
3185
3186impl PartialEq<bool> for Boolean {
3187    #[inline]
3188    fn eq(&self, other: &bool) -> bool {
3189        self.value_of() == *other
3190    }
3191}
3192
3193impl fmt::Debug for Boolean {
3194    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3195        fmt::Debug::fmt(&self.value_of(), f)
3196    }
3197}
3198
3199impl fmt::Display for Boolean {
3200    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3201        fmt::Display::fmt(&self.value_of(), f)
3202    }
3203}
3204
3205impl Default for Boolean {
3206    fn default() -> Self {
3207        Self::from(bool::default())
3208    }
3209}
3210
3211impl Not for &Boolean {
3212    type Output = Boolean;
3213
3214    #[inline]
3215    fn not(self) -> Self::Output {
3216        (!JsValue::as_ref(self)).into()
3217    }
3218}
3219
3220forward_deref_unop!(impl Not, not for Boolean);
3221
3222partialord_ord!(Boolean);
3223
3224// DataView
3225#[wasm_bindgen]
3226extern "C" {
3227    #[wasm_bindgen(extends = Object, typescript_type = "DataView")]
3228    #[derive(Clone, Debug, PartialEq, Eq)]
3229    pub type DataView;
3230
3231    /// The `DataView` view provides a low-level interface for reading and
3232    /// writing multiple number types in an `ArrayBuffer` irrespective of the
3233    /// platform's endianness.
3234    ///
3235    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3236    #[wasm_bindgen(constructor)]
3237    pub fn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView;
3238
3239    /// The `DataView` view provides a low-level interface for reading and
3240    /// writing multiple number types in an `ArrayBuffer` irrespective of the
3241    /// platform's endianness.
3242    ///
3243    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3244    #[wasm_bindgen(constructor)]
3245    pub fn new_with_shared_array_buffer(
3246        buffer: &SharedArrayBuffer,
3247        byteOffset: usize,
3248        byteLength: usize,
3249    ) -> DataView;
3250
3251    /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
3252    ///
3253    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer)
3254    #[wasm_bindgen(method, getter)]
3255    pub fn buffer(this: &DataView) -> ArrayBuffer;
3256
3257    /// The length (in bytes) of this view from the start of its ArrayBuffer.
3258    /// Fixed at construction time and thus read only.
3259    ///
3260    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength)
3261    #[wasm_bindgen(method, getter, js_name = byteLength)]
3262    pub fn byte_length(this: &DataView) -> usize;
3263
3264    /// The offset (in bytes) of this view from the start of its ArrayBuffer.
3265    /// Fixed at construction time and thus read only.
3266    ///
3267    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset)
3268    #[wasm_bindgen(method, getter, js_name = byteOffset)]
3269    pub fn byte_offset(this: &DataView) -> usize;
3270
3271    /// The `getInt8()` method gets a signed 8-bit integer (byte) at the
3272    /// specified byte offset from the start of the DataView.
3273    ///
3274    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8)
3275    #[wasm_bindgen(method, js_name = getInt8)]
3276    pub fn get_int8(this: &DataView, byte_offset: usize) -> i8;
3277
3278    /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified
3279    /// byte offset from the start of the DataView.
3280    ///
3281    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8)
3282    #[wasm_bindgen(method, js_name = getUint8)]
3283    pub fn get_uint8(this: &DataView, byte_offset: usize) -> u8;
3284
3285    /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3286    /// byte offset from the start of the DataView.
3287    ///
3288    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3289    #[wasm_bindgen(method, js_name = getInt16)]
3290    pub fn get_int16(this: &DataView, byte_offset: usize) -> i16;
3291
3292    /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3293    /// byte offset from the start of the DataView.
3294    ///
3295    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3296    #[wasm_bindgen(method, js_name = getInt16)]
3297    pub fn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16;
3298
3299    /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3300    /// byte offset from the start of the view.
3301    ///
3302    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3303    #[wasm_bindgen(method, js_name = getUint16)]
3304    pub fn get_uint16(this: &DataView, byte_offset: usize) -> u16;
3305
3306    /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3307    /// byte offset from the start of the view.
3308    ///
3309    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3310    #[wasm_bindgen(method, js_name = getUint16)]
3311    pub fn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16;
3312
3313    /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3314    /// byte offset from the start of the DataView.
3315    ///
3316    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3317    #[wasm_bindgen(method, js_name = getInt32)]
3318    pub fn get_int32(this: &DataView, byte_offset: usize) -> i32;
3319
3320    /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3321    /// byte offset from the start of the DataView.
3322    ///
3323    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3324    #[wasm_bindgen(method, js_name = getInt32)]
3325    pub fn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32;
3326
3327    /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3328    /// byte offset from the start of the view.
3329    ///
3330    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3331    #[wasm_bindgen(method, js_name = getUint32)]
3332    pub fn get_uint32(this: &DataView, byte_offset: usize) -> u32;
3333
3334    /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3335    /// byte offset from the start of the view.
3336    ///
3337    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3338    #[wasm_bindgen(method, js_name = getUint32)]
3339    pub fn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32;
3340
3341    /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3342    /// byte offset from the start of the DataView.
3343    ///
3344    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3345    #[wasm_bindgen(method, js_name = getFloat32)]
3346    pub fn get_float32(this: &DataView, byte_offset: usize) -> f32;
3347
3348    /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3349    /// byte offset from the start of the DataView.
3350    ///
3351    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3352    #[wasm_bindgen(method, js_name = getFloat32)]
3353    pub fn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32;
3354
3355    /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3356    /// byte offset from the start of the DataView.
3357    ///
3358    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3359    #[wasm_bindgen(method, js_name = getFloat64)]
3360    pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
3361
3362    /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3363    /// byte offset from the start of the DataView.
3364    ///
3365    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3366    #[wasm_bindgen(method, js_name = getFloat64)]
3367    pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
3368
3369    /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
3370    /// specified byte offset from the start of the DataView.
3371    ///
3372    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
3373    #[wasm_bindgen(method, js_name = setInt8)]
3374    pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
3375
3376    /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
3377    /// specified byte offset from the start of the DataView.
3378    ///
3379    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
3380    #[wasm_bindgen(method, js_name = setUint8)]
3381    pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
3382
3383    /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3384    /// specified byte offset from the start of the DataView.
3385    ///
3386    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3387    #[wasm_bindgen(method, js_name = setInt16)]
3388    pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
3389
3390    /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3391    /// specified byte offset from the start of the DataView.
3392    ///
3393    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3394    #[wasm_bindgen(method, js_name = setInt16)]
3395    pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
3396
3397    /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3398    /// specified byte offset from the start of the DataView.
3399    ///
3400    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3401    #[wasm_bindgen(method, js_name = setUint16)]
3402    pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
3403
3404    /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3405    /// specified byte offset from the start of the DataView.
3406    ///
3407    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3408    #[wasm_bindgen(method, js_name = setUint16)]
3409    pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
3410
3411    /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3412    /// specified byte offset from the start of the DataView.
3413    ///
3414    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3415    #[wasm_bindgen(method, js_name = setInt32)]
3416    pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
3417
3418    /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3419    /// specified byte offset from the start of the DataView.
3420    ///
3421    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3422    #[wasm_bindgen(method, js_name = setInt32)]
3423    pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
3424
3425    /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3426    /// specified byte offset from the start of the DataView.
3427    ///
3428    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3429    #[wasm_bindgen(method, js_name = setUint32)]
3430    pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
3431
3432    /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3433    /// specified byte offset from the start of the DataView.
3434    ///
3435    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3436    #[wasm_bindgen(method, js_name = setUint32)]
3437    pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
3438
3439    /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3440    /// specified byte offset from the start of the DataView.
3441    ///
3442    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3443    #[wasm_bindgen(method, js_name = setFloat32)]
3444    pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
3445
3446    /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3447    /// specified byte offset from the start of the DataView.
3448    ///
3449    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3450    #[wasm_bindgen(method, js_name = setFloat32)]
3451    pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
3452
3453    /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3454    /// specified byte offset from the start of the DataView.
3455    ///
3456    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3457    #[wasm_bindgen(method, js_name = setFloat64)]
3458    pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
3459
3460    /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3461    /// specified byte offset from the start of the DataView.
3462    ///
3463    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3464    #[wasm_bindgen(method, js_name = setFloat64)]
3465    pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
3466}
3467
3468// Error
3469#[wasm_bindgen]
3470extern "C" {
3471    #[wasm_bindgen(extends = Object, typescript_type = "Error")]
3472    #[derive(Clone, Debug, PartialEq, Eq)]
3473    pub type Error;
3474
3475    /// The Error constructor creates an error object.
3476    /// Instances of Error objects are thrown when runtime errors occur.
3477    /// The Error object can also be used as a base object for user-defined exceptions.
3478    /// See below for standard built-in error types.
3479    ///
3480    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
3481    #[wasm_bindgen(constructor)]
3482    pub fn new(message: &str) -> Error;
3483    #[wasm_bindgen(constructor)]
3484    pub fn new_with_options(message: &str, options: &Object) -> Error;
3485
3486    /// The cause property is the underlying cause of the error.
3487    /// Usually this is used to add context to re-thrown errors.
3488    ///
3489    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors)
3490    #[wasm_bindgen(method, getter)]
3491    pub fn cause(this: &Error) -> JsValue;
3492    #[wasm_bindgen(method, setter)]
3493    pub fn set_cause(this: &Error, cause: &JsValue);
3494
3495    /// The message property is a human-readable description of the error.
3496    ///
3497    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
3498    #[wasm_bindgen(method, getter)]
3499    pub fn message(this: &Error) -> JsString;
3500    #[wasm_bindgen(method, setter)]
3501    pub fn set_message(this: &Error, message: &str);
3502
3503    /// The name property represents a name for the type of error. The initial value is "Error".
3504    ///
3505    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
3506    #[wasm_bindgen(method, getter)]
3507    pub fn name(this: &Error) -> JsString;
3508    #[wasm_bindgen(method, setter)]
3509    pub fn set_name(this: &Error, name: &str);
3510
3511    /// The `toString()` method returns a string representing the specified Error object
3512    ///
3513    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
3514    #[cfg(not(js_sys_unstable_apis))]
3515    #[wasm_bindgen(method, js_name = toString)]
3516    pub fn to_string(this: &Error) -> JsString;
3517}
3518
3519partialord_ord!(JsString);
3520
3521// EvalError
3522#[wasm_bindgen]
3523extern "C" {
3524    #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
3525    #[derive(Clone, Debug, PartialEq, Eq)]
3526    pub type EvalError;
3527
3528    /// The `EvalError` object indicates an error regarding the global eval() function. This
3529    /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
3530    /// compatibility.
3531    ///
3532    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
3533    #[wasm_bindgen(constructor)]
3534    pub fn new(message: &str) -> EvalError;
3535}
3536
3537#[wasm_bindgen]
3538extern "C" {
3539    #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, no_upcast, typescript_type = "Function")]
3540    #[derive(Clone, Debug, PartialEq, Eq)]
3541    /// `Function` represents any generic Function in JS, by treating all arguments as `JsValue`.
3542    ///
3543    /// It takes a generic parameter of phantom type `fn (Arg1, ..., Argn) -> Ret` which
3544    /// is used to type the JS function. For example, `Function<fn () -> Number>` represents
3545    /// a function taking no arguments that returns a number.
3546    ///
3547    /// The 8 generic argument parameters (`Arg1` through `Arg8`) are the argument
3548    /// types. Arguments not provided enable strict arity checking at compile time.
3549    ///
3550    /// A void function is represented by `fn (Arg) -> Undefined`, and **not** the `()` unit
3551    /// type. This is because generics must be based on JS values in the JS generic type system.
3552    ///
3553    /// _The default without any parameters is as a void function - no arguments, `Undefined` return._
3554    ///
3555    /// _The default generic for `Function` is `fn (JsValue, JsValue, ...) -> JsValue`,
3556    /// representing any function, since all functions safely upcast into this function._
3557    ///
3558    /// ### Arity Enforcement
3559    ///
3560    /// It is not possible to use `call4` or `bind4` on a function that does not have
3561    /// at least 4 arguments — the compiler will reject this because only arguments that
3562    /// are not `None` support the trait bound for `ErasableGeneric`.
3563    ///
3564    /// ### Examples
3565    ///
3566    /// ```ignore
3567    /// // A function taking no args, returning Number
3568    /// let f: Function<Number> = get_some_fn();
3569    ///
3570    /// // A function taking (String, Number) and returning Boolean
3571    /// let f: Function<Boolean, String, Number> = get_some_fn();
3572    ///
3573    /// ### Upcasting
3574    ///
3575    /// To pass a typed `Function` where a different generic Function is expected, `upcast()` may be used
3576    /// to convert into any generic `Function` at zero cost with type-safety.
3577    ///
3578    /// MDN documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3579    pub type Function<
3580        T: JsFunction = fn(
3581            JsValue,
3582            JsValue,
3583            JsValue,
3584            JsValue,
3585            JsValue,
3586            JsValue,
3587            JsValue,
3588            JsValue,
3589        ) -> JsValue,
3590    >;
3591}
3592
3593#[wasm_bindgen]
3594extern "C" {
3595    /// The `Function` constructor creates a new `Function` object. Calling the
3596    /// constructor directly can create functions dynamically, but suffers from
3597    /// security and similar (but far less significant) performance issues
3598    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3599    /// allows executing code in the global scope, prompting better programming
3600    /// habits and allowing for more efficient code minification.
3601    ///
3602    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3603    #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3604    #[wasm_bindgen(constructor)]
3605    pub fn new_with_args(args: &str, body: &str) -> Function;
3606
3607    /// The `Function` constructor creates a new `Function` object. Calling the
3608    /// constructor directly can create functions dynamically, but suffers from
3609    /// security and similar (but far less significant) performance issues
3610    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3611    /// allows executing code in the global scope, prompting better programming
3612    /// habits and allowing for more efficient code minification.
3613    ///
3614    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3615    #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3616    #[wasm_bindgen(constructor)]
3617    pub fn new_with_args<T: JsFunction = fn() -> JsValue>(args: &str, body: &str) -> Function<T>;
3618
3619    // Next major: deprecate
3620    /// The `Function` constructor creates a new `Function` object. Calling the
3621    /// constructor directly can create functions dynamically, but suffers from
3622    /// security and similar (but far less significant) performance issues
3623    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3624    /// allows executing code in the global scope, prompting better programming
3625    /// habits and allowing for more efficient code minification.
3626    ///
3627    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3628    #[cfg(feature = "unsafe-eval")]
3629    #[wasm_bindgen(constructor)]
3630    pub fn new_with_args_typed<T: JsFunction = fn() -> JsValue>(
3631        args: &str,
3632        body: &str,
3633    ) -> Function<T>;
3634
3635    /// The `Function` constructor creates a new `Function` object. Calling the
3636    /// constructor directly can create functions dynamically, but suffers from
3637    /// security and similar (but far less significant) performance issues
3638    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3639    /// allows executing code in the global scope, prompting better programming
3640    /// habits and allowing for more efficient code minification.
3641    ///
3642    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3643    #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3644    #[wasm_bindgen(constructor)]
3645    pub fn new_no_args(body: &str) -> Function;
3646
3647    /// The `Function` constructor creates a new `Function` object. Calling the
3648    /// constructor directly can create functions dynamically, but suffers from
3649    /// security and similar (but far less significant) performance issues
3650    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3651    /// allows executing code in the global scope, prompting better programming
3652    /// habits and allowing for more efficient code minification.
3653    ///
3654    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3655    #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3656    #[wasm_bindgen(constructor)]
3657    pub fn new_no_args<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3658
3659    // Next major: deprecate
3660    /// The `Function` constructor creates a new `Function` object.
3661    ///
3662    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3663    #[cfg(feature = "unsafe-eval")]
3664    #[wasm_bindgen(constructor)]
3665    pub fn new_no_args_typed<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3666
3667    /// The `apply()` method calls a function with a given this value, and arguments provided as an array
3668    /// (or an array-like object).
3669    ///
3670    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
3671    #[wasm_bindgen(method, catch)]
3672    pub fn apply<T: JsFunction = fn() -> JsValue>(
3673        this: &Function<T>,
3674        context: &JsValue,
3675        args: &Array,
3676    ) -> Result<<T as JsFunction>::Ret, JsValue>;
3677
3678    // Next major: Deprecate, and separately provide provide impl
3679    /// The `call()` method calls a function with a given this value and
3680    /// arguments provided individually.
3681    ///
3682    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3683    ///
3684    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3685    #[wasm_bindgen(method, catch, js_name = call)]
3686    pub fn call0<Ret: JsGeneric, F: JsFunction<Ret = Ret> = fn() -> JsValue>(
3687        this: &Function<F>,
3688        context: &JsValue,
3689    ) -> Result<Ret, JsValue>;
3690
3691    // Next major: Deprecate, and separately provide provide impl
3692    /// The `call()` method calls a function with a given this value and
3693    /// arguments provided individually.
3694    ///
3695    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3696    ///
3697    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3698    #[wasm_bindgen(method, catch, js_name = call)]
3699    pub fn call1<
3700        Ret: JsGeneric,
3701        Arg1: JsGeneric,
3702        F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> = fn(JsValue) -> JsValue,
3703    >(
3704        this: &Function<F>,
3705        context: &JsValue,
3706        arg1: &Arg1,
3707    ) -> Result<Ret, JsValue>;
3708
3709    // Next major: Deprecate, and separately provide provide impl
3710    /// The `call()` method calls a function with a given this value and
3711    /// arguments provided individually.
3712    ///
3713    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3714    ///
3715    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3716    #[wasm_bindgen(method, catch, js_name = call)]
3717    pub fn call2<
3718        Ret: JsGeneric,
3719        Arg1: JsGeneric,
3720        Arg2: JsGeneric,
3721        F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> + JsFunction2<Arg2 = Arg2> = fn(
3722            JsValue,
3723            JsValue,
3724        ) -> JsValue,
3725    >(
3726        this: &Function<F>,
3727        context: &JsValue,
3728        arg1: &Arg1,
3729        arg2: &Arg2,
3730    ) -> Result<Ret, JsValue>;
3731
3732    // Next major: Deprecate, and separately provide provide impl
3733    /// The `call()` method calls a function with a given this value and
3734    /// arguments provided individually.
3735    ///
3736    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3737    ///
3738    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3739    #[wasm_bindgen(method, catch, js_name = call)]
3740    pub fn call3<
3741        Ret: JsGeneric,
3742        Arg1: JsGeneric,
3743        Arg2: JsGeneric,
3744        Arg3: JsGeneric,
3745        F: JsFunction<Ret = Ret> + JsFunction3<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
3746            JsValue,
3747            JsValue,
3748            JsValue,
3749        ) -> JsValue,
3750    >(
3751        this: &Function<F>,
3752        context: &JsValue,
3753        arg1: &Arg1,
3754        arg2: &Arg2,
3755        arg3: &Arg3,
3756    ) -> Result<Ret, JsValue>;
3757
3758    // Next major: Deprecate, and separately provide provide impl
3759    /// The `call()` method calls a function with a given this value and
3760    /// arguments provided individually.
3761    ///
3762    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3763    ///
3764    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3765    #[wasm_bindgen(method, catch, js_name = call)]
3766    pub fn call4<
3767        Ret: JsGeneric,
3768        Arg1: JsGeneric,
3769        Arg2: JsGeneric,
3770        Arg3: JsGeneric,
3771        Arg4: JsGeneric,
3772        F: JsFunction<Ret = Ret> + JsFunction4<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
3773            JsValue,
3774            JsValue,
3775            JsValue,
3776            JsValue,
3777        ) -> JsValue,
3778    >(
3779        this: &Function<F>,
3780        context: &JsValue,
3781        arg1: &Arg1,
3782        arg2: &Arg2,
3783        arg3: &Arg3,
3784        arg4: &Arg4,
3785    ) -> Result<Ret, JsValue>;
3786
3787    // Next major: Deprecate, and separately provide provide impl
3788    /// The `call()` method calls a function with a given this value and
3789    /// arguments provided individually.
3790    ///
3791    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3792    ///
3793    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3794    #[wasm_bindgen(method, catch, js_name = call)]
3795    pub fn call5<
3796        Ret: JsGeneric,
3797        Arg1: JsGeneric,
3798        Arg2: JsGeneric,
3799        Arg3: JsGeneric,
3800        Arg4: JsGeneric,
3801        Arg5: JsGeneric,
3802        F: JsFunction<Ret = Ret>
3803            + JsFunction5<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
3804            JsValue,
3805            JsValue,
3806            JsValue,
3807            JsValue,
3808            JsValue,
3809        ) -> JsValue,
3810    >(
3811        this: &Function<F>,
3812        context: &JsValue,
3813        arg1: &Arg1,
3814        arg2: &Arg2,
3815        arg3: &Arg3,
3816        arg4: &Arg4,
3817        arg5: &Arg5,
3818    ) -> Result<Ret, JsValue>;
3819
3820    // Next major: Deprecate, and separately provide provide impl
3821    /// The `call()` method calls a function with a given this value and
3822    /// arguments provided individually.
3823    ///
3824    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3825    ///
3826    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3827    #[wasm_bindgen(method, catch, js_name = call)]
3828    pub fn call6<
3829        Ret: JsGeneric,
3830        Arg1: JsGeneric,
3831        Arg2: JsGeneric,
3832        Arg3: JsGeneric,
3833        Arg4: JsGeneric,
3834        Arg5: JsGeneric,
3835        Arg6: JsGeneric,
3836        F: JsFunction<Ret = Ret>
3837            + JsFunction6<
3838                Arg1 = Arg1,
3839                Arg2 = Arg2,
3840                Arg3 = Arg3,
3841                Arg4 = Arg4,
3842                Arg5 = Arg5,
3843                Arg6 = Arg6,
3844            > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
3845    >(
3846        this: &Function<F>,
3847        context: &JsValue,
3848        arg1: &Arg1,
3849        arg2: &Arg2,
3850        arg3: &Arg3,
3851        arg4: &Arg4,
3852        arg5: &Arg5,
3853        arg6: &Arg6,
3854    ) -> Result<Ret, JsValue>;
3855
3856    // Next major: Deprecate, and separately provide provide impl
3857    /// The `call()` method calls a function with a given this value and
3858    /// arguments provided individually.
3859    ///
3860    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3861    ///
3862    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3863    #[wasm_bindgen(method, catch, js_name = call)]
3864    pub fn call7<
3865        Ret: JsGeneric,
3866        Arg1: JsGeneric,
3867        Arg2: JsGeneric,
3868        Arg3: JsGeneric,
3869        Arg4: JsGeneric,
3870        Arg5: JsGeneric,
3871        Arg6: JsGeneric,
3872        Arg7: JsGeneric,
3873        F: JsFunction<Ret = Ret>
3874            + JsFunction7<
3875                Arg1 = Arg1,
3876                Arg2 = Arg2,
3877                Arg3 = Arg3,
3878                Arg4 = Arg4,
3879                Arg5 = Arg5,
3880                Arg6 = Arg6,
3881                Arg7 = Arg7,
3882            > = fn(
3883            JsValue,
3884            JsValue,
3885            JsValue,
3886            JsValue,
3887            JsValue,
3888            JsValue,
3889            JsValue,
3890        ) -> JsValue,
3891    >(
3892        this: &Function<F>,
3893        context: &JsValue,
3894        arg1: &Arg1,
3895        arg2: &Arg2,
3896        arg3: &Arg3,
3897        arg4: &Arg4,
3898        arg5: &Arg5,
3899        arg6: &Arg6,
3900        arg7: &Arg7,
3901    ) -> Result<Ret, JsValue>;
3902
3903    // Next major: Deprecate, and separately provide provide impl
3904    /// The `call()` method calls a function with a given this value and
3905    /// arguments provided individually.
3906    ///
3907    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3908    ///
3909    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3910    #[wasm_bindgen(method, catch, js_name = call)]
3911    pub fn call8<
3912        Ret: JsGeneric,
3913        Arg1: JsGeneric,
3914        Arg2: JsGeneric,
3915        Arg3: JsGeneric,
3916        Arg4: JsGeneric,
3917        Arg5: JsGeneric,
3918        Arg6: JsGeneric,
3919        Arg7: JsGeneric,
3920        Arg8: JsGeneric,
3921        F: JsFunction8<
3922            Ret = Ret,
3923            Arg1 = Arg1,
3924            Arg2 = Arg2,
3925            Arg3 = Arg3,
3926            Arg4 = Arg4,
3927            Arg5 = Arg5,
3928            Arg6 = Arg6,
3929            Arg7 = Arg7,
3930            Arg8 = Arg8,
3931        > = fn(
3932            JsValue,
3933            JsValue,
3934            JsValue,
3935            JsValue,
3936            JsValue,
3937            JsValue,
3938            JsValue,
3939            JsValue,
3940        ) -> JsValue,
3941    >(
3942        this: &Function<F>,
3943        context: &JsValue,
3944        arg1: &Arg1,
3945        arg2: &Arg2,
3946        arg3: &Arg3,
3947        arg4: &Arg4,
3948        arg5: &Arg5,
3949        arg6: &Arg6,
3950        arg7: &Arg7,
3951        arg8: &Arg8,
3952    ) -> Result<Ret, JsValue>;
3953
3954    /// The `call()` method calls a function with a given this value and
3955    /// arguments provided individually.
3956    ///
3957    /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3958    ///
3959    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3960    #[deprecated]
3961    #[allow(deprecated)]
3962    #[wasm_bindgen(method, catch, js_name = call)]
3963    pub fn call9<
3964        Ret: JsGeneric,
3965        Arg1: JsGeneric,
3966        Arg2: JsGeneric,
3967        Arg3: JsGeneric,
3968        Arg4: JsGeneric,
3969        Arg5: JsGeneric,
3970        Arg6: JsGeneric,
3971        Arg7: JsGeneric,
3972        Arg8: JsGeneric,
3973        F: JsFunction8<
3974            Ret = Ret,
3975            Arg1 = Arg1,
3976            Arg2 = Arg2,
3977            Arg3 = Arg3,
3978            Arg4 = Arg4,
3979            Arg5 = Arg5,
3980            Arg6 = Arg6,
3981            Arg7 = Arg7,
3982            Arg8 = Arg8,
3983        > = fn(
3984            JsValue,
3985            JsValue,
3986            JsValue,
3987            JsValue,
3988            JsValue,
3989            JsValue,
3990            JsValue,
3991            JsValue,
3992        ) -> JsValue,
3993    >(
3994        this: &Function<F>,
3995        context: &JsValue,
3996        arg1: &Arg1,
3997        arg2: &Arg2,
3998        arg3: &Arg3,
3999        arg4: &Arg4,
4000        arg5: &Arg5,
4001        arg6: &Arg6,
4002        arg7: &Arg7,
4003        arg8: &Arg8,
4004        arg9: &JsValue,
4005    ) -> Result<Ret, JsValue>;
4006
4007    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4008    /// with a given sequence of arguments preceding any provided when the new function is called.
4009    ///
4010    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4011    #[cfg(not(js_sys_unstable_apis))]
4012    #[deprecated(note = "Use `Function::bind0` instead.")]
4013    #[allow(deprecated)]
4014    #[wasm_bindgen(method, js_name = bind)]
4015    pub fn bind<T: JsFunction = fn() -> JsValue>(
4016        this: &Function<T>,
4017        context: &JsValue,
4018    ) -> Function<T>;
4019
4020    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4021    /// with a given sequence of arguments preceding any provided when the new function is called.
4022    ///
4023    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4024    ///
4025    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4026    #[wasm_bindgen(method, js_name = bind)]
4027    pub fn bind0<T: JsFunction = fn() -> JsValue>(
4028        this: &Function<T>,
4029        context: &JsValue,
4030    ) -> Function<T>;
4031
4032    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4033    /// with a given sequence of arguments preceding any provided when the new function is called.
4034    ///
4035    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4036    ///
4037    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4038    #[wasm_bindgen(method, js_name = bind)]
4039    pub fn bind1<
4040        Ret: JsGeneric,
4041        Arg1: JsGeneric,
4042        F: JsFunction1<Ret = Ret, Arg1 = Arg1> = fn(JsValue) -> JsValue,
4043    >(
4044        this: &Function<F>,
4045        context: &JsValue,
4046        arg1: &Arg1,
4047    ) -> Function<<F as JsFunction1>::Bind1>;
4048
4049    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4050    /// with a given sequence of arguments preceding any provided when the new function is called.
4051    ///
4052    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4053    ///
4054    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4055    #[wasm_bindgen(method, js_name = bind)]
4056    pub fn bind2<
4057        Ret: JsGeneric,
4058        Arg1: JsGeneric,
4059        Arg2: JsGeneric,
4060        F: JsFunction2<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2> = fn(JsValue, JsValue) -> JsValue,
4061    >(
4062        this: &Function<F>,
4063        context: &JsValue,
4064        arg1: &Arg1,
4065        arg2: &Arg2,
4066    ) -> Function<<F as JsFunction2>::Bind2>;
4067
4068    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4069    /// with a given sequence of arguments preceding any provided when the new function is called.
4070    ///
4071    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4072    ///
4073    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4074    #[wasm_bindgen(method, js_name = bind)]
4075    pub fn bind3<
4076        Ret: JsGeneric,
4077        Arg1: JsGeneric,
4078        Arg2: JsGeneric,
4079        Arg3: JsGeneric,
4080        F: JsFunction3<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
4081            JsValue,
4082            JsValue,
4083            JsValue,
4084        ) -> JsValue,
4085    >(
4086        this: &Function<F>,
4087        context: &JsValue,
4088        arg1: &Arg1,
4089        arg2: &Arg2,
4090        arg3: &Arg3,
4091    ) -> Function<<F as JsFunction3>::Bind3>;
4092
4093    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4094    /// with a given sequence of arguments preceding any provided when the new function is called.
4095    ///
4096    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4097    ///
4098    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4099    #[wasm_bindgen(method, js_name = bind)]
4100    pub fn bind4<
4101        Ret: JsGeneric,
4102        Arg1: JsGeneric,
4103        Arg2: JsGeneric,
4104        Arg3: JsGeneric,
4105        Arg4: JsGeneric,
4106        F: JsFunction4<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
4107            JsValue,
4108            JsValue,
4109            JsValue,
4110            JsValue,
4111        ) -> JsValue,
4112    >(
4113        this: &Function<F>,
4114        context: &JsValue,
4115        arg1: &Arg1,
4116        arg2: &Arg2,
4117        arg3: &Arg3,
4118        arg4: &Arg4,
4119    ) -> Function<<F as JsFunction4>::Bind4>;
4120
4121    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4122    /// with a given sequence of arguments preceding any provided when the new function is called.
4123    ///
4124    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4125    ///
4126    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4127    #[wasm_bindgen(method, js_name = bind)]
4128    pub fn bind5<
4129        Ret: JsGeneric,
4130        Arg1: JsGeneric,
4131        Arg2: JsGeneric,
4132        Arg3: JsGeneric,
4133        Arg4: JsGeneric,
4134        Arg5: JsGeneric,
4135        F: JsFunction5<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4136            JsValue,
4137            JsValue,
4138            JsValue,
4139            JsValue,
4140            JsValue,
4141        ) -> JsValue,
4142    >(
4143        this: &Function<F>,
4144        context: &JsValue,
4145        arg1: &Arg1,
4146        arg2: &Arg2,
4147        arg3: &Arg3,
4148        arg4: &Arg4,
4149        arg5: &Arg5,
4150    ) -> Function<<F as JsFunction5>::Bind5>;
4151
4152    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4153    /// with a given sequence of arguments preceding any provided when the new function is called.
4154    ///
4155    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4156    ///
4157    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4158    #[wasm_bindgen(method, js_name = bind)]
4159    pub fn bind6<
4160        Ret: JsGeneric,
4161        Arg1: JsGeneric,
4162        Arg2: JsGeneric,
4163        Arg3: JsGeneric,
4164        Arg4: JsGeneric,
4165        Arg5: JsGeneric,
4166        Arg6: JsGeneric,
4167        F: JsFunction6<
4168            Ret = Ret,
4169            Arg1 = Arg1,
4170            Arg2 = Arg2,
4171            Arg3 = Arg3,
4172            Arg4 = Arg4,
4173            Arg5 = Arg5,
4174            Arg6 = Arg6,
4175        > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4176    >(
4177        this: &Function<F>,
4178        context: &JsValue,
4179        arg1: &Arg1,
4180        arg2: &Arg2,
4181        arg3: &Arg3,
4182        arg4: &Arg4,
4183        arg5: &Arg5,
4184        arg6: &Arg6,
4185    ) -> Function<<F as JsFunction6>::Bind6>;
4186
4187    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4188    /// with a given sequence of arguments preceding any provided when the new function is called.
4189    ///
4190    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4191    ///
4192    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4193    #[wasm_bindgen(method, js_name = bind)]
4194    pub fn bind7<
4195        Ret: JsGeneric,
4196        Arg1: JsGeneric,
4197        Arg2: JsGeneric,
4198        Arg3: JsGeneric,
4199        Arg4: JsGeneric,
4200        Arg5: JsGeneric,
4201        Arg6: JsGeneric,
4202        Arg7: JsGeneric,
4203        F: JsFunction7<
4204            Ret = Ret,
4205            Arg1 = Arg1,
4206            Arg2 = Arg2,
4207            Arg3 = Arg3,
4208            Arg4 = Arg4,
4209            Arg5 = Arg5,
4210            Arg6 = Arg6,
4211            Arg7 = Arg7,
4212        > = fn(
4213            JsValue,
4214            JsValue,
4215            JsValue,
4216            JsValue,
4217            JsValue,
4218            JsValue,
4219            JsValue,
4220        ) -> JsValue,
4221    >(
4222        this: &Function<F>,
4223        context: &JsValue,
4224        arg1: &Arg1,
4225        arg2: &Arg2,
4226        arg3: &Arg3,
4227        arg4: &Arg4,
4228        arg5: &Arg5,
4229        arg6: &Arg6,
4230        arg7: &Arg7,
4231    ) -> Function<<F as JsFunction7>::Bind7>;
4232
4233    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4234    /// with a given sequence of arguments preceding any provided when the new function is called.
4235    ///
4236    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4237    ///
4238    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4239    #[wasm_bindgen(method, js_name = bind)]
4240    pub fn bind8<
4241        Ret: JsGeneric,
4242        Arg1: JsGeneric,
4243        Arg2: JsGeneric,
4244        Arg3: JsGeneric,
4245        Arg4: JsGeneric,
4246        Arg5: JsGeneric,
4247        Arg6: JsGeneric,
4248        Arg7: JsGeneric,
4249        Arg8: JsGeneric,
4250        F: JsFunction8<
4251            Ret = Ret,
4252            Arg1 = Arg1,
4253            Arg2 = Arg2,
4254            Arg3 = Arg3,
4255            Arg4 = Arg4,
4256            Arg5 = Arg5,
4257            Arg6 = Arg6,
4258            Arg7 = Arg7,
4259            Arg8 = Arg8,
4260        > = fn(
4261            JsValue,
4262            JsValue,
4263            JsValue,
4264            JsValue,
4265            JsValue,
4266            JsValue,
4267            JsValue,
4268            JsValue,
4269        ) -> JsValue,
4270    >(
4271        this: &Function<F>,
4272        context: &JsValue,
4273        arg1: &Arg1,
4274        arg2: &Arg2,
4275        arg3: &Arg3,
4276        arg4: &Arg4,
4277        arg5: &Arg5,
4278        arg6: &Arg6,
4279        arg7: &Arg7,
4280        arg8: &Arg8,
4281    ) -> Function<<F as JsFunction8>::Bind8>;
4282
4283    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4284    /// with a given sequence of arguments preceding any provided when the new function is called.
4285    ///
4286    /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4287    ///
4288    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4289    #[deprecated]
4290    #[allow(deprecated)]
4291    #[wasm_bindgen(method, js_name = bind)]
4292    pub fn bind9<
4293        Ret: JsGeneric,
4294        Arg1: JsGeneric,
4295        Arg2: JsGeneric,
4296        Arg3: JsGeneric,
4297        Arg4: JsGeneric,
4298        Arg5: JsGeneric,
4299        Arg6: JsGeneric,
4300        Arg7: JsGeneric,
4301        Arg8: JsGeneric,
4302        F: JsFunction8<
4303            Ret = Ret,
4304            Arg1 = Arg1,
4305            Arg2 = Arg2,
4306            Arg3 = Arg3,
4307            Arg4 = Arg4,
4308            Arg5 = Arg5,
4309            Arg6 = Arg6,
4310            Arg7 = Arg7,
4311            Arg8 = Arg8,
4312        > = fn(
4313            JsValue,
4314            JsValue,
4315            JsValue,
4316            JsValue,
4317            JsValue,
4318            JsValue,
4319            JsValue,
4320            JsValue,
4321        ) -> JsValue,
4322    >(
4323        this: &Function<F>,
4324        context: &JsValue,
4325        arg1: &Arg1,
4326        arg2: &Arg2,
4327        arg3: &Arg3,
4328        arg4: &Arg4,
4329        arg5: &Arg5,
4330        arg6: &Arg6,
4331        arg7: &Arg7,
4332        arg8: &Arg8,
4333        arg9: &JsValue,
4334    ) -> Function<fn() -> Ret>;
4335
4336    /// The length property indicates the number of arguments expected by the function.
4337    ///
4338    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
4339    #[wasm_bindgen(method, getter)]
4340    pub fn length<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> u32;
4341
4342    /// A Function object's read-only name property indicates the function's
4343    /// name as specified when it was created or "anonymous" for functions
4344    /// created anonymously.
4345    ///
4346    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
4347    #[wasm_bindgen(method, getter)]
4348    pub fn name<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4349
4350    /// The `toString()` method returns a string representing the source code of the function.
4351    ///
4352    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
4353    #[cfg(not(js_sys_unstable_apis))]
4354    #[wasm_bindgen(method, js_name = toString)]
4355    pub fn to_string<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4356}
4357
4358// Basic UpcastFrom impls for Function<T>
4359impl<T: JsFunction> UpcastFrom<Function<T>> for JsValue {}
4360impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<JsValue> {}
4361impl<T: JsFunction> UpcastFrom<Function<T>> for Object {}
4362impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<Object> {}
4363
4364// Blanket trait for Function upcast
4365// Function<T> upcasts to Function<U> when the underlying fn type T upcasts to U.
4366// The fn signature UpcastFrom impls already encode correct variance (covariant return, contravariant args).
4367impl<T: JsFunction, U: JsFunction> UpcastFrom<Function<T>> for Function<U> where U: UpcastFrom<T> {}
4368
4369// len() method for Function<T> using JsFunction::ARITY
4370impl<T: JsFunction> Function<T> {
4371    /// Get the static arity of this function type.
4372    #[allow(clippy::len_without_is_empty)]
4373    pub fn len(&self) -> usize {
4374        T::ARITY
4375    }
4376
4377    /// Returns true if this is a zero-argument function.
4378    pub fn is_empty(&self) -> bool {
4379        T::ARITY == 0
4380    }
4381}
4382
4383// Base traits for function signature types.
4384pub trait JsFunction {
4385    type Ret: JsGeneric;
4386    const ARITY: usize;
4387}
4388
4389pub trait JsFunction1: JsFunction {
4390    type Arg1: JsGeneric;
4391    type Bind1: JsFunction;
4392}
4393pub trait JsFunction2: JsFunction1 {
4394    type Arg2: JsGeneric;
4395    type Bind2: JsFunction;
4396}
4397pub trait JsFunction3: JsFunction2 {
4398    type Arg3: JsGeneric;
4399    type Bind3: JsFunction;
4400}
4401pub trait JsFunction4: JsFunction3 {
4402    type Arg4: JsGeneric;
4403    type Bind4: JsFunction;
4404}
4405pub trait JsFunction5: JsFunction4 {
4406    type Arg5: JsGeneric;
4407    type Bind5: JsFunction;
4408}
4409pub trait JsFunction6: JsFunction5 {
4410    type Arg6: JsGeneric;
4411    type Bind6: JsFunction;
4412}
4413pub trait JsFunction7: JsFunction6 {
4414    type Arg7: JsGeneric;
4415    type Bind7: JsFunction;
4416}
4417pub trait JsFunction8: JsFunction7 {
4418    type Arg8: JsGeneric;
4419    type Bind8: JsFunction;
4420}
4421
4422// Manual impl for fn() -> R
4423impl<Ret: JsGeneric> JsFunction for fn() -> Ret {
4424    type Ret = Ret;
4425    const ARITY: usize = 0;
4426}
4427
4428macro_rules! impl_fn {
4429    () => {
4430        impl_fn!(@impl 1 [Arg1] [
4431            JsFunction1 Arg1 Bind1 {fn() -> Ret}
4432        ]);
4433        impl_fn!(@impl 2 [Arg1 Arg2] [
4434            JsFunction1 Arg1 Bind1 {fn(Arg2) -> Ret}
4435            JsFunction2 Arg2 Bind2 {fn() -> Ret}
4436        ]);
4437        impl_fn!(@impl 3 [Arg1 Arg2 Arg3] [
4438            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3) -> Ret}
4439            JsFunction2 Arg2 Bind2 {fn(Arg3) -> Ret}
4440            JsFunction3 Arg3 Bind3 {fn() -> Ret}
4441        ]);
4442        impl_fn!(@impl 4 [Arg1 Arg2 Arg3 Arg4] [
4443            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4) -> Ret}
4444            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4) -> Ret}
4445            JsFunction3 Arg3 Bind3 {fn(Arg4) -> Ret}
4446            JsFunction4 Arg4 Bind4 {fn() -> Ret}
4447        ]);
4448        impl_fn!(@impl 5 [Arg1 Arg2 Arg3 Arg4 Arg5] [
4449            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5) -> Ret}
4450            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5) -> Ret}
4451            JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5) -> Ret}
4452            JsFunction4 Arg4 Bind4 {fn(Arg5) -> Ret}
4453            JsFunction5 Arg5 Bind5 {fn() -> Ret}
4454        ]);
4455        impl_fn!(@impl 6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [
4456            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6) -> Ret}
4457            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6) -> Ret}
4458            JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6) -> Ret}
4459            JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6) -> Ret}
4460            JsFunction5 Arg5 Bind5 {fn(Arg6) -> Ret}
4461            JsFunction6 Arg6 Bind6 {fn() -> Ret}
4462        ]);
4463        impl_fn!(@impl 7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [
4464            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4465            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4466            JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7) -> Ret}
4467            JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7) -> Ret}
4468            JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7) -> Ret}
4469            JsFunction6 Arg6 Bind6 {fn(Arg7) -> Ret}
4470            JsFunction7 Arg7 Bind7 {fn() -> Ret}
4471        ]);
4472        impl_fn!(@impl 8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [
4473            JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4474            JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4475            JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4476            JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7, Arg8) -> Ret}
4477            JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7, Arg8) -> Ret}
4478            JsFunction6 Arg6 Bind6 {fn(Arg7, Arg8) -> Ret}
4479            JsFunction7 Arg7 Bind7 {fn(Arg8) -> Ret}
4480            JsFunction8 Arg8 Bind8 {fn() -> Ret}
4481        ]);
4482    };
4483
4484    (@impl $arity:literal [$($A:ident)+] [$($trait:ident $arg:ident $bind:ident {$bind_ty:ty})+]) => {
4485        impl<Ret: JsGeneric $(, $A: JsGeneric)+> JsFunction for fn($($A),+) -> Ret {
4486            type Ret = Ret;
4487            const ARITY: usize = $arity;
4488        }
4489
4490        impl_fn!(@traits [$($A)+] [$($trait $arg $bind {$bind_ty})+]);
4491    };
4492
4493    (@traits [$($A:ident)+] []) => {};
4494
4495    (@traits [$($A:ident)+] [$trait:ident $arg:ident $bind:ident {$bind_ty:ty} $($rest:tt)*]) => {
4496        impl<Ret: JsGeneric $(, $A: JsGeneric)+> $trait for fn($($A),+) -> Ret {
4497            type $arg = $arg;
4498            type $bind = $bind_ty;
4499        }
4500
4501        impl_fn!(@traits [$($A)+] [$($rest)*]);
4502    };
4503}
4504
4505impl_fn!();
4506
4507/// Trait for argument tuples that can call or bind a `Function<T>`.
4508pub trait JsArgs<T: JsFunction> {
4509    type BindOutput;
4510    fn apply_call(self, func: &Function<T>, context: &JsValue) -> Result<T::Ret, JsValue>;
4511    fn apply_bind(self, func: &Function<T>, context: &JsValue) -> Self::BindOutput;
4512}
4513
4514// Manual impl for 0-arg
4515impl<Ret: JsGeneric, F: JsFunction<Ret = Ret>> JsArgs<F> for () {
4516    type BindOutput = Function<F>;
4517
4518    #[inline]
4519    fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4520        func.call0(context)
4521    }
4522
4523    #[inline]
4524    fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4525        func.bind0(context)
4526    }
4527}
4528
4529macro_rules! impl_js_args {
4530    ($arity:literal $trait:ident $bind_output:ident [$($A:ident)+] [$($idx:tt)+] $call:ident $bind:ident) => {
4531        impl<Ret: JsGeneric, $($A: JsGeneric,)+ F: $trait<Ret = Ret, $($A = $A,)*>> JsArgs<F> for ($(&$A,)+)
4532        {
4533            type BindOutput = Function<<F as $trait>::$bind_output>;
4534
4535            #[inline]
4536            fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4537                func.$call(context, $(self.$idx),+)
4538            }
4539
4540            #[inline]
4541            fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4542                func.$bind(context, $(self.$idx),+)
4543            }
4544        }
4545    };
4546}
4547
4548impl_js_args!(1 JsFunction1 Bind1 [Arg1] [0] call1 bind1);
4549impl_js_args!(2 JsFunction2 Bind2 [Arg1 Arg2] [0 1] call2 bind2);
4550impl_js_args!(3 JsFunction3 Bind3 [Arg1 Arg2 Arg3] [0 1 2] call3 bind3);
4551impl_js_args!(4 JsFunction4 Bind4 [Arg1 Arg2 Arg3 Arg4] [0 1 2 3] call4 bind4);
4552impl_js_args!(5 JsFunction5 Bind5 [Arg1 Arg2 Arg3 Arg4 Arg5] [0 1 2 3 4] call5 bind5);
4553impl_js_args!(6 JsFunction6 Bind6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [0 1 2 3 4 5] call6 bind6);
4554impl_js_args!(7 JsFunction7 Bind7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [0 1 2 3 4 5 6] call7 bind7);
4555impl_js_args!(8 JsFunction8 Bind8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [0 1 2 3 4 5 6 7] call8 bind8);
4556
4557impl<T: JsFunction> Function<T> {
4558    /// The `call()` method calls a function with a given `this` value and
4559    /// arguments provided as a tuple.
4560    ///
4561    /// This method accepts a tuple of references matching the function's
4562    /// argument types.
4563    ///
4564    /// # Example
4565    ///
4566    /// ```ignore
4567    /// // 0-arg function
4568    /// let f: Function<fn() -> Number> = get_fn();
4569    /// let result = f.call(&JsValue::NULL, ())?;
4570    ///
4571    /// // 1-arg function (note trailing comma for 1-tuple)
4572    /// let f: Function<fn(JsString) -> Number> = get_fn();
4573    /// let result = f.call(&JsValue::NULL, (&name,))?;
4574    ///
4575    /// // 2-arg function
4576    /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4577    /// let result = f.call(&JsValue::NULL, (&name, &flag))?;
4578    /// ```
4579    ///
4580    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4581    #[inline]
4582    pub fn call<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Result<T::Ret, JsValue> {
4583        args.apply_call(self, context)
4584    }
4585
4586    /// The `bind()` method creates a new function that, when called, has its
4587    /// `this` keyword set to the provided value, with a given sequence of
4588    /// arguments preceding any provided when the new function is called.
4589    ///
4590    /// This method accepts a tuple of references to bind.
4591    ///
4592    /// # Example
4593    ///
4594    /// ```ignore
4595    /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4596    ///
4597    /// // Bind no args - same signature
4598    /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4599    ///
4600    /// // Bind one arg (use 1-tuple of references)
4601    /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4602    ///
4603    /// // Bind two args - becomes 0-arg function
4604    /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4605    /// ```
4606    ///
4607    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4608    #[inline]
4609    pub fn bindn<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4610        args.apply_bind(self, context)
4611    }
4612
4613    /// The `bind()` method creates a new function that, when called, has its
4614    /// `this` keyword set to the provided value, with a given sequence of
4615    /// arguments preceding any provided when the new function is called.
4616    ///
4617    /// This method accepts a tuple of references to bind.
4618    ///
4619    /// # Example
4620    ///
4621    /// ```ignore
4622    /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4623    ///
4624    /// // Bind no args - same signature
4625    /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4626    ///
4627    /// // Bind one arg (use 1-tuple of references)
4628    /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4629    ///
4630    /// // Bind two args - becomes 0-arg function
4631    /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4632    /// ```
4633    ///
4634    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4635    #[cfg(js_sys_unstable_apis)]
4636    #[inline]
4637    pub fn bind<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4638        args.apply_bind(self, context)
4639    }
4640}
4641
4642pub trait FunctionIntoClosure: JsFunction {
4643    type ClosureTypeMut: WasmClosure + ?Sized;
4644}
4645
4646macro_rules! impl_function_into_closure {
4647    ( $(($($var:ident)*))* ) => {$(
4648        impl<$($var: FromWasmAbi + JsGeneric,)* R: IntoWasmAbi + JsGeneric> FunctionIntoClosure for fn($($var),*) -> R {
4649            type ClosureTypeMut = dyn FnMut($($var),*) -> R;
4650        }
4651    )*};
4652}
4653
4654impl_function_into_closure! {
4655    ()
4656    (A)
4657    (A B)
4658    (A B C)
4659    (A B C D)
4660    (A B C D E)
4661    (A B C D E F)
4662    (A B C D E F G)
4663    (A B C D E F G H)
4664}
4665
4666impl<F: JsFunction> Function<F> {
4667    /// Convert a borrowed `ScopedClosure` into a typed JavaScript Function reference.
4668    ///
4669    /// The conversion is a direct type-safe conversion and upcast of a
4670    /// closure into its corresponding typed JavaScript Function,
4671    /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4672    ///
4673    /// For transferring ownership to JS, use [`Function::from_closure`].
4674    #[inline]
4675    pub fn closure_ref<'a, C>(closure: &'a ScopedClosure<'_, C>) -> &'a Self
4676    where
4677        F: FunctionIntoClosure,
4678        C: WasmClosure + ?Sized,
4679        <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4680    {
4681        closure.as_js_value().unchecked_ref()
4682    }
4683
4684    /// Convert a Rust closure into a typed JavaScript Function.
4685    ///
4686    /// This function releases ownership of the closure to JS, and provides
4687    /// an owned function handle for the same closure.
4688    ///
4689    /// The conversion is a direct type-safe conversion and upcast of a
4690    /// closure into its corresponding typed JavaScript Function,
4691    /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4692    ///
4693    /// This method is only supported for static closures which do not have
4694    /// borrowed lifetime data, and thus can be released into JS.
4695    ///
4696    /// For borrowed closures, which cannot cede ownership to JS,
4697    /// instead use [`Function::closure_ref`].
4698    #[inline]
4699    pub fn from_closure<C>(closure: ScopedClosure<'static, C>) -> Self
4700    where
4701        F: FunctionIntoClosure,
4702        C: WasmClosure + ?Sized,
4703        <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4704    {
4705        closure.into_js_value().unchecked_into()
4706    }
4707}
4708
4709#[cfg(not(js_sys_unstable_apis))]
4710impl Function {
4711    /// Returns the `Function` value of this JS value if it's an instance of a
4712    /// function.
4713    ///
4714    /// If this JS value is not an instance of a function then this returns
4715    /// `None`.
4716    #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
4717    pub fn try_from(val: &JsValue) -> Option<&Function> {
4718        val.dyn_ref()
4719    }
4720}
4721
4722#[cfg(feature = "unsafe-eval")]
4723impl Default for Function {
4724    fn default() -> Self {
4725        Self::new_no_args("")
4726    }
4727}
4728
4729// Generator
4730#[wasm_bindgen]
4731extern "C" {
4732    #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
4733    #[derive(Clone, Debug, PartialEq, Eq)]
4734    pub type Generator<T = JsValue>;
4735
4736    /// The `next()` method returns an object with two properties done and value.
4737    /// You can also provide a parameter to the next method to send a value to the generator.
4738    ///
4739    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4740    #[cfg(not(js_sys_unstable_apis))]
4741    #[wasm_bindgen(method, catch)]
4742    pub fn next<T>(this: &Generator<T>, value: &T) -> Result<JsValue, JsValue>;
4743
4744    /// The `next()` method returns an object with two properties done and value.
4745    /// You can also provide a parameter to the next method to send a value to the generator.
4746    ///
4747    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4748    #[cfg(js_sys_unstable_apis)]
4749    #[wasm_bindgen(method, catch, js_name = next)]
4750    pub fn next<T: FromWasmAbi>(this: &Generator<T>, value: &T)
4751        -> Result<IteratorNext<T>, JsValue>;
4752
4753    // Next major: deprecate
4754    /// The `next()` method returns an object with two properties done and value.
4755    /// You can also provide a parameter to the next method to send a value to the generator.
4756    ///
4757    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4758    #[wasm_bindgen(method, catch)]
4759    pub fn next_iterator<T: FromWasmAbi>(
4760        this: &Generator<T>,
4761        value: &T,
4762    ) -> Result<IteratorNext<T>, JsValue>;
4763
4764    /// The `return()` method returns the given value and finishes the generator.
4765    ///
4766    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4767    #[cfg(not(js_sys_unstable_apis))]
4768    #[wasm_bindgen(method, js_name = "return")]
4769    pub fn return_<T>(this: &Generator<T>, value: &T) -> JsValue;
4770
4771    /// The `return()` method returns the given value and finishes the generator.
4772    ///
4773    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4774    #[cfg(js_sys_unstable_apis)]
4775    #[wasm_bindgen(method, catch, js_name = "return")]
4776    pub fn return_<T: FromWasmAbi>(
4777        this: &Generator<T>,
4778        value: &T,
4779    ) -> Result<IteratorNext<T>, JsValue>;
4780
4781    // Next major: deprecate
4782    /// The `return()` method returns the given value and finishes the generator.
4783    ///
4784    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4785    #[wasm_bindgen(method, catch, js_name = "return")]
4786    pub fn try_return<T: FromWasmAbi>(
4787        this: &Generator<T>,
4788        value: &T,
4789    ) -> Result<IteratorNext<T>, JsValue>;
4790
4791    /// The `throw()` method resumes the execution of a generator by throwing an error into it
4792    /// and returns an object with two properties done and value.
4793    ///
4794    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4795    #[cfg(not(js_sys_unstable_apis))]
4796    #[wasm_bindgen(method, catch)]
4797    pub fn throw<T>(this: &Generator<T>, error: &Error) -> Result<JsValue, JsValue>;
4798
4799    /// The `throw()` method resumes the execution of a generator by throwing an error into it
4800    /// and returns an object with two properties done and value.
4801    ///
4802    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4803    #[cfg(js_sys_unstable_apis)]
4804    #[wasm_bindgen(method, catch, js_name = throw)]
4805    pub fn throw<T: FromWasmAbi>(
4806        this: &Generator<T>,
4807        error: &JsValue,
4808    ) -> Result<IteratorNext<T>, JsValue>;
4809
4810    // Next major: deprecate
4811    /// The `throw()` method resumes the execution of a generator by throwing an error into it
4812    /// and returns an object with two properties done and value.
4813    ///
4814    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4815    #[wasm_bindgen(method, catch, js_name = throw)]
4816    pub fn throw_value<T: FromWasmAbi>(
4817        this: &Generator<T>,
4818        error: &JsValue,
4819    ) -> Result<IteratorNext<T>, JsValue>;
4820}
4821
4822impl<T: FromWasmAbi> Iterable for Generator<T> {
4823    type Item = T;
4824}
4825
4826// AsyncGenerator
4827#[wasm_bindgen]
4828extern "C" {
4829    #[wasm_bindgen(extends = Object, typescript_type = "AsyncGenerator<any, any, any>")]
4830    #[derive(Clone, Debug, PartialEq, Eq)]
4831    pub type AsyncGenerator<T = JsValue>;
4832
4833    /// The `next()` method returns an object with two properties done and value.
4834    /// You can also provide a parameter to the next method to send a value to the generator.
4835    ///
4836    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/next)
4837    #[wasm_bindgen(method, catch)]
4838    pub fn next<T>(
4839        this: &AsyncGenerator<T>,
4840        value: &T,
4841    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4842
4843    /// The `return()` method returns the given value and finishes the generator.
4844    ///
4845    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/return)
4846    #[wasm_bindgen(method, js_name = "return", catch)]
4847    pub fn return_<T>(
4848        this: &AsyncGenerator<T>,
4849        value: &T,
4850    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4851
4852    /// The `throw()` method resumes the execution of a generator by throwing an error into it
4853    /// and returns an object with two properties done and value.
4854    ///
4855    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/throw)
4856    #[wasm_bindgen(method, catch)]
4857    pub fn throw<T>(
4858        this: &AsyncGenerator<T>,
4859        error: &JsValue,
4860    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4861}
4862
4863impl<T: FromWasmAbi> AsyncIterable for AsyncGenerator<T> {
4864    type Item = T;
4865}
4866
4867// Map
4868#[wasm_bindgen]
4869extern "C" {
4870    #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
4871    #[derive(Clone, Debug, PartialEq, Eq)]
4872    pub type Map<K = JsValue, V = JsValue>;
4873
4874    /// The Map object holds key-value pairs. Any value (both objects and
4875    /// primitive values) maybe used as either a key or a value.
4876    ///
4877    /// **Note:** Consider using [`Map::new_typed`] for typing support.
4878    ///
4879    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4880    #[cfg(not(js_sys_unstable_apis))]
4881    #[wasm_bindgen(constructor)]
4882    pub fn new() -> Map;
4883
4884    /// The Map object holds key-value pairs. Any value (both objects and
4885    /// primitive values) maybe used as either a key or a value.
4886    ///
4887    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4888    #[cfg(js_sys_unstable_apis)]
4889    #[wasm_bindgen(constructor)]
4890    pub fn new<K, V>() -> Map<K, V>;
4891
4892    // Next major: deprecate
4893    /// The Map object holds key-value pairs. Any value (both objects and
4894    /// primitive values) maybe used as either a key or a value.
4895    ///
4896    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4897    #[wasm_bindgen(constructor)]
4898    pub fn new_typed<K, V>() -> Map<K, V>;
4899
4900    /// The Map object holds key-value pairs. Any value (both objects and
4901    /// primitive values) maybe used as either a key or a value.
4902    ///
4903    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4904    #[wasm_bindgen(constructor, js_name = new)]
4905    pub fn new_from_entries<K, V, I: Iterable<Item = ArrayTuple<(K, V)>>>(entries: &I)
4906        -> Map<K, V>;
4907
4908    /// The `clear()` method removes all elements from a Map object.
4909    ///
4910    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
4911    #[wasm_bindgen(method)]
4912    pub fn clear<K, V>(this: &Map<K, V>);
4913
4914    /// The `delete()` method removes the specified element from a Map object.
4915    ///
4916    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
4917    #[wasm_bindgen(method)]
4918    pub fn delete<K, V>(this: &Map<K, V>, key: &K) -> bool;
4919
4920    /// The `forEach()` method executes a provided function once per each
4921    /// key/value pair in the Map object, in insertion order.
4922    /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
4923    /// # Examples
4924    /// ```
4925    /// let js_map = Map::new();
4926    /// js_map.for_each(&mut |value, key| {
4927    ///     // Do something here...
4928    /// })
4929    /// ```
4930    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
4931    #[wasm_bindgen(method, js_name = forEach)]
4932    pub fn for_each<K, V>(this: &Map<K, V>, callback: &mut dyn FnMut(V, K));
4933
4934    /// The `forEach()` method executes a provided function once per each
4935    /// key/value pair in the Map object, in insertion order. _(Fallible variation)_
4936    /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
4937    /// # Examples
4938    /// ```
4939    /// let js_map = Map::new();
4940    /// js_map.for_each(&mut |value, key| {
4941    ///     // Do something here...
4942    /// })
4943    /// ```
4944    ///
4945    /// **Note:** Consider using [`Map::try_for_each`] if the callback might throw an error.
4946    ///
4947    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
4948    #[wasm_bindgen(method, js_name = forEach, catch)]
4949    pub fn try_for_each<'a, K, V>(
4950        this: &Map<K, V>,
4951        callback: &ImmediateClosure<'a, dyn FnMut(V, K) -> Result<(), JsError> + 'a>,
4952    ) -> Result<(), JsValue>;
4953
4954    /// The `get()` method returns a specified element from a Map object.
4955    /// Returns `undefined` if the key is not found.
4956    ///
4957    /// **Note:** Consider using [`Map::get_checked`] to get an `Option<V>` instead.
4958    ///
4959    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4960    #[cfg(not(js_sys_unstable_apis))]
4961    #[wasm_bindgen(method)]
4962    pub fn get<K, V>(this: &Map<K, V>, key: &K) -> V;
4963
4964    /// The `get()` method returns a specified element from a Map object.
4965    /// Returns `None` if the key is not found.
4966    ///
4967    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4968    #[cfg(js_sys_unstable_apis)]
4969    #[wasm_bindgen(method)]
4970    pub fn get<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
4971
4972    /// The `get()` method returns a specified element from a Map object.
4973    /// Returns `None` if the key is not found.
4974    ///
4975    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4976    #[wasm_bindgen(method, js_name = get)]
4977    pub fn get_checked<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
4978
4979    /// The `has()` method returns a boolean indicating whether an element with
4980    /// the specified key exists or not.
4981    ///
4982    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
4983    #[wasm_bindgen(method)]
4984    pub fn has<K, V>(this: &Map<K, V>, key: &K) -> bool;
4985
4986    /// The `set()` method adds or updates an element with a specified key
4987    /// and value to a Map object.
4988    ///
4989    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
4990    #[wasm_bindgen(method)]
4991    pub fn set<K, V>(this: &Map<K, V>, key: &K, value: &V) -> Map<K, V>;
4992
4993    /// The value of size is an integer representing how many entries
4994    /// the Map object has. A set accessor function for size is undefined;
4995    /// you can not change this property.
4996    ///
4997    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
4998    #[wasm_bindgen(method, getter)]
4999    pub fn size<K, V>(this: &Map<K, V>) -> u32;
5000}
5001
5002impl Default for Map<JsValue, JsValue> {
5003    fn default() -> Self {
5004        Self::new()
5005    }
5006}
5007
5008// Map Iterator
5009#[wasm_bindgen]
5010extern "C" {
5011    /// The `entries()` method returns a new Iterator object that contains
5012    /// the [key, value] pairs for each element in the Map object in
5013    /// insertion order.
5014    ///
5015    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5016    #[cfg(not(js_sys_unstable_apis))]
5017    #[wasm_bindgen(method)]
5018    pub fn entries<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator;
5019
5020    /// The `entries()` method returns a new Iterator object that contains
5021    /// the [key, value] pairs for each element in the Map object in
5022    /// insertion order.
5023    ///
5024    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5025    #[cfg(js_sys_unstable_apis)]
5026    #[wasm_bindgen(method, js_name = entries)]
5027    pub fn entries<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5028        this: &Map<K, V>,
5029    ) -> Iterator<ArrayTuple<(K, V)>>;
5030
5031    // Next major: deprecate
5032    /// The `entries()` method returns a new Iterator object that contains
5033    /// the [key, value] pairs for each element in the Map object in
5034    /// insertion order.
5035    ///
5036    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5037    #[wasm_bindgen(method, js_name = entries)]
5038    pub fn entries_typed<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5039        this: &Map<K, V>,
5040    ) -> Iterator<ArrayTuple<(K, V)>>;
5041
5042    /// The `keys()` method returns a new Iterator object that contains the
5043    /// keys for each element in the Map object in insertion order.
5044    ///
5045    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
5046    #[wasm_bindgen(method)]
5047    pub fn keys<K: FromWasmAbi, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<K>;
5048
5049    /// The `values()` method returns a new Iterator object that contains the
5050    /// values for each element in the Map object in insertion order.
5051    ///
5052    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values)
5053    #[wasm_bindgen(method)]
5054    pub fn values<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<V>;
5055}
5056
5057impl<K, V> Iterable for Map<K, V> {
5058    type Item = ArrayTuple<(K, V)>;
5059}
5060
5061// Iterator
5062#[wasm_bindgen]
5063extern "C" {
5064    /// Any object that conforms to the JS iterator protocol. For example,
5065    /// something returned by `myArray[Symbol.iterator]()`.
5066    ///
5067    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5068    #[derive(Clone, Debug)]
5069    #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
5070    pub type Iterator<T = JsValue>;
5071
5072    /// The `next()` method always has to return an object with appropriate
5073    /// properties including done and value. If a non-object value gets returned
5074    /// (such as false or undefined), a TypeError ("iterator.next() returned a
5075    /// non-object value") will be thrown.
5076    #[wasm_bindgen(catch, method)]
5077    pub fn next<T: FromWasmAbi>(this: &Iterator<T>) -> Result<IteratorNext<T>, JsValue>;
5078}
5079
5080impl<T> UpcastFrom<Iterator<T>> for Object {}
5081
5082impl Iterator {
5083    fn looks_like_iterator(it: &JsValue) -> bool {
5084        #[wasm_bindgen]
5085        extern "C" {
5086            type MaybeIterator;
5087
5088            #[wasm_bindgen(method, getter)]
5089            fn next(this: &MaybeIterator) -> JsValue;
5090        }
5091
5092        if !it.is_object() {
5093            return false;
5094        }
5095
5096        let it = it.unchecked_ref::<MaybeIterator>();
5097
5098        it.next().is_function()
5099    }
5100}
5101
5102// iterators in JS are themselves iterable
5103impl<T> Iterable for Iterator<T> {
5104    type Item = T;
5105}
5106
5107// Async Iterator
5108#[wasm_bindgen]
5109extern "C" {
5110    /// Any object that conforms to the JS async iterator protocol. For example,
5111    /// something returned by `myObject[Symbol.asyncIterator]()`.
5112    ///
5113    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
5114    #[derive(Clone, Debug)]
5115    #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>")]
5116    pub type AsyncIterator<T = JsValue>;
5117
5118    /// The `next()` method always has to return a Promise which resolves to an object
5119    /// with appropriate properties including done and value. If a non-object value
5120    /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5121    /// returned a non-object value") will be thrown.
5122    #[cfg(not(js_sys_unstable_apis))]
5123    #[wasm_bindgen(catch, method)]
5124    pub fn next<T>(this: &AsyncIterator<T>) -> Result<Promise, JsValue>;
5125
5126    /// The `next()` method always has to return a Promise which resolves to an object
5127    /// with appropriate properties including done and value. If a non-object value
5128    /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5129    /// returned a non-object value") will be thrown.
5130    #[cfg(js_sys_unstable_apis)]
5131    #[wasm_bindgen(catch, method, js_name = next)]
5132    pub fn next<T: FromWasmAbi>(
5133        this: &AsyncIterator<T>,
5134    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5135
5136    // Next major: deprecate
5137    /// The `next()` method always has to return a Promise which resolves to an object
5138    /// with appropriate properties including done and value. If a non-object value
5139    /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5140    /// returned a non-object value") will be thrown.
5141    #[wasm_bindgen(catch, method, js_name = next)]
5142    pub fn next_iterator<T: FromWasmAbi>(
5143        this: &AsyncIterator<T>,
5144    ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5145}
5146
5147impl<T> UpcastFrom<AsyncIterator<T>> for Object {}
5148
5149// iterators in JS are themselves iterable
5150impl<T> AsyncIterable for AsyncIterator<T> {
5151    type Item = T;
5152}
5153
5154/// An iterator over the JS `Symbol.iterator` iteration protocol.
5155///
5156/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
5157pub struct Iter<'a, T> {
5158    js: &'a Iterator<T>,
5159    state: IterState,
5160}
5161
5162/// An iterator over the JS `Symbol.iterator` iteration protocol.
5163///
5164/// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
5165pub struct IntoIter<T = JsValue> {
5166    js: Iterator<T>,
5167    state: IterState,
5168}
5169
5170struct IterState {
5171    done: bool,
5172}
5173
5174impl<'a, T: FromWasmAbi + JsGeneric> IntoIterator for &'a Iterator<T> {
5175    type Item = Result<T, JsValue>;
5176    type IntoIter = Iter<'a, T>;
5177
5178    fn into_iter(self) -> Iter<'a, T> {
5179        Iter {
5180            js: self,
5181            state: IterState::new(),
5182        }
5183    }
5184}
5185
5186impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for Iter<'_, T> {
5187    type Item = Result<T, JsValue>;
5188
5189    fn next(&mut self) -> Option<Self::Item> {
5190        self.state.next(self.js)
5191    }
5192}
5193
5194impl<T: FromWasmAbi + JsGeneric> IntoIterator for Iterator<T> {
5195    type Item = Result<T, JsValue>;
5196    type IntoIter = IntoIter<T>;
5197
5198    fn into_iter(self) -> IntoIter<T> {
5199        IntoIter {
5200            js: self,
5201            state: IterState::new(),
5202        }
5203    }
5204}
5205
5206impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for IntoIter<T> {
5207    type Item = Result<T, JsValue>;
5208
5209    fn next(&mut self) -> Option<Self::Item> {
5210        self.state.next(&self.js)
5211    }
5212}
5213
5214impl IterState {
5215    fn new() -> IterState {
5216        IterState { done: false }
5217    }
5218
5219    fn next<T: FromWasmAbi + JsGeneric>(&mut self, js: &Iterator<T>) -> Option<Result<T, JsValue>> {
5220        if self.done {
5221            return None;
5222        }
5223        let next = match js.next() {
5224            Ok(val) => val,
5225            Err(e) => {
5226                self.done = true;
5227                return Some(Err(e));
5228            }
5229        };
5230        if next.done() {
5231            self.done = true;
5232            None
5233        } else {
5234            Some(Ok(next.value()))
5235        }
5236    }
5237}
5238
5239/// Create an iterator over `val` using the JS iteration protocol and
5240/// `Symbol.iterator`.
5241// #[cfg(not(js_sys_unstable_apis))]
5242pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter<JsValue>>, JsValue> {
5243    let iter_sym = Symbol::iterator();
5244
5245    let iter_fn = Reflect::get_symbol::<Object>(val.unchecked_ref(), iter_sym.as_ref())?;
5246    let iter_fn: Function = match iter_fn.dyn_into() {
5247        Ok(iter_fn) => iter_fn,
5248        Err(_) => return Ok(None),
5249    };
5250
5251    let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
5252        Ok(it) => it,
5253        Err(_) => return Ok(None),
5254    };
5255
5256    Ok(Some(it.into_iter()))
5257}
5258
5259/// Trait for JavaScript types that implement the iterable protocol via `Symbol.iterator`.
5260///
5261/// Types implementing this trait can be iterated over using JavaScript's iteration
5262/// protocol. The `Item` associated type specifies the type of values yielded.
5263///
5264/// ## Built-in Iterables
5265///
5266/// Many `js-sys` collection types implement `Iterable` out of the box:
5267///
5268/// ```ignore
5269/// use js_sys::{Array, Map, Set};
5270///
5271/// // Array<T> yields T
5272/// let arr: Array<Number> = get_numbers();
5273/// for value in arr.iter() {
5274///     let num: Number = value?;
5275/// }
5276///
5277/// // Map<K, V> yields Array (key-value pairs)
5278/// let map: Map<JsString, Number> = get_map();
5279/// for entry in map.iter() {
5280///     let pair: Array = entry?;
5281/// }
5282///
5283/// // Set<T> yields T
5284/// let set: Set<JsString> = get_set();
5285/// for value in set.iter() {
5286///     let s: JsString = value?;
5287/// }
5288/// ```
5289///
5290/// ## Typing Foreign Iterators
5291///
5292/// If you have a JavaScript value that implements the iterator protocol (has a `next()`
5293/// method) but isn't a built-in type, you can use [`JsCast`] to cast it to [`Iterator<T>`]:
5294///
5295/// ```ignore
5296/// use js_sys::Iterator;
5297/// use wasm_bindgen::JsCast;
5298///
5299/// // For a value you know implements the iterator protocol
5300/// fn process_iterator(js_iter: JsValue) {
5301///     // Checked cast - returns None if not an iterator
5302///     if let Some(iter) = js_iter.dyn_ref::<Iterator<Number>>() {
5303///         for value in iter.into_iter() {
5304///             let num: Number = value.unwrap();
5305///             // ...
5306///         }
5307///     }
5308/// }
5309///
5310/// // Or with unchecked cast when you're certain of the type
5311/// fn process_known_iterator(js_iter: JsValue) {
5312///     let iter: &Iterator<JsString> = js_iter.unchecked_ref();
5313///     for value in iter.into_iter() {
5314///         let s: JsString = value.unwrap();
5315///         // ...
5316///     }
5317/// }
5318/// ```
5319///
5320/// ## Using with `JsValue`
5321///
5322/// For dynamic or unknown iterables, use [`try_iter`] which returns an untyped iterator:
5323///
5324/// ```ignore
5325/// fn iterate_unknown(val: &JsValue) -> Result<(), JsValue> {
5326///     if let Some(iter) = js_sys::try_iter(val)? {
5327///         for item in iter {
5328///             let value: JsValue = item?;
5329///             // Handle dynamically...
5330///         }
5331///     }
5332///     Ok(())
5333/// }
5334/// ```
5335///
5336/// [`JsCast`]: wasm_bindgen::JsCast
5337/// [`Iterator<T>`]: Iterator
5338/// [`try_iter`]: crate::try_iter
5339pub trait Iterable {
5340    /// The type of values yielded by this iterable.
5341    type Item;
5342}
5343
5344impl<T: Iterable> Iterable for &T {
5345    type Item = T::Item;
5346}
5347
5348/// Trait for types known to implement the iterator protocol on Symbol.asyncIterator
5349pub trait AsyncIterable {
5350    type Item;
5351}
5352
5353impl<T: AsyncIterable> AsyncIterable for &T {
5354    type Item = T::Item;
5355}
5356
5357impl AsyncIterable for JsValue {
5358    type Item = JsValue;
5359}
5360
5361// IteratorNext
5362#[wasm_bindgen]
5363extern "C" {
5364    /// The result of calling `next()` on a JS iterator.
5365    ///
5366    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5367    #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
5368    #[derive(Clone, Debug, PartialEq, Eq)]
5369    pub type IteratorNext<T = JsValue>;
5370
5371    /// Has the value `true` if the iterator is past the end of the iterated
5372    /// sequence. In this case value optionally specifies the return value of
5373    /// the iterator.
5374    ///
5375    /// Has the value `false` if the iterator was able to produce the next value
5376    /// in the sequence. This is equivalent of not specifying the done property
5377    /// altogether.
5378    #[wasm_bindgen(method, getter)]
5379    pub fn done<T>(this: &IteratorNext<T>) -> bool;
5380
5381    /// Any JavaScript value returned by the iterator. Can be omitted when done
5382    /// is true.
5383    #[wasm_bindgen(method, getter)]
5384    pub fn value<T>(this: &IteratorNext<T>) -> T;
5385}
5386
5387#[allow(non_snake_case)]
5388pub mod Math {
5389    use super::*;
5390
5391    // Math
5392    #[wasm_bindgen]
5393    extern "C" {
5394        /// The `Math.abs()` function returns the absolute value of a number, that is
5395        /// Math.abs(x) = |x|
5396        ///
5397        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
5398        #[wasm_bindgen(js_namespace = Math)]
5399        pub fn abs(x: f64) -> f64;
5400
5401        /// The `Math.acos()` function returns the arccosine (in radians) of a
5402        /// number, that is ∀x∊[-1;1]
5403        /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
5404        ///
5405        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
5406        #[wasm_bindgen(js_namespace = Math)]
5407        pub fn acos(x: f64) -> f64;
5408
5409        /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
5410        /// number, that is ∀x ≥ 1
5411        /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
5412        ///
5413        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
5414        #[wasm_bindgen(js_namespace = Math)]
5415        pub fn acosh(x: f64) -> f64;
5416
5417        /// The `Math.asin()` function returns the arcsine (in radians) of a
5418        /// number, that is ∀x ∊ [-1;1]
5419        /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
5420        ///
5421        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
5422        #[wasm_bindgen(js_namespace = Math)]
5423        pub fn asin(x: f64) -> f64;
5424
5425        /// The `Math.asinh()` function returns the hyperbolic arcsine of a
5426        /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
5427        ///
5428        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
5429        #[wasm_bindgen(js_namespace = Math)]
5430        pub fn asinh(x: f64) -> f64;
5431
5432        /// The `Math.atan()` function returns the arctangent (in radians) of a
5433        /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
5434        /// tan(y) = x
5435        #[wasm_bindgen(js_namespace = Math)]
5436        pub fn atan(x: f64) -> f64;
5437
5438        /// The `Math.atan2()` function returns the arctangent of the quotient of
5439        /// its arguments.
5440        ///
5441        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
5442        #[wasm_bindgen(js_namespace = Math)]
5443        pub fn atan2(y: f64, x: f64) -> f64;
5444
5445        /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
5446        /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
5447        /// tanh(y) = x
5448        ///
5449        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
5450        #[wasm_bindgen(js_namespace = Math)]
5451        pub fn atanh(x: f64) -> f64;
5452
5453        /// The `Math.cbrt() `function returns the cube root of a number, that is
5454        /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
5455        ///
5456        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
5457        #[wasm_bindgen(js_namespace = Math)]
5458        pub fn cbrt(x: f64) -> f64;
5459
5460        /// The `Math.ceil()` function returns the smallest integer greater than
5461        /// or equal to a given number.
5462        ///
5463        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
5464        #[wasm_bindgen(js_namespace = Math)]
5465        pub fn ceil(x: f64) -> f64;
5466
5467        /// The `Math.clz32()` function returns the number of leading zero bits in
5468        /// the 32-bit binary representation of a number.
5469        ///
5470        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
5471        #[wasm_bindgen(js_namespace = Math)]
5472        pub fn clz32(x: i32) -> u32;
5473
5474        /// The `Math.cos()` static function returns the cosine of the specified angle,
5475        /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
5476        ///
5477        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
5478        #[wasm_bindgen(js_namespace = Math)]
5479        pub fn cos(x: f64) -> f64;
5480
5481        /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
5482        /// that can be expressed using the constant e.
5483        ///
5484        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
5485        #[wasm_bindgen(js_namespace = Math)]
5486        pub fn cosh(x: f64) -> f64;
5487
5488        /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
5489        /// (also known as Napier's constant), the base of the natural logarithms.
5490        ///
5491        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
5492        #[wasm_bindgen(js_namespace = Math)]
5493        pub fn exp(x: f64) -> f64;
5494
5495        /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
5496        /// natural logarithms.
5497        ///
5498        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
5499        #[wasm_bindgen(js_namespace = Math)]
5500        pub fn expm1(x: f64) -> f64;
5501
5502        /// The `Math.floor()` function returns the largest integer less than or
5503        /// equal to a given number.
5504        ///
5505        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
5506        #[wasm_bindgen(js_namespace = Math)]
5507        pub fn floor(x: f64) -> f64;
5508
5509        /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
5510        /// of a Number.
5511        ///
5512        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
5513        #[wasm_bindgen(js_namespace = Math)]
5514        pub fn fround(x: f64) -> f32;
5515
5516        /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
5517        ///
5518        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
5519        #[wasm_bindgen(js_namespace = Math)]
5520        pub fn hypot(x: f64, y: f64) -> f64;
5521
5522        /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
5523        /// two parameters.
5524        ///
5525        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
5526        #[wasm_bindgen(js_namespace = Math)]
5527        pub fn imul(x: i32, y: i32) -> i32;
5528
5529        /// The `Math.log()` function returns the natural logarithm (base e) of a number.
5530        /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
5531        ///
5532        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
5533        #[wasm_bindgen(js_namespace = Math)]
5534        pub fn log(x: f64) -> f64;
5535
5536        /// The `Math.log10()` function returns the base 10 logarithm of a number.
5537        ///
5538        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
5539        #[wasm_bindgen(js_namespace = Math)]
5540        pub fn log10(x: f64) -> f64;
5541
5542        /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
5543        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
5544        #[wasm_bindgen(js_namespace = Math)]
5545        pub fn log1p(x: f64) -> f64;
5546
5547        /// The `Math.log2()` function returns the base 2 logarithm of a number.
5548        ///
5549        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
5550        #[wasm_bindgen(js_namespace = Math)]
5551        pub fn log2(x: f64) -> f64;
5552
5553        /// The `Math.max()` function returns the largest of two numbers.
5554        ///
5555        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
5556        #[wasm_bindgen(js_namespace = Math)]
5557        pub fn max(x: f64, y: f64) -> f64;
5558
5559        /// The static function `Math.min()` returns the lowest-valued number passed into it.
5560        ///
5561        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
5562        #[wasm_bindgen(js_namespace = Math)]
5563        pub fn min(x: f64, y: f64) -> f64;
5564
5565        /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
5566        ///
5567        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
5568        #[wasm_bindgen(js_namespace = Math)]
5569        pub fn pow(base: f64, exponent: f64) -> f64;
5570
5571        /// The `Math.random()` function returns a floating-point, pseudo-random number
5572        /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
5573        /// over that range — which you can then scale to your desired range.
5574        /// The implementation selects the initial seed to the random number generation algorithm;
5575        /// it cannot be chosen or reset by the user.
5576        ///
5577        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
5578        #[wasm_bindgen(js_namespace = Math)]
5579        pub fn random() -> f64;
5580
5581        /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
5582        ///
5583        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
5584        #[wasm_bindgen(js_namespace = Math)]
5585        pub fn round(x: f64) -> f64;
5586
5587        /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
5588        /// positive, negative or zero.
5589        ///
5590        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
5591        #[wasm_bindgen(js_namespace = Math)]
5592        pub fn sign(x: f64) -> f64;
5593
5594        /// The `Math.sin()` function returns the sine of a number.
5595        ///
5596        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
5597        #[wasm_bindgen(js_namespace = Math)]
5598        pub fn sin(x: f64) -> f64;
5599
5600        /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
5601        /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
5602        ///
5603        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
5604        #[wasm_bindgen(js_namespace = Math)]
5605        pub fn sinh(x: f64) -> f64;
5606
5607        /// The `Math.sqrt()` function returns the square root of a number, that is
5608        /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
5609        ///
5610        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
5611        #[wasm_bindgen(js_namespace = Math)]
5612        pub fn sqrt(x: f64) -> f64;
5613
5614        /// The `Math.tan()` function returns the tangent of a number.
5615        ///
5616        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
5617        #[wasm_bindgen(js_namespace = Math)]
5618        pub fn tan(x: f64) -> f64;
5619
5620        /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
5621        /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
5622        ///
5623        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
5624        #[wasm_bindgen(js_namespace = Math)]
5625        pub fn tanh(x: f64) -> f64;
5626
5627        /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
5628        /// digits.
5629        ///
5630        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
5631        #[wasm_bindgen(js_namespace = Math)]
5632        pub fn trunc(x: f64) -> f64;
5633
5634        /// The `Math.PI` property represents the ratio of the circumference of a circle to its diameter,
5635        /// approximately 3.14159.
5636        ///
5637        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI)
5638        #[wasm_bindgen(thread_local_v2, js_namespace = Math)]
5639        pub static PI: f64;
5640    }
5641}
5642
5643// Number.
5644#[wasm_bindgen]
5645extern "C" {
5646    #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
5647    #[derive(Clone, PartialEq)]
5648    pub type Number;
5649
5650    /// The `Number.isFinite()` method determines whether the passed value is a finite number.
5651    ///
5652    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
5653    #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
5654    pub fn is_finite(value: &JsValue) -> bool;
5655
5656    /// The `Number.isInteger()` method determines whether the passed value is an integer.
5657    ///
5658    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
5659    #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
5660    pub fn is_integer(value: &JsValue) -> bool;
5661
5662    /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
5663    /// It is a more robust version of the original, global isNaN().
5664    ///
5665    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
5666    #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
5667    pub fn is_nan(value: &JsValue) -> bool;
5668
5669    /// The `Number.isSafeInteger()` method determines whether the provided value is a number
5670    /// that is a safe integer.
5671    ///
5672    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
5673    #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
5674    pub fn is_safe_integer(value: &JsValue) -> bool;
5675
5676    /// The `Number` JavaScript object is a wrapper object allowing
5677    /// you to work with numerical values. A `Number` object is
5678    /// created using the `Number()` constructor.
5679    ///
5680    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
5681    #[cfg(not(js_sys_unstable_apis))]
5682    #[wasm_bindgen(constructor)]
5683    #[deprecated(note = "recommended to use `Number::from` instead")]
5684    #[allow(deprecated)]
5685    pub fn new(value: &JsValue) -> Number;
5686
5687    #[wasm_bindgen(constructor)]
5688    fn new_from_str(value: &str) -> Number;
5689
5690    /// The `Number.parseInt()` method parses a string argument and returns an
5691    /// integer of the specified radix or base.
5692    ///
5693    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
5694    #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
5695    pub fn parse_int(text: &str, radix: u8) -> f64;
5696
5697    /// The `Number.parseFloat()` method parses a string argument and returns a
5698    /// floating point number.
5699    ///
5700    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
5701    #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
5702    pub fn parse_float(text: &str) -> f64;
5703
5704    /// The `toLocaleString()` method returns a string with a language sensitive
5705    /// representation of this number.
5706    ///
5707    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
5708    #[cfg(not(js_sys_unstable_apis))]
5709    #[wasm_bindgen(method, js_name = toLocaleString)]
5710    pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
5711
5712    /// The `toLocaleString()` method returns a string with a language sensitive
5713    /// representation of this number.
5714    ///
5715    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
5716    #[cfg(js_sys_unstable_apis)]
5717    #[wasm_bindgen(method, js_name = toLocaleString)]
5718    pub fn to_locale_string(
5719        this: &Number,
5720        locales: &[JsString],
5721        options: &Intl::NumberFormatOptions,
5722    ) -> JsString;
5723
5724    /// The `toPrecision()` method returns a string representing the Number
5725    /// object to the specified precision.
5726    ///
5727    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
5728    #[wasm_bindgen(catch, method, js_name = toPrecision)]
5729    pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
5730
5731    /// The `toFixed()` method returns a string representing the Number
5732    /// object using fixed-point notation.
5733    ///
5734    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
5735    #[wasm_bindgen(catch, method, js_name = toFixed)]
5736    pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
5737
5738    /// The `toExponential()` method returns a string representing the Number
5739    /// object in exponential notation.
5740    ///
5741    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
5742    #[wasm_bindgen(catch, method, js_name = toExponential)]
5743    pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
5744
5745    /// The `toString()` method returns a string representing the
5746    /// specified Number object.
5747    ///
5748    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
5749    #[cfg(not(js_sys_unstable_apis))]
5750    #[deprecated(note = "Use `Number::to_string_with_radix` instead.")]
5751    #[allow(deprecated)]
5752    #[wasm_bindgen(catch, method, js_name = toString)]
5753    pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
5754
5755    /// The `toString()` method returns a string representing the
5756    /// specified Number object.
5757    ///
5758    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
5759    #[wasm_bindgen(catch, method, js_name = toString)]
5760    pub fn to_string_with_radix(this: &Number, radix: u8) -> Result<JsString, JsValue>;
5761
5762    /// The `valueOf()` method returns the wrapped primitive value of
5763    /// a Number object.
5764    ///
5765    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
5766    #[wasm_bindgen(method, js_name = valueOf)]
5767    pub fn value_of(this: &Number) -> f64;
5768}
5769
5770impl Number {
5771    /// The smallest interval between two representable numbers.
5772    ///
5773    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
5774    pub const EPSILON: f64 = f64::EPSILON;
5775    /// The maximum safe integer in JavaScript (2^53 - 1).
5776    ///
5777    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
5778    pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
5779    /// The largest positive representable number.
5780    ///
5781    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
5782    pub const MAX_VALUE: f64 = f64::MAX;
5783    /// The minimum safe integer in JavaScript (-(2^53 - 1)).
5784    ///
5785    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
5786    pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
5787    /// The smallest positive representable number—that is, the positive number closest to zero
5788    /// (without actually being zero).
5789    ///
5790    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
5791    // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number.
5792    pub const MIN_VALUE: f64 = 5E-324;
5793    /// Special "Not a Number" value.
5794    ///
5795    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
5796    pub const NAN: f64 = f64::NAN;
5797    /// Special value representing negative infinity. Returned on overflow.
5798    ///
5799    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
5800    pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
5801    /// Special value representing infinity. Returned on overflow.
5802    ///
5803    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
5804    pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
5805
5806    /// Applies the binary `**` JS operator on the two `Number`s.
5807    ///
5808    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
5809    #[inline]
5810    pub fn pow(&self, rhs: &Self) -> Self {
5811        JsValue::as_ref(self)
5812            .pow(JsValue::as_ref(rhs))
5813            .unchecked_into()
5814    }
5815
5816    /// Applies the binary `>>>` JS operator on the two `Number`s.
5817    ///
5818    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
5819    #[inline]
5820    pub fn unsigned_shr(&self, rhs: &Self) -> Self {
5821        Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs)))
5822    }
5823}
5824
5825macro_rules! number_from {
5826    ($($x:ident)*) => ($(
5827        impl From<$x> for Number {
5828            #[inline]
5829            fn from(x: $x) -> Number {
5830                Number::unchecked_from_js(JsValue::from(x))
5831            }
5832        }
5833
5834        impl PartialEq<$x> for Number {
5835            #[inline]
5836            fn eq(&self, other: &$x) -> bool {
5837                self.value_of() == f64::from(*other)
5838            }
5839        }
5840
5841        impl UpcastFrom<$x> for Number {}
5842    )*)
5843}
5844number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
5845
5846// The only guarantee for a JS number
5847impl UpcastFrom<Number> for f64 {}
5848
5849/// The error type returned when a checked integral type conversion fails.
5850#[derive(Debug, Copy, Clone, PartialEq, Eq)]
5851pub struct TryFromIntError(());
5852
5853impl fmt::Display for TryFromIntError {
5854    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
5855        fmt.write_str("out of range integral type conversion attempted")
5856    }
5857}
5858
5859#[cfg(feature = "std")]
5860impl std::error::Error for TryFromIntError {}
5861
5862macro_rules! number_try_from {
5863    ($($x:ident)*) => ($(
5864        impl TryFrom<$x> for Number {
5865            type Error = TryFromIntError;
5866
5867            #[inline]
5868            fn try_from(x: $x) -> Result<Number, Self::Error> {
5869                let x_f64 = x as f64;
5870                if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) {
5871                    Ok(Number::from(x_f64))
5872                } else {
5873                    Err(TryFromIntError(()))
5874                }
5875            }
5876        }
5877    )*)
5878}
5879number_try_from!(i64 u64 i128 u128);
5880
5881impl From<&Number> for f64 {
5882    #[inline]
5883    fn from(n: &Number) -> f64 {
5884        n.value_of()
5885    }
5886}
5887
5888impl From<Number> for f64 {
5889    #[inline]
5890    fn from(n: Number) -> f64 {
5891        <f64 as From<&'_ Number>>::from(&n)
5892    }
5893}
5894
5895impl fmt::Debug for Number {
5896    #[inline]
5897    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5898        fmt::Debug::fmt(&self.value_of(), f)
5899    }
5900}
5901
5902impl fmt::Display for Number {
5903    #[inline]
5904    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5905        fmt::Display::fmt(&self.value_of(), f)
5906    }
5907}
5908
5909impl Default for Number {
5910    fn default() -> Self {
5911        Self::from(f64::default())
5912    }
5913}
5914
5915impl PartialEq<BigInt> for Number {
5916    #[inline]
5917    fn eq(&self, other: &BigInt) -> bool {
5918        JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
5919    }
5920}
5921
5922impl Not for &Number {
5923    type Output = BigInt;
5924
5925    #[inline]
5926    fn not(self) -> Self::Output {
5927        JsValue::as_ref(self).bit_not().unchecked_into()
5928    }
5929}
5930
5931forward_deref_unop!(impl Not, not for Number);
5932forward_js_unop!(impl Neg, neg for Number);
5933forward_js_binop!(impl BitAnd, bitand for Number);
5934forward_js_binop!(impl BitOr, bitor for Number);
5935forward_js_binop!(impl BitXor, bitxor for Number);
5936forward_js_binop!(impl Shl, shl for Number);
5937forward_js_binop!(impl Shr, shr for Number);
5938forward_js_binop!(impl Add, add for Number);
5939forward_js_binop!(impl Sub, sub for Number);
5940forward_js_binop!(impl Div, div for Number);
5941forward_js_binop!(impl Mul, mul for Number);
5942forward_js_binop!(impl Rem, rem for Number);
5943
5944sum_product!(Number);
5945
5946impl PartialOrd for Number {
5947    #[inline]
5948    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
5949        if Number::is_nan(self) || Number::is_nan(other) {
5950            None
5951        } else if self == other {
5952            Some(Ordering::Equal)
5953        } else if self.lt(other) {
5954            Some(Ordering::Less)
5955        } else {
5956            Some(Ordering::Greater)
5957        }
5958    }
5959
5960    #[inline]
5961    fn lt(&self, other: &Self) -> bool {
5962        JsValue::as_ref(self).lt(JsValue::as_ref(other))
5963    }
5964
5965    #[inline]
5966    fn le(&self, other: &Self) -> bool {
5967        JsValue::as_ref(self).le(JsValue::as_ref(other))
5968    }
5969
5970    #[inline]
5971    fn ge(&self, other: &Self) -> bool {
5972        JsValue::as_ref(self).ge(JsValue::as_ref(other))
5973    }
5974
5975    #[inline]
5976    fn gt(&self, other: &Self) -> bool {
5977        JsValue::as_ref(self).gt(JsValue::as_ref(other))
5978    }
5979}
5980
5981#[cfg(not(js_sys_unstable_apis))]
5982impl FromStr for Number {
5983    type Err = Infallible;
5984
5985    #[allow(deprecated)]
5986    #[inline]
5987    fn from_str(s: &str) -> Result<Self, Self::Err> {
5988        Ok(Number::new_from_str(s))
5989    }
5990}
5991
5992// Date.
5993#[wasm_bindgen]
5994extern "C" {
5995    #[wasm_bindgen(extends = Object, typescript_type = "Date")]
5996    #[derive(Clone, Debug, PartialEq, Eq)]
5997    pub type Date;
5998
5999    /// The `getDate()` method returns the day of the month for the
6000    /// specified date according to local time.
6001    ///
6002    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
6003    #[wasm_bindgen(method, js_name = getDate)]
6004    pub fn get_date(this: &Date) -> u32;
6005
6006    /// The `getDay()` method returns the day of the week for the specified date according to local time,
6007    /// where 0 represents Sunday. For the day of the month see getDate().
6008    ///
6009    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
6010    #[wasm_bindgen(method, js_name = getDay)]
6011    pub fn get_day(this: &Date) -> u32;
6012
6013    /// The `getFullYear()` method returns the year of the specified date according to local time.
6014    ///
6015    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
6016    #[wasm_bindgen(method, js_name = getFullYear)]
6017    pub fn get_full_year(this: &Date) -> u32;
6018
6019    /// The `getHours()` method returns the hour for the specified date, according to local time.
6020    ///
6021    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
6022    #[wasm_bindgen(method, js_name = getHours)]
6023    pub fn get_hours(this: &Date) -> u32;
6024
6025    /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
6026    ///
6027    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
6028    #[wasm_bindgen(method, js_name = getMilliseconds)]
6029    pub fn get_milliseconds(this: &Date) -> u32;
6030
6031    /// The `getMinutes()` method returns the minutes in the specified date according to local time.
6032    ///
6033    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
6034    #[wasm_bindgen(method, js_name = getMinutes)]
6035    pub fn get_minutes(this: &Date) -> u32;
6036
6037    /// The `getMonth()` method returns the month in the specified date according to local time,
6038    /// as a zero-based value (where zero indicates the first month of the year).
6039    ///
6040    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
6041    #[wasm_bindgen(method, js_name = getMonth)]
6042    pub fn get_month(this: &Date) -> u32;
6043
6044    /// The `getSeconds()` method returns the seconds in the specified date according to local time.
6045    ///
6046    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
6047    #[wasm_bindgen(method, js_name = getSeconds)]
6048    pub fn get_seconds(this: &Date) -> u32;
6049
6050    /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
6051    /// according to universal time.
6052    ///
6053    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
6054    #[wasm_bindgen(method, js_name = getTime)]
6055    pub fn get_time(this: &Date) -> f64;
6056
6057    /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
6058    /// from current locale (host system settings) to UTC.
6059    ///
6060    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
6061    #[wasm_bindgen(method, js_name = getTimezoneOffset)]
6062    pub fn get_timezone_offset(this: &Date) -> f64;
6063
6064    /// The `getUTCDate()` method returns the day (date) of the month in the specified date
6065    /// according to universal time.
6066    ///
6067    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
6068    #[wasm_bindgen(method, js_name = getUTCDate)]
6069    pub fn get_utc_date(this: &Date) -> u32;
6070
6071    /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
6072    /// where 0 represents Sunday.
6073    ///
6074    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
6075    #[wasm_bindgen(method, js_name = getUTCDay)]
6076    pub fn get_utc_day(this: &Date) -> u32;
6077
6078    /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
6079    ///
6080    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
6081    #[wasm_bindgen(method, js_name = getUTCFullYear)]
6082    pub fn get_utc_full_year(this: &Date) -> u32;
6083
6084    /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
6085    ///
6086    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
6087    #[wasm_bindgen(method, js_name = getUTCHours)]
6088    pub fn get_utc_hours(this: &Date) -> u32;
6089
6090    /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date
6091    /// according to universal time.
6092    ///
6093    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds)
6094    #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
6095    pub fn get_utc_milliseconds(this: &Date) -> u32;
6096
6097    /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
6098    ///
6099    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
6100    #[wasm_bindgen(method, js_name = getUTCMinutes)]
6101    pub fn get_utc_minutes(this: &Date) -> u32;
6102
6103    /// The `getUTCMonth()` returns the month of the specified date according to universal time,
6104    /// as a zero-based value (where zero indicates the first month of the year).
6105    ///
6106    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
6107    #[wasm_bindgen(method, js_name = getUTCMonth)]
6108    pub fn get_utc_month(this: &Date) -> u32;
6109
6110    /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time.
6111    ///
6112    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds)
6113    #[wasm_bindgen(method, js_name = getUTCSeconds)]
6114    pub fn get_utc_seconds(this: &Date) -> u32;
6115
6116    /// Creates a JavaScript `Date` instance that represents
6117    /// a single moment in time. `Date` objects are based on a time value that is
6118    /// the number of milliseconds since 1 January 1970 UTC.
6119    ///
6120    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6121    #[wasm_bindgen(constructor)]
6122    pub fn new(init: &JsValue) -> Date;
6123
6124    /// Creates a JavaScript `Date` instance that represents the current moment in
6125    /// time.
6126    ///
6127    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6128    #[wasm_bindgen(constructor)]
6129    pub fn new_0() -> Date;
6130
6131    /// Creates a JavaScript `Date` instance that represents
6132    /// a single moment in time. `Date` objects are based on a time value that is
6133    /// the number of milliseconds since 1 January 1970 UTC.
6134    ///
6135    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6136    #[wasm_bindgen(constructor)]
6137    pub fn new_with_year_month(year: u32, month: i32) -> Date;
6138
6139    /// Creates a JavaScript `Date` instance that represents
6140    /// a single moment in time. `Date` objects are based on a time value that is
6141    /// the number of milliseconds since 1 January 1970 UTC.
6142    ///
6143    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6144    #[wasm_bindgen(constructor)]
6145    pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
6146
6147    /// Creates a JavaScript `Date` instance that represents
6148    /// a single moment in time. `Date` objects are based on a time value that is
6149    /// the number of milliseconds since 1 January 1970 UTC.
6150    ///
6151    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6152    #[wasm_bindgen(constructor)]
6153    pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
6154
6155    /// Creates a JavaScript `Date` instance that represents
6156    /// a single moment in time. `Date` objects are based on a time value that is
6157    /// the number of milliseconds since 1 January 1970 UTC.
6158    ///
6159    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6160    #[wasm_bindgen(constructor)]
6161    pub fn new_with_year_month_day_hr_min(
6162        year: u32,
6163        month: i32,
6164        day: i32,
6165        hr: i32,
6166        min: i32,
6167    ) -> Date;
6168
6169    /// Creates a JavaScript `Date` instance that represents
6170    /// a single moment in time. `Date` objects are based on a time value that is
6171    /// the number of milliseconds since 1 January 1970 UTC.
6172    ///
6173    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6174    #[wasm_bindgen(constructor)]
6175    pub fn new_with_year_month_day_hr_min_sec(
6176        year: u32,
6177        month: i32,
6178        day: i32,
6179        hr: i32,
6180        min: i32,
6181        sec: i32,
6182    ) -> Date;
6183
6184    /// Creates a JavaScript `Date` instance that represents
6185    /// a single moment in time. `Date` objects are based on a time value that is
6186    /// the number of milliseconds since 1 January 1970 UTC.
6187    ///
6188    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6189    #[wasm_bindgen(constructor)]
6190    pub fn new_with_year_month_day_hr_min_sec_milli(
6191        year: u32,
6192        month: i32,
6193        day: i32,
6194        hr: i32,
6195        min: i32,
6196        sec: i32,
6197        milli: i32,
6198    ) -> Date;
6199
6200    /// The `Date.now()` method returns the number of milliseconds
6201    /// elapsed since January 1, 1970 00:00:00 UTC.
6202    ///
6203    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
6204    #[wasm_bindgen(static_method_of = Date)]
6205    pub fn now() -> f64;
6206
6207    /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
6208    /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
6209    /// contains illegal date values (e.g. 2015-02-31).
6210    ///
6211    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
6212    #[wasm_bindgen(static_method_of = Date)]
6213    pub fn parse(date: &str) -> f64;
6214
6215    /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
6216    ///
6217    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
6218    #[wasm_bindgen(method, js_name = setDate)]
6219    pub fn set_date(this: &Date, day: u32) -> f64;
6220
6221    /// The `setFullYear()` method sets the full year for a specified date according to local time.
6222    /// Returns new timestamp.
6223    ///
6224    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6225    #[wasm_bindgen(method, js_name = setFullYear)]
6226    pub fn set_full_year(this: &Date, year: u32) -> f64;
6227
6228    /// The `setFullYear()` method sets the full year for a specified date according to local time.
6229    /// Returns new timestamp.
6230    ///
6231    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6232    #[wasm_bindgen(method, js_name = setFullYear)]
6233    pub fn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6234
6235    /// The `setFullYear()` method sets the full year for a specified date according to local time.
6236    /// Returns new timestamp.
6237    ///
6238    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6239    #[wasm_bindgen(method, js_name = setFullYear)]
6240    pub fn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6241
6242    /// The `setHours()` method sets the hours for a specified date according to local time,
6243    /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
6244    /// by the updated Date instance.
6245    ///
6246    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
6247    #[wasm_bindgen(method, js_name = setHours)]
6248    pub fn set_hours(this: &Date, hours: u32) -> f64;
6249
6250    /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
6251    ///
6252    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
6253    #[wasm_bindgen(method, js_name = setMilliseconds)]
6254    pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
6255
6256    /// The `setMinutes()` method sets the minutes for a specified date according to local time.
6257    ///
6258    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
6259    #[wasm_bindgen(method, js_name = setMinutes)]
6260    pub fn set_minutes(this: &Date, minutes: u32) -> f64;
6261
6262    /// The `setMonth()` method sets the month for a specified date according to the currently set year.
6263    ///
6264    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
6265    #[wasm_bindgen(method, js_name = setMonth)]
6266    pub fn set_month(this: &Date, month: u32) -> f64;
6267
6268    /// The `setSeconds()` method sets the seconds for a specified date according to local time.
6269    ///
6270    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
6271    #[wasm_bindgen(method, js_name = setSeconds)]
6272    pub fn set_seconds(this: &Date, seconds: u32) -> f64;
6273
6274    /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
6275    /// since January 1, 1970, 00:00:00 UTC.
6276    ///
6277    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
6278    #[wasm_bindgen(method, js_name = setTime)]
6279    pub fn set_time(this: &Date, time: f64) -> f64;
6280
6281    /// The `setUTCDate()` method sets the day of the month for a specified date
6282    /// according to universal time.
6283    ///
6284    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
6285    #[wasm_bindgen(method, js_name = setUTCDate)]
6286    pub fn set_utc_date(this: &Date, day: u32) -> f64;
6287
6288    /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6289    ///
6290    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6291    #[wasm_bindgen(method, js_name = setUTCFullYear)]
6292    pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
6293
6294    /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6295    ///
6296    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6297    #[wasm_bindgen(method, js_name = setUTCFullYear)]
6298    pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6299
6300    /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6301    ///
6302    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6303    #[wasm_bindgen(method, js_name = setUTCFullYear)]
6304    pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6305
6306    /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
6307    /// and returns the number of milliseconds since  January 1, 1970 00:00:00 UTC until the time
6308    /// represented by the updated Date instance.
6309    ///
6310    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
6311    #[wasm_bindgen(method, js_name = setUTCHours)]
6312    pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
6313
6314    /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
6315    /// according to universal time.
6316    ///
6317    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
6318    #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
6319    pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
6320
6321    /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
6322    ///
6323    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
6324    #[wasm_bindgen(method, js_name = setUTCMinutes)]
6325    pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
6326
6327    /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
6328    ///
6329    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
6330    #[wasm_bindgen(method, js_name = setUTCMonth)]
6331    pub fn set_utc_month(this: &Date, month: u32) -> f64;
6332
6333    /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
6334    ///
6335    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
6336    #[wasm_bindgen(method, js_name = setUTCSeconds)]
6337    pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
6338
6339    /// The `toDateString()` method returns the date portion of a Date object
6340    /// in human readable form in American English.
6341    ///
6342    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
6343    #[wasm_bindgen(method, js_name = toDateString)]
6344    pub fn to_date_string(this: &Date) -> JsString;
6345
6346    /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
6347    /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
6348    /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
6349    /// as denoted by the suffix "Z"
6350    ///
6351    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
6352    #[wasm_bindgen(method, js_name = toISOString)]
6353    pub fn to_iso_string(this: &Date) -> JsString;
6354
6355    /// The `toJSON()` method returns a string representation of the Date object.
6356    ///
6357    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
6358    #[wasm_bindgen(method, js_name = toJSON)]
6359    pub fn to_json(this: &Date) -> JsString;
6360
6361    /// The `toLocaleDateString()` method returns a string with a language sensitive
6362    /// representation of the date portion of this date. The new locales and options
6363    /// arguments let applications specify the language whose formatting conventions
6364    /// should be used and allow to customize the behavior of the function.
6365    /// In older implementations, which ignore the locales and options arguments,
6366    /// the locale used and the form of the string
6367    /// returned are entirely implementation dependent.
6368    ///
6369    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6370    #[cfg(not(js_sys_unstable_apis))]
6371    #[wasm_bindgen(method, js_name = toLocaleDateString)]
6372    pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6373
6374    /// The `toLocaleDateString()` method returns a string with a language sensitive
6375    /// representation of the date portion of this date.
6376    ///
6377    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6378    #[cfg(js_sys_unstable_apis)]
6379    #[wasm_bindgen(method, js_name = toLocaleDateString)]
6380    pub fn to_locale_date_string(
6381        this: &Date,
6382        locales: &[JsString],
6383        options: &Intl::DateTimeFormatOptions,
6384    ) -> JsString;
6385
6386    /// The `toLocaleString()` method returns a string with a language sensitive
6387    /// representation of this date. The new locales and options arguments
6388    /// let applications specify the language whose formatting conventions
6389    /// should be used and customize the behavior of the function.
6390    /// In older implementations, which ignore the locales
6391    /// and options arguments, the locale used and the form of the string
6392    /// returned are entirely implementation dependent.
6393    ///
6394    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6395    #[cfg(not(js_sys_unstable_apis))]
6396    #[wasm_bindgen(method, js_name = toLocaleString)]
6397    pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6398
6399    /// The `toLocaleString()` method returns a string with a language sensitive
6400    /// representation of this date.
6401    ///
6402    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6403    #[cfg(js_sys_unstable_apis)]
6404    #[wasm_bindgen(method, js_name = toLocaleString)]
6405    pub fn to_locale_string(
6406        this: &Date,
6407        locales: &[JsString],
6408        options: &Intl::DateTimeFormatOptions,
6409    ) -> JsString;
6410
6411    /// The `toLocaleTimeString()` method returns a string with a language sensitive
6412    /// representation of the time portion of this date. The new locales and options
6413    /// arguments let applications specify the language whose formatting conventions should be
6414    /// used and customize the behavior of the function. In older implementations, which ignore
6415    /// the locales and options arguments, the locale used and the form of the string
6416    /// returned are entirely implementation dependent.
6417    ///
6418    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6419    #[cfg(not(js_sys_unstable_apis))]
6420    #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6421    pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
6422
6423    /// The `toLocaleTimeString()` method returns a string with a language sensitive
6424    /// representation of the time portion of this date.
6425    ///
6426    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6427    #[cfg(js_sys_unstable_apis)]
6428    #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6429    pub fn to_locale_time_string(
6430        this: &Date,
6431        locales: &[JsString],
6432        options: &Intl::DateTimeFormatOptions,
6433    ) -> JsString;
6434
6435    #[cfg(not(js_sys_unstable_apis))]
6436    #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6437    pub fn to_locale_time_string_with_options(
6438        this: &Date,
6439        locale: &str,
6440        options: &JsValue,
6441    ) -> JsString;
6442
6443    /// The `toString()` method returns a string representing
6444    /// the specified Date object.
6445    ///
6446    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
6447    #[cfg(not(js_sys_unstable_apis))]
6448    #[wasm_bindgen(method, js_name = toString)]
6449    pub fn to_string(this: &Date) -> JsString;
6450
6451    /// The `toTimeString()` method returns the time portion of a Date object in human
6452    /// readable form in American English.
6453    ///
6454    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
6455    #[wasm_bindgen(method, js_name = toTimeString)]
6456    pub fn to_time_string(this: &Date) -> JsString;
6457
6458    /// The `toUTCString()` method converts a date to a string,
6459    /// using the UTC time zone.
6460    ///
6461    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
6462    #[wasm_bindgen(method, js_name = toUTCString)]
6463    pub fn to_utc_string(this: &Date) -> JsString;
6464
6465    /// The `Date.UTC()` method accepts the same parameters as the
6466    /// longest form of the constructor, and returns the number of
6467    /// milliseconds in a `Date` object since January 1, 1970,
6468    /// 00:00:00, universal time.
6469    ///
6470    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
6471    #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
6472    pub fn utc(year: f64, month: f64) -> f64;
6473
6474    /// The `valueOf()` method  returns the primitive value of
6475    /// a Date object.
6476    ///
6477    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
6478    #[wasm_bindgen(method, js_name = valueOf)]
6479    pub fn value_of(this: &Date) -> f64;
6480
6481    /// The `toTemporalInstant()` method converts a legacy `Date` object to a
6482    /// `Temporal.Instant` object representing the same moment in time.
6483    ///
6484    /// This method is added by the Temporal proposal to facilitate migration
6485    /// from legacy `Date` to the new Temporal API.
6486    ///
6487    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTemporalInstant)
6488    #[cfg(js_sys_unstable_apis)]
6489    #[wasm_bindgen(method, js_name = toTemporalInstant)]
6490    pub fn to_temporal_instant(this: &Date) -> Temporal::Instant;
6491}
6492
6493// Property Descriptor.
6494#[wasm_bindgen]
6495extern "C" {
6496    #[wasm_bindgen(extends = Object)]
6497    #[derive(Clone, Debug)]
6498    pub type PropertyDescriptor<T = JsValue>;
6499
6500    #[wasm_bindgen(method, getter = writable)]
6501    pub fn get_writable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6502
6503    #[wasm_bindgen(method, setter = writable)]
6504    pub fn set_writable<T>(this: &PropertyDescriptor<T>, writable: bool);
6505
6506    #[wasm_bindgen(method, getter = enumerable)]
6507    pub fn get_enumerable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6508
6509    #[wasm_bindgen(method, setter = enumerable)]
6510    pub fn set_enumerable<T>(this: &PropertyDescriptor<T>, enumerable: bool);
6511
6512    #[wasm_bindgen(method, getter = configurable)]
6513    pub fn get_configurable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6514
6515    #[wasm_bindgen(method, setter = configurable)]
6516    pub fn set_configurable<T>(this: &PropertyDescriptor<T>, configurable: bool);
6517
6518    #[wasm_bindgen(method, getter = get)]
6519    pub fn get_get<T: JsGeneric>(this: &PropertyDescriptor<T>) -> Option<Function<fn() -> T>>;
6520
6521    #[wasm_bindgen(method, setter = get)]
6522    pub fn set_get<T: JsGeneric>(this: &PropertyDescriptor<T>, get: Function<fn() -> T>);
6523
6524    #[wasm_bindgen(method, getter = set)]
6525    pub fn get_set<T: JsGeneric>(
6526        this: &PropertyDescriptor<T>,
6527    ) -> Option<Function<fn(T) -> JsValue>>;
6528
6529    #[wasm_bindgen(method, setter = set)]
6530    pub fn set_set<T: JsGeneric>(this: &PropertyDescriptor<T>, set: Function<fn(T) -> JsValue>);
6531
6532    #[wasm_bindgen(method, getter = value)]
6533    pub fn get_value<T>(this: &PropertyDescriptor<T>) -> Option<T>;
6534
6535    #[wasm_bindgen(method, setter = value)]
6536    pub fn set_value<T>(this: &PropertyDescriptor<T>, value: &T);
6537}
6538
6539impl PropertyDescriptor {
6540    #[cfg(not(js_sys_unstable_apis))]
6541    pub fn new<T>() -> PropertyDescriptor<T> {
6542        JsCast::unchecked_into(Object::new())
6543    }
6544
6545    #[cfg(js_sys_unstable_apis)]
6546    pub fn new<T>() -> PropertyDescriptor<T> {
6547        JsCast::unchecked_into(Object::<JsValue>::new())
6548    }
6549
6550    #[cfg(not(js_sys_unstable_apis))]
6551    pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6552        let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::new());
6553        desc.set_value(value);
6554        desc
6555    }
6556
6557    #[cfg(js_sys_unstable_apis)]
6558    pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6559        let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::<JsValue>::new());
6560        desc.set_value(value);
6561        desc
6562    }
6563}
6564
6565impl Default for PropertyDescriptor {
6566    fn default() -> Self {
6567        PropertyDescriptor::new()
6568    }
6569}
6570
6571// Object.
6572#[wasm_bindgen]
6573extern "C" {
6574    #[wasm_bindgen(typescript_type = "object")]
6575    #[derive(Clone, Debug)]
6576    pub type Object<T = JsValue>;
6577
6578    // Next major: deprecate
6579    /// The `Object.assign()` method is used to copy the values of all enumerable
6580    /// own properties from one or more source objects to a target object. It
6581    /// will return the target object.
6582    ///
6583    /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6584    ///
6585    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6586    #[wasm_bindgen(static_method_of = Object)]
6587    pub fn assign<T>(target: &Object<T>, source: &Object<T>) -> Object<T>;
6588
6589    // Next major: deprecate
6590    /// The `Object.assign()` method is used to copy the values of all enumerable
6591    /// own properties from one or more source objects to a target object. It
6592    /// will return the target object.
6593    ///
6594    /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6595    ///
6596    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6597    #[wasm_bindgen(static_method_of = Object, js_name = assign, catch)]
6598    pub fn try_assign<T>(target: &Object<T>, source: &Object<T>) -> Result<Object<T>, JsValue>;
6599
6600    /// The `Object.assign()` method is used to copy the values of all enumerable
6601    /// own properties from one or more source objects to a target object. It
6602    /// will return the target object.
6603    ///
6604    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6605    #[cfg(not(js_sys_unstable_apis))]
6606    #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6607    #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6608    #[allow(deprecated)]
6609    pub fn assign2<T>(target: &Object<T>, source1: &Object<T>, source2: &Object<T>) -> Object<T>;
6610
6611    /// The `Object.assign()` method is used to copy the values of all enumerable
6612    /// own properties from one or more source objects to a target object. It
6613    /// will return the target object.
6614    ///
6615    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6616    #[cfg(not(js_sys_unstable_apis))]
6617    #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6618    #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6619    #[allow(deprecated)]
6620    pub fn assign3<T>(
6621        target: &Object<T>,
6622        source1: &Object<T>,
6623        source2: &Object<T>,
6624        source3: &Object<T>,
6625    ) -> Object<T>;
6626
6627    /// The `Object.assign()` method is used to copy the values of all enumerable
6628    /// own properties from one or more source objects to a target object. It
6629    /// will return the target object.
6630    ///
6631    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6632    #[wasm_bindgen(static_method_of = Object, js_name = assign, catch, variadic)]
6633    pub fn assign_many<T>(target: &Object<T>, sources: &[Object<T>]) -> Result<Object<T>, JsValue>;
6634
6635    /// The constructor property returns a reference to the `Object` constructor
6636    /// function that created the instance object.
6637    ///
6638    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
6639    #[wasm_bindgen(method, getter)]
6640    pub fn constructor<T>(this: &Object<T>) -> Function;
6641
6642    /// The `Object.create()` method creates a new object, using an existing
6643    /// object to provide the newly created object's prototype.
6644    ///
6645    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
6646    #[wasm_bindgen(static_method_of = Object)]
6647    pub fn create<T>(prototype: &Object<T>) -> Object<T>;
6648
6649    /// The static method `Object.defineProperty()` defines a new
6650    /// property directly on an object, or modifies an existing
6651    /// property on an object, and returns the object.
6652    ///
6653    /// **Note:** Consider using [`Object::define_property_str`] to support typing and error handling.
6654    ///
6655    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6656    #[cfg(not(js_sys_unstable_apis))]
6657    #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
6658    pub fn define_property<T>(obj: &Object<T>, prop: &JsValue, descriptor: &Object) -> Object<T>;
6659
6660    /// The static method `Object.defineProperty()` defines a new
6661    /// property directly on an object, or modifies an existing
6662    /// property on an object, and returns the object.
6663    ///
6664    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6665    #[cfg(js_sys_unstable_apis)]
6666    #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6667    pub fn define_property<T>(
6668        obj: &Object<T>,
6669        prop: &JsString,
6670        descriptor: &PropertyDescriptor<T>,
6671    ) -> Result<Object<T>, JsValue>;
6672
6673    // Next major: deprecate
6674    /// The static method `Object.defineProperty()` defines a new
6675    /// property directly on an object, or modifies an existing
6676    /// property on an object, and returns the object.
6677    ///
6678    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6679    #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6680    pub fn define_property_str<T>(
6681        obj: &Object<T>,
6682        prop: &JsString,
6683        descriptor: &PropertyDescriptor<T>,
6684    ) -> Result<Object<T>, JsValue>;
6685
6686    /// The static method `Object.defineProperty()` defines a new
6687    /// property directly on an object, or modifies an existing
6688    /// property on an object, and returns the object.
6689    ///
6690    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6691    #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6692    pub fn define_property_symbol<T>(
6693        obj: &Object<T>,
6694        prop: &Symbol,
6695        descriptor: &PropertyDescriptor<JsValue>,
6696    ) -> Result<Object<T>, JsValue>;
6697
6698    /// The `Object.defineProperties()` method defines new or modifies
6699    /// existing properties directly on an object, returning the
6700    /// object.
6701    ///
6702    /// **Note:** Consider using [`Object::try_define_properties`] to support typing and error handling.
6703    ///
6704    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
6705    #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
6706    pub fn define_properties<T>(obj: &Object<T>, props: &Object) -> Object<T>;
6707
6708    /// The `Object.defineProperties()` method defines new or modifies
6709    /// existing properties directly on an object, returning the
6710    /// object.
6711    ///
6712    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
6713    #[cfg(js_sys_unstable_apis)]
6714    #[wasm_bindgen(static_method_of = Object, js_name = defineProperties, catch)]
6715    pub fn try_define_properties<T>(
6716        obj: &Object<T>,
6717        props: &Object<PropertyDescriptor<T>>,
6718    ) -> Result<Object<T>, JsValue>;
6719
6720    /// The `Object.entries()` method returns an array of a given
6721    /// object's own enumerable property [key, value] pairs, in the
6722    /// same order as that provided by a for...in loop (the difference
6723    /// being that a for-in loop enumerates properties in the
6724    /// prototype chain as well).
6725    ///
6726    /// **Note:** Consider using [`Object::entries_typed`] to support typing and error handling.
6727    ///
6728    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6729    #[cfg(not(js_sys_unstable_apis))]
6730    #[wasm_bindgen(static_method_of = Object)]
6731    pub fn entries(object: &Object) -> Array;
6732
6733    /// The `Object.entries()` method returns an array of a given
6734    /// object's own enumerable property [key, value] pairs, in the
6735    /// same order as that provided by a for...in loop (the difference
6736    /// being that a for-in loop enumerates properties in the
6737    /// prototype chain as well).
6738    ///
6739    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6740    #[cfg(js_sys_unstable_apis)]
6741    #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
6742    pub fn entries<T: JsGeneric>(
6743        object: &Object<T>,
6744    ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
6745
6746    // Next major: deprecate
6747    /// The `Object.entries()` method returns an array of a given
6748    /// object's own enumerable property [key, value] pairs, in the
6749    /// same order as that provided by a for...in loop (the difference
6750    /// being that a for-in loop enumerates properties in the
6751    /// prototype chain as well).
6752    ///
6753    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6754    #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
6755    pub fn entries_typed<T: JsGeneric>(
6756        object: &Object<T>,
6757    ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
6758
6759    /// The `Object.freeze()` method freezes an object: that is, prevents new
6760    /// properties from being added to it; prevents existing properties from
6761    /// being removed; and prevents existing properties, or their enumerability,
6762    /// configurability, or writability, from being changed, it also prevents
6763    /// the prototype from being changed. The method returns the passed object.
6764    ///
6765    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
6766    #[wasm_bindgen(static_method_of = Object)]
6767    pub fn freeze<T>(value: &Object<T>) -> Object<T>;
6768
6769    /// The `Object.fromEntries()` method transforms a list of key-value pairs
6770    /// into an object.
6771    ///
6772    /// **Note:** Consider using [`Object::from_entries_typed`] to support typing and error handling.
6773    ///
6774    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6775    #[cfg(not(js_sys_unstable_apis))]
6776    #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6777    pub fn from_entries(entries: &JsValue) -> Result<Object, JsValue>;
6778
6779    /// The `Object.fromEntries()` method transforms a list of key-value pairs
6780    /// into an object.
6781    ///
6782    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6783    #[cfg(js_sys_unstable_apis)]
6784    #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6785    pub fn from_entries<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
6786        entries: &I,
6787    ) -> Result<Object<T>, JsValue>;
6788
6789    // Next major: deprecate
6790    /// The `Object.fromEntries()` method transforms a list of key-value pairs
6791    /// into an object.
6792    ///
6793    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6794    #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6795    pub fn from_entries_typed<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
6796        entries: &I,
6797    ) -> Result<Object<T>, JsValue>;
6798
6799    /// The `Object.getOwnPropertyDescriptor()` method returns a
6800    /// property descriptor for an own property (that is, one directly
6801    /// present on an object and not in the object's prototype chain)
6802    /// of a given object.
6803    ///
6804    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6805    #[cfg(not(js_sys_unstable_apis))]
6806    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
6807    pub fn get_own_property_descriptor<T>(obj: &Object<T>, prop: &JsValue) -> JsValue;
6808
6809    /// The `Object.getOwnPropertyDescriptor()` method returns a
6810    /// property descriptor for an own property (that is, one directly
6811    /// present on an object and not in the object's prototype chain)
6812    /// of a given object.
6813    ///
6814    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6815    #[cfg(js_sys_unstable_apis)]
6816    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6817    pub fn get_own_property_descriptor<T>(
6818        obj: &Object<T>,
6819        prop: &JsString,
6820    ) -> Result<PropertyDescriptor<T>, JsValue>;
6821
6822    // Next major: deprecate
6823    /// The `Object.getOwnPropertyDescriptor()` method returns a
6824    /// property descriptor for an own property (that is, one directly
6825    /// present on an object and not in the object's prototype chain)
6826    /// of a given object.
6827    ///
6828    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6829    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6830    pub fn get_own_property_descriptor_str<T>(
6831        obj: &Object<T>,
6832        prop: &JsString,
6833    ) -> Result<PropertyDescriptor<T>, JsValue>;
6834
6835    /// The `Object.getOwnPropertyDescriptor()` method returns a
6836    /// property descriptor for an own property (that is, one directly
6837    /// present on an object and not in the object's prototype chain)
6838    /// of a given object.
6839    ///
6840    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6841    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6842    pub fn get_own_property_descriptor_symbol<T>(
6843        obj: &Object<T>,
6844        prop: &Symbol,
6845    ) -> Result<PropertyDescriptor<JsValue>, JsValue>;
6846
6847    /// The `Object.getOwnPropertyDescriptors()` method returns all own
6848    /// property descriptors of a given object.
6849    ///
6850    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
6851    #[cfg(not(js_sys_unstable_apis))]
6852    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
6853    pub fn get_own_property_descriptors<T>(obj: &Object<T>) -> JsValue;
6854
6855    /// The `Object.getOwnPropertyDescriptors()` method returns all own
6856    /// property descriptors of a given object.
6857    ///
6858    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
6859    #[cfg(js_sys_unstable_apis)]
6860    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors, catch)]
6861    pub fn get_own_property_descriptors<T>(
6862        obj: &Object<T>,
6863    ) -> Result<Object<PropertyDescriptor<T>>, JsValue>;
6864
6865    /// The `Object.getOwnPropertyNames()` method returns an array of
6866    /// all properties (including non-enumerable properties except for
6867    /// those which use Symbol) found directly upon a given object.
6868    ///
6869    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
6870    #[cfg(not(js_sys_unstable_apis))]
6871    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
6872    pub fn get_own_property_names<T>(obj: &Object<T>) -> Array;
6873
6874    /// The `Object.getOwnPropertyNames()` method returns an array of
6875    /// all properties (including non-enumerable properties except for
6876    /// those which use Symbol) found directly upon a given object.
6877    ///
6878    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
6879    #[cfg(js_sys_unstable_apis)]
6880    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames, catch)]
6881    pub fn get_own_property_names<T>(obj: &Object<T>) -> Result<Array<JsString>, JsValue>;
6882
6883    /// The `Object.getOwnPropertySymbols()` method returns an array of
6884    /// all symbol properties found directly upon a given object.
6885    ///
6886    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
6887    #[cfg(not(js_sys_unstable_apis))]
6888    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
6889    pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Array;
6890
6891    /// The `Object.getOwnPropertySymbols()` method returns an array of
6892    /// all symbol properties found directly upon a given object.
6893    ///
6894    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
6895    #[cfg(js_sys_unstable_apis)]
6896    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols, catch)]
6897    pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Result<Array<Symbol>, JsValue>;
6898
6899    /// The `Object.getPrototypeOf()` method returns the prototype
6900    /// (i.e. the value of the internal [[Prototype]] property) of the
6901    /// specified object.
6902    ///
6903    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
6904    #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
6905    pub fn get_prototype_of(obj: &JsValue) -> Object;
6906
6907    /// The `hasOwnProperty()` method returns a boolean indicating whether the
6908    /// object has the specified property as its own property (as opposed to
6909    /// inheriting it).
6910    ///
6911    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
6912    #[deprecated(note = "Use `Object::hasOwn` instead.")]
6913    #[allow(deprecated)]
6914    #[wasm_bindgen(method, js_name = hasOwnProperty)]
6915    pub fn has_own_property<T>(this: &Object<T>, property: &JsValue) -> bool;
6916
6917    /// The `Object.hasOwn()` method returns a boolean indicating whether the
6918    /// object passed in has the specified property as its own property (as
6919    /// opposed to inheriting it).
6920    ///
6921    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6922    #[cfg(not(js_sys_unstable_apis))]
6923    #[wasm_bindgen(static_method_of = Object, js_name = hasOwn)]
6924    pub fn has_own<T>(instance: &Object<T>, property: &JsValue) -> bool;
6925
6926    /// The `Object.hasOwn()` method returns a boolean indicating whether the
6927    /// object passed in has the specified property as its own property (as
6928    /// opposed to inheriting it).
6929    ///
6930    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6931    #[cfg(js_sys_unstable_apis)]
6932    #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6933    pub fn has_own<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
6934
6935    // Next major: deprecate
6936    /// The `Object.hasOwn()` method returns a boolean indicating whether the
6937    /// object passed in has the specified property as its own property (as
6938    /// opposed to inheriting it).
6939    ///
6940    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6941    #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6942    pub fn has_own_str<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
6943
6944    /// The `Object.hasOwn()` method returns a boolean indicating whether the
6945    /// object passed in has the specified property as its own property (as
6946    /// opposed to inheriting it).
6947    ///
6948    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6949    #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6950    pub fn has_own_symbol<T>(instance: &Object<T>, property: &Symbol) -> Result<bool, JsValue>;
6951
6952    /// The `Object.is()` method determines whether two values are the same value.
6953    ///
6954    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
6955    #[wasm_bindgen(static_method_of = Object)]
6956    pub fn is(value1: &JsValue, value_2: &JsValue) -> bool;
6957
6958    /// The `Object.isExtensible()` method determines if an object is extensible
6959    /// (whether it can have new properties added to it).
6960    ///
6961    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
6962    #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
6963    pub fn is_extensible<T>(object: &Object<T>) -> bool;
6964
6965    /// The `Object.isFrozen()` determines if an object is frozen.
6966    ///
6967    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
6968    #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
6969    pub fn is_frozen<T>(object: &Object<T>) -> bool;
6970
6971    /// The `Object.isSealed()` method determines if an object is sealed.
6972    ///
6973    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
6974    #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
6975    pub fn is_sealed<T>(object: &Object<T>) -> bool;
6976
6977    /// The `isPrototypeOf()` method checks if an object exists in another
6978    /// object's prototype chain.
6979    ///
6980    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
6981    #[wasm_bindgen(method, js_name = isPrototypeOf)]
6982    pub fn is_prototype_of<T>(this: &Object<T>, value: &JsValue) -> bool;
6983
6984    /// The `Object.keys()` method returns an array of a given object's property
6985    /// names, in the same order as we get with a normal loop.
6986    ///
6987    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
6988    #[cfg(not(js_sys_unstable_apis))]
6989    #[wasm_bindgen(static_method_of = Object)]
6990    pub fn keys<T>(object: &Object<T>) -> Array;
6991
6992    /// The `Object.keys()` method returns an array of a given object's property
6993    /// names, in the same order as we get with a normal loop.
6994    ///
6995    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
6996    #[cfg(js_sys_unstable_apis)]
6997    #[wasm_bindgen(static_method_of = Object)]
6998    pub fn keys<T>(object: &Object<T>) -> Array<JsString>;
6999
7000    /// The [`Object`] constructor creates an object wrapper.
7001    ///
7002    /// **Note:** Consider using [`Object::new_typed`] for typed object records.
7003    ///
7004    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7005    #[wasm_bindgen(constructor)]
7006    pub fn new() -> Object;
7007
7008    // Next major: deprecate
7009    /// The [`Object`] constructor creates an object wrapper.
7010    ///
7011    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7012    #[wasm_bindgen(constructor)]
7013    pub fn new_typed<T>() -> Object<T>;
7014
7015    /// The `Object.preventExtensions()` method prevents new properties from
7016    /// ever being added to an object (i.e. prevents future extensions to the
7017    /// object).
7018    ///
7019    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
7020    #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
7021    pub fn prevent_extensions<T>(object: &Object<T>);
7022
7023    /// The `propertyIsEnumerable()` method returns a Boolean indicating
7024    /// whether the specified property is enumerable.
7025    ///
7026    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7027    #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
7028    pub fn property_is_enumerable<T>(this: &Object<T>, property: &JsValue) -> bool;
7029
7030    /// The `Object.seal()` method seals an object, preventing new properties
7031    /// from being added to it and marking all existing properties as
7032    /// non-configurable.  Values of present properties can still be changed as
7033    /// long as they are writable.
7034    ///
7035    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
7036    #[wasm_bindgen(static_method_of = Object)]
7037    pub fn seal<T>(value: &Object<T>) -> Object<T>;
7038
7039    /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7040    /// internal `[[Prototype]]` property) of a specified object to another
7041    /// object or `null`.
7042    ///
7043    /// **Note:** Consider using [`Object::try_set_prototype_of`] to support errors.
7044    ///
7045    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7046    #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
7047    pub fn set_prototype_of<T>(object: &Object<T>, prototype: &Object) -> Object<T>;
7048
7049    /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7050    /// internal `[[Prototype]]` property) of a specified object to another
7051    /// object or `null`.
7052    ///
7053    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7054    #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf, catch)]
7055    pub fn try_set_prototype_of<T>(
7056        object: &Object<T>,
7057        prototype: &Object,
7058    ) -> Result<Object<T>, JsValue>;
7059
7060    /// The `toLocaleString()` method returns a string representing the object.
7061    /// This method is meant to be overridden by derived objects for
7062    /// locale-specific purposes.
7063    ///
7064    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
7065    #[wasm_bindgen(method, js_name = toLocaleString)]
7066    pub fn to_locale_string<T>(this: &Object<T>) -> JsString;
7067
7068    // Next major: deprecate
7069    /// The `toString()` method returns a string representing the object.
7070    ///
7071    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7072    #[wasm_bindgen(method, js_name = toString)]
7073    pub fn to_string<T>(this: &Object<T>) -> JsString;
7074
7075    /// The `toString()` method returns a string representing the object.
7076    ///
7077    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7078    #[wasm_bindgen(method, js_name = toString)]
7079    pub fn to_js_string<T>(this: &Object<T>) -> JsString;
7080
7081    /// The `valueOf()` method returns the primitive value of the
7082    /// specified object.
7083    ///
7084    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
7085    #[wasm_bindgen(method, js_name = valueOf)]
7086    pub fn value_of<T>(this: &Object<T>) -> Object;
7087
7088    /// The `Object.values()` method returns an array of a given object's own
7089    /// enumerable property values, in the same order as that provided by a
7090    /// `for...in` loop (the difference being that a for-in loop enumerates
7091    /// properties in the prototype chain as well).
7092    ///
7093    /// **Note:** Consider using [`Object::try_values`] to support errors.
7094    ///
7095    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7096    #[cfg(not(js_sys_unstable_apis))]
7097    #[wasm_bindgen(static_method_of = Object)]
7098    pub fn values<T>(object: &Object<T>) -> Array<T>;
7099
7100    /// The `Object.values()` method returns an array of a given object's own
7101    /// enumerable property values, in the same order as that provided by a
7102    /// `for...in` loop (the difference being that a for-in loop enumerates
7103    /// properties in the prototype chain as well).
7104    ///
7105    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7106    #[cfg(js_sys_unstable_apis)]
7107    #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7108    pub fn values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7109
7110    // Next major: deprecate
7111    /// The `Object.values()` method returns an array of a given object's own
7112    /// enumerable property values, in the same order as that provided by a
7113    /// `for...in` loop (the difference being that a for-in loop enumerates
7114    /// properties in the prototype chain as well).
7115    ///
7116    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7117    #[cfg(not(js_sys_unstable_apis))]
7118    #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7119    pub fn try_values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7120}
7121
7122impl Object {
7123    /// Returns the `Object` value of this JS value if it's an instance of an
7124    /// object.
7125    ///
7126    /// If this JS value is not an instance of an object then this returns
7127    /// `None`.
7128    pub fn try_from(val: &JsValue) -> Option<&Object> {
7129        if val.is_object() {
7130            Some(val.unchecked_ref())
7131        } else {
7132            None
7133        }
7134    }
7135}
7136
7137impl PartialEq for Object {
7138    #[inline]
7139    fn eq(&self, other: &Object) -> bool {
7140        Object::is(self.as_ref(), other.as_ref())
7141    }
7142}
7143
7144impl Eq for Object {}
7145
7146impl Default for Object<JsValue> {
7147    fn default() -> Self {
7148        Self::new()
7149    }
7150}
7151
7152// Proxy
7153#[wasm_bindgen]
7154extern "C" {
7155    #[wasm_bindgen(typescript_type = "ProxyConstructor")]
7156    #[derive(Clone, Debug)]
7157    pub type Proxy;
7158
7159    /// The [`Proxy`] object is used to define custom behavior for fundamental
7160    /// operations (e.g. property lookup, assignment, enumeration, function
7161    /// invocation, etc).
7162    ///
7163    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
7164    #[wasm_bindgen(constructor)]
7165    pub fn new(target: &JsValue, handler: &Object) -> Proxy;
7166
7167    /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
7168    /// object.
7169    ///
7170    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
7171    #[wasm_bindgen(static_method_of = Proxy)]
7172    pub fn revocable(target: &JsValue, handler: &Object) -> Object;
7173}
7174
7175// RangeError
7176#[wasm_bindgen]
7177extern "C" {
7178    /// The `RangeError` object indicates an error when a value is not in the set
7179    /// or range of allowed values.
7180    ///
7181    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7182    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
7183    #[derive(Clone, Debug, PartialEq, Eq)]
7184    pub type RangeError;
7185
7186    /// The `RangeError` object indicates an error when a value is not in the set
7187    /// or range of allowed values.
7188    ///
7189    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7190    #[wasm_bindgen(constructor)]
7191    pub fn new(message: &str) -> RangeError;
7192}
7193
7194// ReferenceError
7195#[wasm_bindgen]
7196extern "C" {
7197    /// The `ReferenceError` object represents an error when a non-existent
7198    /// variable is referenced.
7199    ///
7200    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7201    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
7202    #[derive(Clone, Debug, PartialEq, Eq)]
7203    pub type ReferenceError;
7204
7205    /// The `ReferenceError` object represents an error when a non-existent
7206    /// variable is referenced.
7207    ///
7208    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7209    #[wasm_bindgen(constructor)]
7210    pub fn new(message: &str) -> ReferenceError;
7211}
7212
7213#[allow(non_snake_case)]
7214pub mod Reflect {
7215    use super::*;
7216
7217    // Reflect
7218    #[wasm_bindgen]
7219    extern "C" {
7220        /// The static `Reflect.apply()` method calls a target function with
7221        /// arguments as specified.
7222        ///
7223        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
7224        #[wasm_bindgen(js_namespace = Reflect, catch)]
7225        pub fn apply<T: JsFunction = fn() -> JsValue>(
7226            target: &Function<T>,
7227            this_argument: &JsValue,
7228            arguments_list: &Array,
7229        ) -> Result<<T as JsFunction>::Ret, JsValue>;
7230
7231        /// The static `Reflect.construct()` method acts like the new operator, but
7232        /// as a function.  It is equivalent to calling `new target(...args)`. It
7233        /// gives also the added option to specify a different prototype.
7234        ///
7235        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7236        #[cfg(not(js_sys_unstable_apis))]
7237        #[wasm_bindgen(js_namespace = Reflect, catch)]
7238        pub fn construct<T: JsFunction = fn() -> JsValue>(
7239            target: &Function<T>,
7240            arguments_list: &Array,
7241        ) -> Result<JsValue, JsValue>;
7242
7243        /// The static `Reflect.construct()` method acts like the new operator, but
7244        /// as a function.  It is equivalent to calling `new target(...args)`. It
7245        /// gives also the added option to specify a different prototype.
7246        ///
7247        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7248        #[cfg(js_sys_unstable_apis)]
7249        #[wasm_bindgen(js_namespace = Reflect, catch)]
7250        pub fn construct<T: JsFunction = fn() -> JsValue>(
7251            target: &Function<T>,
7252            arguments_list: &ArrayTuple, // DOTO: <A1, A2, A3, A4, A5, A6, A7, A8>,
7253        ) -> Result<JsValue, JsValue>;
7254
7255        /// The static `Reflect.construct()` method acts like the new operator, but
7256        /// as a function.  It is equivalent to calling `new target(...args)`. It
7257        /// gives also the added option to specify a different prototype.
7258        ///
7259        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7260        #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
7261        pub fn construct_with_new_target(
7262            target: &Function,
7263            arguments_list: &Array,
7264            new_target: &Function,
7265        ) -> Result<JsValue, JsValue>;
7266
7267        /// The static `Reflect.defineProperty()` method is like
7268        /// `Object.defineProperty()` but returns a `Boolean`.
7269        ///
7270        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7271        #[cfg(not(js_sys_unstable_apis))]
7272        #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7273        pub fn define_property<T>(
7274            target: &Object<T>,
7275            property_key: &JsValue,
7276            attributes: &Object,
7277        ) -> Result<bool, JsValue>;
7278
7279        /// The static `Reflect.defineProperty()` method is like
7280        /// `Object.defineProperty()` but returns a `Boolean`.
7281        ///
7282        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7283        #[cfg(js_sys_unstable_apis)]
7284        #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7285        pub fn define_property<T>(
7286            target: &Object<T>,
7287            property_key: &JsValue,
7288            attributes: &PropertyDescriptor<T>,
7289        ) -> Result<bool, JsValue>;
7290
7291        /// The static `Reflect.defineProperty()` method is like
7292        /// `Object.defineProperty()` but returns a `Boolean`.
7293        ///
7294        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7295        #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7296        pub fn define_property_str<T>(
7297            target: &Object<T>,
7298            property_key: &JsString,
7299            attributes: &PropertyDescriptor<T>,
7300        ) -> Result<bool, JsValue>;
7301
7302        /// The static `Reflect.deleteProperty()` method allows to delete
7303        /// properties.  It is like the `delete` operator as a function.
7304        ///
7305        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7306        #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7307        pub fn delete_property<T>(target: &Object<T>, key: &JsValue) -> Result<bool, JsValue>;
7308
7309        /// The static `Reflect.deleteProperty()` method allows to delete
7310        /// properties.  It is like the `delete` operator as a function.
7311        ///
7312        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7313        #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7314        pub fn delete_property_str<T>(target: &Object<T>, key: &JsString) -> Result<bool, JsValue>;
7315
7316        /// The static `Reflect.get()` method works like getting a property from
7317        /// an object (`target[propertyKey]`) as a function.
7318        ///
7319        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7320        #[cfg(not(js_sys_unstable_apis))]
7321        #[wasm_bindgen(js_namespace = Reflect, catch)]
7322        pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
7323
7324        /// The static `Reflect.get()` method works like getting a property from
7325        /// an object (`target[propertyKey]`) as a function.
7326        ///
7327        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7328        #[cfg(js_sys_unstable_apis)]
7329        #[wasm_bindgen(js_namespace = Reflect, catch)]
7330        pub fn get<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7331
7332        /// The static `Reflect.get()` method works like getting a property from
7333        /// an object (`target[propertyKey]`) as a function.
7334        ///
7335        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7336        #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7337        pub fn get_str<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7338
7339        /// The static `Reflect.get()` method works like getting a property from
7340        /// an object (`target[propertyKey]`) as a function.
7341        ///
7342        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7343        #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7344        pub fn get_symbol<T>(target: &Object<T>, key: &Symbol) -> Result<JsValue, JsValue>;
7345
7346        /// The same as [`get`](fn.get.html)
7347        /// except the key is an `f64`, which is slightly faster.
7348        #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7349        pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
7350
7351        /// The same as [`get`](fn.get.html)
7352        /// except the key is a `u32`, which is slightly faster.
7353        #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7354        pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
7355
7356        /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7357        /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7358        /// of the given property if it exists on the object, `undefined` otherwise.
7359        ///
7360        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7361        #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7362        pub fn get_own_property_descriptor<T>(
7363            target: &Object<T>,
7364            property_key: &JsValue,
7365        ) -> Result<JsValue, JsValue>;
7366
7367        /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7368        /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7369        /// of the given property if it exists on the object, `undefined` otherwise.
7370        ///
7371        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7372        #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7373        pub fn get_own_property_descriptor_str<T>(
7374            target: &Object<T>,
7375            property_key: &JsString,
7376        ) -> Result<PropertyDescriptor<T>, JsValue>;
7377
7378        /// The static `Reflect.getPrototypeOf()` method is almost the same
7379        /// method as `Object.getPrototypeOf()`. It returns the prototype
7380        /// (i.e. the value of the internal `[[Prototype]]` property) of
7381        /// the specified object.
7382        ///
7383        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7384        #[cfg(not(js_sys_unstable_apis))]
7385        #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7386        pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
7387
7388        /// The static `Reflect.getPrototypeOf()` method is almost the same
7389        /// method as `Object.getPrototypeOf()`. It returns the prototype
7390        /// (i.e. the value of the internal `[[Prototype]]` property) of
7391        /// the specified object.
7392        ///
7393        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7394        #[cfg(js_sys_unstable_apis)]
7395        #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7396        pub fn get_prototype_of(target: &Object) -> Result<Object, JsValue>;
7397
7398        /// The static `Reflect.has()` method works like the in operator as a
7399        /// function.
7400        ///
7401        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7402        #[cfg(not(js_sys_unstable_apis))]
7403        #[wasm_bindgen(js_namespace = Reflect, catch)]
7404        pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
7405
7406        /// The static `Reflect.has()` method works like the in operator as a
7407        /// function.
7408        ///
7409        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7410        #[cfg(js_sys_unstable_apis)]
7411        #[wasm_bindgen(js_namespace = Reflect, catch)]
7412        pub fn has(target: &JsValue, property_key: &Symbol) -> Result<bool, JsValue>;
7413
7414        // Next major: deprecate
7415        /// The static `Reflect.has()` method works like the in operator as a
7416        /// function.
7417        ///
7418        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7419        #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7420        pub fn has_str<T>(target: &Object<T>, property_key: &JsString) -> Result<bool, JsValue>;
7421
7422        /// The static `Reflect.has()` method works like the in operator as a
7423        /// function.
7424        ///
7425        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7426        #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7427        pub fn has_symbol<T>(target: &Object<T>, property_key: &Symbol) -> Result<bool, JsValue>;
7428
7429        /// The static `Reflect.isExtensible()` method determines if an object is
7430        /// extensible (whether it can have new properties added to it). It is
7431        /// similar to `Object.isExtensible()`, but with some differences.
7432        ///
7433        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
7434        #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
7435        pub fn is_extensible<T>(target: &Object<T>) -> Result<bool, JsValue>;
7436
7437        /// The static `Reflect.ownKeys()` method returns an array of the
7438        /// target object's own property keys.
7439        ///
7440        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
7441        #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
7442        pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
7443
7444        /// The static `Reflect.preventExtensions()` method prevents new
7445        /// properties from ever being added to an object (i.e. prevents
7446        /// future extensions to the object). It is similar to
7447        /// `Object.preventExtensions()`, but with some differences.
7448        ///
7449        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
7450        #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
7451        pub fn prevent_extensions<T>(target: &Object<T>) -> Result<bool, JsValue>;
7452
7453        /// The static `Reflect.set()` method works like setting a
7454        /// property on an object.
7455        ///
7456        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7457        #[cfg(not(js_sys_unstable_apis))]
7458        #[wasm_bindgen(js_namespace = Reflect, catch)]
7459        pub fn set(
7460            target: &JsValue,
7461            property_key: &JsValue,
7462            value: &JsValue,
7463        ) -> Result<bool, JsValue>;
7464
7465        /// The static `Reflect.set()` method works like setting a
7466        /// property on an object.
7467        ///
7468        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7469        #[cfg(js_sys_unstable_apis)]
7470        #[wasm_bindgen(js_namespace = Reflect, catch)]
7471        pub fn set<T>(
7472            target: &Object<T>,
7473            property_key: &JsString,
7474            value: &T,
7475        ) -> Result<bool, JsValue>;
7476
7477        /// The static `Reflect.set()` method works like setting a
7478        /// property on an object.
7479        ///
7480        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7481        #[cfg(js_sys_unstable_apis)]
7482        #[wasm_bindgen(js_namespace = Reflect, catch)]
7483        pub fn set_symbol<T>(
7484            target: &Object<T>,
7485            property_key: &Symbol,
7486            value: &JsValue,
7487        ) -> Result<bool, JsValue>;
7488
7489        // Next major: deprecate
7490        /// The static `Reflect.set()` method works like setting a
7491        /// property on an object.
7492        ///
7493        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7494        #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7495        pub fn set_str<T>(
7496            target: &Object<T>,
7497            property_key: &JsString,
7498            value: &T,
7499        ) -> Result<bool, JsValue>;
7500
7501        /// The same as [`set`](fn.set.html)
7502        /// except the key is an `f64`, which is slightly faster.
7503        #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7504        pub fn set_f64(
7505            target: &JsValue,
7506            property_key: f64,
7507            value: &JsValue,
7508        ) -> Result<bool, JsValue>;
7509
7510        /// The same as [`set`](fn.set.html)
7511        /// except the key is a `u32`, which is slightly faster.
7512        #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7513        pub fn set_u32(
7514            target: &JsValue,
7515            property_key: u32,
7516            value: &JsValue,
7517        ) -> Result<bool, JsValue>;
7518
7519        /// The static `Reflect.set()` method works like setting a
7520        /// property on an object.
7521        ///
7522        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7523        #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7524        pub fn set_with_receiver(
7525            target: &JsValue,
7526            property_key: &JsValue,
7527            value: &JsValue,
7528            receiver: &JsValue,
7529        ) -> Result<bool, JsValue>;
7530
7531        /// The static `Reflect.setPrototypeOf()` method is the same
7532        /// method as `Object.setPrototypeOf()`. It sets the prototype
7533        /// (i.e., the internal `[[Prototype]]` property) of a specified
7534        /// object to another object or to null.
7535        ///
7536        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
7537        #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
7538        pub fn set_prototype_of<T>(
7539            target: &Object<T>,
7540            prototype: &JsValue,
7541        ) -> Result<bool, JsValue>;
7542    }
7543}
7544
7545// RegExp
7546#[wasm_bindgen]
7547extern "C" {
7548    #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
7549    #[derive(Clone, Debug, PartialEq, Eq)]
7550    pub type RegExp;
7551
7552    /// The `exec()` method executes a search for a match in a specified
7553    /// string. Returns a result array, or null.
7554    ///
7555    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7556    #[cfg(not(js_sys_unstable_apis))]
7557    #[wasm_bindgen(method)]
7558    pub fn exec(this: &RegExp, text: &str) -> Option<Array<JsString>>;
7559
7560    /// The `exec()` method executes a search for a match in a specified
7561    /// string. Returns a result array, or null.
7562    ///
7563    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7564    #[cfg(js_sys_unstable_apis)]
7565    #[wasm_bindgen(method)]
7566    pub fn exec(this: &RegExp, text: &str) -> Option<RegExpMatchArray>;
7567
7568    /// The flags property returns a string consisting of the flags of
7569    /// the current regular expression object.
7570    ///
7571    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
7572    #[wasm_bindgen(method, getter)]
7573    pub fn flags(this: &RegExp) -> JsString;
7574
7575    /// The global property indicates whether or not the "g" flag is
7576    /// used with the regular expression. global is a read-only
7577    /// property of an individual regular expression instance.
7578    ///
7579    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
7580    #[wasm_bindgen(method, getter)]
7581    pub fn global(this: &RegExp) -> bool;
7582
7583    /// The ignoreCase property indicates whether or not the "i" flag
7584    /// is used with the regular expression. ignoreCase is a read-only
7585    /// property of an individual regular expression instance.
7586    ///
7587    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
7588    #[wasm_bindgen(method, getter, js_name = ignoreCase)]
7589    pub fn ignore_case(this: &RegExp) -> bool;
7590
7591    /// The non-standard input property is a static property of
7592    /// regular expressions that contains the string against which a
7593    /// regular expression is matched. RegExp.$_ is an alias for this
7594    /// property.
7595    ///
7596    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
7597    #[wasm_bindgen(static_method_of = RegExp, getter)]
7598    pub fn input() -> JsString;
7599
7600    /// The lastIndex is a read/write integer property of regular expression
7601    /// instances that specifies the index at which to start the next match.
7602    ///
7603    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7604    #[wasm_bindgen(structural, getter = lastIndex, method)]
7605    pub fn last_index(this: &RegExp) -> u32;
7606
7607    /// The lastIndex is a read/write integer property of regular expression
7608    /// instances that specifies the index at which to start the next match.
7609    ///
7610    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7611    #[wasm_bindgen(structural, setter = lastIndex, method)]
7612    pub fn set_last_index(this: &RegExp, index: u32);
7613
7614    /// The non-standard lastMatch property is a static and read-only
7615    /// property of regular expressions that contains the last matched
7616    /// characters. `RegExp.$&` is an alias for this property.
7617    ///
7618    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
7619    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
7620    pub fn last_match() -> JsString;
7621
7622    /// The non-standard lastParen property is a static and read-only
7623    /// property of regular expressions that contains the last
7624    /// parenthesized substring match, if any. `RegExp.$+` is an alias
7625    /// for this property.
7626    ///
7627    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
7628    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
7629    pub fn last_paren() -> JsString;
7630
7631    /// The non-standard leftContext property is a static and
7632    /// read-only property of regular expressions that contains the
7633    /// substring preceding the most recent match. `RegExp.$`` is an
7634    /// alias for this property.
7635    ///
7636    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
7637    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
7638    pub fn left_context() -> JsString;
7639
7640    /// The multiline property indicates whether or not the "m" flag
7641    /// is used with the regular expression. multiline is a read-only
7642    /// property of an individual regular expression instance.
7643    ///
7644    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
7645    #[wasm_bindgen(method, getter)]
7646    pub fn multiline(this: &RegExp) -> bool;
7647
7648    /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
7649    /// are static and read-only properties of regular expressions
7650    /// that contain parenthesized substring matches.
7651    ///
7652    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
7653    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
7654    pub fn n1() -> JsString;
7655    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
7656    pub fn n2() -> JsString;
7657    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
7658    pub fn n3() -> JsString;
7659    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
7660    pub fn n4() -> JsString;
7661    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
7662    pub fn n5() -> JsString;
7663    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
7664    pub fn n6() -> JsString;
7665    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
7666    pub fn n7() -> JsString;
7667    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
7668    pub fn n8() -> JsString;
7669    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
7670    pub fn n9() -> JsString;
7671
7672    /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
7673    ///
7674    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
7675    #[wasm_bindgen(constructor)]
7676    pub fn new(pattern: &str, flags: &str) -> RegExp;
7677    #[wasm_bindgen(constructor)]
7678    pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
7679
7680    /// The non-standard rightContext property is a static and
7681    /// read-only property of regular expressions that contains the
7682    /// substring following the most recent match. `RegExp.$'` is an
7683    /// alias for this property.
7684    ///
7685    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
7686    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
7687    pub fn right_context() -> JsString;
7688
7689    /// The source property returns a String containing the source
7690    /// text of the regexp object, and it doesn't contain the two
7691    /// forward slashes on both sides and any flags.
7692    ///
7693    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
7694    #[wasm_bindgen(method, getter)]
7695    pub fn source(this: &RegExp) -> JsString;
7696
7697    /// The sticky property reflects whether or not the search is
7698    /// sticky (searches in strings only from the index indicated by
7699    /// the lastIndex property of this regular expression). sticky is
7700    /// a read-only property of an individual regular expression
7701    /// object.
7702    ///
7703    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
7704    #[wasm_bindgen(method, getter)]
7705    pub fn sticky(this: &RegExp) -> bool;
7706
7707    /// The `test()` method executes a search for a match between a
7708    /// regular expression and a specified string. Returns true or
7709    /// false.
7710    ///
7711    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
7712    #[wasm_bindgen(method)]
7713    pub fn test(this: &RegExp, text: &str) -> bool;
7714
7715    /// The `toString()` method returns a string representing the
7716    /// regular expression.
7717    ///
7718    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
7719    #[cfg(not(js_sys_unstable_apis))]
7720    #[wasm_bindgen(method, js_name = toString)]
7721    pub fn to_string(this: &RegExp) -> JsString;
7722
7723    /// The unicode property indicates whether or not the "u" flag is
7724    /// used with a regular expression. unicode is a read-only
7725    /// property of an individual regular expression instance.
7726    ///
7727    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
7728    #[wasm_bindgen(method, getter)]
7729    pub fn unicode(this: &RegExp) -> bool;
7730}
7731
7732// RegExpMatchArray
7733#[wasm_bindgen]
7734extern "C" {
7735    /// The result array from `RegExp.exec()` or `String.matchAll()`.
7736    ///
7737    /// This is an array of strings with additional properties `index`, `input`, and `groups`.
7738    ///
7739    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#return_value)
7740    #[wasm_bindgen(extends = Object, extends = Array, typescript_type = "RegExpMatchArray")]
7741    #[derive(Clone, Debug, PartialEq, Eq)]
7742    pub type RegExpMatchArray;
7743
7744    /// The 0-based index of the match in the string.
7745    #[wasm_bindgen(method, getter)]
7746    pub fn index(this: &RegExpMatchArray) -> u32;
7747
7748    /// The original string that was matched against.
7749    #[wasm_bindgen(method, getter)]
7750    pub fn input(this: &RegExpMatchArray) -> JsString;
7751
7752    /// An object of named capturing groups whose keys are the names and valuestype Array
7753    /// are the capturing groups, or `undefined` if no named capturing groups were defined.
7754    #[wasm_bindgen(method, getter)]
7755    pub fn groups(this: &RegExpMatchArray) -> Option<Object>;
7756
7757    /// The number of elements in the match array (full match + capture groups).
7758    #[wasm_bindgen(method, getter)]
7759    pub fn length(this: &RegExpMatchArray) -> u32;
7760
7761    /// Gets the matched string or capture group at the given index.
7762    /// Index 0 is the full match, indices 1+ are capture groups.
7763    #[wasm_bindgen(method, indexing_getter)]
7764    pub fn get(this: &RegExpMatchArray, index: u32) -> Option<JsString>;
7765}
7766
7767// Set
7768#[wasm_bindgen]
7769extern "C" {
7770    #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
7771    #[derive(Clone, Debug, PartialEq, Eq)]
7772    pub type Set<T = JsValue>;
7773
7774    /// The [`Set`] object lets you store unique values of any type, whether
7775    /// primitive values or object references.
7776    ///
7777    /// **Note:** Consider using [`Set::new_typed`] to support typing.
7778    ///
7779    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7780    #[cfg(not(js_sys_unstable_apis))]
7781    #[wasm_bindgen(constructor)]
7782    pub fn new(init: &JsValue) -> Set;
7783
7784    /// The [`Set`] object lets you store unique values of any type, whether
7785    /// primitive values or object references.
7786    ///
7787    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7788    #[cfg(js_sys_unstable_apis)]
7789    #[wasm_bindgen(constructor)]
7790    pub fn new<T>() -> Set<T>;
7791
7792    // Next major: deprecate
7793    /// The [`Set`] object lets you store unique values of any type, whether
7794    /// primitive values or object references.
7795    ///
7796    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7797    #[wasm_bindgen(constructor)]
7798    pub fn new_typed<T>() -> Set<T>;
7799
7800    /// The [`Set`] object lets you store unique values of any type, whether
7801    /// primitive values or object references.
7802    ///
7803    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7804    #[wasm_bindgen(constructor, js_name = new)]
7805    pub fn new_empty<T>() -> Set<T>;
7806
7807    /// The [`Set`] object lets you store unique values of any type, whether
7808    /// primitive values or object references.
7809    ///
7810    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7811    #[wasm_bindgen(constructor, js_name = new)]
7812    pub fn new_from_items<T>(items: &[T]) -> Set<T>;
7813
7814    /// The [`Set`] object lets you store unique values of any type, whether
7815    /// primitive values or object references.
7816    ///
7817    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7818    #[wasm_bindgen(constructor, js_name = new, catch)]
7819    pub fn new_from_iterable<T, I: Iterable<Item = T>>(iterable: I) -> Result<Set<T>, JsValue>;
7820
7821    /// The `add()` method appends a new element with a specified value to the
7822    /// end of a [`Set`] object.
7823    ///
7824    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
7825    #[wasm_bindgen(method)]
7826    pub fn add<T>(this: &Set<T>, value: &T) -> Set<T>;
7827
7828    /// The `clear()` method removes all elements from a [`Set`] object.
7829    ///
7830    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
7831    #[wasm_bindgen(method)]
7832    pub fn clear<T>(this: &Set<T>);
7833
7834    /// The `delete()` method removes the specified element from a [`Set`]
7835    /// object.
7836    ///
7837    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
7838    #[wasm_bindgen(method)]
7839    pub fn delete<T>(this: &Set<T>, value: &T) -> bool;
7840
7841    /// The `forEach()` method executes a provided function once for each value
7842    /// in the Set object, in insertion order.
7843    ///
7844    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7845    #[cfg(not(js_sys_unstable_apis))]
7846    #[wasm_bindgen(method, js_name = forEach)]
7847    pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T, T, Set<T>));
7848
7849    /// The `forEach()` method executes a provided function once for each value
7850    /// in the Set object, in insertion order.
7851    ///
7852    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7853    #[cfg(js_sys_unstable_apis)]
7854    #[wasm_bindgen(method, js_name = forEach)]
7855    pub fn for_each<'a, T>(this: &Set<T>, callback: &ImmediateClosure<'a, dyn FnMut(T) + 'a>);
7856
7857    /// The `forEach()` method executes a provided function once for each value
7858    /// in the Set object, in insertion order.
7859    ///
7860    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7861    #[wasm_bindgen(method, js_name = forEach, catch)]
7862    pub fn try_for_each<'a, T>(
7863        this: &Set<T>,
7864        callback: &ImmediateClosure<'a, dyn FnMut(T) -> Result<(), JsError> + 'a>,
7865    ) -> Result<(), JsValue>;
7866
7867    /// The `has()` method returns a boolean indicating whether an element with
7868    /// the specified value exists in a [`Set`] object or not.
7869    ///
7870    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
7871    #[wasm_bindgen(method)]
7872    pub fn has<T>(this: &Set<T>, value: &T) -> bool;
7873
7874    /// The size accessor property returns the number of elements in a [`Set`]
7875    /// object.
7876    ///
7877    /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
7878    #[wasm_bindgen(method, getter)]
7879    pub fn size<T>(this: &Set<T>) -> u32;
7880
7881    /// The `union()` method returns a new set containing elements which are in
7882    /// either or both of this set and the given set.
7883    ///
7884    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union)
7885    #[wasm_bindgen(method)]
7886    pub fn union<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7887
7888    /// The `intersection()` method returns a new set containing elements which are
7889    /// in both this set and the given set.
7890    ///
7891    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection)
7892    #[wasm_bindgen(method)]
7893    pub fn intersection<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7894
7895    /// The `difference()` method returns a new set containing elements which are
7896    /// in this set but not in the given set.
7897    ///
7898    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference)
7899    #[wasm_bindgen(method)]
7900    pub fn difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7901
7902    /// The `symmetricDifference()` method returns a new set containing elements
7903    /// which are in either this set or the given set, but not in both.
7904    ///
7905    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)
7906    #[wasm_bindgen(method, js_name = symmetricDifference)]
7907    pub fn symmetric_difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7908
7909    /// The `isSubsetOf()` method returns a boolean indicating whether all elements
7910    /// of this set are in the given set.
7911    ///
7912    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSubsetOf)
7913    #[wasm_bindgen(method, js_name = isSubsetOf)]
7914    pub fn is_subset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
7915
7916    /// The `isSupersetOf()` method returns a boolean indicating whether all elements
7917    /// of the given set are in this set.
7918    ///
7919    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSupersetOf)
7920    #[wasm_bindgen(method, js_name = isSupersetOf)]
7921    pub fn is_superset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
7922
7923    /// The `isDisjointFrom()` method returns a boolean indicating whether this set
7924    /// has no elements in common with the given set.
7925    ///
7926    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom)
7927    #[wasm_bindgen(method, js_name = isDisjointFrom)]
7928    pub fn is_disjoint_from<T>(this: &Set<T>, other: &Set<T>) -> bool;
7929}
7930
7931impl Default for Set<JsValue> {
7932    fn default() -> Self {
7933        Self::new_typed()
7934    }
7935}
7936
7937impl<T> Iterable for Set<T> {
7938    type Item = T;
7939}
7940
7941// SetIterator
7942#[wasm_bindgen]
7943extern "C" {
7944    /// The `entries()` method returns a new Iterator object that contains an
7945    /// array of [value, value] for each element in the Set object, in insertion
7946    /// order. For Set objects there is no key like in Map objects. However, to
7947    /// keep the API similar to the Map object, each entry has the same value
7948    /// for its key and value here, so that an array [value, value] is returned.
7949    ///
7950    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7951    #[cfg(not(js_sys_unstable_apis))]
7952    #[wasm_bindgen(method)]
7953    pub fn entries<T>(set: &Set<T>) -> Iterator;
7954
7955    /// The `entries()` method returns a new Iterator object that contains an
7956    /// array of [value, value] for each element in the Set object, in insertion
7957    /// order. For Set objects there is no key like in Map objects. However, to
7958    /// keep the API similar to the Map object, each entry has the same value
7959    /// for its key and value here, so that an array [value, value] is returned.
7960    ///
7961    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7962    #[cfg(js_sys_unstable_apis)]
7963    #[wasm_bindgen(method, js_name = entries)]
7964    pub fn entries<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
7965
7966    // Next major: deprecate
7967    /// The `entries()` method returns a new Iterator object that contains an
7968    /// array of [value, value] for each element in the Set object, in insertion
7969    /// order. For Set objects there is no key like in Map objects. However, to
7970    /// keep the API similar to the Map object, each entry has the same value
7971    /// for its key and value here, so that an array [value, value] is returned.
7972    ///
7973    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7974    #[wasm_bindgen(method, js_name = entries)]
7975    pub fn entries_typed<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
7976
7977    /// The `keys()` method is an alias for this method (for similarity with
7978    /// Map objects); it behaves exactly the same and returns values
7979    /// of Set elements.
7980    ///
7981    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
7982    #[wasm_bindgen(method)]
7983    pub fn keys<T>(set: &Set<T>) -> Iterator<T>;
7984
7985    /// The `values()` method returns a new Iterator object that contains the
7986    /// values for each element in the Set object in insertion order.
7987    ///
7988    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
7989    #[wasm_bindgen(method)]
7990    pub fn values<T>(set: &Set<T>) -> Iterator<T>;
7991}
7992
7993// SyntaxError
7994#[wasm_bindgen]
7995extern "C" {
7996    /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
7997    /// token order that does not conform to the syntax of the language when
7998    /// parsing code.
7999    ///
8000    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8001    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
8002    #[derive(Clone, Debug, PartialEq, Eq)]
8003    pub type SyntaxError;
8004
8005    /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8006    /// token order that does not conform to the syntax of the language when
8007    /// parsing code.
8008    ///
8009    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8010    #[wasm_bindgen(constructor)]
8011    pub fn new(message: &str) -> SyntaxError;
8012}
8013
8014// TypeError
8015#[wasm_bindgen]
8016extern "C" {
8017    /// The `TypeError` object represents an error when a value is not of the
8018    /// expected type.
8019    ///
8020    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8021    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
8022    #[derive(Clone, Debug, PartialEq, Eq)]
8023    pub type TypeError;
8024
8025    /// The `TypeError` object represents an error when a value is not of the
8026    /// expected type.
8027    ///
8028    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8029    #[wasm_bindgen(constructor)]
8030    pub fn new(message: &str) -> TypeError;
8031}
8032
8033// URIError
8034#[wasm_bindgen]
8035extern "C" {
8036    /// The `URIError` object represents an error when a global URI handling
8037    /// function was used in a wrong way.
8038    ///
8039    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8040    #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
8041    #[derive(Clone, Debug, PartialEq, Eq)]
8042    pub type UriError;
8043
8044    /// The `URIError` object represents an error when a global URI handling
8045    /// function was used in a wrong way.
8046    ///
8047    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8048    #[wasm_bindgen(constructor, js_class = "URIError")]
8049    pub fn new(message: &str) -> UriError;
8050}
8051
8052// WeakMap
8053#[wasm_bindgen]
8054extern "C" {
8055    #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
8056    #[derive(Clone, Debug, PartialEq, Eq)]
8057    pub type WeakMap<K = Object, V = JsValue>;
8058
8059    /// The [`WeakMap`] object is a collection of key/value pairs in which the
8060    /// keys are weakly referenced.  The keys must be objects and the values can
8061    /// be arbitrary values.
8062    ///
8063    /// **Note:** Consider using [`WeakMap::new_typed`] to support typing.
8064    ///
8065    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8066    #[cfg(not(js_sys_unstable_apis))]
8067    #[wasm_bindgen(constructor)]
8068    pub fn new() -> WeakMap;
8069
8070    /// The [`WeakMap`] object is a collection of key/value pairs in which the
8071    /// keys are weakly referenced.  The keys must be objects and the values can
8072    /// be arbitrary values.
8073    ///
8074    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8075    #[cfg(js_sys_unstable_apis)]
8076    #[wasm_bindgen(constructor)]
8077    pub fn new<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8078
8079    // Next major: deprecate
8080    /// The [`WeakMap`] object is a collection of key/value pairs in which the
8081    /// keys are weakly referenced.  The keys must be objects and the values can
8082    /// be arbitrary values.
8083    ///
8084    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8085    #[wasm_bindgen(constructor)]
8086    pub fn new_typed<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8087
8088    /// The `set()` method sets the value for the key in the [`WeakMap`] object.
8089    /// Returns the [`WeakMap`] object.
8090    ///
8091    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
8092    #[wasm_bindgen(method, js_class = "WeakMap")]
8093    pub fn set<K, V>(this: &WeakMap<K, V>, key: &K, value: &V) -> WeakMap<K, V>;
8094
8095    /// The `get()` method returns a specified by key element
8096    /// from a [`WeakMap`] object. Returns `undefined` if the key is not found.
8097    ///
8098    /// **Note:** Consider using [`WeakMap::get_checked`] to get an `Option<V>` instead.
8099    ///
8100    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8101    #[cfg(not(js_sys_unstable_apis))]
8102    #[wasm_bindgen(method)]
8103    pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> V;
8104
8105    /// The `get()` method returns a specified by key element
8106    /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8107    ///
8108    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8109    #[cfg(js_sys_unstable_apis)]
8110    #[wasm_bindgen(method)]
8111    pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8112
8113    /// The `get()` method returns a specified by key element
8114    /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8115    ///
8116    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8117    #[wasm_bindgen(method, js_name = get)]
8118    pub fn get_checked<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8119
8120    /// The `has()` method returns a boolean indicating whether an element with
8121    /// the specified key exists in the [`WeakMap`] object or not.
8122    ///
8123    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
8124    #[wasm_bindgen(method)]
8125    pub fn has<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8126
8127    /// The `delete()` method removes the specified element from a [`WeakMap`]
8128    /// object.
8129    ///
8130    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
8131    #[wasm_bindgen(method)]
8132    pub fn delete<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8133}
8134
8135impl Default for WeakMap {
8136    fn default() -> Self {
8137        Self::new()
8138    }
8139}
8140
8141// WeakSet
8142#[wasm_bindgen]
8143extern "C" {
8144    #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
8145    #[derive(Clone, Debug, PartialEq, Eq)]
8146    pub type WeakSet<T = Object>;
8147
8148    /// The `WeakSet` object lets you store weakly held objects in a collection.
8149    ///
8150    /// **Note:** Consider using [`WeakSet::new_typed`] for typed sets.
8151    ///
8152    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8153    #[cfg(not(js_sys_unstable_apis))]
8154    #[wasm_bindgen(constructor)]
8155    pub fn new() -> WeakSet;
8156
8157    /// The `WeakSet` object lets you store weakly held objects in a collection.
8158    ///
8159    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8160    #[cfg(js_sys_unstable_apis)]
8161    #[wasm_bindgen(constructor)]
8162    pub fn new<T = Object>() -> WeakSet<T>;
8163
8164    // Next major: deprecate
8165    /// The `WeakSet` object lets you store weakly held objects in a collection.
8166    ///
8167    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8168    #[wasm_bindgen(constructor)]
8169    pub fn new_typed<T = Object>() -> WeakSet<T>;
8170
8171    /// The `has()` method returns a boolean indicating whether an object exists
8172    /// in a WeakSet or not.
8173    ///
8174    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
8175    #[wasm_bindgen(method)]
8176    pub fn has<T>(this: &WeakSet<T>, value: &T) -> bool;
8177
8178    /// The `add()` method appends a new object to the end of a WeakSet object.
8179    ///
8180    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
8181    #[wasm_bindgen(method)]
8182    pub fn add<T>(this: &WeakSet<T>, value: &T) -> WeakSet<T>;
8183
8184    /// The `delete()` method removes the specified element from a WeakSet
8185    /// object.
8186    ///
8187    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
8188    #[wasm_bindgen(method)]
8189    pub fn delete<T>(this: &WeakSet<T>, value: &T) -> bool;
8190}
8191
8192impl Default for WeakSet {
8193    fn default() -> Self {
8194        Self::new()
8195    }
8196}
8197
8198// WeakRef
8199#[wasm_bindgen]
8200extern "C" {
8201    #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
8202    #[derive(Clone, Debug, PartialEq, Eq)]
8203    pub type WeakRef<T = Object>;
8204
8205    /// The `WeakRef` object contains a weak reference to an object. A weak
8206    /// reference to an object is a reference that does not prevent the object
8207    /// from being reclaimed by the garbage collector.
8208    ///
8209    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
8210    #[wasm_bindgen(constructor)]
8211    pub fn new<T = Object>(target: &T) -> WeakRef<T>;
8212
8213    /// Returns the `Object` this `WeakRef` points to, or `None` if the
8214    /// object has been garbage collected.
8215    ///
8216    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
8217    #[wasm_bindgen(method)]
8218    pub fn deref<T>(this: &WeakRef<T>) -> Option<T>;
8219}
8220
8221#[cfg(js_sys_unstable_apis)]
8222#[allow(non_snake_case)]
8223pub mod Temporal;
8224
8225#[allow(non_snake_case)]
8226pub mod WebAssembly {
8227    use super::*;
8228
8229    // WebAssembly
8230    #[wasm_bindgen]
8231    extern "C" {
8232        /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8233        /// from WebAssembly binary code.  This function is useful if it is
8234        /// necessary to a compile a module before it can be instantiated
8235        /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8236        ///
8237        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8238        #[cfg(not(js_sys_unstable_apis))]
8239        #[wasm_bindgen(js_namespace = WebAssembly)]
8240        pub fn compile(buffer_source: &JsValue) -> Promise<JsValue>;
8241
8242        /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8243        /// from WebAssembly binary code.  This function is useful if it is
8244        /// necessary to a compile a module before it can be instantiated
8245        /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8246        ///
8247        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8248        #[cfg(js_sys_unstable_apis)]
8249        #[wasm_bindgen(js_namespace = WebAssembly)]
8250        pub fn compile(buffer_source: &JsValue) -> Promise<Module>;
8251
8252        /// The `WebAssembly.compileStreaming()` function compiles a
8253        /// `WebAssembly.Module` module directly from a streamed underlying
8254        /// source. This function is useful if it is necessary to a compile a
8255        /// module before it can be instantiated (otherwise, the
8256        /// `WebAssembly.instantiateStreaming()` function should be used).
8257        ///
8258        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8259        #[cfg(not(js_sys_unstable_apis))]
8260        #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8261        pub fn compile_streaming(response: &Promise) -> Promise<JsValue>;
8262
8263        /// The `WebAssembly.compileStreaming()` function compiles a
8264        /// `WebAssembly.Module` module directly from a streamed underlying
8265        /// source. This function is useful if it is necessary to a compile a
8266        /// module before it can be instantiated (otherwise, the
8267        /// `WebAssembly.instantiateStreaming()` function should be used).
8268        ///
8269        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8270        #[cfg(js_sys_unstable_apis)]
8271        #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8272        pub fn compile_streaming(response: &Promise) -> Promise<Module>;
8273
8274        /// The `WebAssembly.instantiate()` function allows you to compile and
8275        /// instantiate WebAssembly code.
8276        ///
8277        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8278        #[cfg(not(js_sys_unstable_apis))]
8279        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8280        pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<JsValue>;
8281
8282        /// The `WebAssembly.instantiate()` function allows you to compile and
8283        /// instantiate WebAssembly code.
8284        ///
8285        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8286        #[cfg(js_sys_unstable_apis)]
8287        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8288        pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<Instance>;
8289
8290        /// The `WebAssembly.instantiate()` function allows you to compile and
8291        /// instantiate WebAssembly code.
8292        ///
8293        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8294        #[cfg(not(js_sys_unstable_apis))]
8295        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8296        pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<JsValue>;
8297
8298        /// The `WebAssembly.instantiate()` function allows you to compile and
8299        /// instantiate WebAssembly code.
8300        ///
8301        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8302        #[cfg(js_sys_unstable_apis)]
8303        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8304        pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<Instance>;
8305
8306        /// The `WebAssembly.instantiateStreaming()` function compiles and
8307        /// instantiates a WebAssembly module directly from a streamed
8308        /// underlying source. This is the most efficient, optimized way to load
8309        /// Wasm code.
8310        ///
8311        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8312        #[cfg(not(js_sys_unstable_apis))]
8313        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8314        pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<JsValue>;
8315
8316        /// The `WebAssembly.instantiateStreaming()` function compiles and
8317        /// instantiates a WebAssembly module directly from a streamed
8318        /// underlying source. This is the most efficient, optimized way to load
8319        /// Wasm code.
8320        ///
8321        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8322        #[cfg(js_sys_unstable_apis)]
8323        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8324        pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<Instance>;
8325
8326        /// The `WebAssembly.validate()` function validates a given typed
8327        /// array of WebAssembly binary code, returning whether the bytes
8328        /// form a valid Wasm module (`true`) or not (`false`).
8329        ///
8330        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
8331        #[wasm_bindgen(js_namespace = WebAssembly, catch)]
8332        pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
8333    }
8334
8335    // WebAssembly.CompileError
8336    #[wasm_bindgen]
8337    extern "C" {
8338        /// The `WebAssembly.CompileError()` constructor creates a new
8339        /// WebAssembly `CompileError` object, which indicates an error during
8340        /// WebAssembly decoding or validation.
8341        ///
8342        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8343        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
8344        #[derive(Clone, Debug, PartialEq, Eq)]
8345        pub type CompileError;
8346
8347        /// The `WebAssembly.CompileError()` constructor creates a new
8348        /// WebAssembly `CompileError` object, which indicates an error during
8349        /// WebAssembly decoding or validation.
8350        ///
8351        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8352        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8353        pub fn new(message: &str) -> CompileError;
8354    }
8355
8356    // WebAssembly.Instance
8357    #[wasm_bindgen]
8358    extern "C" {
8359        /// A `WebAssembly.Instance` object is a stateful, executable instance
8360        /// of a `WebAssembly.Module`. Instance objects contain all the exported
8361        /// WebAssembly functions that allow calling into WebAssembly code from
8362        /// JavaScript.
8363        ///
8364        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8365        #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
8366        #[derive(Clone, Debug, PartialEq, Eq)]
8367        pub type Instance;
8368
8369        /// The `WebAssembly.Instance()` constructor function can be called to
8370        /// synchronously instantiate a given `WebAssembly.Module`
8371        /// object. However, the primary way to get an `Instance` is through the
8372        /// asynchronous `WebAssembly.instantiateStreaming()` function.
8373        ///
8374        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8375        #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
8376        pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
8377
8378        /// The `exports` readonly property of the `WebAssembly.Instance` object
8379        /// prototype returns an object containing as its members all the
8380        /// functions exported from the WebAssembly module instance, to allow
8381        /// them to be accessed and used by JavaScript.
8382        ///
8383        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
8384        #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
8385        pub fn exports(this: &Instance) -> Object;
8386    }
8387
8388    // WebAssembly.LinkError
8389    #[wasm_bindgen]
8390    extern "C" {
8391        /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8392        /// LinkError object, which indicates an error during module
8393        /// instantiation (besides traps from the start function).
8394        ///
8395        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8396        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
8397        #[derive(Clone, Debug, PartialEq, Eq)]
8398        pub type LinkError;
8399
8400        /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8401        /// LinkError object, which indicates an error during module
8402        /// instantiation (besides traps from the start function).
8403        ///
8404        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8405        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8406        pub fn new(message: &str) -> LinkError;
8407    }
8408
8409    // WebAssembly.RuntimeError
8410    #[wasm_bindgen]
8411    extern "C" {
8412        /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8413        /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8414        /// specifies a trap.
8415        ///
8416        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8417        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
8418        #[derive(Clone, Debug, PartialEq, Eq)]
8419        pub type RuntimeError;
8420
8421        /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8422        /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8423        /// specifies a trap.
8424        ///
8425        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8426        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8427        pub fn new(message: &str) -> RuntimeError;
8428    }
8429
8430    // WebAssembly.Module
8431    #[wasm_bindgen]
8432    extern "C" {
8433        /// A `WebAssembly.Module` object contains stateless WebAssembly code
8434        /// that has already been compiled by the browser and can be
8435        /// efficiently shared with Workers, and instantiated multiple times.
8436        ///
8437        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8438        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
8439        #[derive(Clone, Debug, PartialEq, Eq)]
8440        pub type Module;
8441
8442        /// A `WebAssembly.Module` object contains stateless WebAssembly code
8443        /// that has already been compiled by the browser and can be
8444        /// efficiently shared with Workers, and instantiated multiple times.
8445        ///
8446        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8447        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8448        pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
8449
8450        /// The `WebAssembly.customSections()` function returns a copy of the
8451        /// contents of all custom sections in the given module with the given
8452        /// string name.
8453        ///
8454        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
8455        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
8456        pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
8457
8458        /// The `WebAssembly.exports()` function returns an array containing
8459        /// descriptions of all the declared exports of the given `Module`.
8460        ///
8461        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
8462        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8463        pub fn exports(module: &Module) -> Array;
8464
8465        /// The `WebAssembly.imports()` function returns an array containing
8466        /// descriptions of all the declared imports of the given `Module`.
8467        ///
8468        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
8469        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8470        pub fn imports(module: &Module) -> Array;
8471    }
8472
8473    // WebAssembly.Table
8474    #[wasm_bindgen]
8475    extern "C" {
8476        /// The `WebAssembly.Table()` constructor creates a new `Table` object
8477        /// of the given size and element type.
8478        ///
8479        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8480        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
8481        #[derive(Clone, Debug, PartialEq, Eq)]
8482        pub type Table;
8483
8484        /// The `WebAssembly.Table()` constructor creates a new `Table` object
8485        /// of the given size and element type.
8486        ///
8487        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8488        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8489        pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
8490
8491        /// The `WebAssembly.Table()` constructor creates a new `Table` object
8492        /// of the given size and element type.
8493        ///
8494        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8495        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8496        pub fn new_with_value(table_descriptor: &Object, value: JsValue) -> Result<Table, JsValue>;
8497
8498        /// The length prototype property of the `WebAssembly.Table` object
8499        /// returns the length of the table, i.e. the number of elements in the
8500        /// table.
8501        ///
8502        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
8503        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8504        pub fn length(this: &Table) -> u32;
8505
8506        /// The `get()` prototype method of the `WebAssembly.Table()` object
8507        /// retrieves a function reference stored at a given index.
8508        ///
8509        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8510        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8511        pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
8512
8513        /// The `get()` prototype method of the `WebAssembly.Table()` object
8514        /// retrieves a function reference stored at a given index.
8515        ///
8516        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8517        #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = get)]
8518        pub fn get_raw(this: &Table, index: u32) -> Result<JsValue, JsValue>;
8519
8520        /// The `grow()` prototype method of the `WebAssembly.Table` object
8521        /// increases the size of the `Table` instance by a specified number of
8522        /// elements.
8523        ///
8524        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8525        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8526        pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
8527
8528        /// The `grow()` prototype method of the `WebAssembly.Table` object
8529        /// increases the size of the `Table` instance by a specified number of
8530        /// elements.
8531        ///
8532        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8533        #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = grow)]
8534        pub fn grow_with_value(
8535            this: &Table,
8536            additional_capacity: u32,
8537            value: JsValue,
8538        ) -> Result<u32, JsValue>;
8539
8540        /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8541        /// reference stored at a given index to a different value.
8542        ///
8543        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8544        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8545        pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
8546
8547        /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8548        /// reference stored at a given index to a different value.
8549        ///
8550        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8551        #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = set)]
8552        pub fn set_raw(this: &Table, index: u32, value: &JsValue) -> Result<(), JsValue>;
8553    }
8554
8555    // WebAssembly.Tag
8556    #[wasm_bindgen]
8557    extern "C" {
8558        /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8559        ///
8560        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8561        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
8562        #[derive(Clone, Debug, PartialEq, Eq)]
8563        pub type Tag;
8564
8565        /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8566        ///
8567        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8568        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8569        pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
8570    }
8571
8572    // WebAssembly.Exception
8573    #[wasm_bindgen]
8574    extern "C" {
8575        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8576        ///
8577        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8578        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
8579        #[derive(Clone, Debug, PartialEq, Eq)]
8580        pub type Exception;
8581
8582        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8583        ///
8584        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8585        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8586        pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
8587
8588        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8589        ///
8590        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8591        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8592        pub fn new_with_options(
8593            tag: &Tag,
8594            payload: &Array,
8595            options: &Object,
8596        ) -> Result<Exception, JsValue>;
8597
8598        /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
8599        /// test if the Exception matches a given tag.
8600        ///
8601        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
8602        #[wasm_bindgen(method, js_namespace = WebAssembly)]
8603        pub fn is(this: &Exception, tag: &Tag) -> bool;
8604
8605        /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
8606        /// to get the value of a specified item in the exception's data arguments
8607        ///
8608        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
8609        #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
8610        pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
8611    }
8612
8613    // WebAssembly.Global
8614    #[wasm_bindgen]
8615    extern "C" {
8616        /// The `WebAssembly.Global()` constructor creates a new `Global` object
8617        /// of the given type and value.
8618        ///
8619        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8620        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
8621        #[derive(Clone, Debug, PartialEq, Eq)]
8622        pub type Global;
8623
8624        /// The `WebAssembly.Global()` constructor creates a new `Global` object
8625        /// of the given type and value.
8626        ///
8627        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8628        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8629        pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
8630
8631        /// The value prototype property of the `WebAssembly.Global` object
8632        /// returns the value of the global.
8633        ///
8634        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8635        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8636        pub fn value(this: &Global) -> JsValue;
8637        #[wasm_bindgen(method, setter = value, js_namespace = WebAssembly)]
8638        pub fn set_value(this: &Global, value: &JsValue);
8639    }
8640
8641    // WebAssembly.Memory
8642    #[wasm_bindgen]
8643    extern "C" {
8644        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
8645        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
8646        #[derive(Clone, Debug, PartialEq, Eq)]
8647        pub type Memory;
8648
8649        /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
8650        /// which is a resizable `ArrayBuffer` that holds the raw bytes of
8651        /// memory accessed by a WebAssembly `Instance`.
8652        ///
8653        /// A memory created by JavaScript or in WebAssembly code will be
8654        /// accessible and mutable from both JavaScript and WebAssembly.
8655        ///
8656        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
8657        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8658        pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
8659
8660        /// An accessor property that returns the buffer contained in the
8661        /// memory.
8662        ///
8663        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
8664        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8665        pub fn buffer(this: &Memory) -> JsValue;
8666
8667        /// The `grow()` prototype method of the `Memory` object increases the
8668        /// size of the memory instance by a specified number of WebAssembly
8669        /// pages.
8670        ///
8671        /// Takes the number of pages to grow (64KiB in size) and returns the
8672        /// previous size of memory, in pages.
8673        ///
8674        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
8675        #[wasm_bindgen(method, js_namespace = WebAssembly)]
8676        pub fn grow(this: &Memory, pages: u32) -> u32;
8677    }
8678}
8679
8680/// The `JSON` object contains methods for parsing [JavaScript Object
8681/// Notation (JSON)](https://json.org/) and converting values to JSON. It
8682/// can't be called or constructed, and aside from its two method
8683/// properties, it has no interesting functionality of its own.
8684#[allow(non_snake_case)]
8685pub mod JSON {
8686    use super::*;
8687
8688    // JSON
8689    #[wasm_bindgen]
8690    extern "C" {
8691        /// The `JSON.parse()` method parses a JSON string, constructing the
8692        /// JavaScript value or object described by the string.
8693        ///
8694        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
8695        #[wasm_bindgen(catch, js_namespace = JSON)]
8696        pub fn parse(text: &str) -> Result<JsValue, JsValue>;
8697
8698        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8699        ///
8700        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8701        #[wasm_bindgen(catch, js_namespace = JSON)]
8702        pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
8703
8704        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8705        ///
8706        /// The `replacer` argument is a function that alters the behavior of the stringification
8707        /// process, or an array of String and Number objects that serve as a whitelist
8708        /// for selecting/filtering the properties of the value object to be included
8709        /// in the JSON string. If this value is null or not provided, all properties
8710        /// of the object are included in the resulting JSON string.
8711        ///
8712        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8713        #[cfg(not(js_sys_unstable_apis))]
8714        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8715        pub fn stringify_with_replacer(
8716            obj: &JsValue,
8717            replacer: &JsValue,
8718        ) -> Result<JsString, JsValue>;
8719
8720        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8721        ///
8722        /// The `replacer` argument is a function that alters the behavior of the stringification
8723        /// process, or an array of String and Number objects that serve as a whitelist
8724        /// for selecting/filtering the properties of the value object to be included
8725        /// in the JSON string. If this value is null or not provided, all properties
8726        /// of the object are included in the resulting JSON string.
8727        ///
8728        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8729        #[cfg(js_sys_unstable_apis)]
8730        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8731        pub fn stringify_with_replacer<'a>(
8732            obj: &JsValue,
8733            replacer: &ImmediateClosure<
8734                'a,
8735                dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError> + 'a,
8736            >,
8737            space: Option<u32>,
8738        ) -> Result<JsString, JsValue>;
8739
8740        // Next major: deprecate
8741        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8742        ///
8743        /// The `replacer` argument is a function that alters the behavior of the stringification
8744        /// process, or an array of String and Number objects that serve as a whitelist
8745        /// for selecting/filtering the properties of the value object to be included
8746        /// in the JSON string. If this value is null or not provided, all properties
8747        /// of the object are included in the resulting JSON string.
8748        ///
8749        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8750        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8751        pub fn stringify_with_replacer_func<'a>(
8752            obj: &JsValue,
8753            replacer: &ImmediateClosure<
8754                'a,
8755                dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError> + 'a,
8756            >,
8757            space: Option<u32>,
8758        ) -> Result<JsString, JsValue>;
8759
8760        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8761        ///
8762        /// The `replacer` argument is a function that alters the behavior of the stringification
8763        /// process, or an array of String and Number objects that serve as a whitelist
8764        /// for selecting/filtering the properties of the value object to be included
8765        /// in the JSON string. If this value is null or not provided, all properties
8766        /// of the object are included in the resulting JSON string.
8767        ///
8768        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8769        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8770        pub fn stringify_with_replacer_list(
8771            obj: &JsValue,
8772            replacer: Vec<String>,
8773            space: Option<u32>,
8774        ) -> Result<JsString, JsValue>;
8775
8776        // Next major: deprecate
8777        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8778        ///
8779        /// The `replacer` argument is a function that alters the behavior of the stringification
8780        /// process, or an array of String and Number objects that serve as a whitelist
8781        /// for selecting/filtering the properties of the value object to be included
8782        /// in the JSON string. If this value is null or not provided, all properties
8783        /// of the object are included in the resulting JSON string.
8784        ///
8785        /// The `space` argument is a String or Number object that's used to insert white space into
8786        /// the output JSON string for readability purposes. If this is a Number, it
8787        /// indicates the number of space characters to use as white space; this number
8788        /// is capped at 10 (if it is greater, the value is just 10). Values less than
8789        /// 1 indicate that no space should be used. If this is a String, the string
8790        /// (or the first 10 characters of the string, if it's longer than that) is
8791        /// used as white space. If this parameter is not provided (or is null), no
8792        /// white space is used.
8793        ///
8794        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8795        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8796        pub fn stringify_with_replacer_and_space(
8797            obj: &JsValue,
8798            replacer: &JsValue,
8799            space: &JsValue,
8800        ) -> Result<JsString, JsValue>;
8801    }
8802}
8803// JsString
8804#[wasm_bindgen]
8805extern "C" {
8806    #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
8807    #[derive(Clone, PartialEq, Eq)]
8808    pub type JsString;
8809
8810    /// The length property of a String object indicates the length of a string,
8811    /// in UTF-16 code units.
8812    ///
8813    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
8814    #[wasm_bindgen(method, getter)]
8815    pub fn length(this: &JsString) -> u32;
8816
8817    /// The 'at()' method returns a new string consisting of the single UTF-16
8818    /// code unit located at the specified offset into the string, counting from
8819    /// the end if it's negative.
8820    ///
8821    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
8822    #[wasm_bindgen(method, js_class = "String")]
8823    pub fn at(this: &JsString, index: i32) -> Option<JsString>;
8824
8825    /// The String object's `charAt()` method returns a new string consisting of
8826    /// the single UTF-16 code unit located at the specified offset into the
8827    /// string.
8828    ///
8829    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
8830    #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
8831    pub fn char_at(this: &JsString, index: u32) -> JsString;
8832
8833    /// The `charCodeAt()` method returns an integer between 0 and 65535
8834    /// representing the UTF-16 code unit at the given index (the UTF-16 code
8835    /// unit matches the Unicode code point for code points representable in a
8836    /// single UTF-16 code unit, but might also be the first code unit of a
8837    /// surrogate pair for code points not representable in a single UTF-16 code
8838    /// unit, e.g. Unicode code points > 0x10000).  If you want the entire code
8839    /// point value, use `codePointAt()`.
8840    ///
8841    /// Returns `NaN` if index is out of range.
8842    ///
8843    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
8844    #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
8845    pub fn char_code_at(this: &JsString, index: u32) -> f64;
8846
8847    /// The `codePointAt()` method returns a non-negative integer that is the
8848    /// Unicode code point value.
8849    ///
8850    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8851    #[cfg(not(js_sys_unstable_apis))]
8852    #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8853    pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
8854
8855    /// The `codePointAt()` method returns a non-negative integer that is the
8856    /// Unicode code point value.
8857    ///
8858    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8859    #[cfg(js_sys_unstable_apis)]
8860    #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8861    pub fn code_point_at(this: &JsString, pos: u32) -> Option<u32>;
8862
8863    // Next major: deprecate
8864    /// The `codePointAt()` method returns a non-negative integer that is the
8865    /// Unicode code point value.
8866    ///
8867    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8868    #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8869    pub fn try_code_point_at(this: &JsString, pos: u32) -> Option<u16>;
8870
8871    /// The `concat()` method concatenates the string arguments to the calling
8872    /// string and returns a new string.
8873    ///
8874    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8875    #[cfg(not(js_sys_unstable_apis))]
8876    #[wasm_bindgen(method, js_class = "String")]
8877    pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
8878
8879    /// The `concat()` method concatenates the string arguments to the calling
8880    /// string and returns a new string.
8881    ///
8882    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8883    #[cfg(js_sys_unstable_apis)]
8884    #[wasm_bindgen(method, js_class = "String")]
8885    pub fn concat(this: &JsString, string: &JsString) -> JsString;
8886
8887    /// The `concat()` method concatenates the string arguments to the calling
8888    /// string and returns a new string.
8889    ///
8890    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8891    #[wasm_bindgen(method, js_class = "String")]
8892    pub fn concat_many(this: &JsString, strings: &[JsString]) -> JsString;
8893
8894    /// The `endsWith()` method determines whether a string ends with the characters of a
8895    /// specified string, returning true or false as appropriate.
8896    ///
8897    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
8898    #[cfg(not(js_sys_unstable_apis))]
8899    #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
8900    pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
8901
8902    /// The `endsWith()` method determines whether a string ends with the characters of a
8903    /// specified string, returning true or false as appropriate.
8904    ///
8905    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
8906    #[cfg(js_sys_unstable_apis)]
8907    #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
8908    pub fn ends_with(this: &JsString, search_string: &str) -> bool;
8909
8910    /// The static `String.fromCharCode()` method returns a string created from
8911    /// the specified sequence of UTF-16 code units.
8912    ///
8913    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8914    ///
8915    /// # Notes
8916    ///
8917    /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
8918    /// with different arities.
8919    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
8920    pub fn from_char_code(char_codes: &[u16]) -> JsString;
8921
8922    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8923    #[cfg(not(js_sys_unstable_apis))]
8924    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8925    pub fn from_char_code1(a: u32) -> JsString;
8926
8927    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8928    #[cfg(js_sys_unstable_apis)]
8929    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8930    pub fn from_char_code1(a: u16) -> JsString;
8931
8932    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8933    #[cfg(not(js_sys_unstable_apis))]
8934    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8935    pub fn from_char_code2(a: u32, b: u32) -> JsString;
8936
8937    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8938    #[cfg(js_sys_unstable_apis)]
8939    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8940    pub fn from_char_code2(a: u16, b: u16) -> JsString;
8941
8942    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8943    #[cfg(not(js_sys_unstable_apis))]
8944    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8945    pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
8946
8947    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8948    #[cfg(js_sys_unstable_apis)]
8949    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8950    pub fn from_char_code3(a: u16, b: u16, c: u16) -> JsString;
8951
8952    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8953    #[cfg(not(js_sys_unstable_apis))]
8954    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8955    pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
8956
8957    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8958    #[cfg(js_sys_unstable_apis)]
8959    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8960    pub fn from_char_code4(a: u16, b: u16, c: u16, d: u16) -> JsString;
8961
8962    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8963    #[cfg(not(js_sys_unstable_apis))]
8964    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8965    pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
8966
8967    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8968    #[cfg(js_sys_unstable_apis)]
8969    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8970    pub fn from_char_code5(a: u16, b: u16, c: u16, d: u16, e: u16) -> JsString;
8971
8972    /// The static `String.fromCodePoint()` method returns a string created by
8973    /// using the specified sequence of code points.
8974    ///
8975    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8976    ///
8977    /// # Exceptions
8978    ///
8979    /// A RangeError is thrown if an invalid Unicode code point is given
8980    ///
8981    /// # Notes
8982    ///
8983    /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
8984    /// with different arities.
8985    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
8986    pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
8987
8988    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8989    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8990    pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
8991
8992    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8993    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8994    pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
8995
8996    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8997    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8998    pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
8999
9000    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9001    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9002    pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
9003
9004    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9005    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9006    pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
9007
9008    /// The `includes()` method determines whether one string may be found
9009    /// within another string, returning true or false as appropriate.
9010    ///
9011    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
9012    #[wasm_bindgen(method, js_class = "String")]
9013    pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
9014
9015    /// The `indexOf()` method returns the index within the calling String
9016    /// object of the first occurrence of the specified value, starting the
9017    /// search at fromIndex.  Returns -1 if the value is not found.
9018    ///
9019    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
9020    #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
9021    pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9022
9023    /// The `lastIndexOf()` method returns the index within the calling String
9024    /// object of the last occurrence of the specified value, searching
9025    /// backwards from fromIndex.  Returns -1 if the value is not found.
9026    ///
9027    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
9028    #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
9029    pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9030
9031    /// The `localeCompare()` method returns a number indicating whether
9032    /// a reference string comes before or after or is the same as
9033    /// the given string in sort order.
9034    ///
9035    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9036    #[cfg(not(js_sys_unstable_apis))]
9037    #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9038    pub fn locale_compare(
9039        this: &JsString,
9040        compare_string: &str,
9041        locales: &Array,
9042        options: &Object,
9043    ) -> i32;
9044
9045    /// The `localeCompare()` method returns a number indicating whether
9046    /// a reference string comes before or after or is the same as
9047    /// the given string in sort order.
9048    ///
9049    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9050    #[cfg(js_sys_unstable_apis)]
9051    #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9052    pub fn locale_compare(
9053        this: &JsString,
9054        compare_string: &str,
9055        locales: &[JsString],
9056        options: &Intl::CollatorOptions,
9057    ) -> i32;
9058
9059    /// The `match()` method retrieves the matches when matching a string against a regular expression.
9060    ///
9061    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
9062    #[wasm_bindgen(method, js_class = "String", js_name = match)]
9063    pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
9064
9065    /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9066    ///
9067    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9068    #[cfg(not(js_sys_unstable_apis))]
9069    #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9070    pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
9071
9072    /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9073    ///
9074    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9075    #[cfg(js_sys_unstable_apis)]
9076    #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9077    pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator<RegExpMatchArray>;
9078
9079    /// The `normalize()` method returns the Unicode Normalization Form
9080    /// of a given string (if the value isn't a string, it will be converted to one first).
9081    ///
9082    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
9083    #[wasm_bindgen(method, js_class = "String")]
9084    pub fn normalize(this: &JsString, form: &str) -> JsString;
9085
9086    /// The `padEnd()` method pads the current string with a given string
9087    /// (repeated, if needed) so that the resulting string reaches a given
9088    /// length. The padding is applied from the end (right) of the current
9089    /// string.
9090    ///
9091    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
9092    #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
9093    pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9094
9095    /// The `padStart()` method pads the current string with another string
9096    /// (repeated, if needed) so that the resulting string reaches the given
9097    /// length. The padding is applied from the start (left) of the current
9098    /// string.
9099    ///
9100    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
9101    #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
9102    pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9103
9104    /// The `repeat()` method constructs and returns a new string which contains the specified
9105    /// number of copies of the string on which it was called, concatenated together.
9106    ///
9107    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
9108    #[wasm_bindgen(method, js_class = "String")]
9109    pub fn repeat(this: &JsString, count: i32) -> JsString;
9110
9111    /// The `replace()` method returns a new string with some or all matches of a pattern
9112    /// replaced by a replacement. The pattern can be a string or a RegExp, and
9113    /// the replacement can be a string or a function to be called for each match.
9114    ///
9115    /// Note: The original string will remain unchanged.
9116    ///
9117    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9118    #[wasm_bindgen(method, js_class = "String")]
9119    pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9120
9121    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9122    #[cfg(not(js_sys_unstable_apis))]
9123    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9124    pub fn replace_with_function(
9125        this: &JsString,
9126        pattern: &str,
9127        replacement: &Function,
9128    ) -> JsString;
9129
9130    /// The replacer function signature is `(match, offset, string) -> replacement`
9131    /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9132    /// when capture groups are present.
9133    ///
9134    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9135    #[cfg(js_sys_unstable_apis)]
9136    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9137    pub fn replace_with_function(
9138        this: &JsString,
9139        pattern: &str,
9140        replacement: &Function<fn(JsString) -> JsString>,
9141    ) -> JsString;
9142
9143    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9144    pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
9145
9146    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9147    #[cfg(not(js_sys_unstable_apis))]
9148    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9149    pub fn replace_by_pattern_with_function(
9150        this: &JsString,
9151        pattern: &RegExp,
9152        replacement: &Function,
9153    ) -> JsString;
9154
9155    /// The replacer function signature is `(match, offset, string) -> replacement`
9156    /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9157    /// when capture groups are present.
9158    ///
9159    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9160    #[cfg(js_sys_unstable_apis)]
9161    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9162    pub fn replace_by_pattern_with_function(
9163        this: &JsString,
9164        pattern: &RegExp,
9165        replacement: &Function<fn(JsString) -> JsString>,
9166    ) -> JsString;
9167
9168    /// The `replace_all()` method returns a new string with all matches of a pattern
9169    /// replaced by a replacement. The pattern can be a string or a global RegExp, and
9170    /// the replacement can be a string or a function to be called for each match.
9171    ///
9172    /// Note: The original string will remain unchanged.
9173    ///
9174    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9175    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9176    pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9177
9178    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9179    #[cfg(not(js_sys_unstable_apis))]
9180    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9181    pub fn replace_all_with_function(
9182        this: &JsString,
9183        pattern: &str,
9184        replacement: &Function,
9185    ) -> JsString;
9186
9187    /// The replacer function signature is `(match, offset, string) -> replacement`
9188    /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9189    /// when capture groups are present.
9190    ///
9191    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9192    #[cfg(js_sys_unstable_apis)]
9193    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9194    pub fn replace_all_with_function(
9195        this: &JsString,
9196        pattern: &str,
9197        replacement: &Function<fn(JsString) -> JsString>,
9198    ) -> JsString;
9199
9200    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9201    pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
9202        -> JsString;
9203
9204    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9205    #[cfg(not(js_sys_unstable_apis))]
9206    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9207    pub fn replace_all_by_pattern_with_function(
9208        this: &JsString,
9209        pattern: &RegExp,
9210        replacement: &Function,
9211    ) -> JsString;
9212
9213    /// The replacer function signature is `(match, offset, string) -> replacement`
9214    /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9215    /// when capture groups are present.
9216    ///
9217    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9218    #[cfg(js_sys_unstable_apis)]
9219    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9220    pub fn replace_all_by_pattern_with_function(
9221        this: &JsString,
9222        pattern: &RegExp,
9223        replacement: &Function<fn(JsString) -> JsString>,
9224    ) -> JsString;
9225
9226    /// The `search()` method executes a search for a match between
9227    /// a regular expression and this String object.
9228    ///
9229    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
9230    #[wasm_bindgen(method, js_class = "String")]
9231    pub fn search(this: &JsString, pattern: &RegExp) -> i32;
9232
9233    /// The `slice()` method extracts a section of a string and returns it as a
9234    /// new string, without modifying the original string.
9235    ///
9236    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
9237    #[wasm_bindgen(method, js_class = "String")]
9238    pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
9239
9240    /// The `split()` method splits a String object into an array of strings by separating the string
9241    /// into substrings, using a specified separator string to determine where to make each split.
9242    ///
9243    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9244    #[wasm_bindgen(method, js_class = "String")]
9245    pub fn split(this: &JsString, separator: &str) -> Array;
9246
9247    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9248    #[wasm_bindgen(method, js_class = "String", js_name = split)]
9249    pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
9250
9251    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9252    #[wasm_bindgen(method, js_class = "String", js_name = split)]
9253    pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
9254
9255    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9256    #[wasm_bindgen(method, js_class = "String", js_name = split)]
9257    pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
9258
9259    /// The `startsWith()` method determines whether a string begins with the
9260    /// characters of a specified string, returning true or false as
9261    /// appropriate.
9262    ///
9263    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
9264    #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
9265    pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
9266
9267    /// The `substring()` method returns the part of the string between the
9268    /// start and end indexes, or to the end of the string.
9269    ///
9270    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
9271    #[wasm_bindgen(method, js_class = "String")]
9272    pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
9273
9274    /// The `substr()` method returns the part of a string between
9275    /// the start index and a number of characters after it.
9276    ///
9277    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
9278    #[wasm_bindgen(method, js_class = "String")]
9279    pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
9280
9281    /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
9282    /// according to any locale-specific case mappings.
9283    ///
9284    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
9285    #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
9286    pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
9287
9288    /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
9289    /// according to any locale-specific case mappings.
9290    ///
9291    /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
9292    #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
9293    pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
9294
9295    /// The `toLowerCase()` method returns the calling string value
9296    /// converted to lower case.
9297    ///
9298    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
9299    #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
9300    pub fn to_lower_case(this: &JsString) -> JsString;
9301
9302    /// The `toString()` method returns a string representing the specified
9303    /// object.
9304    ///
9305    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
9306    #[cfg(not(js_sys_unstable_apis))]
9307    #[wasm_bindgen(method, js_class = "String", js_name = toString)]
9308    pub fn to_string(this: &JsString) -> JsString;
9309
9310    /// The `toUpperCase()` method returns the calling string value converted to
9311    /// uppercase (the value will be converted to a string if it isn't one).
9312    ///
9313    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
9314    #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
9315    pub fn to_upper_case(this: &JsString) -> JsString;
9316
9317    /// The `trim()` method removes whitespace from both ends of a string.
9318    /// Whitespace in this context is all the whitespace characters (space, tab,
9319    /// no-break space, etc.) and all the line terminator characters (LF, CR,
9320    /// etc.).
9321    ///
9322    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
9323    #[wasm_bindgen(method, js_class = "String")]
9324    pub fn trim(this: &JsString) -> JsString;
9325
9326    /// The `trimEnd()` method removes whitespace from the end of a string.
9327    /// `trimRight()` is an alias of this method.
9328    ///
9329    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9330    #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
9331    pub fn trim_end(this: &JsString) -> JsString;
9332
9333    /// The `trimEnd()` method removes whitespace from the end of a string.
9334    /// `trimRight()` is an alias of this method.
9335    ///
9336    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9337    #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
9338    pub fn trim_right(this: &JsString) -> JsString;
9339
9340    /// The `trimStart()` method removes whitespace from the beginning of a
9341    /// string. `trimLeft()` is an alias of this method.
9342    ///
9343    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9344    #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
9345    pub fn trim_start(this: &JsString) -> JsString;
9346
9347    /// The `trimStart()` method removes whitespace from the beginning of a
9348    /// string. `trimLeft()` is an alias of this method.
9349    ///
9350    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9351    #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
9352    pub fn trim_left(this: &JsString) -> JsString;
9353
9354    /// The `valueOf()` method returns the primitive value of a `String` object.
9355    ///
9356    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
9357    #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
9358    pub fn value_of(this: &JsString) -> JsString;
9359
9360    /// The static `raw()` method is a tag function of template literals,
9361    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9362    ///
9363    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9364    #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
9365    pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
9366
9367    /// The static `raw()` method is a tag function of template literals,
9368    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9369    ///
9370    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9371    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9372    pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
9373
9374    /// The static `raw()` method is a tag function of template literals,
9375    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9376    ///
9377    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9378    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9379    pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
9380
9381    /// The static `raw()` method is a tag function of template literals,
9382    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9383    ///
9384    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9385    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9386    pub fn raw_2(
9387        call_site: &Object,
9388        substitutions1: &str,
9389        substitutions2: &str,
9390    ) -> Result<JsString, JsValue>;
9391
9392    /// The static `raw()` method is a tag function of template literals,
9393    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9394    ///
9395    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9396    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9397    pub fn raw_3(
9398        call_site: &Object,
9399        substitutions1: &str,
9400        substitutions2: &str,
9401        substitutions3: &str,
9402    ) -> Result<JsString, JsValue>;
9403
9404    /// The static `raw()` method is a tag function of template literals,
9405    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9406    ///
9407    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9408    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9409    pub fn raw_4(
9410        call_site: &Object,
9411        substitutions1: &str,
9412        substitutions2: &str,
9413        substitutions3: &str,
9414        substitutions4: &str,
9415    ) -> Result<JsString, JsValue>;
9416
9417    /// The static `raw()` method is a tag function of template literals,
9418    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9419    ///
9420    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9421    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9422    pub fn raw_5(
9423        call_site: &Object,
9424        substitutions1: &str,
9425        substitutions2: &str,
9426        substitutions3: &str,
9427        substitutions4: &str,
9428        substitutions5: &str,
9429    ) -> Result<JsString, JsValue>;
9430
9431    /// The static `raw()` method is a tag function of template literals,
9432    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9433    ///
9434    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9435    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9436    pub fn raw_6(
9437        call_site: &Object,
9438        substitutions1: &str,
9439        substitutions2: &str,
9440        substitutions3: &str,
9441        substitutions4: &str,
9442        substitutions5: &str,
9443        substitutions6: &str,
9444    ) -> Result<JsString, JsValue>;
9445
9446    /// The static `raw()` method is a tag function of template literals,
9447    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9448    ///
9449    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9450    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9451    pub fn raw_7(
9452        call_site: &Object,
9453        substitutions1: &str,
9454        substitutions2: &str,
9455        substitutions3: &str,
9456        substitutions4: &str,
9457        substitutions5: &str,
9458        substitutions6: &str,
9459        substitutions7: &str,
9460    ) -> Result<JsString, JsValue>;
9461}
9462
9463// These upcasts are non-castable due to the constraints on the function
9464// but the UpcastFrom covariance must still extend through closure types.
9465// (impl UpcastFrom really just means CovariantGeneric relation)
9466impl UpcastFrom<String> for JsString {}
9467impl UpcastFrom<JsString> for String {}
9468
9469impl UpcastFrom<&str> for JsString {}
9470impl UpcastFrom<JsString> for &str {}
9471
9472impl UpcastFrom<char> for JsString {}
9473impl UpcastFrom<JsString> for char {}
9474
9475impl JsString {
9476    /// Returns the `JsString` value of this JS value if it's an instance of a
9477    /// string.
9478    ///
9479    /// If this JS value is not an instance of a string then this returns
9480    /// `None`.
9481    #[cfg(not(js_sys_unstable_apis))]
9482    #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
9483    pub fn try_from(val: &JsValue) -> Option<&JsString> {
9484        val.dyn_ref()
9485    }
9486
9487    /// Returns whether this string is a valid UTF-16 string.
9488    ///
9489    /// This is useful for learning whether `String::from(..)` will return a
9490    /// lossless representation of the JS string. If this string contains
9491    /// unpaired surrogates then `String::from` will succeed but it will be a
9492    /// lossy representation of the JS string because unpaired surrogates will
9493    /// become replacement characters.
9494    ///
9495    /// If this function returns `false` then to get a lossless representation
9496    /// of the string you'll need to manually use the `iter` method (or the
9497    /// `char_code_at` accessor) to view the raw character codes.
9498    ///
9499    /// For more information, see the documentation on [JS strings vs Rust
9500    /// strings][docs]
9501    ///
9502    /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
9503    pub fn is_valid_utf16(&self) -> bool {
9504        core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
9505    }
9506
9507    /// Returns an iterator over the `u16` character codes that make up this JS
9508    /// string.
9509    ///
9510    /// This method will call `char_code_at` for each code in this JS string,
9511    /// returning an iterator of the codes in sequence.
9512    pub fn iter(
9513        &self,
9514    ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
9515        (0..self.length()).map(move |i| self.char_code_at(i) as u16)
9516    }
9517
9518    /// If this string consists of a single Unicode code point, then this method
9519    /// converts it into a Rust `char` without doing any allocations.
9520    ///
9521    /// If this JS value is not a valid UTF-8 or consists of more than a single
9522    /// codepoint, then this returns `None`.
9523    ///
9524    /// Note that a single Unicode code point might be represented as more than
9525    /// one code unit on the JavaScript side. For example, a JavaScript string
9526    /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
9527    /// corresponds to a character '𐐷'.
9528    pub fn as_char(&self) -> Option<char> {
9529        let len = self.length();
9530
9531        if len == 0 || len > 2 {
9532            return None;
9533        }
9534
9535        #[cfg(not(js_sys_unstable_apis))]
9536        let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
9537        #[cfg(js_sys_unstable_apis)]
9538        let cp = self.code_point_at(0)?;
9539
9540        let c = core::char::from_u32(cp)?;
9541
9542        if c.len_utf16() as u32 == len {
9543            Some(c)
9544        } else {
9545            None
9546        }
9547    }
9548}
9549
9550impl PartialEq<str> for JsString {
9551    #[allow(clippy::cmp_owned)] // prevent infinite recursion
9552    fn eq(&self, other: &str) -> bool {
9553        String::from(self) == other
9554    }
9555}
9556
9557impl<'a> PartialEq<&'a str> for JsString {
9558    fn eq(&self, other: &&'a str) -> bool {
9559        <JsString as PartialEq<str>>::eq(self, other)
9560    }
9561}
9562
9563impl PartialEq<String> for JsString {
9564    fn eq(&self, other: &String) -> bool {
9565        <JsString as PartialEq<str>>::eq(self, other)
9566    }
9567}
9568
9569impl<'a> PartialEq<&'a String> for JsString {
9570    fn eq(&self, other: &&'a String) -> bool {
9571        <JsString as PartialEq<str>>::eq(self, other)
9572    }
9573}
9574
9575impl Default for JsString {
9576    fn default() -> Self {
9577        Self::from("")
9578    }
9579}
9580
9581impl<'a> From<&'a str> for JsString {
9582    fn from(s: &'a str) -> Self {
9583        JsString::unchecked_from_js(JsValue::from_str(s))
9584    }
9585}
9586
9587impl From<String> for JsString {
9588    fn from(s: String) -> Self {
9589        From::from(&*s)
9590    }
9591}
9592
9593impl From<char> for JsString {
9594    #[inline]
9595    fn from(c: char) -> Self {
9596        JsString::from_code_point1(c as u32).unwrap_throw()
9597    }
9598}
9599
9600impl<'a> From<&'a JsString> for String {
9601    fn from(s: &'a JsString) -> Self {
9602        s.obj.as_string().unwrap_throw()
9603    }
9604}
9605
9606impl From<JsString> for String {
9607    fn from(s: JsString) -> Self {
9608        From::from(&s)
9609    }
9610}
9611
9612impl fmt::Debug for JsString {
9613    #[inline]
9614    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9615        fmt::Debug::fmt(&String::from(self), f)
9616    }
9617}
9618
9619impl fmt::Display for JsString {
9620    #[inline]
9621    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9622        fmt::Display::fmt(&String::from(self), f)
9623    }
9624}
9625
9626impl str::FromStr for JsString {
9627    type Err = convert::Infallible;
9628    fn from_str(s: &str) -> Result<Self, Self::Err> {
9629        Ok(JsString::from(s))
9630    }
9631}
9632
9633// Symbol
9634#[wasm_bindgen]
9635extern "C" {
9636    #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
9637    #[derive(Clone, Debug)]
9638    pub type Symbol;
9639
9640    /// The `Symbol.hasInstance` well-known symbol is used to determine
9641    /// if a constructor object recognizes an object as its instance.
9642    /// The `instanceof` operator's behavior can be customized by this symbol.
9643    ///
9644    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
9645    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = hasInstance)]
9646    pub fn has_instance() -> Symbol;
9647
9648    /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
9649    /// if an object should be flattened to its array elements when using the
9650    /// `Array.prototype.concat()` method.
9651    ///
9652    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
9653    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = isConcatSpreadable)]
9654    pub fn is_concat_spreadable() -> Symbol;
9655
9656    /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
9657    /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
9658    ///
9659    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
9660    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncIterator)]
9661    pub fn async_iterator() -> Symbol;
9662
9663    /// The `Symbol.iterator` well-known symbol specifies the default iterator
9664    /// for an object.  Used by `for...of`.
9665    ///
9666    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
9667    #[wasm_bindgen(static_method_of = Symbol, getter)]
9668    pub fn iterator() -> Symbol;
9669
9670    /// The `Symbol.match` well-known symbol specifies the matching of a regular
9671    /// expression against a string. This function is called by the
9672    /// `String.prototype.match()` method.
9673    ///
9674    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
9675    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = match)]
9676    pub fn match_() -> Symbol;
9677
9678    /// The `Symbol.replace` well-known symbol specifies the method that
9679    /// replaces matched substrings of a string.  This function is called by the
9680    /// `String.prototype.replace()` method.
9681    ///
9682    /// For more information, see `RegExp.prototype[@@replace]()` and
9683    /// `String.prototype.replace()`.
9684    ///
9685    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
9686    #[wasm_bindgen(static_method_of = Symbol, getter)]
9687    pub fn replace() -> Symbol;
9688
9689    /// The `Symbol.search` well-known symbol specifies the method that returns
9690    /// the index within a string that matches the regular expression.  This
9691    /// function is called by the `String.prototype.search()` method.
9692    ///
9693    /// For more information, see `RegExp.prototype[@@search]()` and
9694    /// `String.prototype.search()`.
9695    ///
9696    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
9697    #[wasm_bindgen(static_method_of = Symbol, getter)]
9698    pub fn search() -> Symbol;
9699
9700    /// The well-known symbol `Symbol.species` specifies a function-valued
9701    /// property that the constructor function uses to create derived objects.
9702    ///
9703    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
9704    #[wasm_bindgen(static_method_of = Symbol, getter)]
9705    pub fn species() -> Symbol;
9706
9707    /// The `Symbol.split` well-known symbol specifies the method that splits a
9708    /// string at the indices that match a regular expression.  This function is
9709    /// called by the `String.prototype.split()` method.
9710    ///
9711    /// For more information, see `RegExp.prototype[@@split]()` and
9712    /// `String.prototype.split()`.
9713    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
9714    #[wasm_bindgen(static_method_of = Symbol, getter)]
9715    pub fn split() -> Symbol;
9716
9717    /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
9718    /// property that is called to convert an object to a corresponding
9719    /// primitive value.
9720    ///
9721    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
9722    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toPrimitive)]
9723    pub fn to_primitive() -> Symbol;
9724
9725    /// The `Symbol.toStringTag` well-known symbol is a string valued property
9726    /// that is used in the creation of the default string description of an
9727    /// object.  It is accessed internally by the `Object.prototype.toString()`
9728    /// method.
9729    ///
9730    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9731    #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toStringTag)]
9732    pub fn to_string_tag() -> Symbol;
9733
9734    /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
9735    /// the given key and returns it if found.
9736    /// Otherwise a new symbol gets created in the global symbol registry with this key.
9737    ///
9738    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
9739    #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
9740    pub fn for_(key: &str) -> Symbol;
9741
9742    /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
9743    ///
9744    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
9745    #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
9746    pub fn key_for(sym: &Symbol) -> JsValue;
9747
9748    // Next major: deprecate
9749    /// The `toString()` method returns a string representing the specified Symbol object.
9750    ///
9751    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9752    #[wasm_bindgen(method, js_name = toString)]
9753    pub fn to_string(this: &Symbol) -> JsString;
9754
9755    /// The `toString()` method returns a string representing the specified Symbol object.
9756    ///
9757    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9758    #[wasm_bindgen(method, js_name = toString)]
9759    pub fn to_js_string(this: &Symbol) -> JsString;
9760
9761    /// The `Symbol.unscopables` well-known symbol is used to specify an object
9762    /// value of whose own and inherited property names are excluded from the
9763    /// with environment bindings of the associated object.
9764    ///
9765    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
9766    #[wasm_bindgen(static_method_of = Symbol, getter)]
9767    pub fn unscopables() -> Symbol;
9768
9769    /// The `valueOf()` method returns the primitive value of a Symbol object.
9770    ///
9771    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
9772    #[wasm_bindgen(method, js_name = valueOf)]
9773    pub fn value_of(this: &Symbol) -> Symbol;
9774}
9775
9776#[allow(non_snake_case)]
9777pub mod Intl {
9778    use super::*;
9779
9780    // Intl
9781    #[wasm_bindgen]
9782    extern "C" {
9783        /// The `Intl.getCanonicalLocales()` method returns an array containing
9784        /// the canonical locale names. Duplicates will be omitted and elements
9785        /// will be validated as structurally valid language tags.
9786        ///
9787        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
9788        #[cfg(not(js_sys_unstable_apis))]
9789        #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
9790        pub fn get_canonical_locales(s: &JsValue) -> Array;
9791
9792        /// The `Intl.getCanonicalLocales()` method returns an array containing
9793        /// the canonical locale names. Duplicates will be omitted and elements
9794        /// will be validated as structurally valid language tags.
9795        ///
9796        /// Throws a `RangeError` if any of the strings are not valid locale identifiers.
9797        ///
9798        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
9799        #[cfg(js_sys_unstable_apis)]
9800        #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl, catch)]
9801        pub fn get_canonical_locales(s: &[JsString]) -> Result<Array<JsString>, JsValue>;
9802
9803        /// The `Intl.supportedValuesOf()` method returns an array containing the
9804        /// supported calendar, collation, currency, numbering system, or unit values
9805        /// supported by the implementation.
9806        ///
9807        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
9808        #[wasm_bindgen(js_name = supportedValuesOf, js_namespace = Intl)]
9809        pub fn supported_values_of(key: SupportedValuesKey) -> Array<JsString>;
9810    }
9811
9812    // Intl string enums
9813
9814    /// Key for `Intl.supportedValuesOf()`.
9815    #[wasm_bindgen]
9816    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9817    pub enum SupportedValuesKey {
9818        Calendar = "calendar",
9819        Collation = "collation",
9820        Currency = "currency",
9821        NumberingSystem = "numberingSystem",
9822        TimeZone = "timeZone",
9823        Unit = "unit",
9824    }
9825
9826    /// Locale matching algorithm for Intl constructors.
9827    #[wasm_bindgen]
9828    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9829    pub enum LocaleMatcher {
9830        Lookup = "lookup",
9831        BestFit = "best fit",
9832    }
9833
9834    /// Usage for `Intl.Collator`.
9835    #[wasm_bindgen]
9836    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9837    pub enum CollatorUsage {
9838        Sort = "sort",
9839        Search = "search",
9840    }
9841
9842    /// Sensitivity for `Intl.Collator`.
9843    #[wasm_bindgen]
9844    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9845    pub enum CollatorSensitivity {
9846        Base = "base",
9847        Accent = "accent",
9848        Case = "case",
9849        Variant = "variant",
9850    }
9851
9852    /// Case first option for `Intl.Collator`.
9853    #[wasm_bindgen]
9854    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9855    pub enum CollatorCaseFirst {
9856        Upper = "upper",
9857        Lower = "lower",
9858        False = "false",
9859    }
9860
9861    /// Style for `Intl.NumberFormat`.
9862    #[wasm_bindgen]
9863    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9864    pub enum NumberFormatStyle {
9865        Decimal = "decimal",
9866        Currency = "currency",
9867        Percent = "percent",
9868        Unit = "unit",
9869    }
9870
9871    /// Currency display for `Intl.NumberFormat`.
9872    #[wasm_bindgen]
9873    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9874    pub enum CurrencyDisplay {
9875        Code = "code",
9876        Symbol = "symbol",
9877        NarrowSymbol = "narrowSymbol",
9878        Name = "name",
9879    }
9880
9881    /// Currency sign for `Intl.NumberFormat`.
9882    #[wasm_bindgen]
9883    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9884    pub enum CurrencySign {
9885        Standard = "standard",
9886        Accounting = "accounting",
9887    }
9888
9889    /// Unit display for `Intl.NumberFormat`.
9890    #[wasm_bindgen]
9891    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9892    pub enum UnitDisplay {
9893        Short = "short",
9894        Narrow = "narrow",
9895        Long = "long",
9896    }
9897
9898    /// Notation for `Intl.NumberFormat`.
9899    #[wasm_bindgen]
9900    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9901    pub enum NumberFormatNotation {
9902        Standard = "standard",
9903        Scientific = "scientific",
9904        Engineering = "engineering",
9905        Compact = "compact",
9906    }
9907
9908    /// Compact display for `Intl.NumberFormat`.
9909    #[wasm_bindgen]
9910    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9911    pub enum CompactDisplay {
9912        Short = "short",
9913        Long = "long",
9914    }
9915
9916    /// Sign display for `Intl.NumberFormat`.
9917    #[wasm_bindgen]
9918    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9919    pub enum SignDisplay {
9920        Auto = "auto",
9921        Never = "never",
9922        Always = "always",
9923        ExceptZero = "exceptZero",
9924    }
9925
9926    /// Rounding mode for `Intl.NumberFormat`.
9927    #[wasm_bindgen]
9928    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9929    pub enum RoundingMode {
9930        Ceil = "ceil",
9931        Floor = "floor",
9932        Expand = "expand",
9933        Trunc = "trunc",
9934        HalfCeil = "halfCeil",
9935        HalfFloor = "halfFloor",
9936        HalfExpand = "halfExpand",
9937        HalfTrunc = "halfTrunc",
9938        HalfEven = "halfEven",
9939    }
9940
9941    /// Rounding priority for `Intl.NumberFormat`.
9942    #[wasm_bindgen]
9943    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9944    pub enum RoundingPriority {
9945        Auto = "auto",
9946        MorePrecision = "morePrecision",
9947        LessPrecision = "lessPrecision",
9948    }
9949
9950    /// Trailing zero display for `Intl.NumberFormat`.
9951    #[wasm_bindgen]
9952    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9953    pub enum TrailingZeroDisplay {
9954        Auto = "auto",
9955        StripIfInteger = "stripIfInteger",
9956    }
9957
9958    /// Use grouping option for `Intl.NumberFormat`.
9959    ///
9960    /// Determines whether to use grouping separators, such as thousands
9961    /// separators or thousand/lakh/crore separators.
9962    ///
9963    /// The default is `Min2` if notation is "compact", and `Auto` otherwise.
9964    ///
9965    /// Note: The string values `"true"` and `"false"` are accepted by JavaScript
9966    /// but are always converted to the default value. Use `True` and `False`
9967    /// variants for the boolean behavior.
9968    ///
9969    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#usegrouping)
9970    #[wasm_bindgen]
9971    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9972    pub enum UseGrouping {
9973        /// Display grouping separators even if the locale prefers otherwise.
9974        Always = "always",
9975        /// Display grouping separators based on the locale preference,
9976        /// which may also be dependent on the currency.
9977        Auto = "auto",
9978        /// Display grouping separators when there are at least 2 digits in a group.
9979        Min2 = "min2",
9980        /// Same as `Always`. Display grouping separators even if the locale prefers otherwise.
9981        True = "true",
9982        /// Display no grouping separators.
9983        False = "false",
9984    }
9985
9986    /// Date/time style for `Intl.DateTimeFormat`.
9987    #[wasm_bindgen]
9988    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9989    pub enum DateTimeStyle {
9990        Full = "full",
9991        Long = "long",
9992        Medium = "medium",
9993        Short = "short",
9994    }
9995
9996    /// Hour cycle for `Intl.DateTimeFormat`.
9997    #[wasm_bindgen]
9998    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9999    pub enum HourCycle {
10000        H11 = "h11",
10001        H12 = "h12",
10002        H23 = "h23",
10003        H24 = "h24",
10004    }
10005
10006    /// Weekday format for `Intl.DateTimeFormat`.
10007    #[wasm_bindgen]
10008    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10009    pub enum WeekdayFormat {
10010        Narrow = "narrow",
10011        Short = "short",
10012        Long = "long",
10013    }
10014
10015    /// Era format for `Intl.DateTimeFormat`.
10016    #[wasm_bindgen]
10017    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10018    pub enum EraFormat {
10019        Narrow = "narrow",
10020        Short = "short",
10021        Long = "long",
10022    }
10023
10024    /// Year format for `Intl.DateTimeFormat`.
10025    #[wasm_bindgen]
10026    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10027    pub enum YearFormat {
10028        Numeric = "numeric",
10029        TwoDigit = "2-digit",
10030    }
10031
10032    /// Month format for `Intl.DateTimeFormat`.
10033    #[wasm_bindgen]
10034    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10035    pub enum MonthFormat {
10036        #[wasm_bindgen]
10037        Numeric = "numeric",
10038        #[wasm_bindgen]
10039        TwoDigit = "2-digit",
10040        #[wasm_bindgen]
10041        Narrow = "narrow",
10042        #[wasm_bindgen]
10043        Short = "short",
10044        #[wasm_bindgen]
10045        Long = "long",
10046    }
10047
10048    /// Day format for `Intl.DateTimeFormat`.
10049    #[wasm_bindgen]
10050    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10051    pub enum DayFormat {
10052        #[wasm_bindgen]
10053        Numeric = "numeric",
10054        #[wasm_bindgen]
10055        TwoDigit = "2-digit",
10056    }
10057
10058    /// Hour/minute/second format for `Intl.DateTimeFormat`.
10059    #[wasm_bindgen]
10060    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10061    pub enum NumericFormat {
10062        #[wasm_bindgen]
10063        Numeric = "numeric",
10064        #[wasm_bindgen]
10065        TwoDigit = "2-digit",
10066    }
10067
10068    /// Time zone name format for `Intl.DateTimeFormat`.
10069    #[wasm_bindgen]
10070    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10071    pub enum TimeZoneNameFormat {
10072        Short = "short",
10073        Long = "long",
10074        ShortOffset = "shortOffset",
10075        LongOffset = "longOffset",
10076        ShortGeneric = "shortGeneric",
10077        LongGeneric = "longGeneric",
10078    }
10079
10080    /// Day period format for `Intl.DateTimeFormat`.
10081    #[wasm_bindgen]
10082    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10083    pub enum DayPeriodFormat {
10084        Narrow = "narrow",
10085        Short = "short",
10086        Long = "long",
10087    }
10088
10089    /// Part type for `DateTimeFormat.formatToParts()`.
10090    #[wasm_bindgen]
10091    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10092    pub enum DateTimeFormatPartType {
10093        Day = "day",
10094        DayPeriod = "dayPeriod",
10095        Era = "era",
10096        FractionalSecond = "fractionalSecond",
10097        Hour = "hour",
10098        Literal = "literal",
10099        Minute = "minute",
10100        Month = "month",
10101        RelatedYear = "relatedYear",
10102        Second = "second",
10103        TimeZoneName = "timeZoneName",
10104        Weekday = "weekday",
10105        Year = "year",
10106        YearName = "yearName",
10107    }
10108
10109    /// Part type for `NumberFormat.formatToParts()`.
10110    #[wasm_bindgen]
10111    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10112    pub enum NumberFormatPartType {
10113        Compact = "compact",
10114        Currency = "currency",
10115        Decimal = "decimal",
10116        ExponentInteger = "exponentInteger",
10117        ExponentMinusSign = "exponentMinusSign",
10118        ExponentSeparator = "exponentSeparator",
10119        Fraction = "fraction",
10120        Group = "group",
10121        Infinity = "infinity",
10122        Integer = "integer",
10123        Literal = "literal",
10124        MinusSign = "minusSign",
10125        Nan = "nan",
10126        PercentSign = "percentSign",
10127        PlusSign = "plusSign",
10128        Unit = "unit",
10129        Unknown = "unknown",
10130    }
10131
10132    /// Type for `Intl.PluralRules` (cardinal or ordinal).
10133    #[wasm_bindgen]
10134    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10135    pub enum PluralRulesType {
10136        Cardinal = "cardinal",
10137        Ordinal = "ordinal",
10138    }
10139
10140    /// Plural category returned by `PluralRules.select()`.
10141    #[wasm_bindgen]
10142    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10143    pub enum PluralCategory {
10144        Zero = "zero",
10145        One = "one",
10146        Two = "two",
10147        Few = "few",
10148        Many = "many",
10149        Other = "other",
10150    }
10151
10152    /// Numeric option for `Intl.RelativeTimeFormat`.
10153    #[wasm_bindgen]
10154    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10155    pub enum RelativeTimeFormatNumeric {
10156        Always = "always",
10157        Auto = "auto",
10158    }
10159
10160    /// Style for `Intl.RelativeTimeFormat`.
10161    #[wasm_bindgen]
10162    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10163    pub enum RelativeTimeFormatStyle {
10164        Long = "long",
10165        Short = "short",
10166        Narrow = "narrow",
10167    }
10168
10169    /// Unit for `RelativeTimeFormat.format()`.
10170    #[wasm_bindgen]
10171    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10172    pub enum RelativeTimeFormatUnit {
10173        Year = "year",
10174        Years = "years",
10175        Quarter = "quarter",
10176        Quarters = "quarters",
10177        Month = "month",
10178        Months = "months",
10179        Week = "week",
10180        Weeks = "weeks",
10181        Day = "day",
10182        Days = "days",
10183        Hour = "hour",
10184        Hours = "hours",
10185        Minute = "minute",
10186        Minutes = "minutes",
10187        Second = "second",
10188        Seconds = "seconds",
10189    }
10190
10191    /// Part type for `RelativeTimeFormat.formatToParts()`.
10192    #[wasm_bindgen]
10193    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10194    pub enum RelativeTimeFormatPartType {
10195        Literal = "literal",
10196        Integer = "integer",
10197        Decimal = "decimal",
10198        Fraction = "fraction",
10199    }
10200
10201    /// Source indicator for range format parts.
10202    ///
10203    /// Indicates which part of the range (start, end, or shared) a formatted
10204    /// part belongs to when using `formatRangeToParts()`.
10205    ///
10206    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts#description)
10207    #[wasm_bindgen]
10208    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10209    pub enum RangeSource {
10210        /// The part is from the start of the range.
10211        StartRange = "startRange",
10212        /// The part is from the end of the range.
10213        EndRange = "endRange",
10214        /// The part is shared between start and end (e.g., a separator or common element).
10215        Shared = "shared",
10216    }
10217
10218    /// Type for `Intl.ListFormat`.
10219    #[wasm_bindgen]
10220    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10221    pub enum ListFormatType {
10222        /// For lists of standalone items (default).
10223        Conjunction = "conjunction",
10224        /// For lists representing alternatives.
10225        Disjunction = "disjunction",
10226        /// For lists of values with units.
10227        Unit = "unit",
10228    }
10229
10230    /// Style for `Intl.ListFormat`.
10231    #[wasm_bindgen]
10232    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10233    pub enum ListFormatStyle {
10234        /// "A, B, and C" (default).
10235        Long = "long",
10236        /// "A, B, C".
10237        Short = "short",
10238        /// "A B C".
10239        Narrow = "narrow",
10240    }
10241
10242    /// Part type for `Intl.ListFormat.formatToParts()`.
10243    #[wasm_bindgen]
10244    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10245    pub enum ListFormatPartType {
10246        /// A value from the list.
10247        Element = "element",
10248        /// A linguistic construct (e.g., ", ", " and ").
10249        Literal = "literal",
10250    }
10251
10252    /// Type for `Intl.Segmenter`.
10253    #[wasm_bindgen]
10254    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10255    pub enum SegmenterGranularity {
10256        /// Segment by grapheme clusters (user-perceived characters).
10257        Grapheme = "grapheme",
10258        /// Segment by words.
10259        Word = "word",
10260        /// Segment by sentences.
10261        Sentence = "sentence",
10262    }
10263
10264    /// Type for `Intl.DisplayNames`.
10265    #[wasm_bindgen]
10266    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10267    pub enum DisplayNamesType {
10268        /// Language display names.
10269        Language = "language",
10270        /// Region display names.
10271        Region = "region",
10272        /// Script display names.
10273        Script = "script",
10274        /// Currency display names.
10275        Currency = "currency",
10276        /// Calendar display names.
10277        Calendar = "calendar",
10278        /// Date/time field display names.
10279        DateTimeField = "dateTimeField",
10280    }
10281
10282    /// Style for `Intl.DisplayNames`.
10283    #[wasm_bindgen]
10284    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10285    pub enum DisplayNamesStyle {
10286        /// Full display name (default).
10287        Long = "long",
10288        /// Abbreviated display name.
10289        Short = "short",
10290        /// Minimal display name.
10291        Narrow = "narrow",
10292    }
10293
10294    /// Fallback for `Intl.DisplayNames`.
10295    #[wasm_bindgen]
10296    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10297    pub enum DisplayNamesFallback {
10298        /// Return the input code if no display name is available (default).
10299        Code = "code",
10300        /// Return undefined if no display name is available.
10301        None = "none",
10302    }
10303
10304    /// Language display for `Intl.DisplayNames`.
10305    #[wasm_bindgen]
10306    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10307    pub enum DisplayNamesLanguageDisplay {
10308        /// Use dialect names (e.g., "British English").
10309        Dialect = "dialect",
10310        /// Use standard names (e.g., "English (United Kingdom)").
10311        Standard = "standard",
10312    }
10313
10314    // Intl.RelativeTimeFormatOptions
10315    #[wasm_bindgen]
10316    extern "C" {
10317        /// Options for `Intl.RelativeTimeFormat` constructor.
10318        ///
10319        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#options)
10320        #[wasm_bindgen(extends = Object)]
10321        #[derive(Clone, Debug)]
10322        pub type RelativeTimeFormatOptions;
10323
10324        #[wasm_bindgen(method, getter = localeMatcher)]
10325        pub fn get_locale_matcher(this: &RelativeTimeFormatOptions) -> Option<LocaleMatcher>;
10326        #[wasm_bindgen(method, setter = localeMatcher)]
10327        pub fn set_locale_matcher(this: &RelativeTimeFormatOptions, value: LocaleMatcher);
10328
10329        #[wasm_bindgen(method, getter = numeric)]
10330        pub fn get_numeric(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatNumeric>;
10331        #[wasm_bindgen(method, setter = numeric)]
10332        pub fn set_numeric(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatNumeric);
10333
10334        #[wasm_bindgen(method, getter = style)]
10335        pub fn get_style(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatStyle>;
10336        #[wasm_bindgen(method, setter = style)]
10337        pub fn set_style(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatStyle);
10338    }
10339
10340    impl RelativeTimeFormatOptions {
10341        pub fn new() -> RelativeTimeFormatOptions {
10342            JsCast::unchecked_into(Object::new())
10343        }
10344    }
10345
10346    impl Default for RelativeTimeFormatOptions {
10347        fn default() -> Self {
10348            RelativeTimeFormatOptions::new()
10349        }
10350    }
10351
10352    // Intl.ResolvedRelativeTimeFormatOptions
10353    #[wasm_bindgen]
10354    extern "C" {
10355        /// Resolved options returned by `Intl.RelativeTimeFormat.prototype.resolvedOptions()`.
10356        ///
10357        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
10358        #[wasm_bindgen(extends = RelativeTimeFormatOptions)]
10359        #[derive(Clone, Debug)]
10360        pub type ResolvedRelativeTimeFormatOptions;
10361
10362        /// The resolved locale string.
10363        #[wasm_bindgen(method, getter = locale)]
10364        pub fn get_locale(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10365
10366        /// The numbering system used.
10367        #[wasm_bindgen(method, getter = numberingSystem)]
10368        pub fn get_numbering_system(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10369    }
10370
10371    // Intl.RelativeTimeFormatPart
10372    #[wasm_bindgen]
10373    extern "C" {
10374        /// A part of the formatted relative time returned by `formatToParts()`.
10375        ///
10376        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
10377        #[wasm_bindgen(extends = Object)]
10378        #[derive(Clone, Debug)]
10379        pub type RelativeTimeFormatPart;
10380
10381        /// The type of this part.
10382        #[wasm_bindgen(method, getter = type)]
10383        pub fn type_(this: &RelativeTimeFormatPart) -> RelativeTimeFormatPartType;
10384
10385        /// The string value of this part.
10386        #[wasm_bindgen(method, getter = value)]
10387        pub fn value(this: &RelativeTimeFormatPart) -> JsString;
10388
10389        /// The unit used in this part (only for integer parts).
10390        #[wasm_bindgen(method, getter = unit)]
10391        pub fn unit(this: &RelativeTimeFormatPart) -> Option<JsString>;
10392    }
10393
10394    // Intl.LocaleMatcherOptions
10395    #[wasm_bindgen]
10396    extern "C" {
10397        /// Options for `supportedLocalesOf` methods.
10398        #[wasm_bindgen(extends = Object)]
10399        #[derive(Clone, Debug)]
10400        pub type LocaleMatcherOptions;
10401
10402        #[wasm_bindgen(method, getter = localeMatcher)]
10403        pub fn get_locale_matcher(this: &LocaleMatcherOptions) -> Option<LocaleMatcher>;
10404
10405        #[wasm_bindgen(method, setter = localeMatcher)]
10406        pub fn set_locale_matcher(this: &LocaleMatcherOptions, value: LocaleMatcher);
10407    }
10408
10409    impl LocaleMatcherOptions {
10410        pub fn new() -> LocaleMatcherOptions {
10411            JsCast::unchecked_into(Object::new())
10412        }
10413    }
10414
10415    impl Default for LocaleMatcherOptions {
10416        fn default() -> Self {
10417            LocaleMatcherOptions::new()
10418        }
10419    }
10420
10421    // Intl.Collator Options
10422    #[wasm_bindgen]
10423    extern "C" {
10424        /// Options for `Intl.Collator` and `String.prototype.localeCompare`.
10425        ///
10426        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options)
10427        #[wasm_bindgen(extends = Object)]
10428        #[derive(Clone, Debug)]
10429        pub type CollatorOptions;
10430
10431        #[wasm_bindgen(method, getter = localeMatcher)]
10432        pub fn get_locale_matcher(this: &CollatorOptions) -> Option<LocaleMatcher>;
10433        #[wasm_bindgen(method, setter = localeMatcher)]
10434        pub fn set_locale_matcher(this: &CollatorOptions, value: LocaleMatcher);
10435
10436        #[wasm_bindgen(method, getter = usage)]
10437        pub fn get_usage(this: &CollatorOptions) -> Option<CollatorUsage>;
10438        #[wasm_bindgen(method, setter = usage)]
10439        pub fn set_usage(this: &CollatorOptions, value: CollatorUsage);
10440
10441        #[wasm_bindgen(method, getter = sensitivity)]
10442        pub fn get_sensitivity(this: &CollatorOptions) -> Option<CollatorSensitivity>;
10443        #[wasm_bindgen(method, setter = sensitivity)]
10444        pub fn set_sensitivity(this: &CollatorOptions, value: CollatorSensitivity);
10445
10446        #[wasm_bindgen(method, getter = ignorePunctuation)]
10447        pub fn get_ignore_punctuation(this: &CollatorOptions) -> Option<bool>;
10448        #[wasm_bindgen(method, setter = ignorePunctuation)]
10449        pub fn set_ignore_punctuation(this: &CollatorOptions, value: bool);
10450
10451        #[wasm_bindgen(method, getter = numeric)]
10452        pub fn get_numeric(this: &CollatorOptions) -> Option<bool>;
10453        #[wasm_bindgen(method, setter = numeric)]
10454        pub fn set_numeric(this: &CollatorOptions, value: bool);
10455
10456        #[wasm_bindgen(method, getter = caseFirst)]
10457        pub fn get_case_first(this: &CollatorOptions) -> Option<CollatorCaseFirst>;
10458        #[wasm_bindgen(method, setter = caseFirst)]
10459        pub fn set_case_first(this: &CollatorOptions, value: CollatorCaseFirst);
10460    }
10461    impl CollatorOptions {
10462        pub fn new() -> CollatorOptions {
10463            JsCast::unchecked_into(Object::new())
10464        }
10465    }
10466    impl Default for CollatorOptions {
10467        fn default() -> Self {
10468            CollatorOptions::new()
10469        }
10470    }
10471
10472    // Intl.Collator ResolvedCollatorOptions
10473    #[wasm_bindgen]
10474    extern "C" {
10475        #[wasm_bindgen(extends = CollatorOptions)]
10476        pub type ResolvedCollatorOptions;
10477
10478        #[wasm_bindgen(method, getter = locale)]
10479        pub fn get_locale(this: &ResolvedCollatorOptions) -> JsString; // not Option, always present
10480        #[wasm_bindgen(method, getter = collation)]
10481        pub fn get_collation(this: &ResolvedCollatorOptions) -> JsString;
10482    }
10483
10484    // Intl.Collator
10485    #[wasm_bindgen]
10486    extern "C" {
10487        /// The `Intl.Collator` object is a constructor for collators, objects
10488        /// that enable language sensitive string comparison.
10489        ///
10490        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10491        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
10492        #[derive(Clone, Debug)]
10493        pub type Collator;
10494
10495        /// The `Intl.Collator` object is a constructor for collators, objects
10496        /// that enable language sensitive string comparison.
10497        ///
10498        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10499        #[cfg(not(js_sys_unstable_apis))]
10500        #[wasm_bindgen(constructor, js_namespace = Intl)]
10501        pub fn new(locales: &Array, options: &Object) -> Collator;
10502
10503        /// The `Intl.Collator` object is a constructor for collators, objects
10504        /// that enable language sensitive string comparison.
10505        ///
10506        /// Throws a `RangeError` if locales contain invalid values.
10507        ///
10508        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10509        #[cfg(js_sys_unstable_apis)]
10510        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10511        pub fn new(locales: &[JsString], options: &CollatorOptions) -> Result<Collator, JsValue>;
10512
10513        /// The Intl.Collator.prototype.compare property returns a function that
10514        /// compares two strings according to the sort order of this Collator
10515        /// object.
10516        ///
10517        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
10518        #[cfg(not(js_sys_unstable_apis))]
10519        #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
10520        pub fn compare(this: &Collator) -> Function;
10521
10522        /// Compares two strings according to the sort order of this Collator.
10523        ///
10524        /// Returns a negative value if `a` comes before `b`, positive if `a` comes
10525        /// after `b`, and zero if they are equal.
10526        ///
10527        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare)
10528        #[cfg(js_sys_unstable_apis)]
10529        #[wasm_bindgen(method, js_class = "Intl.Collator")]
10530        pub fn compare(this: &Collator, a: &str, b: &str) -> i32;
10531
10532        /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10533        /// object with properties reflecting the locale and collation options
10534        /// computed during initialization of this Collator object.
10535        ///
10536        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10537        #[cfg(not(js_sys_unstable_apis))]
10538        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10539        pub fn resolved_options(this: &Collator) -> Object;
10540
10541        /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10542        /// object with properties reflecting the locale and collation options
10543        /// computed during initialization of this Collator object.
10544        ///
10545        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10546        #[cfg(js_sys_unstable_apis)]
10547        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10548        pub fn resolved_options(this: &Collator) -> ResolvedCollatorOptions;
10549
10550        /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10551        /// containing those of the provided locales that are supported in
10552        /// collation without having to fall back to the runtime's default
10553        /// locale.
10554        ///
10555        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10556        #[cfg(not(js_sys_unstable_apis))]
10557        #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
10558        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10559
10560        /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10561        /// containing those of the provided locales that are supported in
10562        /// collation without having to fall back to the runtime's default
10563        /// locale.
10564        ///
10565        /// Throws a `RangeError` if locales contain invalid values.
10566        ///
10567        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10568        #[cfg(js_sys_unstable_apis)]
10569        #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10570        pub fn supported_locales_of(
10571            locales: &[JsString],
10572            options: &LocaleMatcherOptions,
10573        ) -> Result<Array<JsString>, JsValue>;
10574    }
10575
10576    #[cfg(not(js_sys_unstable_apis))]
10577    impl Default for Collator {
10578        fn default() -> Self {
10579            Self::new(
10580                &JsValue::UNDEFINED.unchecked_into(),
10581                &JsValue::UNDEFINED.unchecked_into(),
10582            )
10583        }
10584    }
10585
10586    #[cfg(js_sys_unstable_apis)]
10587    impl Default for Collator {
10588        fn default() -> Self {
10589            Self::new(&[], &Default::default()).unwrap()
10590        }
10591    }
10592
10593    // Intl.DateTimeFormatOptions
10594    #[wasm_bindgen]
10595    extern "C" {
10596        /// Options for `Intl.DateTimeFormat` constructor.
10597        ///
10598        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)
10599        #[wasm_bindgen(extends = Object)]
10600        #[derive(Clone, Debug)]
10601        pub type DateTimeFormatOptions;
10602
10603        // Locale matching
10604        #[wasm_bindgen(method, getter = localeMatcher)]
10605        pub fn get_locale_matcher(this: &DateTimeFormatOptions) -> Option<LocaleMatcher>;
10606        #[wasm_bindgen(method, setter = localeMatcher)]
10607        pub fn set_locale_matcher(this: &DateTimeFormatOptions, value: LocaleMatcher);
10608
10609        // Calendar/numbering (free-form strings, no enum)
10610        #[wasm_bindgen(method, getter = calendar)]
10611        pub fn get_calendar(this: &DateTimeFormatOptions) -> Option<JsString>;
10612        #[wasm_bindgen(method, setter = calendar)]
10613        pub fn set_calendar(this: &DateTimeFormatOptions, value: &str);
10614
10615        #[wasm_bindgen(method, getter = numberingSystem)]
10616        pub fn get_numbering_system(this: &DateTimeFormatOptions) -> Option<JsString>;
10617        #[wasm_bindgen(method, setter = numberingSystem)]
10618        pub fn set_numbering_system(this: &DateTimeFormatOptions, value: &str);
10619
10620        // Timezone (free-form string)
10621        #[wasm_bindgen(method, getter = timeZone)]
10622        pub fn get_time_zone(this: &DateTimeFormatOptions) -> Option<JsString>;
10623        #[wasm_bindgen(method, setter = timeZone)]
10624        pub fn set_time_zone(this: &DateTimeFormatOptions, value: &str);
10625
10626        // Hour cycle
10627        #[wasm_bindgen(method, getter = hour12)]
10628        pub fn get_hour12(this: &DateTimeFormatOptions) -> Option<bool>;
10629        #[wasm_bindgen(method, setter = hour12)]
10630        pub fn set_hour12(this: &DateTimeFormatOptions, value: bool);
10631
10632        #[wasm_bindgen(method, getter = hourCycle)]
10633        pub fn get_hour_cycle(this: &DateTimeFormatOptions) -> Option<HourCycle>;
10634        #[wasm_bindgen(method, setter = hourCycle)]
10635        pub fn set_hour_cycle(this: &DateTimeFormatOptions, value: HourCycle);
10636
10637        // Style shortcuts
10638        #[wasm_bindgen(method, getter = dateStyle)]
10639        pub fn get_date_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10640        #[wasm_bindgen(method, setter = dateStyle)]
10641        pub fn set_date_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10642
10643        #[wasm_bindgen(method, getter = timeStyle)]
10644        pub fn get_time_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10645        #[wasm_bindgen(method, setter = timeStyle)]
10646        pub fn set_time_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10647
10648        // Component options
10649        #[wasm_bindgen(method, getter = weekday)]
10650        pub fn get_weekday(this: &DateTimeFormatOptions) -> Option<WeekdayFormat>;
10651        #[wasm_bindgen(method, setter = weekday)]
10652        pub fn set_weekday(this: &DateTimeFormatOptions, value: WeekdayFormat);
10653
10654        #[wasm_bindgen(method, getter = era)]
10655        pub fn get_era(this: &DateTimeFormatOptions) -> Option<EraFormat>;
10656        #[wasm_bindgen(method, setter = era)]
10657        pub fn set_era(this: &DateTimeFormatOptions, value: EraFormat);
10658
10659        #[wasm_bindgen(method, getter = year)]
10660        pub fn get_year(this: &DateTimeFormatOptions) -> Option<YearFormat>;
10661        #[wasm_bindgen(method, setter = year)]
10662        pub fn set_year(this: &DateTimeFormatOptions, value: YearFormat);
10663
10664        #[wasm_bindgen(method, getter = month)]
10665        pub fn get_month(this: &DateTimeFormatOptions) -> Option<MonthFormat>;
10666        #[wasm_bindgen(method, setter = month)]
10667        pub fn set_month(this: &DateTimeFormatOptions, value: MonthFormat);
10668
10669        #[wasm_bindgen(method, getter = day)]
10670        pub fn get_day(this: &DateTimeFormatOptions) -> Option<DayFormat>;
10671        #[wasm_bindgen(method, setter = day)]
10672        pub fn set_day(this: &DateTimeFormatOptions, value: DayFormat);
10673
10674        #[wasm_bindgen(method, getter = hour)]
10675        pub fn get_hour(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10676        #[wasm_bindgen(method, setter = hour)]
10677        pub fn set_hour(this: &DateTimeFormatOptions, value: NumericFormat);
10678
10679        #[wasm_bindgen(method, getter = minute)]
10680        pub fn get_minute(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10681        #[wasm_bindgen(method, setter = minute)]
10682        pub fn set_minute(this: &DateTimeFormatOptions, value: NumericFormat);
10683
10684        #[wasm_bindgen(method, getter = second)]
10685        pub fn get_second(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10686        #[wasm_bindgen(method, setter = second)]
10687        pub fn set_second(this: &DateTimeFormatOptions, value: NumericFormat);
10688
10689        #[wasm_bindgen(method, getter = fractionalSecondDigits)]
10690        pub fn get_fractional_second_digits(this: &DateTimeFormatOptions) -> Option<u8>;
10691        #[wasm_bindgen(method, setter = fractionalSecondDigits)]
10692        pub fn set_fractional_second_digits(this: &DateTimeFormatOptions, value: u8);
10693
10694        #[wasm_bindgen(method, getter = timeZoneName)]
10695        pub fn get_time_zone_name(this: &DateTimeFormatOptions) -> Option<TimeZoneNameFormat>;
10696        #[wasm_bindgen(method, setter = timeZoneName)]
10697        pub fn set_time_zone_name(this: &DateTimeFormatOptions, value: TimeZoneNameFormat);
10698
10699        #[wasm_bindgen(method, getter = dayPeriod)]
10700        pub fn get_day_period(this: &DateTimeFormatOptions) -> Option<DayPeriodFormat>;
10701        #[wasm_bindgen(method, setter = dayPeriod)]
10702        pub fn set_day_period(this: &DateTimeFormatOptions, value: DayPeriodFormat);
10703    }
10704
10705    impl DateTimeFormatOptions {
10706        pub fn new() -> DateTimeFormatOptions {
10707            JsCast::unchecked_into(Object::new())
10708        }
10709    }
10710
10711    impl Default for DateTimeFormatOptions {
10712        fn default() -> Self {
10713            DateTimeFormatOptions::new()
10714        }
10715    }
10716
10717    // Intl.ResolvedDateTimeFormatOptions
10718    #[wasm_bindgen]
10719    extern "C" {
10720        /// Resolved options returned by `Intl.DateTimeFormat.prototype.resolvedOptions()`.
10721        ///
10722        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions)
10723        #[wasm_bindgen(extends = DateTimeFormatOptions)]
10724        #[derive(Clone, Debug)]
10725        pub type ResolvedDateTimeFormatOptions;
10726
10727        /// The resolved locale string.
10728        #[wasm_bindgen(method, getter = locale)]
10729        pub fn get_locale(this: &ResolvedDateTimeFormatOptions) -> JsString;
10730    }
10731
10732    // Intl.DateTimeFormatPart
10733    #[wasm_bindgen]
10734    extern "C" {
10735        /// A part of the formatted date returned by `formatToParts()`.
10736        ///
10737        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
10738        #[wasm_bindgen(extends = Object)]
10739        #[derive(Clone, Debug)]
10740        pub type DateTimeFormatPart;
10741
10742        /// The type of the part (e.g., "day", "month", "year", "literal", etc.)
10743        #[wasm_bindgen(method, getter = type)]
10744        pub fn type_(this: &DateTimeFormatPart) -> DateTimeFormatPartType;
10745
10746        /// The value of the part.
10747        #[wasm_bindgen(method, getter)]
10748        pub fn value(this: &DateTimeFormatPart) -> JsString;
10749    }
10750
10751    // Intl.DateTimeRangeFormatPart
10752    #[wasm_bindgen]
10753    extern "C" {
10754        /// A part of the formatted date range returned by `formatRangeToParts()`.
10755        ///
10756        /// Extends `DateTimeFormatPart` with a `source` property indicating whether
10757        /// the part is from the start date, end date, or shared between them.
10758        ///
10759        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
10760        #[wasm_bindgen(extends = DateTimeFormatPart)]
10761        #[derive(Clone, Debug)]
10762        pub type DateTimeRangeFormatPart;
10763
10764        /// The source of the part: "startRange", "endRange", or "shared".
10765        #[wasm_bindgen(method, getter)]
10766        pub fn source(this: &DateTimeRangeFormatPart) -> RangeSource;
10767    }
10768
10769    // Intl.DateTimeFormat
10770    #[wasm_bindgen]
10771    extern "C" {
10772        /// The `Intl.DateTimeFormat` object is a constructor for objects
10773        /// that enable language-sensitive date and time formatting.
10774        ///
10775        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10776        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
10777        #[derive(Clone, Debug)]
10778        pub type DateTimeFormat;
10779
10780        /// The `Intl.DateTimeFormat` object is a constructor for objects
10781        /// that enable language-sensitive date and time formatting.
10782        ///
10783        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10784        #[cfg(not(js_sys_unstable_apis))]
10785        #[wasm_bindgen(constructor, js_namespace = Intl)]
10786        pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
10787
10788        /// The `Intl.DateTimeFormat` object is a constructor for objects
10789        /// that enable language-sensitive date and time formatting.
10790        ///
10791        /// Throws a `RangeError` if locales contain invalid values.
10792        ///
10793        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10794        #[cfg(js_sys_unstable_apis)]
10795        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10796        pub fn new(
10797            locales: &[JsString],
10798            options: &DateTimeFormatOptions,
10799        ) -> Result<DateTimeFormat, JsValue>;
10800
10801        /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
10802        /// formats a date according to the locale and formatting options of this
10803        /// Intl.DateTimeFormat object.
10804        ///
10805        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
10806        #[cfg(not(js_sys_unstable_apis))]
10807        #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
10808        pub fn format(this: &DateTimeFormat) -> Function;
10809
10810        /// Formats a date according to the locale and formatting options of this
10811        /// `Intl.DateTimeFormat` object.
10812        ///
10813        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format)
10814        #[cfg(js_sys_unstable_apis)]
10815        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat")]
10816        pub fn format(this: &DateTimeFormat, date: &Date) -> JsString;
10817
10818        /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
10819        /// formatting of strings produced by DateTimeFormat formatters.
10820        ///
10821        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
10822        #[cfg(not(js_sys_unstable_apis))]
10823        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
10824        pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
10825
10826        /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
10827        /// formatting of strings produced by DateTimeFormat formatters.
10828        ///
10829        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
10830        #[cfg(js_sys_unstable_apis)]
10831        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
10832        pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array<DateTimeFormatPart>;
10833
10834        /// The `Intl.DateTimeFormat.prototype.formatRange()` method formats a date range
10835        /// in the most concise way based on the locales and options provided when
10836        /// instantiating this `Intl.DateTimeFormat` object.
10837        ///
10838        /// Throws a `TypeError` if the dates are invalid.
10839        ///
10840        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange)
10841        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRange, catch)]
10842        pub fn format_range(
10843            this: &DateTimeFormat,
10844            start_date: &Date,
10845            end_date: &Date,
10846        ) -> Result<JsString, JsValue>;
10847
10848        /// The `Intl.DateTimeFormat.prototype.formatRangeToParts()` method returns an array
10849        /// of locale-specific tokens representing each part of the formatted date range
10850        /// produced by `Intl.DateTimeFormat` formatters.
10851        ///
10852        /// Throws a `TypeError` if the dates are invalid.
10853        ///
10854        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
10855        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRangeToParts, catch)]
10856        pub fn format_range_to_parts(
10857            this: &DateTimeFormat,
10858            start_date: &Date,
10859            end_date: &Date,
10860        ) -> Result<Array<DateTimeRangeFormatPart>, JsValue>;
10861
10862        /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
10863        /// object with properties reflecting the locale and date and time formatting
10864        /// options computed during initialization of this DateTimeFormat object.
10865        ///
10866        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
10867        #[cfg(not(js_sys_unstable_apis))]
10868        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10869        pub fn resolved_options(this: &DateTimeFormat) -> Object;
10870
10871        /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
10872        /// object with properties reflecting the locale and date and time formatting
10873        /// options computed during initialization of this DateTimeFormat object.
10874        ///
10875        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
10876        #[cfg(js_sys_unstable_apis)]
10877        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10878        pub fn resolved_options(this: &DateTimeFormat) -> ResolvedDateTimeFormatOptions;
10879
10880        /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
10881        /// containing those of the provided locales that are supported in date
10882        /// and time formatting without having to fall back to the runtime's default
10883        /// locale.
10884        ///
10885        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
10886        #[cfg(not(js_sys_unstable_apis))]
10887        #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
10888        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10889
10890        /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
10891        /// containing those of the provided locales that are supported in date
10892        /// and time formatting without having to fall back to the runtime's default
10893        /// locale.
10894        ///
10895        /// Throws a `RangeError` if locales contain invalid values.
10896        ///
10897        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
10898        #[cfg(js_sys_unstable_apis)]
10899        #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10900        pub fn supported_locales_of(
10901            locales: &[JsString],
10902            options: &LocaleMatcherOptions,
10903        ) -> Result<Array<JsString>, JsValue>;
10904    }
10905
10906    #[cfg(not(js_sys_unstable_apis))]
10907    impl Default for DateTimeFormat {
10908        fn default() -> Self {
10909            Self::new(
10910                &JsValue::UNDEFINED.unchecked_into(),
10911                &JsValue::UNDEFINED.unchecked_into(),
10912            )
10913        }
10914    }
10915
10916    #[cfg(js_sys_unstable_apis)]
10917    impl Default for DateTimeFormat {
10918        fn default() -> Self {
10919            Self::new(&[], &Default::default()).unwrap()
10920        }
10921    }
10922
10923    // Intl.NumberFormatOptions
10924    #[wasm_bindgen]
10925    extern "C" {
10926        /// Options for `Intl.NumberFormat` constructor.
10927        ///
10928        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options)
10929        #[wasm_bindgen(extends = Object)]
10930        #[derive(Clone, Debug)]
10931        pub type NumberFormatOptions;
10932
10933        // Locale matching
10934        #[wasm_bindgen(method, getter = localeMatcher)]
10935        pub fn get_locale_matcher(this: &NumberFormatOptions) -> Option<LocaleMatcher>;
10936        #[wasm_bindgen(method, setter = localeMatcher)]
10937        pub fn set_locale_matcher(this: &NumberFormatOptions, value: LocaleMatcher);
10938
10939        // Numbering system (free-form string)
10940        #[wasm_bindgen(method, getter = numberingSystem)]
10941        pub fn get_numbering_system(this: &NumberFormatOptions) -> Option<JsString>;
10942        #[wasm_bindgen(method, setter = numberingSystem)]
10943        pub fn set_numbering_system(this: &NumberFormatOptions, value: &str);
10944
10945        // Style
10946        #[wasm_bindgen(method, getter = style)]
10947        pub fn get_style(this: &NumberFormatOptions) -> Option<NumberFormatStyle>;
10948        #[wasm_bindgen(method, setter = style)]
10949        pub fn set_style(this: &NumberFormatOptions, value: NumberFormatStyle);
10950
10951        // Currency options (currency code is free-form ISO 4217 string)
10952        #[wasm_bindgen(method, getter = currency)]
10953        pub fn get_currency(this: &NumberFormatOptions) -> Option<JsString>;
10954        #[wasm_bindgen(method, setter = currency)]
10955        pub fn set_currency(this: &NumberFormatOptions, value: &str);
10956
10957        #[wasm_bindgen(method, getter = currencyDisplay)]
10958        pub fn get_currency_display(this: &NumberFormatOptions) -> Option<CurrencyDisplay>;
10959        #[wasm_bindgen(method, setter = currencyDisplay)]
10960        pub fn set_currency_display(this: &NumberFormatOptions, value: CurrencyDisplay);
10961
10962        #[wasm_bindgen(method, getter = currencySign)]
10963        pub fn get_currency_sign(this: &NumberFormatOptions) -> Option<CurrencySign>;
10964        #[wasm_bindgen(method, setter = currencySign)]
10965        pub fn set_currency_sign(this: &NumberFormatOptions, value: CurrencySign);
10966
10967        // Unit options (unit name is free-form string)
10968        #[wasm_bindgen(method, getter = unit)]
10969        pub fn get_unit(this: &NumberFormatOptions) -> Option<JsString>;
10970        #[wasm_bindgen(method, setter = unit)]
10971        pub fn set_unit(this: &NumberFormatOptions, value: &str);
10972
10973        #[wasm_bindgen(method, getter = unitDisplay)]
10974        pub fn get_unit_display(this: &NumberFormatOptions) -> Option<UnitDisplay>;
10975        #[wasm_bindgen(method, setter = unitDisplay)]
10976        pub fn set_unit_display(this: &NumberFormatOptions, value: UnitDisplay);
10977
10978        // Notation
10979        #[wasm_bindgen(method, getter = notation)]
10980        pub fn get_notation(this: &NumberFormatOptions) -> Option<NumberFormatNotation>;
10981        #[wasm_bindgen(method, setter = notation)]
10982        pub fn set_notation(this: &NumberFormatOptions, value: NumberFormatNotation);
10983
10984        #[wasm_bindgen(method, getter = compactDisplay)]
10985        pub fn get_compact_display(this: &NumberFormatOptions) -> Option<CompactDisplay>;
10986        #[wasm_bindgen(method, setter = compactDisplay)]
10987        pub fn set_compact_display(this: &NumberFormatOptions, value: CompactDisplay);
10988
10989        // Sign display
10990        #[wasm_bindgen(method, getter = signDisplay)]
10991        pub fn get_sign_display(this: &NumberFormatOptions) -> Option<SignDisplay>;
10992        #[wasm_bindgen(method, setter = signDisplay)]
10993        pub fn set_sign_display(this: &NumberFormatOptions, value: SignDisplay);
10994
10995        // Digit options
10996        #[wasm_bindgen(method, getter = minimumIntegerDigits)]
10997        pub fn get_minimum_integer_digits(this: &NumberFormatOptions) -> Option<u8>;
10998        #[wasm_bindgen(method, setter = minimumIntegerDigits)]
10999        pub fn set_minimum_integer_digits(this: &NumberFormatOptions, value: u8);
11000
11001        #[wasm_bindgen(method, getter = minimumFractionDigits)]
11002        pub fn get_minimum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11003        #[wasm_bindgen(method, setter = minimumFractionDigits)]
11004        pub fn set_minimum_fraction_digits(this: &NumberFormatOptions, value: u8);
11005
11006        #[wasm_bindgen(method, getter = maximumFractionDigits)]
11007        pub fn get_maximum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11008        #[wasm_bindgen(method, setter = maximumFractionDigits)]
11009        pub fn set_maximum_fraction_digits(this: &NumberFormatOptions, value: u8);
11010
11011        #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11012        pub fn get_minimum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11013        #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11014        pub fn set_minimum_significant_digits(this: &NumberFormatOptions, value: u8);
11015
11016        #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11017        pub fn get_maximum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11018        #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11019        pub fn set_maximum_significant_digits(this: &NumberFormatOptions, value: u8);
11020
11021        // Grouping
11022        #[wasm_bindgen(method, getter = useGrouping)]
11023        pub fn get_use_grouping(this: &NumberFormatOptions) -> Option<UseGrouping>;
11024        #[wasm_bindgen(method, setter = useGrouping)]
11025        pub fn set_use_grouping(this: &NumberFormatOptions, value: UseGrouping);
11026
11027        // Rounding
11028        #[wasm_bindgen(method, getter = roundingMode)]
11029        pub fn get_rounding_mode(this: &NumberFormatOptions) -> Option<RoundingMode>;
11030        #[wasm_bindgen(method, setter = roundingMode)]
11031        pub fn set_rounding_mode(this: &NumberFormatOptions, value: RoundingMode);
11032
11033        #[wasm_bindgen(method, getter = roundingPriority)]
11034        pub fn get_rounding_priority(this: &NumberFormatOptions) -> Option<RoundingPriority>;
11035        #[wasm_bindgen(method, setter = roundingPriority)]
11036        pub fn set_rounding_priority(this: &NumberFormatOptions, value: RoundingPriority);
11037
11038        #[wasm_bindgen(method, getter = roundingIncrement)]
11039        pub fn get_rounding_increment(this: &NumberFormatOptions) -> Option<u32>;
11040        #[wasm_bindgen(method, setter = roundingIncrement)]
11041        pub fn set_rounding_increment(this: &NumberFormatOptions, value: u32);
11042
11043        #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11044        pub fn get_trailing_zero_display(this: &NumberFormatOptions)
11045            -> Option<TrailingZeroDisplay>;
11046        #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11047        pub fn set_trailing_zero_display(this: &NumberFormatOptions, value: TrailingZeroDisplay);
11048    }
11049
11050    impl NumberFormatOptions {
11051        pub fn new() -> NumberFormatOptions {
11052            JsCast::unchecked_into(Object::new())
11053        }
11054    }
11055
11056    impl Default for NumberFormatOptions {
11057        fn default() -> Self {
11058            NumberFormatOptions::new()
11059        }
11060    }
11061
11062    // Intl.ResolvedNumberFormatOptions
11063    #[wasm_bindgen]
11064    extern "C" {
11065        /// Resolved options returned by `Intl.NumberFormat.prototype.resolvedOptions()`.
11066        ///
11067        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions)
11068        #[wasm_bindgen(extends = NumberFormatOptions)]
11069        #[derive(Clone, Debug)]
11070        pub type ResolvedNumberFormatOptions;
11071
11072        /// The resolved locale string.
11073        #[wasm_bindgen(method, getter = locale)]
11074        pub fn get_locale(this: &ResolvedNumberFormatOptions) -> JsString;
11075    }
11076
11077    // Intl.NumberFormatPart
11078    #[wasm_bindgen]
11079    extern "C" {
11080        /// A part of the formatted number returned by `formatToParts()`.
11081        ///
11082        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11083        #[wasm_bindgen(extends = Object)]
11084        #[derive(Clone, Debug)]
11085        pub type NumberFormatPart;
11086
11087        /// The type of the part (e.g., "integer", "decimal", "fraction", "currency", etc.)
11088        #[wasm_bindgen(method, getter = type)]
11089        pub fn type_(this: &NumberFormatPart) -> NumberFormatPartType;
11090
11091        /// The value of the part.
11092        #[wasm_bindgen(method, getter)]
11093        pub fn value(this: &NumberFormatPart) -> JsString;
11094    }
11095
11096    // Intl.NumberRangeFormatPart
11097    #[wasm_bindgen]
11098    extern "C" {
11099        /// A part of the formatted number range returned by `formatRangeToParts()`.
11100        ///
11101        /// Extends `NumberFormatPart` with a `source` property indicating whether
11102        /// the part is from the start number, end number, or shared between them.
11103        ///
11104        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11105        #[wasm_bindgen(extends = NumberFormatPart)]
11106        #[derive(Clone, Debug)]
11107        pub type NumberRangeFormatPart;
11108
11109        /// The source of the part: "startRange", "endRange", or "shared".
11110        #[wasm_bindgen(method, getter)]
11111        pub fn source(this: &NumberRangeFormatPart) -> RangeSource;
11112    }
11113
11114    // Intl.NumberFormat
11115    #[wasm_bindgen]
11116    extern "C" {
11117        /// The `Intl.NumberFormat` object is a constructor for objects
11118        /// that enable language sensitive number formatting.
11119        ///
11120        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11121        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
11122        #[derive(Clone, Debug)]
11123        pub type NumberFormat;
11124
11125        /// The `Intl.NumberFormat` object is a constructor for objects
11126        /// that enable language sensitive number formatting.
11127        ///
11128        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11129        #[cfg(not(js_sys_unstable_apis))]
11130        #[wasm_bindgen(constructor, js_namespace = Intl)]
11131        pub fn new(locales: &Array, options: &Object) -> NumberFormat;
11132
11133        /// The `Intl.NumberFormat` object is a constructor for objects
11134        /// that enable language sensitive number formatting.
11135        ///
11136        /// Throws a `RangeError` if locales contain invalid values.
11137        ///
11138        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11139        #[cfg(js_sys_unstable_apis)]
11140        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11141        pub fn new(
11142            locales: &[JsString],
11143            options: &NumberFormatOptions,
11144        ) -> Result<NumberFormat, JsValue>;
11145
11146        /// The Intl.NumberFormat.prototype.format property returns a getter function that
11147        /// formats a number according to the locale and formatting options of this
11148        /// NumberFormat object.
11149        ///
11150        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
11151        #[cfg(not(js_sys_unstable_apis))]
11152        #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
11153        pub fn format(this: &NumberFormat) -> Function;
11154
11155        /// Formats a number according to the locale and formatting options of this
11156        /// `Intl.NumberFormat` object.
11157        ///
11158        /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11159        /// or use E notation: `"1000000E-6"` → `"1"`).
11160        ///
11161        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format)
11162        #[cfg(js_sys_unstable_apis)]
11163        #[wasm_bindgen(method, js_class = "Intl.NumberFormat")]
11164        pub fn format(this: &NumberFormat, value: &JsString) -> JsString;
11165
11166        /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
11167        /// formatting of strings produced by NumberTimeFormat formatters.
11168        ///
11169        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
11170        #[cfg(not(js_sys_unstable_apis))]
11171        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11172        pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
11173
11174        /// The `Intl.NumberFormat.prototype.formatToParts()` method allows locale-aware
11175        /// formatting of strings produced by `Intl.NumberFormat` formatters.
11176        ///
11177        /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11178        /// or use E notation: `"1000000E-6"` → `"1"`).
11179        ///
11180        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11181        #[cfg(js_sys_unstable_apis)]
11182        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11183        pub fn format_to_parts(this: &NumberFormat, value: &JsString) -> Array<NumberFormatPart>;
11184
11185        /// Formats a range of numbers according to the locale and formatting options
11186        /// of this `Intl.NumberFormat` object.
11187        ///
11188        /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11189        /// or use E notation: `"1000000E-6"` → `"1"`).
11190        ///
11191        /// Throws a `TypeError` if the values are invalid.
11192        ///
11193        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange)
11194        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRange, catch)]
11195        pub fn format_range(
11196            this: &NumberFormat,
11197            start: &JsString,
11198            end: &JsString,
11199        ) -> Result<JsString, JsValue>;
11200
11201        /// Returns an array of locale-specific tokens representing each part of
11202        /// the formatted number range.
11203        ///
11204        /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11205        /// or use E notation: `"1000000E-6"` → `"1"`).
11206        ///
11207        /// Throws a `TypeError` if the values are invalid.
11208        ///
11209        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11210        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRangeToParts, catch)]
11211        pub fn format_range_to_parts(
11212            this: &NumberFormat,
11213            start: &JsString,
11214            end: &JsString,
11215        ) -> Result<Array<NumberRangeFormatPart>, JsValue>;
11216
11217        /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11218        /// object with properties reflecting the locale and number formatting
11219        /// options computed during initialization of this NumberFormat object.
11220        ///
11221        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11222        #[cfg(not(js_sys_unstable_apis))]
11223        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11224        pub fn resolved_options(this: &NumberFormat) -> Object;
11225
11226        /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11227        /// object with properties reflecting the locale and number formatting
11228        /// options computed during initialization of this NumberFormat object.
11229        ///
11230        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11231        #[cfg(js_sys_unstable_apis)]
11232        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11233        pub fn resolved_options(this: &NumberFormat) -> ResolvedNumberFormatOptions;
11234
11235        /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11236        /// containing those of the provided locales that are supported in number
11237        /// formatting without having to fall back to the runtime's default locale.
11238        ///
11239        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11240        #[cfg(not(js_sys_unstable_apis))]
11241        #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11242        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11243
11244        /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11245        /// containing those of the provided locales that are supported in number
11246        /// formatting without having to fall back to the runtime's default locale.
11247        ///
11248        /// Throws a `RangeError` if locales contain invalid values.
11249        ///
11250        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11251        #[cfg(js_sys_unstable_apis)]
11252        #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11253        pub fn supported_locales_of(
11254            locales: &[JsString],
11255            options: &LocaleMatcherOptions,
11256        ) -> Result<Array<JsString>, JsValue>;
11257    }
11258
11259    #[cfg(not(js_sys_unstable_apis))]
11260    impl Default for NumberFormat {
11261        fn default() -> Self {
11262            Self::new(
11263                &JsValue::UNDEFINED.unchecked_into(),
11264                &JsValue::UNDEFINED.unchecked_into(),
11265            )
11266        }
11267    }
11268
11269    #[cfg(js_sys_unstable_apis)]
11270    impl Default for NumberFormat {
11271        fn default() -> Self {
11272            Self::new(&[], &Default::default()).unwrap()
11273        }
11274    }
11275
11276    // Intl.PluralRulesOptions
11277    #[wasm_bindgen]
11278    extern "C" {
11279        /// Options for `Intl.PluralRules` constructor.
11280        ///
11281        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#options)
11282        #[wasm_bindgen(extends = Object)]
11283        #[derive(Clone, Debug)]
11284        pub type PluralRulesOptions;
11285
11286        #[wasm_bindgen(method, getter = localeMatcher)]
11287        pub fn get_locale_matcher(this: &PluralRulesOptions) -> Option<LocaleMatcher>;
11288        #[wasm_bindgen(method, setter = localeMatcher)]
11289        pub fn set_locale_matcher(this: &PluralRulesOptions, value: LocaleMatcher);
11290
11291        #[wasm_bindgen(method, getter = type)]
11292        pub fn get_type(this: &PluralRulesOptions) -> Option<PluralRulesType>;
11293        #[wasm_bindgen(method, setter = type)]
11294        pub fn set_type(this: &PluralRulesOptions, value: PluralRulesType);
11295
11296        #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11297        pub fn get_minimum_integer_digits(this: &PluralRulesOptions) -> Option<u8>;
11298        #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11299        pub fn set_minimum_integer_digits(this: &PluralRulesOptions, value: u8);
11300
11301        #[wasm_bindgen(method, getter = minimumFractionDigits)]
11302        pub fn get_minimum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11303        #[wasm_bindgen(method, setter = minimumFractionDigits)]
11304        pub fn set_minimum_fraction_digits(this: &PluralRulesOptions, value: u8);
11305
11306        #[wasm_bindgen(method, getter = maximumFractionDigits)]
11307        pub fn get_maximum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11308        #[wasm_bindgen(method, setter = maximumFractionDigits)]
11309        pub fn set_maximum_fraction_digits(this: &PluralRulesOptions, value: u8);
11310
11311        #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11312        pub fn get_minimum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11313        #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11314        pub fn set_minimum_significant_digits(this: &PluralRulesOptions, value: u8);
11315
11316        #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11317        pub fn get_maximum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11318        #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11319        pub fn set_maximum_significant_digits(this: &PluralRulesOptions, value: u8);
11320
11321        #[wasm_bindgen(method, getter = roundingPriority)]
11322        pub fn get_rounding_priority(this: &PluralRulesOptions) -> Option<RoundingPriority>;
11323        #[wasm_bindgen(method, setter = roundingPriority)]
11324        pub fn set_rounding_priority(this: &PluralRulesOptions, value: RoundingPriority);
11325
11326        #[wasm_bindgen(method, getter = roundingIncrement)]
11327        pub fn get_rounding_increment(this: &PluralRulesOptions) -> Option<u32>;
11328        #[wasm_bindgen(method, setter = roundingIncrement)]
11329        pub fn set_rounding_increment(this: &PluralRulesOptions, value: u32);
11330
11331        #[wasm_bindgen(method, getter = roundingMode)]
11332        pub fn get_rounding_mode(this: &PluralRulesOptions) -> Option<RoundingMode>;
11333        #[wasm_bindgen(method, setter = roundingMode)]
11334        pub fn set_rounding_mode(this: &PluralRulesOptions, value: RoundingMode);
11335
11336        #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11337        pub fn get_trailing_zero_display(this: &PluralRulesOptions) -> Option<TrailingZeroDisplay>;
11338        #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11339        pub fn set_trailing_zero_display(this: &PluralRulesOptions, value: TrailingZeroDisplay);
11340    }
11341
11342    impl PluralRulesOptions {
11343        pub fn new() -> PluralRulesOptions {
11344            JsCast::unchecked_into(Object::new())
11345        }
11346    }
11347
11348    impl Default for PluralRulesOptions {
11349        fn default() -> Self {
11350            PluralRulesOptions::new()
11351        }
11352    }
11353
11354    // Intl.ResolvedPluralRulesOptions
11355    #[wasm_bindgen]
11356    extern "C" {
11357        /// Resolved options returned by `Intl.PluralRules.prototype.resolvedOptions()`.
11358        ///
11359        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/resolvedOptions)
11360        #[wasm_bindgen(extends = PluralRulesOptions)]
11361        #[derive(Clone, Debug)]
11362        pub type ResolvedPluralRulesOptions;
11363
11364        /// The resolved locale string.
11365        #[wasm_bindgen(method, getter = locale)]
11366        pub fn get_locale(this: &ResolvedPluralRulesOptions) -> JsString;
11367
11368        /// The plural categories used by the locale.
11369        #[wasm_bindgen(method, getter = pluralCategories)]
11370        pub fn get_plural_categories(this: &ResolvedPluralRulesOptions) -> Array<JsString>;
11371    }
11372
11373    // Intl.PluralRules
11374    #[wasm_bindgen]
11375    extern "C" {
11376        /// The `Intl.PluralRules` object is a constructor for objects
11377        /// that enable plural sensitive formatting and plural language rules.
11378        ///
11379        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11380        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
11381        #[derive(Clone, Debug)]
11382        pub type PluralRules;
11383
11384        /// The `Intl.PluralRules` object is a constructor for objects
11385        /// that enable plural sensitive formatting and plural language rules.
11386        ///
11387        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11388        #[cfg(not(js_sys_unstable_apis))]
11389        #[wasm_bindgen(constructor, js_namespace = Intl)]
11390        pub fn new(locales: &Array, options: &Object) -> PluralRules;
11391
11392        /// The `Intl.PluralRules` object is a constructor for objects
11393        /// that enable plural sensitive formatting and plural language rules.
11394        ///
11395        /// Throws a `RangeError` if locales contain invalid values.
11396        ///
11397        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11398        #[cfg(js_sys_unstable_apis)]
11399        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11400        pub fn new(
11401            locales: &[JsString],
11402            options: &PluralRulesOptions,
11403        ) -> Result<PluralRules, JsValue>;
11404
11405        /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11406        /// object with properties reflecting the locale and plural formatting
11407        /// options computed during initialization of this PluralRules object.
11408        ///
11409        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11410        #[cfg(not(js_sys_unstable_apis))]
11411        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11412        pub fn resolved_options(this: &PluralRules) -> Object;
11413
11414        /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11415        /// object with properties reflecting the locale and plural formatting
11416        /// options computed during initialization of this PluralRules object.
11417        ///
11418        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11419        #[cfg(js_sys_unstable_apis)]
11420        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11421        pub fn resolved_options(this: &PluralRules) -> ResolvedPluralRulesOptions;
11422
11423        /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11424        /// which plural rule to use for locale-aware formatting.
11425        ///
11426        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11427        #[cfg(not(js_sys_unstable_apis))]
11428        #[wasm_bindgen(method, js_namespace = Intl)]
11429        pub fn select(this: &PluralRules, number: f64) -> JsString;
11430
11431        /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11432        /// which plural rule to use for locale-aware formatting.
11433        ///
11434        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11435        #[cfg(js_sys_unstable_apis)]
11436        #[wasm_bindgen(method, js_namespace = Intl)]
11437        pub fn select(this: &PluralRules, number: f64) -> PluralCategory;
11438
11439        /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11440        /// which plural rule to use for locale-aware formatting of a range of numbers.
11441        ///
11442        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11443        #[cfg(not(js_sys_unstable_apis))]
11444        #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11445        pub fn select_range(this: &PluralRules, start: f64, end: f64) -> JsString;
11446
11447        /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11448        /// which plural rule to use for locale-aware formatting of a range of numbers.
11449        ///
11450        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11451        #[cfg(js_sys_unstable_apis)]
11452        #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11453        pub fn select_range(this: &PluralRules, start: f64, end: f64) -> PluralCategory;
11454
11455        /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11456        /// containing those of the provided locales that are supported in plural
11457        /// formatting without having to fall back to the runtime's default locale.
11458        ///
11459        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11460        #[cfg(not(js_sys_unstable_apis))]
11461        #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
11462        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11463
11464        /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11465        /// containing those of the provided locales that are supported in plural
11466        /// formatting without having to fall back to the runtime's default locale.
11467        ///
11468        /// Throws a `RangeError` if locales contain invalid values.
11469        ///
11470        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11471        #[cfg(js_sys_unstable_apis)]
11472        #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11473        pub fn supported_locales_of(
11474            locales: &[JsString],
11475            options: &LocaleMatcherOptions,
11476        ) -> Result<Array<JsString>, JsValue>;
11477    }
11478
11479    #[cfg(not(js_sys_unstable_apis))]
11480    impl Default for PluralRules {
11481        fn default() -> Self {
11482            Self::new(
11483                &JsValue::UNDEFINED.unchecked_into(),
11484                &JsValue::UNDEFINED.unchecked_into(),
11485            )
11486        }
11487    }
11488
11489    #[cfg(js_sys_unstable_apis)]
11490    impl Default for PluralRules {
11491        fn default() -> Self {
11492            Self::new(&[], &Default::default()).unwrap()
11493        }
11494    }
11495
11496    // Intl.RelativeTimeFormat
11497    #[wasm_bindgen]
11498    extern "C" {
11499        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11500        /// that enable language-sensitive relative time formatting.
11501        ///
11502        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11503        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
11504        #[derive(Clone, Debug)]
11505        pub type RelativeTimeFormat;
11506
11507        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11508        /// that enable language-sensitive relative time formatting.
11509        ///
11510        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11511        #[cfg(not(js_sys_unstable_apis))]
11512        #[wasm_bindgen(constructor, js_namespace = Intl)]
11513        pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
11514
11515        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11516        /// that enable language-sensitive relative time formatting.
11517        ///
11518        /// Throws a `RangeError` if locales contain invalid values.
11519        ///
11520        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11521        #[cfg(js_sys_unstable_apis)]
11522        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11523        pub fn new(locales: &[JsString]) -> Result<RelativeTimeFormat, JsValue>;
11524
11525        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11526        /// that enable language-sensitive relative time formatting.
11527        ///
11528        /// Throws a `RangeError` if locales or options contain invalid values.
11529        ///
11530        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11531        #[cfg(js_sys_unstable_apis)]
11532        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11533        pub fn new_with_options(
11534            locales: &[JsString],
11535            options: &RelativeTimeFormatOptions,
11536        ) -> Result<RelativeTimeFormat, JsValue>;
11537
11538        /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11539        /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11540        ///
11541        /// Throws a `RangeError` if unit is invalid.
11542        ///
11543        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11544        #[cfg(not(js_sys_unstable_apis))]
11545        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11546        pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
11547
11548        /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11549        /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11550        ///
11551        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11552        #[cfg(js_sys_unstable_apis)]
11553        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11554        pub fn format(
11555            this: &RelativeTimeFormat,
11556            value: f64,
11557            unit: RelativeTimeFormatUnit,
11558        ) -> JsString;
11559
11560        /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11561        /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11562        ///
11563        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11564        #[cfg(not(js_sys_unstable_apis))]
11565        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11566        pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
11567
11568        /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11569        /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11570        ///
11571        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11572        #[cfg(js_sys_unstable_apis)]
11573        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11574        pub fn format_to_parts(
11575            this: &RelativeTimeFormat,
11576            value: f64,
11577            unit: RelativeTimeFormatUnit,
11578        ) -> Array<RelativeTimeFormatPart>;
11579
11580        /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11581        /// object with properties reflecting the locale and relative time formatting
11582        /// options computed during initialization of this RelativeTimeFormat object.
11583        ///
11584        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11585        #[cfg(not(js_sys_unstable_apis))]
11586        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11587        pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
11588
11589        /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11590        /// object with properties reflecting the locale and relative time formatting
11591        /// options computed during initialization of this RelativeTimeFormat object.
11592        ///
11593        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11594        #[cfg(js_sys_unstable_apis)]
11595        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11596        pub fn resolved_options(this: &RelativeTimeFormat) -> ResolvedRelativeTimeFormatOptions;
11597
11598        /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11599        /// containing those of the provided locales that are supported in date and time
11600        /// formatting without having to fall back to the runtime's default locale.
11601        ///
11602        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11603        #[cfg(not(js_sys_unstable_apis))]
11604        #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11605        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11606
11607        /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11608        /// containing those of the provided locales that are supported in date and time
11609        /// formatting without having to fall back to the runtime's default locale.
11610        ///
11611        /// Throws a `RangeError` if locales contain invalid values.
11612        ///
11613        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11614        #[cfg(js_sys_unstable_apis)]
11615        #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11616        pub fn supported_locales_of(
11617            locales: &[JsString],
11618            options: &LocaleMatcherOptions,
11619        ) -> Result<Array<JsString>, JsValue>;
11620    }
11621
11622    #[cfg(not(js_sys_unstable_apis))]
11623    impl Default for RelativeTimeFormat {
11624        fn default() -> Self {
11625            Self::new(
11626                &JsValue::UNDEFINED.unchecked_into(),
11627                &JsValue::UNDEFINED.unchecked_into(),
11628            )
11629        }
11630    }
11631
11632    #[cfg(js_sys_unstable_apis)]
11633    impl Default for RelativeTimeFormat {
11634        fn default() -> Self {
11635            Self::new(&[]).unwrap()
11636        }
11637    }
11638
11639    // Intl.ListFormatOptions
11640    #[wasm_bindgen]
11641    extern "C" {
11642        /// Options for `Intl.ListFormat` constructor.
11643        ///
11644        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#options)
11645        #[wasm_bindgen(extends = Object)]
11646        #[derive(Clone, Debug)]
11647        pub type ListFormatOptions;
11648
11649        #[wasm_bindgen(method, getter = localeMatcher)]
11650        pub fn get_locale_matcher(this: &ListFormatOptions) -> Option<LocaleMatcher>;
11651        #[wasm_bindgen(method, setter = localeMatcher)]
11652        pub fn set_locale_matcher(this: &ListFormatOptions, value: LocaleMatcher);
11653
11654        #[wasm_bindgen(method, getter = type)]
11655        pub fn get_type(this: &ListFormatOptions) -> Option<ListFormatType>;
11656        #[wasm_bindgen(method, setter = type)]
11657        pub fn set_type(this: &ListFormatOptions, value: ListFormatType);
11658
11659        #[wasm_bindgen(method, getter = style)]
11660        pub fn get_style(this: &ListFormatOptions) -> Option<ListFormatStyle>;
11661        #[wasm_bindgen(method, setter = style)]
11662        pub fn set_style(this: &ListFormatOptions, value: ListFormatStyle);
11663    }
11664
11665    impl ListFormatOptions {
11666        pub fn new() -> ListFormatOptions {
11667            JsCast::unchecked_into(Object::new())
11668        }
11669    }
11670
11671    impl Default for ListFormatOptions {
11672        fn default() -> Self {
11673            ListFormatOptions::new()
11674        }
11675    }
11676
11677    // Intl.ResolvedListFormatOptions
11678    #[wasm_bindgen]
11679    extern "C" {
11680        /// Resolved options returned by `Intl.ListFormat.prototype.resolvedOptions()`.
11681        ///
11682        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11683        #[wasm_bindgen(extends = ListFormatOptions)]
11684        #[derive(Clone, Debug)]
11685        pub type ResolvedListFormatOptions;
11686
11687        /// The resolved locale string.
11688        #[wasm_bindgen(method, getter = locale)]
11689        pub fn get_locale(this: &ResolvedListFormatOptions) -> JsString;
11690    }
11691
11692    // Intl.ListFormatPart
11693    #[wasm_bindgen]
11694    extern "C" {
11695        /// A part of the formatted list returned by `formatToParts()`.
11696        ///
11697        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11698        #[wasm_bindgen(extends = Object)]
11699        #[derive(Clone, Debug)]
11700        pub type ListFormatPart;
11701
11702        /// The type of the part ("element" or "literal").
11703        #[wasm_bindgen(method, getter = type)]
11704        pub fn type_(this: &ListFormatPart) -> ListFormatPartType;
11705
11706        /// The value of the part.
11707        #[wasm_bindgen(method, getter)]
11708        pub fn value(this: &ListFormatPart) -> JsString;
11709    }
11710
11711    // Intl.ListFormat
11712    #[wasm_bindgen]
11713    extern "C" {
11714        /// The `Intl.ListFormat` object enables language-sensitive list formatting.
11715        ///
11716        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat)
11717        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.ListFormat")]
11718        #[derive(Clone, Debug)]
11719        pub type ListFormat;
11720
11721        /// Creates a new `Intl.ListFormat` object.
11722        ///
11723        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
11724        #[cfg(not(js_sys_unstable_apis))]
11725        #[wasm_bindgen(constructor, js_namespace = Intl)]
11726        pub fn new(locales: &Array, options: &Object) -> ListFormat;
11727
11728        /// Creates a new `Intl.ListFormat` object.
11729        ///
11730        /// Throws a `RangeError` if locales or options contain invalid values.
11731        ///
11732        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
11733        #[cfg(js_sys_unstable_apis)]
11734        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11735        pub fn new(
11736            locales: &[JsString],
11737            options: &ListFormatOptions,
11738        ) -> Result<ListFormat, JsValue>;
11739
11740        /// Formats a list of strings according to the locale and options.
11741        ///
11742        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
11743        #[cfg(not(js_sys_unstable_apis))]
11744        #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
11745        pub fn format(this: &ListFormat, list: &Array) -> JsString;
11746
11747        /// Formats a list of strings according to the locale and options.
11748        ///
11749        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
11750        #[cfg(js_sys_unstable_apis)]
11751        #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
11752        pub fn format(this: &ListFormat, list: &[JsString]) -> JsString;
11753
11754        /// Returns an array of objects representing the list in parts.
11755        ///
11756        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11757        #[cfg(not(js_sys_unstable_apis))]
11758        #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
11759        pub fn format_to_parts(this: &ListFormat, list: &Array) -> Array;
11760
11761        /// Returns an array of objects representing the list in parts.
11762        ///
11763        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11764        #[cfg(js_sys_unstable_apis)]
11765        #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
11766        pub fn format_to_parts(this: &ListFormat, list: &[JsString]) -> Array<ListFormatPart>;
11767
11768        /// Returns an object with properties reflecting the options used.
11769        ///
11770        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11771        #[cfg(not(js_sys_unstable_apis))]
11772        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11773        pub fn resolved_options(this: &ListFormat) -> Object;
11774
11775        /// Returns an object with properties reflecting the options used.
11776        ///
11777        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11778        #[cfg(js_sys_unstable_apis)]
11779        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11780        pub fn resolved_options(this: &ListFormat) -> ResolvedListFormatOptions;
11781
11782        /// Returns an array of supported locales.
11783        ///
11784        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
11785        #[cfg(not(js_sys_unstable_apis))]
11786        #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11787        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11788
11789        /// Returns an array of supported locales.
11790        ///
11791        /// Throws a `RangeError` if locales contain invalid values.
11792        ///
11793        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
11794        #[cfg(js_sys_unstable_apis)]
11795        #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11796        pub fn supported_locales_of(
11797            locales: &[JsString],
11798            options: &LocaleMatcherOptions,
11799        ) -> Result<Array<JsString>, JsValue>;
11800    }
11801
11802    #[cfg(not(js_sys_unstable_apis))]
11803    impl Default for ListFormat {
11804        fn default() -> Self {
11805            Self::new(
11806                &JsValue::UNDEFINED.unchecked_into(),
11807                &JsValue::UNDEFINED.unchecked_into(),
11808            )
11809        }
11810    }
11811
11812    #[cfg(js_sys_unstable_apis)]
11813    impl Default for ListFormat {
11814        fn default() -> Self {
11815            Self::new(&[], &Default::default()).unwrap()
11816        }
11817    }
11818
11819    // Intl.SegmenterOptions
11820    #[wasm_bindgen]
11821    extern "C" {
11822        /// Options for `Intl.Segmenter` constructor.
11823        ///
11824        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#options)
11825        #[wasm_bindgen(extends = Object)]
11826        #[derive(Clone, Debug)]
11827        pub type SegmenterOptions;
11828
11829        #[wasm_bindgen(method, getter = localeMatcher)]
11830        pub fn get_locale_matcher(this: &SegmenterOptions) -> Option<LocaleMatcher>;
11831        #[wasm_bindgen(method, setter = localeMatcher)]
11832        pub fn set_locale_matcher(this: &SegmenterOptions, value: LocaleMatcher);
11833
11834        #[wasm_bindgen(method, getter = granularity)]
11835        pub fn get_granularity(this: &SegmenterOptions) -> Option<SegmenterGranularity>;
11836        #[wasm_bindgen(method, setter = granularity)]
11837        pub fn set_granularity(this: &SegmenterOptions, value: SegmenterGranularity);
11838    }
11839
11840    impl SegmenterOptions {
11841        pub fn new() -> SegmenterOptions {
11842            JsCast::unchecked_into(Object::new())
11843        }
11844    }
11845
11846    impl Default for SegmenterOptions {
11847        fn default() -> Self {
11848            SegmenterOptions::new()
11849        }
11850    }
11851
11852    // Intl.ResolvedSegmenterOptions
11853    #[wasm_bindgen]
11854    extern "C" {
11855        /// Resolved options returned by `Intl.Segmenter.prototype.resolvedOptions()`.
11856        ///
11857        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11858        #[wasm_bindgen(extends = SegmenterOptions)]
11859        #[derive(Clone, Debug)]
11860        pub type ResolvedSegmenterOptions;
11861
11862        /// The resolved locale string.
11863        #[wasm_bindgen(method, getter = locale)]
11864        pub fn get_locale(this: &ResolvedSegmenterOptions) -> JsString;
11865    }
11866
11867    // Intl.SegmentData
11868    #[wasm_bindgen]
11869    extern "C" {
11870        /// Data about a segment returned by the Segments iterator.
11871        ///
11872        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments#segment_data)
11873        #[wasm_bindgen(extends = Object)]
11874        #[derive(Clone, Debug)]
11875        pub type SegmentData;
11876
11877        /// The segment string.
11878        #[wasm_bindgen(method, getter)]
11879        pub fn segment(this: &SegmentData) -> JsString;
11880
11881        /// The index of the segment in the original string.
11882        #[wasm_bindgen(method, getter)]
11883        pub fn index(this: &SegmentData) -> u32;
11884
11885        /// The original input string.
11886        #[wasm_bindgen(method, getter)]
11887        pub fn input(this: &SegmentData) -> JsString;
11888
11889        /// Whether the segment is word-like (only for word granularity).
11890        #[wasm_bindgen(method, getter = isWordLike)]
11891        pub fn is_word_like(this: &SegmentData) -> Option<bool>;
11892    }
11893
11894    // Intl.Segments
11895    #[wasm_bindgen]
11896    extern "C" {
11897        /// The Segments object is an iterable collection of segments of a string.
11898        ///
11899        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments)
11900        #[wasm_bindgen(extends = Object)]
11901        #[derive(Clone, Debug)]
11902        pub type Segments;
11903
11904        /// Returns segment data for the segment containing the character at the given index.
11905        ///
11906        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments/containing)
11907        #[wasm_bindgen(method)]
11908        pub fn containing(this: &Segments, index: u32) -> Option<SegmentData>;
11909    }
11910
11911    // Intl.Segmenter
11912    #[wasm_bindgen]
11913    extern "C" {
11914        /// The `Intl.Segmenter` object enables locale-sensitive text segmentation.
11915        ///
11916        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter)
11917        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Segmenter")]
11918        #[derive(Clone, Debug)]
11919        pub type Segmenter;
11920
11921        /// Creates a new `Intl.Segmenter` object.
11922        ///
11923        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
11924        #[cfg(not(js_sys_unstable_apis))]
11925        #[wasm_bindgen(constructor, js_namespace = Intl)]
11926        pub fn new(locales: &Array, options: &Object) -> Segmenter;
11927
11928        /// Creates a new `Intl.Segmenter` object.
11929        ///
11930        /// Throws a `RangeError` if locales or options contain invalid values.
11931        ///
11932        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
11933        #[cfg(js_sys_unstable_apis)]
11934        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11935        pub fn new(locales: &[JsString], options: &SegmenterOptions) -> Result<Segmenter, JsValue>;
11936
11937        /// Returns a Segments object containing the segments of the input string.
11938        ///
11939        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment)
11940        #[wasm_bindgen(method, js_class = "Intl.Segmenter")]
11941        pub fn segment(this: &Segmenter, input: &str) -> Segments;
11942
11943        /// Returns an object with properties reflecting the options used.
11944        ///
11945        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11946        #[cfg(not(js_sys_unstable_apis))]
11947        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11948        pub fn resolved_options(this: &Segmenter) -> Object;
11949
11950        /// Returns an object with properties reflecting the options used.
11951        ///
11952        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11953        #[cfg(js_sys_unstable_apis)]
11954        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11955        pub fn resolved_options(this: &Segmenter) -> ResolvedSegmenterOptions;
11956
11957        /// Returns an array of supported locales.
11958        ///
11959        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
11960        #[cfg(not(js_sys_unstable_apis))]
11961        #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf)]
11962        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11963
11964        /// Returns an array of supported locales.
11965        ///
11966        /// Throws a `RangeError` if locales contain invalid values.
11967        ///
11968        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
11969        #[cfg(js_sys_unstable_apis)]
11970        #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11971        pub fn supported_locales_of(
11972            locales: &[JsString],
11973            options: &LocaleMatcherOptions,
11974        ) -> Result<Array<JsString>, JsValue>;
11975    }
11976
11977    #[cfg(not(js_sys_unstable_apis))]
11978    impl Default for Segmenter {
11979        fn default() -> Self {
11980            Self::new(
11981                &JsValue::UNDEFINED.unchecked_into(),
11982                &JsValue::UNDEFINED.unchecked_into(),
11983            )
11984        }
11985    }
11986
11987    #[cfg(js_sys_unstable_apis)]
11988    impl Default for Segmenter {
11989        fn default() -> Self {
11990            Self::new(&[], &Default::default()).unwrap()
11991        }
11992    }
11993
11994    // Intl.DisplayNamesOptions
11995    #[wasm_bindgen]
11996    extern "C" {
11997        /// Options for `Intl.DisplayNames` constructor.
11998        ///
11999        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options)
12000        #[wasm_bindgen(extends = Object)]
12001        #[derive(Clone, Debug)]
12002        pub type DisplayNamesOptions;
12003
12004        #[wasm_bindgen(method, getter = localeMatcher)]
12005        pub fn get_locale_matcher(this: &DisplayNamesOptions) -> Option<LocaleMatcher>;
12006        #[wasm_bindgen(method, setter = localeMatcher)]
12007        pub fn set_locale_matcher(this: &DisplayNamesOptions, value: LocaleMatcher);
12008
12009        #[wasm_bindgen(method, getter = type)]
12010        pub fn get_type(this: &DisplayNamesOptions) -> Option<DisplayNamesType>;
12011        #[wasm_bindgen(method, setter = type)]
12012        pub fn set_type(this: &DisplayNamesOptions, value: DisplayNamesType);
12013
12014        #[wasm_bindgen(method, getter = style)]
12015        pub fn get_style(this: &DisplayNamesOptions) -> Option<DisplayNamesStyle>;
12016        #[wasm_bindgen(method, setter = style)]
12017        pub fn set_style(this: &DisplayNamesOptions, value: DisplayNamesStyle);
12018
12019        #[wasm_bindgen(method, getter = fallback)]
12020        pub fn get_fallback(this: &DisplayNamesOptions) -> Option<DisplayNamesFallback>;
12021        #[wasm_bindgen(method, setter = fallback)]
12022        pub fn set_fallback(this: &DisplayNamesOptions, value: DisplayNamesFallback);
12023
12024        #[wasm_bindgen(method, getter = languageDisplay)]
12025        pub fn get_language_display(
12026            this: &DisplayNamesOptions,
12027        ) -> Option<DisplayNamesLanguageDisplay>;
12028        #[wasm_bindgen(method, setter = languageDisplay)]
12029        pub fn set_language_display(this: &DisplayNamesOptions, value: DisplayNamesLanguageDisplay);
12030    }
12031
12032    impl DisplayNamesOptions {
12033        pub fn new() -> DisplayNamesOptions {
12034            JsCast::unchecked_into(Object::new())
12035        }
12036    }
12037
12038    impl Default for DisplayNamesOptions {
12039        fn default() -> Self {
12040            DisplayNamesOptions::new()
12041        }
12042    }
12043
12044    // Intl.ResolvedDisplayNamesOptions
12045    #[wasm_bindgen]
12046    extern "C" {
12047        /// Resolved options returned by `Intl.DisplayNames.prototype.resolvedOptions()`.
12048        ///
12049        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12050        #[wasm_bindgen(extends = DisplayNamesOptions)]
12051        #[derive(Clone, Debug)]
12052        pub type ResolvedDisplayNamesOptions;
12053
12054        /// The resolved locale string.
12055        #[wasm_bindgen(method, getter = locale)]
12056        pub fn get_locale(this: &ResolvedDisplayNamesOptions) -> JsString;
12057    }
12058
12059    // Intl.DisplayNames
12060    #[wasm_bindgen]
12061    extern "C" {
12062        /// The `Intl.DisplayNames` object enables the consistent translation of
12063        /// language, region, and script display names.
12064        ///
12065        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
12066        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DisplayNames")]
12067        #[derive(Clone, Debug)]
12068        pub type DisplayNames;
12069
12070        /// Creates a new `Intl.DisplayNames` object.
12071        ///
12072        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12073        #[cfg(not(js_sys_unstable_apis))]
12074        #[wasm_bindgen(constructor, js_namespace = Intl)]
12075        pub fn new(locales: &Array, options: &Object) -> DisplayNames;
12076
12077        /// Creates a new `Intl.DisplayNames` object.
12078        ///
12079        /// Throws a `RangeError` if locales or options contain invalid values.
12080        ///
12081        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12082        #[cfg(js_sys_unstable_apis)]
12083        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12084        pub fn new(
12085            locales: &[JsString],
12086            options: &DisplayNamesOptions,
12087        ) -> Result<DisplayNames, JsValue>;
12088
12089        /// Returns the display name for the given code.
12090        ///
12091        /// Returns `undefined` if fallback is "none" and no name is available.
12092        ///
12093        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of)
12094        #[wasm_bindgen(method, js_class = "Intl.DisplayNames")]
12095        pub fn of(this: &DisplayNames, code: &str) -> Option<JsString>;
12096
12097        /// Returns an object with properties reflecting the options used.
12098        ///
12099        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12100        #[cfg(not(js_sys_unstable_apis))]
12101        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12102        pub fn resolved_options(this: &DisplayNames) -> Object;
12103
12104        /// Returns an object with properties reflecting the options used.
12105        ///
12106        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12107        #[cfg(js_sys_unstable_apis)]
12108        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12109        pub fn resolved_options(this: &DisplayNames) -> ResolvedDisplayNamesOptions;
12110
12111        /// Returns an array of supported locales.
12112        ///
12113        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12114        #[cfg(not(js_sys_unstable_apis))]
12115        #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf)]
12116        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12117
12118        /// Returns an array of supported locales.
12119        ///
12120        /// Throws a `RangeError` if locales contain invalid values.
12121        ///
12122        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12123        #[cfg(js_sys_unstable_apis)]
12124        #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12125        pub fn supported_locales_of(
12126            locales: &[JsString],
12127            options: &LocaleMatcherOptions,
12128        ) -> Result<Array<JsString>, JsValue>;
12129    }
12130
12131    // Intl.Locale
12132    #[wasm_bindgen]
12133    extern "C" {
12134        /// The `Intl.Locale` object is a standard built-in property of the Intl object
12135        /// that represents a Unicode locale identifier.
12136        ///
12137        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
12138        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Locale")]
12139        #[derive(Clone, Debug)]
12140        pub type Locale;
12141
12142        /// Creates a new `Intl.Locale` object.
12143        ///
12144        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12145        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12146        pub fn new(tag: &str) -> Result<Locale, JsValue>;
12147
12148        /// Creates a new `Intl.Locale` object with options.
12149        ///
12150        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12151        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12152        pub fn new_with_options(tag: &str, options: &Object) -> Result<Locale, JsValue>;
12153
12154        /// The base name of the locale (language + region + script).
12155        ///
12156        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName)
12157        #[wasm_bindgen(method, getter = baseName)]
12158        pub fn base_name(this: &Locale) -> JsString;
12159
12160        /// The calendar type for the locale.
12161        ///
12162        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar)
12163        #[wasm_bindgen(method, getter)]
12164        pub fn calendar(this: &Locale) -> Option<JsString>;
12165
12166        /// The case first sorting option.
12167        ///
12168        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst)
12169        #[wasm_bindgen(method, getter = caseFirst)]
12170        pub fn case_first(this: &Locale) -> Option<JsString>;
12171
12172        /// The collation type for the locale.
12173        ///
12174        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation)
12175        #[wasm_bindgen(method, getter)]
12176        pub fn collation(this: &Locale) -> Option<JsString>;
12177
12178        /// The hour cycle for the locale.
12179        ///
12180        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle)
12181        #[wasm_bindgen(method, getter = hourCycle)]
12182        pub fn hour_cycle(this: &Locale) -> Option<JsString>;
12183
12184        /// The language code for the locale.
12185        ///
12186        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language)
12187        #[wasm_bindgen(method, getter)]
12188        pub fn language(this: &Locale) -> JsString;
12189
12190        /// The numbering system for the locale.
12191        ///
12192        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem)
12193        #[wasm_bindgen(method, getter = numberingSystem)]
12194        pub fn numbering_system(this: &Locale) -> Option<JsString>;
12195
12196        /// Whether the locale uses numeric collation.
12197        ///
12198        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric)
12199        #[wasm_bindgen(method, getter)]
12200        pub fn numeric(this: &Locale) -> bool;
12201
12202        /// The region code for the locale.
12203        ///
12204        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/region)
12205        #[wasm_bindgen(method, getter)]
12206        pub fn region(this: &Locale) -> Option<JsString>;
12207
12208        /// The script code for the locale.
12209        ///
12210        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/script)
12211        #[wasm_bindgen(method, getter)]
12212        pub fn script(this: &Locale) -> Option<JsString>;
12213
12214        /// Returns an array of available calendars for the locale.
12215        ///
12216        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars)
12217        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCalendars)]
12218        pub fn get_calendars(this: &Locale) -> Array<JsString>;
12219
12220        /// Returns an array of available collations for the locale.
12221        ///
12222        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations)
12223        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCollations)]
12224        pub fn get_collations(this: &Locale) -> Array<JsString>;
12225
12226        /// Returns an array of available hour cycles for the locale.
12227        ///
12228        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles)
12229        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getHourCycles)]
12230        pub fn get_hour_cycles(this: &Locale) -> Array<JsString>;
12231
12232        /// Returns an array of available numbering systems for the locale.
12233        ///
12234        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems)
12235        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getNumberingSystems)]
12236        pub fn get_numbering_systems(this: &Locale) -> Array<JsString>;
12237
12238        /// Returns an array of available time zones for the locale's region.
12239        ///
12240        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones)
12241        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTimeZones)]
12242        pub fn get_time_zones(this: &Locale) -> Option<Array<JsString>>;
12243
12244        /// Returns week information for the locale.
12245        ///
12246        /// May not be available in all environments.
12247        ///
12248        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12249        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getWeekInfo, catch)]
12250        pub fn get_week_info(this: &Locale) -> Result<WeekInfo, JsValue>;
12251
12252        /// Returns text layout information for the locale.
12253        ///
12254        /// May not be available in all environments.
12255        ///
12256        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12257        #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTextInfo, catch)]
12258        pub fn get_text_info(this: &Locale) -> Result<TextInfo, JsValue>;
12259
12260        /// Returns a new Locale with the specified calendar.
12261        ///
12262        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize)
12263        #[wasm_bindgen(method, js_class = "Intl.Locale")]
12264        pub fn maximize(this: &Locale) -> Locale;
12265
12266        /// Returns a new Locale with the minimal subtags.
12267        ///
12268        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize)
12269        #[wasm_bindgen(method, js_class = "Intl.Locale")]
12270        pub fn minimize(this: &Locale) -> Locale;
12271    }
12272
12273    // Intl.Locale WeekInfo
12274    #[wasm_bindgen]
12275    extern "C" {
12276        /// Week information for a locale.
12277        ///
12278        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12279        #[wasm_bindgen(extends = Object)]
12280        #[derive(Clone, Debug)]
12281        pub type WeekInfo;
12282
12283        /// The first day of the week (1 = Monday, 7 = Sunday).
12284        #[wasm_bindgen(method, getter = firstDay)]
12285        pub fn first_day(this: &WeekInfo) -> u8;
12286
12287        /// Array of weekend days.
12288        #[wasm_bindgen(method, getter)]
12289        pub fn weekend(this: &WeekInfo) -> Array<Number>;
12290
12291        /// Minimal days in the first week of the year.
12292        #[wasm_bindgen(method, getter = minimalDays)]
12293        pub fn minimal_days(this: &WeekInfo) -> u8;
12294    }
12295
12296    // Intl.Locale TextInfo
12297    #[wasm_bindgen]
12298    extern "C" {
12299        /// Text layout information for a locale.
12300        ///
12301        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12302        #[wasm_bindgen(extends = Object)]
12303        #[derive(Clone, Debug)]
12304        pub type TextInfo;
12305
12306        /// The text direction ("ltr" or "rtl").
12307        #[wasm_bindgen(method, getter)]
12308        pub fn direction(this: &TextInfo) -> JsString;
12309    }
12310
12311    // Intl.DurationFormat enums
12312
12313    /// The style for duration formatting.
12314    ///
12315    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style)
12316    #[wasm_bindgen]
12317    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12318    pub enum DurationFormatStyle {
12319        Long = "long",
12320        Short = "short",
12321        Narrow = "narrow",
12322        Digital = "digital",
12323    }
12324
12325    /// The display style for individual duration units.
12326    ///
12327    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#years)
12328    #[wasm_bindgen]
12329    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12330    pub enum DurationUnitStyle {
12331        Long = "long",
12332        Short = "short",
12333        Narrow = "narrow",
12334    }
12335
12336    /// The display style for time duration units (hours, minutes, seconds).
12337    ///
12338    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#hours)
12339    #[wasm_bindgen]
12340    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12341    pub enum DurationTimeUnitStyle {
12342        Long = "long",
12343        Short = "short",
12344        Narrow = "narrow",
12345        Numeric = "numeric",
12346        #[wasm_bindgen(js_name = "2-digit")]
12347        TwoDigit = "2-digit",
12348    }
12349
12350    /// The display option for duration units.
12351    ///
12352    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#yearsdisplay)
12353    #[wasm_bindgen]
12354    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12355    pub enum DurationUnitDisplay {
12356        Auto = "auto",
12357        Always = "always",
12358    }
12359
12360    /// The type of a duration format part.
12361    ///
12362    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts#type)
12363    #[wasm_bindgen]
12364    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12365    pub enum DurationFormatPartType {
12366        Years = "years",
12367        Months = "months",
12368        Weeks = "weeks",
12369        Days = "days",
12370        Hours = "hours",
12371        Minutes = "minutes",
12372        Seconds = "seconds",
12373        Milliseconds = "milliseconds",
12374        Microseconds = "microseconds",
12375        Nanoseconds = "nanoseconds",
12376        Literal = "literal",
12377        Integer = "integer",
12378        Decimal = "decimal",
12379        Fraction = "fraction",
12380    }
12381
12382    // Intl.DurationFormatOptions
12383    #[wasm_bindgen]
12384    extern "C" {
12385        /// Options for `Intl.DurationFormat` constructor.
12386        ///
12387        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#options)
12388        #[wasm_bindgen(extends = Object)]
12389        #[derive(Clone, Debug)]
12390        pub type DurationFormatOptions;
12391
12392        #[wasm_bindgen(method, getter = localeMatcher)]
12393        pub fn get_locale_matcher(this: &DurationFormatOptions) -> Option<LocaleMatcher>;
12394        #[wasm_bindgen(method, setter = localeMatcher)]
12395        pub fn set_locale_matcher(this: &DurationFormatOptions, value: LocaleMatcher);
12396
12397        #[wasm_bindgen(method, getter = style)]
12398        pub fn get_style(this: &DurationFormatOptions) -> Option<DurationFormatStyle>;
12399        #[wasm_bindgen(method, setter = style)]
12400        pub fn set_style(this: &DurationFormatOptions, value: DurationFormatStyle);
12401
12402        #[wasm_bindgen(method, getter = years)]
12403        pub fn get_years(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12404        #[wasm_bindgen(method, setter = years)]
12405        pub fn set_years(this: &DurationFormatOptions, value: DurationUnitStyle);
12406
12407        #[wasm_bindgen(method, getter = yearsDisplay)]
12408        pub fn get_years_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12409        #[wasm_bindgen(method, setter = yearsDisplay)]
12410        pub fn set_years_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12411
12412        #[wasm_bindgen(method, getter = months)]
12413        pub fn get_months(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12414        #[wasm_bindgen(method, setter = months)]
12415        pub fn set_months(this: &DurationFormatOptions, value: DurationUnitStyle);
12416
12417        #[wasm_bindgen(method, getter = monthsDisplay)]
12418        pub fn get_months_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12419        #[wasm_bindgen(method, setter = monthsDisplay)]
12420        pub fn set_months_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12421
12422        #[wasm_bindgen(method, getter = weeks)]
12423        pub fn get_weeks(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12424        #[wasm_bindgen(method, setter = weeks)]
12425        pub fn set_weeks(this: &DurationFormatOptions, value: DurationUnitStyle);
12426
12427        #[wasm_bindgen(method, getter = weeksDisplay)]
12428        pub fn get_weeks_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12429        #[wasm_bindgen(method, setter = weeksDisplay)]
12430        pub fn set_weeks_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12431
12432        #[wasm_bindgen(method, getter = days)]
12433        pub fn get_days(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12434        #[wasm_bindgen(method, setter = days)]
12435        pub fn set_days(this: &DurationFormatOptions, value: DurationUnitStyle);
12436
12437        #[wasm_bindgen(method, getter = daysDisplay)]
12438        pub fn get_days_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12439        #[wasm_bindgen(method, setter = daysDisplay)]
12440        pub fn set_days_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12441
12442        #[wasm_bindgen(method, getter = hours)]
12443        pub fn get_hours(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12444        #[wasm_bindgen(method, setter = hours)]
12445        pub fn set_hours(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12446
12447        #[wasm_bindgen(method, getter = hoursDisplay)]
12448        pub fn get_hours_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12449        #[wasm_bindgen(method, setter = hoursDisplay)]
12450        pub fn set_hours_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12451
12452        #[wasm_bindgen(method, getter = minutes)]
12453        pub fn get_minutes(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12454        #[wasm_bindgen(method, setter = minutes)]
12455        pub fn set_minutes(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12456
12457        #[wasm_bindgen(method, getter = minutesDisplay)]
12458        pub fn get_minutes_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12459        #[wasm_bindgen(method, setter = minutesDisplay)]
12460        pub fn set_minutes_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12461
12462        #[wasm_bindgen(method, getter = seconds)]
12463        pub fn get_seconds(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12464        #[wasm_bindgen(method, setter = seconds)]
12465        pub fn set_seconds(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12466
12467        #[wasm_bindgen(method, getter = secondsDisplay)]
12468        pub fn get_seconds_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12469        #[wasm_bindgen(method, setter = secondsDisplay)]
12470        pub fn set_seconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12471
12472        #[wasm_bindgen(method, getter = milliseconds)]
12473        pub fn get_milliseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12474        #[wasm_bindgen(method, setter = milliseconds)]
12475        pub fn set_milliseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12476
12477        #[wasm_bindgen(method, getter = millisecondsDisplay)]
12478        pub fn get_milliseconds_display(
12479            this: &DurationFormatOptions,
12480        ) -> Option<DurationUnitDisplay>;
12481        #[wasm_bindgen(method, setter = millisecondsDisplay)]
12482        pub fn set_milliseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12483
12484        #[wasm_bindgen(method, getter = microseconds)]
12485        pub fn get_microseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12486        #[wasm_bindgen(method, setter = microseconds)]
12487        pub fn set_microseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12488
12489        #[wasm_bindgen(method, getter = microsecondsDisplay)]
12490        pub fn get_microseconds_display(
12491            this: &DurationFormatOptions,
12492        ) -> Option<DurationUnitDisplay>;
12493        #[wasm_bindgen(method, setter = microsecondsDisplay)]
12494        pub fn set_microseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12495
12496        #[wasm_bindgen(method, getter = nanoseconds)]
12497        pub fn get_nanoseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12498        #[wasm_bindgen(method, setter = nanoseconds)]
12499        pub fn set_nanoseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12500
12501        #[wasm_bindgen(method, getter = nanosecondsDisplay)]
12502        pub fn get_nanoseconds_display(this: &DurationFormatOptions)
12503            -> Option<DurationUnitDisplay>;
12504        #[wasm_bindgen(method, setter = nanosecondsDisplay)]
12505        pub fn set_nanoseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12506
12507        #[wasm_bindgen(method, getter = fractionalDigits)]
12508        pub fn get_fractional_digits(this: &DurationFormatOptions) -> Option<u8>;
12509        #[wasm_bindgen(method, setter = fractionalDigits)]
12510        pub fn set_fractional_digits(this: &DurationFormatOptions, value: u8);
12511    }
12512
12513    impl DurationFormatOptions {
12514        pub fn new() -> DurationFormatOptions {
12515            JsCast::unchecked_into(Object::new())
12516        }
12517    }
12518
12519    impl Default for DurationFormatOptions {
12520        fn default() -> Self {
12521            DurationFormatOptions::new()
12522        }
12523    }
12524
12525    // Intl.ResolvedDurationFormatOptions
12526    #[wasm_bindgen]
12527    extern "C" {
12528        /// Resolved options returned by `Intl.DurationFormat.prototype.resolvedOptions()`.
12529        ///
12530        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12531        #[wasm_bindgen(extends = DurationFormatOptions)]
12532        #[derive(Clone, Debug)]
12533        pub type ResolvedDurationFormatOptions;
12534
12535        /// The resolved locale string.
12536        #[wasm_bindgen(method, getter = locale)]
12537        pub fn get_locale(this: &ResolvedDurationFormatOptions) -> JsString;
12538
12539        /// The resolved numbering system.
12540        #[wasm_bindgen(method, getter = numberingSystem)]
12541        pub fn get_numbering_system(this: &ResolvedDurationFormatOptions) -> JsString;
12542    }
12543
12544    // Intl.Duration (input object for DurationFormat)
12545    #[wasm_bindgen]
12546    extern "C" {
12547        /// A duration object used as input to `Intl.DurationFormat.format()`.
12548        ///
12549        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration)
12550        #[wasm_bindgen(extends = Object)]
12551        #[derive(Clone, Debug)]
12552        pub type Duration;
12553
12554        #[wasm_bindgen(method, getter)]
12555        pub fn years(this: &Duration) -> Option<f64>;
12556        #[wasm_bindgen(method, setter)]
12557        pub fn set_years(this: &Duration, value: f64);
12558
12559        #[wasm_bindgen(method, getter)]
12560        pub fn months(this: &Duration) -> Option<f64>;
12561        #[wasm_bindgen(method, setter)]
12562        pub fn set_months(this: &Duration, value: f64);
12563
12564        #[wasm_bindgen(method, getter)]
12565        pub fn weeks(this: &Duration) -> Option<f64>;
12566        #[wasm_bindgen(method, setter)]
12567        pub fn set_weeks(this: &Duration, value: f64);
12568
12569        #[wasm_bindgen(method, getter)]
12570        pub fn days(this: &Duration) -> Option<f64>;
12571        #[wasm_bindgen(method, setter)]
12572        pub fn set_days(this: &Duration, value: f64);
12573
12574        #[wasm_bindgen(method, getter)]
12575        pub fn hours(this: &Duration) -> Option<f64>;
12576        #[wasm_bindgen(method, setter)]
12577        pub fn set_hours(this: &Duration, value: f64);
12578
12579        #[wasm_bindgen(method, getter)]
12580        pub fn minutes(this: &Duration) -> Option<f64>;
12581        #[wasm_bindgen(method, setter)]
12582        pub fn set_minutes(this: &Duration, value: f64);
12583
12584        #[wasm_bindgen(method, getter)]
12585        pub fn seconds(this: &Duration) -> Option<f64>;
12586        #[wasm_bindgen(method, setter)]
12587        pub fn set_seconds(this: &Duration, value: f64);
12588
12589        #[wasm_bindgen(method, getter)]
12590        pub fn milliseconds(this: &Duration) -> Option<f64>;
12591        #[wasm_bindgen(method, setter)]
12592        pub fn set_milliseconds(this: &Duration, value: f64);
12593
12594        #[wasm_bindgen(method, getter)]
12595        pub fn microseconds(this: &Duration) -> Option<f64>;
12596        #[wasm_bindgen(method, setter)]
12597        pub fn set_microseconds(this: &Duration, value: f64);
12598
12599        #[wasm_bindgen(method, getter)]
12600        pub fn nanoseconds(this: &Duration) -> Option<f64>;
12601        #[wasm_bindgen(method, setter)]
12602        pub fn set_nanoseconds(this: &Duration, value: f64);
12603    }
12604
12605    impl Duration {
12606        pub fn new() -> Duration {
12607            JsCast::unchecked_into(Object::new())
12608        }
12609    }
12610
12611    impl Default for Duration {
12612        fn default() -> Self {
12613            Duration::new()
12614        }
12615    }
12616
12617    // Intl.DurationFormatPart
12618    #[wasm_bindgen]
12619    extern "C" {
12620        /// A part of the formatted duration returned by `formatToParts()`.
12621        ///
12622        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12623        #[wasm_bindgen(extends = Object)]
12624        #[derive(Clone, Debug)]
12625        pub type DurationFormatPart;
12626
12627        /// The type of the part.
12628        #[wasm_bindgen(method, getter = type)]
12629        pub fn type_(this: &DurationFormatPart) -> DurationFormatPartType;
12630
12631        /// The value of the part.
12632        #[wasm_bindgen(method, getter)]
12633        pub fn value(this: &DurationFormatPart) -> JsString;
12634
12635        /// The unit this part represents (if applicable).
12636        #[wasm_bindgen(method, getter)]
12637        pub fn unit(this: &DurationFormatPart) -> Option<JsString>;
12638    }
12639
12640    // Intl.DurationFormat
12641    #[wasm_bindgen]
12642    extern "C" {
12643        /// The `Intl.DurationFormat` object enables language-sensitive duration formatting.
12644        ///
12645        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat)
12646        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DurationFormat")]
12647        #[derive(Clone, Debug)]
12648        pub type DurationFormat;
12649
12650        /// Creates a new `Intl.DurationFormat` object.
12651        ///
12652        /// Throws a `RangeError` if locales or options contain invalid values.
12653        ///
12654        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat)
12655        #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12656        pub fn new(
12657            locales: &[JsString],
12658            options: &DurationFormatOptions,
12659        ) -> Result<DurationFormat, JsValue>;
12660
12661        /// Formats a duration according to the locale and formatting options.
12662        ///
12663        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format)
12664        #[wasm_bindgen(method, js_class = "Intl.DurationFormat")]
12665        pub fn format(this: &DurationFormat, duration: &Duration) -> JsString;
12666
12667        /// Returns an array of objects representing the formatted duration in parts.
12668        ///
12669        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12670        #[wasm_bindgen(method, js_class = "Intl.DurationFormat", js_name = formatToParts)]
12671        pub fn format_to_parts(
12672            this: &DurationFormat,
12673            duration: &Duration,
12674        ) -> Array<DurationFormatPart>;
12675
12676        /// Returns an object with properties reflecting the options used.
12677        ///
12678        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12679        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12680        pub fn resolved_options(this: &DurationFormat) -> ResolvedDurationFormatOptions;
12681
12682        /// Returns an array of supported locales.
12683        ///
12684        /// Throws a `RangeError` if locales contain invalid values.
12685        ///
12686        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf)
12687        #[wasm_bindgen(static_method_of = DurationFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12688        pub fn supported_locales_of(
12689            locales: &[JsString],
12690            options: &LocaleMatcherOptions,
12691        ) -> Result<Array<JsString>, JsValue>;
12692    }
12693
12694    impl Default for DurationFormat {
12695        fn default() -> Self {
12696            Self::new(&[], &Default::default()).unwrap()
12697        }
12698    }
12699}
12700
12701#[wasm_bindgen]
12702extern "C" {
12703    /// The `PromiseState` object represents the the status of the promise,
12704    /// as used in `allSettled`.
12705    ///
12706    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12707    #[must_use]
12708    #[wasm_bindgen(extends = Object, typescript_type = "any")]
12709    #[derive(Clone, Debug)]
12710    pub type PromiseState<T = JsValue>;
12711
12712    /// A string, either "fulfilled" or "rejected", indicating the eventual state of the promise.
12713    #[wasm_bindgen(method, getter = status)]
12714    pub fn get_status<T>(this: &PromiseState<T>) -> String;
12715
12716    /// Only present if status is "fulfilled". The value that the promise was fulfilled with.
12717    #[wasm_bindgen(method, getter = value)]
12718    pub fn get_value<T>(this: &PromiseState<T>) -> Option<T>;
12719
12720    /// Only present if status is "rejected". The reason that the promise was rejected with.
12721    #[wasm_bindgen(method, getter = reason)]
12722    pub fn get_reason<T>(this: &PromiseState<T>) -> Option<JsValue>;
12723}
12724
12725impl<T> PromiseState<T> {
12726    pub fn is_fulfilled(&self) -> bool {
12727        self.get_status() == "fulfilled"
12728    }
12729
12730    pub fn is_rejected(&self) -> bool {
12731        self.get_status() == "rejected"
12732    }
12733}
12734
12735// Promise
12736#[wasm_bindgen]
12737extern "C" {
12738    /// The `Promise` object represents the eventual completion (or failure) of
12739    /// an asynchronous operation, and its resulting value.
12740    ///
12741    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12742    #[must_use]
12743    #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>", no_promising)]
12744    #[derive(Clone, Debug)]
12745    pub type Promise<T = JsValue>;
12746
12747    /// Creates a new `Promise` with the provided executor `cb`
12748    ///
12749    /// The `cb` is a function that is passed with the arguments `resolve` and
12750    /// `reject`. The `cb` function is executed immediately by the `Promise`
12751    /// implementation, passing `resolve` and `reject` functions (the executor
12752    /// is called before the `Promise` constructor even returns the created
12753    /// object). The `resolve` and `reject` functions, when called, resolve or
12754    /// reject the promise, respectively. The executor normally initiates
12755    /// some asynchronous work, and then, once that completes, either calls
12756    /// the `resolve` function to resolve the promise or else rejects it if an
12757    /// error occurred.
12758    ///
12759    /// If an error is thrown in the executor function, the promise is rejected.
12760    /// The return value of the executor is ignored.
12761    ///
12762    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12763    #[cfg(not(js_sys_unstable_apis))]
12764    #[wasm_bindgen(constructor)]
12765    pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
12766
12767    /// Creates a new `Promise` with the provided executor `cb`
12768    ///
12769    /// The `cb` is a function that is passed with the arguments `resolve` and
12770    /// `reject`. The `cb` function is executed immediately by the `Promise`
12771    /// implementation, passing `resolve` and `reject` functions (the executor
12772    /// is called before the `Promise` constructor even returns the created
12773    /// object). The `resolve` and `reject` functions, when called, resolve or
12774    /// reject the promise, respectively. The executor normally initiates
12775    /// some asynchronous work, and then, once that completes, either calls
12776    /// the `resolve` function to resolve the promise or else rejects it if an
12777    /// error occurred.
12778    ///
12779    /// If an error is thrown in the executor function, the promise is rejected.
12780    /// The return value of the executor is ignored.
12781    ///
12782    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12783    #[cfg(js_sys_unstable_apis)]
12784    #[wasm_bindgen(constructor)]
12785    pub fn new<'a, T: JsGeneric>(
12786        cb: &ImmediateClosure<
12787            'a,
12788            dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>) + 'a,
12789        >,
12790    ) -> Promise<T>;
12791
12792    // Next major: deprecate
12793    /// Creates a new `Promise` with the provided executor `cb`
12794    ///
12795    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12796    #[wasm_bindgen(constructor)]
12797    pub fn new_typed<'a, T: JsGeneric>(
12798        cb: &ImmediateClosure<
12799            'a,
12800            dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>) + 'a,
12801        >,
12802    ) -> Promise<T>;
12803
12804    /// The `Promise.all(iterable)` method returns a single `Promise` that
12805    /// resolves when all of the promises in the iterable argument have resolved
12806    /// or when the iterable argument contains no promises. It rejects with the
12807    /// reason of the first promise that rejects.
12808    ///
12809    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12810    #[cfg(not(js_sys_unstable_apis))]
12811    #[wasm_bindgen(static_method_of = Promise)]
12812    pub fn all(obj: &JsValue) -> Promise;
12813
12814    /// The `Promise.all(iterable)` method returns a single `Promise` that
12815    /// resolves when all of the promises in the iterable argument have resolved
12816    /// or when the iterable argument contains no promises. It rejects with the
12817    /// reason of the first promise that rejects.
12818    ///
12819    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12820    #[cfg(js_sys_unstable_apis)]
12821    #[wasm_bindgen(static_method_of = Promise, js_name = all)]
12822    pub fn all<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
12823    where
12824        I::Item: Promising;
12825
12826    // Next major: deprecate
12827    /// The `Promise.all(iterable)` method returns a single `Promise` that
12828    /// resolves when all of the promises in the iterable argument have resolved
12829    /// or when the iterable argument contains no promises. It rejects with the
12830    /// reason of the first promise that rejects.
12831    ///
12832    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12833    #[wasm_bindgen(static_method_of = Promise, js_name = all)]
12834    pub fn all_iterable<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
12835    where
12836        I::Item: Promising;
12837
12838    /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12839    /// resolves when all of the promises in the iterable argument have either
12840    /// fulfilled or rejected or when the iterable argument contains no promises.
12841    ///
12842    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12843    #[cfg(not(js_sys_unstable_apis))]
12844    #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12845    pub fn all_settled(obj: Object) -> Promise;
12846
12847    /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12848    /// resolves when all of the promises in the iterable argument have either
12849    /// fulfilled or rejected or when the iterable argument contains no promises.
12850    ///
12851    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12852    #[cfg(js_sys_unstable_apis)]
12853    #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12854    pub fn all_settled<I: Iterable>(
12855        obj: &I,
12856    ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
12857    where
12858        I::Item: Promising;
12859
12860    // Next major: deprecate
12861    /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12862    /// resolves when all of the promises in the iterable argument have either
12863    /// fulfilled or rejected or when the iterable argument contains no promises.
12864    ///
12865    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12866    #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12867    pub fn all_settled_iterable<I: Iterable>(
12868        obj: &I,
12869    ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
12870    where
12871        I::Item: Promising;
12872
12873    /// The `Promise.any(iterable)` method returns a single `Promise` that
12874    /// resolves when any of the promises in the iterable argument have resolved
12875    /// or when the iterable argument contains no promises. It rejects with an
12876    /// `AggregateError` if all promises in the iterable rejected.
12877    ///
12878    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12879    #[cfg(not(js_sys_unstable_apis))]
12880    #[wasm_bindgen(static_method_of = Promise)]
12881    pub fn any(obj: &JsValue) -> Promise;
12882
12883    /// The `Promise.any(iterable)` method returns a single `Promise` that
12884    /// resolves when any of the promises in the iterable argument have resolved
12885    /// or when the iterable argument contains no promises. It rejects with an
12886    /// `AggregateError` if all promises in the iterable rejected.
12887    ///
12888    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12889    #[cfg(js_sys_unstable_apis)]
12890    #[wasm_bindgen(static_method_of = Promise, js_name = any)]
12891    pub fn any<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12892    where
12893        I::Item: Promising;
12894
12895    // Next major: deprecate
12896    /// The `Promise.any(iterable)` method returns a single `Promise` that
12897    /// resolves when any of the promises in the iterable argument have resolved
12898    /// or when the iterable argument contains no promises. It rejects with an
12899    /// `AggregateError` if all promises in the iterable rejected.
12900    ///
12901    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12902    #[cfg(not(js_sys_unstable_apis))]
12903    #[wasm_bindgen(static_method_of = Promise, js_name = any)]
12904    pub fn any_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12905    where
12906        I::Item: Promising;
12907
12908    /// The `Promise.race(iterable)` method returns a promise that resolves or
12909    /// rejects as soon as one of the promises in the iterable resolves or
12910    /// rejects, with the value or reason from that promise.
12911    ///
12912    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12913    #[cfg(not(js_sys_unstable_apis))]
12914    #[wasm_bindgen(static_method_of = Promise)]
12915    pub fn race(obj: &JsValue) -> Promise;
12916
12917    /// The `Promise.race(iterable)` method returns a promise that resolves or
12918    /// rejects as soon as one of the promises in the iterable resolves or
12919    /// rejects, with the value or reason from that promise.
12920    ///
12921    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12922    #[cfg(js_sys_unstable_apis)]
12923    #[wasm_bindgen(static_method_of = Promise, js_name = race)]
12924    pub fn race<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12925    where
12926        I::Item: Promising;
12927
12928    // Next major: deprecate
12929    /// The `Promise.race(iterable)` method returns a promise that resolves or
12930    /// rejects as soon as one of the promises in the iterable resolves or
12931    /// rejects, with the value or reason from that promise.
12932    ///
12933    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12934    #[wasm_bindgen(static_method_of = Promise, js_name = race)]
12935    pub fn race_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12936    where
12937        I::Item: Promising;
12938
12939    /// The `Promise.reject(reason)` method returns a `Promise` object that is
12940    /// rejected with the given reason.
12941    ///
12942    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12943    #[cfg(not(js_sys_unstable_apis))]
12944    #[wasm_bindgen(static_method_of = Promise)]
12945    pub fn reject(obj: &JsValue) -> Promise;
12946
12947    /// The `Promise.reject(reason)` method returns a `Promise` object that is
12948    /// rejected with the given reason.
12949    ///
12950    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12951    #[cfg(js_sys_unstable_apis)]
12952    #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
12953    pub fn reject<T>(obj: &JsValue) -> Promise<T>;
12954
12955    // Next major: deprecate
12956    /// The `Promise.reject(reason)` method returns a `Promise` object that is
12957    /// rejected with the given reason.
12958    ///
12959    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12960    #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
12961    pub fn reject_typed<T>(obj: &JsValue) -> Promise<T>;
12962
12963    /// The `Promise.resolve(value)` method returns a `Promise` object that is
12964    /// resolved with the given value. If the value is a promise, that promise
12965    /// is returned; if the value is a thenable (i.e. has a "then" method), the
12966    /// returned promise will "follow" that thenable, adopting its eventual
12967    /// state; otherwise the returned promise will be fulfilled with the value.
12968    ///
12969    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
12970    #[wasm_bindgen(static_method_of = Promise, js_name = resolve)]
12971    pub fn resolve<U: Promising>(obj: &U) -> Promise<U::Resolution>;
12972
12973    /// The `catch()` method returns a `Promise` and deals with rejected cases
12974    /// only.  It behaves the same as calling `Promise.prototype.then(undefined,
12975    /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
12976    /// `obj.then(undefined, onRejected)`).
12977    ///
12978    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
12979    #[cfg(not(js_sys_unstable_apis))]
12980    #[wasm_bindgen(method)]
12981    pub fn catch<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut(JsValue)>) -> Promise<JsValue>;
12982
12983    /// The `catch()` method returns a `Promise` and deals with rejected cases
12984    /// only.  It behaves the same as calling `Promise.prototype.then(undefined,
12985    /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
12986    /// `obj.then(undefined, onRejected)`).
12987    ///
12988    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
12989    #[cfg(js_sys_unstable_apis)]
12990    #[wasm_bindgen(method, js_name = catch)]
12991    pub fn catch<'a, T, R: Promising>(
12992        this: &Promise<T>,
12993        cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
12994    ) -> Promise<R::Resolution>;
12995
12996    // Next major: deprecate
12997    /// Same as `catch`, but returning a result to become the new Promise value.
12998    #[wasm_bindgen(method, js_name = catch)]
12999    pub fn catch_map<'a, T, R: Promising>(
13000        this: &Promise<T>,
13001        cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13002    ) -> Promise<R::Resolution>;
13003
13004    /// The `then()` method returns a `Promise`. It takes up to two arguments:
13005    /// callback functions for the success and failure cases of the `Promise`.
13006    ///
13007    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13008    #[cfg(not(js_sys_unstable_apis))]
13009    #[wasm_bindgen(method)]
13010    pub fn then<'a, T>(this: &Promise<T>, cb: &ScopedClosure<'a, dyn FnMut(T)>)
13011        -> Promise<JsValue>;
13012
13013    /// The `then()` method returns a `Promise`. It takes up to two arguments:
13014    /// callback functions for the success and failure cases of the `Promise`.
13015    ///
13016    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13017    #[cfg(js_sys_unstable_apis)]
13018    #[wasm_bindgen(method, js_name = then)]
13019    pub fn then<'a, T, R: Promising>(
13020        this: &Promise<T>,
13021        cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13022    ) -> Promise<R::Resolution>;
13023
13024    /// The `then()` method returns a `Promise`. It takes up to two arguments:
13025    /// callback functions for the success and failure cases of the `Promise`.
13026    ///
13027    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13028    #[wasm_bindgen(method, js_name = then)]
13029    pub fn then_with_reject<'a, T, R: Promising>(
13030        this: &Promise<T>,
13031        resolve: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13032        reject: &ScopedClosure<'a, dyn FnMut(JsValue) -> Result<R, JsError>>,
13033    ) -> Promise<R::Resolution>;
13034
13035    // Next major: deprecate
13036    /// Alias for `then()` with a return value.
13037    /// The `then()` method returns a `Promise`. It takes up to two arguments:
13038    /// callback functions for the success and failure cases of the `Promise`.
13039    ///
13040    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13041    #[wasm_bindgen(method, js_name = then)]
13042    pub fn then_map<'a, T, R: Promising>(
13043        this: &Promise<T>,
13044        cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13045    ) -> Promise<R::Resolution>;
13046
13047    /// The `finally()` method returns a `Promise`. When the promise is settled,
13048    /// whether fulfilled or rejected, the specified callback function is
13049    /// executed. This provides a way for code that must be executed once the
13050    /// `Promise` has been dealt with to be run whether the promise was
13051    /// fulfilled successfully or rejected.
13052    ///
13053    /// This lets you avoid duplicating code in both the promise's `then()` and
13054    /// `catch()` handlers.
13055    ///
13056    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
13057    #[wasm_bindgen(method)]
13058    pub fn finally<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut()>) -> Promise<JsValue>;
13059}
13060
13061impl<T: JsGeneric> Promising for Promise<T> {
13062    type Resolution = T;
13063}
13064
13065/// Returns a handle to the global scope object.
13066///
13067/// This allows access to the global properties and global names by accessing
13068/// the `Object` returned.
13069pub fn global() -> Object {
13070    use once_cell::unsync::Lazy;
13071
13072    struct Wrapper<T>(Lazy<T>);
13073
13074    #[cfg(not(target_feature = "atomics"))]
13075    unsafe impl<T> Sync for Wrapper<T> {}
13076
13077    #[cfg(not(target_feature = "atomics"))]
13078    unsafe impl<T> Send for Wrapper<T> {}
13079
13080    #[cfg_attr(target_feature = "atomics", thread_local)]
13081    static GLOBAL: Wrapper<Object> = Wrapper(Lazy::new(get_global_object));
13082
13083    return GLOBAL.0.clone();
13084
13085    fn get_global_object() -> Object {
13086        // Accessing the global object is not an easy thing to do, and what we
13087        // basically want is `globalThis` but we can't rely on that existing
13088        // everywhere. In the meantime we've got the fallbacks mentioned in:
13089        //
13090        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
13091        //
13092        // Note that this is pretty heavy code-size wise but it at least gets
13093        // the job largely done for now and avoids the `Function` constructor at
13094        // the end which triggers CSP errors.
13095        #[wasm_bindgen]
13096        extern "C" {
13097            type Global;
13098
13099            #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
13100            static GLOBAL_THIS: Option<Object>;
13101
13102            #[wasm_bindgen(thread_local_v2, js_name = self)]
13103            static SELF: Option<Object>;
13104
13105            #[wasm_bindgen(thread_local_v2, js_name = window)]
13106            static WINDOW: Option<Object>;
13107
13108            #[wasm_bindgen(thread_local_v2, js_name = global)]
13109            static GLOBAL: Option<Object>;
13110        }
13111
13112        // The order is important: in Firefox Extension Content Scripts `globalThis`
13113        // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
13114        let static_object = SELF
13115            .with(Option::clone)
13116            .or_else(|| WINDOW.with(Option::clone))
13117            .or_else(|| GLOBAL_THIS.with(Option::clone))
13118            .or_else(|| GLOBAL.with(Option::clone));
13119        if let Some(obj) = static_object {
13120            if !obj.is_undefined() {
13121                return obj;
13122            }
13123        }
13124
13125        // Global object not found
13126        JsValue::undefined().unchecked_into()
13127    }
13128}
13129
13130macro_rules! arrays {
13131    ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
13132        #[wasm_bindgen]
13133        extern "C" {
13134            #[wasm_bindgen(extends = Object, typescript_type = $name)]
13135            #[derive(Clone, Debug)]
13136            pub type $name;
13137
13138            /// The
13139            #[doc = $ctor]
13140            /// constructor creates a new array.
13141            ///
13142            /// [MDN documentation](
13143            #[doc = $mdn]
13144            /// )
13145            #[wasm_bindgen(constructor)]
13146            pub fn new(constructor_arg: &JsValue) -> $name;
13147
13148            /// An
13149            #[doc = $ctor]
13150            /// which creates an array with an internal buffer large
13151            /// enough for `length` elements.
13152            ///
13153            /// [MDN documentation](
13154            #[doc = $mdn]
13155            /// )
13156            #[wasm_bindgen(constructor)]
13157            pub fn new_with_length(length: u32) -> $name;
13158
13159            /// An
13160            #[doc = $ctor]
13161            /// which creates an array from a Rust slice.
13162            ///
13163            /// [MDN documentation](
13164            #[doc = $mdn]
13165            /// )
13166            #[wasm_bindgen(constructor)]
13167            pub fn new_from_slice(slice: &[$ty]) -> $name;
13168
13169            /// An
13170            #[doc = $ctor]
13171            /// which creates an array with the given buffer but is a
13172            /// view starting at `byte_offset`.
13173            ///
13174            /// [MDN documentation](
13175            #[doc = $mdn]
13176            /// )
13177            #[wasm_bindgen(constructor)]
13178            pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
13179
13180            /// An
13181            #[doc = $ctor]
13182            /// which creates an array with the given buffer but is a
13183            /// view starting at `byte_offset` for `length` elements.
13184            ///
13185            /// [MDN documentation](
13186            #[doc = $mdn]
13187            /// )
13188            #[wasm_bindgen(constructor)]
13189            pub fn new_with_byte_offset_and_length(
13190                buffer: &JsValue,
13191                byte_offset: u32,
13192                length: u32,
13193            ) -> $name;
13194
13195            /// The `fill()` method fills all the elements of an array from a start index
13196            /// to an end index with a static value. The end index is not included.
13197            ///
13198            /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
13199            #[wasm_bindgen(method)]
13200            pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
13201
13202            /// The buffer accessor property represents the `ArrayBuffer` referenced
13203            /// by a `TypedArray` at construction time.
13204            #[wasm_bindgen(getter, method)]
13205            pub fn buffer(this: &$name) -> ArrayBuffer;
13206
13207            /// The `subarray()` method returns a new `TypedArray` on the same
13208            /// `ArrayBuffer` store and with the same element types as for this
13209            /// `TypedArray` object.
13210            #[wasm_bindgen(method)]
13211            pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
13212
13213            /// The `slice()` method returns a shallow copy of a portion of a typed
13214            /// array into a new typed array object. This method has the same algorithm
13215            /// as `Array.prototype.slice()`.
13216            #[wasm_bindgen(method)]
13217            pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
13218
13219            /// The `forEach()` method executes a provided function once per array
13220            /// element. This method has the same algorithm as
13221            /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13222            /// types here.
13223            #[wasm_bindgen(method, js_name = forEach)]
13224            pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
13225
13226            /// The `forEach()` method executes a provided function once per array
13227            /// element. This method has the same algorithm as
13228            /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13229            /// types here.
13230            #[wasm_bindgen(method, js_name = forEach, catch)]
13231            pub fn try_for_each<'a>(this: &$name, callback: &ImmediateClosure<'a, dyn FnMut($ty, u32, $name) -> Result<(), JsError> + 'a>) -> Result<(), JsValue>;
13232
13233            /// The length accessor property represents the length (in elements) of a
13234            /// typed array.
13235            #[wasm_bindgen(method, getter)]
13236            pub fn length(this: &$name) -> u32;
13237
13238            /// The byteLength accessor property represents the length (in bytes) of a
13239            /// typed array.
13240            #[wasm_bindgen(method, getter, js_name = byteLength)]
13241            pub fn byte_length(this: &$name) -> u32;
13242
13243            /// The byteOffset accessor property represents the offset (in bytes) of a
13244            /// typed array from the start of its `ArrayBuffer`.
13245            #[wasm_bindgen(method, getter, js_name = byteOffset)]
13246            pub fn byte_offset(this: &$name) -> u32;
13247
13248            /// The `set()` method stores multiple values in the typed array, reading
13249            /// input values from a specified array.
13250            #[wasm_bindgen(method)]
13251            pub fn set(this: &$name, src: &JsValue, offset: u32);
13252
13253            /// Gets the value at `idx`, counting from the end if negative.
13254            #[wasm_bindgen(method)]
13255            pub fn at(this: &$name, idx: i32) -> Option<$ty>;
13256
13257            /// The `copyWithin()` method shallow copies part of a typed array to another
13258            /// location in the same typed array and returns it, without modifying its size.
13259            ///
13260            /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
13261            #[wasm_bindgen(method, js_name = copyWithin)]
13262            pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
13263
13264            /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
13265            #[wasm_bindgen(method, indexing_getter)]
13266            pub fn get_index(this: &$name, idx: u32) -> $ty;
13267
13268            /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
13269            #[wasm_bindgen(method, indexing_setter)]
13270            pub fn set_index(this: &$name, idx: u32, value: $ty);
13271
13272            /// Copies the Rust slice's data to self.
13273            ///
13274            /// This method is not expected to be public. It requires the length of the
13275            /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
13276            #[wasm_bindgen(method, js_name = set)]
13277            fn copy_from_slice(this: &$name, slice: &[$ty]);
13278
13279            /// Copies this TypedArray's data to Rust slice;
13280            ///
13281            /// This method is not expected to be public. It requires the length of the
13282            /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
13283            ///
13284            /// # Workaround
13285            ///
13286            /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
13287            /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
13288            /// us to specify the `this` value inside the function.
13289            ///
13290            /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
13291            /// `slice.set(typed_array)`.
13292            #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
13293            fn copy_to_slice(slice: &mut [$ty], this: &$name);
13294        }
13295
13296        impl $name {
13297            /// Creates a JS typed array which is a view into wasm's linear
13298            /// memory at the slice specified.
13299            ///
13300            /// This function returns a new typed array which is a view into
13301            /// wasm's memory. This view does not copy the underlying data.
13302            ///
13303            /// # Safety
13304            ///
13305            /// Views into WebAssembly memory are only valid so long as the
13306            /// backing buffer isn't resized in JS. Once this function is called
13307            /// any future calls to `Box::new` (or malloc of any form) may cause
13308            /// the returned value here to be invalidated. Use with caution!
13309            ///
13310            /// Additionally the returned object can be safely mutated but the
13311            /// input slice isn't guaranteed to be mutable.
13312            ///
13313            /// Finally, the returned object is disconnected from the input
13314            /// slice's lifetime, so there's no guarantee that the data is read
13315            /// at the right time.
13316            pub unsafe fn view(rust: &[$ty]) -> $name {
13317                wasm_bindgen::__rt::wbg_cast(rust)
13318            }
13319
13320            /// Creates a JS typed array which is a view into wasm's linear
13321            /// memory at the specified pointer with specified length.
13322            ///
13323            /// This function returns a new typed array which is a view into
13324            /// wasm's memory. This view does not copy the underlying data.
13325            ///
13326            /// # Safety
13327            ///
13328            /// Views into WebAssembly memory are only valid so long as the
13329            /// backing buffer isn't resized in JS. Once this function is called
13330            /// any future calls to `Box::new` (or malloc of any form) may cause
13331            /// the returned value here to be invalidated. Use with caution!
13332            ///
13333            /// Additionally the returned object can be safely mutated,
13334            /// the changes are guaranteed to be reflected in the input array.
13335            pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
13336                let slice = core::slice::from_raw_parts_mut(ptr, length);
13337                Self::view(slice)
13338            }
13339
13340            /// Copy the contents of this JS typed array into the destination
13341            /// Rust pointer.
13342            ///
13343            /// This function will efficiently copy the memory from a typed
13344            /// array into this Wasm module's own linear memory, initializing
13345            /// the memory destination provided.
13346            ///
13347            /// # Safety
13348            ///
13349            /// This function requires `dst` to point to a buffer
13350            /// large enough to fit this array's contents.
13351            pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
13352                let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
13353                self.copy_to(slice);
13354            }
13355
13356            /// Copy the contents of this JS typed array into the destination
13357            /// Rust slice.
13358            ///
13359            /// This function will efficiently copy the memory from a typed
13360            /// array into this Wasm module's own linear memory, initializing
13361            /// the memory destination provided.
13362            ///
13363            /// # Panics
13364            ///
13365            /// This function will panic if this typed array's length is
13366            /// different than the length of the provided `dst` array.
13367            pub fn copy_to(&self, dst: &mut [$ty]) {
13368                core::assert_eq!(self.length() as usize, dst.len());
13369                $name::copy_to_slice(dst, self);
13370            }
13371
13372            /// Copy the contents of this JS typed array into the destination
13373            /// Rust slice.
13374            ///
13375            /// This function will efficiently copy the memory from a typed
13376            /// array into this Wasm module's own linear memory, initializing
13377            /// the memory destination provided.
13378            ///
13379            /// # Panics
13380            ///
13381            /// This function will panic if this typed array's length is
13382            /// different than the length of the provided `dst` array.
13383            pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
13384                core::assert_eq!(self.length() as usize, dst.len());
13385                let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
13386                self.copy_to(dst);
13387                dst
13388            }
13389
13390            /// Copy the contents of the source Rust slice into this
13391            /// JS typed array.
13392            ///
13393            /// This function will efficiently copy the memory from within
13394            /// the Wasm module's own linear memory to this typed array.
13395            ///
13396            /// # Panics
13397            ///
13398            /// This function will panic if this typed array's length is
13399            /// different than the length of the provided `src` array.
13400            pub fn copy_from(&self, src: &[$ty]) {
13401                core::assert_eq!(self.length() as usize, src.len());
13402                self.copy_from_slice(src);
13403            }
13404
13405            /// Efficiently copies the contents of this JS typed array into a new Vec.
13406            pub fn to_vec(&self) -> Vec<$ty> {
13407                let len = self.length() as usize;
13408                let mut output = Vec::with_capacity(len);
13409                // Safety: the capacity has been set
13410                unsafe {
13411                    self.raw_copy_to_ptr(output.as_mut_ptr());
13412                    output.set_len(len);
13413                }
13414                output
13415            }
13416        }
13417
13418        impl<'a> From<&'a [$ty]> for $name {
13419            #[inline]
13420            fn from(slice: &'a [$ty]) -> $name {
13421                // This is safe because the `new` function makes a copy if its argument is a TypedArray
13422                $name::new_from_slice(slice)
13423            }
13424        }
13425
13426        impl Default for $name {
13427            fn default() -> Self {
13428                Self::new(&JsValue::UNDEFINED.unchecked_into())
13429            }
13430        }
13431
13432        impl TypedArray for $name {}
13433
13434
13435    )*);
13436}
13437
13438arrays! {
13439    /// `Int8Array()`
13440    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
13441    Int8Array: i8,
13442
13443    /// `Int16Array()`
13444    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
13445    Int16Array: i16,
13446
13447    /// `Int32Array()`
13448    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
13449    Int32Array: i32,
13450
13451    /// `Uint8Array()`
13452    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
13453    Uint8Array: u8,
13454
13455    /// `Uint8ClampedArray()`
13456    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
13457    Uint8ClampedArray: u8,
13458
13459    /// `Uint16Array()`
13460    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
13461    Uint16Array: u16,
13462
13463    /// `Uint32Array()`
13464    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
13465    Uint32Array: u32,
13466
13467    /// `Float32Array()`
13468    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
13469    Float32Array: f32,
13470
13471    /// `Float64Array()`
13472    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
13473    Float64Array: f64,
13474
13475    /// `BigInt64Array()`
13476    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
13477    BigInt64Array: i64,
13478
13479    /// `BigUint64Array()`
13480    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
13481    BigUint64Array: u64,
13482}