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#![doc(html_root_url = "https://docs.rs/js-sys/0.2")]
20#![cfg_attr(not(feature = "std"), no_std)]
21#![cfg_attr(target_feature = "atomics", feature(thread_local))]
22
23extern crate alloc;
24
25use alloc::string::String;
26use alloc::vec::Vec;
27use core::cmp::Ordering;
28use core::convert::{self, Infallible, TryFrom};
29use core::f64;
30use core::fmt;
31use core::iter::{self, Product, Sum};
32use core::mem::MaybeUninit;
33use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub};
34use core::str;
35use core::str::FromStr;
36
37pub use wasm_bindgen;
38use wasm_bindgen::prelude::*;
39
40// When adding new imports:
41//
42// * Keep imports in alphabetical order.
43//
44// * Rename imports with `js_name = ...` according to the note about `camelCase`
45//   and `snake_case` in the module's documentation above.
46//
47// * Include the one sentence summary of the import from the MDN link in the
48//   module's documentation above, and the MDN link itself.
49//
50// * If a function or method can throw an exception, make it catchable by adding
51//   `#[wasm_bindgen(catch)]`.
52//
53// * Add a new `#[test]` into the appropriate file in the
54//   `crates/js-sys/tests/wasm/` directory. If the imported function or method
55//   can throw an exception, make sure to also add test coverage for that case.
56//
57// * Arguments that are `JsValue`s or imported JavaScript types should be taken
58//   by reference.
59
60macro_rules! forward_deref_unop {
61    (impl $imp:ident, $method:ident for $t:ty) => {
62        impl $imp for $t {
63            type Output = <&'static $t as $imp>::Output;
64
65            #[inline]
66            fn $method(self) -> Self::Output {
67                $imp::$method(&self)
68            }
69        }
70    };
71}
72
73macro_rules! forward_deref_binop {
74    (impl $imp:ident, $method:ident for $t:ty) => {
75        impl<'a> $imp<$t> for &'a $t {
76            type Output = <&'static $t as $imp<&'static $t>>::Output;
77
78            #[inline]
79            fn $method(self, other: $t) -> Self::Output {
80                $imp::$method(self, &other)
81            }
82        }
83
84        impl $imp<&$t> for $t {
85            type Output = <&'static $t as $imp<&'static $t>>::Output;
86
87            #[inline]
88            fn $method(self, other: &$t) -> Self::Output {
89                $imp::$method(&self, other)
90            }
91        }
92
93        impl $imp<$t> for $t {
94            type Output = <&'static $t as $imp<&'static $t>>::Output;
95
96            #[inline]
97            fn $method(self, other: $t) -> Self::Output {
98                $imp::$method(&self, &other)
99            }
100        }
101    };
102}
103
104macro_rules! forward_js_unop {
105    (impl $imp:ident, $method:ident for $t:ty) => {
106        impl $imp for &$t {
107            type Output = $t;
108
109            #[inline]
110            fn $method(self) -> Self::Output {
111                $imp::$method(JsValue::as_ref(self)).unchecked_into()
112            }
113        }
114
115        forward_deref_unop!(impl $imp, $method for $t);
116    };
117}
118
119macro_rules! forward_js_binop {
120    (impl $imp:ident, $method:ident for $t:ty) => {
121        impl $imp<&$t> for &$t {
122            type Output = $t;
123
124            #[inline]
125            fn $method(self, other: &$t) -> Self::Output {
126                $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
127            }
128        }
129
130        forward_deref_binop!(impl $imp, $method for $t);
131    };
132}
133
134macro_rules! sum_product {
135    ($($a:ident)*) => ($(
136        impl Sum for $a {
137            #[inline]
138            fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
139                iter.fold(
140                    $a::from(0),
141                    |a, b| a + b,
142                )
143            }
144        }
145
146        impl Product for $a {
147            #[inline]
148            fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
149                iter.fold(
150                    $a::from(1),
151                    |a, b| a * b,
152                )
153            }
154        }
155
156        impl<'a> Sum<&'a $a> for $a {
157            fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
158                iter.fold(
159                    $a::from(0),
160                    |a, b| a + b,
161                )
162            }
163        }
164
165        impl<'a> Product<&'a $a> for $a {
166            #[inline]
167            fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
168                iter.fold(
169                    $a::from(1),
170                    |a, b| a * b,
171                )
172            }
173        }
174    )*)
175}
176
177macro_rules! partialord_ord {
178    ($t:ident) => {
179        impl PartialOrd for $t {
180            #[inline]
181            fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
182                Some(self.cmp(other))
183            }
184
185            #[inline]
186            fn lt(&self, other: &Self) -> bool {
187                JsValue::as_ref(self).lt(JsValue::as_ref(other))
188            }
189
190            #[inline]
191            fn le(&self, other: &Self) -> bool {
192                JsValue::as_ref(self).le(JsValue::as_ref(other))
193            }
194
195            #[inline]
196            fn ge(&self, other: &Self) -> bool {
197                JsValue::as_ref(self).ge(JsValue::as_ref(other))
198            }
199
200            #[inline]
201            fn gt(&self, other: &Self) -> bool {
202                JsValue::as_ref(self).gt(JsValue::as_ref(other))
203            }
204        }
205
206        impl Ord for $t {
207            #[inline]
208            fn cmp(&self, other: &Self) -> Ordering {
209                if self == other {
210                    Ordering::Equal
211                } else if self.lt(other) {
212                    Ordering::Less
213                } else {
214                    Ordering::Greater
215                }
216            }
217        }
218    };
219}
220
221#[wasm_bindgen]
222extern "C" {
223    /// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
224    /// previously created by `encodeURI` or by a similar routine.
225    ///
226    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI)
227    #[wasm_bindgen(catch, js_name = decodeURI)]
228    pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
229
230    /// The `decodeURIComponent()` function decodes a Uniform Resource Identifier (URI) component
231    /// previously created by `encodeURIComponent` or by a similar routine.
232    ///
233    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
234    #[wasm_bindgen(catch, js_name = decodeURIComponent)]
235    pub fn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>;
236
237    /// The `encodeURI()` function encodes a Uniform Resource Identifier (URI)
238    /// by replacing each instance of certain characters by one, two, three, or
239    /// four escape sequences representing the UTF-8 encoding of the character
240    /// (will only be four escape sequences for characters composed of two
241    /// "surrogate" characters).
242    ///
243    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
244    #[wasm_bindgen(js_name = encodeURI)]
245    pub fn encode_uri(decoded: &str) -> JsString;
246
247    /// The `encodeURIComponent()` function encodes a Uniform Resource Identifier (URI) component
248    /// by replacing each instance of certain characters by one, two, three, or four escape sequences
249    /// representing the UTF-8 encoding of the character
250    /// (will only be four escape sequences for characters composed of two "surrogate" characters).
251    ///
252    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
253    #[wasm_bindgen(js_name = encodeURIComponent)]
254    pub fn encode_uri_component(decoded: &str) -> JsString;
255
256    /// The `eval()` function evaluates JavaScript code represented as a string.
257    ///
258    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)
259    #[wasm_bindgen(catch)]
260    pub fn eval(js_source_text: &str) -> Result<JsValue, JsValue>;
261
262    /// The global `isFinite()` function determines whether the passed value is a finite number.
263    /// If needed, the parameter is first converted to a number.
264    ///
265    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
266    #[wasm_bindgen(js_name = isFinite)]
267    pub fn is_finite(value: &JsValue) -> bool;
268
269    /// The `parseInt()` function parses a string argument and returns an integer
270    /// of the specified radix (the base in mathematical numeral systems), or NaN on error.
271    ///
272    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
273    #[wasm_bindgen(js_name = parseInt)]
274    pub fn parse_int(text: &str, radix: u8) -> f64;
275
276    /// The `parseFloat()` function parses an argument and returns a floating point number,
277    /// or NaN on error.
278    ///
279    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
280    #[wasm_bindgen(js_name = parseFloat)]
281    pub fn parse_float(text: &str) -> f64;
282
283    /// The `escape()` function computes a new string in which certain characters have been
284    /// replaced by a hexadecimal escape sequence.
285    ///
286    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape)
287    #[wasm_bindgen]
288    pub fn escape(string: &str) -> JsString;
289
290    /// The `unescape()` function computes a new string in which hexadecimal escape
291    /// sequences are replaced with the character that it represents. The escape sequences might
292    /// be introduced by a function like `escape`. Usually, `decodeURI` or `decodeURIComponent`
293    /// are preferred over `unescape`.
294    ///
295    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape)
296    #[wasm_bindgen]
297    pub fn unescape(string: &str) -> JsString;
298}
299
300// Array
301#[wasm_bindgen]
302extern "C" {
303    #[wasm_bindgen(extends = Object, is_type_of = Array::is_array, typescript_type = "Array<any>")]
304    #[derive(Clone, Debug, PartialEq, Eq)]
305    pub type Array;
306
307    /// Creates a new empty array.
308    #[wasm_bindgen(constructor)]
309    pub fn new() -> Array;
310
311    /// Creates a new array with the specified length (elements are initialized to `undefined`).
312    #[wasm_bindgen(constructor)]
313    pub fn new_with_length(len: u32) -> Array;
314
315    /// Retrieves the element at the index, counting from the end if negative
316    /// (returns `undefined` if the index is out of range).
317    #[wasm_bindgen(method)]
318    pub fn at(this: &Array, index: i32) -> JsValue;
319
320    /// Retrieves the element at the index (returns `undefined` if the index is out of range).
321    #[wasm_bindgen(method, structural, indexing_getter)]
322    pub fn get(this: &Array, index: u32) -> JsValue;
323
324    /// Sets the element at the index (auto-enlarges the array if the index is out of range).
325    #[wasm_bindgen(method, structural, indexing_setter)]
326    pub fn set(this: &Array, index: u32, value: JsValue);
327
328    /// Deletes the element at the index (does nothing if the index is out of range).
329    ///
330    /// The element at the index is set to `undefined`.
331    ///
332    /// This does not resize the array, the array will still be the same length.
333    #[wasm_bindgen(method, structural, indexing_deleter)]
334    pub fn delete(this: &Array, index: u32);
335
336    /// The `Array.from()` method creates a new, shallow-copied `Array` instance
337    /// from an array-like or iterable object.
338    #[wasm_bindgen(static_method_of = Array)]
339    pub fn from(val: &JsValue) -> Array;
340
341    /// The `copyWithin()` method shallow copies part of an array to another
342    /// location in the same array and returns it, without modifying its size.
343    ///
344    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)
345    #[wasm_bindgen(method, js_name = copyWithin)]
346    pub fn copy_within(this: &Array, target: i32, start: i32, end: i32) -> Array;
347
348    /// The `concat()` method is used to merge two or more arrays. This method
349    /// does not change the existing arrays, but instead returns a new array.
350    ///
351    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
352    #[wasm_bindgen(method)]
353    pub fn concat(this: &Array, array: &Array) -> Array;
354
355    /// The `every()` method tests whether all elements in the array pass the test
356    /// implemented by the provided function.
357    ///
358    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
359    #[wasm_bindgen(method)]
360    pub fn every(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> bool;
361
362    /// The `fill()` method fills all the elements of an array from a start index
363    /// to an end index with a static value. The end index is not included.
364    ///
365    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
366    #[wasm_bindgen(method)]
367    pub fn fill(this: &Array, value: &JsValue, start: u32, end: u32) -> Array;
368
369    /// The `filter()` method creates a new array with all elements that pass the
370    /// test implemented by the provided function.
371    ///
372    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
373    #[wasm_bindgen(method)]
374    pub fn filter(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> Array;
375
376    /// The `find()` method returns the value of the first element in the array that satisfies
377    ///  the provided testing function. Otherwise `undefined` is returned.
378    ///
379    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
380    #[wasm_bindgen(method)]
381    pub fn find(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> JsValue;
382
383    /// The `findIndex()` method returns the index of the first element in the array that
384    /// satisfies the provided testing function. Otherwise -1 is returned.
385    ///
386    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
387    #[wasm_bindgen(method, js_name = findIndex)]
388    pub fn find_index(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> i32;
389
390    /// The `findLast()` method of Array instances iterates the array in reverse order
391    /// and returns the value of the first element that satisfies the provided testing function.
392    /// If no elements satisfy the testing function, undefined is returned.
393    ///
394    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
395    #[wasm_bindgen(method, js_name = findLast)]
396    pub fn find_last(
397        this: &Array,
398        predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool,
399    ) -> JsValue;
400
401    /// The `findLastIndex()` method of Array instances iterates the array in reverse order
402    /// and returns the index of the first element that satisfies the provided testing function.
403    /// If no elements satisfy the testing function, -1 is returned.
404    ///
405    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
406    #[wasm_bindgen(method, js_name = findLastIndex)]
407    pub fn find_last_index(
408        this: &Array,
409        predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool,
410    ) -> i32;
411
412    /// The `flat()` method creates a new array with all sub-array elements concatenated into it
413    /// recursively up to the specified depth.
414    ///
415    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
416    #[wasm_bindgen(method)]
417    pub fn flat(this: &Array, depth: i32) -> Array;
418
419    /// The `flatMap()` method first maps each element using a mapping function, then flattens
420    /// the result into a new array.
421    ///
422    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
423    #[wasm_bindgen(method, js_name = flatMap)]
424    pub fn flat_map(
425        this: &Array,
426        callback: &mut dyn FnMut(JsValue, u32, Array) -> Vec<JsValue>,
427    ) -> Array;
428
429    /// The `forEach()` method executes a provided function once for each array element.
430    ///
431    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
432    #[wasm_bindgen(method, js_name = forEach)]
433    pub fn for_each(this: &Array, callback: &mut dyn FnMut(JsValue, u32, Array));
434
435    /// The `includes()` method determines whether an array includes a certain
436    /// element, returning true or false as appropriate.
437    ///
438    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
439    #[wasm_bindgen(method)]
440    pub fn includes(this: &Array, value: &JsValue, from_index: i32) -> bool;
441
442    /// The `indexOf()` method returns the first index at which a given element
443    /// can be found in the array, or -1 if it is not present.
444    ///
445    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
446    #[wasm_bindgen(method, js_name = indexOf)]
447    pub fn index_of(this: &Array, value: &JsValue, from_index: i32) -> i32;
448
449    /// The `Array.isArray()` method determines whether the passed value is an Array.
450    ///
451    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)
452    #[wasm_bindgen(static_method_of = Array, js_name = isArray)]
453    pub fn is_array(value: &JsValue) -> bool;
454
455    /// The `join()` method joins all elements of an array (or an array-like object)
456    /// into a string and returns this string.
457    ///
458    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
459    #[wasm_bindgen(method)]
460    pub fn join(this: &Array, delimiter: &str) -> JsString;
461
462    /// The `lastIndexOf()` method returns the last index at which a given element
463    /// can be found in the array, or -1 if it is not present. The array is
464    /// searched backwards, starting at fromIndex.
465    ///
466    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
467    #[wasm_bindgen(method, js_name = lastIndexOf)]
468    pub fn last_index_of(this: &Array, value: &JsValue, from_index: i32) -> i32;
469
470    /// The length property of an object which is an instance of type Array
471    /// sets or returns the number of elements in that array. The value is an
472    /// unsigned, 32-bit integer that is always numerically greater than the
473    /// highest index in the array.
474    ///
475    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
476    #[wasm_bindgen(method, getter, structural)]
477    pub fn length(this: &Array) -> u32;
478
479    /// Sets the length of the array.
480    ///
481    /// If it is set to less than the current length of the array, it will
482    /// shrink the array.
483    ///
484    /// If it is set to more than the current length of the array, it will
485    /// increase the length of the array, filling the new space with empty
486    /// slots.
487    ///
488    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
489    #[wasm_bindgen(method, setter)]
490    pub fn set_length(this: &Array, value: u32);
491
492    /// `map()` calls a provided callback function once for each element in an array,
493    /// in order, and constructs a new array from the results. callback is invoked
494    /// only for indexes of the array which have assigned values, including undefined.
495    /// It is not called for missing elements of the array (that is, indexes that have
496    /// never been set, which have been deleted or which have never been assigned a value).
497    ///
498    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
499    #[wasm_bindgen(method)]
500    pub fn map(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> JsValue) -> Array;
501
502    /// The `Array.of()` method creates a new Array instance with a variable
503    /// number of arguments, regardless of number or type of the arguments.
504    ///
505    /// The difference between `Array.of()` and the `Array` constructor is in the
506    /// handling of integer arguments: `Array.of(7)` creates an array with a single
507    /// element, `7`, whereas `Array(7)` creates an empty array with a `length`
508    /// property of `7` (Note: this implies an array of 7 empty slots, not slots
509    /// with actual undefined values).
510    ///
511    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
512    ///
513    /// # Notes
514    ///
515    /// There are a few bindings to `of` in `js-sys`: `of1`, `of2`, etc...
516    /// with different arities.
517    #[wasm_bindgen(static_method_of = Array, js_name = of)]
518    pub fn of1(a: &JsValue) -> Array;
519
520    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
521    #[wasm_bindgen(static_method_of = Array, js_name = of)]
522    pub fn of2(a: &JsValue, b: &JsValue) -> Array;
523
524    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
525    #[wasm_bindgen(static_method_of = Array, js_name = of)]
526    pub fn of3(a: &JsValue, b: &JsValue, c: &JsValue) -> Array;
527
528    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
529    #[wasm_bindgen(static_method_of = Array, js_name = of)]
530    pub fn of4(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue) -> Array;
531
532    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
533    #[wasm_bindgen(static_method_of = Array, js_name = of)]
534    pub fn of5(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue, e: &JsValue) -> Array;
535
536    /// The `pop()` method removes the last element from an array and returns that
537    /// element. This method changes the length of the array.
538    ///
539    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
540    #[wasm_bindgen(method)]
541    pub fn pop(this: &Array) -> JsValue;
542
543    /// The `push()` method adds one or more elements to the end of an array and
544    /// returns the new length of the array.
545    ///
546    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
547    #[wasm_bindgen(method)]
548    pub fn push(this: &Array, value: &JsValue) -> u32;
549
550    /// The `reduce()` method applies a function against an accumulator and each element in
551    /// the array (from left to right) to reduce it to a single value.
552    ///
553    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
554    #[wasm_bindgen(method)]
555    pub fn reduce(
556        this: &Array,
557        predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue,
558        initial_value: &JsValue,
559    ) -> JsValue;
560
561    /// The `reduceRight()` method applies a function against an accumulator and each value
562    /// of the array (from right-to-left) to reduce it to a single value.
563    ///
564    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
565    #[wasm_bindgen(method, js_name = reduceRight)]
566    pub fn reduce_right(
567        this: &Array,
568        predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue,
569        initial_value: &JsValue,
570    ) -> JsValue;
571
572    /// The `reverse()` method reverses an array in place. The first array
573    /// element becomes the last, and the last array element becomes the first.
574    ///
575    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
576    #[wasm_bindgen(method)]
577    pub fn reverse(this: &Array) -> Array;
578
579    /// The `shift()` method removes the first element from an array and returns
580    /// that removed element. This method changes the length of the array.
581    ///
582    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
583    #[wasm_bindgen(method)]
584    pub fn shift(this: &Array) -> JsValue;
585
586    /// The `slice()` method returns a shallow copy of a portion of an array into
587    /// a new array object selected from begin to end (end not included).
588    /// The original array will not be modified.
589    ///
590    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
591    #[wasm_bindgen(method)]
592    pub fn slice(this: &Array, start: u32, end: u32) -> Array;
593
594    /// The `some()` method tests whether at least one element in the array passes the test implemented
595    /// by the provided function.
596    /// Note: This method returns false for any condition put on an empty array.
597    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
598    #[wasm_bindgen(method)]
599    pub fn some(this: &Array, predicate: &mut dyn FnMut(JsValue) -> bool) -> bool;
600
601    /// The `sort()` method sorts the elements of an array in place and returns
602    /// the array. The sort is not necessarily stable. The default sort
603    /// order is according to string Unicode code points.
604    ///
605    /// The time and space complexity of the sort cannot be guaranteed as it
606    /// is implementation dependent.
607    ///
608    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
609    #[wasm_bindgen(method)]
610    pub fn sort(this: &Array) -> Array;
611
612    /// The `splice()` method changes the contents of an array by removing existing elements and/or
613    /// adding new elements.
614    ///
615    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
616    #[wasm_bindgen(method)]
617    pub fn splice(this: &Array, start: u32, delete_count: u32, item: &JsValue) -> Array;
618
619    /// The `toLocaleString()` method returns a string representing the elements of the array.
620    /// The elements are converted to Strings using their toLocaleString methods and these
621    /// Strings are separated by a locale-specific String (such as a comma “,”).
622    ///
623    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
624    #[wasm_bindgen(method, js_name = toLocaleString)]
625    pub fn to_locale_string(this: &Array, locales: &JsValue, options: &JsValue) -> JsString;
626
627    /// The `toString()` method returns a string representing the specified array
628    /// and its elements.
629    ///
630    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)
631    #[wasm_bindgen(method, js_name = toString)]
632    pub fn to_string(this: &Array) -> JsString;
633
634    /// The `unshift()` method adds one or more elements to the beginning of an
635    /// array and returns the new length of the array.
636    ///
637    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
638    #[wasm_bindgen(method)]
639    pub fn unshift(this: &Array, value: &JsValue) -> u32;
640}
641
642/// Iterator returned by `Array::into_iter`
643#[derive(Debug, Clone)]
644pub struct ArrayIntoIter {
645    range: core::ops::Range<u32>,
646    array: Array,
647}
648
649impl core::iter::Iterator for ArrayIntoIter {
650    type Item = JsValue;
651
652    fn next(&mut self) -> Option<Self::Item> {
653        let index = self.range.next()?;
654        Some(self.array.get(index))
655    }
656
657    #[inline]
658    fn size_hint(&self) -> (usize, Option<usize>) {
659        self.range.size_hint()
660    }
661
662    #[inline]
663    fn count(self) -> usize
664    where
665        Self: Sized,
666    {
667        self.range.count()
668    }
669
670    #[inline]
671    fn last(self) -> Option<Self::Item>
672    where
673        Self: Sized,
674    {
675        let Self { range, array } = self;
676        range.last().map(|index| array.get(index))
677    }
678
679    #[inline]
680    fn nth(&mut self, n: usize) -> Option<Self::Item> {
681        self.range.nth(n).map(|index| self.array.get(index))
682    }
683}
684
685impl core::iter::DoubleEndedIterator for ArrayIntoIter {
686    fn next_back(&mut self) -> Option<Self::Item> {
687        let index = self.range.next_back()?;
688        Some(self.array.get(index))
689    }
690
691    fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
692        self.range.nth_back(n).map(|index| self.array.get(index))
693    }
694}
695
696impl core::iter::FusedIterator for ArrayIntoIter {}
697
698impl core::iter::ExactSizeIterator for ArrayIntoIter {}
699
700/// Iterator returned by `Array::iter`
701#[derive(Debug, Clone)]
702pub struct ArrayIter<'a> {
703    range: core::ops::Range<u32>,
704    array: &'a Array,
705}
706
707impl core::iter::Iterator for ArrayIter<'_> {
708    type Item = JsValue;
709
710    fn next(&mut self) -> Option<Self::Item> {
711        let index = self.range.next()?;
712        Some(self.array.get(index))
713    }
714
715    #[inline]
716    fn size_hint(&self) -> (usize, Option<usize>) {
717        self.range.size_hint()
718    }
719
720    #[inline]
721    fn count(self) -> usize
722    where
723        Self: Sized,
724    {
725        self.range.count()
726    }
727
728    #[inline]
729    fn last(self) -> Option<Self::Item>
730    where
731        Self: Sized,
732    {
733        let Self { range, array } = self;
734        range.last().map(|index| array.get(index))
735    }
736
737    #[inline]
738    fn nth(&mut self, n: usize) -> Option<Self::Item> {
739        self.range.nth(n).map(|index| self.array.get(index))
740    }
741}
742
743impl core::iter::DoubleEndedIterator for ArrayIter<'_> {
744    fn next_back(&mut self) -> Option<Self::Item> {
745        let index = self.range.next_back()?;
746        Some(self.array.get(index))
747    }
748
749    fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
750        self.range.nth_back(n).map(|index| self.array.get(index))
751    }
752}
753
754impl core::iter::FusedIterator for ArrayIter<'_> {}
755
756impl core::iter::ExactSizeIterator for ArrayIter<'_> {}
757
758impl Array {
759    /// Returns an iterator over the values of the JS array.
760    pub fn iter(&self) -> ArrayIter<'_> {
761        ArrayIter {
762            range: 0..self.length(),
763            array: self,
764        }
765    }
766
767    /// Converts the JS array into a new Vec.
768    pub fn to_vec(&self) -> Vec<JsValue> {
769        let len = self.length();
770
771        let mut output = Vec::with_capacity(len as usize);
772
773        for i in 0..len {
774            output.push(self.get(i));
775        }
776
777        output
778    }
779}
780
781impl core::iter::IntoIterator for Array {
782    type Item = JsValue;
783    type IntoIter = ArrayIntoIter;
784
785    fn into_iter(self) -> Self::IntoIter {
786        ArrayIntoIter {
787            range: 0..self.length(),
788            array: self,
789        }
790    }
791}
792
793// TODO pre-initialize the Array with the correct length using TrustedLen
794impl<A> core::iter::FromIterator<A> for Array
795where
796    A: AsRef<JsValue>,
797{
798    fn from_iter<T>(iter: T) -> Array
799    where
800        T: IntoIterator<Item = A>,
801    {
802        let mut out = Array::new();
803        out.extend(iter);
804        out
805    }
806}
807
808impl<A> core::iter::Extend<A> for Array
809where
810    A: AsRef<JsValue>,
811{
812    fn extend<T>(&mut self, iter: T)
813    where
814        T: IntoIterator<Item = A>,
815    {
816        for value in iter {
817            self.push(value.as_ref());
818        }
819    }
820}
821
822impl Default for Array {
823    fn default() -> Self {
824        Self::new()
825    }
826}
827
828// ArrayBuffer
829#[wasm_bindgen]
830extern "C" {
831    #[wasm_bindgen(extends = Object, typescript_type = "ArrayBuffer")]
832    #[derive(Clone, Debug, PartialEq, Eq)]
833    pub type ArrayBuffer;
834
835    /// The `ArrayBuffer` object is used to represent a generic,
836    /// fixed-length raw binary data buffer. You cannot directly
837    /// manipulate the contents of an `ArrayBuffer`; instead, you
838    /// create one of the typed array objects or a `DataView` object
839    /// which represents the buffer in a specific format, and use that
840    /// to read and write the contents of the buffer.
841    ///
842    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
843    #[wasm_bindgen(constructor)]
844    pub fn new(length: u32) -> ArrayBuffer;
845
846    /// The byteLength property of an object which is an instance of type ArrayBuffer
847    /// it's an accessor property whose set accessor function is undefined,
848    /// meaning that you can only read this property.
849    /// The value is established when the array is constructed and cannot be changed.
850    /// This property returns 0 if this ArrayBuffer has been detached.
851    ///
852    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
853    #[wasm_bindgen(method, getter, js_name = byteLength)]
854    pub fn byte_length(this: &ArrayBuffer) -> u32;
855
856    /// The `isView()` method returns true if arg is one of the `ArrayBuffer`
857    /// views, such as typed array objects or a DataView; false otherwise.
858    ///
859    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView)
860    #[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
861    pub fn is_view(value: &JsValue) -> bool;
862
863    /// The `slice()` method returns a new `ArrayBuffer` whose contents
864    /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
865    /// up to end, exclusive.
866    ///
867    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
868    #[wasm_bindgen(method)]
869    pub fn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer;
870
871    /// Like `slice()` but with the `end` argument.
872    ///
873    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
874    #[wasm_bindgen(method, js_name = slice)]
875    pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer;
876}
877
878// SharedArrayBuffer
879#[wasm_bindgen]
880extern "C" {
881    #[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
882    #[derive(Clone, Debug)]
883    pub type SharedArrayBuffer;
884
885    /// The `SharedArrayBuffer` object is used to represent a generic,
886    /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
887    /// object, but in a way that they can be used to create views
888    /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
889    /// cannot become detached.
890    ///
891    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
892    #[wasm_bindgen(constructor)]
893    pub fn new(length: u32) -> SharedArrayBuffer;
894
895    /// The byteLength accessor property represents the length of
896    /// an `SharedArrayBuffer` in bytes. This is established when
897    /// the `SharedArrayBuffer` is constructed and cannot be changed.
898    ///
899    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
900    #[wasm_bindgen(method, getter, js_name = byteLength)]
901    pub fn byte_length(this: &SharedArrayBuffer) -> u32;
902
903    /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
904    /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
905    /// up to end, exclusive.
906    ///
907    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
908    #[wasm_bindgen(method)]
909    pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer;
910
911    /// Like `slice()` but with the `end` argument.
912    ///
913    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
914    #[wasm_bindgen(method, js_name = slice)]
915    pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer;
916}
917
918// Array Iterator
919#[wasm_bindgen]
920extern "C" {
921    /// The `keys()` method returns a new Array Iterator object that contains the
922    /// keys for each index in the array.
923    ///
924    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys)
925    #[wasm_bindgen(method)]
926    pub fn keys(this: &Array) -> Iterator;
927
928    /// The `entries()` method returns a new Array Iterator object that contains
929    /// the key/value pairs for each index in the array.
930    ///
931    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
932    #[wasm_bindgen(method)]
933    pub fn entries(this: &Array) -> Iterator;
934
935    /// The `values()` method returns a new Array Iterator object that
936    /// contains the values for each index in the array.
937    ///
938    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
939    #[wasm_bindgen(method)]
940    pub fn values(this: &Array) -> Iterator;
941}
942
943/// The `Atomics` object provides atomic operations as static methods.
944/// They are used with `SharedArrayBuffer` objects.
945///
946/// The Atomic operations are installed on an `Atomics` module. Unlike
947/// the other global objects, `Atomics` is not a constructor. You cannot
948/// use it with a new operator or invoke the `Atomics` object as a
949/// function. All properties and methods of `Atomics` are static
950/// (as is the case with the Math object, for example).
951/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
952#[allow(non_snake_case)]
953pub mod Atomics {
954    use super::*;
955
956    #[wasm_bindgen]
957    extern "C" {
958        /// The static `Atomics.add()` method adds a given value at a given
959        /// position in the array and returns the old value at that position.
960        /// This atomic operation guarantees that no other write happens
961        /// until the modified value is written back.
962        ///
963        /// You should use `add_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
964        ///
965        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
966        #[wasm_bindgen(js_namespace = Atomics, catch)]
967        pub fn add(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
968
969        /// The static `Atomics.add()` method adds a given value at a given
970        /// position in the array and returns the old value at that position.
971        /// This atomic operation guarantees that no other write happens
972        /// until the modified value is written back.
973        ///
974        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
975        ///
976        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
977        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = add)]
978        pub fn add_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>;
979
980        /// The static `Atomics.and()` method computes a bitwise AND with a given
981        /// value at a given position in the array, and returns the old value
982        /// at that position.
983        /// This atomic operation guarantees that no other write happens
984        /// until the modified value is written back.
985        ///
986        /// You should use `and_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
987        ///
988        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
989        #[wasm_bindgen(js_namespace = Atomics, catch)]
990        pub fn and(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
991
992        /// The static `Atomics.and()` method computes a bitwise AND with a given
993        /// value at a given position in the array, and returns the old value
994        /// at that position.
995        /// This atomic operation guarantees that no other write happens
996        /// until the modified value is written back.
997        ///
998        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
999        ///
1000        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
1001        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = and)]
1002        pub fn and_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>;
1003
1004        /// The static `Atomics.compareExchange()` method exchanges a given
1005        /// replacement value at a given position in the array, if a given expected
1006        /// value equals the old value. It returns the old value at that position
1007        /// whether it was equal to the expected value or not.
1008        /// This atomic operation guarantees that no other write happens
1009        /// until the modified value is written back.
1010        ///
1011        /// You should use `compare_exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1012        ///
1013        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
1014        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
1015        pub fn compare_exchange(
1016            typed_array: &JsValue,
1017            index: u32,
1018            expected_value: i32,
1019            replacement_value: i32,
1020        ) -> Result<i32, JsValue>;
1021
1022        /// The static `Atomics.compareExchange()` method exchanges a given
1023        /// replacement value at a given position in the array, if a given expected
1024        /// value equals the old value. It returns the old value at that position
1025        /// whether it was equal to the expected value or not.
1026        /// This atomic operation guarantees that no other write happens
1027        /// until the modified value is written back.
1028        ///
1029        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1030        ///
1031        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
1032        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
1033        pub fn compare_exchange_bigint(
1034            typed_array: &JsValue,
1035            index: u32,
1036            expected_value: i64,
1037            replacement_value: i64,
1038        ) -> Result<i64, JsValue>;
1039
1040        /// The static `Atomics.exchange()` method stores a given value at a given
1041        /// position in the array and returns the old value at that position.
1042        /// This atomic operation guarantees that no other write happens
1043        /// until the modified value is written back.
1044        ///
1045        /// You should use `exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1046        ///
1047        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
1048        #[wasm_bindgen(js_namespace = Atomics, catch)]
1049        pub fn exchange(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
1050
1051        /// The static `Atomics.exchange()` method stores a given value at a given
1052        /// position in the array and returns the old value at that position.
1053        /// This atomic operation guarantees that no other write happens
1054        /// until the modified value is written back.
1055        ///
1056        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1057        ///
1058        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
1059        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = exchange)]
1060        pub fn exchange_bigint(
1061            typed_array: &JsValue,
1062            index: u32,
1063            value: i64,
1064        ) -> Result<i64, JsValue>;
1065
1066        /// The static `Atomics.isLockFree()` method is used to determine
1067        /// whether to use locks or atomic operations. It returns true,
1068        /// if the given size is one of the `BYTES_PER_ELEMENT` property
1069        /// of integer `TypedArray` types.
1070        ///
1071        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree)
1072        #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)]
1073        pub fn is_lock_free(size: u32) -> bool;
1074
1075        /// The static `Atomics.load()` method returns a value at a given
1076        /// position in the array.
1077        ///
1078        /// You should use `load_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1079        ///
1080        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
1081        #[wasm_bindgen(js_namespace = Atomics, catch)]
1082        pub fn load(typed_array: &JsValue, index: u32) -> Result<i32, JsValue>;
1083
1084        /// The static `Atomics.load()` method returns a value at a given
1085        /// position in the array.
1086        ///
1087        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1088        ///
1089        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
1090        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = load)]
1091        pub fn load_bigint(typed_array: &JsValue, index: i64) -> Result<i64, JsValue>;
1092
1093        /// The static `Atomics.notify()` method notifies up some agents that
1094        /// are sleeping in the wait queue.
1095        /// Note: This operation works with a shared `Int32Array` only.
1096        /// If `count` is not provided, notifies all the agents in the queue.
1097        ///
1098        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
1099        #[wasm_bindgen(js_namespace = Atomics, catch)]
1100        pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>;
1101
1102        /// Notifies up to `count` agents in the wait queue.
1103        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
1104        pub fn notify_with_count(
1105            typed_array: &Int32Array,
1106            index: u32,
1107            count: u32,
1108        ) -> Result<u32, JsValue>;
1109
1110        /// The static `Atomics.or()` method computes a bitwise OR with a given value
1111        /// at a given position in the array, and returns the old value at that position.
1112        /// This atomic operation guarantees that no other write happens
1113        /// until the modified value is written back.
1114        ///
1115        /// You should use `or_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1116        ///
1117        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
1118        #[wasm_bindgen(js_namespace = Atomics, catch)]
1119        pub fn or(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
1120
1121        /// The static `Atomics.or()` method computes a bitwise OR with a given value
1122        /// at a given position in the array, and returns the old value at that position.
1123        /// This atomic operation guarantees that no other write happens
1124        /// until the modified value is written back.
1125        ///
1126        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1127        ///
1128        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
1129        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = or)]
1130        pub fn or_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>;
1131
1132        /// The static `Atomics.store()` method stores a given value at the given
1133        /// position in the array and returns that value.
1134        ///
1135        /// You should use `store_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1136        ///
1137        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
1138        #[wasm_bindgen(js_namespace = Atomics, catch)]
1139        pub fn store(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
1140
1141        /// The static `Atomics.store()` method stores a given value at the given
1142        /// position in the array and returns that value.
1143        ///
1144        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1145        ///
1146        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
1147        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = store)]
1148        pub fn store_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>;
1149
1150        /// The static `Atomics.sub()` method subtracts a given value at a
1151        /// given position in the array and returns the old value at that position.
1152        /// This atomic operation guarantees that no other write happens
1153        /// until the modified value is written back.
1154        ///
1155        /// You should use `sub_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1156        ///
1157        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
1158        #[wasm_bindgen(js_namespace = Atomics, catch)]
1159        pub fn sub(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
1160
1161        /// The static `Atomics.sub()` method subtracts a given value at a
1162        /// given position in the array and returns the old value at that position.
1163        /// This atomic operation guarantees that no other write happens
1164        /// until the modified value is written back.
1165        ///
1166        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1167        ///
1168        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
1169        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = sub)]
1170        pub fn sub_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>;
1171
1172        /// The static `Atomics.wait()` method verifies that a given
1173        /// position in an `Int32Array` still contains a given value
1174        /// and if so sleeps, awaiting a wakeup or a timeout.
1175        /// It returns a string which is either "ok", "not-equal", or "timed-out".
1176        /// Note: This operation only works with a shared `Int32Array`
1177        /// and may not be allowed on the main thread.
1178        ///
1179        /// You should use `wait_bigint` to operate on a `BigInt64Array`.
1180        ///
1181        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
1182        #[wasm_bindgen(js_namespace = Atomics, catch)]
1183        pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>;
1184
1185        /// The static `Atomics.wait()` method verifies that a given
1186        /// position in an `BigInt64Array` still contains a given value
1187        /// and if so sleeps, awaiting a wakeup or a timeout.
1188        /// It returns a string which is either "ok", "not-equal", or "timed-out".
1189        /// Note: This operation only works with a shared `BigInt64Array`
1190        /// and may not be allowed on the main thread.
1191        ///
1192        /// You should use `wait` to operate on a `Int32Array`.
1193        ///
1194        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
1195        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
1196        pub fn wait_bigint(
1197            typed_array: &BigInt64Array,
1198            index: u32,
1199            value: i64,
1200        ) -> Result<JsString, JsValue>;
1201
1202        /// Like `wait()`, but with timeout
1203        ///
1204        /// You should use `wait_with_timeout_bigint` to operate on a `BigInt64Array`.
1205        ///
1206        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
1207        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
1208        pub fn wait_with_timeout(
1209            typed_array: &Int32Array,
1210            index: u32,
1211            value: i32,
1212            timeout: f64,
1213        ) -> Result<JsString, JsValue>;
1214
1215        /// Like `wait()`, but with timeout
1216        ///
1217        /// You should use `wait_with_timeout` to operate on a `Int32Array`.
1218        ///
1219        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
1220        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
1221        pub fn wait_with_timeout_bigint(
1222            typed_array: &BigInt64Array,
1223            index: u32,
1224            value: i64,
1225            timeout: f64,
1226        ) -> Result<JsString, JsValue>;
1227
1228        /// The static `Atomics.waitAsync()` method verifies that a given position in an
1229        /// `Int32Array` still contains a given value and if so sleeps, awaiting a
1230        /// wakeup or a timeout. It returns an object with two properties. The first
1231        /// property `async` is a boolean which if true indicates that the second
1232        /// property `value` is a promise. If `async` is false then value is a string
1233        /// whether equal to either "not-equal" or "timed-out".
1234        /// Note: This operation only works with a shared `Int32Array` and may be used
1235        /// on the main thread.
1236        ///
1237        /// You should use `wait_async_bigint` to operate on a `BigInt64Array`.
1238        ///
1239        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
1240        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
1241        pub fn wait_async(
1242            typed_array: &Int32Array,
1243            index: u32,
1244            value: i32,
1245        ) -> Result<Object, JsValue>;
1246
1247        /// The static `Atomics.waitAsync()` method verifies that a given position in an
1248        /// `Int32Array` still contains a given value and if so sleeps, awaiting a
1249        /// wakeup or a timeout. It returns an object with two properties. The first
1250        /// property `async` is a boolean which if true indicates that the second
1251        /// property `value` is a promise. If `async` is false then value is a string
1252        /// whether equal to either "not-equal" or "timed-out".
1253        /// Note: This operation only works with a shared `BigInt64Array` and may be used
1254        /// on the main thread.
1255        ///
1256        /// You should use `wait_async` to operate on a `Int32Array`.
1257        ///
1258        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
1259        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
1260        pub fn wait_async_bigint(
1261            typed_array: &BigInt64Array,
1262            index: u32,
1263            value: i64,
1264        ) -> Result<Object, JsValue>;
1265
1266        /// Like `waitAsync()`, but with timeout
1267        ///
1268        /// You should use `wait_async_with_timeout_bigint` to operate on a `BigInt64Array`.
1269        ///
1270        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
1271        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
1272        pub fn wait_async_with_timeout(
1273            typed_array: &Int32Array,
1274            index: u32,
1275            value: i32,
1276            timeout: f64,
1277        ) -> Result<Object, JsValue>;
1278
1279        /// Like `waitAsync()`, but with timeout
1280        ///
1281        /// You should use `wait_async_with_timeout` to operate on a `Int32Array`.
1282        ///
1283        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
1284        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
1285        pub fn wait_async_with_timeout_bigint(
1286            typed_array: &BigInt64Array,
1287            index: u32,
1288            value: i64,
1289            timeout: f64,
1290        ) -> Result<Object, JsValue>;
1291
1292        /// The static `Atomics.xor()` method computes a bitwise XOR
1293        /// with a given value at a given position in the array,
1294        /// and returns the old value at that position.
1295        /// This atomic operation guarantees that no other write happens
1296        /// until the modified value is written back.
1297        ///
1298        /// You should use `xor_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1299        ///
1300        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
1301        #[wasm_bindgen(js_namespace = Atomics, catch)]
1302        pub fn xor(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
1303
1304        /// The static `Atomics.xor()` method computes a bitwise XOR
1305        /// with a given value at a given position in the array,
1306        /// and returns the old value at that position.
1307        /// This atomic operation guarantees that no other write happens
1308        /// until the modified value is written back.
1309        ///
1310        /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1311        ///
1312        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
1313        #[wasm_bindgen(js_namespace = Atomics, catch, js_name = xor)]
1314        pub fn xor_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>;
1315    }
1316}
1317
1318// BigInt
1319#[wasm_bindgen]
1320extern "C" {
1321    #[wasm_bindgen(extends = Object, is_type_of = |v| v.is_bigint(), typescript_type = "bigint")]
1322    #[derive(Clone, PartialEq, Eq)]
1323    pub type BigInt;
1324
1325    #[wasm_bindgen(catch, js_name = BigInt)]
1326    fn new_bigint(value: &JsValue) -> Result<BigInt, Error>;
1327
1328    #[wasm_bindgen(js_name = BigInt)]
1329    fn new_bigint_unchecked(value: &JsValue) -> BigInt;
1330
1331    /// Clamps a BigInt value to a signed integer value, and returns that value.
1332    ///
1333    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)
1334    #[wasm_bindgen(static_method_of = BigInt, js_name = asIntN)]
1335    pub fn as_int_n(bits: f64, bigint: &BigInt) -> BigInt;
1336
1337    /// Clamps a BigInt value to an unsigned integer value, and returns that value.
1338    ///
1339    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)
1340    #[wasm_bindgen(static_method_of = BigInt, js_name = asUintN)]
1341    pub fn as_uint_n(bits: f64, bigint: &BigInt) -> BigInt;
1342
1343    /// 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.
1344    ///
1345    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
1346    #[wasm_bindgen(method, js_name = toLocaleString)]
1347    pub fn to_locale_string(this: &BigInt, locales: &JsValue, options: &JsValue) -> JsString;
1348
1349    /// 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.
1350    ///
1351    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
1352    #[wasm_bindgen(catch, method, js_name = toString)]
1353    pub fn to_string(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
1354
1355    #[wasm_bindgen(method, js_name = toString)]
1356    fn to_string_unchecked(this: &BigInt, radix: u8) -> String;
1357
1358    /// Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method.
1359    ///
1360    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)
1361    #[wasm_bindgen(method, js_name = valueOf)]
1362    pub fn value_of(this: &BigInt, radix: u8) -> BigInt;
1363}
1364
1365impl BigInt {
1366    /// Creates a new BigInt value.
1367    ///
1368    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)
1369    #[inline]
1370    pub fn new(value: &JsValue) -> Result<BigInt, Error> {
1371        new_bigint(value)
1372    }
1373
1374    /// Applies the binary `/` JS operator on two `BigInt`s, catching and returning any `RangeError` thrown.
1375    ///
1376    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division)
1377    pub fn checked_div(&self, rhs: &Self) -> Result<Self, RangeError> {
1378        let result = JsValue::as_ref(self).checked_div(JsValue::as_ref(rhs));
1379
1380        if result.is_instance_of::<RangeError>() {
1381            Err(result.unchecked_into())
1382        } else {
1383            Ok(result.unchecked_into())
1384        }
1385    }
1386
1387    /// Applies the binary `**` JS operator on the two `BigInt`s.
1388    ///
1389    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
1390    #[inline]
1391    pub fn pow(&self, rhs: &Self) -> Self {
1392        JsValue::as_ref(self)
1393            .pow(JsValue::as_ref(rhs))
1394            .unchecked_into()
1395    }
1396
1397    /// Returns a tuple of this [`BigInt`]'s absolute value along with a
1398    /// [`bool`] indicating whether the [`BigInt`] was negative.
1399    fn abs(&self) -> (Self, bool) {
1400        if self < &BigInt::from(0) {
1401            (-self, true)
1402        } else {
1403            (self.clone(), false)
1404        }
1405    }
1406}
1407
1408macro_rules! bigint_from {
1409    ($($x:ident)*) => ($(
1410        impl From<$x> for BigInt {
1411            #[inline]
1412            fn from(x: $x) -> BigInt {
1413                new_bigint_unchecked(&JsValue::from(x))
1414            }
1415        }
1416
1417        impl PartialEq<$x> for BigInt {
1418            #[inline]
1419            fn eq(&self, other: &$x) -> bool {
1420                JsValue::from(self) == JsValue::from(BigInt::from(*other))
1421            }
1422        }
1423    )*)
1424}
1425bigint_from!(i8 u8 i16 u16 i32 u32 isize usize);
1426
1427macro_rules! bigint_from_big {
1428    ($($x:ident)*) => ($(
1429        impl From<$x> for BigInt {
1430            #[inline]
1431            fn from(x: $x) -> BigInt {
1432                JsValue::from(x).unchecked_into()
1433            }
1434        }
1435
1436        impl PartialEq<$x> for BigInt {
1437            #[inline]
1438            fn eq(&self, other: &$x) -> bool {
1439                self == &BigInt::from(*other)
1440            }
1441        }
1442
1443        impl TryFrom<BigInt> for $x {
1444            type Error = BigInt;
1445
1446            #[inline]
1447            fn try_from(x: BigInt) -> Result<Self, BigInt> {
1448                Self::try_from(JsValue::from(x)).map_err(JsCast::unchecked_into)
1449            }
1450        }
1451    )*)
1452}
1453bigint_from_big!(i64 u64 i128 u128);
1454
1455impl PartialEq<Number> for BigInt {
1456    #[inline]
1457    fn eq(&self, other: &Number) -> bool {
1458        JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
1459    }
1460}
1461
1462impl Not for &BigInt {
1463    type Output = BigInt;
1464
1465    #[inline]
1466    fn not(self) -> Self::Output {
1467        JsValue::as_ref(self).bit_not().unchecked_into()
1468    }
1469}
1470
1471forward_deref_unop!(impl Not, not for BigInt);
1472forward_js_unop!(impl Neg, neg for BigInt);
1473forward_js_binop!(impl BitAnd, bitand for BigInt);
1474forward_js_binop!(impl BitOr, bitor for BigInt);
1475forward_js_binop!(impl BitXor, bitxor for BigInt);
1476forward_js_binop!(impl Shl, shl for BigInt);
1477forward_js_binop!(impl Shr, shr for BigInt);
1478forward_js_binop!(impl Add, add for BigInt);
1479forward_js_binop!(impl Sub, sub for BigInt);
1480forward_js_binop!(impl Div, div for BigInt);
1481forward_js_binop!(impl Mul, mul for BigInt);
1482forward_js_binop!(impl Rem, rem for BigInt);
1483sum_product!(BigInt);
1484
1485partialord_ord!(BigInt);
1486
1487impl Default for BigInt {
1488    fn default() -> Self {
1489        BigInt::from(i32::default())
1490    }
1491}
1492
1493impl FromStr for BigInt {
1494    type Err = Error;
1495
1496    #[inline]
1497    fn from_str(s: &str) -> Result<Self, Self::Err> {
1498        BigInt::new(&s.into())
1499    }
1500}
1501
1502impl fmt::Debug for BigInt {
1503    #[inline]
1504    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1505        fmt::Display::fmt(self, f)
1506    }
1507}
1508
1509impl fmt::Display for BigInt {
1510    #[inline]
1511    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1512        let (abs, is_neg) = self.abs();
1513        f.pad_integral(!is_neg, "", &abs.to_string_unchecked(10))
1514    }
1515}
1516
1517impl fmt::Binary for BigInt {
1518    #[inline]
1519    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1520        let (abs, is_neg) = self.abs();
1521        f.pad_integral(!is_neg, "0b", &abs.to_string_unchecked(2))
1522    }
1523}
1524
1525impl fmt::Octal for BigInt {
1526    #[inline]
1527    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1528        let (abs, is_neg) = self.abs();
1529        f.pad_integral(!is_neg, "0o", &abs.to_string_unchecked(8))
1530    }
1531}
1532
1533impl fmt::LowerHex for BigInt {
1534    #[inline]
1535    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1536        let (abs, is_neg) = self.abs();
1537        f.pad_integral(!is_neg, "0x", &abs.to_string_unchecked(16))
1538    }
1539}
1540
1541impl fmt::UpperHex for BigInt {
1542    #[inline]
1543    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1544        let (abs, is_neg) = self.abs();
1545        let mut s: String = abs.to_string_unchecked(16);
1546        s.make_ascii_uppercase();
1547        f.pad_integral(!is_neg, "0x", &s)
1548    }
1549}
1550
1551// Boolean
1552#[wasm_bindgen]
1553extern "C" {
1554    #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
1555    #[derive(Clone, PartialEq, Eq)]
1556    pub type Boolean;
1557
1558    /// The `Boolean()` constructor creates an object wrapper for a boolean value.
1559    ///
1560    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
1561    #[wasm_bindgen(constructor)]
1562    #[deprecated(note = "recommended to use `Boolean::from` instead")]
1563    #[allow(deprecated)]
1564    pub fn new(value: &JsValue) -> Boolean;
1565
1566    /// The `valueOf()` method returns the primitive value of a `Boolean` object.
1567    ///
1568    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf)
1569    #[wasm_bindgen(method, js_name = valueOf)]
1570    pub fn value_of(this: &Boolean) -> bool;
1571}
1572
1573impl From<bool> for Boolean {
1574    #[inline]
1575    fn from(b: bool) -> Boolean {
1576        Boolean::unchecked_from_js(JsValue::from(b))
1577    }
1578}
1579
1580impl From<Boolean> for bool {
1581    #[inline]
1582    fn from(b: Boolean) -> bool {
1583        b.value_of()
1584    }
1585}
1586
1587impl PartialEq<bool> for Boolean {
1588    #[inline]
1589    fn eq(&self, other: &bool) -> bool {
1590        self.value_of() == *other
1591    }
1592}
1593
1594impl fmt::Debug for Boolean {
1595    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1596        fmt::Debug::fmt(&self.value_of(), f)
1597    }
1598}
1599
1600impl fmt::Display for Boolean {
1601    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1602        fmt::Display::fmt(&self.value_of(), f)
1603    }
1604}
1605
1606impl Default for Boolean {
1607    fn default() -> Self {
1608        Self::from(bool::default())
1609    }
1610}
1611
1612impl Not for &Boolean {
1613    type Output = Boolean;
1614
1615    #[inline]
1616    fn not(self) -> Self::Output {
1617        (!JsValue::as_ref(self)).into()
1618    }
1619}
1620
1621forward_deref_unop!(impl Not, not for Boolean);
1622
1623partialord_ord!(Boolean);
1624
1625// DataView
1626#[wasm_bindgen]
1627extern "C" {
1628    #[wasm_bindgen(extends = Object, typescript_type = "DataView")]
1629    #[derive(Clone, Debug, PartialEq, Eq)]
1630    pub type DataView;
1631
1632    /// The `DataView` view provides a low-level interface for reading and
1633    /// writing multiple number types in an `ArrayBuffer` irrespective of the
1634    /// platform's endianness.
1635    ///
1636    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
1637    #[wasm_bindgen(constructor)]
1638    pub fn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView;
1639
1640    /// The `DataView` view provides a low-level interface for reading and
1641    /// writing multiple number types in an `ArrayBuffer` irrespective of the
1642    /// platform's endianness.
1643    ///
1644    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
1645    #[wasm_bindgen(constructor)]
1646    pub fn new_with_shared_array_buffer(
1647        buffer: &SharedArrayBuffer,
1648        byteOffset: usize,
1649        byteLength: usize,
1650    ) -> DataView;
1651
1652    /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
1653    ///
1654    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer)
1655    #[wasm_bindgen(method, getter, structural)]
1656    pub fn buffer(this: &DataView) -> ArrayBuffer;
1657
1658    /// The length (in bytes) of this view from the start of its ArrayBuffer.
1659    /// Fixed at construction time and thus read only.
1660    ///
1661    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength)
1662    #[wasm_bindgen(method, getter, structural, js_name = byteLength)]
1663    pub fn byte_length(this: &DataView) -> usize;
1664
1665    /// The offset (in bytes) of this view from the start of its ArrayBuffer.
1666    /// Fixed at construction time and thus read only.
1667    ///
1668    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset)
1669    #[wasm_bindgen(method, getter, structural, js_name = byteOffset)]
1670    pub fn byte_offset(this: &DataView) -> usize;
1671
1672    /// The `getInt8()` method gets a signed 8-bit integer (byte) at the
1673    /// specified byte offset from the start of the DataView.
1674    ///
1675    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8)
1676    #[wasm_bindgen(method, js_name = getInt8)]
1677    pub fn get_int8(this: &DataView, byte_offset: usize) -> i8;
1678
1679    /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified
1680    /// byte offset from the start of the DataView.
1681    ///
1682    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8)
1683    #[wasm_bindgen(method, js_name = getUint8)]
1684    pub fn get_uint8(this: &DataView, byte_offset: usize) -> u8;
1685
1686    /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
1687    /// byte offset from the start of the DataView.
1688    ///
1689    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
1690    #[wasm_bindgen(method, js_name = getInt16)]
1691    pub fn get_int16(this: &DataView, byte_offset: usize) -> i16;
1692
1693    /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
1694    /// byte offset from the start of the DataView.
1695    ///
1696    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
1697    #[wasm_bindgen(method, js_name = getInt16)]
1698    pub fn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16;
1699
1700    /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
1701    /// byte offset from the start of the view.
1702    ///
1703    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
1704    #[wasm_bindgen(method, js_name = getUint16)]
1705    pub fn get_uint16(this: &DataView, byte_offset: usize) -> u16;
1706
1707    /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
1708    /// byte offset from the start of the view.
1709    ///
1710    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
1711    #[wasm_bindgen(method, js_name = getUint16)]
1712    pub fn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16;
1713
1714    /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
1715    /// byte offset from the start of the DataView.
1716    ///
1717    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
1718    #[wasm_bindgen(method, js_name = getInt32)]
1719    pub fn get_int32(this: &DataView, byte_offset: usize) -> i32;
1720
1721    /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
1722    /// byte offset from the start of the DataView.
1723    ///
1724    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
1725    #[wasm_bindgen(method, js_name = getInt32)]
1726    pub fn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32;
1727
1728    /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
1729    /// byte offset from the start of the view.
1730    ///
1731    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
1732    #[wasm_bindgen(method, js_name = getUint32)]
1733    pub fn get_uint32(this: &DataView, byte_offset: usize) -> u32;
1734
1735    /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
1736    /// byte offset from the start of the view.
1737    ///
1738    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
1739    #[wasm_bindgen(method, js_name = getUint32)]
1740    pub fn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32;
1741
1742    /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
1743    /// byte offset from the start of the DataView.
1744    ///
1745    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
1746    #[wasm_bindgen(method, js_name = getFloat32)]
1747    pub fn get_float32(this: &DataView, byte_offset: usize) -> f32;
1748
1749    /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
1750    /// byte offset from the start of the DataView.
1751    ///
1752    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
1753    #[wasm_bindgen(method, js_name = getFloat32)]
1754    pub fn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32;
1755
1756    /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
1757    /// byte offset from the start of the DataView.
1758    ///
1759    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
1760    #[wasm_bindgen(method, js_name = getFloat64)]
1761    pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
1762
1763    /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
1764    /// byte offset from the start of the DataView.
1765    ///
1766    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
1767    #[wasm_bindgen(method, js_name = getFloat64)]
1768    pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
1769
1770    /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
1771    /// specified byte offset from the start of the DataView.
1772    ///
1773    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
1774    #[wasm_bindgen(method, js_name = setInt8)]
1775    pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
1776
1777    /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
1778    /// specified byte offset from the start of the DataView.
1779    ///
1780    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
1781    #[wasm_bindgen(method, js_name = setUint8)]
1782    pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
1783
1784    /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
1785    /// specified byte offset from the start of the DataView.
1786    ///
1787    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
1788    #[wasm_bindgen(method, js_name = setInt16)]
1789    pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
1790
1791    /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
1792    /// specified byte offset from the start of the DataView.
1793    ///
1794    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
1795    #[wasm_bindgen(method, js_name = setInt16)]
1796    pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
1797
1798    /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
1799    /// specified byte offset from the start of the DataView.
1800    ///
1801    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
1802    #[wasm_bindgen(method, js_name = setUint16)]
1803    pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
1804
1805    /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
1806    /// specified byte offset from the start of the DataView.
1807    ///
1808    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
1809    #[wasm_bindgen(method, js_name = setUint16)]
1810    pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
1811
1812    /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
1813    /// specified byte offset from the start of the DataView.
1814    ///
1815    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
1816    #[wasm_bindgen(method, js_name = setInt32)]
1817    pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
1818
1819    /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
1820    /// specified byte offset from the start of the DataView.
1821    ///
1822    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
1823    #[wasm_bindgen(method, js_name = setInt32)]
1824    pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
1825
1826    /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
1827    /// specified byte offset from the start of the DataView.
1828    ///
1829    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
1830    #[wasm_bindgen(method, js_name = setUint32)]
1831    pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
1832
1833    /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
1834    /// specified byte offset from the start of the DataView.
1835    ///
1836    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
1837    #[wasm_bindgen(method, js_name = setUint32)]
1838    pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
1839
1840    /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
1841    /// specified byte offset from the start of the DataView.
1842    ///
1843    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
1844    #[wasm_bindgen(method, js_name = setFloat32)]
1845    pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
1846
1847    /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
1848    /// specified byte offset from the start of the DataView.
1849    ///
1850    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
1851    #[wasm_bindgen(method, js_name = setFloat32)]
1852    pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
1853
1854    /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
1855    /// specified byte offset from the start of the DataView.
1856    ///
1857    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
1858    #[wasm_bindgen(method, js_name = setFloat64)]
1859    pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
1860
1861    /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
1862    /// specified byte offset from the start of the DataView.
1863    ///
1864    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
1865    #[wasm_bindgen(method, js_name = setFloat64)]
1866    pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
1867}
1868
1869// Error
1870#[wasm_bindgen]
1871extern "C" {
1872    #[wasm_bindgen(extends = Object, typescript_type = "Error")]
1873    #[derive(Clone, Debug, PartialEq, Eq)]
1874    pub type Error;
1875
1876    /// The Error constructor creates an error object.
1877    /// Instances of Error objects are thrown when runtime errors occur.
1878    /// The Error object can also be used as a base object for user-defined exceptions.
1879    /// See below for standard built-in error types.
1880    ///
1881    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
1882    #[wasm_bindgen(constructor)]
1883    pub fn new(message: &str) -> Error;
1884    #[wasm_bindgen(constructor)]
1885    pub fn new_with_options(message: &str, options: &Object) -> Error;
1886
1887    /// The cause property is the underlying cause of the error.
1888    /// Usually this is used to add context to re-thrown errors.
1889    ///
1890    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors)
1891    #[wasm_bindgen(method, getter, structural)]
1892    pub fn cause(this: &Error) -> JsValue;
1893    #[wasm_bindgen(method, setter, structural)]
1894    pub fn set_cause(this: &Error, cause: &JsValue);
1895
1896    /// The message property is a human-readable description of the error.
1897    ///
1898    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
1899    #[wasm_bindgen(method, getter, structural)]
1900    pub fn message(this: &Error) -> JsString;
1901    #[wasm_bindgen(method, setter, structural)]
1902    pub fn set_message(this: &Error, message: &str);
1903
1904    /// The name property represents a name for the type of error. The initial value is "Error".
1905    ///
1906    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
1907    #[wasm_bindgen(method, getter, structural)]
1908    pub fn name(this: &Error) -> JsString;
1909    #[wasm_bindgen(method, setter, structural)]
1910    pub fn set_name(this: &Error, name: &str);
1911
1912    /// The `toString()` method returns a string representing the specified Error object
1913    ///
1914    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
1915    #[wasm_bindgen(method, js_name = toString)]
1916    pub fn to_string(this: &Error) -> JsString;
1917}
1918
1919partialord_ord!(JsString);
1920
1921// EvalError
1922#[wasm_bindgen]
1923extern "C" {
1924    #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
1925    #[derive(Clone, Debug, PartialEq, Eq)]
1926    pub type EvalError;
1927
1928    /// The EvalError object indicates an error regarding the global eval() function. This
1929    /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
1930    /// compatibility.
1931    ///
1932    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
1933    #[wasm_bindgen(constructor)]
1934    pub fn new(message: &str) -> EvalError;
1935}
1936
1937// Function
1938#[wasm_bindgen]
1939extern "C" {
1940    #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, typescript_type = "Function")]
1941    #[derive(Clone, Debug, PartialEq, Eq)]
1942    pub type Function;
1943
1944    /// The `Function` constructor creates a new `Function` object. Calling the
1945    /// constructor directly can create functions dynamically, but suffers from
1946    /// security and similar (but far less significant) performance issues
1947    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
1948    /// allows executing code in the global scope, prompting better programming
1949    /// habits and allowing for more efficient code minification.
1950    ///
1951    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
1952    #[wasm_bindgen(constructor)]
1953    pub fn new_with_args(args: &str, body: &str) -> Function;
1954
1955    /// The `Function` constructor creates a new `Function` object. Calling the
1956    /// constructor directly can create functions dynamically, but suffers from
1957    /// security and similar (but far less significant) performance issues
1958    /// similar to `eval`. However, unlike `eval`, the `Function` constructor
1959    /// allows executing code in the global scope, prompting better programming
1960    /// habits and allowing for more efficient code minification.
1961    ///
1962    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
1963    #[wasm_bindgen(constructor)]
1964    pub fn new_no_args(body: &str) -> Function;
1965
1966    /// The `apply()` method calls a function with a given this value, and arguments provided as an array
1967    /// (or an array-like object).
1968    ///
1969    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
1970    #[wasm_bindgen(method, catch)]
1971    pub fn apply(this: &Function, context: &JsValue, args: &Array) -> Result<JsValue, JsValue>;
1972
1973    /// The `call()` method calls a function with a given this value and
1974    /// arguments provided individually.
1975    ///
1976    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
1977    #[wasm_bindgen(method, catch, js_name = call)]
1978    pub fn call0(this: &Function, context: &JsValue) -> Result<JsValue, JsValue>;
1979
1980    /// The `call()` method calls a function with a given this value and
1981    /// arguments provided individually.
1982    ///
1983    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
1984    #[wasm_bindgen(method, catch, js_name = call)]
1985    pub fn call1(this: &Function, context: &JsValue, arg1: &JsValue) -> Result<JsValue, JsValue>;
1986
1987    /// The `call()` method calls a function with a given this value and
1988    /// arguments provided individually.
1989    ///
1990    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
1991    #[wasm_bindgen(method, catch, js_name = call)]
1992    pub fn call2(
1993        this: &Function,
1994        context: &JsValue,
1995        arg1: &JsValue,
1996        arg2: &JsValue,
1997    ) -> Result<JsValue, JsValue>;
1998
1999    /// The `call()` method calls a function with a given this value and
2000    /// arguments provided individually.
2001    ///
2002    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2003    #[wasm_bindgen(method, catch, js_name = call)]
2004    pub fn call3(
2005        this: &Function,
2006        context: &JsValue,
2007        arg1: &JsValue,
2008        arg2: &JsValue,
2009        arg3: &JsValue,
2010    ) -> Result<JsValue, JsValue>;
2011
2012    /// The `call()` method calls a function with a given this value and
2013    /// arguments provided individually.
2014    ///
2015    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2016    #[wasm_bindgen(method, catch, js_name = call)]
2017    pub fn call4(
2018        this: &Function,
2019        context: &JsValue,
2020        arg1: &JsValue,
2021        arg2: &JsValue,
2022        arg3: &JsValue,
2023        arg4: &JsValue,
2024    ) -> Result<JsValue, JsValue>;
2025
2026    /// The `call()` method calls a function with a given this value and
2027    /// arguments provided individually.
2028    ///
2029    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2030    #[wasm_bindgen(method, catch, js_name = call)]
2031    pub fn call5(
2032        this: &Function,
2033        context: &JsValue,
2034        arg1: &JsValue,
2035        arg2: &JsValue,
2036        arg3: &JsValue,
2037        arg4: &JsValue,
2038        arg5: &JsValue,
2039    ) -> Result<JsValue, JsValue>;
2040
2041    /// The `call()` method calls a function with a given this value and
2042    /// arguments provided individually.
2043    ///
2044    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2045    #[wasm_bindgen(method, catch, js_name = call)]
2046    pub fn call6(
2047        this: &Function,
2048        context: &JsValue,
2049        arg1: &JsValue,
2050        arg2: &JsValue,
2051        arg3: &JsValue,
2052        arg4: &JsValue,
2053        arg5: &JsValue,
2054        arg6: &JsValue,
2055    ) -> Result<JsValue, JsValue>;
2056
2057    /// The `call()` method calls a function with a given this value and
2058    /// arguments provided individually.
2059    ///
2060    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2061    #[wasm_bindgen(method, catch, js_name = call)]
2062    pub fn call7(
2063        this: &Function,
2064        context: &JsValue,
2065        arg1: &JsValue,
2066        arg2: &JsValue,
2067        arg3: &JsValue,
2068        arg4: &JsValue,
2069        arg5: &JsValue,
2070        arg6: &JsValue,
2071        arg7: &JsValue,
2072    ) -> Result<JsValue, JsValue>;
2073
2074    /// The `call()` method calls a function with a given this value and
2075    /// arguments provided individually.
2076    ///
2077    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2078    #[wasm_bindgen(method, catch, js_name = call)]
2079    pub fn call8(
2080        this: &Function,
2081        context: &JsValue,
2082        arg1: &JsValue,
2083        arg2: &JsValue,
2084        arg3: &JsValue,
2085        arg4: &JsValue,
2086        arg5: &JsValue,
2087        arg6: &JsValue,
2088        arg7: &JsValue,
2089        arg8: &JsValue,
2090    ) -> Result<JsValue, JsValue>;
2091
2092    /// The `call()` method calls a function with a given this value and
2093    /// arguments provided individually.
2094    ///
2095    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2096    #[wasm_bindgen(method, catch, js_name = call)]
2097    pub fn call9(
2098        this: &Function,
2099        context: &JsValue,
2100        arg1: &JsValue,
2101        arg2: &JsValue,
2102        arg3: &JsValue,
2103        arg4: &JsValue,
2104        arg5: &JsValue,
2105        arg6: &JsValue,
2106        arg7: &JsValue,
2107        arg8: &JsValue,
2108        arg9: &JsValue,
2109    ) -> Result<JsValue, JsValue>;
2110
2111    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2112    /// with a given sequence of arguments preceding any provided when the new function is called.
2113    ///
2114    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2115    #[wasm_bindgen(method, js_name = bind)]
2116    pub fn bind(this: &Function, context: &JsValue) -> Function;
2117
2118    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2119    /// with a given sequence of arguments preceding any provided when the new function is called.
2120    ///
2121    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2122    #[wasm_bindgen(method, js_name = bind)]
2123    pub fn bind0(this: &Function, context: &JsValue) -> Function;
2124
2125    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2126    /// with a given sequence of arguments preceding any provided when the new function is called.
2127    ///
2128    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2129    #[wasm_bindgen(method, js_name = bind)]
2130    pub fn bind1(this: &Function, context: &JsValue, arg1: &JsValue) -> Function;
2131
2132    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2133    /// with a given sequence of arguments preceding any provided when the new function is called.
2134    ///
2135    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2136    #[wasm_bindgen(method, js_name = bind)]
2137    pub fn bind2(this: &Function, context: &JsValue, arg1: &JsValue, arg2: &JsValue) -> Function;
2138
2139    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2140    /// with a given sequence of arguments preceding any provided when the new function is called.
2141    ///
2142    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2143    #[wasm_bindgen(method, js_name = bind)]
2144    pub fn bind3(
2145        this: &Function,
2146        context: &JsValue,
2147        arg1: &JsValue,
2148        arg2: &JsValue,
2149        arg3: &JsValue,
2150    ) -> Function;
2151
2152    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2153    /// with a given sequence of arguments preceding any provided when the new function is called.
2154    ///
2155    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2156    #[wasm_bindgen(method, js_name = bind)]
2157    pub fn bind4(
2158        this: &Function,
2159        context: &JsValue,
2160        arg1: &JsValue,
2161        arg2: &JsValue,
2162        arg3: &JsValue,
2163        arg4: &JsValue,
2164    ) -> Function;
2165
2166    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2167    /// with a given sequence of arguments preceding any provided when the new function is called.
2168    ///
2169    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2170    #[wasm_bindgen(method, js_name = bind)]
2171    pub fn bind5(
2172        this: &Function,
2173        context: &JsValue,
2174        arg1: &JsValue,
2175        arg2: &JsValue,
2176        arg3: &JsValue,
2177        arg4: &JsValue,
2178        arg5: &JsValue,
2179    ) -> Function;
2180
2181    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2182    /// with a given sequence of arguments preceding any provided when the new function is called.
2183    ///
2184    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2185    #[wasm_bindgen(method, js_name = bind)]
2186    pub fn bind6(
2187        this: &Function,
2188        context: &JsValue,
2189        arg1: &JsValue,
2190        arg2: &JsValue,
2191        arg3: &JsValue,
2192        arg4: &JsValue,
2193        arg5: &JsValue,
2194        arg6: &JsValue,
2195    ) -> Function;
2196
2197    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2198    /// with a given sequence of arguments preceding any provided when the new function is called.
2199    ///
2200    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2201    #[wasm_bindgen(method, js_name = bind)]
2202    pub fn bind7(
2203        this: &Function,
2204        context: &JsValue,
2205        arg1: &JsValue,
2206        arg2: &JsValue,
2207        arg3: &JsValue,
2208        arg4: &JsValue,
2209        arg5: &JsValue,
2210        arg6: &JsValue,
2211        arg7: &JsValue,
2212    ) -> Function;
2213
2214    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2215    /// with a given sequence of arguments preceding any provided when the new function is called.
2216    ///
2217    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2218    #[wasm_bindgen(method, js_name = bind)]
2219    pub fn bind8(
2220        this: &Function,
2221        context: &JsValue,
2222        arg1: &JsValue,
2223        arg2: &JsValue,
2224        arg3: &JsValue,
2225        arg4: &JsValue,
2226        arg5: &JsValue,
2227        arg6: &JsValue,
2228        arg7: &JsValue,
2229        arg8: &JsValue,
2230    ) -> Function;
2231
2232    /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2233    /// with a given sequence of arguments preceding any provided when the new function is called.
2234    ///
2235    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2236    #[wasm_bindgen(method, js_name = bind)]
2237    pub fn bind9(
2238        this: &Function,
2239        context: &JsValue,
2240        arg1: &JsValue,
2241        arg2: &JsValue,
2242        arg3: &JsValue,
2243        arg4: &JsValue,
2244        arg5: &JsValue,
2245        arg6: &JsValue,
2246        arg7: &JsValue,
2247        arg8: &JsValue,
2248        arg9: &JsValue,
2249    ) -> Function;
2250
2251    /// The length property indicates the number of arguments expected by the function.
2252    ///
2253    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
2254    #[wasm_bindgen(method, getter, structural)]
2255    pub fn length(this: &Function) -> u32;
2256
2257    /// A Function object's read-only name property indicates the function's
2258    /// name as specified when it was created or "anonymous" for functions
2259    /// created anonymously.
2260    ///
2261    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
2262    #[wasm_bindgen(method, getter, structural)]
2263    pub fn name(this: &Function) -> JsString;
2264
2265    /// The `toString()` method returns a string representing the source code of the function.
2266    ///
2267    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
2268    #[wasm_bindgen(method, js_name = toString)]
2269    pub fn to_string(this: &Function) -> JsString;
2270}
2271
2272impl Function {
2273    /// Returns the `Function` value of this JS value if it's an instance of a
2274    /// function.
2275    ///
2276    /// If this JS value is not an instance of a function then this returns
2277    /// `None`.
2278    #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
2279    pub fn try_from(val: &JsValue) -> Option<&Function> {
2280        val.dyn_ref()
2281    }
2282}
2283
2284impl Default for Function {
2285    fn default() -> Self {
2286        Self::new_no_args("")
2287    }
2288}
2289
2290// Generator
2291#[wasm_bindgen]
2292extern "C" {
2293    #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
2294    #[derive(Clone, Debug, PartialEq, Eq)]
2295    pub type Generator;
2296
2297    /// The `next()` method returns an object with two properties done and value.
2298    /// You can also provide a parameter to the next method to send a value to the generator.
2299    ///
2300    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
2301    #[wasm_bindgen(method, structural, catch)]
2302    pub fn next(this: &Generator, value: &JsValue) -> Result<JsValue, JsValue>;
2303
2304    /// The `return()` method returns the given value and finishes the generator.
2305    ///
2306    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
2307    #[wasm_bindgen(method, structural, js_name = return)]
2308    pub fn return_(this: &Generator, value: &JsValue) -> JsValue;
2309
2310    /// The `throw()` method resumes the execution of a generator by throwing an error into it
2311    /// and returns an object with two properties done and value.
2312    ///
2313    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
2314    #[wasm_bindgen(method, structural, catch)]
2315    pub fn throw(this: &Generator, error: &Error) -> Result<JsValue, JsValue>;
2316}
2317
2318// Map
2319#[wasm_bindgen]
2320extern "C" {
2321    #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
2322    #[derive(Clone, Debug, PartialEq, Eq)]
2323    pub type Map;
2324
2325    /// The `clear()` method removes all elements from a Map object.
2326    ///
2327    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
2328    #[wasm_bindgen(method)]
2329    pub fn clear(this: &Map);
2330
2331    /// The `delete()` method removes the specified element from a Map object.
2332    ///
2333    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
2334    #[wasm_bindgen(method)]
2335    pub fn delete(this: &Map, key: &JsValue) -> bool;
2336
2337    /// The `forEach()` method executes a provided function once per each
2338    /// key/value pair in the Map object, in insertion order.
2339    /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
2340    /// # Examples
2341    /// ```
2342    /// let js_map = Map::new();
2343    /// js_map.for_each(&mut |value, key| {
2344    ///     // Do something here...
2345    /// })
2346    /// ```
2347    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
2348    #[wasm_bindgen(method, js_name = forEach)]
2349    pub fn for_each(this: &Map, callback: &mut dyn FnMut(JsValue, JsValue));
2350
2351    /// The `get()` method returns a specified element from a Map object.
2352    ///
2353    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
2354    #[wasm_bindgen(method)]
2355    pub fn get(this: &Map, key: &JsValue) -> JsValue;
2356
2357    /// The `has()` method returns a boolean indicating whether an element with
2358    /// the specified key exists or not.
2359    ///
2360    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
2361    #[wasm_bindgen(method)]
2362    pub fn has(this: &Map, key: &JsValue) -> bool;
2363
2364    /// The Map object holds key-value pairs. Any value (both objects and
2365    /// primitive values) maybe used as either a key or a value.
2366    ///
2367    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
2368    #[wasm_bindgen(constructor)]
2369    pub fn new() -> Map;
2370
2371    /// The `set()` method adds or updates an element with a specified key
2372    /// and value to a Map object.
2373    ///
2374    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
2375    #[wasm_bindgen(method)]
2376    pub fn set(this: &Map, key: &JsValue, value: &JsValue) -> Map;
2377
2378    /// The value of size is an integer representing how many entries
2379    /// the Map object has. A set accessor function for size is undefined;
2380    /// you can not change this property.
2381    ///
2382    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
2383    #[wasm_bindgen(method, getter, structural)]
2384    pub fn size(this: &Map) -> u32;
2385}
2386
2387impl Default for Map {
2388    fn default() -> Self {
2389        Self::new()
2390    }
2391}
2392
2393// Map Iterator
2394#[wasm_bindgen]
2395extern "C" {
2396    /// The `entries()` method returns a new Iterator object that contains
2397    /// the [key, value] pairs for each element in the Map object in
2398    /// insertion order.
2399    ///
2400    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
2401    #[wasm_bindgen(method)]
2402    pub fn entries(this: &Map) -> Iterator;
2403
2404    /// The `keys()` method returns a new Iterator object that contains the
2405    /// keys for each element in the Map object in insertion order.
2406    ///
2407    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
2408    #[wasm_bindgen(method)]
2409    pub fn keys(this: &Map) -> Iterator;
2410
2411    /// The `values()` method returns a new Iterator object that contains the
2412    /// values for each element in the Map object in insertion order.
2413    ///
2414    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values)
2415    #[wasm_bindgen(method)]
2416    pub fn values(this: &Map) -> Iterator;
2417}
2418
2419// Iterator
2420#[wasm_bindgen]
2421extern "C" {
2422    /// Any object that conforms to the JS iterator protocol. For example,
2423    /// something returned by `myArray[Symbol.iterator]()`.
2424    ///
2425    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
2426    #[derive(Clone, Debug)]
2427    #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
2428    pub type Iterator;
2429
2430    /// The `next()` method always has to return an object with appropriate
2431    /// properties including done and value. If a non-object value gets returned
2432    /// (such as false or undefined), a TypeError ("iterator.next() returned a
2433    /// non-object value") will be thrown.
2434    #[wasm_bindgen(catch, method, structural)]
2435    pub fn next(this: &Iterator) -> Result<IteratorNext, JsValue>;
2436}
2437
2438impl Iterator {
2439    fn looks_like_iterator(it: &JsValue) -> bool {
2440        #[wasm_bindgen]
2441        extern "C" {
2442            type MaybeIterator;
2443
2444            #[wasm_bindgen(method, getter)]
2445            fn next(this: &MaybeIterator) -> JsValue;
2446        }
2447
2448        if !it.is_object() {
2449            return false;
2450        }
2451
2452        let it = it.unchecked_ref::<MaybeIterator>();
2453
2454        it.next().is_function()
2455    }
2456}
2457
2458// Async Iterator
2459#[wasm_bindgen]
2460extern "C" {
2461    /// Any object that conforms to the JS async iterator protocol. For example,
2462    /// something returned by `myObject[Symbol.asyncIterator]()`.
2463    ///
2464    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
2465    #[derive(Clone, Debug)]
2466    #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>")]
2467    pub type AsyncIterator;
2468
2469    /// The `next()` method always has to return a Promise which resolves to an object
2470    /// with appropriate properties including done and value. If a non-object value
2471    /// gets returned (such as false or undefined), a TypeError ("iterator.next()
2472    /// returned a non-object value") will be thrown.
2473    #[wasm_bindgen(catch, method, structural)]
2474    pub fn next(this: &AsyncIterator) -> Result<Promise, JsValue>;
2475}
2476
2477/// An iterator over the JS `Symbol.iterator` iteration protocol.
2478///
2479/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
2480pub struct Iter<'a> {
2481    js: &'a Iterator,
2482    state: IterState,
2483}
2484
2485/// An iterator over the JS `Symbol.iterator` iteration protocol.
2486///
2487/// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
2488pub struct IntoIter {
2489    js: Iterator,
2490    state: IterState,
2491}
2492
2493struct IterState {
2494    done: bool,
2495}
2496
2497impl<'a> IntoIterator for &'a Iterator {
2498    type Item = Result<JsValue, JsValue>;
2499    type IntoIter = Iter<'a>;
2500
2501    fn into_iter(self) -> Iter<'a> {
2502        Iter {
2503            js: self,
2504            state: IterState::new(),
2505        }
2506    }
2507}
2508
2509impl core::iter::Iterator for Iter<'_> {
2510    type Item = Result<JsValue, JsValue>;
2511
2512    fn next(&mut self) -> Option<Self::Item> {
2513        self.state.next(self.js)
2514    }
2515}
2516
2517impl IntoIterator for Iterator {
2518    type Item = Result<JsValue, JsValue>;
2519    type IntoIter = IntoIter;
2520
2521    fn into_iter(self) -> IntoIter {
2522        IntoIter {
2523            js: self,
2524            state: IterState::new(),
2525        }
2526    }
2527}
2528
2529impl core::iter::Iterator for IntoIter {
2530    type Item = Result<JsValue, JsValue>;
2531
2532    fn next(&mut self) -> Option<Self::Item> {
2533        self.state.next(&self.js)
2534    }
2535}
2536
2537impl IterState {
2538    fn new() -> IterState {
2539        IterState { done: false }
2540    }
2541
2542    fn next(&mut self, js: &Iterator) -> Option<Result<JsValue, JsValue>> {
2543        if self.done {
2544            return None;
2545        }
2546        let next = match js.next() {
2547            Ok(val) => val,
2548            Err(e) => {
2549                self.done = true;
2550                return Some(Err(e));
2551            }
2552        };
2553        if next.done() {
2554            self.done = true;
2555            None
2556        } else {
2557            Some(Ok(next.value()))
2558        }
2559    }
2560}
2561
2562/// Create an iterator over `val` using the JS iteration protocol and
2563/// `Symbol.iterator`.
2564pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter>, JsValue> {
2565    let iter_sym = Symbol::iterator();
2566    let iter_fn = Reflect::get(val, iter_sym.as_ref())?;
2567
2568    let iter_fn: Function = match iter_fn.dyn_into() {
2569        Ok(iter_fn) => iter_fn,
2570        Err(_) => return Ok(None),
2571    };
2572
2573    let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
2574        Ok(it) => it,
2575        Err(_) => return Ok(None),
2576    };
2577
2578    Ok(Some(it.into_iter()))
2579}
2580
2581// IteratorNext
2582#[wasm_bindgen]
2583extern "C" {
2584    /// The result of calling `next()` on a JS iterator.
2585    ///
2586    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
2587    #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
2588    #[derive(Clone, Debug, PartialEq, Eq)]
2589    pub type IteratorNext;
2590
2591    /// Has the value `true` if the iterator is past the end of the iterated
2592    /// sequence. In this case value optionally specifies the return value of
2593    /// the iterator.
2594    ///
2595    /// Has the value `false` if the iterator was able to produce the next value
2596    /// in the sequence. This is equivalent of not specifying the done property
2597    /// altogether.
2598    #[wasm_bindgen(method, getter, structural)]
2599    pub fn done(this: &IteratorNext) -> bool;
2600
2601    /// Any JavaScript value returned by the iterator. Can be omitted when done
2602    /// is true.
2603    #[wasm_bindgen(method, getter, structural)]
2604    pub fn value(this: &IteratorNext) -> JsValue;
2605}
2606
2607#[allow(non_snake_case)]
2608pub mod Math {
2609    use super::*;
2610
2611    // Math
2612    #[wasm_bindgen]
2613    extern "C" {
2614        /// The `Math.abs()` function returns the absolute value of a number, that is
2615        /// Math.abs(x) = |x|
2616        ///
2617        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
2618        #[wasm_bindgen(js_namespace = Math)]
2619        pub fn abs(x: f64) -> f64;
2620
2621        /// The `Math.acos()` function returns the arccosine (in radians) of a
2622        /// number, that is ∀x∊[-1;1]
2623        /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
2624        ///
2625        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
2626        #[wasm_bindgen(js_namespace = Math)]
2627        pub fn acos(x: f64) -> f64;
2628
2629        /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
2630        /// number, that is ∀x ≥ 1
2631        /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
2632        ///
2633        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
2634        #[wasm_bindgen(js_namespace = Math)]
2635        pub fn acosh(x: f64) -> f64;
2636
2637        /// The `Math.asin()` function returns the arcsine (in radians) of a
2638        /// number, that is ∀x ∊ [-1;1]
2639        /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
2640        ///
2641        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
2642        #[wasm_bindgen(js_namespace = Math)]
2643        pub fn asin(x: f64) -> f64;
2644
2645        /// The `Math.asinh()` function returns the hyperbolic arcsine of a
2646        /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
2647        ///
2648        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
2649        #[wasm_bindgen(js_namespace = Math)]
2650        pub fn asinh(x: f64) -> f64;
2651
2652        /// The `Math.atan()` function returns the arctangent (in radians) of a
2653        /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
2654        /// tan(y) = x
2655        #[wasm_bindgen(js_namespace = Math)]
2656        pub fn atan(x: f64) -> f64;
2657
2658        /// The `Math.atan2()` function returns the arctangent of the quotient of
2659        /// its arguments.
2660        ///
2661        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
2662        #[wasm_bindgen(js_namespace = Math)]
2663        pub fn atan2(y: f64, x: f64) -> f64;
2664
2665        /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
2666        /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
2667        /// tanh(y) = x
2668        ///
2669        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
2670        #[wasm_bindgen(js_namespace = Math)]
2671        pub fn atanh(x: f64) -> f64;
2672
2673        /// The `Math.cbrt() `function returns the cube root of a number, that is
2674        /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
2675        ///
2676        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
2677        #[wasm_bindgen(js_namespace = Math)]
2678        pub fn cbrt(x: f64) -> f64;
2679
2680        /// The `Math.ceil()` function returns the smallest integer greater than
2681        /// or equal to a given number.
2682        ///
2683        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
2684        #[wasm_bindgen(js_namespace = Math)]
2685        pub fn ceil(x: f64) -> f64;
2686
2687        /// The `Math.clz32()` function returns the number of leading zero bits in
2688        /// the 32-bit binary representation of a number.
2689        ///
2690        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
2691        #[wasm_bindgen(js_namespace = Math)]
2692        pub fn clz32(x: i32) -> u32;
2693
2694        /// The `Math.cos()` static function returns the cosine of the specified angle,
2695        /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
2696        ///
2697        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
2698        #[wasm_bindgen(js_namespace = Math)]
2699        pub fn cos(x: f64) -> f64;
2700
2701        /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
2702        /// that can be expressed using the constant e.
2703        ///
2704        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
2705        #[wasm_bindgen(js_namespace = Math)]
2706        pub fn cosh(x: f64) -> f64;
2707
2708        /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
2709        /// (also known as Napier's constant), the base of the natural logarithms.
2710        ///
2711        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
2712        #[wasm_bindgen(js_namespace = Math)]
2713        pub fn exp(x: f64) -> f64;
2714
2715        /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
2716        /// natural logarithms.
2717        ///
2718        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
2719        #[wasm_bindgen(js_namespace = Math)]
2720        pub fn expm1(x: f64) -> f64;
2721
2722        /// The `Math.floor()` function returns the largest integer less than or
2723        /// equal to a given number.
2724        ///
2725        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
2726        #[wasm_bindgen(js_namespace = Math)]
2727        pub fn floor(x: f64) -> f64;
2728
2729        /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
2730        /// of a Number.
2731        ///
2732        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
2733        #[wasm_bindgen(js_namespace = Math)]
2734        pub fn fround(x: f64) -> f32;
2735
2736        /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
2737        ///
2738        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
2739        #[wasm_bindgen(js_namespace = Math)]
2740        pub fn hypot(x: f64, y: f64) -> f64;
2741
2742        /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
2743        /// two parameters.
2744        ///
2745        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
2746        #[wasm_bindgen(js_namespace = Math)]
2747        pub fn imul(x: i32, y: i32) -> i32;
2748
2749        /// The `Math.log()` function returns the natural logarithm (base e) of a number.
2750        /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
2751        ///
2752        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
2753        #[wasm_bindgen(js_namespace = Math)]
2754        pub fn log(x: f64) -> f64;
2755
2756        /// The `Math.log10()` function returns the base 10 logarithm of a number.
2757        ///
2758        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
2759        #[wasm_bindgen(js_namespace = Math)]
2760        pub fn log10(x: f64) -> f64;
2761
2762        /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
2763        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
2764        #[wasm_bindgen(js_namespace = Math)]
2765        pub fn log1p(x: f64) -> f64;
2766
2767        /// The `Math.log2()` function returns the base 2 logarithm of a number.
2768        ///
2769        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
2770        #[wasm_bindgen(js_namespace = Math)]
2771        pub fn log2(x: f64) -> f64;
2772
2773        /// The `Math.max()` function returns the largest of two numbers.
2774        ///
2775        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
2776        #[wasm_bindgen(js_namespace = Math)]
2777        pub fn max(x: f64, y: f64) -> f64;
2778
2779        /// The static function `Math.min()` returns the lowest-valued number passed into it.
2780        ///
2781        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
2782        #[wasm_bindgen(js_namespace = Math)]
2783        pub fn min(x: f64, y: f64) -> f64;
2784
2785        /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
2786        ///
2787        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
2788        #[wasm_bindgen(js_namespace = Math)]
2789        pub fn pow(base: f64, exponent: f64) -> f64;
2790
2791        /// The `Math.random()` function returns a floating-point, pseudo-random number
2792        /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
2793        /// over that range — which you can then scale to your desired range.
2794        /// The implementation selects the initial seed to the random number generation algorithm;
2795        /// it cannot be chosen or reset by the user.
2796        ///
2797        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
2798        #[wasm_bindgen(js_namespace = Math)]
2799        pub fn random() -> f64;
2800
2801        /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
2802        ///
2803        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
2804        #[wasm_bindgen(js_namespace = Math)]
2805        pub fn round(x: f64) -> f64;
2806
2807        /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
2808        /// positive, negative or zero.
2809        ///
2810        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
2811        #[wasm_bindgen(js_namespace = Math)]
2812        pub fn sign(x: f64) -> f64;
2813
2814        /// The `Math.sin()` function returns the sine of a number.
2815        ///
2816        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
2817        #[wasm_bindgen(js_namespace = Math)]
2818        pub fn sin(x: f64) -> f64;
2819
2820        /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
2821        /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
2822        ///
2823        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
2824        #[wasm_bindgen(js_namespace = Math)]
2825        pub fn sinh(x: f64) -> f64;
2826
2827        /// The `Math.sqrt()` function returns the square root of a number, that is
2828        /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
2829        ///
2830        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
2831        #[wasm_bindgen(js_namespace = Math)]
2832        pub fn sqrt(x: f64) -> f64;
2833
2834        /// The `Math.tan()` function returns the tangent of a number.
2835        ///
2836        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
2837        #[wasm_bindgen(js_namespace = Math)]
2838        pub fn tan(x: f64) -> f64;
2839
2840        /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
2841        /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
2842        ///
2843        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
2844        #[wasm_bindgen(js_namespace = Math)]
2845        pub fn tanh(x: f64) -> f64;
2846
2847        /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
2848        /// digits.
2849        ///
2850        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
2851        #[wasm_bindgen(js_namespace = Math)]
2852        pub fn trunc(x: f64) -> f64;
2853    }
2854}
2855
2856// Number.
2857#[wasm_bindgen]
2858extern "C" {
2859    #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
2860    #[derive(Clone, PartialEq)]
2861    pub type Number;
2862
2863    /// The `Number.isFinite()` method determines whether the passed value is a finite number.
2864    ///
2865    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
2866    #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
2867    pub fn is_finite(value: &JsValue) -> bool;
2868
2869    /// The `Number.isInteger()` method determines whether the passed value is an integer.
2870    ///
2871    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
2872    #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
2873    pub fn is_integer(value: &JsValue) -> bool;
2874
2875    /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
2876    /// It is a more robust version of the original, global isNaN().
2877    ///
2878    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
2879    #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
2880    pub fn is_nan(value: &JsValue) -> bool;
2881
2882    /// The `Number.isSafeInteger()` method determines whether the provided value is a number
2883    /// that is a safe integer.
2884    ///
2885    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
2886    #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
2887    pub fn is_safe_integer(value: &JsValue) -> bool;
2888
2889    /// The `Number` JavaScript object is a wrapper object allowing
2890    /// you to work with numerical values. A `Number` object is
2891    /// created using the `Number()` constructor.
2892    ///
2893    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
2894    #[wasm_bindgen(constructor)]
2895    #[deprecated(note = "recommended to use `Number::from` instead")]
2896    #[allow(deprecated)]
2897    pub fn new(value: &JsValue) -> Number;
2898
2899    #[wasm_bindgen(constructor)]
2900    fn new_from_str(value: &str) -> Number;
2901
2902    /// The `Number.parseInt()` method parses a string argument and returns an
2903    /// integer of the specified radix or base.
2904    ///
2905    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
2906    #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
2907    pub fn parse_int(text: &str, radix: u8) -> f64;
2908
2909    /// The `Number.parseFloat()` method parses a string argument and returns a
2910    /// floating point number.
2911    ///
2912    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
2913    #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
2914    pub fn parse_float(text: &str) -> f64;
2915
2916    /// The `toLocaleString()` method returns a string with a language sensitive
2917    /// representation of this number.
2918    ///
2919    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
2920    #[wasm_bindgen(method, js_name = toLocaleString)]
2921    pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
2922
2923    /// The `toPrecision()` method returns a string representing the Number
2924    /// object to the specified precision.
2925    ///
2926    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
2927    #[wasm_bindgen(catch, method, js_name = toPrecision)]
2928    pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
2929
2930    /// The `toFixed()` method returns a string representing the Number
2931    /// object using fixed-point notation.
2932    ///
2933    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
2934    #[wasm_bindgen(catch, method, js_name = toFixed)]
2935    pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
2936
2937    /// The `toExponential()` method returns a string representing the Number
2938    /// object in exponential notation.
2939    ///
2940    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
2941    #[wasm_bindgen(catch, method, js_name = toExponential)]
2942    pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
2943
2944    /// The `toString()` method returns a string representing the
2945    /// specified Number object.
2946    ///
2947    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
2948    #[wasm_bindgen(catch, method, js_name = toString)]
2949    pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
2950
2951    /// The `valueOf()` method returns the wrapped primitive value of
2952    /// a Number object.
2953    ///
2954    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
2955    #[wasm_bindgen(method, js_name = valueOf)]
2956    pub fn value_of(this: &Number) -> f64;
2957}
2958
2959impl Number {
2960    /// The smallest interval between two representable numbers.
2961    ///
2962    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
2963    pub const EPSILON: f64 = f64::EPSILON;
2964    /// The maximum safe integer in JavaScript (2^53 - 1).
2965    ///
2966    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
2967    pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
2968    /// The largest positive representable number.
2969    ///
2970    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
2971    pub const MAX_VALUE: f64 = f64::MAX;
2972    /// The minimum safe integer in JavaScript (-(2^53 - 1)).
2973    ///
2974    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
2975    pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
2976    /// The smallest positive representable number—that is, the positive number closest to zero
2977    /// (without actually being zero).
2978    ///
2979    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
2980    // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number.
2981    pub const MIN_VALUE: f64 = 5E-324;
2982    /// Special "Not a Number" value.
2983    ///
2984    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
2985    pub const NAN: f64 = f64::NAN;
2986    /// Special value representing negative infinity. Returned on overflow.
2987    ///
2988    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
2989    pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
2990    /// Special value representing infinity. Returned on overflow.
2991    ///
2992    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
2993    pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
2994
2995    /// Applies the binary `**` JS operator on the two `Number`s.
2996    ///
2997    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
2998    #[inline]
2999    pub fn pow(&self, rhs: &Self) -> Self {
3000        JsValue::as_ref(self)
3001            .pow(JsValue::as_ref(rhs))
3002            .unchecked_into()
3003    }
3004
3005    /// Applies the binary `>>>` JS operator on the two `Number`s.
3006    ///
3007    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
3008    #[inline]
3009    pub fn unsigned_shr(&self, rhs: &Self) -> Self {
3010        Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs)))
3011    }
3012}
3013
3014macro_rules! number_from {
3015    ($($x:ident)*) => ($(
3016        impl From<$x> for Number {
3017            #[inline]
3018            fn from(x: $x) -> Number {
3019                Number::unchecked_from_js(JsValue::from(x))
3020            }
3021        }
3022
3023        impl PartialEq<$x> for Number {
3024            #[inline]
3025            fn eq(&self, other: &$x) -> bool {
3026                self.value_of() == f64::from(*other)
3027            }
3028        }
3029    )*)
3030}
3031number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
3032
3033/// The error type returned when a checked integral type conversion fails.
3034#[derive(Debug, Copy, Clone, PartialEq, Eq)]
3035pub struct TryFromIntError(());
3036
3037impl fmt::Display for TryFromIntError {
3038    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
3039        fmt.write_str("out of range integral type conversion attempted")
3040    }
3041}
3042
3043#[cfg(feature = "std")]
3044impl std::error::Error for TryFromIntError {}
3045
3046macro_rules! number_try_from {
3047    ($($x:ident)*) => ($(
3048        impl TryFrom<$x> for Number {
3049            type Error = TryFromIntError;
3050
3051            #[inline]
3052            fn try_from(x: $x) -> Result<Number, Self::Error> {
3053                let x_f64 = x as f64;
3054                if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) {
3055                    Ok(Number::from(x_f64))
3056                } else {
3057                    Err(TryFromIntError(()))
3058                }
3059            }
3060        }
3061    )*)
3062}
3063number_try_from!(i64 u64 i128 u128);
3064
3065// TODO: add this on the next major version, when blanket impl is removed
3066/*
3067impl convert::TryFrom<JsValue> for Number {
3068    type Error = Error;
3069
3070    fn try_from(value: JsValue) -> Result<Self, Self::Error> {
3071        return match f64::try_from(value) {
3072            Ok(num) => Ok(Number::from(num)),
3073            Err(jsval) => Err(jsval.unchecked_into())
3074        }
3075    }
3076}
3077*/
3078
3079impl From<&Number> for f64 {
3080    #[inline]
3081    fn from(n: &Number) -> f64 {
3082        n.value_of()
3083    }
3084}
3085
3086impl From<Number> for f64 {
3087    #[inline]
3088    fn from(n: Number) -> f64 {
3089        <f64 as From<&'_ Number>>::from(&n)
3090    }
3091}
3092
3093impl fmt::Debug for Number {
3094    #[inline]
3095    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3096        fmt::Debug::fmt(&self.value_of(), f)
3097    }
3098}
3099
3100impl fmt::Display for Number {
3101    #[inline]
3102    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3103        fmt::Display::fmt(&self.value_of(), f)
3104    }
3105}
3106
3107impl Default for Number {
3108    fn default() -> Self {
3109        Self::from(f64::default())
3110    }
3111}
3112
3113impl PartialEq<BigInt> for Number {
3114    #[inline]
3115    fn eq(&self, other: &BigInt) -> bool {
3116        JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
3117    }
3118}
3119
3120impl Not for &Number {
3121    type Output = BigInt;
3122
3123    #[inline]
3124    fn not(self) -> Self::Output {
3125        JsValue::as_ref(self).bit_not().unchecked_into()
3126    }
3127}
3128
3129forward_deref_unop!(impl Not, not for Number);
3130forward_js_unop!(impl Neg, neg for Number);
3131forward_js_binop!(impl BitAnd, bitand for Number);
3132forward_js_binop!(impl BitOr, bitor for Number);
3133forward_js_binop!(impl BitXor, bitxor for Number);
3134forward_js_binop!(impl Shl, shl for Number);
3135forward_js_binop!(impl Shr, shr for Number);
3136forward_js_binop!(impl Add, add for Number);
3137forward_js_binop!(impl Sub, sub for Number);
3138forward_js_binop!(impl Div, div for Number);
3139forward_js_binop!(impl Mul, mul for Number);
3140forward_js_binop!(impl Rem, rem for Number);
3141
3142sum_product!(Number);
3143
3144impl PartialOrd for Number {
3145    #[inline]
3146    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
3147        if Number::is_nan(self) || Number::is_nan(other) {
3148            None
3149        } else if self == other {
3150            Some(Ordering::Equal)
3151        } else if self.lt(other) {
3152            Some(Ordering::Less)
3153        } else {
3154            Some(Ordering::Greater)
3155        }
3156    }
3157
3158    #[inline]
3159    fn lt(&self, other: &Self) -> bool {
3160        JsValue::as_ref(self).lt(JsValue::as_ref(other))
3161    }
3162
3163    #[inline]
3164    fn le(&self, other: &Self) -> bool {
3165        JsValue::as_ref(self).le(JsValue::as_ref(other))
3166    }
3167
3168    #[inline]
3169    fn ge(&self, other: &Self) -> bool {
3170        JsValue::as_ref(self).ge(JsValue::as_ref(other))
3171    }
3172
3173    #[inline]
3174    fn gt(&self, other: &Self) -> bool {
3175        JsValue::as_ref(self).gt(JsValue::as_ref(other))
3176    }
3177}
3178
3179impl FromStr for Number {
3180    type Err = Infallible;
3181
3182    #[allow(deprecated)]
3183    #[inline]
3184    fn from_str(s: &str) -> Result<Self, Self::Err> {
3185        Ok(Number::new_from_str(s))
3186    }
3187}
3188
3189// Date.
3190#[wasm_bindgen]
3191extern "C" {
3192    #[wasm_bindgen(extends = Object, typescript_type = "Date")]
3193    #[derive(Clone, Debug, PartialEq, Eq)]
3194    pub type Date;
3195
3196    /// The `getDate()` method returns the day of the month for the
3197    /// specified date according to local time.
3198    ///
3199    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
3200    #[wasm_bindgen(method, js_name = getDate)]
3201    pub fn get_date(this: &Date) -> u32;
3202
3203    /// The `getDay()` method returns the day of the week for the specified date according to local time,
3204    /// where 0 represents Sunday. For the day of the month see getDate().
3205    ///
3206    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
3207    #[wasm_bindgen(method, js_name = getDay)]
3208    pub fn get_day(this: &Date) -> u32;
3209
3210    /// The `getFullYear()` method returns the year of the specified date according to local time.
3211    ///
3212    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
3213    #[wasm_bindgen(method, js_name = getFullYear)]
3214    pub fn get_full_year(this: &Date) -> u32;
3215
3216    /// The `getHours()` method returns the hour for the specified date, according to local time.
3217    ///
3218    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
3219    #[wasm_bindgen(method, js_name = getHours)]
3220    pub fn get_hours(this: &Date) -> u32;
3221
3222    /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
3223    ///
3224    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
3225    #[wasm_bindgen(method, js_name = getMilliseconds)]
3226    pub fn get_milliseconds(this: &Date) -> u32;
3227
3228    /// The `getMinutes()` method returns the minutes in the specified date according to local time.
3229    ///
3230    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
3231    #[wasm_bindgen(method, js_name = getMinutes)]
3232    pub fn get_minutes(this: &Date) -> u32;
3233
3234    /// The `getMonth()` method returns the month in the specified date according to local time,
3235    /// as a zero-based value (where zero indicates the first month of the year).
3236    ///
3237    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
3238    #[wasm_bindgen(method, js_name = getMonth)]
3239    pub fn get_month(this: &Date) -> u32;
3240
3241    /// The `getSeconds()` method returns the seconds in the specified date according to local time.
3242    ///
3243    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
3244    #[wasm_bindgen(method, js_name = getSeconds)]
3245    pub fn get_seconds(this: &Date) -> u32;
3246
3247    /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
3248    /// according to universal time.
3249    ///
3250    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
3251    #[wasm_bindgen(method, js_name = getTime)]
3252    pub fn get_time(this: &Date) -> f64;
3253
3254    /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
3255    /// from current locale (host system settings) to UTC.
3256    ///
3257    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
3258    #[wasm_bindgen(method, js_name = getTimezoneOffset)]
3259    pub fn get_timezone_offset(this: &Date) -> f64;
3260
3261    /// The `getUTCDate()` method returns the day (date) of the month in the specified date
3262    /// according to universal time.
3263    ///
3264    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
3265    #[wasm_bindgen(method, js_name = getUTCDate)]
3266    pub fn get_utc_date(this: &Date) -> u32;
3267
3268    /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
3269    /// where 0 represents Sunday.
3270    ///
3271    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
3272    #[wasm_bindgen(method, js_name = getUTCDay)]
3273    pub fn get_utc_day(this: &Date) -> u32;
3274
3275    /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
3276    ///
3277    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
3278    #[wasm_bindgen(method, js_name = getUTCFullYear)]
3279    pub fn get_utc_full_year(this: &Date) -> u32;
3280
3281    /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
3282    ///
3283    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
3284    #[wasm_bindgen(method, js_name = getUTCHours)]
3285    pub fn get_utc_hours(this: &Date) -> u32;
3286
3287    /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date
3288    /// according to universal time.
3289    ///
3290    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds)
3291    #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
3292    pub fn get_utc_milliseconds(this: &Date) -> u32;
3293
3294    /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
3295    ///
3296    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
3297    #[wasm_bindgen(method, js_name = getUTCMinutes)]
3298    pub fn get_utc_minutes(this: &Date) -> u32;
3299
3300    /// The `getUTCMonth()` returns the month of the specified date according to universal time,
3301    /// as a zero-based value (where zero indicates the first month of the year).
3302    ///
3303    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
3304    #[wasm_bindgen(method, js_name = getUTCMonth)]
3305    pub fn get_utc_month(this: &Date) -> u32;
3306
3307    /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time.
3308    ///
3309    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds)
3310    #[wasm_bindgen(method, js_name = getUTCSeconds)]
3311    pub fn get_utc_seconds(this: &Date) -> u32;
3312
3313    /// Creates a JavaScript `Date` instance that represents
3314    /// a single moment in time. `Date` objects are based on a time value that is
3315    /// the number of milliseconds since 1 January 1970 UTC.
3316    ///
3317    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3318    #[wasm_bindgen(constructor)]
3319    pub fn new(init: &JsValue) -> Date;
3320
3321    /// Creates a JavaScript `Date` instance that represents the current moment in
3322    /// time.
3323    ///
3324    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3325    #[wasm_bindgen(constructor)]
3326    pub fn new_0() -> Date;
3327
3328    /// Creates a JavaScript `Date` instance that represents
3329    /// a single moment in time. `Date` objects are based on a time value that is
3330    /// the number of milliseconds since 1 January 1970 UTC.
3331    ///
3332    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3333    #[wasm_bindgen(constructor)]
3334    pub fn new_with_year_month(year: u32, month: i32) -> Date;
3335
3336    /// Creates a JavaScript `Date` instance that represents
3337    /// a single moment in time. `Date` objects are based on a time value that is
3338    /// the number of milliseconds since 1 January 1970 UTC.
3339    ///
3340    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3341    #[wasm_bindgen(constructor)]
3342    pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
3343
3344    /// Creates a JavaScript `Date` instance that represents
3345    /// a single moment in time. `Date` objects are based on a time value that is
3346    /// the number of milliseconds since 1 January 1970 UTC.
3347    ///
3348    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3349    #[wasm_bindgen(constructor)]
3350    pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
3351
3352    /// Creates a JavaScript `Date` instance that represents
3353    /// a single moment in time. `Date` objects are based on a time value that is
3354    /// the number of milliseconds since 1 January 1970 UTC.
3355    ///
3356    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3357    #[wasm_bindgen(constructor)]
3358    pub fn new_with_year_month_day_hr_min(
3359        year: u32,
3360        month: i32,
3361        day: i32,
3362        hr: i32,
3363        min: i32,
3364    ) -> Date;
3365
3366    /// Creates a JavaScript `Date` instance that represents
3367    /// a single moment in time. `Date` objects are based on a time value that is
3368    /// the number of milliseconds since 1 January 1970 UTC.
3369    ///
3370    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3371    #[wasm_bindgen(constructor)]
3372    pub fn new_with_year_month_day_hr_min_sec(
3373        year: u32,
3374        month: i32,
3375        day: i32,
3376        hr: i32,
3377        min: i32,
3378        sec: i32,
3379    ) -> Date;
3380
3381    /// Creates a JavaScript `Date` instance that represents
3382    /// a single moment in time. `Date` objects are based on a time value that is
3383    /// the number of milliseconds since 1 January 1970 UTC.
3384    ///
3385    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3386    #[wasm_bindgen(constructor)]
3387    pub fn new_with_year_month_day_hr_min_sec_milli(
3388        year: u32,
3389        month: i32,
3390        day: i32,
3391        hr: i32,
3392        min: i32,
3393        sec: i32,
3394        milli: i32,
3395    ) -> Date;
3396
3397    /// The `Date.now()` method returns the number of milliseconds
3398    /// elapsed since January 1, 1970 00:00:00 UTC.
3399    ///
3400    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
3401    #[wasm_bindgen(static_method_of = Date)]
3402    pub fn now() -> f64;
3403
3404    /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
3405    /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
3406    /// contains illegal date values (e.g. 2015-02-31).
3407    ///
3408    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
3409    #[wasm_bindgen(static_method_of = Date)]
3410    pub fn parse(date: &str) -> f64;
3411
3412    /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
3413    ///
3414    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
3415    #[wasm_bindgen(method, js_name = setDate)]
3416    pub fn set_date(this: &Date, day: u32) -> f64;
3417
3418    /// The `setFullYear()` method sets the full year for a specified date according to local time.
3419    /// Returns new timestamp.
3420    ///
3421    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
3422    #[wasm_bindgen(method, js_name = setFullYear)]
3423    pub fn set_full_year(this: &Date, year: u32) -> f64;
3424
3425    /// The `setFullYear()` method sets the full year for a specified date according to local time.
3426    /// Returns new timestamp.
3427    ///
3428    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
3429    #[wasm_bindgen(method, js_name = setFullYear)]
3430    pub fn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
3431
3432    /// The `setFullYear()` method sets the full year for a specified date according to local time.
3433    /// Returns new timestamp.
3434    ///
3435    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
3436    #[wasm_bindgen(method, js_name = setFullYear)]
3437    pub fn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
3438
3439    /// The `setHours()` method sets the hours for a specified date according to local time,
3440    /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
3441    /// by the updated Date instance.
3442    ///
3443    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
3444    #[wasm_bindgen(method, js_name = setHours)]
3445    pub fn set_hours(this: &Date, hours: u32) -> f64;
3446
3447    /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
3448    ///
3449    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
3450    #[wasm_bindgen(method, js_name = setMilliseconds)]
3451    pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
3452
3453    /// The `setMinutes()` method sets the minutes for a specified date according to local time.
3454    ///
3455    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
3456    #[wasm_bindgen(method, js_name = setMinutes)]
3457    pub fn set_minutes(this: &Date, minutes: u32) -> f64;
3458
3459    /// The `setMonth()` method sets the month for a specified date according to the currently set year.
3460    ///
3461    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
3462    #[wasm_bindgen(method, js_name = setMonth)]
3463    pub fn set_month(this: &Date, month: u32) -> f64;
3464
3465    /// The `setSeconds()` method sets the seconds for a specified date according to local time.
3466    ///
3467    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
3468    #[wasm_bindgen(method, js_name = setSeconds)]
3469    pub fn set_seconds(this: &Date, seconds: u32) -> f64;
3470
3471    /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
3472    /// since January 1, 1970, 00:00:00 UTC.
3473    ///
3474    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
3475    #[wasm_bindgen(method, js_name = setTime)]
3476    pub fn set_time(this: &Date, time: f64) -> f64;
3477
3478    /// The `setUTCDate()` method sets the day of the month for a specified date
3479    /// according to universal time.
3480    ///
3481    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
3482    #[wasm_bindgen(method, js_name = setUTCDate)]
3483    pub fn set_utc_date(this: &Date, day: u32) -> f64;
3484
3485    /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
3486    ///
3487    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
3488    #[wasm_bindgen(method, js_name = setUTCFullYear)]
3489    pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
3490
3491    /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
3492    ///
3493    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
3494    #[wasm_bindgen(method, js_name = setUTCFullYear)]
3495    pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
3496
3497    /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
3498    ///
3499    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
3500    #[wasm_bindgen(method, js_name = setUTCFullYear)]
3501    pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
3502
3503    /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
3504    /// and returns the number of milliseconds since  January 1, 1970 00:00:00 UTC until the time
3505    /// represented by the updated Date instance.
3506    ///
3507    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
3508    #[wasm_bindgen(method, js_name = setUTCHours)]
3509    pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
3510
3511    /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
3512    /// according to universal time.
3513    ///
3514    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
3515    #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
3516    pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
3517
3518    /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
3519    ///
3520    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
3521    #[wasm_bindgen(method, js_name = setUTCMinutes)]
3522    pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
3523
3524    /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
3525    ///
3526    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
3527    #[wasm_bindgen(method, js_name = setUTCMonth)]
3528    pub fn set_utc_month(this: &Date, month: u32) -> f64;
3529
3530    /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
3531    ///
3532    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
3533    #[wasm_bindgen(method, js_name = setUTCSeconds)]
3534    pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
3535
3536    /// The `toDateString()` method returns the date portion of a Date object
3537    /// in human readable form in American English.
3538    ///
3539    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
3540    #[wasm_bindgen(method, js_name = toDateString)]
3541    pub fn to_date_string(this: &Date) -> JsString;
3542
3543    /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
3544    /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
3545    /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
3546    /// as denoted by the suffix "Z"
3547    ///
3548    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
3549    #[wasm_bindgen(method, js_name = toISOString)]
3550    pub fn to_iso_string(this: &Date) -> JsString;
3551
3552    /// The `toJSON()` method returns a string representation of the Date object.
3553    ///
3554    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
3555    #[wasm_bindgen(method, js_name = toJSON)]
3556    pub fn to_json(this: &Date) -> JsString;
3557
3558    /// The `toLocaleDateString()` method returns a string with a language sensitive
3559    /// representation of the date portion of this date. The new locales and options
3560    /// arguments let applications specify the language whose formatting conventions
3561    /// should be used and allow to customize the behavior of the function.
3562    /// In older implementations, which ignore the locales and options arguments,
3563    /// the locale used and the form of the string
3564    /// returned are entirely implementation dependent.
3565    ///
3566    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
3567    #[wasm_bindgen(method, js_name = toLocaleDateString)]
3568    pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
3569
3570    /// The `toLocaleString()` method returns a string with a language sensitive
3571    /// representation of this date. The new locales and options arguments
3572    /// let applications specify the language whose formatting conventions
3573    /// should be used and customize the behavior of the function.
3574    /// In older implementations, which ignore the locales
3575    /// and options arguments, the locale used and the form of the string
3576    /// returned are entirely implementation dependent.
3577    ///
3578    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
3579    #[wasm_bindgen(method, js_name = toLocaleString)]
3580    pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
3581
3582    /// The `toLocaleTimeString()` method returns a string with a language sensitive
3583    /// representation of the time portion of this date. The new locales and options
3584    /// arguments let applications specify the language whose formatting conventions should be
3585    /// used and customize the behavior of the function. In older implementations, which ignore
3586    /// the locales and options arguments, the locale used and the form of the string
3587    /// returned are entirely implementation dependent.
3588    ///
3589    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
3590    #[wasm_bindgen(method, js_name = toLocaleTimeString)]
3591    pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
3592
3593    #[wasm_bindgen(method, js_name = toLocaleTimeString)]
3594    pub fn to_locale_time_string_with_options(
3595        this: &Date,
3596        locale: &str,
3597        options: &JsValue,
3598    ) -> JsString;
3599
3600    /// The `toString()` method returns a string representing
3601    /// the specified Date object.
3602    ///
3603    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
3604    #[wasm_bindgen(method, js_name = toString)]
3605    pub fn to_string(this: &Date) -> JsString;
3606
3607    /// The `toTimeString()` method returns the time portion of a Date object in human
3608    /// readable form in American English.
3609    ///
3610    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
3611    #[wasm_bindgen(method, js_name = toTimeString)]
3612    pub fn to_time_string(this: &Date) -> JsString;
3613
3614    /// The `toUTCString()` method converts a date to a string,
3615    /// using the UTC time zone.
3616    ///
3617    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
3618    #[wasm_bindgen(method, js_name = toUTCString)]
3619    pub fn to_utc_string(this: &Date) -> JsString;
3620
3621    /// The `Date.UTC()` method accepts the same parameters as the
3622    /// longest form of the constructor, and returns the number of
3623    /// milliseconds in a `Date` object since January 1, 1970,
3624    /// 00:00:00, universal time.
3625    ///
3626    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
3627    #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
3628    pub fn utc(year: f64, month: f64) -> f64;
3629
3630    /// The `valueOf()` method  returns the primitive value of
3631    /// a Date object.
3632    ///
3633    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
3634    #[wasm_bindgen(method, js_name = valueOf)]
3635    pub fn value_of(this: &Date) -> f64;
3636}
3637
3638// Object.
3639#[wasm_bindgen]
3640extern "C" {
3641    #[wasm_bindgen(typescript_type = "object")]
3642    #[derive(Clone, Debug)]
3643    pub type Object;
3644
3645    /// The `Object.assign()` method is used to copy the values of all enumerable
3646    /// own properties from one or more source objects to a target object. It
3647    /// will return the target object.
3648    ///
3649    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
3650    #[wasm_bindgen(static_method_of = Object)]
3651    pub fn assign(target: &Object, source: &Object) -> Object;
3652
3653    /// The `Object.assign()` method is used to copy the values of all enumerable
3654    /// own properties from one or more source objects to a target object. It
3655    /// will return the target object.
3656    ///
3657    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
3658    #[wasm_bindgen(static_method_of = Object, js_name = assign)]
3659    pub fn assign2(target: &Object, source1: &Object, source2: &Object) -> Object;
3660
3661    /// The `Object.assign()` method is used to copy the values of all enumerable
3662    /// own properties from one or more source objects to a target object. It
3663    /// will return the target object.
3664    ///
3665    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
3666    #[wasm_bindgen(static_method_of = Object, js_name = assign)]
3667    pub fn assign3(target: &Object, source1: &Object, source2: &Object, source3: &Object)
3668        -> Object;
3669
3670    /// The constructor property returns a reference to the `Object` constructor
3671    /// function that created the instance object.
3672    ///
3673    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
3674    #[wasm_bindgen(method, getter)]
3675    pub fn constructor(this: &Object) -> Function;
3676
3677    /// The `Object.create()` method creates a new object, using an existing
3678    /// object to provide the newly created object's prototype.
3679    ///
3680    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
3681    #[wasm_bindgen(static_method_of = Object)]
3682    pub fn create(prototype: &Object) -> Object;
3683
3684    /// The static method `Object.defineProperty()` defines a new
3685    /// property directly on an object, or modifies an existing
3686    /// property on an object, and returns the object.
3687    ///
3688    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
3689    #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
3690    pub fn define_property(obj: &Object, prop: &JsValue, descriptor: &Object) -> Object;
3691
3692    /// The `Object.defineProperties()` method defines new or modifies
3693    /// existing properties directly on an object, returning the
3694    /// object.
3695    ///
3696    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
3697    #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
3698    pub fn define_properties(obj: &Object, props: &Object) -> Object;
3699
3700    /// The `Object.entries()` method returns an array of a given
3701    /// object's own enumerable property [key, value] pairs, in the
3702    /// same order as that provided by a for...in loop (the difference
3703    /// being that a for-in loop enumerates properties in the
3704    /// prototype chain as well).
3705    ///
3706    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
3707    #[wasm_bindgen(static_method_of = Object)]
3708    pub fn entries(object: &Object) -> Array;
3709
3710    /// The `Object.freeze()` method freezes an object: that is, prevents new
3711    /// properties from being added to it; prevents existing properties from
3712    /// being removed; and prevents existing properties, or their enumerability,
3713    /// configurability, or writability, from being changed, it also prevents
3714    /// the prototype from being changed. The method returns the passed object.
3715    ///
3716    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
3717    #[wasm_bindgen(static_method_of = Object)]
3718    pub fn freeze(value: &Object) -> Object;
3719
3720    /// The `Object.fromEntries()` method transforms a list of key-value pairs
3721    /// into an object.
3722    ///
3723    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
3724    #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
3725    pub fn from_entries(iterable: &JsValue) -> Result<Object, JsValue>;
3726
3727    /// The `Object.getOwnPropertyDescriptor()` method returns a
3728    /// property descriptor for an own property (that is, one directly
3729    /// present on an object and not in the object's prototype chain)
3730    /// of a given object.
3731    ///
3732    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
3733    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
3734    pub fn get_own_property_descriptor(obj: &Object, prop: &JsValue) -> JsValue;
3735
3736    /// The `Object.getOwnPropertyDescriptors()` method returns all own
3737    /// property descriptors of a given object.
3738    ///
3739    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
3740    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
3741    pub fn get_own_property_descriptors(obj: &Object) -> JsValue;
3742
3743    /// The `Object.getOwnPropertyNames()` method returns an array of
3744    /// all properties (including non-enumerable properties except for
3745    /// those which use Symbol) found directly upon a given object.
3746    ///
3747    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
3748    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
3749    pub fn get_own_property_names(obj: &Object) -> Array;
3750
3751    /// The `Object.getOwnPropertySymbols()` method returns an array of
3752    /// all symbol properties found directly upon a given object.
3753    ///
3754    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
3755    #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
3756    pub fn get_own_property_symbols(obj: &Object) -> Array;
3757
3758    /// The `Object.getPrototypeOf()` method returns the prototype
3759    /// (i.e. the value of the internal [[Prototype]] property) of the
3760    /// specified object.
3761    ///
3762    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
3763    #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
3764    pub fn get_prototype_of(obj: &JsValue) -> Object;
3765
3766    /// The `hasOwnProperty()` method returns a boolean indicating whether the
3767    /// object has the specified property as its own property (as opposed to
3768    /// inheriting it).
3769    ///
3770    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
3771    #[wasm_bindgen(method, js_name = hasOwnProperty)]
3772    pub fn has_own_property(this: &Object, property: &JsValue) -> bool;
3773
3774    /// The `Object.hasOwn()` method returns a boolean indicating whether the
3775    /// object passed in has the specified property as its own property (as
3776    /// opposed to inheriting it).
3777    ///
3778    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
3779    #[wasm_bindgen(static_method_of = Object, js_name = hasOwn)]
3780    pub fn has_own(instance: &Object, property: &JsValue) -> bool;
3781
3782    /// The `Object.is()` method determines whether two values are the same value.
3783    ///
3784    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
3785    #[wasm_bindgen(static_method_of = Object)]
3786    pub fn is(value_1: &JsValue, value_2: &JsValue) -> bool;
3787
3788    /// The `Object.isExtensible()` method determines if an object is extensible
3789    /// (whether it can have new properties added to it).
3790    ///
3791    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
3792    #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
3793    pub fn is_extensible(object: &Object) -> bool;
3794
3795    /// The `Object.isFrozen()` determines if an object is frozen.
3796    ///
3797    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
3798    #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
3799    pub fn is_frozen(object: &Object) -> bool;
3800
3801    /// The `Object.isSealed()` method determines if an object is sealed.
3802    ///
3803    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
3804    #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
3805    pub fn is_sealed(object: &Object) -> bool;
3806
3807    /// The `isPrototypeOf()` method checks if an object exists in another
3808    /// object's prototype chain.
3809    ///
3810    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
3811    #[wasm_bindgen(method, js_name = isPrototypeOf)]
3812    pub fn is_prototype_of(this: &Object, value: &JsValue) -> bool;
3813
3814    /// The `Object.keys()` method returns an array of a given object's property
3815    /// names, in the same order as we get with a normal loop.
3816    ///
3817    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
3818    #[wasm_bindgen(static_method_of = Object)]
3819    pub fn keys(object: &Object) -> Array;
3820
3821    /// The [`Object`] constructor creates an object wrapper.
3822    ///
3823    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
3824    #[wasm_bindgen(constructor)]
3825    pub fn new() -> Object;
3826
3827    /// The `Object.preventExtensions()` method prevents new properties from
3828    /// ever being added to an object (i.e. prevents future extensions to the
3829    /// object).
3830    ///
3831    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
3832    #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
3833    pub fn prevent_extensions(object: &Object);
3834
3835    /// The `propertyIsEnumerable()` method returns a Boolean indicating
3836    /// whether the specified property is enumerable.
3837    ///
3838    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
3839    #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
3840    pub fn property_is_enumerable(this: &Object, property: &JsValue) -> bool;
3841
3842    /// The `Object.seal()` method seals an object, preventing new properties
3843    /// from being added to it and marking all existing properties as
3844    /// non-configurable.  Values of present properties can still be changed as
3845    /// long as they are writable.
3846    ///
3847    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
3848    #[wasm_bindgen(static_method_of = Object)]
3849    pub fn seal(value: &Object) -> Object;
3850
3851    /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
3852    /// internal `[[Prototype]]` property) of a specified object to another
3853    /// object or `null`.
3854    ///
3855    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
3856    #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
3857    pub fn set_prototype_of(object: &Object, prototype: &Object) -> Object;
3858
3859    /// The `toLocaleString()` method returns a string representing the object.
3860    /// This method is meant to be overridden by derived objects for
3861    /// locale-specific purposes.
3862    ///
3863    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
3864    #[wasm_bindgen(method, js_name = toLocaleString)]
3865    pub fn to_locale_string(this: &Object) -> JsString;
3866
3867    /// The `toString()` method returns a string representing the object.
3868    ///
3869    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
3870    #[wasm_bindgen(method, js_name = toString)]
3871    pub fn to_string(this: &Object) -> JsString;
3872
3873    /// The `valueOf()` method returns the primitive value of the
3874    /// specified object.
3875    ///
3876    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
3877    #[wasm_bindgen(method, js_name = valueOf)]
3878    pub fn value_of(this: &Object) -> Object;
3879
3880    /// The `Object.values()` method returns an array of a given object's own
3881    /// enumerable property values, in the same order as that provided by a
3882    /// `for...in` loop (the difference being that a for-in loop enumerates
3883    /// properties in the prototype chain as well).
3884    ///
3885    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
3886    #[wasm_bindgen(static_method_of = Object)]
3887    pub fn values(object: &Object) -> Array;
3888}
3889
3890impl Object {
3891    /// Returns the `Object` value of this JS value if it's an instance of an
3892    /// object.
3893    ///
3894    /// If this JS value is not an instance of an object then this returns
3895    /// `None`.
3896    pub fn try_from(val: &JsValue) -> Option<&Object> {
3897        if val.is_object() {
3898            Some(val.unchecked_ref())
3899        } else {
3900            None
3901        }
3902    }
3903}
3904
3905impl PartialEq for Object {
3906    #[inline]
3907    fn eq(&self, other: &Object) -> bool {
3908        Object::is(self.as_ref(), other.as_ref())
3909    }
3910}
3911
3912impl Eq for Object {}
3913
3914impl Default for Object {
3915    fn default() -> Self {
3916        Self::new()
3917    }
3918}
3919
3920// Proxy
3921#[wasm_bindgen]
3922extern "C" {
3923    #[wasm_bindgen(typescript_type = "ProxyConstructor")]
3924    #[derive(Clone, Debug)]
3925    pub type Proxy;
3926
3927    /// The [`Proxy`] object is used to define custom behavior for fundamental
3928    /// operations (e.g. property lookup, assignment, enumeration, function
3929    /// invocation, etc).
3930    ///
3931    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
3932    #[wasm_bindgen(constructor)]
3933    pub fn new(target: &JsValue, handler: &Object) -> Proxy;
3934
3935    /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
3936    /// object.
3937    ///
3938    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
3939    #[wasm_bindgen(static_method_of = Proxy)]
3940    pub fn revocable(target: &JsValue, handler: &Object) -> Object;
3941}
3942
3943// RangeError
3944#[wasm_bindgen]
3945extern "C" {
3946    /// The `RangeError` object indicates an error when a value is not in the set
3947    /// or range of allowed values.
3948    ///
3949    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
3950    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
3951    #[derive(Clone, Debug, PartialEq, Eq)]
3952    pub type RangeError;
3953
3954    /// The `RangeError` object indicates an error when a value is not in the set
3955    /// or range of allowed values.
3956    ///
3957    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
3958    #[wasm_bindgen(constructor)]
3959    pub fn new(message: &str) -> RangeError;
3960}
3961
3962// ReferenceError
3963#[wasm_bindgen]
3964extern "C" {
3965    /// The `ReferenceError` object represents an error when a non-existent
3966    /// variable is referenced.
3967    ///
3968    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
3969    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
3970    #[derive(Clone, Debug, PartialEq, Eq)]
3971    pub type ReferenceError;
3972
3973    /// The `ReferenceError` object represents an error when a non-existent
3974    /// variable is referenced.
3975    ///
3976    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
3977    #[wasm_bindgen(constructor)]
3978    pub fn new(message: &str) -> ReferenceError;
3979}
3980
3981#[allow(non_snake_case)]
3982pub mod Reflect {
3983    use super::*;
3984
3985    // Reflect
3986    #[wasm_bindgen]
3987    extern "C" {
3988        /// The static `Reflect.apply()` method calls a target function with
3989        /// arguments as specified.
3990        ///
3991        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
3992        #[wasm_bindgen(js_namespace = Reflect, catch)]
3993        pub fn apply(
3994            target: &Function,
3995            this_argument: &JsValue,
3996            arguments_list: &Array,
3997        ) -> Result<JsValue, JsValue>;
3998
3999        /// The static `Reflect.construct()` method acts like the new operator, but
4000        /// as a function.  It is equivalent to calling `new target(...args)`. It
4001        /// gives also the added option to specify a different prototype.
4002        ///
4003        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
4004        #[wasm_bindgen(js_namespace = Reflect, catch)]
4005        pub fn construct(target: &Function, arguments_list: &Array) -> Result<JsValue, JsValue>;
4006
4007        /// The static `Reflect.construct()` method acts like the new operator, but
4008        /// as a function.  It is equivalent to calling `new target(...args)`. It
4009        /// gives also the added option to specify a different prototype.
4010        ///
4011        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
4012        #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
4013        pub fn construct_with_new_target(
4014            target: &Function,
4015            arguments_list: &Array,
4016            new_target: &Function,
4017        ) -> Result<JsValue, JsValue>;
4018
4019        /// The static `Reflect.defineProperty()` method is like
4020        /// `Object.defineProperty()` but returns a `Boolean`.
4021        ///
4022        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
4023        #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
4024        pub fn define_property(
4025            target: &Object,
4026            property_key: &JsValue,
4027            attributes: &Object,
4028        ) -> Result<bool, JsValue>;
4029
4030        /// The static `Reflect.deleteProperty()` method allows to delete
4031        /// properties.  It is like the `delete` operator as a function.
4032        ///
4033        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
4034        #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
4035        pub fn delete_property(target: &Object, key: &JsValue) -> Result<bool, JsValue>;
4036
4037        /// The static `Reflect.get()` method works like getting a property from
4038        /// an object (`target[propertyKey]`) as a function.
4039        ///
4040        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
4041        #[wasm_bindgen(js_namespace = Reflect, catch)]
4042        pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
4043
4044        /// The same as [`get`](fn.get.html)
4045        /// except the key is an `f64`, which is slightly faster.
4046        #[wasm_bindgen(js_namespace = Reflect, js_name = "get", catch)]
4047        pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
4048
4049        /// The same as [`get`](fn.get.html)
4050        /// except the key is a `u32`, which is slightly faster.
4051        #[wasm_bindgen(js_namespace = Reflect, js_name = "get", catch)]
4052        pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
4053
4054        /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
4055        /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
4056        /// of the given property if it exists on the object, `undefined` otherwise.
4057        ///
4058        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
4059        #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
4060        pub fn get_own_property_descriptor(
4061            target: &Object,
4062            property_key: &JsValue,
4063        ) -> Result<JsValue, JsValue>;
4064
4065        /// The static `Reflect.getPrototypeOf()` method is almost the same
4066        /// method as `Object.getPrototypeOf()`. It returns the prototype
4067        /// (i.e. the value of the internal `[[Prototype]]` property) of
4068        /// the specified object.
4069        ///
4070        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
4071        #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
4072        pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
4073
4074        /// The static `Reflect.has()` method works like the in operator as a
4075        /// function.
4076        ///
4077        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
4078        #[wasm_bindgen(js_namespace = Reflect, catch)]
4079        pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
4080
4081        /// The static `Reflect.isExtensible()` method determines if an object is
4082        /// extensible (whether it can have new properties added to it). It is
4083        /// similar to `Object.isExtensible()`, but with some differences.
4084        ///
4085        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
4086        #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
4087        pub fn is_extensible(target: &Object) -> Result<bool, JsValue>;
4088
4089        /// The static `Reflect.ownKeys()` method returns an array of the
4090        /// target object's own property keys.
4091        ///
4092        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
4093        #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
4094        pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
4095
4096        /// The static `Reflect.preventExtensions()` method prevents new
4097        /// properties from ever being added to an object (i.e. prevents
4098        /// future extensions to the object). It is similar to
4099        /// `Object.preventExtensions()`, but with some differences.
4100        ///
4101        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
4102        #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
4103        pub fn prevent_extensions(target: &Object) -> Result<bool, JsValue>;
4104
4105        /// The static `Reflect.set()` method works like setting a
4106        /// property on an object.
4107        ///
4108        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
4109        #[wasm_bindgen(js_namespace = Reflect, catch)]
4110        pub fn set(
4111            target: &JsValue,
4112            property_key: &JsValue,
4113            value: &JsValue,
4114        ) -> Result<bool, JsValue>;
4115
4116        /// The same as [`set`](fn.set.html)
4117        /// except the key is an `f64`, which is slightly faster.
4118        #[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)]
4119        pub fn set_f64(
4120            target: &JsValue,
4121            property_key: f64,
4122            value: &JsValue,
4123        ) -> Result<bool, JsValue>;
4124
4125        /// The same as [`set`](fn.set.html)
4126        /// except the key is a `u32`, which is slightly faster.
4127        #[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)]
4128        pub fn set_u32(
4129            target: &JsValue,
4130            property_key: u32,
4131            value: &JsValue,
4132        ) -> Result<bool, JsValue>;
4133
4134        /// The static `Reflect.set()` method works like setting a
4135        /// property on an object.
4136        ///
4137        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
4138        #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
4139        pub fn set_with_receiver(
4140            target: &JsValue,
4141            property_key: &JsValue,
4142            value: &JsValue,
4143            receiver: &JsValue,
4144        ) -> Result<bool, JsValue>;
4145
4146        /// The static `Reflect.setPrototypeOf()` method is the same
4147        /// method as `Object.setPrototypeOf()`. It sets the prototype
4148        /// (i.e., the internal `[[Prototype]]` property) of a specified
4149        /// object to another object or to null.
4150        ///
4151        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
4152        #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
4153        pub fn set_prototype_of(target: &Object, prototype: &JsValue) -> Result<bool, JsValue>;
4154    }
4155}
4156
4157// RegExp
4158#[wasm_bindgen]
4159extern "C" {
4160    #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
4161    #[derive(Clone, Debug, PartialEq, Eq)]
4162    pub type RegExp;
4163
4164    /// The `exec()` method executes a search for a match in a specified
4165    /// string. Returns a result array, or null.
4166    ///
4167    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
4168    #[wasm_bindgen(method)]
4169    pub fn exec(this: &RegExp, text: &str) -> Option<Array>;
4170
4171    /// The flags property returns a string consisting of the flags of
4172    /// the current regular expression object.
4173    ///
4174    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
4175    #[wasm_bindgen(method, getter)]
4176    pub fn flags(this: &RegExp) -> JsString;
4177
4178    /// The global property indicates whether or not the "g" flag is
4179    /// used with the regular expression. global is a read-only
4180    /// property of an individual regular expression instance.
4181    ///
4182    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
4183    #[wasm_bindgen(method, getter)]
4184    pub fn global(this: &RegExp) -> bool;
4185
4186    /// The ignoreCase property indicates whether or not the "i" flag
4187    /// is used with the regular expression. ignoreCase is a read-only
4188    /// property of an individual regular expression instance.
4189    ///
4190    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
4191    #[wasm_bindgen(method, getter, js_name = ignoreCase)]
4192    pub fn ignore_case(this: &RegExp) -> bool;
4193
4194    /// The non-standard input property is a static property of
4195    /// regular expressions that contains the string against which a
4196    /// regular expression is matched. RegExp.$_ is an alias for this
4197    /// property.
4198    ///
4199    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
4200    #[wasm_bindgen(static_method_of = RegExp, getter)]
4201    pub fn input() -> JsString;
4202
4203    /// The lastIndex is a read/write integer property of regular expression
4204    /// instances that specifies the index at which to start the next match.
4205    ///
4206    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
4207    #[wasm_bindgen(structural, getter = lastIndex, method)]
4208    pub fn last_index(this: &RegExp) -> u32;
4209
4210    /// The lastIndex is a read/write integer property of regular expression
4211    /// instances that specifies the index at which to start the next match.
4212    ///
4213    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
4214    #[wasm_bindgen(structural, setter = lastIndex, method)]
4215    pub fn set_last_index(this: &RegExp, index: u32);
4216
4217    /// The non-standard lastMatch property is a static and read-only
4218    /// property of regular expressions that contains the last matched
4219    /// characters. `RegExp.$&` is an alias for this property.
4220    ///
4221    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
4222    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
4223    pub fn last_match() -> JsString;
4224
4225    /// The non-standard lastParen property is a static and read-only
4226    /// property of regular expressions that contains the last
4227    /// parenthesized substring match, if any. `RegExp.$+` is an alias
4228    /// for this property.
4229    ///
4230    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
4231    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
4232    pub fn last_paren() -> JsString;
4233
4234    /// The non-standard leftContext property is a static and
4235    /// read-only property of regular expressions that contains the
4236    /// substring preceding the most recent match. `RegExp.$`` is an
4237    /// alias for this property.
4238    ///
4239    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
4240    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
4241    pub fn left_context() -> JsString;
4242
4243    /// The multiline property indicates whether or not the "m" flag
4244    /// is used with the regular expression. multiline is a read-only
4245    /// property of an individual regular expression instance.
4246    ///
4247    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
4248    #[wasm_bindgen(method, getter)]
4249    pub fn multiline(this: &RegExp) -> bool;
4250
4251    /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
4252    /// are static and read-only properties of regular expressions
4253    /// that contain parenthesized substring matches.
4254    ///
4255    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
4256    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
4257    pub fn n1() -> JsString;
4258    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
4259    pub fn n2() -> JsString;
4260    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
4261    pub fn n3() -> JsString;
4262    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
4263    pub fn n4() -> JsString;
4264    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
4265    pub fn n5() -> JsString;
4266    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
4267    pub fn n6() -> JsString;
4268    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
4269    pub fn n7() -> JsString;
4270    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
4271    pub fn n8() -> JsString;
4272    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
4273    pub fn n9() -> JsString;
4274
4275    /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
4276    ///
4277    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
4278    #[wasm_bindgen(constructor)]
4279    pub fn new(pattern: &str, flags: &str) -> RegExp;
4280    #[wasm_bindgen(constructor)]
4281    pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
4282
4283    /// The non-standard rightContext property is a static and
4284    /// read-only property of regular expressions that contains the
4285    /// substring following the most recent match. `RegExp.$'` is an
4286    /// alias for this property.
4287    ///
4288    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
4289    #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
4290    pub fn right_context() -> JsString;
4291
4292    /// The source property returns a String containing the source
4293    /// text of the regexp object, and it doesn't contain the two
4294    /// forward slashes on both sides and any flags.
4295    ///
4296    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
4297    #[wasm_bindgen(method, getter)]
4298    pub fn source(this: &RegExp) -> JsString;
4299
4300    /// The sticky property reflects whether or not the search is
4301    /// sticky (searches in strings only from the index indicated by
4302    /// the lastIndex property of this regular expression). sticky is
4303    /// a read-only property of an individual regular expression
4304    /// object.
4305    ///
4306    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
4307    #[wasm_bindgen(method, getter)]
4308    pub fn sticky(this: &RegExp) -> bool;
4309
4310    /// The `test()` method executes a search for a match between a
4311    /// regular expression and a specified string. Returns true or
4312    /// false.
4313    ///
4314    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
4315    #[wasm_bindgen(method)]
4316    pub fn test(this: &RegExp, text: &str) -> bool;
4317
4318    /// The `toString()` method returns a string representing the
4319    /// regular expression.
4320    ///
4321    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
4322    #[wasm_bindgen(method, js_name = toString)]
4323    pub fn to_string(this: &RegExp) -> JsString;
4324
4325    /// The unicode property indicates whether or not the "u" flag is
4326    /// used with a regular expression. unicode is a read-only
4327    /// property of an individual regular expression instance.
4328    ///
4329    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
4330    #[wasm_bindgen(method, getter)]
4331    pub fn unicode(this: &RegExp) -> bool;
4332}
4333
4334// Set
4335#[wasm_bindgen]
4336extern "C" {
4337    #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
4338    #[derive(Clone, Debug, PartialEq, Eq)]
4339    pub type Set;
4340
4341    /// The `add()` method appends a new element with a specified value to the
4342    /// end of a [`Set`] object.
4343    ///
4344    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
4345    #[wasm_bindgen(method)]
4346    pub fn add(this: &Set, value: &JsValue) -> Set;
4347
4348    /// The `clear()` method removes all elements from a [`Set`] object.
4349    ///
4350    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
4351    #[wasm_bindgen(method)]
4352    pub fn clear(this: &Set);
4353
4354    /// The `delete()` method removes the specified element from a [`Set`]
4355    /// object.
4356    ///
4357    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
4358    #[wasm_bindgen(method)]
4359    pub fn delete(this: &Set, value: &JsValue) -> bool;
4360
4361    /// The `forEach()` method executes a provided function once for each value
4362    /// in the Set object, in insertion order.
4363    ///
4364    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
4365    #[wasm_bindgen(method, js_name = forEach)]
4366    pub fn for_each(this: &Set, callback: &mut dyn FnMut(JsValue, JsValue, Set));
4367
4368    /// The `has()` method returns a boolean indicating whether an element with
4369    /// the specified value exists in a [`Set`] object or not.
4370    ///
4371    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
4372    #[wasm_bindgen(method)]
4373    pub fn has(this: &Set, value: &JsValue) -> bool;
4374
4375    /// The [`Set`] object lets you store unique values of any type, whether
4376    /// primitive values or object references.
4377    ///
4378    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
4379    #[wasm_bindgen(constructor)]
4380    pub fn new(init: &JsValue) -> Set;
4381
4382    /// The size accessor property returns the number of elements in a [`Set`]
4383    /// object.
4384    ///
4385    /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
4386    #[wasm_bindgen(method, getter, structural)]
4387    pub fn size(this: &Set) -> u32;
4388}
4389
4390impl Default for Set {
4391    fn default() -> Self {
4392        Self::new(&JsValue::UNDEFINED)
4393    }
4394}
4395
4396// SetIterator
4397#[wasm_bindgen]
4398extern "C" {
4399    /// The `entries()` method returns a new Iterator object that contains an
4400    /// array of [value, value] for each element in the Set object, in insertion
4401    /// order. For Set objects there is no key like in Map objects. However, to
4402    /// keep the API similar to the Map object, each entry has the same value
4403    /// for its key and value here, so that an array [value, value] is returned.
4404    ///
4405    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
4406    #[wasm_bindgen(method)]
4407    pub fn entries(set: &Set) -> Iterator;
4408
4409    /// The `keys()` method is an alias for this method (for similarity with
4410    /// Map objects); it behaves exactly the same and returns values
4411    /// of Set elements.
4412    ///
4413    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
4414    #[wasm_bindgen(method)]
4415    pub fn keys(set: &Set) -> Iterator;
4416
4417    /// The `values()` method returns a new Iterator object that contains the
4418    /// values for each element in the Set object in insertion order.
4419    ///
4420    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
4421    #[wasm_bindgen(method)]
4422    pub fn values(set: &Set) -> Iterator;
4423}
4424
4425// SyntaxError
4426#[wasm_bindgen]
4427extern "C" {
4428    /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
4429    /// token order that does not conform to the syntax of the language when
4430    /// parsing code.
4431    ///
4432    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
4433    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
4434    #[derive(Clone, Debug, PartialEq, Eq)]
4435    pub type SyntaxError;
4436
4437    /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
4438    /// token order that does not conform to the syntax of the language when
4439    /// parsing code.
4440    ///
4441    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
4442    #[wasm_bindgen(constructor)]
4443    pub fn new(message: &str) -> SyntaxError;
4444}
4445
4446// TypeError
4447#[wasm_bindgen]
4448extern "C" {
4449    /// The `TypeError` object represents an error when a value is not of the
4450    /// expected type.
4451    ///
4452    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
4453    #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
4454    #[derive(Clone, Debug, PartialEq, Eq)]
4455    pub type TypeError;
4456
4457    /// The `TypeError` object represents an error when a value is not of the
4458    /// expected type.
4459    ///
4460    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
4461    #[wasm_bindgen(constructor)]
4462    pub fn new(message: &str) -> TypeError;
4463}
4464
4465// URIError
4466#[wasm_bindgen]
4467extern "C" {
4468    /// The `URIError` object represents an error when a global URI handling
4469    /// function was used in a wrong way.
4470    ///
4471    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
4472    #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
4473    #[derive(Clone, Debug, PartialEq, Eq)]
4474    pub type UriError;
4475
4476    /// The `URIError` object represents an error when a global URI handling
4477    /// function was used in a wrong way.
4478    ///
4479    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
4480    #[wasm_bindgen(constructor, js_class = "URIError")]
4481    pub fn new(message: &str) -> UriError;
4482}
4483
4484// WeakMap
4485#[wasm_bindgen]
4486extern "C" {
4487    #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
4488    #[derive(Clone, Debug, PartialEq, Eq)]
4489    pub type WeakMap;
4490
4491    /// The [`WeakMap`] object is a collection of key/value pairs in which the
4492    /// keys are weakly referenced.  The keys must be objects and the values can
4493    /// be arbitrary values.
4494    ///
4495    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
4496    #[wasm_bindgen(constructor)]
4497    pub fn new() -> WeakMap;
4498
4499    /// The `set()` method sets the value for the key in the [`WeakMap`] object.
4500    /// Returns the [`WeakMap`] object.
4501    ///
4502    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
4503    #[wasm_bindgen(method, js_class = "WeakMap")]
4504    pub fn set(this: &WeakMap, key: &Object, value: &JsValue) -> WeakMap;
4505
4506    /// The `get()` method returns a specified by key element
4507    /// from a [`WeakMap`] object.
4508    ///
4509    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
4510    #[wasm_bindgen(method)]
4511    pub fn get(this: &WeakMap, key: &Object) -> JsValue;
4512
4513    /// The `has()` method returns a boolean indicating whether an element with
4514    /// the specified key exists in the [`WeakMap`] object or not.
4515    ///
4516    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
4517    #[wasm_bindgen(method)]
4518    pub fn has(this: &WeakMap, key: &Object) -> bool;
4519
4520    /// The `delete()` method removes the specified element from a [`WeakMap`]
4521    /// object.
4522    ///
4523    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
4524    #[wasm_bindgen(method)]
4525    pub fn delete(this: &WeakMap, key: &Object) -> bool;
4526}
4527
4528impl Default for WeakMap {
4529    fn default() -> Self {
4530        Self::new()
4531    }
4532}
4533
4534// WeakSet
4535#[wasm_bindgen]
4536extern "C" {
4537    #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
4538    #[derive(Clone, Debug, PartialEq, Eq)]
4539    pub type WeakSet;
4540
4541    /// The `WeakSet` object lets you store weakly held objects in a collection.
4542    ///
4543    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
4544    #[wasm_bindgen(constructor)]
4545    pub fn new() -> WeakSet;
4546
4547    /// The `has()` method returns a boolean indicating whether an object exists
4548    /// in a WeakSet or not.
4549    ///
4550    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
4551    #[wasm_bindgen(method)]
4552    pub fn has(this: &WeakSet, value: &Object) -> bool;
4553
4554    /// The `add()` method appends a new object to the end of a WeakSet object.
4555    ///
4556    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
4557    #[wasm_bindgen(method)]
4558    pub fn add(this: &WeakSet, value: &Object) -> WeakSet;
4559
4560    /// The `delete()` method removes the specified element from a WeakSet
4561    /// object.
4562    ///
4563    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
4564    #[wasm_bindgen(method)]
4565    pub fn delete(this: &WeakSet, value: &Object) -> bool;
4566}
4567
4568impl Default for WeakSet {
4569    fn default() -> Self {
4570        Self::new()
4571    }
4572}
4573
4574// WeakRef
4575#[wasm_bindgen]
4576extern "C" {
4577    #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
4578    #[derive(Clone, Debug, PartialEq, Eq)]
4579    pub type WeakRef;
4580
4581    /// The `WeakRef` object contains a weak reference to an object. A weak
4582    /// reference to an object is a reference that does not prevent the object
4583    /// from being reclaimed by the garbage collector.
4584    ///
4585    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
4586    #[wasm_bindgen(constructor)]
4587    pub fn new(target: &Object) -> WeakRef;
4588
4589    /// Returns the `Object` this `WeakRef` points to, or `None` if the
4590    /// object has been garbage collected.
4591    ///
4592    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
4593    #[wasm_bindgen(method)]
4594    pub fn deref(this: &WeakRef) -> Option<Object>;
4595}
4596
4597#[cfg(js_sys_unstable_apis)]
4598#[allow(non_snake_case)]
4599pub mod Temporal;
4600
4601#[allow(non_snake_case)]
4602pub mod WebAssembly {
4603    use super::*;
4604
4605    // WebAssembly
4606    #[wasm_bindgen]
4607    extern "C" {
4608        /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
4609        /// from WebAssembly binary code.  This function is useful if it is
4610        /// necessary to a compile a module before it can be instantiated
4611        /// (otherwise, the `WebAssembly.instantiate()` function should be used).
4612        ///
4613        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
4614        #[wasm_bindgen(js_namespace = WebAssembly)]
4615        pub fn compile(buffer_source: &JsValue) -> Promise;
4616
4617        /// The `WebAssembly.compileStreaming()` function compiles a
4618        /// `WebAssembly.Module` module directly from a streamed underlying
4619        /// source. This function is useful if it is necessary to a compile a
4620        /// module before it can be instantiated (otherwise, the
4621        /// `WebAssembly.instantiateStreaming()` function should be used).
4622        ///
4623        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
4624        #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
4625        pub fn compile_streaming(response: &Promise) -> Promise;
4626
4627        /// The `WebAssembly.instantiate()` function allows you to compile and
4628        /// instantiate WebAssembly code.
4629        ///
4630        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
4631        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
4632        pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise;
4633
4634        /// The `WebAssembly.instantiate()` function allows you to compile and
4635        /// instantiate WebAssembly code.
4636        ///
4637        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
4638        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
4639        pub fn instantiate_module(module: &Module, imports: &Object) -> Promise;
4640
4641        /// The `WebAssembly.instantiateStreaming()` function compiles and
4642        /// instantiates a WebAssembly module directly from a streamed
4643        /// underlying source. This is the most efficient, optimized way to load
4644        /// Wasm code.
4645        ///
4646        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
4647        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
4648        pub fn instantiate_streaming(response: &Promise, imports: &Object) -> Promise;
4649
4650        /// The `WebAssembly.validate()` function validates a given typed
4651        /// array of WebAssembly binary code, returning whether the bytes
4652        /// form a valid Wasm module (`true`) or not (`false`).
4653        ///
4654        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
4655        #[wasm_bindgen(js_namespace = WebAssembly, catch)]
4656        pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
4657    }
4658
4659    // WebAssembly.CompileError
4660    #[wasm_bindgen]
4661    extern "C" {
4662        /// The `WebAssembly.CompileError()` constructor creates a new
4663        /// WebAssembly `CompileError` object, which indicates an error during
4664        /// WebAssembly decoding or validation.
4665        ///
4666        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
4667        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
4668        #[derive(Clone, Debug, PartialEq, Eq)]
4669        pub type CompileError;
4670
4671        /// The `WebAssembly.CompileError()` constructor creates a new
4672        /// WebAssembly `CompileError` object, which indicates an error during
4673        /// WebAssembly decoding or validation.
4674        ///
4675        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
4676        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
4677        pub fn new(message: &str) -> CompileError;
4678    }
4679
4680    // WebAssembly.Instance
4681    #[wasm_bindgen]
4682    extern "C" {
4683        /// A `WebAssembly.Instance` object is a stateful, executable instance
4684        /// of a `WebAssembly.Module`. Instance objects contain all the exported
4685        /// WebAssembly functions that allow calling into WebAssembly code from
4686        /// JavaScript.
4687        ///
4688        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
4689        #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
4690        #[derive(Clone, Debug, PartialEq, Eq)]
4691        pub type Instance;
4692
4693        /// The `WebAssembly.Instance()` constructor function can be called to
4694        /// synchronously instantiate a given `WebAssembly.Module`
4695        /// object. However, the primary way to get an `Instance` is through the
4696        /// asynchronous `WebAssembly.instantiateStreaming()` function.
4697        ///
4698        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
4699        #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
4700        pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
4701
4702        /// The `exports` readonly property of the `WebAssembly.Instance` object
4703        /// prototype returns an object containing as its members all the
4704        /// functions exported from the WebAssembly module instance, to allow
4705        /// them to be accessed and used by JavaScript.
4706        ///
4707        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
4708        #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
4709        pub fn exports(this: &Instance) -> Object;
4710    }
4711
4712    // WebAssembly.LinkError
4713    #[wasm_bindgen]
4714    extern "C" {
4715        /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
4716        /// LinkError object, which indicates an error during module
4717        /// instantiation (besides traps from the start function).
4718        ///
4719        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
4720        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
4721        #[derive(Clone, Debug, PartialEq, Eq)]
4722        pub type LinkError;
4723
4724        /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
4725        /// LinkError object, which indicates an error during module
4726        /// instantiation (besides traps from the start function).
4727        ///
4728        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
4729        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
4730        pub fn new(message: &str) -> LinkError;
4731    }
4732
4733    // WebAssembly.RuntimeError
4734    #[wasm_bindgen]
4735    extern "C" {
4736        /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
4737        /// `RuntimeError` object — the type that is thrown whenever WebAssembly
4738        /// specifies a trap.
4739        ///
4740        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
4741        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
4742        #[derive(Clone, Debug, PartialEq, Eq)]
4743        pub type RuntimeError;
4744
4745        /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
4746        /// `RuntimeError` object — the type that is thrown whenever WebAssembly
4747        /// specifies a trap.
4748        ///
4749        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
4750        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
4751        pub fn new(message: &str) -> RuntimeError;
4752    }
4753
4754    // WebAssembly.Module
4755    #[wasm_bindgen]
4756    extern "C" {
4757        /// A `WebAssembly.Module` object contains stateless WebAssembly code
4758        /// that has already been compiled by the browser and can be
4759        /// efficiently shared with Workers, and instantiated multiple times.
4760        ///
4761        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
4762        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
4763        #[derive(Clone, Debug, PartialEq, Eq)]
4764        pub type Module;
4765
4766        /// A `WebAssembly.Module` object contains stateless WebAssembly code
4767        /// that has already been compiled by the browser and can be
4768        /// efficiently shared with Workers, and instantiated multiple times.
4769        ///
4770        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
4771        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4772        pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
4773
4774        /// The `WebAssembly.customSections()` function returns a copy of the
4775        /// contents of all custom sections in the given module with the given
4776        /// string name.
4777        ///
4778        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
4779        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
4780        pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
4781
4782        /// The `WebAssembly.exports()` function returns an array containing
4783        /// descriptions of all the declared exports of the given `Module`.
4784        ///
4785        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
4786        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
4787        pub fn exports(module: &Module) -> Array;
4788
4789        /// The `WebAssembly.imports()` function returns an array containing
4790        /// descriptions of all the declared imports of the given `Module`.
4791        ///
4792        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
4793        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
4794        pub fn imports(module: &Module) -> Array;
4795    }
4796
4797    // WebAssembly.Table
4798    #[wasm_bindgen]
4799    extern "C" {
4800        /// The `WebAssembly.Table()` constructor creates a new `Table` object
4801        /// of the given size and element type.
4802        ///
4803        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
4804        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
4805        #[derive(Clone, Debug, PartialEq, Eq)]
4806        pub type Table;
4807
4808        /// The `WebAssembly.Table()` constructor creates a new `Table` object
4809        /// of the given size and element type.
4810        ///
4811        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
4812        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4813        pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
4814
4815        /// The length prototype property of the `WebAssembly.Table` object
4816        /// returns the length of the table, i.e. the number of elements in the
4817        /// table.
4818        ///
4819        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
4820        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
4821        pub fn length(this: &Table) -> u32;
4822
4823        /// The `get()` prototype method of the `WebAssembly.Table()` object
4824        /// retrieves a function reference stored at a given index.
4825        ///
4826        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
4827        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
4828        pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
4829
4830        /// The `grow()` prototype method of the `WebAssembly.Table` object
4831        /// increases the size of the `Table` instance by a specified number of
4832        /// elements.
4833        ///
4834        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
4835        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
4836        pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
4837
4838        /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
4839        /// reference stored at a given index to a different value.
4840        ///
4841        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
4842        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
4843        pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
4844    }
4845
4846    // WebAssembly.Tag
4847    #[wasm_bindgen]
4848    extern "C" {
4849        /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
4850        ///
4851        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
4852        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
4853        #[derive(Clone, Debug, PartialEq, Eq)]
4854        pub type Tag;
4855
4856        /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
4857        ///
4858        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
4859        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4860        pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
4861    }
4862
4863    // WebAssembly.Exception
4864    #[wasm_bindgen]
4865    extern "C" {
4866        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
4867        ///
4868        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
4869        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
4870        #[derive(Clone, Debug, PartialEq, Eq)]
4871        pub type Exception;
4872
4873        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
4874        ///
4875        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
4876        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4877        pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
4878
4879        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
4880        ///
4881        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
4882        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4883        pub fn new_with_options(
4884            tag: &Tag,
4885            payload: &Array,
4886            options: &Object,
4887        ) -> Result<Exception, JsValue>;
4888
4889        /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
4890        /// test if the Exception matches a given tag.
4891        ///
4892        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
4893        #[wasm_bindgen(method, js_namespace = WebAssembly)]
4894        pub fn is(this: &Exception, tag: &Tag) -> bool;
4895
4896        /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
4897        /// to get the value of a specified item in the exception's data arguments
4898        ///
4899        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
4900        #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
4901        pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
4902    }
4903
4904    // WebAssembly.Global
4905    #[wasm_bindgen]
4906    extern "C" {
4907        /// The `WebAssembly.Global()` constructor creates a new `Global` object
4908        /// of the given type and value.
4909        ///
4910        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
4911        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
4912        #[derive(Clone, Debug, PartialEq, Eq)]
4913        pub type Global;
4914
4915        /// The `WebAssembly.Global()` constructor creates a new `Global` object
4916        /// of the given type and value.
4917        ///
4918        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
4919        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4920        pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
4921
4922        /// The value prototype property of the `WebAssembly.Global` object
4923        /// returns the value of the global.
4924        ///
4925        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
4926        #[wasm_bindgen(method, getter, structural, js_namespace = WebAssembly)]
4927        pub fn value(this: &Global) -> JsValue;
4928        #[wasm_bindgen(method, setter = value, structural, js_namespace = WebAssembly)]
4929        pub fn set_value(this: &Global, value: &JsValue);
4930    }
4931
4932    // WebAssembly.Memory
4933    #[wasm_bindgen]
4934    extern "C" {
4935        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
4936        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
4937        #[derive(Clone, Debug, PartialEq, Eq)]
4938        pub type Memory;
4939
4940        /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
4941        /// which is a resizable `ArrayBuffer` that holds the raw bytes of
4942        /// memory accessed by a WebAssembly `Instance`.
4943        ///
4944        /// A memory created by JavaScript or in WebAssembly code will be
4945        /// accessible and mutable from both JavaScript and WebAssembly.
4946        ///
4947        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
4948        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4949        pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
4950
4951        /// An accessor property that returns the buffer contained in the
4952        /// memory.
4953        ///
4954        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
4955        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
4956        pub fn buffer(this: &Memory) -> JsValue;
4957
4958        /// The `grow()` prototype method of the `Memory` object increases the
4959        /// size of the memory instance by a specified number of WebAssembly
4960        /// pages.
4961        ///
4962        /// Takes the number of pages to grow (64KiB in size) and returns the
4963        /// previous size of memory, in pages.
4964        ///
4965        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
4966        #[wasm_bindgen(method, js_namespace = WebAssembly)]
4967        pub fn grow(this: &Memory, pages: u32) -> u32;
4968    }
4969}
4970
4971/// The `JSON` object contains methods for parsing [JavaScript Object
4972/// Notation (JSON)](https://json.org/) and converting values to JSON. It
4973/// can't be called or constructed, and aside from its two method
4974/// properties, it has no interesting functionality of its own.
4975#[allow(non_snake_case)]
4976pub mod JSON {
4977    use super::*;
4978
4979    // JSON
4980    #[wasm_bindgen]
4981    extern "C" {
4982        /// The `JSON.parse()` method parses a JSON string, constructing the
4983        /// JavaScript value or object described by the string.
4984        ///
4985        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
4986        #[wasm_bindgen(catch, js_namespace = JSON)]
4987        pub fn parse(text: &str) -> Result<JsValue, JsValue>;
4988
4989        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
4990        ///
4991        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
4992        #[wasm_bindgen(catch, js_namespace = JSON)]
4993        pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
4994
4995        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
4996        ///
4997        /// The `replacer` argument is a function that alters the behavior of the stringification
4998        /// process, or an array of String and Number objects that serve as a whitelist
4999        /// for selecting/filtering the properties of the value object to be included
5000        /// in the JSON string. If this value is null or not provided, all properties
5001        /// of the object are included in the resulting JSON string.
5002        ///
5003        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
5004        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
5005        pub fn stringify_with_replacer(
5006            obj: &JsValue,
5007            replacer: &JsValue,
5008        ) -> Result<JsString, JsValue>;
5009
5010        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
5011        ///
5012        /// The `replacer` argument is a function that alters the behavior of the stringification
5013        /// process, or an array of String and Number objects that serve as a whitelist
5014        /// for selecting/filtering the properties of the value object to be included
5015        /// in the JSON string. If this value is null or not provided, all properties
5016        /// of the object are included in the resulting JSON string.
5017        ///
5018        /// The `space` argument is a String or Number object that's used to insert white space into
5019        /// the output JSON string for readability purposes. If this is a Number, it
5020        /// indicates the number of space characters to use as white space; this number
5021        /// is capped at 10 (if it is greater, the value is just 10). Values less than
5022        /// 1 indicate that no space should be used. If this is a String, the string
5023        /// (or the first 10 characters of the string, if it's longer than that) is
5024        /// used as white space. If this parameter is not provided (or is null), no
5025        /// white space is used.
5026        ///
5027        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
5028        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
5029        pub fn stringify_with_replacer_and_space(
5030            obj: &JsValue,
5031            replacer: &JsValue,
5032            space: &JsValue,
5033        ) -> Result<JsString, JsValue>;
5034
5035    }
5036}
5037
5038// JsString
5039#[wasm_bindgen]
5040extern "C" {
5041    #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
5042    #[derive(Clone, PartialEq, Eq)]
5043    pub type JsString;
5044
5045    /// The length property of a String object indicates the length of a string,
5046    /// in UTF-16 code units.
5047    ///
5048    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
5049    #[wasm_bindgen(method, getter, structural)]
5050    pub fn length(this: &JsString) -> u32;
5051
5052    /// The 'at()' method returns a new string consisting of the single UTF-16
5053    /// code unit located at the specified offset into the string, counting from
5054    /// the end if it's negative.
5055    ///
5056    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
5057    #[wasm_bindgen(method, js_class = "String")]
5058    pub fn at(this: &JsString, index: i32) -> Option<JsString>;
5059
5060    /// The String object's `charAt()` method returns a new string consisting of
5061    /// the single UTF-16 code unit located at the specified offset into the
5062    /// string.
5063    ///
5064    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
5065    #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
5066    pub fn char_at(this: &JsString, index: u32) -> JsString;
5067
5068    /// The `charCodeAt()` method returns an integer between 0 and 65535
5069    /// representing the UTF-16 code unit at the given index (the UTF-16 code
5070    /// unit matches the Unicode code point for code points representable in a
5071    /// single UTF-16 code unit, but might also be the first code unit of a
5072    /// surrogate pair for code points not representable in a single UTF-16 code
5073    /// unit, e.g. Unicode code points > 0x10000).  If you want the entire code
5074    /// point value, use `codePointAt()`.
5075    ///
5076    /// Returns `NaN` if index is out of range.
5077    ///
5078    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
5079    #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
5080    pub fn char_code_at(this: &JsString, index: u32) -> f64;
5081
5082    /// The `codePointAt()` method returns a non-negative integer that is the
5083    /// Unicode code point value.
5084    ///
5085    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
5086    #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
5087    pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
5088
5089    /// The `concat()` method concatenates the string arguments to the calling
5090    /// string and returns a new string.
5091    ///
5092    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
5093    #[wasm_bindgen(method, js_class = "String")]
5094    pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
5095
5096    /// The `endsWith()` method determines whether a string ends with the characters of a
5097    /// specified string, returning true or false as appropriate.
5098    ///
5099    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
5100    #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
5101    pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
5102
5103    /// The static `String.fromCharCode()` method returns a string created from
5104    /// the specified sequence of UTF-16 code units.
5105    ///
5106    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5107    ///
5108    /// # Notes
5109    ///
5110    /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
5111    /// with different arities.
5112    ///
5113    /// Additionally, this function accepts `u16` for character codes, but
5114    /// fixing others requires a breaking change release
5115    /// (see https://github.com/wasm-bindgen/wasm-bindgen/issues/1460 for details).
5116    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
5117    pub fn from_char_code(char_codes: &[u16]) -> JsString;
5118
5119    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5120    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5121    pub fn from_char_code1(a: u32) -> JsString;
5122
5123    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5124    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5125    pub fn from_char_code2(a: u32, b: u32) -> JsString;
5126
5127    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5128    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5129    pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
5130
5131    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5132    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5133    pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
5134
5135    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5136    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5137    pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
5138
5139    /// The static `String.fromCodePoint()` method returns a string created by
5140    /// using the specified sequence of code points.
5141    ///
5142    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5143    ///
5144    /// # Exceptions
5145    ///
5146    /// A RangeError is thrown if an invalid Unicode code point is given
5147    ///
5148    /// # Notes
5149    ///
5150    /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
5151    /// with different arities.
5152    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
5153    pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
5154
5155    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5156    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5157    pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
5158
5159    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5160    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5161    pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
5162
5163    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5164    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5165    pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
5166
5167    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5168    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5169    pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
5170
5171    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5172    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5173    pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
5174
5175    /// The `includes()` method determines whether one string may be found
5176    /// within another string, returning true or false as appropriate.
5177    ///
5178    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
5179    #[wasm_bindgen(method, js_class = "String")]
5180    pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
5181
5182    /// The `indexOf()` method returns the index within the calling String
5183    /// object of the first occurrence of the specified value, starting the
5184    /// search at fromIndex.  Returns -1 if the value is not found.
5185    ///
5186    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
5187    #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
5188    pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
5189
5190    /// The `lastIndexOf()` method returns the index within the calling String
5191    /// object of the last occurrence of the specified value, searching
5192    /// backwards from fromIndex.  Returns -1 if the value is not found.
5193    ///
5194    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
5195    #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
5196    pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
5197
5198    /// The `localeCompare()` method returns a number indicating whether
5199    /// a reference string comes before or after or is the same as
5200    /// the given string in sort order.
5201    ///
5202    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
5203    #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
5204    pub fn locale_compare(
5205        this: &JsString,
5206        compare_string: &str,
5207        locales: &Array,
5208        options: &Object,
5209    ) -> i32;
5210
5211    /// The `match()` method retrieves the matches when matching a string against a regular expression.
5212    ///
5213    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
5214    #[wasm_bindgen(method, js_class = "String", js_name = match)]
5215    pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
5216
5217    /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
5218    ///
5219    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
5220    #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
5221    pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
5222
5223    /// The `normalize()` method returns the Unicode Normalization Form
5224    /// of a given string (if the value isn't a string, it will be converted to one first).
5225    ///
5226    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
5227    #[wasm_bindgen(method, js_class = "String")]
5228    pub fn normalize(this: &JsString, form: &str) -> JsString;
5229
5230    /// The `padEnd()` method pads the current string with a given string
5231    /// (repeated, if needed) so that the resulting string reaches a given
5232    /// length. The padding is applied from the end (right) of the current
5233    /// string.
5234    ///
5235    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
5236    #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
5237    pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
5238
5239    /// The `padStart()` method pads the current string with another string
5240    /// (repeated, if needed) so that the resulting string reaches the given
5241    /// length. The padding is applied from the start (left) of the current
5242    /// string.
5243    ///
5244    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
5245    #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
5246    pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
5247
5248    /// The `repeat()` method constructs and returns a new string which contains the specified
5249    /// number of copies of the string on which it was called, concatenated together.
5250    ///
5251    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
5252    #[wasm_bindgen(method, js_class = "String")]
5253    pub fn repeat(this: &JsString, count: i32) -> JsString;
5254
5255    /// The `replace()` method returns a new string with some or all matches of a pattern
5256    /// replaced by a replacement. The pattern can be a string or a RegExp, and
5257    /// the replacement can be a string or a function to be called for each match.
5258    ///
5259    /// Note: The original string will remain unchanged.
5260    ///
5261    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
5262    #[wasm_bindgen(method, js_class = "String")]
5263    pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
5264
5265    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
5266    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
5267    pub fn replace_with_function(
5268        this: &JsString,
5269        pattern: &str,
5270        replacement: &Function,
5271    ) -> JsString;
5272
5273    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
5274    pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
5275
5276    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
5277    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
5278    pub fn replace_by_pattern_with_function(
5279        this: &JsString,
5280        pattern: &RegExp,
5281        replacement: &Function,
5282    ) -> JsString;
5283
5284    /// The `replace_all()` method returns a new string with all matches of a pattern
5285    /// replaced by a replacement. The pattern can be a string or a global RegExp, and
5286    /// the replacement can be a string or a function to be called for each match.
5287    ///
5288    /// Note: The original string will remain unchanged.
5289    ///
5290    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
5291    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
5292    pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
5293
5294    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
5295    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
5296    pub fn replace_all_with_function(
5297        this: &JsString,
5298        pattern: &str,
5299        replacement: &Function,
5300    ) -> JsString;
5301
5302    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
5303    pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
5304        -> JsString;
5305
5306    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
5307    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
5308    pub fn replace_all_by_pattern_with_function(
5309        this: &JsString,
5310        pattern: &RegExp,
5311        replacement: &Function,
5312    ) -> JsString;
5313
5314    /// The `search()` method executes a search for a match between
5315    /// a regular expression and this String object.
5316    ///
5317    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
5318    #[wasm_bindgen(method, js_class = "String")]
5319    pub fn search(this: &JsString, pattern: &RegExp) -> i32;
5320
5321    /// The `slice()` method extracts a section of a string and returns it as a
5322    /// new string, without modifying the original string.
5323    ///
5324    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
5325    #[wasm_bindgen(method, js_class = "String")]
5326    pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
5327
5328    /// The `split()` method splits a String object into an array of strings by separating the string
5329    /// into substrings, using a specified separator string to determine where to make each split.
5330    ///
5331    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5332    #[wasm_bindgen(method, js_class = "String")]
5333    pub fn split(this: &JsString, separator: &str) -> Array;
5334
5335    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5336    #[wasm_bindgen(method, js_class = "String", js_name = split)]
5337    pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
5338
5339    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5340    #[wasm_bindgen(method, js_class = "String", js_name = split)]
5341    pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
5342
5343    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5344    #[wasm_bindgen(method, js_class = "String", js_name = split)]
5345    pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
5346
5347    /// The `startsWith()` method determines whether a string begins with the
5348    /// characters of a specified string, returning true or false as
5349    /// appropriate.
5350    ///
5351    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
5352    #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
5353    pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
5354
5355    /// The `substring()` method returns the part of the string between the
5356    /// start and end indexes, or to the end of the string.
5357    ///
5358    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
5359    #[wasm_bindgen(method, js_class = "String")]
5360    pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
5361
5362    /// The `substr()` method returns the part of a string between
5363    /// the start index and a number of characters after it.
5364    ///
5365    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
5366    #[wasm_bindgen(method, js_class = "String")]
5367    pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
5368
5369    /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
5370    /// according to any locale-specific case mappings.
5371    ///
5372    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
5373    #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
5374    pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
5375
5376    /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
5377    /// according to any locale-specific case mappings.
5378    ///
5379    /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
5380    #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
5381    pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
5382
5383    /// The `toLowerCase()` method returns the calling string value
5384    /// converted to lower case.
5385    ///
5386    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
5387    #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
5388    pub fn to_lower_case(this: &JsString) -> JsString;
5389
5390    /// The `toString()` method returns a string representing the specified
5391    /// object.
5392    ///
5393    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
5394    #[wasm_bindgen(method, js_class = "String", js_name = toString)]
5395    pub fn to_string(this: &JsString) -> JsString;
5396
5397    /// The `toUpperCase()` method returns the calling string value converted to
5398    /// uppercase (the value will be converted to a string if it isn't one).
5399    ///
5400    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
5401    #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
5402    pub fn to_upper_case(this: &JsString) -> JsString;
5403
5404    /// The `trim()` method removes whitespace from both ends of a string.
5405    /// Whitespace in this context is all the whitespace characters (space, tab,
5406    /// no-break space, etc.) and all the line terminator characters (LF, CR,
5407    /// etc.).
5408    ///
5409    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
5410    #[wasm_bindgen(method, js_class = "String")]
5411    pub fn trim(this: &JsString) -> JsString;
5412
5413    /// The `trimEnd()` method removes whitespace from the end of a string.
5414    /// `trimRight()` is an alias of this method.
5415    ///
5416    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
5417    #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
5418    pub fn trim_end(this: &JsString) -> JsString;
5419
5420    /// The `trimEnd()` method removes whitespace from the end of a string.
5421    /// `trimRight()` is an alias of this method.
5422    ///
5423    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
5424    #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
5425    pub fn trim_right(this: &JsString) -> JsString;
5426
5427    /// The `trimStart()` method removes whitespace from the beginning of a
5428    /// string. `trimLeft()` is an alias of this method.
5429    ///
5430    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
5431    #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
5432    pub fn trim_start(this: &JsString) -> JsString;
5433
5434    /// The `trimStart()` method removes whitespace from the beginning of a
5435    /// string. `trimLeft()` is an alias of this method.
5436    ///
5437    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
5438    #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
5439    pub fn trim_left(this: &JsString) -> JsString;
5440
5441    /// The `valueOf()` method returns the primitive value of a `String` object.
5442    ///
5443    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
5444    #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
5445    pub fn value_of(this: &JsString) -> JsString;
5446
5447    /// The static `raw()` method is a tag function of template literals,
5448    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5449    ///
5450    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5451    #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
5452    pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
5453
5454    /// The static `raw()` method is a tag function of template literals,
5455    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5456    ///
5457    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5458    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5459    pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
5460
5461    /// The static `raw()` method is a tag function of template literals,
5462    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5463    ///
5464    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5465    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5466    pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
5467
5468    /// The static `raw()` method is a tag function of template literals,
5469    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5470    ///
5471    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5472    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5473    pub fn raw_2(
5474        call_site: &Object,
5475        substitutions_1: &str,
5476        substitutions_2: &str,
5477    ) -> Result<JsString, JsValue>;
5478
5479    /// The static `raw()` method is a tag function of template literals,
5480    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5481    ///
5482    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5483    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5484    pub fn raw_3(
5485        call_site: &Object,
5486        substitutions_1: &str,
5487        substitutions_2: &str,
5488        substitutions_3: &str,
5489    ) -> Result<JsString, JsValue>;
5490
5491    /// The static `raw()` method is a tag function of template literals,
5492    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5493    ///
5494    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5495    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5496    pub fn raw_4(
5497        call_site: &Object,
5498        substitutions_1: &str,
5499        substitutions_2: &str,
5500        substitutions_3: &str,
5501        substitutions_4: &str,
5502    ) -> Result<JsString, JsValue>;
5503
5504    /// The static `raw()` method is a tag function of template literals,
5505    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5506    ///
5507    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5508    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5509    pub fn raw_5(
5510        call_site: &Object,
5511        substitutions_1: &str,
5512        substitutions_2: &str,
5513        substitutions_3: &str,
5514        substitutions_4: &str,
5515        substitutions_5: &str,
5516    ) -> Result<JsString, JsValue>;
5517
5518    /// The static `raw()` method is a tag function of template literals,
5519    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5520    ///
5521    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5522    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5523    pub fn raw_6(
5524        call_site: &Object,
5525        substitutions_1: &str,
5526        substitutions_2: &str,
5527        substitutions_3: &str,
5528        substitutions_4: &str,
5529        substitutions_5: &str,
5530        substitutions_6: &str,
5531    ) -> Result<JsString, JsValue>;
5532
5533    /// The static `raw()` method is a tag function of template literals,
5534    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5535    ///
5536    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5537    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5538    pub fn raw_7(
5539        call_site: &Object,
5540        substitutions_1: &str,
5541        substitutions_2: &str,
5542        substitutions_3: &str,
5543        substitutions_4: &str,
5544        substitutions_5: &str,
5545        substitutions_6: &str,
5546        substitutions_7: &str,
5547    ) -> Result<JsString, JsValue>;
5548}
5549
5550impl JsString {
5551    /// Returns the `JsString` value of this JS value if it's an instance of a
5552    /// string.
5553    ///
5554    /// If this JS value is not an instance of a string then this returns
5555    /// `None`.
5556    #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
5557    pub fn try_from(val: &JsValue) -> Option<&JsString> {
5558        val.dyn_ref()
5559    }
5560
5561    /// Returns whether this string is a valid UTF-16 string.
5562    ///
5563    /// This is useful for learning whether `String::from(..)` will return a
5564    /// lossless representation of the JS string. If this string contains
5565    /// unpaired surrogates then `String::from` will succeed but it will be a
5566    /// lossy representation of the JS string because unpaired surrogates will
5567    /// become replacement characters.
5568    ///
5569    /// If this function returns `false` then to get a lossless representation
5570    /// of the string you'll need to manually use the `iter` method (or the
5571    /// `char_code_at` accessor) to view the raw character codes.
5572    ///
5573    /// For more information, see the documentation on [JS strings vs Rust
5574    /// strings][docs]
5575    ///
5576    /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
5577    pub fn is_valid_utf16(&self) -> bool {
5578        core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
5579    }
5580
5581    /// Returns an iterator over the `u16` character codes that make up this JS
5582    /// string.
5583    ///
5584    /// This method will call `char_code_at` for each code in this JS string,
5585    /// returning an iterator of the codes in sequence.
5586    pub fn iter(
5587        &self,
5588    ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
5589        (0..self.length()).map(move |i| self.char_code_at(i) as u16)
5590    }
5591
5592    /// If this string consists of a single Unicode code point, then this method
5593    /// converts it into a Rust `char` without doing any allocations.
5594    ///
5595    /// If this JS value is not a valid UTF-8 or consists of more than a single
5596    /// codepoint, then this returns `None`.
5597    ///
5598    /// Note that a single Unicode code point might be represented as more than
5599    /// one code unit on the JavaScript side. For example, a JavaScript string
5600    /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
5601    /// corresponds to a character '𐐷'.
5602    pub fn as_char(&self) -> Option<char> {
5603        let len = self.length();
5604
5605        if len == 0 || len > 2 {
5606            return None;
5607        }
5608
5609        // This will be simplified when definitions are fixed:
5610        // https://github.com/wasm-bindgen/wasm-bindgen/issues/1362
5611        let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
5612
5613        let c = core::char::from_u32(cp)?;
5614
5615        if c.len_utf16() as u32 == len {
5616            Some(c)
5617        } else {
5618            None
5619        }
5620    }
5621}
5622
5623impl PartialEq<str> for JsString {
5624    #[allow(clippy::cmp_owned)] // prevent infinite recursion
5625    fn eq(&self, other: &str) -> bool {
5626        String::from(self) == other
5627    }
5628}
5629
5630impl<'a> PartialEq<&'a str> for JsString {
5631    fn eq(&self, other: &&'a str) -> bool {
5632        <JsString as PartialEq<str>>::eq(self, other)
5633    }
5634}
5635
5636impl PartialEq<String> for JsString {
5637    fn eq(&self, other: &String) -> bool {
5638        <JsString as PartialEq<str>>::eq(self, other)
5639    }
5640}
5641
5642impl<'a> PartialEq<&'a String> for JsString {
5643    fn eq(&self, other: &&'a String) -> bool {
5644        <JsString as PartialEq<str>>::eq(self, other)
5645    }
5646}
5647
5648impl<'a> From<&'a str> for JsString {
5649    fn from(s: &'a str) -> Self {
5650        JsString::unchecked_from_js(JsValue::from_str(s))
5651    }
5652}
5653
5654impl From<String> for JsString {
5655    fn from(s: String) -> Self {
5656        From::from(&*s)
5657    }
5658}
5659
5660impl From<char> for JsString {
5661    #[inline]
5662    fn from(c: char) -> Self {
5663        JsString::from_code_point1(c as u32).unwrap_throw()
5664    }
5665}
5666
5667impl<'a> From<&'a JsString> for String {
5668    fn from(s: &'a JsString) -> Self {
5669        s.obj.as_string().unwrap_throw()
5670    }
5671}
5672
5673impl From<JsString> for String {
5674    fn from(s: JsString) -> Self {
5675        From::from(&s)
5676    }
5677}
5678
5679impl fmt::Debug for JsString {
5680    #[inline]
5681    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5682        fmt::Debug::fmt(&String::from(self), f)
5683    }
5684}
5685
5686impl fmt::Display for JsString {
5687    #[inline]
5688    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5689        fmt::Display::fmt(&String::from(self), f)
5690    }
5691}
5692
5693impl str::FromStr for JsString {
5694    type Err = convert::Infallible;
5695    fn from_str(s: &str) -> Result<Self, Self::Err> {
5696        Ok(JsString::from(s))
5697    }
5698}
5699
5700// Symbol
5701#[wasm_bindgen]
5702extern "C" {
5703    #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
5704    #[derive(Clone, Debug)]
5705    pub type Symbol;
5706
5707    /// The `Symbol.hasInstance` well-known symbol is used to determine
5708    /// if a constructor object recognizes an object as its instance.
5709    /// The `instanceof` operator's behavior can be customized by this symbol.
5710    ///
5711    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
5712    #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = hasInstance)]
5713    pub fn has_instance() -> Symbol;
5714
5715    /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
5716    /// if an object should be flattened to its array elements when using the
5717    /// `Array.prototype.concat()` method.
5718    ///
5719    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
5720    #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = isConcatSpreadable)]
5721    pub fn is_concat_spreadable() -> Symbol;
5722
5723    /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
5724    /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
5725    ///
5726    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
5727    #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = asyncIterator)]
5728    pub fn async_iterator() -> Symbol;
5729
5730    /// The `Symbol.iterator` well-known symbol specifies the default iterator
5731    /// for an object.  Used by `for...of`.
5732    ///
5733    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
5734    #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5735    pub fn iterator() -> Symbol;
5736
5737    /// The `Symbol.match` well-known symbol specifies the matching of a regular
5738    /// expression against a string. This function is called by the
5739    /// `String.prototype.match()` method.
5740    ///
5741    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
5742    #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = match)]
5743    pub fn match_() -> Symbol;
5744
5745    /// The `Symbol.replace` well-known symbol specifies the method that
5746    /// replaces matched substrings of a string.  This function is called by the
5747    /// `String.prototype.replace()` method.
5748    ///
5749    /// For more information, see `RegExp.prototype[@@replace]()` and
5750    /// `String.prototype.replace()`.
5751    ///
5752    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
5753    #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5754    pub fn replace() -> Symbol;
5755
5756    /// The `Symbol.search` well-known symbol specifies the method that returns
5757    /// the index within a string that matches the regular expression.  This
5758    /// function is called by the `String.prototype.search()` method.
5759    ///
5760    /// For more information, see `RegExp.prototype[@@search]()` and
5761    /// `String.prototype.search()`.
5762    ///
5763    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
5764    #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5765    pub fn search() -> Symbol;
5766
5767    /// The well-known symbol `Symbol.species` specifies a function-valued
5768    /// property that the constructor function uses to create derived objects.
5769    ///
5770    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
5771    #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5772    pub fn species() -> Symbol;
5773
5774    /// The `Symbol.split` well-known symbol specifies the method that splits a
5775    /// string at the indices that match a regular expression.  This function is
5776    /// called by the `String.prototype.split()` method.
5777    ///
5778    /// For more information, see `RegExp.prototype[@@split]()` and
5779    /// `String.prototype.split()`.
5780    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
5781    #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5782    pub fn split() -> Symbol;
5783
5784    /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
5785    /// property that is called to convert an object to a corresponding
5786    /// primitive value.
5787    ///
5788    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
5789    #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = toPrimitive)]
5790    pub fn to_primitive() -> Symbol;
5791
5792    /// The `Symbol.toStringTag` well-known symbol is a string valued property
5793    /// that is used in the creation of the default string description of an
5794    /// object.  It is accessed internally by the `Object.prototype.toString()`
5795    /// method.
5796    ///
5797    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
5798    #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = toStringTag)]
5799    pub fn to_string_tag() -> Symbol;
5800
5801    /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
5802    /// the given key and returns it if found.
5803    /// Otherwise a new symbol gets created in the global symbol registry with this key.
5804    ///
5805    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
5806    #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
5807    pub fn for_(key: &str) -> Symbol;
5808
5809    /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
5810    ///
5811    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
5812    #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
5813    pub fn key_for(sym: &Symbol) -> JsValue;
5814
5815    /// The `toString()` method returns a string representing the specified Symbol object.
5816    ///
5817    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
5818    #[wasm_bindgen(method, js_name = toString)]
5819    pub fn to_string(this: &Symbol) -> JsString;
5820
5821    /// The `Symbol.unscopables` well-known symbol is used to specify an object
5822    /// value of whose own and inherited property names are excluded from the
5823    /// with environment bindings of the associated object.
5824    ///
5825    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
5826    #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5827    pub fn unscopables() -> Symbol;
5828
5829    /// The `valueOf()` method returns the primitive value of a Symbol object.
5830    ///
5831    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
5832    #[wasm_bindgen(method, js_name = valueOf)]
5833    pub fn value_of(this: &Symbol) -> Symbol;
5834}
5835
5836#[allow(non_snake_case)]
5837pub mod Intl {
5838    use super::*;
5839
5840    // Intl
5841    #[wasm_bindgen]
5842    extern "C" {
5843        /// The `Intl.getCanonicalLocales()` method returns an array containing
5844        /// the canonical locale names. Duplicates will be omitted and elements
5845        /// will be validated as structurally valid language tags.
5846        ///
5847        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
5848        #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
5849        pub fn get_canonical_locales(s: &JsValue) -> Array;
5850    }
5851
5852    // Intl.Collator
5853    #[wasm_bindgen]
5854    extern "C" {
5855        /// The `Intl.Collator` object is a constructor for collators, objects
5856        /// that enable language sensitive string comparison.
5857        ///
5858        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
5859        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
5860        #[derive(Clone, Debug)]
5861        pub type Collator;
5862
5863        /// The `Intl.Collator` object is a constructor for collators, objects
5864        /// that enable language sensitive string comparison.
5865        ///
5866        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
5867        #[wasm_bindgen(constructor, js_namespace = Intl)]
5868        pub fn new(locales: &Array, options: &Object) -> Collator;
5869
5870        /// The Intl.Collator.prototype.compare property returns a function that
5871        /// compares two strings according to the sort order of this Collator
5872        /// object.
5873        ///
5874        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
5875        #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
5876        pub fn compare(this: &Collator) -> Function;
5877
5878        /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
5879        /// object with properties reflecting the locale and collation options
5880        /// computed during initialization of this Collator object.
5881        ///
5882        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
5883        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
5884        pub fn resolved_options(this: &Collator) -> Object;
5885
5886        /// The `Intl.Collator.supportedLocalesOf()` method returns an array
5887        /// containing those of the provided locales that are supported in
5888        /// collation without having to fall back to the runtime's default
5889        /// locale.
5890        ///
5891        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
5892        #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
5893        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
5894    }
5895
5896    impl Default for Collator {
5897        fn default() -> Self {
5898            Self::new(
5899                &JsValue::UNDEFINED.unchecked_into(),
5900                &JsValue::UNDEFINED.unchecked_into(),
5901            )
5902        }
5903    }
5904
5905    // Intl.DateTimeFormat
5906    #[wasm_bindgen]
5907    extern "C" {
5908        /// The `Intl.DateTimeFormat` object is a constructor for objects
5909        /// that enable language-sensitive date and time formatting.
5910        ///
5911        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
5912        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
5913        #[derive(Clone, Debug)]
5914        pub type DateTimeFormat;
5915
5916        /// The `Intl.DateTimeFormat` object is a constructor for objects
5917        /// that enable language-sensitive date and time formatting.
5918        ///
5919        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
5920        #[wasm_bindgen(constructor, js_namespace = Intl)]
5921        pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
5922
5923        /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
5924        /// formats a date according to the locale and formatting options of this
5925        /// Intl.DateTimeFormat object.
5926        ///
5927        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
5928        #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
5929        pub fn format(this: &DateTimeFormat) -> Function;
5930
5931        /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
5932        /// formatting of strings produced by DateTimeFormat formatters.
5933        ///
5934        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
5935        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
5936        pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
5937
5938        /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
5939        /// object with properties reflecting the locale and date and time formatting
5940        /// options computed during initialization of this DateTimeFormat object.
5941        ///
5942        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
5943        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
5944        pub fn resolved_options(this: &DateTimeFormat) -> Object;
5945
5946        /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
5947        /// containing those of the provided locales that are supported in date
5948        /// and time formatting without having to fall back to the runtime's default
5949        /// locale.
5950        ///
5951        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
5952        #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
5953        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
5954    }
5955
5956    impl Default for DateTimeFormat {
5957        fn default() -> Self {
5958            Self::new(
5959                &JsValue::UNDEFINED.unchecked_into(),
5960                &JsValue::UNDEFINED.unchecked_into(),
5961            )
5962        }
5963    }
5964
5965    // Intl.NumberFormat
5966    #[wasm_bindgen]
5967    extern "C" {
5968        /// The `Intl.NumberFormat` object is a constructor for objects
5969        /// that enable language sensitive number formatting.
5970        ///
5971        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
5972        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
5973        #[derive(Clone, Debug)]
5974        pub type NumberFormat;
5975
5976        /// The `Intl.NumberFormat` object is a constructor for objects
5977        /// that enable language sensitive number formatting.
5978        ///
5979        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
5980        #[wasm_bindgen(constructor, js_namespace = Intl)]
5981        pub fn new(locales: &Array, options: &Object) -> NumberFormat;
5982
5983        /// The Intl.NumberFormat.prototype.format property returns a getter function that
5984        /// formats a number according to the locale and formatting options of this
5985        /// NumberFormat object.
5986        ///
5987        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
5988        #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
5989        pub fn format(this: &NumberFormat) -> Function;
5990
5991        /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
5992        /// formatting of strings produced by NumberTimeFormat formatters.
5993        ///
5994        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
5995        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
5996        pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
5997
5998        /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
5999        /// object with properties reflecting the locale and number formatting
6000        /// options computed during initialization of this NumberFormat object.
6001        ///
6002        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
6003        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
6004        pub fn resolved_options(this: &NumberFormat) -> Object;
6005
6006        /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
6007        /// containing those of the provided locales that are supported in number
6008        /// formatting without having to fall back to the runtime's default locale.
6009        ///
6010        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
6011        #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
6012        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
6013    }
6014
6015    impl Default for NumberFormat {
6016        fn default() -> Self {
6017            Self::new(
6018                &JsValue::UNDEFINED.unchecked_into(),
6019                &JsValue::UNDEFINED.unchecked_into(),
6020            )
6021        }
6022    }
6023
6024    // Intl.PluralRules
6025    #[wasm_bindgen]
6026    extern "C" {
6027        /// The `Intl.PluralRules` object is a constructor for objects
6028        /// that enable plural sensitive formatting and plural language rules.
6029        ///
6030        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
6031        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
6032        #[derive(Clone, Debug)]
6033        pub type PluralRules;
6034
6035        /// The `Intl.PluralRules` object is a constructor for objects
6036        /// that enable plural sensitive formatting and plural language rules.
6037        ///
6038        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
6039        #[wasm_bindgen(constructor, js_namespace = Intl)]
6040        pub fn new(locales: &Array, options: &Object) -> PluralRules;
6041
6042        /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
6043        /// object with properties reflecting the locale and plural formatting
6044        /// options computed during initialization of this PluralRules object.
6045        ///
6046        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
6047        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
6048        pub fn resolved_options(this: &PluralRules) -> Object;
6049
6050        /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
6051        /// which plural rule to use for locale-aware formatting.
6052        ///
6053        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
6054        #[wasm_bindgen(method, js_namespace = Intl)]
6055        pub fn select(this: &PluralRules, number: f64) -> JsString;
6056
6057        /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
6058        /// containing those of the provided locales that are supported in plural
6059        /// formatting without having to fall back to the runtime's default locale.
6060        ///
6061        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
6062        #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
6063        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
6064    }
6065
6066    impl Default for PluralRules {
6067        fn default() -> Self {
6068            Self::new(
6069                &JsValue::UNDEFINED.unchecked_into(),
6070                &JsValue::UNDEFINED.unchecked_into(),
6071            )
6072        }
6073    }
6074
6075    // Intl.RelativeTimeFormat
6076    #[wasm_bindgen]
6077    extern "C" {
6078        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
6079        /// that enable language-sensitive relative time formatting.
6080        ///
6081        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
6082        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
6083        #[derive(Clone, Debug)]
6084        pub type RelativeTimeFormat;
6085
6086        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
6087        /// that enable language-sensitive relative time formatting.
6088        ///
6089        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
6090        #[wasm_bindgen(constructor, js_namespace = Intl)]
6091        pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
6092
6093        /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
6094        /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
6095        ///
6096        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
6097        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
6098        pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
6099
6100        /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
6101        /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
6102        ///
6103        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
6104        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
6105        pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
6106
6107        /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
6108        /// object with properties reflecting the locale and relative time formatting
6109        /// options computed during initialization of this RelativeTimeFormat object.
6110        ///
6111        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
6112        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
6113        pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
6114
6115        /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
6116        /// containing those of the provided locales that are supported in date and time
6117        /// formatting without having to fall back to the runtime's default locale.
6118        ///
6119        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
6120        #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
6121        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
6122    }
6123
6124    impl Default for RelativeTimeFormat {
6125        fn default() -> Self {
6126            Self::new(
6127                &JsValue::UNDEFINED.unchecked_into(),
6128                &JsValue::UNDEFINED.unchecked_into(),
6129            )
6130        }
6131    }
6132}
6133
6134// Promise
6135#[wasm_bindgen]
6136extern "C" {
6137    /// The `Promise` object represents the eventual completion (or failure) of
6138    /// an asynchronous operation, and its resulting value.
6139    ///
6140    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
6141    #[must_use]
6142    #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>")]
6143    #[derive(Clone, Debug)]
6144    pub type Promise;
6145
6146    /// Creates a new `Promise` with the provided executor `cb`
6147    ///
6148    /// The `cb` is a function that is passed with the arguments `resolve` and
6149    /// `reject`. The `cb` function is executed immediately by the `Promise`
6150    /// implementation, passing `resolve` and `reject` functions (the executor
6151    /// is called before the `Promise` constructor even returns the created
6152    /// object). The `resolve` and `reject` functions, when called, resolve or
6153    /// reject the promise, respectively. The executor normally initiates
6154    /// some asynchronous work, and then, once that completes, either calls
6155    /// the `resolve` function to resolve the promise or else rejects it if an
6156    /// error occurred.
6157    ///
6158    /// If an error is thrown in the executor function, the promise is rejected.
6159    /// The return value of the executor is ignored.
6160    ///
6161    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
6162    #[wasm_bindgen(constructor)]
6163    pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
6164
6165    /// The `Promise.all(iterable)` method returns a single `Promise` that
6166    /// resolves when all of the promises in the iterable argument have resolved
6167    /// or when the iterable argument contains no promises. It rejects with the
6168    /// reason of the first promise that rejects.
6169    ///
6170    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
6171    #[wasm_bindgen(static_method_of = Promise)]
6172    pub fn all(obj: &JsValue) -> Promise;
6173
6174    /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
6175    /// resolves when all of the promises in the iterable argument have either
6176    /// fulfilled or rejected or when the iterable argument contains no promises.
6177    ///
6178    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
6179    #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
6180    pub fn all_settled(obj: &JsValue) -> Promise;
6181
6182    /// The `Promise.any(iterable)` method returns a single `Promise` that
6183    /// resolves when any of the promises in the iterable argument have resolved
6184    /// or when the iterable argument contains no promises. It rejects with an
6185    /// `AggregateError` if all promises in the iterable rejected.
6186    ///
6187    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
6188    #[wasm_bindgen(static_method_of = Promise)]
6189    pub fn any(obj: &JsValue) -> Promise;
6190
6191    /// The `Promise.race(iterable)` method returns a promise that resolves or
6192    /// rejects as soon as one of the promises in the iterable resolves or
6193    /// rejects, with the value or reason from that promise.
6194    ///
6195    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
6196    #[wasm_bindgen(static_method_of = Promise)]
6197    pub fn race(obj: &JsValue) -> Promise;
6198
6199    /// The `Promise.reject(reason)` method returns a `Promise` object that is
6200    /// rejected with the given reason.
6201    ///
6202    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
6203    #[wasm_bindgen(static_method_of = Promise)]
6204    pub fn reject(obj: &JsValue) -> Promise;
6205
6206    /// The `Promise.resolve(value)` method returns a `Promise` object that is
6207    /// resolved with the given value. If the value is a promise, that promise
6208    /// is returned; if the value is a thenable (i.e. has a "then" method), the
6209    /// returned promise will "follow" that thenable, adopting its eventual
6210    /// state; otherwise the returned promise will be fulfilled with the value.
6211    ///
6212    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
6213    #[wasm_bindgen(static_method_of = Promise)]
6214    pub fn resolve(obj: &JsValue) -> Promise;
6215
6216    /// The `catch()` method returns a `Promise` and deals with rejected cases
6217    /// only.  It behaves the same as calling `Promise.prototype.then(undefined,
6218    /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
6219    /// `obj.then(undefined, onRejected)`).
6220    ///
6221    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
6222    #[wasm_bindgen(method)]
6223    pub fn catch(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise;
6224
6225    /// The `then()` method returns a `Promise`. It takes up to two arguments:
6226    /// callback functions for the success and failure cases of the `Promise`.
6227    ///
6228    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
6229    #[wasm_bindgen(method)]
6230    pub fn then(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise;
6231
6232    /// Same as `then`, only with both arguments provided.
6233    #[wasm_bindgen(method, js_name = then)]
6234    pub fn then2(
6235        this: &Promise,
6236        resolve: &Closure<dyn FnMut(JsValue)>,
6237        reject: &Closure<dyn FnMut(JsValue)>,
6238    ) -> Promise;
6239
6240    /// The `finally()` method returns a `Promise`. When the promise is settled,
6241    /// whether fulfilled or rejected, the specified callback function is
6242    /// executed. This provides a way for code that must be executed once the
6243    /// `Promise` has been dealt with to be run whether the promise was
6244    /// fulfilled successfully or rejected.
6245    ///
6246    /// This lets you avoid duplicating code in both the promise's `then()` and
6247    /// `catch()` handlers.
6248    ///
6249    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
6250    #[wasm_bindgen(method)]
6251    pub fn finally(this: &Promise, cb: &Closure<dyn FnMut()>) -> Promise;
6252}
6253
6254/// Returns a handle to the global scope object.
6255///
6256/// This allows access to the global properties and global names by accessing
6257/// the `Object` returned.
6258pub fn global() -> Object {
6259    use once_cell::unsync::Lazy;
6260
6261    struct Wrapper<T>(Lazy<T>);
6262
6263    #[cfg(not(target_feature = "atomics"))]
6264    unsafe impl<T> Sync for Wrapper<T> {}
6265
6266    #[cfg(not(target_feature = "atomics"))]
6267    unsafe impl<T> Send for Wrapper<T> {}
6268
6269    #[cfg_attr(target_feature = "atomics", thread_local)]
6270    static GLOBAL: Wrapper<Object> = Wrapper(Lazy::new(get_global_object));
6271
6272    return GLOBAL.0.clone();
6273
6274    fn get_global_object() -> Object {
6275        // Accessing the global object is not an easy thing to do, and what we
6276        // basically want is `globalThis` but we can't rely on that existing
6277        // everywhere. In the meantime we've got the fallbacks mentioned in:
6278        //
6279        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
6280        //
6281        // Note that this is pretty heavy code-size wise but it at least gets
6282        // the job largely done for now and avoids the `Function` constructor at
6283        // the end which triggers CSP errors.
6284        #[wasm_bindgen]
6285        extern "C" {
6286            type Global;
6287
6288            #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
6289            static GLOBAL_THIS: Option<Object>;
6290
6291            #[wasm_bindgen(thread_local_v2, js_name = self)]
6292            static SELF: Option<Object>;
6293
6294            #[wasm_bindgen(thread_local_v2, js_name = window)]
6295            static WINDOW: Option<Object>;
6296
6297            #[wasm_bindgen(thread_local_v2, js_name = global)]
6298            static GLOBAL: Option<Object>;
6299        }
6300
6301        // The order is important: in Firefox Extension Content Scripts `globalThis`
6302        // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
6303        let static_object = SELF
6304            .with(Option::clone)
6305            .or_else(|| WINDOW.with(Option::clone))
6306            .or_else(|| GLOBAL_THIS.with(Option::clone))
6307            .or_else(|| GLOBAL.with(Option::clone));
6308        if let Some(obj) = static_object {
6309            if !obj.is_undefined() {
6310                return obj;
6311            }
6312        }
6313
6314        // According to StackOverflow you can access the global object via:
6315        //
6316        //      const global = Function('return this')();
6317        //
6318        // I think that's because the manufactured function isn't in "strict" mode.
6319        // It also turns out that non-strict functions will ignore `undefined`
6320        // values for `this` when using the `apply` function.
6321        //
6322        // As a result we use the equivalent of this snippet to get a handle to the
6323        // global object in a sort of roundabout way that should hopefully work in
6324        // all contexts like ESM, node, browsers, etc.
6325        let this = Function::new_no_args("return this")
6326            .call0(&JsValue::undefined())
6327            .ok();
6328
6329        // Note that we avoid `unwrap()` on `call0` to avoid code size bloat, we
6330        // just handle the `Err` case as returning a different object.
6331        debug_assert!(this.is_some());
6332        match this {
6333            Some(this) => this.unchecked_into(),
6334            None => JsValue::undefined().unchecked_into(),
6335        }
6336    }
6337}
6338
6339macro_rules! arrays {
6340    ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
6341        #[wasm_bindgen]
6342        extern "C" {
6343            #[wasm_bindgen(extends = Object, typescript_type = $name)]
6344            #[derive(Clone, Debug)]
6345            pub type $name;
6346
6347            /// The
6348            #[doc = $ctor]
6349            /// constructor creates a new array.
6350            ///
6351            /// [MDN documentation](
6352            #[doc = $mdn]
6353            /// )
6354            #[wasm_bindgen(constructor)]
6355            pub fn new(constructor_arg: &JsValue) -> $name;
6356
6357            /// An
6358            #[doc = $ctor]
6359            /// which creates an array with an internal buffer large
6360            /// enough for `length` elements.
6361            ///
6362            /// [MDN documentation](
6363            #[doc = $mdn]
6364            /// )
6365            #[wasm_bindgen(constructor)]
6366            pub fn new_with_length(length: u32) -> $name;
6367
6368            /// An
6369            #[doc = $ctor]
6370            /// which creates an array from a Rust slice.
6371            ///
6372            /// [MDN documentation](
6373            #[doc = $mdn]
6374            /// )
6375            #[wasm_bindgen(constructor)]
6376            pub fn new_from_slice(slice: &[$ty]) -> $name;
6377
6378            /// An
6379            #[doc = $ctor]
6380            /// which creates an array with the given buffer but is a
6381            /// view starting at `byte_offset`.
6382            ///
6383            /// [MDN documentation](
6384            #[doc = $mdn]
6385            /// )
6386            #[wasm_bindgen(constructor)]
6387            pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
6388
6389            /// An
6390            #[doc = $ctor]
6391            /// which creates an array with the given buffer but is a
6392            /// view starting at `byte_offset` for `length` elements.
6393            ///
6394            /// [MDN documentation](
6395            #[doc = $mdn]
6396            /// )
6397            #[wasm_bindgen(constructor)]
6398            pub fn new_with_byte_offset_and_length(
6399                buffer: &JsValue,
6400                byte_offset: u32,
6401                length: u32,
6402            ) -> $name;
6403
6404            /// The `fill()` method fills all the elements of an array from a start index
6405            /// to an end index with a static value. The end index is not included.
6406            ///
6407            /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
6408            #[wasm_bindgen(method)]
6409            pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
6410
6411            /// The buffer accessor property represents the `ArrayBuffer` referenced
6412            /// by a `TypedArray` at construction time.
6413            #[wasm_bindgen(getter, method)]
6414            pub fn buffer(this: &$name) -> ArrayBuffer;
6415
6416            /// The `subarray()` method returns a new `TypedArray` on the same
6417            /// `ArrayBuffer` store and with the same element types as for this
6418            /// `TypedArray` object.
6419            #[wasm_bindgen(method)]
6420            pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
6421
6422            /// The `slice()` method returns a shallow copy of a portion of a typed
6423            /// array into a new typed array object. This method has the same algorithm
6424            /// as `Array.prototype.slice()`.
6425            #[wasm_bindgen(method)]
6426            pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
6427
6428            /// The `forEach()` method executes a provided function once per array
6429            /// element. This method has the same algorithm as
6430            /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
6431            /// types here.
6432            #[wasm_bindgen(method, js_name = forEach)]
6433            pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
6434
6435            /// The length accessor property represents the length (in elements) of a
6436            /// typed array.
6437            #[wasm_bindgen(method, getter)]
6438            pub fn length(this: &$name) -> u32;
6439
6440            /// The byteLength accessor property represents the length (in bytes) of a
6441            /// typed array.
6442            #[wasm_bindgen(method, getter, js_name = byteLength)]
6443            pub fn byte_length(this: &$name) -> u32;
6444
6445            /// The byteOffset accessor property represents the offset (in bytes) of a
6446            /// typed array from the start of its `ArrayBuffer`.
6447            #[wasm_bindgen(method, getter, js_name = byteOffset)]
6448            pub fn byte_offset(this: &$name) -> u32;
6449
6450            /// The `set()` method stores multiple values in the typed array, reading
6451            /// input values from a specified array.
6452            #[wasm_bindgen(method)]
6453            pub fn set(this: &$name, src: &JsValue, offset: u32);
6454
6455            /// Gets the value at `idx`, counting from the end if negative.
6456            #[wasm_bindgen(method)]
6457            pub fn at(this: &$name, idx: i32) -> Option<$ty>;
6458
6459            /// The `copyWithin()` method shallow copies part of a typed array to another
6460            /// location in the same typed array and returns it, without modifying its size.
6461            ///
6462            /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
6463            #[wasm_bindgen(method, js_name = copyWithin)]
6464            pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
6465
6466            /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
6467            #[wasm_bindgen(method, structural, indexing_getter)]
6468            pub fn get_index(this: &$name, idx: u32) -> $ty;
6469
6470            /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
6471            #[wasm_bindgen(method, structural, indexing_setter)]
6472            pub fn set_index(this: &$name, idx: u32, value: $ty);
6473
6474            /// Copies the Rust slice's data to self.
6475            ///
6476            /// This method is not expected to be public. It requires the length of the
6477            /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
6478            #[wasm_bindgen(method, js_name = set)]
6479            fn copy_from_slice(this: &$name, slice: &[$ty]);
6480
6481            /// Copies this TypedArray's data to Rust slice;
6482            ///
6483            /// This method is not expected to be public. It requires the length of the
6484            /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
6485            ///
6486            /// # Workaround
6487            ///
6488            /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
6489            /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
6490            /// us to specify the `this` value inside the function.
6491            ///
6492            /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
6493            /// `slice.set(typed_array)`.
6494            #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
6495            fn copy_to_slice(slice: &mut [$ty], this: &$name);
6496        }
6497
6498        impl $name {
6499            /// Creates a JS typed array which is a view into wasm's linear
6500            /// memory at the slice specified.
6501            ///
6502            /// This function returns a new typed array which is a view into
6503            /// wasm's memory. This view does not copy the underlying data.
6504            ///
6505            /// # Safety
6506            ///
6507            /// Views into WebAssembly memory are only valid so long as the
6508            /// backing buffer isn't resized in JS. Once this function is called
6509            /// any future calls to `Box::new` (or malloc of any form) may cause
6510            /// the returned value here to be invalidated. Use with caution!
6511            ///
6512            /// Additionally the returned object can be safely mutated but the
6513            /// input slice isn't guaranteed to be mutable.
6514            ///
6515            /// Finally, the returned object is disconnected from the input
6516            /// slice's lifetime, so there's no guarantee that the data is read
6517            /// at the right time.
6518            pub unsafe fn view(rust: &[$ty]) -> $name {
6519                wasm_bindgen::__rt::wbg_cast(rust)
6520            }
6521
6522            /// Creates a JS typed array which is a view into wasm's linear
6523            /// memory at the specified pointer with specified length.
6524            ///
6525            /// This function returns a new typed array which is a view into
6526            /// wasm's memory. This view does not copy the underlying data.
6527            ///
6528            /// # Safety
6529            ///
6530            /// Views into WebAssembly memory are only valid so long as the
6531            /// backing buffer isn't resized in JS. Once this function is called
6532            /// any future calls to `Box::new` (or malloc of any form) may cause
6533            /// the returned value here to be invalidated. Use with caution!
6534            ///
6535            /// Additionally the returned object can be safely mutated,
6536            /// the changes are guaranteed to be reflected in the input array.
6537            pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
6538                let slice = core::slice::from_raw_parts_mut(ptr, length);
6539                Self::view(slice)
6540            }
6541
6542            /// Copy the contents of this JS typed array into the destination
6543            /// Rust pointer.
6544            ///
6545            /// This function will efficiently copy the memory from a typed
6546            /// array into this Wasm module's own linear memory, initializing
6547            /// the memory destination provided.
6548            ///
6549            /// # Safety
6550            ///
6551            /// This function requires `dst` to point to a buffer
6552            /// large enough to fit this array's contents.
6553            pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
6554                let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
6555                self.copy_to(slice);
6556            }
6557
6558            /// Copy the contents of this JS typed array into the destination
6559            /// Rust slice.
6560            ///
6561            /// This function will efficiently copy the memory from a typed
6562            /// array into this Wasm module's own linear memory, initializing
6563            /// the memory destination provided.
6564            ///
6565            /// # Panics
6566            ///
6567            /// This function will panic if this typed array's length is
6568            /// different than the length of the provided `dst` array.
6569            pub fn copy_to(&self, dst: &mut [$ty]) {
6570                core::assert_eq!(self.length() as usize, dst.len());
6571                $name::copy_to_slice(dst, self);
6572            }
6573
6574            /// Copy the contents of this JS typed array into the destination
6575            /// Rust slice.
6576            ///
6577            /// This function will efficiently copy the memory from a typed
6578            /// array into this Wasm module's own linear memory, initializing
6579            /// the memory destination provided.
6580            ///
6581            /// # Panics
6582            ///
6583            /// This function will panic if this typed array's length is
6584            /// different than the length of the provided `dst` array.
6585            pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
6586                core::assert_eq!(self.length() as usize, dst.len());
6587                let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
6588                self.copy_to(dst);
6589                dst
6590            }
6591
6592            /// Copy the contents of the source Rust slice into this
6593            /// JS typed array.
6594            ///
6595            /// This function will efficiently copy the memory from within
6596            /// the Wasm module's own linear memory to this typed array.
6597            ///
6598            /// # Panics
6599            ///
6600            /// This function will panic if this typed array's length is
6601            /// different than the length of the provided `src` array.
6602            pub fn copy_from(&self, src: &[$ty]) {
6603                core::assert_eq!(self.length() as usize, src.len());
6604                self.copy_from_slice(src);
6605            }
6606
6607            /// Efficiently copies the contents of this JS typed array into a new Vec.
6608            pub fn to_vec(&self) -> Vec<$ty> {
6609                let len = self.length() as usize;
6610                let mut output = Vec::with_capacity(len);
6611                // Safety: the capacity has been set
6612                unsafe {
6613                    self.raw_copy_to_ptr(output.as_mut_ptr());
6614                    output.set_len(len);
6615                }
6616                output
6617            }
6618        }
6619
6620        impl<'a> From<&'a [$ty]> for $name {
6621            #[inline]
6622            fn from(slice: &'a [$ty]) -> $name {
6623                // This is safe because the `new` function makes a copy if its argument is a TypedArray
6624                $name::new_from_slice(slice)
6625            }
6626        }
6627
6628        impl Default for $name {
6629            fn default() -> Self {
6630                Self::new(&JsValue::UNDEFINED.unchecked_into())
6631            }
6632        }
6633    )*);
6634}
6635
6636arrays! {
6637    /// `Int8Array()`
6638    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
6639    Int8Array: i8,
6640
6641    /// `Int16Array()`
6642    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
6643    Int16Array: i16,
6644
6645    /// `Int32Array()`
6646    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
6647    Int32Array: i32,
6648
6649    /// `Uint8Array()`
6650    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
6651    Uint8Array: u8,
6652
6653    /// `Uint8ClampedArray()`
6654    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
6655    Uint8ClampedArray: u8,
6656
6657    /// `Uint16Array()`
6658    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
6659    Uint16Array: u16,
6660
6661    /// `Uint32Array()`
6662    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
6663    Uint32Array: u32,
6664
6665    /// `Float32Array()`
6666    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
6667    Float32Array: f32,
6668
6669    /// `Float64Array()`
6670    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
6671    Float64Array: f64,
6672
6673    /// `BigInt64Array()`
6674    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
6675    BigInt64Array: i64,
6676
6677    /// `BigUint64Array()`
6678    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
6679    BigUint64Array: u64,
6680}