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::{self, 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#[cfg(js_sys_unstable_apis)]
4575#[allow(non_snake_case)]
4576pub mod Temporal;
4577
4578#[allow(non_snake_case)]
4579pub mod WebAssembly {
4580    use super::*;
4581
4582    // WebAssembly
4583    #[wasm_bindgen]
4584    extern "C" {
4585        /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
4586        /// from WebAssembly binary code.  This function is useful if it is
4587        /// necessary to a compile a module before it can be instantiated
4588        /// (otherwise, the `WebAssembly.instantiate()` function should be used).
4589        ///
4590        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
4591        #[wasm_bindgen(js_namespace = WebAssembly)]
4592        pub fn compile(buffer_source: &JsValue) -> Promise;
4593
4594        /// The `WebAssembly.compileStreaming()` function compiles a
4595        /// `WebAssembly.Module` module directly from a streamed underlying
4596        /// source. This function is useful if it is necessary to a compile a
4597        /// module before it can be instantiated (otherwise, the
4598        /// `WebAssembly.instantiateStreaming()` function should be used).
4599        ///
4600        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
4601        #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
4602        pub fn compile_streaming(response: &Promise) -> Promise;
4603
4604        /// The `WebAssembly.instantiate()` function allows you to compile and
4605        /// instantiate WebAssembly code.
4606        ///
4607        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
4608        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
4609        pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise;
4610
4611        /// The `WebAssembly.instantiate()` function allows you to compile and
4612        /// instantiate WebAssembly code.
4613        ///
4614        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
4615        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
4616        pub fn instantiate_module(module: &Module, imports: &Object) -> Promise;
4617
4618        /// The `WebAssembly.instantiateStreaming()` function compiles and
4619        /// instantiates a WebAssembly module directly from a streamed
4620        /// underlying source. This is the most efficient, optimized way to load
4621        /// Wasm code.
4622        ///
4623        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
4624        #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
4625        pub fn instantiate_streaming(response: &Promise, imports: &Object) -> Promise;
4626
4627        /// The `WebAssembly.validate()` function validates a given typed
4628        /// array of WebAssembly binary code, returning whether the bytes
4629        /// form a valid Wasm module (`true`) or not (`false`).
4630        ///
4631        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
4632        #[wasm_bindgen(js_namespace = WebAssembly, catch)]
4633        pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
4634    }
4635
4636    // WebAssembly.CompileError
4637    #[wasm_bindgen]
4638    extern "C" {
4639        /// The `WebAssembly.CompileError()` constructor creates a new
4640        /// WebAssembly `CompileError` object, which indicates an error during
4641        /// WebAssembly decoding or validation.
4642        ///
4643        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
4644        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
4645        #[derive(Clone, Debug, PartialEq, Eq)]
4646        pub type CompileError;
4647
4648        /// The `WebAssembly.CompileError()` constructor creates a new
4649        /// WebAssembly `CompileError` object, which indicates an error during
4650        /// WebAssembly decoding or validation.
4651        ///
4652        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
4653        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
4654        pub fn new(message: &str) -> CompileError;
4655    }
4656
4657    // WebAssembly.Instance
4658    #[wasm_bindgen]
4659    extern "C" {
4660        /// A `WebAssembly.Instance` object is a stateful, executable instance
4661        /// of a `WebAssembly.Module`. Instance objects contain all the exported
4662        /// WebAssembly functions that allow calling into WebAssembly code from
4663        /// JavaScript.
4664        ///
4665        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
4666        #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
4667        #[derive(Clone, Debug, PartialEq, Eq)]
4668        pub type Instance;
4669
4670        /// The `WebAssembly.Instance()` constructor function can be called to
4671        /// synchronously instantiate a given `WebAssembly.Module`
4672        /// object. However, the primary way to get an `Instance` is through the
4673        /// asynchronous `WebAssembly.instantiateStreaming()` function.
4674        ///
4675        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
4676        #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
4677        pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
4678
4679        /// The `exports` readonly property of the `WebAssembly.Instance` object
4680        /// prototype returns an object containing as its members all the
4681        /// functions exported from the WebAssembly module instance, to allow
4682        /// them to be accessed and used by JavaScript.
4683        ///
4684        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
4685        #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
4686        pub fn exports(this: &Instance) -> Object;
4687    }
4688
4689    // WebAssembly.LinkError
4690    #[wasm_bindgen]
4691    extern "C" {
4692        /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
4693        /// LinkError object, which indicates an error during module
4694        /// instantiation (besides traps from the start function).
4695        ///
4696        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
4697        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
4698        #[derive(Clone, Debug, PartialEq, Eq)]
4699        pub type LinkError;
4700
4701        /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
4702        /// LinkError object, which indicates an error during module
4703        /// instantiation (besides traps from the start function).
4704        ///
4705        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
4706        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
4707        pub fn new(message: &str) -> LinkError;
4708    }
4709
4710    // WebAssembly.RuntimeError
4711    #[wasm_bindgen]
4712    extern "C" {
4713        /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
4714        /// `RuntimeError` object — the type that is thrown whenever WebAssembly
4715        /// specifies a trap.
4716        ///
4717        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
4718        #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
4719        #[derive(Clone, Debug, PartialEq, Eq)]
4720        pub type RuntimeError;
4721
4722        /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
4723        /// `RuntimeError` object — the type that is thrown whenever WebAssembly
4724        /// specifies a trap.
4725        ///
4726        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
4727        #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
4728        pub fn new(message: &str) -> RuntimeError;
4729    }
4730
4731    // WebAssembly.Module
4732    #[wasm_bindgen]
4733    extern "C" {
4734        /// A `WebAssembly.Module` object contains stateless WebAssembly code
4735        /// that has already been compiled by the browser and can be
4736        /// efficiently shared with Workers, and instantiated multiple times.
4737        ///
4738        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
4739        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
4740        #[derive(Clone, Debug, PartialEq, Eq)]
4741        pub type Module;
4742
4743        /// A `WebAssembly.Module` object contains stateless WebAssembly code
4744        /// that has already been compiled by the browser and can be
4745        /// efficiently shared with Workers, and instantiated multiple times.
4746        ///
4747        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
4748        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4749        pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
4750
4751        /// The `WebAssembly.customSections()` function returns a copy of the
4752        /// contents of all custom sections in the given module with the given
4753        /// string name.
4754        ///
4755        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
4756        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
4757        pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
4758
4759        /// The `WebAssembly.exports()` function returns an array containing
4760        /// descriptions of all the declared exports of the given `Module`.
4761        ///
4762        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
4763        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
4764        pub fn exports(module: &Module) -> Array;
4765
4766        /// The `WebAssembly.imports()` function returns an array containing
4767        /// descriptions of all the declared imports of the given `Module`.
4768        ///
4769        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
4770        #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
4771        pub fn imports(module: &Module) -> Array;
4772    }
4773
4774    // WebAssembly.Table
4775    #[wasm_bindgen]
4776    extern "C" {
4777        /// The `WebAssembly.Table()` constructor creates a new `Table` object
4778        /// of the given size and element type.
4779        ///
4780        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
4781        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
4782        #[derive(Clone, Debug, PartialEq, Eq)]
4783        pub type Table;
4784
4785        /// The `WebAssembly.Table()` constructor creates a new `Table` object
4786        /// of the given size and element type.
4787        ///
4788        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
4789        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4790        pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
4791
4792        /// The length prototype property of the `WebAssembly.Table` object
4793        /// returns the length of the table, i.e. the number of elements in the
4794        /// table.
4795        ///
4796        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
4797        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
4798        pub fn length(this: &Table) -> u32;
4799
4800        /// The `get()` prototype method of the `WebAssembly.Table()` object
4801        /// retrieves a function reference stored at a given index.
4802        ///
4803        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
4804        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
4805        pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
4806
4807        /// The `grow()` prototype method of the `WebAssembly.Table` object
4808        /// increases the size of the `Table` instance by a specified number of
4809        /// elements.
4810        ///
4811        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
4812        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
4813        pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
4814
4815        /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
4816        /// reference stored at a given index to a different value.
4817        ///
4818        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
4819        #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
4820        pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
4821    }
4822
4823    // WebAssembly.Tag
4824    #[wasm_bindgen]
4825    extern "C" {
4826        /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
4827        ///
4828        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
4829        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
4830        #[derive(Clone, Debug, PartialEq, Eq)]
4831        pub type Tag;
4832
4833        /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
4834        ///
4835        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
4836        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4837        pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
4838    }
4839
4840    // WebAssembly.Exception
4841    #[wasm_bindgen]
4842    extern "C" {
4843        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
4844        ///
4845        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
4846        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
4847        #[derive(Clone, Debug, PartialEq, Eq)]
4848        pub type Exception;
4849
4850        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
4851        ///
4852        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
4853        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4854        pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
4855
4856        /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
4857        ///
4858        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
4859        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4860        pub fn new_with_options(
4861            tag: &Tag,
4862            payload: &Array,
4863            options: &Object,
4864        ) -> Result<Exception, JsValue>;
4865
4866        /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
4867        /// test if the Exception matches a given tag.
4868        ///
4869        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
4870        #[wasm_bindgen(method, js_namespace = WebAssembly)]
4871        pub fn is(this: &Exception, tag: &Tag) -> bool;
4872
4873        /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
4874        /// to get the value of a specified item in the exception's data arguments
4875        ///
4876        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
4877        #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
4878        pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
4879    }
4880
4881    // WebAssembly.Global
4882    #[wasm_bindgen]
4883    extern "C" {
4884        /// The `WebAssembly.Global()` constructor creates a new `Global` object
4885        /// of the given type and value.
4886        ///
4887        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
4888        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
4889        #[derive(Clone, Debug, PartialEq, Eq)]
4890        pub type Global;
4891
4892        /// The `WebAssembly.Global()` constructor creates a new `Global` object
4893        /// of the given type and value.
4894        ///
4895        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
4896        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4897        pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
4898
4899        /// The value prototype property of the `WebAssembly.Global` object
4900        /// returns the value of the global.
4901        ///
4902        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
4903        #[wasm_bindgen(method, getter, structural, js_namespace = WebAssembly)]
4904        pub fn value(this: &Global) -> JsValue;
4905        #[wasm_bindgen(method, setter = value, structural, js_namespace = WebAssembly)]
4906        pub fn set_value(this: &Global, value: &JsValue);
4907    }
4908
4909    // WebAssembly.Memory
4910    #[wasm_bindgen]
4911    extern "C" {
4912        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
4913        #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
4914        #[derive(Clone, Debug, PartialEq, Eq)]
4915        pub type Memory;
4916
4917        /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
4918        /// which is a resizable `ArrayBuffer` that holds the raw bytes of
4919        /// memory accessed by a WebAssembly `Instance`.
4920        ///
4921        /// A memory created by JavaScript or in WebAssembly code will be
4922        /// accessible and mutable from both JavaScript and WebAssembly.
4923        ///
4924        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
4925        #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4926        pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
4927
4928        /// An accessor property that returns the buffer contained in the
4929        /// memory.
4930        ///
4931        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
4932        #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
4933        pub fn buffer(this: &Memory) -> JsValue;
4934
4935        /// The `grow()` prototype method of the `Memory` object increases the
4936        /// size of the memory instance by a specified number of WebAssembly
4937        /// pages.
4938        ///
4939        /// Takes the number of pages to grow (64KiB in size) and returns the
4940        /// previous size of memory, in pages.
4941        ///
4942        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
4943        #[wasm_bindgen(method, js_namespace = WebAssembly)]
4944        pub fn grow(this: &Memory, pages: u32) -> u32;
4945    }
4946}
4947
4948/// The `JSON` object contains methods for parsing [JavaScript Object
4949/// Notation (JSON)](https://json.org/) and converting values to JSON. It
4950/// can't be called or constructed, and aside from its two method
4951/// properties, it has no interesting functionality of its own.
4952#[allow(non_snake_case)]
4953pub mod JSON {
4954    use super::*;
4955
4956    // JSON
4957    #[wasm_bindgen]
4958    extern "C" {
4959        /// The `JSON.parse()` method parses a JSON string, constructing the
4960        /// JavaScript value or object described by the string.
4961        ///
4962        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
4963        #[wasm_bindgen(catch, js_namespace = JSON)]
4964        pub fn parse(text: &str) -> Result<JsValue, JsValue>;
4965
4966        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
4967        ///
4968        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
4969        #[wasm_bindgen(catch, js_namespace = JSON)]
4970        pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
4971
4972        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
4973        ///
4974        /// The `replacer` argument is a function that alters the behavior of the stringification
4975        /// process, or an array of String and Number objects that serve as a whitelist
4976        /// for selecting/filtering the properties of the value object to be included
4977        /// in the JSON string. If this value is null or not provided, all properties
4978        /// of the object are included in the resulting JSON string.
4979        ///
4980        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
4981        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
4982        pub fn stringify_with_replacer(
4983            obj: &JsValue,
4984            replacer: &JsValue,
4985        ) -> Result<JsString, JsValue>;
4986
4987        /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
4988        ///
4989        /// The `replacer` argument is a function that alters the behavior of the stringification
4990        /// process, or an array of String and Number objects that serve as a whitelist
4991        /// for selecting/filtering the properties of the value object to be included
4992        /// in the JSON string. If this value is null or not provided, all properties
4993        /// of the object are included in the resulting JSON string.
4994        ///
4995        /// The `space` argument is a String or Number object that's used to insert white space into
4996        /// the output JSON string for readability purposes. If this is a Number, it
4997        /// indicates the number of space characters to use as white space; this number
4998        /// is capped at 10 (if it is greater, the value is just 10). Values less than
4999        /// 1 indicate that no space should be used. If this is a String, the string
5000        /// (or the first 10 characters of the string, if it's longer than that) is
5001        /// used as white space. If this parameter is not provided (or is null), no
5002        /// white space is used.
5003        ///
5004        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
5005        #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
5006        pub fn stringify_with_replacer_and_space(
5007            obj: &JsValue,
5008            replacer: &JsValue,
5009            space: &JsValue,
5010        ) -> Result<JsString, JsValue>;
5011
5012    }
5013}
5014
5015// JsString
5016#[wasm_bindgen]
5017extern "C" {
5018    #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
5019    #[derive(Clone, PartialEq, Eq)]
5020    pub type JsString;
5021
5022    /// The length property of a String object indicates the length of a string,
5023    /// in UTF-16 code units.
5024    ///
5025    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
5026    #[wasm_bindgen(method, getter, structural)]
5027    pub fn length(this: &JsString) -> u32;
5028
5029    /// The 'at()' method returns a new string consisting of the single UTF-16
5030    /// code unit located at the specified offset into the string, counting from
5031    /// the end if it's negative.
5032    ///
5033    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
5034    #[wasm_bindgen(method, js_class = "String")]
5035    pub fn at(this: &JsString, index: i32) -> Option<JsString>;
5036
5037    /// The String object's `charAt()` method returns a new string consisting of
5038    /// the single UTF-16 code unit located at the specified offset into the
5039    /// string.
5040    ///
5041    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
5042    #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
5043    pub fn char_at(this: &JsString, index: u32) -> JsString;
5044
5045    /// The `charCodeAt()` method returns an integer between 0 and 65535
5046    /// representing the UTF-16 code unit at the given index (the UTF-16 code
5047    /// unit matches the Unicode code point for code points representable in a
5048    /// single UTF-16 code unit, but might also be the first code unit of a
5049    /// surrogate pair for code points not representable in a single UTF-16 code
5050    /// unit, e.g. Unicode code points > 0x10000).  If you want the entire code
5051    /// point value, use `codePointAt()`.
5052    ///
5053    /// Returns `NaN` if index is out of range.
5054    ///
5055    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
5056    #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
5057    pub fn char_code_at(this: &JsString, index: u32) -> f64;
5058
5059    /// The `codePointAt()` method returns a non-negative integer that is the
5060    /// Unicode code point value.
5061    ///
5062    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
5063    #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
5064    pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
5065
5066    /// The `concat()` method concatenates the string arguments to the calling
5067    /// string and returns a new string.
5068    ///
5069    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
5070    #[wasm_bindgen(method, js_class = "String")]
5071    pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
5072
5073    /// The `endsWith()` method determines whether a string ends with the characters of a
5074    /// specified string, returning true or false as appropriate.
5075    ///
5076    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
5077    #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
5078    pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
5079
5080    /// The static `String.fromCharCode()` method returns a string created from
5081    /// the specified sequence of UTF-16 code units.
5082    ///
5083    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5084    ///
5085    /// # Notes
5086    ///
5087    /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
5088    /// with different arities.
5089    ///
5090    /// Additionally, this function accepts `u16` for character codes, but
5091    /// fixing others requires a breaking change release
5092    /// (see https://github.com/wasm-bindgen/wasm-bindgen/issues/1460 for details).
5093    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
5094    pub fn from_char_code(char_codes: &[u16]) -> JsString;
5095
5096    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5097    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5098    pub fn from_char_code1(a: u32) -> JsString;
5099
5100    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5101    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5102    pub fn from_char_code2(a: u32, b: u32) -> JsString;
5103
5104    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5105    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5106    pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
5107
5108    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5109    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5110    pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
5111
5112    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5113    #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5114    pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
5115
5116    /// The static `String.fromCodePoint()` method returns a string created by
5117    /// using the specified sequence of code points.
5118    ///
5119    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5120    ///
5121    /// # Exceptions
5122    ///
5123    /// A RangeError is thrown if an invalid Unicode code point is given
5124    ///
5125    /// # Notes
5126    ///
5127    /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
5128    /// with different arities.
5129    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
5130    pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
5131
5132    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5133    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5134    pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
5135
5136    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5137    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5138    pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
5139
5140    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5141    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5142    pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
5143
5144    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5145    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5146    pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
5147
5148    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5149    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5150    pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
5151
5152    /// The `includes()` method determines whether one string may be found
5153    /// within another string, returning true or false as appropriate.
5154    ///
5155    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
5156    #[wasm_bindgen(method, js_class = "String")]
5157    pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
5158
5159    /// The `indexOf()` method returns the index within the calling String
5160    /// object of the first occurrence of the specified value, starting the
5161    /// search at fromIndex.  Returns -1 if the value is not found.
5162    ///
5163    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
5164    #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
5165    pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
5166
5167    /// The `lastIndexOf()` method returns the index within the calling String
5168    /// object of the last occurrence of the specified value, searching
5169    /// backwards from fromIndex.  Returns -1 if the value is not found.
5170    ///
5171    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
5172    #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
5173    pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
5174
5175    /// The `localeCompare()` method returns a number indicating whether
5176    /// a reference string comes before or after or is the same as
5177    /// the given string in sort order.
5178    ///
5179    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
5180    #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
5181    pub fn locale_compare(
5182        this: &JsString,
5183        compare_string: &str,
5184        locales: &Array,
5185        options: &Object,
5186    ) -> i32;
5187
5188    /// The `match()` method retrieves the matches when matching a string against a regular expression.
5189    ///
5190    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
5191    #[wasm_bindgen(method, js_class = "String", js_name = match)]
5192    pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
5193
5194    /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
5195    ///
5196    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
5197    #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
5198    pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
5199
5200    /// The `normalize()` method returns the Unicode Normalization Form
5201    /// of a given string (if the value isn't a string, it will be converted to one first).
5202    ///
5203    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
5204    #[wasm_bindgen(method, js_class = "String")]
5205    pub fn normalize(this: &JsString, form: &str) -> JsString;
5206
5207    /// The `padEnd()` method pads the current string with a given string
5208    /// (repeated, if needed) so that the resulting string reaches a given
5209    /// length. The padding is applied from the end (right) of the current
5210    /// string.
5211    ///
5212    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
5213    #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
5214    pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
5215
5216    /// The `padStart()` method pads the current string with another string
5217    /// (repeated, if needed) so that the resulting string reaches the given
5218    /// length. The padding is applied from the start (left) of the current
5219    /// string.
5220    ///
5221    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
5222    #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
5223    pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
5224
5225    /// The `repeat()` method constructs and returns a new string which contains the specified
5226    /// number of copies of the string on which it was called, concatenated together.
5227    ///
5228    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
5229    #[wasm_bindgen(method, js_class = "String")]
5230    pub fn repeat(this: &JsString, count: i32) -> JsString;
5231
5232    /// The `replace()` method returns a new string with some or all matches of a pattern
5233    /// replaced by a replacement. The pattern can be a string or a RegExp, and
5234    /// the replacement can be a string or a function to be called for each match.
5235    ///
5236    /// Note: The original string will remain unchanged.
5237    ///
5238    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
5239    #[wasm_bindgen(method, js_class = "String")]
5240    pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
5241
5242    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
5243    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
5244    pub fn replace_with_function(
5245        this: &JsString,
5246        pattern: &str,
5247        replacement: &Function,
5248    ) -> JsString;
5249
5250    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
5251    pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
5252
5253    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
5254    #[wasm_bindgen(method, js_class = "String", js_name = replace)]
5255    pub fn replace_by_pattern_with_function(
5256        this: &JsString,
5257        pattern: &RegExp,
5258        replacement: &Function,
5259    ) -> JsString;
5260
5261    /// The `replace_all()` method returns a new string with all matches of a pattern
5262    /// replaced by a replacement. The pattern can be a string or a global RegExp, and
5263    /// the replacement can be a string or a function to be called for each match.
5264    ///
5265    /// Note: The original string will remain unchanged.
5266    ///
5267    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
5268    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
5269    pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
5270
5271    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
5272    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
5273    pub fn replace_all_with_function(
5274        this: &JsString,
5275        pattern: &str,
5276        replacement: &Function,
5277    ) -> JsString;
5278
5279    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
5280    pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
5281        -> JsString;
5282
5283    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
5284    #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
5285    pub fn replace_all_by_pattern_with_function(
5286        this: &JsString,
5287        pattern: &RegExp,
5288        replacement: &Function,
5289    ) -> JsString;
5290
5291    /// The `search()` method executes a search for a match between
5292    /// a regular expression and this String object.
5293    ///
5294    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
5295    #[wasm_bindgen(method, js_class = "String")]
5296    pub fn search(this: &JsString, pattern: &RegExp) -> i32;
5297
5298    /// The `slice()` method extracts a section of a string and returns it as a
5299    /// new string, without modifying the original string.
5300    ///
5301    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
5302    #[wasm_bindgen(method, js_class = "String")]
5303    pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
5304
5305    /// The `split()` method splits a String object into an array of strings by separating the string
5306    /// into substrings, using a specified separator string to determine where to make each split.
5307    ///
5308    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5309    #[wasm_bindgen(method, js_class = "String")]
5310    pub fn split(this: &JsString, separator: &str) -> Array;
5311
5312    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5313    #[wasm_bindgen(method, js_class = "String", js_name = split)]
5314    pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
5315
5316    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5317    #[wasm_bindgen(method, js_class = "String", js_name = split)]
5318    pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
5319
5320    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5321    #[wasm_bindgen(method, js_class = "String", js_name = split)]
5322    pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
5323
5324    /// The `startsWith()` method determines whether a string begins with the
5325    /// characters of a specified string, returning true or false as
5326    /// appropriate.
5327    ///
5328    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
5329    #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
5330    pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
5331
5332    /// The `substring()` method returns the part of the string between the
5333    /// start and end indexes, or to the end of the string.
5334    ///
5335    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
5336    #[wasm_bindgen(method, js_class = "String")]
5337    pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
5338
5339    /// The `substr()` method returns the part of a string between
5340    /// the start index and a number of characters after it.
5341    ///
5342    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
5343    #[wasm_bindgen(method, js_class = "String")]
5344    pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
5345
5346    /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
5347    /// according to any locale-specific case mappings.
5348    ///
5349    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
5350    #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
5351    pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
5352
5353    /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
5354    /// according to any locale-specific case mappings.
5355    ///
5356    /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
5357    #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
5358    pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
5359
5360    /// The `toLowerCase()` method returns the calling string value
5361    /// converted to lower case.
5362    ///
5363    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
5364    #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
5365    pub fn to_lower_case(this: &JsString) -> JsString;
5366
5367    /// The `toString()` method returns a string representing the specified
5368    /// object.
5369    ///
5370    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
5371    #[wasm_bindgen(method, js_class = "String", js_name = toString)]
5372    pub fn to_string(this: &JsString) -> JsString;
5373
5374    /// The `toUpperCase()` method returns the calling string value converted to
5375    /// uppercase (the value will be converted to a string if it isn't one).
5376    ///
5377    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
5378    #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
5379    pub fn to_upper_case(this: &JsString) -> JsString;
5380
5381    /// The `trim()` method removes whitespace from both ends of a string.
5382    /// Whitespace in this context is all the whitespace characters (space, tab,
5383    /// no-break space, etc.) and all the line terminator characters (LF, CR,
5384    /// etc.).
5385    ///
5386    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
5387    #[wasm_bindgen(method, js_class = "String")]
5388    pub fn trim(this: &JsString) -> JsString;
5389
5390    /// The `trimEnd()` method removes whitespace from the end of a string.
5391    /// `trimRight()` is an alias of this method.
5392    ///
5393    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
5394    #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
5395    pub fn trim_end(this: &JsString) -> JsString;
5396
5397    /// The `trimEnd()` method removes whitespace from the end of a string.
5398    /// `trimRight()` is an alias of this method.
5399    ///
5400    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
5401    #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
5402    pub fn trim_right(this: &JsString) -> JsString;
5403
5404    /// The `trimStart()` method removes whitespace from the beginning of a
5405    /// string. `trimLeft()` is an alias of this method.
5406    ///
5407    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
5408    #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
5409    pub fn trim_start(this: &JsString) -> JsString;
5410
5411    /// The `trimStart()` method removes whitespace from the beginning of a
5412    /// string. `trimLeft()` is an alias of this method.
5413    ///
5414    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
5415    #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
5416    pub fn trim_left(this: &JsString) -> JsString;
5417
5418    /// The `valueOf()` method returns the primitive value of a `String` object.
5419    ///
5420    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
5421    #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
5422    pub fn value_of(this: &JsString) -> JsString;
5423
5424    /// The static `raw()` method is a tag function of template literals,
5425    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5426    ///
5427    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5428    #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
5429    pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
5430
5431    /// The static `raw()` method is a tag function of template literals,
5432    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5433    ///
5434    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5435    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5436    pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
5437
5438    /// The static `raw()` method is a tag function of template literals,
5439    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5440    ///
5441    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5442    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5443    pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
5444
5445    /// The static `raw()` method is a tag function of template literals,
5446    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5447    ///
5448    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5449    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5450    pub fn raw_2(
5451        call_site: &Object,
5452        substitutions_1: &str,
5453        substitutions_2: &str,
5454    ) -> Result<JsString, JsValue>;
5455
5456    /// The static `raw()` method is a tag function of template literals,
5457    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5458    ///
5459    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5460    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5461    pub fn raw_3(
5462        call_site: &Object,
5463        substitutions_1: &str,
5464        substitutions_2: &str,
5465        substitutions_3: &str,
5466    ) -> 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_4(
5474        call_site: &Object,
5475        substitutions_1: &str,
5476        substitutions_2: &str,
5477        substitutions_3: &str,
5478        substitutions_4: &str,
5479    ) -> Result<JsString, JsValue>;
5480
5481    /// The static `raw()` method is a tag function of template literals,
5482    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5483    ///
5484    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5485    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5486    pub fn raw_5(
5487        call_site: &Object,
5488        substitutions_1: &str,
5489        substitutions_2: &str,
5490        substitutions_3: &str,
5491        substitutions_4: &str,
5492        substitutions_5: &str,
5493    ) -> Result<JsString, JsValue>;
5494
5495    /// The static `raw()` method is a tag function of template literals,
5496    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5497    ///
5498    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5499    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5500    pub fn raw_6(
5501        call_site: &Object,
5502        substitutions_1: &str,
5503        substitutions_2: &str,
5504        substitutions_3: &str,
5505        substitutions_4: &str,
5506        substitutions_5: &str,
5507        substitutions_6: &str,
5508    ) -> Result<JsString, JsValue>;
5509
5510    /// The static `raw()` method is a tag function of template literals,
5511    /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5512    ///
5513    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5514    #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5515    pub fn raw_7(
5516        call_site: &Object,
5517        substitutions_1: &str,
5518        substitutions_2: &str,
5519        substitutions_3: &str,
5520        substitutions_4: &str,
5521        substitutions_5: &str,
5522        substitutions_6: &str,
5523        substitutions_7: &str,
5524    ) -> Result<JsString, JsValue>;
5525}
5526
5527impl JsString {
5528    /// Returns the `JsString` value of this JS value if it's an instance of a
5529    /// string.
5530    ///
5531    /// If this JS value is not an instance of a string then this returns
5532    /// `None`.
5533    #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
5534    pub fn try_from(val: &JsValue) -> Option<&JsString> {
5535        val.dyn_ref()
5536    }
5537
5538    /// Returns whether this string is a valid UTF-16 string.
5539    ///
5540    /// This is useful for learning whether `String::from(..)` will return a
5541    /// lossless representation of the JS string. If this string contains
5542    /// unpaired surrogates then `String::from` will succeed but it will be a
5543    /// lossy representation of the JS string because unpaired surrogates will
5544    /// become replacement characters.
5545    ///
5546    /// If this function returns `false` then to get a lossless representation
5547    /// of the string you'll need to manually use the `iter` method (or the
5548    /// `char_code_at` accessor) to view the raw character codes.
5549    ///
5550    /// For more information, see the documentation on [JS strings vs Rust
5551    /// strings][docs]
5552    ///
5553    /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
5554    pub fn is_valid_utf16(&self) -> bool {
5555        core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
5556    }
5557
5558    /// Returns an iterator over the `u16` character codes that make up this JS
5559    /// string.
5560    ///
5561    /// This method will call `char_code_at` for each code in this JS string,
5562    /// returning an iterator of the codes in sequence.
5563    pub fn iter(
5564        &self,
5565    ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
5566        (0..self.length()).map(move |i| self.char_code_at(i) as u16)
5567    }
5568
5569    /// If this string consists of a single Unicode code point, then this method
5570    /// converts it into a Rust `char` without doing any allocations.
5571    ///
5572    /// If this JS value is not a valid UTF-8 or consists of more than a single
5573    /// codepoint, then this returns `None`.
5574    ///
5575    /// Note that a single Unicode code point might be represented as more than
5576    /// one code unit on the JavaScript side. For example, a JavaScript string
5577    /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
5578    /// corresponds to a character '𐐷'.
5579    pub fn as_char(&self) -> Option<char> {
5580        let len = self.length();
5581
5582        if len == 0 || len > 2 {
5583            return None;
5584        }
5585
5586        // This will be simplified when definitions are fixed:
5587        // https://github.com/wasm-bindgen/wasm-bindgen/issues/1362
5588        let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
5589
5590        let c = core::char::from_u32(cp)?;
5591
5592        if c.len_utf16() as u32 == len {
5593            Some(c)
5594        } else {
5595            None
5596        }
5597    }
5598}
5599
5600impl PartialEq<str> for JsString {
5601    #[allow(clippy::cmp_owned)] // prevent infinite recursion
5602    fn eq(&self, other: &str) -> bool {
5603        String::from(self) == other
5604    }
5605}
5606
5607impl<'a> PartialEq<&'a str> for JsString {
5608    fn eq(&self, other: &&'a str) -> bool {
5609        <JsString as PartialEq<str>>::eq(self, other)
5610    }
5611}
5612
5613impl PartialEq<String> for JsString {
5614    fn eq(&self, other: &String) -> bool {
5615        <JsString as PartialEq<str>>::eq(self, other)
5616    }
5617}
5618
5619impl<'a> PartialEq<&'a String> for JsString {
5620    fn eq(&self, other: &&'a String) -> bool {
5621        <JsString as PartialEq<str>>::eq(self, other)
5622    }
5623}
5624
5625impl<'a> From<&'a str> for JsString {
5626    fn from(s: &'a str) -> Self {
5627        JsString::unchecked_from_js(JsValue::from_str(s))
5628    }
5629}
5630
5631impl From<String> for JsString {
5632    fn from(s: String) -> Self {
5633        From::from(&*s)
5634    }
5635}
5636
5637impl From<char> for JsString {
5638    #[inline]
5639    fn from(c: char) -> Self {
5640        JsString::from_code_point1(c as u32).unwrap_throw()
5641    }
5642}
5643
5644impl<'a> From<&'a JsString> for String {
5645    fn from(s: &'a JsString) -> Self {
5646        s.obj.as_string().unwrap_throw()
5647    }
5648}
5649
5650impl From<JsString> for String {
5651    fn from(s: JsString) -> Self {
5652        From::from(&s)
5653    }
5654}
5655
5656impl fmt::Debug for JsString {
5657    #[inline]
5658    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5659        fmt::Debug::fmt(&String::from(self), f)
5660    }
5661}
5662
5663impl fmt::Display for JsString {
5664    #[inline]
5665    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5666        fmt::Display::fmt(&String::from(self), f)
5667    }
5668}
5669
5670impl str::FromStr for JsString {
5671    type Err = convert::Infallible;
5672    fn from_str(s: &str) -> Result<Self, Self::Err> {
5673        Ok(JsString::from(s))
5674    }
5675}
5676
5677// Symbol
5678#[wasm_bindgen]
5679extern "C" {
5680    #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
5681    #[derive(Clone, Debug)]
5682    pub type Symbol;
5683
5684    /// The `Symbol.hasInstance` well-known symbol is used to determine
5685    /// if a constructor object recognizes an object as its instance.
5686    /// The `instanceof` operator's behavior can be customized by this symbol.
5687    ///
5688    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
5689    #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = hasInstance)]
5690    pub fn has_instance() -> Symbol;
5691
5692    /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
5693    /// if an object should be flattened to its array elements when using the
5694    /// `Array.prototype.concat()` method.
5695    ///
5696    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
5697    #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = isConcatSpreadable)]
5698    pub fn is_concat_spreadable() -> Symbol;
5699
5700    /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
5701    /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
5702    ///
5703    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
5704    #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = asyncIterator)]
5705    pub fn async_iterator() -> Symbol;
5706
5707    /// The `Symbol.iterator` well-known symbol specifies the default iterator
5708    /// for an object.  Used by `for...of`.
5709    ///
5710    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
5711    #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5712    pub fn iterator() -> Symbol;
5713
5714    /// The `Symbol.match` well-known symbol specifies the matching of a regular
5715    /// expression against a string. This function is called by the
5716    /// `String.prototype.match()` method.
5717    ///
5718    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
5719    #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = match)]
5720    pub fn match_() -> Symbol;
5721
5722    /// The `Symbol.replace` well-known symbol specifies the method that
5723    /// replaces matched substrings of a string.  This function is called by the
5724    /// `String.prototype.replace()` method.
5725    ///
5726    /// For more information, see `RegExp.prototype[@@replace]()` and
5727    /// `String.prototype.replace()`.
5728    ///
5729    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
5730    #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5731    pub fn replace() -> Symbol;
5732
5733    /// The `Symbol.search` well-known symbol specifies the method that returns
5734    /// the index within a string that matches the regular expression.  This
5735    /// function is called by the `String.prototype.search()` method.
5736    ///
5737    /// For more information, see `RegExp.prototype[@@search]()` and
5738    /// `String.prototype.search()`.
5739    ///
5740    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
5741    #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5742    pub fn search() -> Symbol;
5743
5744    /// The well-known symbol `Symbol.species` specifies a function-valued
5745    /// property that the constructor function uses to create derived objects.
5746    ///
5747    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
5748    #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5749    pub fn species() -> Symbol;
5750
5751    /// The `Symbol.split` well-known symbol specifies the method that splits a
5752    /// string at the indices that match a regular expression.  This function is
5753    /// called by the `String.prototype.split()` method.
5754    ///
5755    /// For more information, see `RegExp.prototype[@@split]()` and
5756    /// `String.prototype.split()`.
5757    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
5758    #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5759    pub fn split() -> Symbol;
5760
5761    /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
5762    /// property that is called to convert an object to a corresponding
5763    /// primitive value.
5764    ///
5765    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
5766    #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = toPrimitive)]
5767    pub fn to_primitive() -> Symbol;
5768
5769    /// The `Symbol.toStringTag` well-known symbol is a string valued property
5770    /// that is used in the creation of the default string description of an
5771    /// object.  It is accessed internally by the `Object.prototype.toString()`
5772    /// method.
5773    ///
5774    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
5775    #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = toStringTag)]
5776    pub fn to_string_tag() -> Symbol;
5777
5778    /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
5779    /// the given key and returns it if found.
5780    /// Otherwise a new symbol gets created in the global symbol registry with this key.
5781    ///
5782    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
5783    #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
5784    pub fn for_(key: &str) -> Symbol;
5785
5786    /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
5787    ///
5788    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
5789    #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
5790    pub fn key_for(sym: &Symbol) -> JsValue;
5791
5792    /// The `toString()` method returns a string representing the specified Symbol object.
5793    ///
5794    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
5795    #[wasm_bindgen(method, js_name = toString)]
5796    pub fn to_string(this: &Symbol) -> JsString;
5797
5798    /// The `Symbol.unscopables` well-known symbol is used to specify an object
5799    /// value of whose own and inherited property names are excluded from the
5800    /// with environment bindings of the associated object.
5801    ///
5802    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
5803    #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5804    pub fn unscopables() -> Symbol;
5805
5806    /// The `valueOf()` method returns the primitive value of a Symbol object.
5807    ///
5808    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
5809    #[wasm_bindgen(method, js_name = valueOf)]
5810    pub fn value_of(this: &Symbol) -> Symbol;
5811}
5812
5813#[allow(non_snake_case)]
5814pub mod Intl {
5815    use super::*;
5816
5817    // Intl
5818    #[wasm_bindgen]
5819    extern "C" {
5820        /// The `Intl.getCanonicalLocales()` method returns an array containing
5821        /// the canonical locale names. Duplicates will be omitted and elements
5822        /// will be validated as structurally valid language tags.
5823        ///
5824        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
5825        #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
5826        pub fn get_canonical_locales(s: &JsValue) -> Array;
5827    }
5828
5829    // Intl.Collator
5830    #[wasm_bindgen]
5831    extern "C" {
5832        /// The `Intl.Collator` object is a constructor for collators, objects
5833        /// that enable language sensitive string comparison.
5834        ///
5835        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
5836        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
5837        #[derive(Clone, Debug)]
5838        pub type Collator;
5839
5840        /// The `Intl.Collator` object is a constructor for collators, objects
5841        /// that enable language sensitive string comparison.
5842        ///
5843        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
5844        #[wasm_bindgen(constructor, js_namespace = Intl)]
5845        pub fn new(locales: &Array, options: &Object) -> Collator;
5846
5847        /// The Intl.Collator.prototype.compare property returns a function that
5848        /// compares two strings according to the sort order of this Collator
5849        /// object.
5850        ///
5851        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
5852        #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
5853        pub fn compare(this: &Collator) -> Function;
5854
5855        /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
5856        /// object with properties reflecting the locale and collation options
5857        /// computed during initialization of this Collator object.
5858        ///
5859        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
5860        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
5861        pub fn resolved_options(this: &Collator) -> Object;
5862
5863        /// The `Intl.Collator.supportedLocalesOf()` method returns an array
5864        /// containing those of the provided locales that are supported in
5865        /// collation without having to fall back to the runtime's default
5866        /// locale.
5867        ///
5868        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
5869        #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
5870        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
5871    }
5872
5873    impl Default for Collator {
5874        fn default() -> Self {
5875            Self::new(
5876                &JsValue::UNDEFINED.unchecked_into(),
5877                &JsValue::UNDEFINED.unchecked_into(),
5878            )
5879        }
5880    }
5881
5882    // Intl.DateTimeFormat
5883    #[wasm_bindgen]
5884    extern "C" {
5885        /// The `Intl.DateTimeFormat` object is a constructor for objects
5886        /// that enable language-sensitive date and time formatting.
5887        ///
5888        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
5889        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
5890        #[derive(Clone, Debug)]
5891        pub type DateTimeFormat;
5892
5893        /// The `Intl.DateTimeFormat` object is a constructor for objects
5894        /// that enable language-sensitive date and time formatting.
5895        ///
5896        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
5897        #[wasm_bindgen(constructor, js_namespace = Intl)]
5898        pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
5899
5900        /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
5901        /// formats a date according to the locale and formatting options of this
5902        /// Intl.DateTimeFormat object.
5903        ///
5904        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
5905        #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
5906        pub fn format(this: &DateTimeFormat) -> Function;
5907
5908        /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
5909        /// formatting of strings produced by DateTimeFormat formatters.
5910        ///
5911        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
5912        #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
5913        pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
5914
5915        /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
5916        /// object with properties reflecting the locale and date and time formatting
5917        /// options computed during initialization of this DateTimeFormat object.
5918        ///
5919        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
5920        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
5921        pub fn resolved_options(this: &DateTimeFormat) -> Object;
5922
5923        /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
5924        /// containing those of the provided locales that are supported in date
5925        /// and time formatting without having to fall back to the runtime's default
5926        /// locale.
5927        ///
5928        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
5929        #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
5930        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
5931    }
5932
5933    impl Default for DateTimeFormat {
5934        fn default() -> Self {
5935            Self::new(
5936                &JsValue::UNDEFINED.unchecked_into(),
5937                &JsValue::UNDEFINED.unchecked_into(),
5938            )
5939        }
5940    }
5941
5942    // Intl.NumberFormat
5943    #[wasm_bindgen]
5944    extern "C" {
5945        /// The `Intl.NumberFormat` object is a constructor for objects
5946        /// that enable language sensitive number formatting.
5947        ///
5948        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
5949        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
5950        #[derive(Clone, Debug)]
5951        pub type NumberFormat;
5952
5953        /// The `Intl.NumberFormat` object is a constructor for objects
5954        /// that enable language sensitive number formatting.
5955        ///
5956        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
5957        #[wasm_bindgen(constructor, js_namespace = Intl)]
5958        pub fn new(locales: &Array, options: &Object) -> NumberFormat;
5959
5960        /// The Intl.NumberFormat.prototype.format property returns a getter function that
5961        /// formats a number according to the locale and formatting options of this
5962        /// NumberFormat object.
5963        ///
5964        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
5965        #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
5966        pub fn format(this: &NumberFormat) -> Function;
5967
5968        /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
5969        /// formatting of strings produced by NumberTimeFormat formatters.
5970        ///
5971        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
5972        #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
5973        pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
5974
5975        /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
5976        /// object with properties reflecting the locale and number formatting
5977        /// options computed during initialization of this NumberFormat object.
5978        ///
5979        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
5980        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
5981        pub fn resolved_options(this: &NumberFormat) -> Object;
5982
5983        /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
5984        /// containing those of the provided locales that are supported in number
5985        /// formatting without having to fall back to the runtime's default locale.
5986        ///
5987        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
5988        #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
5989        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
5990    }
5991
5992    impl Default for NumberFormat {
5993        fn default() -> Self {
5994            Self::new(
5995                &JsValue::UNDEFINED.unchecked_into(),
5996                &JsValue::UNDEFINED.unchecked_into(),
5997            )
5998        }
5999    }
6000
6001    // Intl.PluralRules
6002    #[wasm_bindgen]
6003    extern "C" {
6004        /// The `Intl.PluralRules` object is a constructor for objects
6005        /// that enable plural sensitive formatting and plural language rules.
6006        ///
6007        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
6008        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
6009        #[derive(Clone, Debug)]
6010        pub type PluralRules;
6011
6012        /// The `Intl.PluralRules` object is a constructor for objects
6013        /// that enable plural sensitive formatting and plural language rules.
6014        ///
6015        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
6016        #[wasm_bindgen(constructor, js_namespace = Intl)]
6017        pub fn new(locales: &Array, options: &Object) -> PluralRules;
6018
6019        /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
6020        /// object with properties reflecting the locale and plural formatting
6021        /// options computed during initialization of this PluralRules object.
6022        ///
6023        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
6024        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
6025        pub fn resolved_options(this: &PluralRules) -> Object;
6026
6027        /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
6028        /// which plural rule to use for locale-aware formatting.
6029        ///
6030        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
6031        #[wasm_bindgen(method, js_namespace = Intl)]
6032        pub fn select(this: &PluralRules, number: f64) -> JsString;
6033
6034        /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
6035        /// containing those of the provided locales that are supported in plural
6036        /// formatting without having to fall back to the runtime's default locale.
6037        ///
6038        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
6039        #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
6040        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
6041    }
6042
6043    impl Default for PluralRules {
6044        fn default() -> Self {
6045            Self::new(
6046                &JsValue::UNDEFINED.unchecked_into(),
6047                &JsValue::UNDEFINED.unchecked_into(),
6048            )
6049        }
6050    }
6051
6052    // Intl.RelativeTimeFormat
6053    #[wasm_bindgen]
6054    extern "C" {
6055        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
6056        /// that enable language-sensitive relative time formatting.
6057        ///
6058        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
6059        #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
6060        #[derive(Clone, Debug)]
6061        pub type RelativeTimeFormat;
6062
6063        /// The `Intl.RelativeTimeFormat` object is a constructor for objects
6064        /// that enable language-sensitive relative time formatting.
6065        ///
6066        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
6067        #[wasm_bindgen(constructor, js_namespace = Intl)]
6068        pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
6069
6070        /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
6071        /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
6072        ///
6073        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
6074        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
6075        pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
6076
6077        /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
6078        /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
6079        ///
6080        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
6081        #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
6082        pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
6083
6084        /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
6085        /// object with properties reflecting the locale and relative time formatting
6086        /// options computed during initialization of this RelativeTimeFormat object.
6087        ///
6088        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
6089        #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
6090        pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
6091
6092        /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
6093        /// containing those of the provided locales that are supported in date and time
6094        /// formatting without having to fall back to the runtime's default locale.
6095        ///
6096        /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
6097        #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
6098        pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
6099    }
6100
6101    impl Default for RelativeTimeFormat {
6102        fn default() -> Self {
6103            Self::new(
6104                &JsValue::UNDEFINED.unchecked_into(),
6105                &JsValue::UNDEFINED.unchecked_into(),
6106            )
6107        }
6108    }
6109}
6110
6111// Promise
6112#[wasm_bindgen]
6113extern "C" {
6114    /// The `Promise` object represents the eventual completion (or failure) of
6115    /// an asynchronous operation, and its resulting value.
6116    ///
6117    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
6118    #[must_use]
6119    #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>")]
6120    #[derive(Clone, Debug)]
6121    pub type Promise;
6122
6123    /// Creates a new `Promise` with the provided executor `cb`
6124    ///
6125    /// The `cb` is a function that is passed with the arguments `resolve` and
6126    /// `reject`. The `cb` function is executed immediately by the `Promise`
6127    /// implementation, passing `resolve` and `reject` functions (the executor
6128    /// is called before the `Promise` constructor even returns the created
6129    /// object). The `resolve` and `reject` functions, when called, resolve or
6130    /// reject the promise, respectively. The executor normally initiates
6131    /// some asynchronous work, and then, once that completes, either calls
6132    /// the `resolve` function to resolve the promise or else rejects it if an
6133    /// error occurred.
6134    ///
6135    /// If an error is thrown in the executor function, the promise is rejected.
6136    /// The return value of the executor is ignored.
6137    ///
6138    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
6139    #[wasm_bindgen(constructor)]
6140    pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
6141
6142    /// The `Promise.all(iterable)` method returns a single `Promise` that
6143    /// resolves when all of the promises in the iterable argument have resolved
6144    /// or when the iterable argument contains no promises. It rejects with the
6145    /// reason of the first promise that rejects.
6146    ///
6147    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
6148    #[wasm_bindgen(static_method_of = Promise)]
6149    pub fn all(obj: &JsValue) -> Promise;
6150
6151    /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
6152    /// resolves when all of the promises in the iterable argument have either
6153    /// fulfilled or rejected or when the iterable argument contains no promises.
6154    ///
6155    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
6156    #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
6157    pub fn all_settled(obj: &JsValue) -> Promise;
6158
6159    /// The `Promise.any(iterable)` method returns a single `Promise` that
6160    /// resolves when any of the promises in the iterable argument have resolved
6161    /// or when the iterable argument contains no promises. It rejects with an
6162    /// `AggregateError` if all promises in the iterable rejected.
6163    ///
6164    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
6165    #[wasm_bindgen(static_method_of = Promise)]
6166    pub fn any(obj: &JsValue) -> Promise;
6167
6168    /// The `Promise.race(iterable)` method returns a promise that resolves or
6169    /// rejects as soon as one of the promises in the iterable resolves or
6170    /// rejects, with the value or reason from that promise.
6171    ///
6172    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
6173    #[wasm_bindgen(static_method_of = Promise)]
6174    pub fn race(obj: &JsValue) -> Promise;
6175
6176    /// The `Promise.reject(reason)` method returns a `Promise` object that is
6177    /// rejected with the given reason.
6178    ///
6179    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
6180    #[wasm_bindgen(static_method_of = Promise)]
6181    pub fn reject(obj: &JsValue) -> Promise;
6182
6183    /// The `Promise.resolve(value)` method returns a `Promise` object that is
6184    /// resolved with the given value. If the value is a promise, that promise
6185    /// is returned; if the value is a thenable (i.e. has a "then" method), the
6186    /// returned promise will "follow" that thenable, adopting its eventual
6187    /// state; otherwise the returned promise will be fulfilled with the value.
6188    ///
6189    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
6190    #[wasm_bindgen(static_method_of = Promise)]
6191    pub fn resolve(obj: &JsValue) -> Promise;
6192
6193    /// The `catch()` method returns a `Promise` and deals with rejected cases
6194    /// only.  It behaves the same as calling `Promise.prototype.then(undefined,
6195    /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
6196    /// `obj.then(undefined, onRejected)`).
6197    ///
6198    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
6199    #[wasm_bindgen(method)]
6200    pub fn catch(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise;
6201
6202    /// The `then()` method returns a `Promise`. It takes up to two arguments:
6203    /// callback functions for the success and failure cases of the `Promise`.
6204    ///
6205    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
6206    #[wasm_bindgen(method)]
6207    pub fn then(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise;
6208
6209    /// Same as `then`, only with both arguments provided.
6210    #[wasm_bindgen(method, js_name = then)]
6211    pub fn then2(
6212        this: &Promise,
6213        resolve: &Closure<dyn FnMut(JsValue)>,
6214        reject: &Closure<dyn FnMut(JsValue)>,
6215    ) -> Promise;
6216
6217    /// The `finally()` method returns a `Promise`. When the promise is settled,
6218    /// whether fulfilled or rejected, the specified callback function is
6219    /// executed. This provides a way for code that must be executed once the
6220    /// `Promise` has been dealt with to be run whether the promise was
6221    /// fulfilled successfully or rejected.
6222    ///
6223    /// This lets you avoid duplicating code in both the promise's `then()` and
6224    /// `catch()` handlers.
6225    ///
6226    /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
6227    #[wasm_bindgen(method)]
6228    pub fn finally(this: &Promise, cb: &Closure<dyn FnMut()>) -> Promise;
6229}
6230
6231/// Returns a handle to the global scope object.
6232///
6233/// This allows access to the global properties and global names by accessing
6234/// the `Object` returned.
6235pub fn global() -> Object {
6236    use once_cell::unsync::Lazy;
6237
6238    struct Wrapper<T>(Lazy<T>);
6239
6240    #[cfg(not(target_feature = "atomics"))]
6241    unsafe impl<T> Sync for Wrapper<T> {}
6242
6243    #[cfg(not(target_feature = "atomics"))]
6244    unsafe impl<T> Send for Wrapper<T> {}
6245
6246    #[cfg_attr(target_feature = "atomics", thread_local)]
6247    static GLOBAL: Wrapper<Object> = Wrapper(Lazy::new(get_global_object));
6248
6249    return GLOBAL.0.clone();
6250
6251    fn get_global_object() -> Object {
6252        // Accessing the global object is not an easy thing to do, and what we
6253        // basically want is `globalThis` but we can't rely on that existing
6254        // everywhere. In the meantime we've got the fallbacks mentioned in:
6255        //
6256        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
6257        //
6258        // Note that this is pretty heavy code-size wise but it at least gets
6259        // the job largely done for now and avoids the `Function` constructor at
6260        // the end which triggers CSP errors.
6261        #[wasm_bindgen]
6262        extern "C" {
6263            type Global;
6264
6265            #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
6266            static GLOBAL_THIS: Option<Object>;
6267
6268            #[wasm_bindgen(thread_local_v2, js_name = self)]
6269            static SELF: Option<Object>;
6270
6271            #[wasm_bindgen(thread_local_v2, js_name = window)]
6272            static WINDOW: Option<Object>;
6273
6274            #[wasm_bindgen(thread_local_v2, js_name = global)]
6275            static GLOBAL: Option<Object>;
6276        }
6277
6278        // The order is important: in Firefox Extension Content Scripts `globalThis`
6279        // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
6280        let static_object = SELF
6281            .with(Option::clone)
6282            .or_else(|| WINDOW.with(Option::clone))
6283            .or_else(|| GLOBAL_THIS.with(Option::clone))
6284            .or_else(|| GLOBAL.with(Option::clone));
6285        if let Some(obj) = static_object {
6286            if !obj.is_undefined() {
6287                return obj;
6288            }
6289        }
6290
6291        // According to StackOverflow you can access the global object via:
6292        //
6293        //      const global = Function('return this')();
6294        //
6295        // I think that's because the manufactured function isn't in "strict" mode.
6296        // It also turns out that non-strict functions will ignore `undefined`
6297        // values for `this` when using the `apply` function.
6298        //
6299        // As a result we use the equivalent of this snippet to get a handle to the
6300        // global object in a sort of roundabout way that should hopefully work in
6301        // all contexts like ESM, node, browsers, etc.
6302        let this = Function::new_no_args("return this")
6303            .call0(&JsValue::undefined())
6304            .ok();
6305
6306        // Note that we avoid `unwrap()` on `call0` to avoid code size bloat, we
6307        // just handle the `Err` case as returning a different object.
6308        debug_assert!(this.is_some());
6309        match this {
6310            Some(this) => this.unchecked_into(),
6311            None => JsValue::undefined().unchecked_into(),
6312        }
6313    }
6314}
6315
6316macro_rules! arrays {
6317    ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
6318        #[wasm_bindgen]
6319        extern "C" {
6320            #[wasm_bindgen(extends = Object, typescript_type = $name)]
6321            #[derive(Clone, Debug)]
6322            pub type $name;
6323
6324            /// The
6325            #[doc = $ctor]
6326            /// constructor creates a new array.
6327            ///
6328            /// [MDN documentation](
6329            #[doc = $mdn]
6330            /// )
6331            #[wasm_bindgen(constructor)]
6332            pub fn new(constructor_arg: &JsValue) -> $name;
6333
6334            /// An
6335            #[doc = $ctor]
6336            /// which creates an array with an internal buffer large
6337            /// enough for `length` elements.
6338            ///
6339            /// [MDN documentation](
6340            #[doc = $mdn]
6341            /// )
6342            #[wasm_bindgen(constructor)]
6343            pub fn new_with_length(length: u32) -> $name;
6344
6345            /// An
6346            #[doc = $ctor]
6347            /// which creates an array from a Rust slice.
6348            ///
6349            /// [MDN documentation](
6350            #[doc = $mdn]
6351            /// )
6352            #[wasm_bindgen(constructor)]
6353            pub fn new_from_slice(slice: &[$ty]) -> $name;
6354
6355            /// An
6356            #[doc = $ctor]
6357            /// which creates an array with the given buffer but is a
6358            /// view starting at `byte_offset`.
6359            ///
6360            /// [MDN documentation](
6361            #[doc = $mdn]
6362            /// )
6363            #[wasm_bindgen(constructor)]
6364            pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
6365
6366            /// An
6367            #[doc = $ctor]
6368            /// which creates an array with the given buffer but is a
6369            /// view starting at `byte_offset` for `length` elements.
6370            ///
6371            /// [MDN documentation](
6372            #[doc = $mdn]
6373            /// )
6374            #[wasm_bindgen(constructor)]
6375            pub fn new_with_byte_offset_and_length(
6376                buffer: &JsValue,
6377                byte_offset: u32,
6378                length: u32,
6379            ) -> $name;
6380
6381            /// The `fill()` method fills all the elements of an array from a start index
6382            /// to an end index with a static value. The end index is not included.
6383            ///
6384            /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
6385            #[wasm_bindgen(method)]
6386            pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
6387
6388            /// The buffer accessor property represents the `ArrayBuffer` referenced
6389            /// by a `TypedArray` at construction time.
6390            #[wasm_bindgen(getter, method)]
6391            pub fn buffer(this: &$name) -> ArrayBuffer;
6392
6393            /// The `subarray()` method returns a new `TypedArray` on the same
6394            /// `ArrayBuffer` store and with the same element types as for this
6395            /// `TypedArray` object.
6396            #[wasm_bindgen(method)]
6397            pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
6398
6399            /// The `slice()` method returns a shallow copy of a portion of a typed
6400            /// array into a new typed array object. This method has the same algorithm
6401            /// as `Array.prototype.slice()`.
6402            #[wasm_bindgen(method)]
6403            pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
6404
6405            /// The `forEach()` method executes a provided function once per array
6406            /// element. This method has the same algorithm as
6407            /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
6408            /// types here.
6409            #[wasm_bindgen(method, js_name = forEach)]
6410            pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
6411
6412            /// The length accessor property represents the length (in elements) of a
6413            /// typed array.
6414            #[wasm_bindgen(method, getter)]
6415            pub fn length(this: &$name) -> u32;
6416
6417            /// The byteLength accessor property represents the length (in bytes) of a
6418            /// typed array.
6419            #[wasm_bindgen(method, getter, js_name = byteLength)]
6420            pub fn byte_length(this: &$name) -> u32;
6421
6422            /// The byteOffset accessor property represents the offset (in bytes) of a
6423            /// typed array from the start of its `ArrayBuffer`.
6424            #[wasm_bindgen(method, getter, js_name = byteOffset)]
6425            pub fn byte_offset(this: &$name) -> u32;
6426
6427            /// The `set()` method stores multiple values in the typed array, reading
6428            /// input values from a specified array.
6429            #[wasm_bindgen(method)]
6430            pub fn set(this: &$name, src: &JsValue, offset: u32);
6431
6432            /// Gets the value at `idx`, counting from the end if negative.
6433            #[wasm_bindgen(method)]
6434            pub fn at(this: &$name, idx: i32) -> Option<$ty>;
6435
6436            /// The `copyWithin()` method shallow copies part of a typed array to another
6437            /// location in the same typed array and returns it, without modifying its size.
6438            ///
6439            /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
6440            #[wasm_bindgen(method, js_name = copyWithin)]
6441            pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
6442
6443            /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
6444            #[wasm_bindgen(method, structural, indexing_getter)]
6445            pub fn get_index(this: &$name, idx: u32) -> $ty;
6446
6447            /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
6448            #[wasm_bindgen(method, structural, indexing_setter)]
6449            pub fn set_index(this: &$name, idx: u32, value: $ty);
6450        }
6451
6452        impl $name {
6453            /// Creates a JS typed array which is a view into wasm's linear
6454            /// memory at the slice specified.
6455            ///
6456            /// This function returns a new typed array which is a view into
6457            /// wasm's memory. This view does not copy the underlying data.
6458            ///
6459            /// # Safety
6460            ///
6461            /// Views into WebAssembly memory are only valid so long as the
6462            /// backing buffer isn't resized in JS. Once this function is called
6463            /// any future calls to `Box::new` (or malloc of any form) may cause
6464            /// the returned value here to be invalidated. Use with caution!
6465            ///
6466            /// Additionally the returned object can be safely mutated but the
6467            /// input slice isn't guaranteed to be mutable.
6468            ///
6469            /// Finally, the returned object is disconnected from the input
6470            /// slice's lifetime, so there's no guarantee that the data is read
6471            /// at the right time.
6472            pub unsafe fn view(rust: &[$ty]) -> $name {
6473                let buf = wasm_bindgen::memory();
6474                let mem = buf.unchecked_ref::<WebAssembly::Memory>();
6475                $name::new_with_byte_offset_and_length(
6476                    &mem.buffer(),
6477                    rust.as_ptr() as u32,
6478                    rust.len() as u32,
6479                )
6480            }
6481
6482            /// Creates a JS typed array which is a view into wasm's linear
6483            /// memory at the specified pointer with specified length.
6484            ///
6485            /// This function returns a new typed array which is a view into
6486            /// wasm's memory. This view does not copy the underlying data.
6487            ///
6488            /// # Safety
6489            ///
6490            /// Views into WebAssembly memory are only valid so long as the
6491            /// backing buffer isn't resized in JS. Once this function is called
6492            /// any future calls to `Box::new` (or malloc of any form) may cause
6493            /// the returned value here to be invalidated. Use with caution!
6494            ///
6495            /// Additionally the returned object can be safely mutated,
6496            /// the changes are guaranteed to be reflected in the input array.
6497            pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
6498                let buf = wasm_bindgen::memory();
6499                let mem = buf.unchecked_ref::<WebAssembly::Memory>();
6500                $name::new_with_byte_offset_and_length(
6501                    &mem.buffer(),
6502                    ptr as u32,
6503                    length as u32
6504                )
6505            }
6506
6507
6508            /// Copy the contents of this JS typed array into the destination
6509            /// Rust pointer.
6510            ///
6511            /// This function will efficiently copy the memory from a typed
6512            /// array into this Wasm module's own linear memory, initializing
6513            /// the memory destination provided.
6514            ///
6515            /// # Safety
6516            ///
6517            /// This function requires `dst` to point to a buffer
6518            /// large enough to fit this array's contents.
6519            pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
6520                let buf = wasm_bindgen::memory();
6521                let mem = buf.unchecked_ref::<WebAssembly::Memory>();
6522                let all_wasm_memory = $name::new(&mem.buffer());
6523                let offset = dst as usize / mem::size_of::<$ty>();
6524                all_wasm_memory.set(self, offset as u32);
6525            }
6526
6527            /// Copy the contents of this JS typed array into the destination
6528            /// Rust slice.
6529            ///
6530            /// This function will efficiently copy the memory from a typed
6531            /// array into this Wasm module's own linear memory, initializing
6532            /// the memory destination provided.
6533            ///
6534            /// # Panics
6535            ///
6536            /// This function will panic if this typed array's length is
6537            /// different than the length of the provided `dst` array.
6538            pub fn copy_to(&self, dst: &mut [$ty]) {
6539                core::assert_eq!(self.length() as usize, dst.len());
6540                unsafe { self.raw_copy_to_ptr(dst.as_mut_ptr()); }
6541            }
6542
6543            /// Copy the contents of this JS typed array into the destination
6544            /// Rust slice.
6545            ///
6546            /// This function will efficiently copy the memory from a typed
6547            /// array into this Wasm module's own linear memory, initializing
6548            /// the memory destination provided.
6549            ///
6550            /// # Panics
6551            ///
6552            /// This function will panic if this typed array's length is
6553            /// different than the length of the provided `dst` array.
6554            pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
6555                core::assert_eq!(self.length() as usize, dst.len());
6556                unsafe { self.raw_copy_to_ptr(dst.as_mut_ptr().cast()); }
6557                unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) }
6558            }
6559
6560            /// Copy the contents of the source Rust slice into this
6561            /// JS typed array.
6562            ///
6563            /// This function will efficiently copy the memory from within
6564            /// the Wasm module's own linear memory to this typed array.
6565            ///
6566            /// # Panics
6567            ///
6568            /// This function will panic if this typed array's length is
6569            /// different than the length of the provided `src` array.
6570            pub fn copy_from(&self, src: &[$ty]) {
6571                core::assert_eq!(self.length() as usize, src.len());
6572                // This is safe because the `set` function copies from its TypedArray argument
6573                unsafe { self.set(&$name::view(src), 0) }
6574            }
6575
6576            /// Efficiently copies the contents of this JS typed array into a new Vec.
6577            pub fn to_vec(&self) -> Vec<$ty> {
6578                let mut output = Vec::with_capacity(self.length() as usize);
6579                unsafe {
6580                    self.raw_copy_to_ptr(output.as_mut_ptr());
6581                    output.set_len(self.length() as usize);
6582                }
6583                output
6584            }
6585        }
6586
6587        impl<'a> From<&'a [$ty]> for $name {
6588            #[inline]
6589            fn from(slice: &'a [$ty]) -> $name {
6590                // This is safe because the `new` function makes a copy if its argument is a TypedArray
6591                $name::new_from_slice(slice)
6592            }
6593        }
6594
6595        impl Default for $name {
6596            fn default() -> Self {
6597                Self::new(&JsValue::UNDEFINED.unchecked_into())
6598            }
6599        }
6600    )*);
6601}
6602
6603arrays! {
6604    /// `Int8Array()`
6605    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
6606    Int8Array: i8,
6607
6608    /// `Int16Array()`
6609    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
6610    Int16Array: i16,
6611
6612    /// `Int32Array()`
6613    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
6614    Int32Array: i32,
6615
6616    /// `Uint8Array()`
6617    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
6618    Uint8Array: u8,
6619
6620    /// `Uint8ClampedArray()`
6621    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
6622    Uint8ClampedArray: u8,
6623
6624    /// `Uint16Array()`
6625    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
6626    Uint16Array: u16,
6627
6628    /// `Uint32Array()`
6629    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
6630    Uint32Array: u32,
6631
6632    /// `Float32Array()`
6633    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
6634    Float32Array: f32,
6635
6636    /// `Float64Array()`
6637    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
6638    Float64Array: f64,
6639
6640    /// `BigInt64Array()`
6641    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
6642    BigInt64Array: i64,
6643
6644    /// `BigUint64Array()`
6645    /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
6646    BigUint64Array: u64,
6647}