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