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