js_sys/lib.rs
1//! Bindings to JavaScript's standard, built-in objects, including their methods
2//! and properties.
3//!
4//! This does *not* include any Web, Node, or any other JS environment
5//! APIs. Only the things that are guaranteed to exist in the global scope by
6//! the ECMAScript standard.
7//!
8//! <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects>
9//!
10//! ## A Note About `camelCase`, `snake_case`, and Naming Conventions
11//!
12//! JavaScript's global objects use `camelCase` naming conventions for functions
13//! and methods, but Rust style is to use `snake_case`. These bindings expose
14//! the Rust style `snake_case` name. Additionally, acronyms within a method
15//! name are all lower case, where as in JavaScript they are all upper case. For
16//! example, `decodeURI` in JavaScript is exposed as `decode_uri` in these
17//! bindings.
18//!
19//! ## A Note About `toString` and `to_js_string`
20//!
21//! JavaScript's `toString()` method is exposed as `to_js_string()` in these
22//! bindings to avoid confusion with Rust's [`ToString`] trait and its
23//! `to_string()` method. This allows types to implement both the Rust
24//! [`Display`](core::fmt::Display) trait (which provides `to_string()` via
25//! [`ToString`]) and still expose the JavaScript `toString()` functionality.
26
27#![doc(html_root_url = "https://docs.rs/js-sys/0.2")]
28#![cfg_attr(not(feature = "std"), no_std)]
29#![cfg_attr(target_feature = "atomics", feature(thread_local))]
30
31extern crate alloc;
32
33use alloc::string::String;
34use alloc::vec::Vec;
35use core::cmp::Ordering;
36#[cfg(not(js_sys_unstable_apis))]
37use core::convert::Infallible;
38use core::convert::{self, TryFrom};
39use core::f64;
40use core::fmt;
41use core::iter::{self, Product, Sum};
42use core::mem::MaybeUninit;
43use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub};
44use core::str;
45use core::str::FromStr;
46pub use wasm_bindgen;
47use wasm_bindgen::closure::{ScopedClosure, WasmClosure};
48use wasm_bindgen::convert::{FromWasmAbi, IntoWasmAbi, Upcast, UpcastFrom};
49use wasm_bindgen::prelude::*;
50use wasm_bindgen::JsError;
51
52// Re-export sys types as js-sys types
53pub use wasm_bindgen::sys::{JsOption, Null, Promising, Undefined};
54pub use wasm_bindgen::JsGeneric;
55
56// When adding new imports:
57//
58// * Keep imports in alphabetical order.
59//
60// * Rename imports with `js_name = ...` according to the note about `camelCase`
61// and `snake_case` in the module's documentation above.
62//
63// * Include the one sentence summary of the import from the MDN link in the
64// module's documentation above, and the MDN link itself.
65//
66// * If a function or method can throw an exception, make it catchable by adding
67// `#[wasm_bindgen(catch)]`.
68//
69// * Add a new `#[test]` into the appropriate file in the
70// `crates/js-sys/tests/wasm/` directory. If the imported function or method
71// can throw an exception, make sure to also add test coverage for that case.
72//
73// * Arguments that are `JsValue`s or imported JavaScript types should be taken
74// by reference.
75//
76// * Name JavaScript's `toString()` method as `to_js_string()` to avoid conflict
77// with Rust's `ToString` trait.
78
79macro_rules! forward_deref_unop {
80 (impl $imp:ident, $method:ident for $t:ty) => {
81 impl $imp for $t {
82 type Output = <&'static $t as $imp>::Output;
83
84 #[inline]
85 fn $method(self) -> Self::Output {
86 $imp::$method(&self)
87 }
88 }
89 };
90 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
91 impl<$($gen),+> $imp for $t {
92 type Output = <&'static $t as $imp>::Output;
93
94 #[inline]
95 fn $method(self) -> Self::Output {
96 $imp::$method(&self)
97 }
98 }
99 };
100}
101
102macro_rules! forward_deref_binop {
103 (impl $imp:ident, $method:ident for $t:ty) => {
104 impl<'a> $imp<$t> for &'a $t {
105 type Output = <&'static $t as $imp<&'static $t>>::Output;
106
107 #[inline]
108 fn $method(self, other: $t) -> Self::Output {
109 $imp::$method(self, &other)
110 }
111 }
112
113 impl $imp<&$t> for $t {
114 type Output = <&'static $t as $imp<&'static $t>>::Output;
115
116 #[inline]
117 fn $method(self, other: &$t) -> Self::Output {
118 $imp::$method(&self, other)
119 }
120 }
121
122 impl $imp<$t> for $t {
123 type Output = <&'static $t as $imp<&'static $t>>::Output;
124
125 #[inline]
126 fn $method(self, other: $t) -> Self::Output {
127 $imp::$method(&self, &other)
128 }
129 }
130 };
131 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
132 impl<'a, $($gen),+> $imp<$t> for &'a $t {
133 type Output = <&'static $t as $imp<&'static $t>>::Output;
134
135 #[inline]
136 fn $method(self, other: $t) -> Self::Output {
137 $imp::$method(self, &other)
138 }
139 }
140
141 impl<$($gen),+> $imp<&$t> for $t {
142 type Output = <&'static $t as $imp<&'static $t>>::Output;
143
144 #[inline]
145 fn $method(self, other: &$t) -> Self::Output {
146 $imp::$method(&self, other)
147 }
148 }
149
150 impl<$($gen),+> $imp<$t> for $t {
151 type Output = <&'static $t as $imp<&'static $t>>::Output;
152
153 #[inline]
154 fn $method(self, other: $t) -> Self::Output {
155 $imp::$method(&self, &other)
156 }
157 }
158 };
159}
160
161macro_rules! forward_js_unop {
162 (impl $imp:ident, $method:ident for $t:ty) => {
163 impl $imp for &$t {
164 type Output = $t;
165
166 #[inline]
167 fn $method(self) -> Self::Output {
168 $imp::$method(JsValue::as_ref(self)).unchecked_into()
169 }
170 }
171
172 forward_deref_unop!(impl $imp, $method for $t);
173 };
174 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
175 impl<$($gen),+> $imp for &$t {
176 type Output = $t;
177
178 #[inline]
179 fn $method(self) -> Self::Output {
180 $imp::$method(JsValue::as_ref(self)).unchecked_into()
181 }
182 }
183
184 forward_deref_unop!(impl<$($gen),+> $imp, $method for $t);
185 };
186}
187
188macro_rules! forward_js_binop {
189 (impl $imp:ident, $method:ident for $t:ty) => {
190 impl $imp<&$t> for &$t {
191 type Output = $t;
192
193 #[inline]
194 fn $method(self, other: &$t) -> Self::Output {
195 $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
196 }
197 }
198
199 forward_deref_binop!(impl $imp, $method for $t);
200 };
201 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
202 impl<$($gen),+> $imp<&$t> for &$t {
203 type Output = $t;
204
205 #[inline]
206 fn $method(self, other: &$t) -> Self::Output {
207 $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
208 }
209 }
210
211 forward_deref_binop!(impl<$($gen),+> $imp, $method for $t);
212 };
213}
214
215macro_rules! sum_product {
216 ($($a:ident)*) => ($(
217 impl Sum for $a {
218 #[inline]
219 fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
220 iter.fold(
221 $a::from(0),
222 |a, b| a + b,
223 )
224 }
225 }
226
227 impl Product for $a {
228 #[inline]
229 fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
230 iter.fold(
231 $a::from(1),
232 |a, b| a * b,
233 )
234 }
235 }
236
237 impl<'a> Sum<&'a $a> for $a {
238 fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
239 iter.fold(
240 $a::from(0),
241 |a, b| a + b,
242 )
243 }
244 }
245
246 impl<'a> Product<&'a $a> for $a {
247 #[inline]
248 fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
249 iter.fold(
250 $a::from(1),
251 |a, b| a * b,
252 )
253 }
254 }
255 )*);
256 // Generic variant: impl<T> for Type<T>
257 (impl<$gen:ident> $a:ident<$g2:ident>) => {
258 impl<$gen> Sum for $a<$g2>
259 where
260 $a<$g2>: From<$gen>,
261 $g2: From<u32>
262 {
263 #[inline]
264 fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
265 iter.fold(
266 $a::from($g2::from(0)),
267 |a, b| a + b,
268 )
269 }
270 }
271
272 impl<$gen> Product for $a<$g2>
273 where
274 $a<$g2>: From<$gen>,
275 $g2: From<u32>
276 {
277 #[inline]
278 fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
279 iter.fold(
280 $a::from($g2::from(1)),
281 |a, b| a * b,
282 )
283 }
284 }
285
286 impl<'a, $gen> Sum<&'a $a<$g2>> for $a<$g2>
287 where
288 $a<$g2>: From<$gen>,
289 $g2: From<u32>
290 {
291 fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
292 iter.fold(
293 $a::from($g2::from(0)),
294 |a, b| a + b,
295 )
296 }
297 }
298
299 impl<'a, $gen> Product<&'a $a<$g2>> for $a<$g2>
300 where
301 $a<$g2>: From<$gen>,
302 $g2: From<u32>
303 {
304 #[inline]
305 fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
306 iter.fold(
307 $a::from($g2::from(1)),
308 |a, b| a * b,
309 )
310 }
311 }
312 };
313}
314
315macro_rules! partialord_ord {
316 ($t:ident) => {
317 impl PartialOrd for $t {
318 #[inline]
319 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
320 Some(self.cmp(other))
321 }
322
323 #[inline]
324 fn lt(&self, other: &Self) -> bool {
325 JsValue::as_ref(self).lt(JsValue::as_ref(other))
326 }
327
328 #[inline]
329 fn le(&self, other: &Self) -> bool {
330 JsValue::as_ref(self).le(JsValue::as_ref(other))
331 }
332
333 #[inline]
334 fn ge(&self, other: &Self) -> bool {
335 JsValue::as_ref(self).ge(JsValue::as_ref(other))
336 }
337
338 #[inline]
339 fn gt(&self, other: &Self) -> bool {
340 JsValue::as_ref(self).gt(JsValue::as_ref(other))
341 }
342 }
343
344 impl Ord for $t {
345 #[inline]
346 fn cmp(&self, other: &Self) -> Ordering {
347 if self == other {
348 Ordering::Equal
349 } else if self.lt(other) {
350 Ordering::Less
351 } else {
352 Ordering::Greater
353 }
354 }
355 }
356 };
357}
358
359#[wasm_bindgen]
360extern "C" {
361 /// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
362 /// previously created by `encodeURI` or by a similar routine.
363 ///
364 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI)
365 #[wasm_bindgen(catch, js_name = decodeURI)]
366 pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
367
368 /// The `decodeURIComponent()` function decodes a Uniform Resource Identifier (URI) component
369 /// previously created by `encodeURIComponent` or by a similar routine.
370 ///
371 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
372 #[wasm_bindgen(catch, js_name = decodeURIComponent)]
373 pub fn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>;
374
375 /// The `encodeURI()` function encodes a Uniform Resource Identifier (URI)
376 /// by replacing each instance of certain characters by one, two, three, or
377 /// four escape sequences representing the UTF-8 encoding of the character
378 /// (will only be four escape sequences for characters composed of two
379 /// "surrogate" characters).
380 ///
381 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
382 #[wasm_bindgen(js_name = encodeURI)]
383 pub fn encode_uri(decoded: &str) -> JsString;
384
385 /// The `encodeURIComponent()` function encodes a Uniform Resource Identifier (URI) component
386 /// by replacing each instance of certain characters by one, two, three, or four escape sequences
387 /// representing the UTF-8 encoding of the character
388 /// (will only be four escape sequences for characters composed of two "surrogate" characters).
389 ///
390 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
391 #[wasm_bindgen(js_name = encodeURIComponent)]
392 pub fn encode_uri_component(decoded: &str) -> JsString;
393
394 /// The `eval()` function evaluates JavaScript code represented as a string.
395 ///
396 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)
397 #[cfg(feature = "unsafe-eval")]
398 #[wasm_bindgen(catch)]
399 pub fn eval(js_source_text: &str) -> Result<JsValue, JsValue>;
400
401 /// The global `isFinite()` function determines whether the passed value is a finite number.
402 /// If needed, the parameter is first converted to a number.
403 ///
404 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
405 #[wasm_bindgen(js_name = isFinite)]
406 pub fn is_finite(value: &JsValue) -> bool;
407
408 /// The `parseInt()` function parses a string argument and returns an integer
409 /// of the specified radix (the base in mathematical numeral systems), or NaN on error.
410 ///
411 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
412 #[wasm_bindgen(js_name = parseInt)]
413 pub fn parse_int(text: &str, radix: u8) -> f64;
414
415 /// The `parseFloat()` function parses an argument and returns a floating point number,
416 /// or NaN on error.
417 ///
418 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
419 #[wasm_bindgen(js_name = parseFloat)]
420 pub fn parse_float(text: &str) -> f64;
421
422 /// The `escape()` function computes a new string in which certain characters have been
423 /// replaced by a hexadecimal escape sequence.
424 ///
425 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape)
426 #[wasm_bindgen]
427 pub fn escape(string: &str) -> JsString;
428
429 /// The `unescape()` function computes a new string in which hexadecimal escape
430 /// sequences are replaced with the character that it represents. The escape sequences might
431 /// be introduced by a function like `escape`. Usually, `decodeURI` or `decodeURIComponent`
432 /// are preferred over `unescape`.
433 ///
434 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape)
435 #[wasm_bindgen]
436 pub fn unescape(string: &str) -> JsString;
437}
438
439// Array
440#[wasm_bindgen]
441extern "C" {
442 #[wasm_bindgen(extends = Object, is_type_of = Array::is_array, typescript_type = "Array<any>")]
443 #[derive(Clone, Debug, PartialEq, Eq)]
444 pub type Array<T = JsValue>;
445
446 /// Creates a new empty array.
447 ///
448 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
449 #[cfg(not(js_sys_unstable_apis))]
450 #[wasm_bindgen(constructor)]
451 pub fn new() -> Array;
452
453 /// Creates a new empty array.
454 ///
455 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
456 #[cfg(js_sys_unstable_apis)]
457 #[wasm_bindgen(constructor)]
458 pub fn new<T>() -> Array<T>;
459
460 // Next major: deprecate
461 /// Creates a new empty array.
462 ///
463 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
464 #[wasm_bindgen(constructor)]
465 pub fn new_typed<T>() -> Array<T>;
466
467 /// Creates a new array with the specified length (elements are initialized to `undefined`).
468 ///
469 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
470 #[cfg(not(js_sys_unstable_apis))]
471 #[wasm_bindgen(constructor)]
472 pub fn new_with_length(len: u32) -> Array;
473
474 /// Creates a new array with the specified length (elements are initialized to `undefined`).
475 ///
476 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
477 #[cfg(js_sys_unstable_apis)]
478 #[wasm_bindgen(constructor)]
479 pub fn new_with_length<T>(len: u32) -> Array<T>;
480
481 // Next major: deprecate
482 /// Creates a new array with the specified length (elements are initialized to `undefined`).
483 ///
484 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
485 #[wasm_bindgen(constructor)]
486 pub fn new_with_length_typed<T>(len: u32) -> Array<T>;
487
488 /// Retrieves the element at the index, counting from the end if negative
489 /// (returns `undefined` if the index is out of range).
490 ///
491 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
492 #[cfg(not(js_sys_unstable_apis))]
493 #[wasm_bindgen(method)]
494 pub fn at<T>(this: &Array<T>, index: i32) -> T;
495
496 /// Retrieves the element at the index, counting from the end if negative
497 /// (returns `None` if the index is out of range).
498 ///
499 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
500 #[cfg(js_sys_unstable_apis)]
501 #[wasm_bindgen(method)]
502 pub fn at<T>(this: &Array<T>, index: i32) -> Option<T>;
503
504 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
505 ///
506 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
507 #[cfg(not(js_sys_unstable_apis))]
508 #[wasm_bindgen(method, indexing_getter)]
509 pub fn get<T>(this: &Array<T>, index: u32) -> T;
510
511 /// Retrieves the element at the index (returns `None` if the index is out of range).
512 ///
513 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
514 #[cfg(js_sys_unstable_apis)]
515 #[wasm_bindgen(method, indexing_getter)]
516 pub fn get<T>(this: &Array<T>, index: u32) -> Option<T>;
517
518 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
519 ///
520 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
521 #[wasm_bindgen(method, indexing_getter)]
522 pub fn get_unchecked<T>(this: &Array<T>, index: u32) -> T;
523
524 // Next major: deprecate
525 /// Retrieves the element at the index (returns `None` if the index is out of range,
526 /// or if the element is explicitly `undefined`).
527 #[wasm_bindgen(method, indexing_getter)]
528 pub fn get_checked<T>(this: &Array<T>, index: u32) -> Option<T>;
529
530 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
531 #[cfg(not(js_sys_unstable_apis))]
532 #[wasm_bindgen(method, indexing_setter)]
533 pub fn set<T>(this: &Array<T>, index: u32, value: T);
534
535 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
536 #[cfg(js_sys_unstable_apis)]
537 #[wasm_bindgen(method, indexing_setter)]
538 pub fn set<T>(this: &Array<T>, index: u32, value: &T);
539
540 // Next major: deprecate
541 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
542 #[wasm_bindgen(method, indexing_setter)]
543 pub fn set_ref<T>(this: &Array<T>, index: u32, value: &T);
544
545 /// Deletes the element at the index (does nothing if the index is out of range).
546 ///
547 /// The element at the index is set to `undefined`.
548 ///
549 /// This does not resize the array, the array will still be the same length.
550 #[wasm_bindgen(method, indexing_deleter)]
551 pub fn delete<T>(this: &Array<T>, index: u32);
552
553 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
554 /// from an array-like or iterable object.
555 ///
556 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
557 #[cfg(not(js_sys_unstable_apis))]
558 #[wasm_bindgen(static_method_of = Array)]
559 pub fn from(val: &JsValue) -> Array;
560
561 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
562 /// from an array-like or iterable object.
563 ///
564 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
565 #[cfg(js_sys_unstable_apis)]
566 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
567 pub fn from<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
568
569 // Next major: deprecate
570 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
571 /// from an array-like or iterable object.
572 ///
573 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
574 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
575 pub fn from_iterable<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
576
577 /// The `Array.from()` static method with a map function creates a new, shallow-copied
578 /// `Array` instance from an array-like or iterable object, applying the map function
579 /// to each value.
580 ///
581 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
582 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
583 pub fn from_iterable_map<I: Iterable, U>(
584 val: &I,
585 map: &mut dyn FnMut(I::Item, u32) -> Result<U, JsError>,
586 ) -> Result<Array<U>, JsValue>;
587
588 /// The `Array.fromAsync()` static method creates a new, shallow-copied `Array` instance
589 /// from an async iterable, iterable or array-like object.
590 ///
591 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
592 #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
593 pub fn from_async<I: AsyncIterable>(val: &I) -> Result<Promise<Array<I::Item>>, JsValue>;
594
595 /// The `Array.fromAsync()` static method with a map function creates a new, shallow-copied
596 /// `Array` instance from an async iterable, iterable or array-like object, applying the map
597 /// function to each value.
598 ///
599 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
600 #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
601 pub fn from_async_map<'a, I: AsyncIterable, R: Promising>(
602 val: &I,
603 map: &ScopedClosure<'a, dyn FnMut(I::Item, u32) -> Result<R, JsError>>,
604 ) -> Result<Promise<Array<R::Resolution>>, JsValue>;
605
606 /// The `copyWithin()` method shallow copies part of an array to another
607 /// location in the same array and returns it, without modifying its size.
608 ///
609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)
610 #[wasm_bindgen(method, js_name = copyWithin)]
611 pub fn copy_within<T>(this: &Array<T>, target: i32, start: i32, end: i32) -> Array<T>;
612
613 /// The `concat()` method is used to merge two or more arrays. This method
614 /// does not change the existing arrays, but instead returns a new array.
615 ///
616 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
617 #[wasm_bindgen(method)]
618 pub fn concat<T, U: Upcast<T>>(this: &Array<T>, array: &Array<U>) -> Array<T>;
619
620 /// The `concat()` method is used to merge two or more arrays. This method
621 /// does not change the existing arrays, but instead returns a new array.
622 ///
623 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
624 #[wasm_bindgen(method)]
625 pub fn concat_many<T, U: Upcast<T>>(this: &Array<T>, array: &[Array<U>]) -> Array<T>;
626
627 /// The `every()` method tests whether all elements in the array pass the test
628 /// implemented by the provided function.
629 ///
630 /// **Note:** Consider using [`Array::try_every`] if the predicate might throw an error.
631 ///
632 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
633 #[wasm_bindgen(method)]
634 pub fn every<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> bool;
635
636 /// The `every()` method tests whether all elements in the array pass the test
637 /// implemented by the provided function. _(Fallible variation)_
638 ///
639 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
640 #[wasm_bindgen(method, js_name = every, catch)]
641 pub fn try_every<T>(
642 this: &Array<T>,
643 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
644 ) -> Result<bool, JsValue>;
645
646 /// The `fill()` method fills all the elements of an array from a start index
647 /// to an end index with a static value. The end index is not included.
648 ///
649 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
650 #[wasm_bindgen(method)]
651 pub fn fill<T>(this: &Array<T>, value: &T, start: u32, end: u32) -> Array<T>;
652
653 /// The `filter()` method creates a new array with all elements that pass the
654 /// test implemented by the provided function.
655 ///
656 /// **Note:** Consider using [`Array::try_filter`] if the predicate might throw an error.
657 ///
658 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
659 #[wasm_bindgen(method)]
660 pub fn filter<T>(
661 this: &Array<T>,
662 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
663 ) -> Array<T>;
664
665 /// The `filter()` method creates a new array with all elements that pass the
666 /// test implemented by the provided function. _(Fallible variation)_
667 ///
668 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
669 #[wasm_bindgen(method, js_name = filter, catch)]
670 pub fn try_filter<T>(
671 this: &Array<T>,
672 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
673 ) -> Result<Array<T>, JsValue>;
674
675 /// The `find()` method returns the value of the first element in the array that satisfies
676 /// the provided testing function. Otherwise `undefined` is returned.
677 ///
678 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
679 #[cfg(not(js_sys_unstable_apis))]
680 #[wasm_bindgen(method)]
681 pub fn find<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
682
683 /// The `find()` method returns the value of the first element in the array that satisfies
684 /// the provided testing function. Returns `None` if no element matches.
685 ///
686 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
687 #[cfg(js_sys_unstable_apis)]
688 #[wasm_bindgen(method)]
689 pub fn find<T>(
690 this: &Array<T>,
691 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
692 ) -> Option<T>;
693
694 /// The `find()` method returns the value of the first element in the array that satisfies
695 /// the provided testing function. Otherwise `undefined` is returned. _(Fallible variation)_
696 ///
697 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
698 #[wasm_bindgen(method, js_name = find, catch)]
699 pub fn try_find<T>(
700 this: &Array<T>,
701 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
702 ) -> Result<Option<T>, JsValue>;
703
704 /// The `findIndex()` method returns the index of the first element in the array that
705 /// satisfies the provided testing function. Otherwise -1 is returned.
706 ///
707 /// **Note:** Consider using [`Array::try_find_index`] if the predicate might throw an error.
708 ///
709 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
710 #[wasm_bindgen(method, js_name = findIndex)]
711 pub fn find_index<T>(
712 this: &Array<T>,
713 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
714 ) -> i32;
715
716 /// The `findIndex()` method returns the index of the first element in the array that
717 /// satisfies the provided testing function. Otherwise -1 is returned. _(Fallible variation)_
718 ///
719 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
720 #[wasm_bindgen(method, js_name = findIndex, catch)]
721 pub fn try_find_index<T>(
722 this: &Array<T>,
723 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
724 ) -> Result<i32, JsValue>;
725
726 /// The `findLast()` method of Array instances iterates the array in reverse order
727 /// and returns the value of the first element that satisfies the provided testing function.
728 /// If no elements satisfy the testing function, undefined is returned.
729 ///
730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
731 #[cfg(not(js_sys_unstable_apis))]
732 #[wasm_bindgen(method, js_name = findLast)]
733 pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
734
735 /// The `findLast()` method of Array instances iterates the array in reverse order
736 /// and returns the value of the first element that satisfies the provided testing function.
737 /// Returns `None` if no element matches.
738 ///
739 /// **Note:** Consider using [`Array::try_find_last`] if the predicate might throw an error.
740 ///
741 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
742 #[cfg(js_sys_unstable_apis)]
743 #[wasm_bindgen(method, js_name = findLast)]
744 pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32) -> bool) -> Option<T>;
745
746 /// The `findLast()` method of Array instances iterates the array in reverse order
747 /// and returns the value of the first element that satisfies the provided testing function.
748 /// If no elements satisfy the testing function, undefined is returned. _(Fallible variation)_
749 ///
750 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
751 #[wasm_bindgen(method, js_name = findLast, catch)]
752 pub fn try_find_last<T>(
753 this: &Array<T>,
754 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
755 ) -> Result<Option<T>, JsValue>;
756
757 /// The `findLastIndex()` method of Array instances iterates the array in reverse order
758 /// and returns the index of the first element that satisfies the provided testing function.
759 /// If no elements satisfy the testing function, -1 is returned.
760 ///
761 /// **Note:** Consider using [`Array::try_find_last_index`] if the predicate might throw an error.
762 ///
763 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
764 #[wasm_bindgen(method, js_name = findLastIndex)]
765 pub fn find_last_index<T>(
766 this: &Array<T>,
767 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
768 ) -> i32;
769
770 /// The `findLastIndex()` method of Array instances iterates the array in reverse order
771 /// and returns the index of the first element that satisfies the provided testing function.
772 /// If no elements satisfy the testing function, -1 is returned. _(Fallible variation)_
773 ///
774 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
775 #[wasm_bindgen(method, js_name = findLastIndex, catch)]
776 pub fn try_find_last_index<T>(
777 this: &Array<T>,
778 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
779 ) -> Result<i32, JsValue>;
780
781 /// The `flat()` method creates a new array with all sub-array elements concatenated into it
782 /// recursively up to the specified depth.
783 ///
784 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
785 #[wasm_bindgen(method)]
786 pub fn flat<T>(this: &Array<T>, depth: i32) -> Array<JsValue>;
787
788 /// The `flatMap()` method first maps each element using a mapping function, then flattens
789 /// the result into a new array.
790 ///
791 /// **Note:** Consider using [`Array::try_flat_map`] for safer fallible handling.
792 ///
793 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
794 #[wasm_bindgen(method, js_name = flatMap)]
795 pub fn flat_map<T, U>(
796 this: &Array<T>,
797 callback: &mut dyn FnMut(T, u32, Array<T>) -> Vec<U>,
798 ) -> Array<U>;
799
800 /// The `flatMap()` method first maps each element using a mapping function, then flattens
801 /// the result into a new array.
802 ///
803 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
804 #[wasm_bindgen(method, js_name = flatMap, catch)]
805 pub fn try_flat_map<T, U>(
806 this: &Array<T>,
807 callback: &mut dyn FnMut(T, u32) -> Vec<U>,
808 ) -> Result<Array<U>, JsValue>;
809
810 /// The `forEach()` method executes a provided function once for each array element.
811 ///
812 /// **Note:** Consider using [`Array::try_for_each`] if the callback might throw an error.
813 ///
814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
815 #[wasm_bindgen(method, js_name = forEach)]
816 pub fn for_each<T: JsGeneric>(this: &Array<T>, callback: &mut dyn FnMut(T, u32, Array<T>));
817
818 /// The `forEach()` method executes a provided function once for each array element. _(Fallible variation)_
819 ///
820 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
821 #[wasm_bindgen(method, js_name = forEach, catch)]
822 pub fn try_for_each<T>(
823 this: &Array<T>,
824 callback: &mut dyn FnMut(T, u32) -> Result<(), JsError>,
825 ) -> Result<(), JsValue>;
826
827 /// The `includes()` method determines whether an array includes a certain
828 /// element, returning true or false as appropriate.
829 ///
830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
831 #[wasm_bindgen(method)]
832 pub fn includes<T>(this: &Array<T>, value: &T, from_index: i32) -> bool;
833
834 /// The `indexOf()` method returns the first index at which a given element
835 /// can be found in the array, or -1 if it is not present.
836 ///
837 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
838 #[wasm_bindgen(method, js_name = indexOf)]
839 pub fn index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
840
841 /// The `Array.isArray()` method determines whether the passed value is an Array.
842 ///
843 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)
844 #[wasm_bindgen(static_method_of = Array, js_name = isArray)]
845 pub fn is_array(value: &JsValue) -> bool;
846
847 /// The `join()` method joins all elements of an array (or an array-like object)
848 /// into a string and returns this string.
849 ///
850 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
851 #[wasm_bindgen(method)]
852 pub fn join<T>(this: &Array<T>, delimiter: &str) -> JsString;
853
854 /// The `lastIndexOf()` method returns the last index at which a given element
855 /// can be found in the array, or -1 if it is not present. The array is
856 /// searched backwards, starting at fromIndex.
857 ///
858 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
859 #[wasm_bindgen(method, js_name = lastIndexOf)]
860 pub fn last_index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
861
862 /// The length property of an object which is an instance of type Array
863 /// sets or returns the number of elements in that array. The value is an
864 /// unsigned, 32-bit integer that is always numerically greater than the
865 /// highest index in the array.
866 ///
867 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
868 #[wasm_bindgen(method, getter)]
869 pub fn length<T>(this: &Array<T>) -> u32;
870
871 /// Sets the length of the array.
872 ///
873 /// If it is set to less than the current length of the array, it will
874 /// shrink the array.
875 ///
876 /// If it is set to more than the current length of the array, it will
877 /// increase the length of the array, filling the new space with empty
878 /// slots.
879 ///
880 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
881 #[wasm_bindgen(method, setter)]
882 pub fn set_length<T>(this: &Array<T>, value: u32);
883
884 /// `map()` calls a provided callback function once for each element in an array,
885 /// in order, and constructs a new array from the results. callback is invoked
886 /// only for indexes of the array which have assigned values, including undefined.
887 /// It is not called for missing elements of the array (that is, indexes that have
888 /// never been set, which have been deleted or which have never been assigned a value).
889 ///
890 /// **Note:** Consider using [`Array::try_map`] for safer fallible handling.
891 ///
892 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
893 #[wasm_bindgen(method)]
894 pub fn map<T, U>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> U)
895 -> Array<U>;
896
897 /// `map()` calls a provided callback function once for each element in an array,
898 /// in order, and constructs a new array from the results. callback is invoked
899 /// only for indexes of the array which have assigned values, including undefined.
900 /// It is not called for missing elements of the array (that is, indexes that have
901 /// never been set, which have been deleted or which have never been assigned a value).
902 /// _(Fallible variation)_
903 ///
904 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
905 #[wasm_bindgen(method, js_name = map, catch)]
906 pub fn try_map<T, U>(
907 this: &Array<T>,
908 predicate: &mut dyn FnMut(T, u32) -> Result<U, JsError>,
909 ) -> Result<Array<U>, JsValue>;
910
911 /// The `Array.of()` method creates a new Array instance with a variable
912 /// number of arguments, regardless of number or type of the arguments.
913 ///
914 /// Note: For type inference use `Array::<T>::of(&[T])`.
915 ///
916 /// The difference between `Array.of()` and the `Array` constructor is in the
917 /// handling of integer arguments: `Array.of(7)` creates an array with a single
918 /// element, `7`, whereas `Array(7)` creates an empty array with a `length`
919 /// property of `7` (Note: this implies an array of 7 empty slots, not slots
920 /// with actual undefined values).
921 ///
922 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
923 #[wasm_bindgen(static_method_of = Array, js_name = of, variadic)]
924 pub fn of<T>(values: &[T]) -> Array<T>;
925
926 // Next major: deprecate these
927 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
928 #[wasm_bindgen(static_method_of = Array, js_name = of)]
929 pub fn of1(a: &JsValue) -> Array;
930
931 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
932 #[wasm_bindgen(static_method_of = Array, js_name = of)]
933 pub fn of2(a: &JsValue, b: &JsValue) -> Array;
934
935 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
936 #[wasm_bindgen(static_method_of = Array, js_name = of)]
937 pub fn of3(a: &JsValue, b: &JsValue, c: &JsValue) -> Array;
938
939 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
940 #[wasm_bindgen(static_method_of = Array, js_name = of)]
941 pub fn of4(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue) -> Array;
942
943 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
944 #[wasm_bindgen(static_method_of = Array, js_name = of)]
945 pub fn of5(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue, e: &JsValue) -> Array;
946
947 /// The `pop()` method removes the last element from an array and returns that
948 /// element. This method changes the length of the array.
949 ///
950 /// **Note:** Consider using [`Array::pop_checked`] for handling empty arrays.
951 ///
952 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
953 #[cfg(not(js_sys_unstable_apis))]
954 #[wasm_bindgen(method)]
955 pub fn pop<T>(this: &Array<T>) -> T;
956
957 /// The `pop()` method removes the last element from an array and returns that
958 /// element. This method changes the length of the array.
959 /// Returns `None` if the array is empty.
960 ///
961 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
962 #[cfg(js_sys_unstable_apis)]
963 #[wasm_bindgen(method)]
964 pub fn pop<T>(this: &Array<T>) -> Option<T>;
965
966 // Next major: deprecate
967 /// The `pop()` method removes the last element from an array and returns that
968 /// element. This method changes the length of the array.
969 ///
970 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
971 #[wasm_bindgen(method, js_name = pop)]
972 pub fn pop_checked<T>(this: &Array<T>) -> Option<T>;
973
974 /// The `push()` method adds one element to the end of an array and
975 /// returns the new length of the array.
976 ///
977 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
978 #[wasm_bindgen(method)]
979 pub fn push<T>(this: &Array<T>, value: &T) -> u32;
980
981 /// The `push()` method adds one or more elements to the end of an array and
982 /// returns the new length of the array.
983 ///
984 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
985 #[wasm_bindgen(method, js_name = push, variadic)]
986 pub fn push_many<T>(this: &Array<T>, values: &[T]) -> u32;
987
988 /// The `reduce()` method applies a function against an accumulator and each element in
989 /// the array (from left to right) to reduce it to a single value.
990 ///
991 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
992 #[cfg(not(js_sys_unstable_apis))]
993 #[wasm_bindgen(method)]
994 pub fn reduce<T>(
995 this: &Array<T>,
996 predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
997 initial_value: &JsValue,
998 ) -> JsValue;
999
1000 /// The `reduce()` method applies a function against an accumulator and each element in
1001 /// the array (from left to right) to reduce it to a single value.
1002 ///
1003 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1004 #[cfg(js_sys_unstable_apis)]
1005 #[wasm_bindgen(method)]
1006 pub fn reduce<T, A>(
1007 this: &Array<T>,
1008 predicate: &mut dyn FnMut(A, T, u32, Array<T>) -> A,
1009 initial_value: &A,
1010 ) -> A;
1011
1012 /// The `reduce()` method applies a function against an accumulator and each element in
1013 /// the array (from left to right) to reduce it to a single value. _(Fallible variation)_
1014 ///
1015 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1016 #[wasm_bindgen(method, js_name = reduce, catch)]
1017 pub fn try_reduce<T, A>(
1018 this: &Array<T>,
1019 predicate: &mut dyn FnMut(A, T, u32) -> Result<A, JsError>,
1020 initial_value: &A,
1021 ) -> Result<A, JsValue>;
1022
1023 /// The `reduceRight()` method applies a function against an accumulator and each value
1024 /// of the array (from right-to-left) to reduce it to a single value.
1025 ///
1026 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1027 #[cfg(not(js_sys_unstable_apis))]
1028 #[wasm_bindgen(method, js_name = reduceRight)]
1029 pub fn reduce_right<T>(
1030 this: &Array<T>,
1031 predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
1032 initial_value: &JsValue,
1033 ) -> JsValue;
1034
1035 /// The `reduceRight()` method applies a function against an accumulator and each value
1036 /// of the array (from right-to-left) to reduce it to a single value.
1037 ///
1038 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1039 #[cfg(js_sys_unstable_apis)]
1040 #[wasm_bindgen(method, js_name = reduceRight)]
1041 pub fn reduce_right<T, A>(
1042 this: &Array<T>,
1043 predicate: &mut dyn FnMut(A, T, u32, Array<T>) -> A,
1044 initial_value: &A,
1045 ) -> A;
1046
1047 /// The `reduceRight()` method applies a function against an accumulator and each value
1048 /// of the array (from right-to-left) to reduce it to a single value. _(Fallible variation)_
1049 ///
1050 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1051 #[wasm_bindgen(method, js_name = reduceRight, catch)]
1052 pub fn try_reduce_right<T, A>(
1053 this: &Array<T>,
1054 predicate: &mut dyn FnMut(JsValue, T, u32) -> Result<A, JsError>,
1055 initial_value: &A,
1056 ) -> Result<A, JsValue>;
1057
1058 /// The `reverse()` method reverses an array in place. The first array
1059 /// element becomes the last, and the last array element becomes the first.
1060 ///
1061 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
1062 #[wasm_bindgen(method)]
1063 pub fn reverse<T>(this: &Array<T>) -> Array<T>;
1064
1065 /// The `shift()` method removes the first element from an array and returns
1066 /// that removed element. This method changes the length of the array.
1067 ///
1068 /// **Note:** Consider using [`Array::shift_checked`] for handling empty arrays.
1069 ///
1070 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1071 #[cfg(not(js_sys_unstable_apis))]
1072 #[wasm_bindgen(method)]
1073 pub fn shift<T>(this: &Array<T>) -> T;
1074
1075 /// The `shift()` method removes the first element from an array and returns
1076 /// that removed element. This method changes the length of the array.
1077 /// Returns `None` if the array is empty.
1078 ///
1079 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1080 #[cfg(js_sys_unstable_apis)]
1081 #[wasm_bindgen(method)]
1082 pub fn shift<T>(this: &Array<T>) -> Option<T>;
1083
1084 // Next major: deprecate
1085 /// The `shift()` method removes the first element from an array and returns
1086 /// that removed element. This method changes the length of the array.
1087 ///
1088 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1089 #[wasm_bindgen(method, js_name = shift)]
1090 pub fn shift_checked<T>(this: &Array<T>) -> Option<T>;
1091
1092 /// The `slice()` method returns a shallow copy of a portion of an array into
1093 /// a new array object selected from begin to end (end not included).
1094 /// The original array will not be modified.
1095 ///
1096 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1097 #[cfg(not(js_sys_unstable_apis))]
1098 #[wasm_bindgen(method)]
1099 pub fn slice<T>(this: &Array<T>, start: u32, end: u32) -> Array<T>;
1100
1101 /// The `slice()` method returns a shallow copy of a portion of an array into
1102 /// a new array object selected from begin to end (end not included).
1103 /// The original array will not be modified. Negative indices count from the end.
1104 ///
1105 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1106 #[cfg(js_sys_unstable_apis)]
1107 #[wasm_bindgen(method)]
1108 pub fn slice<T>(this: &Array<T>, start: i32, end: i32) -> Array<T>;
1109
1110 /// The `slice()` method returns a shallow copy of a portion of an array into
1111 /// a new array object selected from the given index to the end.
1112 /// The original array will not be modified.
1113 ///
1114 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1115 #[cfg(not(js_sys_unstable_apis))]
1116 #[wasm_bindgen(method, js_name = slice)]
1117 pub fn slice_from<T>(this: &Array<T>, start: u32) -> Array<T>;
1118
1119 /// The `slice()` method returns a shallow copy of a portion of an array into
1120 /// a new array object selected from the given index to the end.
1121 /// The original array will not be modified. Negative indices count from the end.
1122 ///
1123 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1124 #[cfg(js_sys_unstable_apis)]
1125 #[wasm_bindgen(method, js_name = slice)]
1126 pub fn slice_from<T>(this: &Array<T>, start: i32) -> Array<T>;
1127
1128 /// The `some()` method tests whether at least one element in the array passes the test implemented
1129 /// by the provided function.
1130 /// Note: This method returns false for any condition put on an empty array.
1131 ///
1132 /// **Note:** Consider using [`Array::try_some`] if the predicate might throw an error.
1133 ///
1134 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1135 #[wasm_bindgen(method)]
1136 pub fn some<T>(this: &Array<T>, predicate: &mut dyn FnMut(T) -> bool) -> bool;
1137
1138 /// The `some()` method tests whether at least one element in the array passes the test implemented
1139 /// by the provided function. _(Fallible variation)_
1140 /// Note: This method returns false for any condition put on an empty array.
1141 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1142 #[wasm_bindgen(method, js_name = some, catch)]
1143 pub fn try_some<T>(
1144 this: &Array<T>,
1145 predicate: &mut dyn FnMut(T) -> Result<bool, JsError>,
1146 ) -> Result<bool, JsValue>;
1147
1148 /// The `sort()` method sorts the elements of an array in place and returns
1149 /// the array. The sort is not necessarily stable. The default sort
1150 /// order is according to string Unicode code points.
1151 ///
1152 /// The time and space complexity of the sort cannot be guaranteed as it
1153 /// is implementation dependent.
1154 ///
1155 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1156 #[wasm_bindgen(method)]
1157 pub fn sort<T>(this: &Array<T>) -> Array<T>;
1158
1159 /// The `sort()` method with a custom compare function.
1160 ///
1161 /// **Note:** Consider using [`Array::try_sort_by`] if the predicate might throw an error.
1162 ///
1163 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1164 #[wasm_bindgen(method, js_name = sort)]
1165 pub fn sort_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1166
1167 /// The `sort()` method with a custom compare function. _(Fallible variation)_
1168 ///
1169 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1170 #[wasm_bindgen(method, js_name = sort, catch)]
1171 pub fn try_sort_by<T>(
1172 this: &Array<T>,
1173 compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>,
1174 ) -> Result<Array<T>, JsValue>;
1175
1176 /// The `splice()` method changes the contents of an array by removing existing elements and/or
1177 /// adding new elements.
1178 ///
1179 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1180 #[wasm_bindgen(method)]
1181 pub fn splice<T>(this: &Array<T>, start: u32, delete_count: u32, item: &T) -> Array<T>;
1182
1183 /// The `splice()` method changes the contents of an array by removing existing elements and/or
1184 /// adding new elements.
1185 ///
1186 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1187 #[wasm_bindgen(method, js_name = splice, variadic)]
1188 pub fn splice_many<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1189
1190 /// The `toLocaleString()` method returns a string representing the elements of the array.
1191 /// The elements are converted to Strings using their toLocaleString methods and these
1192 /// Strings are separated by a locale-specific String (such as a comma ",").
1193 ///
1194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1195 #[cfg(not(js_sys_unstable_apis))]
1196 #[wasm_bindgen(method, js_name = toLocaleString)]
1197 pub fn to_locale_string<T>(this: &Array<T>, locales: &JsValue, options: &JsValue) -> JsString;
1198
1199 /// The `toLocaleString()` method returns a string representing the elements of the array.
1200 /// The elements are converted to Strings using their toLocaleString methods and these
1201 /// Strings are separated by a locale-specific String (such as a comma ",").
1202 ///
1203 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1204 #[cfg(js_sys_unstable_apis)]
1205 #[wasm_bindgen(method, js_name = toLocaleString)]
1206 pub fn to_locale_string<T>(
1207 this: &Array<T>,
1208 locales: &[JsString],
1209 options: &Intl::NumberFormatOptions,
1210 ) -> JsString;
1211
1212 /// The `toReversed()` method returns a new array with the elements in reversed order,
1213 /// without modifying the original array.
1214 ///
1215 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed)
1216 #[wasm_bindgen(method, js_name = toReversed)]
1217 pub fn to_reversed<T>(this: &Array<T>) -> Array<T>;
1218
1219 /// The `toSorted()` method returns a new array with the elements sorted in ascending order,
1220 /// without modifying the original array.
1221 ///
1222 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1223 #[wasm_bindgen(method, js_name = toSorted)]
1224 pub fn to_sorted<T>(this: &Array<T>) -> Array<T>;
1225
1226 /// The `toSorted()` method with a custom compare function.
1227 ///
1228 /// **Note:** Consider using [`Array::try_to_sorted_by`] if the predicate might throw an error.
1229 ///
1230 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1231 #[wasm_bindgen(method, js_name = toSorted)]
1232 pub fn to_sorted_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1233
1234 /// The `toSorted()` method with a custom compare function. _(Fallible variation)_
1235 ///
1236 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1237 #[wasm_bindgen(method, js_name = toSorted, catch)]
1238 pub fn try_to_sorted_by<T>(
1239 this: &Array<T>,
1240 compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>,
1241 ) -> Result<Array<T>, JsValue>;
1242
1243 /// The `toSpliced()` method returns a new array with some elements removed and/or
1244 /// replaced at a given index, without modifying the original array.
1245 ///
1246 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced)
1247 #[wasm_bindgen(method, js_name = toSpliced, variadic)]
1248 pub fn to_spliced<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1249
1250 /// The `toString()` method returns a string representing the specified array
1251 /// and its elements.
1252 ///
1253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)
1254 #[cfg(not(js_sys_unstable_apis))]
1255 #[wasm_bindgen(method, js_name = toString)]
1256 pub fn to_string<T>(this: &Array<T>) -> JsString;
1257
1258 /// Converts the Array into a Vector.
1259 #[wasm_bindgen(method, js_name = slice)]
1260 pub fn to_vec<T>(this: &Array<T>) -> Vec<T>;
1261
1262 /// The `unshift()` method adds one element to the beginning of an
1263 /// array and returns the new length of the array.
1264 ///
1265 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1266 #[wasm_bindgen(method)]
1267 pub fn unshift<T>(this: &Array<T>, value: &T) -> u32;
1268
1269 /// The `unshift()` method adds one or more elements to the beginning of an
1270 /// array and returns the new length of the array.
1271 ///
1272 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1273 #[wasm_bindgen(method, js_name = unshift, variadic)]
1274 pub fn unshift_many<T>(this: &Array<T>, values: &[T]) -> u32;
1275
1276 /// The `with()` method returns a new array with the element at the given index
1277 /// replaced with the given value, without modifying the original array.
1278 ///
1279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/with)
1280 #[wasm_bindgen(method, js_name = with)]
1281 pub fn with<T>(this: &Array<T>, index: u32, value: &T) -> Array<T>;
1282}
1283
1284// Tuples as a typed array variant
1285#[wasm_bindgen]
1286extern "C" {
1287 #[wasm_bindgen(extends = Object, js_name = Array, is_type_of = Array::is_array, no_upcast, typescript_type = "Array<any>")]
1288 #[derive(Clone, Debug)]
1289 pub type ArrayTuple<T: JsTuple = (JsValue,)>;
1290
1291 /// Creates a new JS array typed as a 1-tuple.
1292 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1293 pub fn new1<T1>(t1: &T1) -> ArrayTuple<(T1,)>;
1294
1295 /// Creates a new JS array typed as a 2-tuple.
1296 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1297 pub fn new2<T1, T2>(t1: &T1, t2: &T2) -> ArrayTuple<(T1, T2)>;
1298
1299 /// Creates a new JS array typed as a 3-tuple.
1300 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1301 pub fn new3<T1, T2, T3>(t1: &T1, t2: &T2, t3: &T3) -> ArrayTuple<(T1, T2, T3)>;
1302
1303 /// Creates a new JS array typed as a 4-tuple.
1304 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1305 pub fn new4<T1, T2, T3, T4>(t1: &T1, t2: &T2, t3: &T3, t4: &T4)
1306 -> ArrayTuple<(T1, T2, T3, T4)>;
1307
1308 /// Creates a new JS array typed as a 5-tuple.
1309 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1310 pub fn new5<T1, T2, T3, T4, T5>(
1311 t1: &T1,
1312 t2: &T2,
1313 t3: &T3,
1314 t4: &T4,
1315 t5: &T5,
1316 ) -> ArrayTuple<(T1, T2, T3, T4, T5)>;
1317
1318 /// Creates a new JS array typed as a 6-tuple.
1319 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1320 pub fn new6<T1, T2, T3, T4, T5, T6>(
1321 t1: &T1,
1322 t2: &T2,
1323 t3: &T3,
1324 t4: &T4,
1325 t5: &T5,
1326 t6: &T6,
1327 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6)>;
1328
1329 /// Creates a new JS array typed as a 7-tuple.
1330 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1331 pub fn new7<T1, T2, T3, T4, T5, T6, T7>(
1332 t1: &T1,
1333 t2: &T2,
1334 t3: &T3,
1335 t4: &T4,
1336 t5: &T5,
1337 t6: &T6,
1338 t7: &T7,
1339 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7)>;
1340
1341 /// Creates a new JS array typed as a 8-tuple.
1342 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1343 pub fn new8<T1, T2, T3, T4, T5, T6, T7, T8>(
1344 t1: &T1,
1345 t2: &T2,
1346 t3: &T3,
1347 t4: &T4,
1348 t5: &T5,
1349 t6: &T6,
1350 t7: &T7,
1351 t8: &T8,
1352 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7, T8)>;
1353
1354 /// Gets the 1st item
1355 #[wasm_bindgen(
1356 method,
1357 js_class = Array,
1358 getter,
1359 js_name = "0"
1360 )]
1361 pub fn get0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>) -> <T as JsTuple1>::T1;
1362
1363 /// Gets the 2nd item
1364 #[wasm_bindgen(
1365 method,
1366 js_class = Array,
1367 getter,
1368 js_name = "1"
1369 )]
1370 pub fn get1<T: JsTuple2 = (JsValue, JsValue)>(this: &ArrayTuple<T>) -> <T as JsTuple2>::T2;
1371
1372 /// Gets the 3rd item
1373 #[wasm_bindgen(
1374 method,
1375 js_class = Array,
1376 getter,
1377 js_name = "2"
1378 )]
1379 pub fn get2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1380 this: &ArrayTuple<T>,
1381 ) -> <T as JsTuple3>::T3;
1382
1383 /// Gets the 4th item
1384 #[wasm_bindgen(
1385 method,
1386 js_class = Array,
1387 getter,
1388 js_name = "3"
1389 )]
1390 pub fn get3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1391 this: &ArrayTuple<T>,
1392 ) -> <T as JsTuple4>::T4;
1393
1394 /// Gets the 5th item
1395 #[wasm_bindgen(
1396 method,
1397 js_class = Array,
1398 getter,
1399 js_name = "4"
1400 )]
1401 pub fn get4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1402 this: &ArrayTuple<T>,
1403 ) -> <T as JsTuple5>::T5;
1404
1405 /// Gets the 6th item
1406 #[wasm_bindgen(
1407 method,
1408 js_class = Array,
1409 getter,
1410 js_name = "5"
1411 )]
1412 pub fn get5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1413 this: &ArrayTuple<T>,
1414 ) -> <T as JsTuple6>::T6;
1415
1416 /// Gets the 7th item
1417 #[wasm_bindgen(
1418 method,
1419 js_class = Array,
1420 getter,
1421 js_name = "6"
1422 )]
1423 pub fn get6<
1424 T: JsTuple7 = (
1425 JsValue,
1426 JsValue,
1427 JsValue,
1428 JsValue,
1429 JsValue,
1430 JsValue,
1431 JsValue,
1432 ),
1433 >(
1434 this: &ArrayTuple<T>,
1435 ) -> <T as JsTuple7>::T7;
1436
1437 /// Gets the 8th item
1438 #[wasm_bindgen(
1439 method,
1440 js_class = Array,
1441 getter,
1442 js_name = "7"
1443 )]
1444 pub fn get7<
1445 T: JsTuple8 = (
1446 JsValue,
1447 JsValue,
1448 JsValue,
1449 JsValue,
1450 JsValue,
1451 JsValue,
1452 JsValue,
1453 JsValue,
1454 ),
1455 >(
1456 this: &ArrayTuple<T>,
1457 ) -> <T as JsTuple8>::T8;
1458
1459 /// Sets the 1st item
1460 #[wasm_bindgen(
1461 method,
1462 js_class = Array,
1463 setter,
1464 js_name = "0"
1465 )]
1466 pub fn set0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>, value: &<T as JsTuple1>::T1);
1467
1468 /// Sets the 2nd item
1469 #[wasm_bindgen(
1470 method,
1471 js_class = Array,
1472 setter,
1473 js_name = "1"
1474 )]
1475 pub fn set1<T: JsTuple2 = (JsValue, JsValue)>(
1476 this: &ArrayTuple<T>,
1477 value: &<T as JsTuple2>::T2,
1478 );
1479
1480 /// Sets the 3rd item
1481 #[wasm_bindgen(
1482 method,
1483 js_class = Array,
1484 setter,
1485 js_name = "2"
1486 )]
1487 pub fn set2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1488 this: &ArrayTuple<T>,
1489 value: &<T as JsTuple3>::T3,
1490 );
1491
1492 /// Sets the 4th item
1493 #[wasm_bindgen(
1494 method,
1495 js_class = Array,
1496 setter,
1497 js_name = "3"
1498 )]
1499 pub fn set3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1500 this: &ArrayTuple<T>,
1501 value: &<T as JsTuple4>::T4,
1502 );
1503
1504 /// Sets the 5th item
1505 #[wasm_bindgen(
1506 method,
1507 js_class = Array,
1508 setter,
1509 js_name = "4"
1510 )]
1511 pub fn set4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1512 this: &ArrayTuple<T>,
1513 value: &<T as JsTuple5>::T5,
1514 );
1515
1516 /// Sets the 6th item
1517 #[wasm_bindgen(
1518 method,
1519 js_class = Array,
1520 setter,
1521 js_name = "5"
1522 )]
1523 pub fn set5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1524 this: &ArrayTuple<T>,
1525 value: &<T as JsTuple6>::T6,
1526 );
1527
1528 /// Sets the 7th item
1529 #[wasm_bindgen(
1530 method,
1531 js_class = Array,
1532 setter,
1533 js_name = "6"
1534 )]
1535 pub fn set6<
1536 T: JsTuple7 = (
1537 JsValue,
1538 JsValue,
1539 JsValue,
1540 JsValue,
1541 JsValue,
1542 JsValue,
1543 JsValue,
1544 ),
1545 >(
1546 this: &ArrayTuple<T>,
1547 value: &<T as JsTuple7>::T7,
1548 );
1549
1550 /// Sets the 8th item
1551 #[wasm_bindgen(
1552 method,
1553 js_class = Array,
1554 setter,
1555 js_name = "7"
1556 )]
1557 pub fn set7<
1558 T: JsTuple8 = (
1559 JsValue,
1560 JsValue,
1561 JsValue,
1562 JsValue,
1563 JsValue,
1564 JsValue,
1565 JsValue,
1566 JsValue,
1567 ),
1568 >(
1569 this: &ArrayTuple<T>,
1570 value: &<T as JsTuple8>::T8,
1571 );
1572}
1573
1574/// Base trait for tuple types.
1575pub trait JsTuple {
1576 const ARITY: usize;
1577}
1578
1579macro_rules! impl_tuple_traits {
1580 // Base case: first trait has no parent (besides JsTuple)
1581 ($name:ident $ty:tt) => {
1582 pub trait $name: JsTuple {
1583 type $ty;
1584 }
1585 };
1586
1587 // Recursive case: define trait with parent, then recurse
1588 ($name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1589 pub trait $name: JsTuple {
1590 type $ty;
1591 }
1592
1593 impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1594 };
1595
1596 // Internal: traits that have a parent
1597 (@with_parent $trait:ident $name:ident $ty:tt) => {
1598 pub trait $name: $trait {
1599 type $ty;
1600 }
1601 };
1602
1603 (@with_parent $trait:ident $name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1604 pub trait $name: $trait {
1605 type $ty;
1606 }
1607
1608 impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1609 };
1610}
1611
1612macro_rules! impl_parent_traits {
1613 ([$($types:tt),+] [] []) => {};
1614
1615 ([$($types:tt),+] [$trait:ident $($rest_traits:ident)*] [$ty:tt $($rest_tys:tt)*]) => {
1616 impl<$($types),+> $trait for ($($types),+,) {
1617 type $ty = $ty;
1618 }
1619
1620 impl_parent_traits!([$($types),+] [$($rest_traits)*] [$($rest_tys)*]);
1621 };
1622}
1623
1624// Define the trait hierarchy once
1625impl_tuple_traits!(
1626 JsTuple1 T1
1627 JsTuple2 T2
1628 JsTuple3 T3
1629 JsTuple4 T4
1630 JsTuple5 T5
1631 JsTuple6 T6
1632 JsTuple7 T7
1633 JsTuple8 T8
1634);
1635
1636impl<T: JsTuple> ArrayTuple<T> {
1637 /// Get the static arity of the ArrayTuple type.
1638 #[allow(clippy::len_without_is_empty)]
1639 pub fn len(&self) -> usize {
1640 <T as JsTuple>::ARITY
1641 }
1642}
1643
1644macro_rules! impl_tuple {
1645 ($arity:literal [$($traits:ident)*] [$($T:tt)+] [$($vars:tt)+] $new:ident $last:ident $last_ty:tt) => {
1646 impl<$($T),+> JsTuple for ($($T),+,) {
1647 const ARITY: usize = $arity;
1648 }
1649
1650 impl_parent_traits!([$($T),+] [$($traits)*] [$($T)*]);
1651
1652 impl<$($T: JsGeneric),+> From<($($T,)+)> for ArrayTuple<($($T),+,)> {
1653 fn from(($($vars,)+): ($($T,)+)) -> Self {
1654 let arr = [$(
1655 unsafe { core::mem::transmute_copy::<$T, JsValue>(&$vars) }
1656 ),+];
1657 core::mem::forget(($($vars,)+));
1658 Array::of(&arr).unchecked_into()
1659 }
1660 }
1661
1662 impl<$($T: JsGeneric + Default),+> Default for ArrayTuple<($($T),+,)> {
1663 fn default() -> Self {
1664 $(
1665 let $vars: $T = Default::default();
1666 )+
1667 let arr = [$(
1668 unsafe { core::mem::transmute_copy::<$T, JsValue>(&$vars) }
1669 ),+];
1670 core::mem::forget(($($vars,)+));
1671 Array::of(&arr).unchecked_into()
1672 }
1673 }
1674
1675 impl<$($T: JsGeneric),+> ArrayTuple<($($T),+,)> {
1676 /// Get the first element of the ArrayTuple
1677 pub fn first(&self) -> T1 {
1678 self.get0()
1679 }
1680
1681 /// Get the last element of the ArrayTuple
1682 pub fn last(&self) -> $last_ty {
1683 self.$last()
1684 }
1685
1686 /// Convert the ArrayTuple into its corresponding Rust tuple
1687 pub fn into_parts(self) -> ($($T,)+) {
1688 ($(self.$vars(),)+)
1689 }
1690
1691 /// Create a new ArrayTuple from the corresponding parts.
1692 ///
1693 /// # Example
1694 ///
1695 /// ```
1696 /// use js_sys::{ArrayTuple, JsString};
1697 ///
1698 /// let tuple = ArrayTuple::<JsString, JsString>::new(&"a".into(), &"b".into());
1699 /// ```
1700 ///
1701 /// Note: You must specify the T using `::<...>` syntax on `ArrayTuple`.
1702 /// Alternatively, use `new1`, `new2`, etc. for type inference from the left-hand side.
1703 pub fn new($($vars: &$T),+) -> ArrayTuple<($($T),+,)> {
1704 ArrayTuple::$new($($vars),+)
1705 }
1706 }
1707 };
1708}
1709
1710// Implement for each tuple size
1711impl_tuple!(1 [JsTuple1] [T1] [get0] new1 get0 T1);
1712impl_tuple!(2 [JsTuple1 JsTuple2] [T1 T2] [get0 get1] new2 get1 T2);
1713impl_tuple!(3 [JsTuple1 JsTuple2 JsTuple3] [T1 T2 T3] [get0 get1 get2] new3 get2 T3);
1714impl_tuple!(4 [JsTuple1 JsTuple2 JsTuple3 JsTuple4] [T1 T2 T3 T4] [get0 get1 get2 get3] new4 get3 T4);
1715impl_tuple!(5 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5] [T1 T2 T3 T4 T5] [get0 get1 get2 get3 get4] new5 get4 T5);
1716impl_tuple!(6 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5 JsTuple6] [T1 T2 T3 T4 T5 T6] [get0 get1 get2 get3 get4 get5] new6 get5 T6);
1717impl_tuple!(7 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5 JsTuple6 JsTuple7] [T1 T2 T3 T4 T5 T6 T7] [get0 get1 get2 get3 get4 get5 get6] new7 get6 T7);
1718impl_tuple!(8 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5 JsTuple6 JsTuple7 JsTuple8] [T1 T2 T3 T4 T5 T6 T7 T8] [get0 get1 get2 get3 get4 get5 get6 get7] new8 get7 T8);
1719
1720// Macro to generate structural covariance impls for each arity
1721macro_rules! impl_tuple_covariance {
1722 ([$($T:ident)+] [$($Target:ident)+] [$($Ts:ident)+]) => {
1723 // ArrayTuple -> Array
1724 // Allows (T1, T2, ...) to be used where (Target) is expected
1725 // when all T1, T2, ... are covariant to Target
1726 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for Array<Target>
1727 where
1728 $(Target: UpcastFrom<$T>,)+
1729 {
1730 }
1731 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for JsOption<Array<Target>>
1732 where
1733 $(Target: UpcastFrom<$T>,)+
1734 {}
1735 // Array<T> -> ArrayTuple<T, ...>
1736 impl<T> UpcastFrom<Array<T>> for ArrayTuple<($($Ts,)+)> {}
1737 impl<T: JsGeneric> UpcastFrom<Array<T>> for ArrayTuple<($(JsOption<$Ts>,)+)> {}
1738 };
1739}
1740
1741impl_tuple_covariance!([T1][Target1][T]);
1742impl_tuple_covariance!([T1 T2] [Target1 Target2] [T T]);
1743impl_tuple_covariance!([T1 T2 T3] [Target1 Target2 Target3] [T T T]);
1744impl_tuple_covariance!([T1 T2 T3 T4] [Target1 Target2 Target3 Target4] [T T T T]);
1745impl_tuple_covariance!([T1 T2 T3 T4 T5] [Target1 Target2 Target3 Target4 Target5] [T T T T T]);
1746impl_tuple_covariance!([T1 T2 T3 T4 T5 T6] [Target1 Target2 Target3 Target4 Target5 Target6] [T T T T T T]);
1747impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7] [Target1 Target2 Target3 Target4 Target5 Target6 Target7] [T T T T T T T]);
1748impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7 T8] [Target1 Target2 Target3 Target4 Target5 Target6 Target7 Target8] [T T T T T T T T]);
1749
1750// Tuple casting is implemented in core
1751impl<T: JsTuple, U: JsTuple> UpcastFrom<ArrayTuple<T>> for ArrayTuple<U> where U: UpcastFrom<T> {}
1752impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsValue {}
1753impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsOption<JsValue> {}
1754
1755/// Iterator returned by `Array::into_iter`
1756#[derive(Debug, Clone)]
1757pub struct ArrayIntoIter<T: JsGeneric = JsValue> {
1758 range: core::ops::Range<u32>,
1759 array: Array<T>,
1760}
1761
1762#[cfg(not(js_sys_unstable_apis))]
1763impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1764 type Item = T;
1765
1766 fn next(&mut self) -> Option<Self::Item> {
1767 let index = self.range.next()?;
1768 Some(self.array.get(index))
1769 }
1770
1771 #[inline]
1772 fn size_hint(&self) -> (usize, Option<usize>) {
1773 self.range.size_hint()
1774 }
1775
1776 #[inline]
1777 fn count(self) -> usize
1778 where
1779 Self: Sized,
1780 {
1781 self.range.count()
1782 }
1783
1784 #[inline]
1785 fn last(self) -> Option<Self::Item>
1786 where
1787 Self: Sized,
1788 {
1789 let Self { range, array } = self;
1790 range.last().map(|index| array.get(index))
1791 }
1792
1793 #[inline]
1794 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1795 self.range.nth(n).map(|index| self.array.get(index))
1796 }
1797}
1798
1799#[cfg(js_sys_unstable_apis)]
1800impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1801 type Item = T;
1802
1803 fn next(&mut self) -> Option<Self::Item> {
1804 let index = self.range.next()?;
1805 self.array.get(index)
1806 }
1807
1808 #[inline]
1809 fn size_hint(&self) -> (usize, Option<usize>) {
1810 self.range.size_hint()
1811 }
1812
1813 #[inline]
1814 fn count(self) -> usize
1815 where
1816 Self: Sized,
1817 {
1818 self.range.count()
1819 }
1820
1821 #[inline]
1822 fn last(self) -> Option<Self::Item>
1823 where
1824 Self: Sized,
1825 {
1826 let Self { range, array } = self;
1827 range.last().and_then(|index| array.get(index))
1828 }
1829
1830 #[inline]
1831 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1832 self.range.nth(n).and_then(|index| self.array.get(index))
1833 }
1834}
1835
1836#[cfg(not(js_sys_unstable_apis))]
1837impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1838 fn next_back(&mut self) -> Option<Self::Item> {
1839 let index = self.range.next_back()?;
1840 Some(self.array.get(index))
1841 }
1842
1843 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1844 self.range.nth_back(n).map(|index| self.array.get(index))
1845 }
1846}
1847
1848#[cfg(js_sys_unstable_apis)]
1849impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1850 fn next_back(&mut self) -> Option<Self::Item> {
1851 let index = self.range.next_back()?;
1852 self.array.get(index)
1853 }
1854
1855 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1856 self.range
1857 .nth_back(n)
1858 .and_then(|index| self.array.get(index))
1859 }
1860}
1861
1862impl<T: JsGeneric> core::iter::FusedIterator for ArrayIntoIter<T> {}
1863
1864impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIntoIter<T> {}
1865
1866/// Iterator returned by `Array::iter`
1867#[derive(Debug, Clone)]
1868pub struct ArrayIter<'a, T: JsGeneric = JsValue> {
1869 range: core::ops::Range<u32>,
1870 array: &'a Array<T>,
1871}
1872
1873impl<T: JsGeneric> core::iter::Iterator for ArrayIter<'_, T> {
1874 type Item = T;
1875
1876 fn next(&mut self) -> Option<Self::Item> {
1877 let index = self.range.next()?;
1878 Some(self.array.get_unchecked(index))
1879 }
1880
1881 #[inline]
1882 fn size_hint(&self) -> (usize, Option<usize>) {
1883 self.range.size_hint()
1884 }
1885
1886 #[inline]
1887 fn count(self) -> usize
1888 where
1889 Self: Sized,
1890 {
1891 self.range.count()
1892 }
1893
1894 #[inline]
1895 fn last(self) -> Option<Self::Item>
1896 where
1897 Self: Sized,
1898 {
1899 let Self { range, array } = self;
1900 range.last().map(|index| array.get_unchecked(index))
1901 }
1902
1903 #[inline]
1904 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1905 self.range
1906 .nth(n)
1907 .map(|index| self.array.get_unchecked(index))
1908 }
1909}
1910
1911impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIter<'_, T> {
1912 fn next_back(&mut self) -> Option<Self::Item> {
1913 let index = self.range.next_back()?;
1914 Some(self.array.get_unchecked(index))
1915 }
1916
1917 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1918 self.range
1919 .nth_back(n)
1920 .map(|index| self.array.get_unchecked(index))
1921 }
1922}
1923
1924impl<T: JsGeneric> core::iter::FusedIterator for ArrayIter<'_, T> {}
1925
1926impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIter<'_, T> {}
1927
1928impl<T: JsGeneric> Array<T> {
1929 /// Returns an iterator over the values of the JS array.
1930 pub fn iter(&self) -> ArrayIter<'_, T> {
1931 ArrayIter {
1932 range: 0..self.length(),
1933 array: self,
1934 }
1935 }
1936}
1937
1938impl<T: JsGeneric> core::iter::IntoIterator for Array<T> {
1939 type Item = T;
1940 type IntoIter = ArrayIntoIter<T>;
1941
1942 fn into_iter(self) -> Self::IntoIter {
1943 ArrayIntoIter {
1944 range: 0..self.length(),
1945 array: self,
1946 }
1947 }
1948}
1949
1950#[cfg(not(js_sys_unstable_apis))]
1951impl<A, T: JsGeneric> core::iter::FromIterator<A> for Array<T>
1952where
1953 A: AsRef<T>,
1954{
1955 fn from_iter<I>(iter: I) -> Array<T>
1956 where
1957 I: IntoIterator<Item = A>,
1958 {
1959 let iter = iter.into_iter();
1960 let mut out = Array::new_typed();
1961 out.extend(iter);
1962 out
1963 }
1964}
1965
1966#[cfg(js_sys_unstable_apis)]
1967impl<A, T: JsGeneric> core::iter::FromIterator<A> for Array<T>
1968where
1969 A: AsRef<T>,
1970{
1971 fn from_iter<I>(iter: I) -> Array<T>
1972 where
1973 I: IntoIterator<Item = A>,
1974 {
1975 let iter = iter.into_iter();
1976 let (lower, upper) = iter.size_hint();
1977 let capacity = upper.unwrap_or(lower);
1978 let out = Array::new_with_length_typed(capacity as u32);
1979 let mut i = 0;
1980 for value in iter {
1981 out.set(i, value.as_ref());
1982 i += 1;
1983 }
1984 out
1985 }
1986}
1987
1988impl<A, T: JsGeneric> core::iter::Extend<A> for Array<T>
1989where
1990 A: AsRef<T>,
1991{
1992 fn extend<I>(&mut self, iter: I)
1993 where
1994 I: IntoIterator<Item = A>,
1995 {
1996 for value in iter {
1997 self.push(value.as_ref());
1998 }
1999 }
2000}
2001
2002impl Default for Array<JsValue> {
2003 fn default() -> Self {
2004 Self::new()
2005 }
2006}
2007
2008impl<T> Iterable for Array<T> {
2009 type Item = T;
2010}
2011
2012impl<T: JsTuple> Iterable for ArrayTuple<T> {
2013 type Item = JsValue;
2014}
2015
2016// ArrayBufferOptions
2017#[wasm_bindgen]
2018extern "C" {
2019 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBufferOptions")]
2020 #[derive(Clone, Debug, PartialEq, Eq)]
2021 pub type ArrayBufferOptions;
2022
2023 /// The maximum size, in bytes, that the array buffer can be resized to.
2024 #[wasm_bindgen(method, setter, js_name = maxByteLength)]
2025 pub fn set_max_byte_length(this: &ArrayBufferOptions, max_byte_length: usize);
2026
2027 /// The maximum size, in bytes, that the array buffer can be resized to.
2028 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2029 pub fn get_max_byte_length(this: &ArrayBufferOptions) -> usize;
2030}
2031
2032impl ArrayBufferOptions {
2033 #[cfg(not(js_sys_unstable_apis))]
2034 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2035 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::new());
2036 options.set_max_byte_length(max_byte_length);
2037 options
2038 }
2039
2040 #[cfg(js_sys_unstable_apis)]
2041 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2042 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::<JsValue>::new());
2043 options.set_max_byte_length(max_byte_length);
2044 options
2045 }
2046}
2047
2048// ArrayBuffer
2049#[wasm_bindgen]
2050extern "C" {
2051 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBuffer")]
2052 #[derive(Clone, Debug, PartialEq, Eq)]
2053 pub type ArrayBuffer;
2054
2055 /// The `ArrayBuffer` object is used to represent a generic,
2056 /// fixed-length raw binary data buffer. You cannot directly
2057 /// manipulate the contents of an `ArrayBuffer`; instead, you
2058 /// create one of the typed array objects or a `DataView` object
2059 /// which represents the buffer in a specific format, and use that
2060 /// to read and write the contents of the buffer.
2061 ///
2062 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2063 #[cfg(not(js_sys_unstable_apis))]
2064 #[wasm_bindgen(constructor)]
2065 pub fn new(length: u32) -> ArrayBuffer;
2066
2067 /// The `ArrayBuffer` object is used to represent a generic,
2068 /// fixed-length raw binary data buffer. You cannot directly
2069 /// manipulate the contents of an `ArrayBuffer`; instead, you
2070 /// create one of the typed array objects or a `DataView` object
2071 /// which represents the buffer in a specific format, and use that
2072 /// to read and write the contents of the buffer.
2073 ///
2074 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2075 #[cfg(js_sys_unstable_apis)]
2076 #[wasm_bindgen(constructor)]
2077 pub fn new(length: usize) -> ArrayBuffer;
2078
2079 /// The `ArrayBuffer` object is used to represent a generic,
2080 /// fixed-length raw binary data buffer. You cannot directly
2081 /// manipulate the contents of an `ArrayBuffer`; instead, you
2082 /// create one of the typed array objects or a `DataView` object
2083 /// which represents the buffer in a specific format, and use that
2084 /// to read and write the contents of the buffer.
2085 ///
2086 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2087 #[wasm_bindgen(constructor)]
2088 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> ArrayBuffer;
2089
2090 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2091 /// it's an accessor property whose set accessor function is undefined,
2092 /// meaning that you can only read this property.
2093 /// The value is established when the array is constructed and cannot be changed.
2094 /// This property returns 0 if this ArrayBuffer has been detached.
2095 ///
2096 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2097 #[cfg(not(js_sys_unstable_apis))]
2098 #[wasm_bindgen(method, getter, js_name = byteLength)]
2099 pub fn byte_length(this: &ArrayBuffer) -> u32;
2100
2101 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2102 /// it's an accessor property whose set accessor function is undefined,
2103 /// meaning that you can only read this property.
2104 /// The value is established when the array is constructed and cannot be changed.
2105 /// This property returns 0 if this ArrayBuffer has been detached.
2106 ///
2107 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2108 #[cfg(js_sys_unstable_apis)]
2109 #[wasm_bindgen(method, getter, js_name = byteLength)]
2110 pub fn byte_length(this: &ArrayBuffer) -> usize;
2111
2112 /// The `detached` accessor property of `ArrayBuffer` instances returns a boolean indicating
2113 /// whether or not this buffer has been detached (transferred).
2114 ///
2115 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/detached)
2116 #[wasm_bindgen(method, getter)]
2117 pub fn detached(this: &ArrayBuffer) -> bool;
2118
2119 /// The `isView()` method returns true if arg is one of the `ArrayBuffer`
2120 /// views, such as typed array objects or a DataView; false otherwise.
2121 ///
2122 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView)
2123 #[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
2124 pub fn is_view(value: &JsValue) -> bool;
2125
2126 /// The `maxByteLength` accessor property of ArrayBuffer instances returns the maximum
2127 /// length (in bytes) that this array buffer can be resized to.
2128 ///
2129 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/maxByteLength)
2130 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2131 pub fn max_byte_length(this: &ArrayBuffer) -> usize;
2132
2133 /// The `resizable` accessor property of `ArrayBuffer` instances returns whether this array buffer
2134 /// can be resized or not.
2135 ///
2136 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resizable)
2137 #[wasm_bindgen(method, getter)]
2138 pub fn resizable(this: &ArrayBuffer) -> bool;
2139
2140 /// The `resize()` method of ArrayBuffer instances resizes the ArrayBuffer to the
2141 /// specified size, in bytes.
2142 ///
2143 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resize)
2144 #[wasm_bindgen(method, catch)]
2145 pub fn resize(this: &ArrayBuffer, new_len: usize) -> Result<(), JsValue>;
2146
2147 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2148 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2149 /// up to end, exclusive.
2150 ///
2151 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2152 #[cfg(not(js_sys_unstable_apis))]
2153 #[wasm_bindgen(method)]
2154 pub fn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer;
2155
2156 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2157 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2158 /// up to end, exclusive. Negative indices count from the end.
2159 ///
2160 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2161 #[cfg(js_sys_unstable_apis)]
2162 #[wasm_bindgen(method)]
2163 pub fn slice(this: &ArrayBuffer, begin: isize, end: isize) -> ArrayBuffer;
2164
2165 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2166 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2167 /// up to end, exclusive.
2168 ///
2169 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2170 #[cfg(not(js_sys_unstable_apis))]
2171 #[wasm_bindgen(method, js_name = slice)]
2172 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2173
2174 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2175 /// are a copy of this `ArrayBuffer`'s bytes from begin to the end.
2176 /// Negative indices count from the end.
2177 ///
2178 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2179 #[cfg(js_sys_unstable_apis)]
2180 #[wasm_bindgen(method, js_name = slice)]
2181 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2182
2183 // Next major: deprecate
2184 /// Like `slice()` but with the `end` argument.
2185 ///
2186 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2187 #[wasm_bindgen(method, js_name = slice)]
2188 pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer;
2189
2190 /// The `transfer()` method of ArrayBuffer instances creates a new `ArrayBuffer`
2191 /// with the same byte content as this buffer, then detaches this buffer.
2192 ///
2193 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2194 #[wasm_bindgen(method, catch)]
2195 pub fn transfer(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2196
2197 /// The `transfer()` method of `ArrayBuffer` instances creates a new `ArrayBuffer`
2198 /// with the same byte content as this buffer, then detaches this buffer.
2199 ///
2200 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2201 #[wasm_bindgen(method, catch, js_name = transfer)]
2202 pub fn transfer_with_length(
2203 this: &ArrayBuffer,
2204 new_byte_length: usize,
2205 ) -> Result<ArrayBuffer, JsValue>;
2206
2207 /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2208 /// ArrayBuffer with the same byte content as this buffer, then detaches this buffer.
2209 ///
2210 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2211 #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2212 pub fn transfer_to_fixed_length(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2213
2214 /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2215 /// `ArrayBuffer` with the same byte content as this buffer, then detaches this buffer.
2216 ///
2217 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2218 #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2219 pub fn transfer_to_fixed_length_with_length(
2220 this: &ArrayBuffer,
2221 new_byte_length: usize,
2222 ) -> Result<ArrayBuffer, JsValue>;
2223}
2224
2225impl UpcastFrom<&[u8]> for ArrayBuffer {}
2226
2227// SharedArrayBuffer
2228#[wasm_bindgen]
2229extern "C" {
2230 #[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
2231 #[derive(Clone, Debug)]
2232 pub type SharedArrayBuffer;
2233
2234 /// The `SharedArrayBuffer` object is used to represent a generic,
2235 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2236 /// object, but in a way that they can be used to create views
2237 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2238 /// cannot become detached.
2239 ///
2240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2241 #[cfg(not(js_sys_unstable_apis))]
2242 #[wasm_bindgen(constructor)]
2243 pub fn new(length: u32) -> SharedArrayBuffer;
2244
2245 /// The `SharedArrayBuffer` object is used to represent a generic,
2246 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2247 /// object, but in a way that they can be used to create views
2248 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2249 /// cannot become detached.
2250 ///
2251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2252 #[cfg(js_sys_unstable_apis)]
2253 #[wasm_bindgen(constructor)]
2254 pub fn new(length: usize) -> SharedArrayBuffer;
2255
2256 /// The `SharedArrayBuffer` object is used to represent a generic,
2257 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2258 /// object, but in a way that they can be used to create views
2259 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2260 /// cannot become detached.
2261 ///
2262 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2263 #[wasm_bindgen(constructor)]
2264 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> SharedArrayBuffer;
2265
2266 /// The `byteLength` accessor property represents the length of
2267 /// an `SharedArrayBuffer` in bytes. This is established when
2268 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2269 ///
2270 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2271 #[cfg(not(js_sys_unstable_apis))]
2272 #[wasm_bindgen(method, getter, js_name = byteLength)]
2273 pub fn byte_length(this: &SharedArrayBuffer) -> u32;
2274
2275 /// The `byteLength` accessor property represents the length of
2276 /// an `SharedArrayBuffer` in bytes. This is established when
2277 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2278 ///
2279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2280 #[cfg(js_sys_unstable_apis)]
2281 #[wasm_bindgen(method, getter, js_name = byteLength)]
2282 pub fn byte_length(this: &SharedArrayBuffer) -> usize;
2283
2284 /// The `growable` accessor property of `SharedArrayBuffer` instances returns whether
2285 /// this `SharedArrayBuffer` can be grown or not.
2286 ///
2287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/growable)
2288 #[wasm_bindgen(method, getter)]
2289 pub fn growable(this: &SharedArrayBuffer) -> bool;
2290
2291 /// The `grow()` method of `SharedArrayBuffer` instances grows the
2292 /// `SharedArrayBuffer` to the specified size, in bytes.
2293 ///
2294 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/grow)
2295 #[wasm_bindgen(method, catch)]
2296 pub fn grow(this: &SharedArrayBuffer, new_byte_length: usize) -> Result<(), JsValue>;
2297
2298 /// The `maxByteLength` accessor property of `SharedArrayBuffer` instances returns the maximum
2299 /// length (in bytes) that this `SharedArrayBuffer` can be resized to.
2300 ///
2301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/maxByteLength)
2302 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2303 pub fn max_byte_length(this: &SharedArrayBuffer) -> usize;
2304
2305 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2306 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2307 /// up to end, exclusive.
2308 ///
2309 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2310 #[cfg(not(js_sys_unstable_apis))]
2311 #[wasm_bindgen(method)]
2312 pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer;
2313
2314 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2315 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2316 /// up to end, exclusive. Negative indices count from the end.
2317 ///
2318 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2319 #[cfg(js_sys_unstable_apis)]
2320 #[wasm_bindgen(method)]
2321 pub fn slice(this: &SharedArrayBuffer, begin: isize, end: isize) -> SharedArrayBuffer;
2322
2323 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2324 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2325 /// up to end, exclusive.
2326 ///
2327 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2328 #[cfg(not(js_sys_unstable_apis))]
2329 #[wasm_bindgen(method)]
2330 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2331
2332 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2333 /// are a copy of this `SharedArrayBuffer`'s bytes from begin to end.
2334 /// Negative indices count from the end.
2335 ///
2336 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2337 #[cfg(js_sys_unstable_apis)]
2338 #[wasm_bindgen(method)]
2339 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2340
2341 // Next major: deprecate
2342 /// Like `slice()` but with the `end` argument.
2343 ///
2344 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2345 #[wasm_bindgen(method, js_name = slice)]
2346 pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer;
2347}
2348
2349// Array Iterator
2350#[wasm_bindgen]
2351extern "C" {
2352 /// The `keys()` method returns a new Array Iterator object that contains the
2353 /// keys for each index in the array.
2354 ///
2355 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys)
2356 #[wasm_bindgen(method)]
2357 pub fn keys<T>(this: &Array<T>) -> Iterator<T>;
2358
2359 /// The `entries()` method returns a new Array Iterator object that contains
2360 /// the key/value pairs for each index in the array.
2361 ///
2362 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2363 #[cfg(not(js_sys_unstable_apis))]
2364 #[wasm_bindgen(method)]
2365 #[deprecated(note = "recommended to use `Array::entries_typed` instead for typing")]
2366 #[allow(deprecated)]
2367 pub fn entries<T>(this: &Array<T>) -> Iterator<T>;
2368
2369 /// The `entries()` method returns a new Array Iterator object that contains
2370 /// the key/value pairs for each index in the array.
2371 ///
2372 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2373 #[cfg(js_sys_unstable_apis)]
2374 #[wasm_bindgen(method)]
2375 pub fn entries<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2376
2377 // Next major: deprecate
2378 /// The `entries()` method returns a new Array Iterator object that contains
2379 /// the key/value pairs for each index in the array.
2380 ///
2381 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2382 #[wasm_bindgen(method, js_name = entries)]
2383 pub fn entries_typed<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2384
2385 /// The `values()` method returns a new Array Iterator object that
2386 /// contains the values for each index in the array.
2387 ///
2388 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
2389 #[wasm_bindgen(method)]
2390 pub fn values<T>(this: &Array<T>) -> Iterator<T>;
2391}
2392
2393pub trait TypedArray: JsGeneric {}
2394
2395// Next major: use usize/isize for indices
2396/// The `Atomics` object provides atomic operations as static methods.
2397/// They are used with `SharedArrayBuffer` objects.
2398///
2399/// The Atomic operations are installed on an `Atomics` module. Unlike
2400/// the other global objects, `Atomics` is not a constructor. You cannot
2401/// use it with a new operator or invoke the `Atomics` object as a
2402/// function. All properties and methods of `Atomics` are static
2403/// (as is the case with the Math object, for example).
2404/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
2405#[allow(non_snake_case)]
2406pub mod Atomics {
2407 use super::*;
2408
2409 #[wasm_bindgen]
2410 extern "C" {
2411 /// The static `Atomics.add()` method adds a given value at a given
2412 /// position in the array and returns the old value at that position.
2413 /// This atomic operation guarantees that no other write happens
2414 /// until the modified value is written back.
2415 ///
2416 /// You should use `add_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2417 ///
2418 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2419 #[wasm_bindgen(js_namespace = Atomics, catch)]
2420 pub fn add<T: TypedArray = Int32Array>(
2421 typed_array: &T,
2422 index: u32,
2423 value: i32,
2424 ) -> Result<i32, JsValue>;
2425
2426 /// The static `Atomics.add()` method adds a given value at a given
2427 /// position in the array and returns the old value at that position.
2428 /// This atomic operation guarantees that no other write happens
2429 /// until the modified value is written back.
2430 ///
2431 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2432 ///
2433 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2434 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = add)]
2435 pub fn add_bigint<T: TypedArray = Int32Array>(
2436 typed_array: &T,
2437 index: u32,
2438 value: i64,
2439 ) -> Result<i64, JsValue>;
2440
2441 /// The static `Atomics.and()` method computes a bitwise AND with a given
2442 /// value at a given position in the array, and returns the old value
2443 /// at that position.
2444 /// This atomic operation guarantees that no other write happens
2445 /// until the modified value is written back.
2446 ///
2447 /// You should use `and_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2448 ///
2449 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2450 #[wasm_bindgen(js_namespace = Atomics, catch)]
2451 pub fn and<T: TypedArray = Int32Array>(
2452 typed_array: &T,
2453 index: u32,
2454 value: i32,
2455 ) -> Result<i32, JsValue>;
2456
2457 /// The static `Atomics.and()` method computes a bitwise AND with a given
2458 /// value at a given position in the array, and returns the old value
2459 /// at that position.
2460 /// This atomic operation guarantees that no other write happens
2461 /// until the modified value is written back.
2462 ///
2463 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2464 ///
2465 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2466 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = and)]
2467 pub fn and_bigint<T: TypedArray = Int32Array>(
2468 typed_array: &T,
2469 index: u32,
2470 value: i64,
2471 ) -> Result<i64, JsValue>;
2472
2473 /// The static `Atomics.compareExchange()` method exchanges a given
2474 /// replacement value at a given position in the array, if a given expected
2475 /// value equals the old value. It returns the old value at that position
2476 /// whether it was equal to the expected value or not.
2477 /// This atomic operation guarantees that no other write happens
2478 /// until the modified value is written back.
2479 ///
2480 /// You should use `compare_exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2481 ///
2482 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2483 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2484 pub fn compare_exchange<T: TypedArray = Int32Array>(
2485 typed_array: &T,
2486 index: u32,
2487 expected_value: i32,
2488 replacement_value: i32,
2489 ) -> Result<i32, JsValue>;
2490
2491 /// The static `Atomics.compareExchange()` method exchanges a given
2492 /// replacement value at a given position in the array, if a given expected
2493 /// value equals the old value. It returns the old value at that position
2494 /// whether it was equal to the expected value or not.
2495 /// This atomic operation guarantees that no other write happens
2496 /// until the modified value is written back.
2497 ///
2498 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2499 ///
2500 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2501 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2502 pub fn compare_exchange_bigint<T: TypedArray = Int32Array>(
2503 typed_array: &T,
2504 index: u32,
2505 expected_value: i64,
2506 replacement_value: i64,
2507 ) -> Result<i64, JsValue>;
2508
2509 /// The static `Atomics.exchange()` method stores a given value at a given
2510 /// position in the array and returns the old value at that position.
2511 /// This atomic operation guarantees that no other write happens
2512 /// until the modified value is written back.
2513 ///
2514 /// You should use `exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2515 ///
2516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2517 #[wasm_bindgen(js_namespace = Atomics, catch)]
2518 pub fn exchange<T: TypedArray = Int32Array>(
2519 typed_array: &T,
2520 index: u32,
2521 value: i32,
2522 ) -> Result<i32, JsValue>;
2523
2524 /// The static `Atomics.exchange()` method stores a given value at a given
2525 /// position in the array and returns the old value at that position.
2526 /// This atomic operation guarantees that no other write happens
2527 /// until the modified value is written back.
2528 ///
2529 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2530 ///
2531 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2532 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = exchange)]
2533 pub fn exchange_bigint<T: TypedArray = Int32Array>(
2534 typed_array: &T,
2535 index: u32,
2536 value: i64,
2537 ) -> Result<i64, JsValue>;
2538
2539 /// The static `Atomics.isLockFree()` method is used to determine
2540 /// whether to use locks or atomic operations. It returns true,
2541 /// if the given size is one of the `BYTES_PER_ELEMENT` property
2542 /// of integer `TypedArray` types.
2543 ///
2544 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree)
2545 #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)]
2546 pub fn is_lock_free(size: u32) -> bool;
2547
2548 /// The static `Atomics.load()` method returns a value at a given
2549 /// position in the array.
2550 ///
2551 /// You should use `load_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2552 ///
2553 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2554 #[wasm_bindgen(js_namespace = Atomics, catch)]
2555 pub fn load<T: TypedArray = Int32Array>(
2556 typed_array: &T,
2557 index: u32,
2558 ) -> Result<i32, JsValue>;
2559
2560 /// The static `Atomics.load()` method returns a value at a given
2561 /// position in the array.
2562 ///
2563 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2564 ///
2565 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2566 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = load)]
2567 pub fn load_bigint<T: TypedArray = Int32Array>(
2568 typed_array: &T,
2569 index: i64,
2570 ) -> Result<i64, JsValue>;
2571
2572 /// The static `Atomics.notify()` method notifies up some agents that
2573 /// are sleeping in the wait queue.
2574 /// Note: This operation works with a shared `Int32Array` only.
2575 /// If `count` is not provided, notifies all the agents in the queue.
2576 ///
2577 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2578 #[wasm_bindgen(js_namespace = Atomics, catch)]
2579 pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>;
2580
2581 /// The static `Atomics.notify()` method notifies up some agents that
2582 /// are sleeping in the wait queue.
2583 /// Note: This operation works with a shared `Int32Array` only.
2584 /// If `count` is not provided, notifies all the agents in the queue.
2585 ///
2586 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2587 #[wasm_bindgen(js_namespace = Atomics, catch)]
2588 pub fn notify_bigint(typed_array: &BigInt64Array, index: u32) -> Result<u32, JsValue>;
2589
2590 /// Notifies up to `count` agents in the wait queue.
2591 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2592 pub fn notify_with_count(
2593 typed_array: &Int32Array,
2594 index: u32,
2595 count: u32,
2596 ) -> Result<u32, JsValue>;
2597
2598 /// Notifies up to `count` agents in the wait queue.
2599 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2600 pub fn notify_bigint_with_count(
2601 typed_array: &BigInt64Array,
2602 index: u32,
2603 count: u32,
2604 ) -> Result<u32, JsValue>;
2605
2606 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2607 /// at a given position in the array, and returns the old value at that position.
2608 /// This atomic operation guarantees that no other write happens
2609 /// until the modified value is written back.
2610 ///
2611 /// You should use `or_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2612 ///
2613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2614 #[wasm_bindgen(js_namespace = Atomics, catch)]
2615 pub fn or<T: TypedArray = Int32Array>(
2616 typed_array: &T,
2617 index: u32,
2618 value: i32,
2619 ) -> Result<i32, JsValue>;
2620
2621 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2622 /// at a given position in the array, and returns the old value at that position.
2623 /// This atomic operation guarantees that no other write happens
2624 /// until the modified value is written back.
2625 ///
2626 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2627 ///
2628 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2629 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = or)]
2630 pub fn or_bigint<T: TypedArray = Int32Array>(
2631 typed_array: &T,
2632 index: u32,
2633 value: i64,
2634 ) -> Result<i64, JsValue>;
2635
2636 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2637 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2638 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2639 /// current thread.
2640 ///
2641 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2642 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2643 /// per Intel's optimization manual. It could be a no-op in certain platforms.
2644 ///
2645 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2646 ///
2647 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2648 #[wasm_bindgen(js_namespace = Atomics)]
2649 pub fn pause();
2650
2651 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2652 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2653 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2654 /// current thread.
2655 ///
2656 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2657 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2658 /// per Intel's optimization manual. It could be a no-op in certain platforms.
2659 ///
2660 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2661 ///
2662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2663 #[wasm_bindgen(js_namespace = Atomics)]
2664 pub fn pause_with_hint(duration_hint: u32);
2665
2666 /// The static `Atomics.store()` method stores a given value at the given
2667 /// position in the array and returns that value.
2668 ///
2669 /// You should use `store_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2670 ///
2671 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2672 #[wasm_bindgen(js_namespace = Atomics, catch)]
2673 pub fn store<T: TypedArray = Int32Array>(
2674 typed_array: &T,
2675 index: u32,
2676 value: i32,
2677 ) -> Result<i32, JsValue>;
2678
2679 /// The static `Atomics.store()` method stores a given value at the given
2680 /// position in the array and returns that value.
2681 ///
2682 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2683 ///
2684 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2685 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = store)]
2686 pub fn store_bigint<T: TypedArray = Int32Array>(
2687 typed_array: &T,
2688 index: u32,
2689 value: i64,
2690 ) -> Result<i64, JsValue>;
2691
2692 /// The static `Atomics.sub()` method subtracts a given value at a
2693 /// given position in the array and returns the old value at that position.
2694 /// This atomic operation guarantees that no other write happens
2695 /// until the modified value is written back.
2696 ///
2697 /// You should use `sub_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2698 ///
2699 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2700 #[wasm_bindgen(js_namespace = Atomics, catch)]
2701 pub fn sub<T: TypedArray = Int32Array>(
2702 typed_array: &T,
2703 index: u32,
2704 value: i32,
2705 ) -> Result<i32, JsValue>;
2706
2707 /// The static `Atomics.sub()` method subtracts a given value at a
2708 /// given position in the array and returns the old value at that position.
2709 /// This atomic operation guarantees that no other write happens
2710 /// until the modified value is written back.
2711 ///
2712 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2713 ///
2714 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2715 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = sub)]
2716 pub fn sub_bigint<T: TypedArray = Int32Array>(
2717 typed_array: &T,
2718 index: u32,
2719 value: i64,
2720 ) -> Result<i64, JsValue>;
2721
2722 /// The static `Atomics.wait()` method verifies that a given
2723 /// position in an `Int32Array` still contains a given value
2724 /// and if so sleeps, awaiting a wakeup or a timeout.
2725 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2726 /// Note: This operation only works with a shared `Int32Array`
2727 /// and may not be allowed on the main thread.
2728 ///
2729 /// You should use `wait_bigint` to operate on a `BigInt64Array`.
2730 ///
2731 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2732 #[wasm_bindgen(js_namespace = Atomics, catch)]
2733 pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>;
2734
2735 /// The static `Atomics.wait()` method verifies that a given
2736 /// position in an `BigInt64Array` still contains a given value
2737 /// and if so sleeps, awaiting a wakeup or a timeout.
2738 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2739 /// Note: This operation only works with a shared `BigInt64Array`
2740 /// and may not be allowed on the main thread.
2741 ///
2742 /// You should use `wait` to operate on a `Int32Array`.
2743 ///
2744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2745 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2746 pub fn wait_bigint(
2747 typed_array: &BigInt64Array,
2748 index: u32,
2749 value: i64,
2750 ) -> Result<JsString, JsValue>;
2751
2752 /// Like `wait()`, but with timeout
2753 ///
2754 /// You should use `wait_with_timeout_bigint` to operate on a `BigInt64Array`.
2755 ///
2756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2757 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2758 pub fn wait_with_timeout(
2759 typed_array: &Int32Array,
2760 index: u32,
2761 value: i32,
2762 timeout: f64,
2763 ) -> Result<JsString, JsValue>;
2764
2765 /// Like `wait()`, but with timeout
2766 ///
2767 /// You should use `wait_with_timeout` to operate on a `Int32Array`.
2768 ///
2769 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2770 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2771 pub fn wait_with_timeout_bigint(
2772 typed_array: &BigInt64Array,
2773 index: u32,
2774 value: i64,
2775 timeout: f64,
2776 ) -> Result<JsString, JsValue>;
2777
2778 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2779 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2780 /// wakeup or a timeout. It returns an object with two properties. The first
2781 /// property `async` is a boolean which if true indicates that the second
2782 /// property `value` is a promise. If `async` is false then value is a string
2783 /// whether equal to either "not-equal" or "timed-out".
2784 /// Note: This operation only works with a shared `Int32Array` and may be used
2785 /// on the main thread.
2786 ///
2787 /// You should use `wait_async_bigint` to operate on a `BigInt64Array`.
2788 ///
2789 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2790 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2791 pub fn wait_async(
2792 typed_array: &Int32Array,
2793 index: u32,
2794 value: i32,
2795 ) -> Result<Object, JsValue>;
2796
2797 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2798 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2799 /// wakeup or a timeout. It returns an object with two properties. The first
2800 /// property `async` is a boolean which if true indicates that the second
2801 /// property `value` is a promise. If `async` is false then value is a string
2802 /// whether equal to either "not-equal" or "timed-out".
2803 /// Note: This operation only works with a shared `BigInt64Array` and may be used
2804 /// on the main thread.
2805 ///
2806 /// You should use `wait_async` to operate on a `Int32Array`.
2807 ///
2808 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2809 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2810 pub fn wait_async_bigint(
2811 typed_array: &BigInt64Array,
2812 index: u32,
2813 value: i64,
2814 ) -> Result<Object, JsValue>;
2815
2816 /// Like `waitAsync()`, but with timeout
2817 ///
2818 /// You should use `wait_async_with_timeout_bigint` to operate on a `BigInt64Array`.
2819 ///
2820 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2821 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2822 pub fn wait_async_with_timeout(
2823 typed_array: &Int32Array,
2824 index: u32,
2825 value: i32,
2826 timeout: f64,
2827 ) -> Result<Object, JsValue>;
2828
2829 /// Like `waitAsync()`, but with timeout
2830 ///
2831 /// You should use `wait_async_with_timeout` to operate on a `Int32Array`.
2832 ///
2833 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2834 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2835 pub fn wait_async_with_timeout_bigint(
2836 typed_array: &BigInt64Array,
2837 index: u32,
2838 value: i64,
2839 timeout: f64,
2840 ) -> Result<Object, JsValue>;
2841
2842 /// The static `Atomics.xor()` method computes a bitwise XOR
2843 /// with a given value at a given position in the array,
2844 /// and returns the old value at that position.
2845 /// This atomic operation guarantees that no other write happens
2846 /// until the modified value is written back.
2847 ///
2848 /// You should use `xor_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2849 ///
2850 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2851 #[wasm_bindgen(js_namespace = Atomics, catch)]
2852 pub fn xor<T: TypedArray = Int32Array>(
2853 typed_array: &T,
2854 index: u32,
2855 value: i32,
2856 ) -> Result<i32, JsValue>;
2857
2858 /// The static `Atomics.xor()` method computes a bitwise XOR
2859 /// with a given value at a given position in the array,
2860 /// and returns the old value at that position.
2861 /// This atomic operation guarantees that no other write happens
2862 /// until the modified value is written back.
2863 ///
2864 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2865 ///
2866 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2867 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = xor)]
2868 pub fn xor_bigint<T: TypedArray = Int32Array>(
2869 typed_array: &T,
2870 index: u32,
2871 value: i64,
2872 ) -> Result<i64, JsValue>;
2873 }
2874}
2875
2876// BigInt
2877#[wasm_bindgen]
2878extern "C" {
2879 #[wasm_bindgen(extends = Object, is_type_of = |v| v.is_bigint(), typescript_type = "bigint")]
2880 #[derive(Clone, PartialEq, Eq)]
2881 pub type BigInt;
2882
2883 #[wasm_bindgen(catch, js_name = BigInt)]
2884 fn new_bigint(value: &JsValue) -> Result<BigInt, Error>;
2885
2886 #[wasm_bindgen(js_name = BigInt)]
2887 fn new_bigint_unchecked(value: &JsValue) -> BigInt;
2888
2889 /// Clamps a BigInt value to a signed integer value, and returns that value.
2890 ///
2891 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)
2892 #[wasm_bindgen(static_method_of = BigInt, js_name = asIntN)]
2893 pub fn as_int_n(bits: f64, bigint: &BigInt) -> BigInt;
2894
2895 /// Clamps a BigInt value to an unsigned integer value, and returns that value.
2896 ///
2897 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)
2898 #[wasm_bindgen(static_method_of = BigInt, js_name = asUintN)]
2899 pub fn as_uint_n(bits: f64, bigint: &BigInt) -> BigInt;
2900
2901 /// 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.
2902 ///
2903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
2904 #[cfg(not(js_sys_unstable_apis))]
2905 #[wasm_bindgen(method, js_name = toLocaleString)]
2906 pub fn to_locale_string(this: &BigInt, locales: &JsValue, options: &JsValue) -> JsString;
2907
2908 /// 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.
2909 ///
2910 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
2911 #[cfg(js_sys_unstable_apis)]
2912 #[wasm_bindgen(method, js_name = toLocaleString)]
2913 pub fn to_locale_string(
2914 this: &BigInt,
2915 locales: &[JsString],
2916 options: &Intl::NumberFormatOptions,
2917 ) -> JsString;
2918
2919 // Next major: deprecate
2920 /// 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.
2921 ///
2922 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
2923 #[wasm_bindgen(catch, method, js_name = toString)]
2924 pub fn to_string(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
2925
2926 /// Returns a string representing this BigInt value in the specified radix (base).
2927 ///
2928 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
2929 #[cfg(js_sys_unstable_apis)]
2930 #[wasm_bindgen(catch, method, js_name = toString)]
2931 pub fn to_string_with_radix(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
2932
2933 #[wasm_bindgen(method, js_name = toString)]
2934 fn to_string_unchecked(this: &BigInt, radix: u8) -> String;
2935
2936 /// Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method.
2937 ///
2938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)
2939 #[wasm_bindgen(method, js_name = valueOf)]
2940 pub fn value_of(this: &BigInt, radix: u8) -> BigInt;
2941}
2942
2943impl BigInt {
2944 /// Creates a new BigInt value.
2945 ///
2946 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)
2947 #[inline]
2948 pub fn new(value: &JsValue) -> Result<BigInt, Error> {
2949 new_bigint(value)
2950 }
2951
2952 /// Applies the binary `/` JS operator on two `BigInt`s, catching and returning any `RangeError` thrown.
2953 ///
2954 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division)
2955 pub fn checked_div(&self, rhs: &Self) -> Result<Self, RangeError> {
2956 let result = JsValue::as_ref(self).checked_div(JsValue::as_ref(rhs));
2957
2958 if result.is_instance_of::<RangeError>() {
2959 Err(result.unchecked_into())
2960 } else {
2961 Ok(result.unchecked_into())
2962 }
2963 }
2964
2965 /// Applies the binary `**` JS operator on the two `BigInt`s.
2966 ///
2967 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
2968 #[inline]
2969 pub fn pow(&self, rhs: &Self) -> Self {
2970 JsValue::as_ref(self)
2971 .pow(JsValue::as_ref(rhs))
2972 .unchecked_into()
2973 }
2974
2975 /// Returns a tuple of this [`BigInt`]'s absolute value along with a
2976 /// [`bool`] indicating whether the [`BigInt`] was negative.
2977 fn abs(&self) -> (Self, bool) {
2978 if self < &BigInt::from(0) {
2979 (-self, true)
2980 } else {
2981 (self.clone(), false)
2982 }
2983 }
2984}
2985
2986macro_rules! bigint_from {
2987 ($($x:ident)*) => ($(
2988 impl From<$x> for BigInt {
2989 #[inline]
2990 fn from(x: $x) -> BigInt {
2991 new_bigint_unchecked(&JsValue::from(x))
2992 }
2993 }
2994
2995 impl PartialEq<$x> for BigInt {
2996 #[inline]
2997 fn eq(&self, other: &$x) -> bool {
2998 JsValue::from(self) == JsValue::from(BigInt::from(*other))
2999 }
3000 }
3001 )*)
3002}
3003bigint_from!(i8 u8 i16 u16 i32 u32 isize usize);
3004
3005macro_rules! bigint_from_big {
3006 ($($x:ident)*) => ($(
3007 impl From<$x> for BigInt {
3008 #[inline]
3009 fn from(x: $x) -> BigInt {
3010 JsValue::from(x).unchecked_into()
3011 }
3012 }
3013
3014 impl PartialEq<$x> for BigInt {
3015 #[inline]
3016 fn eq(&self, other: &$x) -> bool {
3017 self == &BigInt::from(*other)
3018 }
3019 }
3020
3021 impl TryFrom<BigInt> for $x {
3022 type Error = BigInt;
3023
3024 #[inline]
3025 fn try_from(x: BigInt) -> Result<Self, BigInt> {
3026 Self::try_from(JsValue::from(x)).map_err(JsCast::unchecked_into)
3027 }
3028 }
3029 )*)
3030}
3031bigint_from_big!(i64 u64 i128 u128);
3032
3033impl PartialEq<Number> for BigInt {
3034 #[inline]
3035 fn eq(&self, other: &Number) -> bool {
3036 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
3037 }
3038}
3039
3040impl Not for &BigInt {
3041 type Output = BigInt;
3042
3043 #[inline]
3044 fn not(self) -> Self::Output {
3045 JsValue::as_ref(self).bit_not().unchecked_into()
3046 }
3047}
3048
3049forward_deref_unop!(impl Not, not for BigInt);
3050forward_js_unop!(impl Neg, neg for BigInt);
3051forward_js_binop!(impl BitAnd, bitand for BigInt);
3052forward_js_binop!(impl BitOr, bitor for BigInt);
3053forward_js_binop!(impl BitXor, bitxor for BigInt);
3054forward_js_binop!(impl Shl, shl for BigInt);
3055forward_js_binop!(impl Shr, shr for BigInt);
3056forward_js_binop!(impl Add, add for BigInt);
3057forward_js_binop!(impl Sub, sub for BigInt);
3058forward_js_binop!(impl Div, div for BigInt);
3059forward_js_binop!(impl Mul, mul for BigInt);
3060forward_js_binop!(impl Rem, rem for BigInt);
3061sum_product!(BigInt);
3062
3063partialord_ord!(BigInt);
3064
3065impl Default for BigInt {
3066 fn default() -> Self {
3067 BigInt::from(i32::default())
3068 }
3069}
3070
3071impl FromStr for BigInt {
3072 type Err = Error;
3073
3074 #[inline]
3075 fn from_str(s: &str) -> Result<Self, Self::Err> {
3076 BigInt::new(&s.into())
3077 }
3078}
3079
3080impl fmt::Debug for BigInt {
3081 #[inline]
3082 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3083 fmt::Display::fmt(self, f)
3084 }
3085}
3086
3087impl fmt::Display for BigInt {
3088 #[inline]
3089 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3090 let (abs, is_neg) = self.abs();
3091 f.pad_integral(!is_neg, "", &abs.to_string_unchecked(10))
3092 }
3093}
3094
3095impl fmt::Binary for BigInt {
3096 #[inline]
3097 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3098 let (abs, is_neg) = self.abs();
3099 f.pad_integral(!is_neg, "0b", &abs.to_string_unchecked(2))
3100 }
3101}
3102
3103impl fmt::Octal for BigInt {
3104 #[inline]
3105 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3106 let (abs, is_neg) = self.abs();
3107 f.pad_integral(!is_neg, "0o", &abs.to_string_unchecked(8))
3108 }
3109}
3110
3111impl fmt::LowerHex for BigInt {
3112 #[inline]
3113 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3114 let (abs, is_neg) = self.abs();
3115 f.pad_integral(!is_neg, "0x", &abs.to_string_unchecked(16))
3116 }
3117}
3118
3119impl fmt::UpperHex for BigInt {
3120 #[inline]
3121 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3122 let (abs, is_neg) = self.abs();
3123 let mut s: String = abs.to_string_unchecked(16);
3124 s.make_ascii_uppercase();
3125 f.pad_integral(!is_neg, "0x", &s)
3126 }
3127}
3128
3129// Boolean
3130#[wasm_bindgen]
3131extern "C" {
3132 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
3133 #[derive(Clone, PartialEq, Eq)]
3134 pub type Boolean;
3135
3136 /// The `Boolean()` constructor creates an object wrapper for a boolean value.
3137 ///
3138 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
3139 #[cfg(not(js_sys_unstable_apis))]
3140 #[wasm_bindgen(constructor)]
3141 #[deprecated(note = "recommended to use `Boolean::from` instead")]
3142 #[allow(deprecated)]
3143 pub fn new(value: &JsValue) -> Boolean;
3144
3145 /// The `valueOf()` method returns the primitive value of a `Boolean` object.
3146 ///
3147 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf)
3148 #[wasm_bindgen(method, js_name = valueOf)]
3149 pub fn value_of(this: &Boolean) -> bool;
3150}
3151
3152impl UpcastFrom<bool> for Boolean {}
3153impl UpcastFrom<Boolean> for bool {}
3154
3155impl Boolean {
3156 /// Typed Boolean true constant.
3157 pub const TRUE: Boolean = unsafe { core::mem::transmute(JsValue::TRUE) };
3158
3159 /// Typed Boolean false constant.
3160 pub const FALSE: Boolean = unsafe { core::mem::transmute(JsValue::FALSE) };
3161}
3162
3163impl From<bool> for Boolean {
3164 #[inline]
3165 fn from(b: bool) -> Boolean {
3166 Boolean::unchecked_from_js(JsValue::from(b))
3167 }
3168}
3169
3170impl From<Boolean> for bool {
3171 #[inline]
3172 fn from(b: Boolean) -> bool {
3173 b.value_of()
3174 }
3175}
3176
3177impl PartialEq<bool> for Boolean {
3178 #[inline]
3179 fn eq(&self, other: &bool) -> bool {
3180 self.value_of() == *other
3181 }
3182}
3183
3184impl fmt::Debug for Boolean {
3185 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3186 fmt::Debug::fmt(&self.value_of(), f)
3187 }
3188}
3189
3190impl fmt::Display for Boolean {
3191 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3192 fmt::Display::fmt(&self.value_of(), f)
3193 }
3194}
3195
3196impl Default for Boolean {
3197 fn default() -> Self {
3198 Self::from(bool::default())
3199 }
3200}
3201
3202impl Not for &Boolean {
3203 type Output = Boolean;
3204
3205 #[inline]
3206 fn not(self) -> Self::Output {
3207 (!JsValue::as_ref(self)).into()
3208 }
3209}
3210
3211forward_deref_unop!(impl Not, not for Boolean);
3212
3213partialord_ord!(Boolean);
3214
3215// DataView
3216#[wasm_bindgen]
3217extern "C" {
3218 #[wasm_bindgen(extends = Object, typescript_type = "DataView")]
3219 #[derive(Clone, Debug, PartialEq, Eq)]
3220 pub type DataView;
3221
3222 /// The `DataView` view provides a low-level interface for reading and
3223 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3224 /// platform's endianness.
3225 ///
3226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3227 #[wasm_bindgen(constructor)]
3228 pub fn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView;
3229
3230 /// The `DataView` view provides a low-level interface for reading and
3231 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3232 /// platform's endianness.
3233 ///
3234 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3235 #[wasm_bindgen(constructor)]
3236 pub fn new_with_shared_array_buffer(
3237 buffer: &SharedArrayBuffer,
3238 byteOffset: usize,
3239 byteLength: usize,
3240 ) -> DataView;
3241
3242 /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
3243 ///
3244 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer)
3245 #[wasm_bindgen(method, getter)]
3246 pub fn buffer(this: &DataView) -> ArrayBuffer;
3247
3248 /// The length (in bytes) of this view from the start of its ArrayBuffer.
3249 /// Fixed at construction time and thus read only.
3250 ///
3251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength)
3252 #[wasm_bindgen(method, getter, js_name = byteLength)]
3253 pub fn byte_length(this: &DataView) -> usize;
3254
3255 /// The offset (in bytes) of this view from the start of its ArrayBuffer.
3256 /// Fixed at construction time and thus read only.
3257 ///
3258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset)
3259 #[wasm_bindgen(method, getter, js_name = byteOffset)]
3260 pub fn byte_offset(this: &DataView) -> usize;
3261
3262 /// The `getInt8()` method gets a signed 8-bit integer (byte) at the
3263 /// specified byte offset from the start of the DataView.
3264 ///
3265 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8)
3266 #[wasm_bindgen(method, js_name = getInt8)]
3267 pub fn get_int8(this: &DataView, byte_offset: usize) -> i8;
3268
3269 /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified
3270 /// byte offset from the start of the DataView.
3271 ///
3272 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8)
3273 #[wasm_bindgen(method, js_name = getUint8)]
3274 pub fn get_uint8(this: &DataView, byte_offset: usize) -> u8;
3275
3276 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3277 /// byte offset from the start of the DataView.
3278 ///
3279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3280 #[wasm_bindgen(method, js_name = getInt16)]
3281 pub fn get_int16(this: &DataView, byte_offset: usize) -> i16;
3282
3283 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3284 /// byte offset from the start of the DataView.
3285 ///
3286 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3287 #[wasm_bindgen(method, js_name = getInt16)]
3288 pub fn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16;
3289
3290 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3291 /// byte offset from the start of the view.
3292 ///
3293 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3294 #[wasm_bindgen(method, js_name = getUint16)]
3295 pub fn get_uint16(this: &DataView, byte_offset: usize) -> u16;
3296
3297 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3298 /// byte offset from the start of the view.
3299 ///
3300 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3301 #[wasm_bindgen(method, js_name = getUint16)]
3302 pub fn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16;
3303
3304 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3305 /// byte offset from the start of the DataView.
3306 ///
3307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3308 #[wasm_bindgen(method, js_name = getInt32)]
3309 pub fn get_int32(this: &DataView, byte_offset: usize) -> i32;
3310
3311 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3312 /// byte offset from the start of the DataView.
3313 ///
3314 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3315 #[wasm_bindgen(method, js_name = getInt32)]
3316 pub fn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32;
3317
3318 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3319 /// byte offset from the start of the view.
3320 ///
3321 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3322 #[wasm_bindgen(method, js_name = getUint32)]
3323 pub fn get_uint32(this: &DataView, byte_offset: usize) -> u32;
3324
3325 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3326 /// byte offset from the start of the view.
3327 ///
3328 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3329 #[wasm_bindgen(method, js_name = getUint32)]
3330 pub fn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32;
3331
3332 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3333 /// byte offset from the start of the DataView.
3334 ///
3335 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3336 #[wasm_bindgen(method, js_name = getFloat32)]
3337 pub fn get_float32(this: &DataView, byte_offset: usize) -> f32;
3338
3339 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3340 /// byte offset from the start of the DataView.
3341 ///
3342 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3343 #[wasm_bindgen(method, js_name = getFloat32)]
3344 pub fn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32;
3345
3346 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3347 /// byte offset from the start of the DataView.
3348 ///
3349 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3350 #[wasm_bindgen(method, js_name = getFloat64)]
3351 pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
3352
3353 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3354 /// byte offset from the start of the DataView.
3355 ///
3356 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3357 #[wasm_bindgen(method, js_name = getFloat64)]
3358 pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
3359
3360 /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
3361 /// specified byte offset from the start of the DataView.
3362 ///
3363 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
3364 #[wasm_bindgen(method, js_name = setInt8)]
3365 pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
3366
3367 /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
3368 /// specified byte offset from the start of the DataView.
3369 ///
3370 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
3371 #[wasm_bindgen(method, js_name = setUint8)]
3372 pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
3373
3374 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3375 /// specified byte offset from the start of the DataView.
3376 ///
3377 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3378 #[wasm_bindgen(method, js_name = setInt16)]
3379 pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
3380
3381 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3382 /// specified byte offset from the start of the DataView.
3383 ///
3384 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3385 #[wasm_bindgen(method, js_name = setInt16)]
3386 pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
3387
3388 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3389 /// specified byte offset from the start of the DataView.
3390 ///
3391 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3392 #[wasm_bindgen(method, js_name = setUint16)]
3393 pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
3394
3395 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3396 /// specified byte offset from the start of the DataView.
3397 ///
3398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3399 #[wasm_bindgen(method, js_name = setUint16)]
3400 pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
3401
3402 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3403 /// specified byte offset from the start of the DataView.
3404 ///
3405 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3406 #[wasm_bindgen(method, js_name = setInt32)]
3407 pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
3408
3409 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3410 /// specified byte offset from the start of the DataView.
3411 ///
3412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3413 #[wasm_bindgen(method, js_name = setInt32)]
3414 pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
3415
3416 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3417 /// specified byte offset from the start of the DataView.
3418 ///
3419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3420 #[wasm_bindgen(method, js_name = setUint32)]
3421 pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
3422
3423 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3424 /// specified byte offset from the start of the DataView.
3425 ///
3426 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3427 #[wasm_bindgen(method, js_name = setUint32)]
3428 pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
3429
3430 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3431 /// specified byte offset from the start of the DataView.
3432 ///
3433 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3434 #[wasm_bindgen(method, js_name = setFloat32)]
3435 pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
3436
3437 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3438 /// specified byte offset from the start of the DataView.
3439 ///
3440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3441 #[wasm_bindgen(method, js_name = setFloat32)]
3442 pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
3443
3444 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3445 /// specified byte offset from the start of the DataView.
3446 ///
3447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3448 #[wasm_bindgen(method, js_name = setFloat64)]
3449 pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
3450
3451 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3452 /// specified byte offset from the start of the DataView.
3453 ///
3454 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3455 #[wasm_bindgen(method, js_name = setFloat64)]
3456 pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
3457}
3458
3459// Error
3460#[wasm_bindgen]
3461extern "C" {
3462 #[wasm_bindgen(extends = Object, typescript_type = "Error")]
3463 #[derive(Clone, Debug, PartialEq, Eq)]
3464 pub type Error;
3465
3466 /// The Error constructor creates an error object.
3467 /// Instances of Error objects are thrown when runtime errors occur.
3468 /// The Error object can also be used as a base object for user-defined exceptions.
3469 /// See below for standard built-in error types.
3470 ///
3471 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
3472 #[wasm_bindgen(constructor)]
3473 pub fn new(message: &str) -> Error;
3474 #[wasm_bindgen(constructor)]
3475 pub fn new_with_options(message: &str, options: &Object) -> Error;
3476
3477 /// The cause property is the underlying cause of the error.
3478 /// Usually this is used to add context to re-thrown errors.
3479 ///
3480 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors)
3481 #[wasm_bindgen(method, getter)]
3482 pub fn cause(this: &Error) -> JsValue;
3483 #[wasm_bindgen(method, setter)]
3484 pub fn set_cause(this: &Error, cause: &JsValue);
3485
3486 /// The message property is a human-readable description of the error.
3487 ///
3488 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
3489 #[wasm_bindgen(method, getter)]
3490 pub fn message(this: &Error) -> JsString;
3491 #[wasm_bindgen(method, setter)]
3492 pub fn set_message(this: &Error, message: &str);
3493
3494 /// The name property represents a name for the type of error. The initial value is "Error".
3495 ///
3496 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
3497 #[wasm_bindgen(method, getter)]
3498 pub fn name(this: &Error) -> JsString;
3499 #[wasm_bindgen(method, setter)]
3500 pub fn set_name(this: &Error, name: &str);
3501
3502 /// The `toString()` method returns a string representing the specified Error object
3503 ///
3504 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
3505 #[cfg(not(js_sys_unstable_apis))]
3506 #[wasm_bindgen(method, js_name = toString)]
3507 pub fn to_string(this: &Error) -> JsString;
3508}
3509
3510partialord_ord!(JsString);
3511
3512// EvalError
3513#[wasm_bindgen]
3514extern "C" {
3515 #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
3516 #[derive(Clone, Debug, PartialEq, Eq)]
3517 pub type EvalError;
3518
3519 /// The `EvalError` object indicates an error regarding the global eval() function. This
3520 /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
3521 /// compatibility.
3522 ///
3523 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
3524 #[wasm_bindgen(constructor)]
3525 pub fn new(message: &str) -> EvalError;
3526}
3527
3528#[wasm_bindgen]
3529extern "C" {
3530 #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, no_upcast, typescript_type = "Function")]
3531 #[derive(Clone, Debug, PartialEq, Eq)]
3532 /// `Function` represents any generic Function in JS, by treating all arguments as `JsValue`.
3533 ///
3534 /// It takes a generic parameter of phantom type `fn (Arg1, ..., Argn) -> Ret` which
3535 /// is used to type the JS function. For example, `Function<fn () -> Number>` represents
3536 /// a function taking no arguments that returns a number.
3537 ///
3538 /// The 8 generic argument parameters (`Arg1` through `Arg8`) are the argument
3539 /// types. Arguments not provided enable strict arity checking at compile time.
3540 ///
3541 /// A void function is represented by `fn (Arg) -> Undefined`, and **not** the `()` unit
3542 /// type. This is because generics must be based on JS values in the JS generic type system.
3543 ///
3544 /// _The default without any parameters is as a void function - no arguments, `Undefined` return._
3545 ///
3546 /// _The default generic for `Function` is `fn (JsValue, JsValue, ...) -> JsValue`,
3547 /// representing any function, since all functions safely upcast into this function._
3548 ///
3549 /// ### Arity Enforcement
3550 ///
3551 /// It is not possible to use `call4` or `bind4` on a function that does not have
3552 /// at least 4 arguments — the compiler will reject this because only arguments that
3553 /// are not `None` support the trait bound for `ErasableGeneric`.
3554 ///
3555 /// ### Examples
3556 ///
3557 /// ```ignore
3558 /// // A function taking no args, returning Number
3559 /// let f: Function<Number> = get_some_fn();
3560 ///
3561 /// // A function taking (String, Number) and returning Boolean
3562 /// let f: Function<Boolean, String, Number> = get_some_fn();
3563 ///
3564 /// ### Upcasting
3565 ///
3566 /// To pass a typed `Function` where a different generic Function is expected, `upcast()` may be used
3567 /// to convert into any generic `Function` at zero cost with type-safety.
3568 ///
3569 /// MDN documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3570 pub type Function<
3571 T: JsFunction = fn(
3572 JsValue,
3573 JsValue,
3574 JsValue,
3575 JsValue,
3576 JsValue,
3577 JsValue,
3578 JsValue,
3579 JsValue,
3580 ) -> JsValue,
3581 >;
3582}
3583
3584#[wasm_bindgen]
3585extern "C" {
3586 /// The `Function` constructor creates a new `Function` object. Calling the
3587 /// constructor directly can create functions dynamically, but suffers from
3588 /// security and similar (but far less significant) performance issues
3589 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3590 /// allows executing code in the global scope, prompting better programming
3591 /// habits and allowing for more efficient code minification.
3592 ///
3593 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3594 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3595 #[wasm_bindgen(constructor)]
3596 pub fn new_with_args(args: &str, body: &str) -> Function;
3597
3598 /// The `Function` constructor creates a new `Function` object. Calling the
3599 /// constructor directly can create functions dynamically, but suffers from
3600 /// security and similar (but far less significant) performance issues
3601 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3602 /// allows executing code in the global scope, prompting better programming
3603 /// habits and allowing for more efficient code minification.
3604 ///
3605 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3606 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3607 #[wasm_bindgen(constructor)]
3608 pub fn new_with_args<T: JsFunction = fn() -> JsValue>(args: &str, body: &str) -> Function<T>;
3609
3610 // Next major: deprecate
3611 /// The `Function` constructor creates a new `Function` object. Calling the
3612 /// constructor directly can create functions dynamically, but suffers from
3613 /// security and similar (but far less significant) performance issues
3614 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3615 /// allows executing code in the global scope, prompting better programming
3616 /// habits and allowing for more efficient code minification.
3617 ///
3618 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3619 #[cfg(feature = "unsafe-eval")]
3620 #[wasm_bindgen(constructor)]
3621 pub fn new_with_args_typed<T: JsFunction = fn() -> JsValue>(
3622 args: &str,
3623 body: &str,
3624 ) -> Function<T>;
3625
3626 /// The `Function` constructor creates a new `Function` object. Calling the
3627 /// constructor directly can create functions dynamically, but suffers from
3628 /// security and similar (but far less significant) performance issues
3629 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3630 /// allows executing code in the global scope, prompting better programming
3631 /// habits and allowing for more efficient code minification.
3632 ///
3633 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3634 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3635 #[wasm_bindgen(constructor)]
3636 pub fn new_no_args(body: &str) -> Function;
3637
3638 /// The `Function` constructor creates a new `Function` object. Calling the
3639 /// constructor directly can create functions dynamically, but suffers from
3640 /// security and similar (but far less significant) performance issues
3641 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3642 /// allows executing code in the global scope, prompting better programming
3643 /// habits and allowing for more efficient code minification.
3644 ///
3645 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3646 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3647 #[wasm_bindgen(constructor)]
3648 pub fn new_no_args<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3649
3650 // Next major: deprecate
3651 /// The `Function` constructor creates a new `Function` object.
3652 ///
3653 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3654 #[cfg(feature = "unsafe-eval")]
3655 #[wasm_bindgen(constructor)]
3656 pub fn new_no_args_typed<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3657
3658 /// The `apply()` method calls a function with a given this value, and arguments provided as an array
3659 /// (or an array-like object).
3660 ///
3661 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
3662 #[wasm_bindgen(method, catch)]
3663 pub fn apply<T: JsFunction = fn() -> JsValue>(
3664 this: &Function<T>,
3665 context: &JsValue,
3666 args: &Array,
3667 ) -> Result<<T as JsFunction>::Ret, JsValue>;
3668
3669 // Next major: Deprecate, and separately provide provide impl
3670 /// The `call()` method calls a function with a given this value and
3671 /// arguments provided individually.
3672 ///
3673 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3674 ///
3675 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3676 #[wasm_bindgen(method, catch, js_name = call)]
3677 pub fn call0<Ret: JsGeneric, F: JsFunction<Ret = Ret> = fn() -> JsValue>(
3678 this: &Function<F>,
3679 context: &JsValue,
3680 ) -> Result<Ret, JsValue>;
3681
3682 // Next major: Deprecate, and separately provide provide impl
3683 /// The `call()` method calls a function with a given this value and
3684 /// arguments provided individually.
3685 ///
3686 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3687 ///
3688 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3689 #[wasm_bindgen(method, catch, js_name = call)]
3690 pub fn call1<
3691 Ret: JsGeneric,
3692 Arg1: JsGeneric,
3693 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> = fn(JsValue) -> JsValue,
3694 >(
3695 this: &Function<F>,
3696 context: &JsValue,
3697 arg1: &Arg1,
3698 ) -> Result<Ret, JsValue>;
3699
3700 // Next major: Deprecate, and separately provide provide impl
3701 /// The `call()` method calls a function with a given this value and
3702 /// arguments provided individually.
3703 ///
3704 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3705 ///
3706 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3707 #[wasm_bindgen(method, catch, js_name = call)]
3708 pub fn call2<
3709 Ret: JsGeneric,
3710 Arg1: JsGeneric,
3711 Arg2: JsGeneric,
3712 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> + JsFunction2<Arg2 = Arg2> = fn(
3713 JsValue,
3714 JsValue,
3715 ) -> JsValue,
3716 >(
3717 this: &Function<F>,
3718 context: &JsValue,
3719 arg1: &Arg1,
3720 arg2: &Arg2,
3721 ) -> Result<Ret, JsValue>;
3722
3723 // Next major: Deprecate, and separately provide provide impl
3724 /// The `call()` method calls a function with a given this value and
3725 /// arguments provided individually.
3726 ///
3727 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3728 ///
3729 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3730 #[wasm_bindgen(method, catch, js_name = call)]
3731 pub fn call3<
3732 Ret: JsGeneric,
3733 Arg1: JsGeneric,
3734 Arg2: JsGeneric,
3735 Arg3: JsGeneric,
3736 F: JsFunction<Ret = Ret> + JsFunction3<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
3737 JsValue,
3738 JsValue,
3739 JsValue,
3740 ) -> JsValue,
3741 >(
3742 this: &Function<F>,
3743 context: &JsValue,
3744 arg1: &Arg1,
3745 arg2: &Arg2,
3746 arg3: &Arg3,
3747 ) -> Result<Ret, JsValue>;
3748
3749 // Next major: Deprecate, and separately provide provide impl
3750 /// The `call()` method calls a function with a given this value and
3751 /// arguments provided individually.
3752 ///
3753 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3754 ///
3755 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3756 #[wasm_bindgen(method, catch, js_name = call)]
3757 pub fn call4<
3758 Ret: JsGeneric,
3759 Arg1: JsGeneric,
3760 Arg2: JsGeneric,
3761 Arg3: JsGeneric,
3762 Arg4: JsGeneric,
3763 F: JsFunction<Ret = Ret> + JsFunction4<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
3764 JsValue,
3765 JsValue,
3766 JsValue,
3767 JsValue,
3768 ) -> JsValue,
3769 >(
3770 this: &Function<F>,
3771 context: &JsValue,
3772 arg1: &Arg1,
3773 arg2: &Arg2,
3774 arg3: &Arg3,
3775 arg4: &Arg4,
3776 ) -> Result<Ret, JsValue>;
3777
3778 // Next major: Deprecate, and separately provide provide impl
3779 /// The `call()` method calls a function with a given this value and
3780 /// arguments provided individually.
3781 ///
3782 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3783 ///
3784 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3785 #[wasm_bindgen(method, catch, js_name = call)]
3786 pub fn call5<
3787 Ret: JsGeneric,
3788 Arg1: JsGeneric,
3789 Arg2: JsGeneric,
3790 Arg3: JsGeneric,
3791 Arg4: JsGeneric,
3792 Arg5: JsGeneric,
3793 F: JsFunction<Ret = Ret>
3794 + JsFunction5<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
3795 JsValue,
3796 JsValue,
3797 JsValue,
3798 JsValue,
3799 JsValue,
3800 ) -> JsValue,
3801 >(
3802 this: &Function<F>,
3803 context: &JsValue,
3804 arg1: &Arg1,
3805 arg2: &Arg2,
3806 arg3: &Arg3,
3807 arg4: &Arg4,
3808 arg5: &Arg5,
3809 ) -> Result<Ret, JsValue>;
3810
3811 // Next major: Deprecate, and separately provide provide impl
3812 /// The `call()` method calls a function with a given this value and
3813 /// arguments provided individually.
3814 ///
3815 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3816 ///
3817 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3818 #[wasm_bindgen(method, catch, js_name = call)]
3819 pub fn call6<
3820 Ret: JsGeneric,
3821 Arg1: JsGeneric,
3822 Arg2: JsGeneric,
3823 Arg3: JsGeneric,
3824 Arg4: JsGeneric,
3825 Arg5: JsGeneric,
3826 Arg6: JsGeneric,
3827 F: JsFunction<Ret = Ret>
3828 + JsFunction6<
3829 Arg1 = Arg1,
3830 Arg2 = Arg2,
3831 Arg3 = Arg3,
3832 Arg4 = Arg4,
3833 Arg5 = Arg5,
3834 Arg6 = Arg6,
3835 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
3836 >(
3837 this: &Function<F>,
3838 context: &JsValue,
3839 arg1: &Arg1,
3840 arg2: &Arg2,
3841 arg3: &Arg3,
3842 arg4: &Arg4,
3843 arg5: &Arg5,
3844 arg6: &Arg6,
3845 ) -> Result<Ret, JsValue>;
3846
3847 // Next major: Deprecate, and separately provide provide impl
3848 /// The `call()` method calls a function with a given this value and
3849 /// arguments provided individually.
3850 ///
3851 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3852 ///
3853 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3854 #[wasm_bindgen(method, catch, js_name = call)]
3855 pub fn call7<
3856 Ret: JsGeneric,
3857 Arg1: JsGeneric,
3858 Arg2: JsGeneric,
3859 Arg3: JsGeneric,
3860 Arg4: JsGeneric,
3861 Arg5: JsGeneric,
3862 Arg6: JsGeneric,
3863 Arg7: JsGeneric,
3864 F: JsFunction<Ret = Ret>
3865 + JsFunction7<
3866 Arg1 = Arg1,
3867 Arg2 = Arg2,
3868 Arg3 = Arg3,
3869 Arg4 = Arg4,
3870 Arg5 = Arg5,
3871 Arg6 = Arg6,
3872 Arg7 = Arg7,
3873 > = fn(
3874 JsValue,
3875 JsValue,
3876 JsValue,
3877 JsValue,
3878 JsValue,
3879 JsValue,
3880 JsValue,
3881 ) -> JsValue,
3882 >(
3883 this: &Function<F>,
3884 context: &JsValue,
3885 arg1: &Arg1,
3886 arg2: &Arg2,
3887 arg3: &Arg3,
3888 arg4: &Arg4,
3889 arg5: &Arg5,
3890 arg6: &Arg6,
3891 arg7: &Arg7,
3892 ) -> Result<Ret, JsValue>;
3893
3894 // Next major: Deprecate, and separately provide provide impl
3895 /// The `call()` method calls a function with a given this value and
3896 /// arguments provided individually.
3897 ///
3898 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3899 ///
3900 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3901 #[wasm_bindgen(method, catch, js_name = call)]
3902 pub fn call8<
3903 Ret: JsGeneric,
3904 Arg1: JsGeneric,
3905 Arg2: JsGeneric,
3906 Arg3: JsGeneric,
3907 Arg4: JsGeneric,
3908 Arg5: JsGeneric,
3909 Arg6: JsGeneric,
3910 Arg7: JsGeneric,
3911 Arg8: JsGeneric,
3912 F: JsFunction8<
3913 Ret = Ret,
3914 Arg1 = Arg1,
3915 Arg2 = Arg2,
3916 Arg3 = Arg3,
3917 Arg4 = Arg4,
3918 Arg5 = Arg5,
3919 Arg6 = Arg6,
3920 Arg7 = Arg7,
3921 Arg8 = Arg8,
3922 > = fn(
3923 JsValue,
3924 JsValue,
3925 JsValue,
3926 JsValue,
3927 JsValue,
3928 JsValue,
3929 JsValue,
3930 JsValue,
3931 ) -> JsValue,
3932 >(
3933 this: &Function<F>,
3934 context: &JsValue,
3935 arg1: &Arg1,
3936 arg2: &Arg2,
3937 arg3: &Arg3,
3938 arg4: &Arg4,
3939 arg5: &Arg5,
3940 arg6: &Arg6,
3941 arg7: &Arg7,
3942 arg8: &Arg8,
3943 ) -> Result<Ret, JsValue>;
3944
3945 /// The `call()` method calls a function with a given this value and
3946 /// arguments provided individually.
3947 ///
3948 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3949 ///
3950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3951 #[deprecated]
3952 #[allow(deprecated)]
3953 #[wasm_bindgen(method, catch, js_name = call)]
3954 pub fn call9<
3955 Ret: JsGeneric,
3956 Arg1: JsGeneric,
3957 Arg2: JsGeneric,
3958 Arg3: JsGeneric,
3959 Arg4: JsGeneric,
3960 Arg5: JsGeneric,
3961 Arg6: JsGeneric,
3962 Arg7: JsGeneric,
3963 Arg8: JsGeneric,
3964 F: JsFunction8<
3965 Ret = Ret,
3966 Arg1 = Arg1,
3967 Arg2 = Arg2,
3968 Arg3 = Arg3,
3969 Arg4 = Arg4,
3970 Arg5 = Arg5,
3971 Arg6 = Arg6,
3972 Arg7 = Arg7,
3973 Arg8 = Arg8,
3974 > = fn(
3975 JsValue,
3976 JsValue,
3977 JsValue,
3978 JsValue,
3979 JsValue,
3980 JsValue,
3981 JsValue,
3982 JsValue,
3983 ) -> JsValue,
3984 >(
3985 this: &Function<F>,
3986 context: &JsValue,
3987 arg1: &Arg1,
3988 arg2: &Arg2,
3989 arg3: &Arg3,
3990 arg4: &Arg4,
3991 arg5: &Arg5,
3992 arg6: &Arg6,
3993 arg7: &Arg7,
3994 arg8: &Arg8,
3995 arg9: &JsValue,
3996 ) -> Result<Ret, JsValue>;
3997
3998 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
3999 /// with a given sequence of arguments preceding any provided when the new function is called.
4000 ///
4001 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4002 #[cfg(not(js_sys_unstable_apis))]
4003 #[deprecated(note = "Use `Function::bind0` instead.")]
4004 #[allow(deprecated)]
4005 #[wasm_bindgen(method, js_name = bind)]
4006 pub fn bind<T: JsFunction = fn() -> JsValue>(
4007 this: &Function<T>,
4008 context: &JsValue,
4009 ) -> Function<T>;
4010
4011 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4012 /// with a given sequence of arguments preceding any provided when the new function is called.
4013 ///
4014 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4015 ///
4016 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4017 #[wasm_bindgen(method, js_name = bind)]
4018 pub fn bind0<T: JsFunction = fn() -> JsValue>(
4019 this: &Function<T>,
4020 context: &JsValue,
4021 ) -> Function<T>;
4022
4023 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4024 /// with a given sequence of arguments preceding any provided when the new function is called.
4025 ///
4026 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4027 ///
4028 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4029 #[wasm_bindgen(method, js_name = bind)]
4030 pub fn bind1<
4031 Ret: JsGeneric,
4032 Arg1: JsGeneric,
4033 F: JsFunction1<Ret = Ret, Arg1 = Arg1> = fn(JsValue) -> JsValue,
4034 >(
4035 this: &Function<F>,
4036 context: &JsValue,
4037 arg1: &Arg1,
4038 ) -> Function<<F as JsFunction1>::Bind1>;
4039
4040 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4041 /// with a given sequence of arguments preceding any provided when the new function is called.
4042 ///
4043 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4044 ///
4045 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4046 #[wasm_bindgen(method, js_name = bind)]
4047 pub fn bind2<
4048 Ret: JsGeneric,
4049 Arg1: JsGeneric,
4050 Arg2: JsGeneric,
4051 F: JsFunction2<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2> = fn(JsValue, JsValue) -> JsValue,
4052 >(
4053 this: &Function<F>,
4054 context: &JsValue,
4055 arg1: &Arg1,
4056 arg2: &Arg2,
4057 ) -> Function<<F as JsFunction2>::Bind2>;
4058
4059 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4060 /// with a given sequence of arguments preceding any provided when the new function is called.
4061 ///
4062 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4063 ///
4064 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4065 #[wasm_bindgen(method, js_name = bind)]
4066 pub fn bind3<
4067 Ret: JsGeneric,
4068 Arg1: JsGeneric,
4069 Arg2: JsGeneric,
4070 Arg3: JsGeneric,
4071 F: JsFunction3<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
4072 JsValue,
4073 JsValue,
4074 JsValue,
4075 ) -> JsValue,
4076 >(
4077 this: &Function<F>,
4078 context: &JsValue,
4079 arg1: &Arg1,
4080 arg2: &Arg2,
4081 arg3: &Arg3,
4082 ) -> Function<<F as JsFunction3>::Bind3>;
4083
4084 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4085 /// with a given sequence of arguments preceding any provided when the new function is called.
4086 ///
4087 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4088 ///
4089 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4090 #[wasm_bindgen(method, js_name = bind)]
4091 pub fn bind4<
4092 Ret: JsGeneric,
4093 Arg1: JsGeneric,
4094 Arg2: JsGeneric,
4095 Arg3: JsGeneric,
4096 Arg4: JsGeneric,
4097 F: JsFunction4<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
4098 JsValue,
4099 JsValue,
4100 JsValue,
4101 JsValue,
4102 ) -> JsValue,
4103 >(
4104 this: &Function<F>,
4105 context: &JsValue,
4106 arg1: &Arg1,
4107 arg2: &Arg2,
4108 arg3: &Arg3,
4109 arg4: &Arg4,
4110 ) -> Function<<F as JsFunction4>::Bind4>;
4111
4112 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4113 /// with a given sequence of arguments preceding any provided when the new function is called.
4114 ///
4115 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4116 ///
4117 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4118 #[wasm_bindgen(method, js_name = bind)]
4119 pub fn bind5<
4120 Ret: JsGeneric,
4121 Arg1: JsGeneric,
4122 Arg2: JsGeneric,
4123 Arg3: JsGeneric,
4124 Arg4: JsGeneric,
4125 Arg5: JsGeneric,
4126 F: JsFunction5<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4127 JsValue,
4128 JsValue,
4129 JsValue,
4130 JsValue,
4131 JsValue,
4132 ) -> JsValue,
4133 >(
4134 this: &Function<F>,
4135 context: &JsValue,
4136 arg1: &Arg1,
4137 arg2: &Arg2,
4138 arg3: &Arg3,
4139 arg4: &Arg4,
4140 arg5: &Arg5,
4141 ) -> Function<<F as JsFunction5>::Bind5>;
4142
4143 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4144 /// with a given sequence of arguments preceding any provided when the new function is called.
4145 ///
4146 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4147 ///
4148 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4149 #[wasm_bindgen(method, js_name = bind)]
4150 pub fn bind6<
4151 Ret: JsGeneric,
4152 Arg1: JsGeneric,
4153 Arg2: JsGeneric,
4154 Arg3: JsGeneric,
4155 Arg4: JsGeneric,
4156 Arg5: JsGeneric,
4157 Arg6: JsGeneric,
4158 F: JsFunction6<
4159 Ret = Ret,
4160 Arg1 = Arg1,
4161 Arg2 = Arg2,
4162 Arg3 = Arg3,
4163 Arg4 = Arg4,
4164 Arg5 = Arg5,
4165 Arg6 = Arg6,
4166 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4167 >(
4168 this: &Function<F>,
4169 context: &JsValue,
4170 arg1: &Arg1,
4171 arg2: &Arg2,
4172 arg3: &Arg3,
4173 arg4: &Arg4,
4174 arg5: &Arg5,
4175 arg6: &Arg6,
4176 ) -> Function<<F as JsFunction6>::Bind6>;
4177
4178 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4179 /// with a given sequence of arguments preceding any provided when the new function is called.
4180 ///
4181 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4182 ///
4183 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4184 #[wasm_bindgen(method, js_name = bind)]
4185 pub fn bind7<
4186 Ret: JsGeneric,
4187 Arg1: JsGeneric,
4188 Arg2: JsGeneric,
4189 Arg3: JsGeneric,
4190 Arg4: JsGeneric,
4191 Arg5: JsGeneric,
4192 Arg6: JsGeneric,
4193 Arg7: JsGeneric,
4194 F: JsFunction7<
4195 Ret = Ret,
4196 Arg1 = Arg1,
4197 Arg2 = Arg2,
4198 Arg3 = Arg3,
4199 Arg4 = Arg4,
4200 Arg5 = Arg5,
4201 Arg6 = Arg6,
4202 Arg7 = Arg7,
4203 > = fn(
4204 JsValue,
4205 JsValue,
4206 JsValue,
4207 JsValue,
4208 JsValue,
4209 JsValue,
4210 JsValue,
4211 ) -> JsValue,
4212 >(
4213 this: &Function<F>,
4214 context: &JsValue,
4215 arg1: &Arg1,
4216 arg2: &Arg2,
4217 arg3: &Arg3,
4218 arg4: &Arg4,
4219 arg5: &Arg5,
4220 arg6: &Arg6,
4221 arg7: &Arg7,
4222 ) -> Function<<F as JsFunction7>::Bind7>;
4223
4224 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4225 /// with a given sequence of arguments preceding any provided when the new function is called.
4226 ///
4227 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4228 ///
4229 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4230 #[wasm_bindgen(method, js_name = bind)]
4231 pub fn bind8<
4232 Ret: JsGeneric,
4233 Arg1: JsGeneric,
4234 Arg2: JsGeneric,
4235 Arg3: JsGeneric,
4236 Arg4: JsGeneric,
4237 Arg5: JsGeneric,
4238 Arg6: JsGeneric,
4239 Arg7: JsGeneric,
4240 Arg8: JsGeneric,
4241 F: JsFunction8<
4242 Ret = Ret,
4243 Arg1 = Arg1,
4244 Arg2 = Arg2,
4245 Arg3 = Arg3,
4246 Arg4 = Arg4,
4247 Arg5 = Arg5,
4248 Arg6 = Arg6,
4249 Arg7 = Arg7,
4250 Arg8 = Arg8,
4251 > = fn(
4252 JsValue,
4253 JsValue,
4254 JsValue,
4255 JsValue,
4256 JsValue,
4257 JsValue,
4258 JsValue,
4259 JsValue,
4260 ) -> JsValue,
4261 >(
4262 this: &Function<F>,
4263 context: &JsValue,
4264 arg1: &Arg1,
4265 arg2: &Arg2,
4266 arg3: &Arg3,
4267 arg4: &Arg4,
4268 arg5: &Arg5,
4269 arg6: &Arg6,
4270 arg7: &Arg7,
4271 arg8: &Arg8,
4272 ) -> Function<<F as JsFunction8>::Bind8>;
4273
4274 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4275 /// with a given sequence of arguments preceding any provided when the new function is called.
4276 ///
4277 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4278 ///
4279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4280 #[deprecated]
4281 #[allow(deprecated)]
4282 #[wasm_bindgen(method, js_name = bind)]
4283 pub fn bind9<
4284 Ret: JsGeneric,
4285 Arg1: JsGeneric,
4286 Arg2: JsGeneric,
4287 Arg3: JsGeneric,
4288 Arg4: JsGeneric,
4289 Arg5: JsGeneric,
4290 Arg6: JsGeneric,
4291 Arg7: JsGeneric,
4292 Arg8: JsGeneric,
4293 F: JsFunction8<
4294 Ret = Ret,
4295 Arg1 = Arg1,
4296 Arg2 = Arg2,
4297 Arg3 = Arg3,
4298 Arg4 = Arg4,
4299 Arg5 = Arg5,
4300 Arg6 = Arg6,
4301 Arg7 = Arg7,
4302 Arg8 = Arg8,
4303 > = fn(
4304 JsValue,
4305 JsValue,
4306 JsValue,
4307 JsValue,
4308 JsValue,
4309 JsValue,
4310 JsValue,
4311 JsValue,
4312 ) -> JsValue,
4313 >(
4314 this: &Function<F>,
4315 context: &JsValue,
4316 arg1: &Arg1,
4317 arg2: &Arg2,
4318 arg3: &Arg3,
4319 arg4: &Arg4,
4320 arg5: &Arg5,
4321 arg6: &Arg6,
4322 arg7: &Arg7,
4323 arg8: &Arg8,
4324 arg9: &JsValue,
4325 ) -> Function<fn() -> Ret>;
4326
4327 /// The length property indicates the number of arguments expected by the function.
4328 ///
4329 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
4330 #[wasm_bindgen(method, getter)]
4331 pub fn length<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> u32;
4332
4333 /// A Function object's read-only name property indicates the function's
4334 /// name as specified when it was created or "anonymous" for functions
4335 /// created anonymously.
4336 ///
4337 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
4338 #[wasm_bindgen(method, getter)]
4339 pub fn name<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4340
4341 /// The `toString()` method returns a string representing the source code of the function.
4342 ///
4343 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
4344 #[cfg(not(js_sys_unstable_apis))]
4345 #[wasm_bindgen(method, js_name = toString)]
4346 pub fn to_string<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4347}
4348
4349// Basic UpcastFrom impls for Function<T>
4350impl<T: JsFunction> UpcastFrom<Function<T>> for JsValue {}
4351impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<JsValue> {}
4352impl<T: JsFunction> UpcastFrom<Function<T>> for Object {}
4353impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<Object> {}
4354
4355// Blanket trait for Function upcast
4356// Function<T> upcasts to Function<U> when the underlying fn type T upcasts to U.
4357// The fn signature UpcastFrom impls already encode correct variance (covariant return, contravariant args).
4358impl<T: JsFunction, U: JsFunction> UpcastFrom<Function<T>> for Function<U> where U: UpcastFrom<T> {}
4359
4360// len() method for Function<T> using JsFunction::ARITY
4361impl<T: JsFunction> Function<T> {
4362 /// Get the static arity of this function type.
4363 #[allow(clippy::len_without_is_empty)]
4364 pub fn len(&self) -> usize {
4365 T::ARITY
4366 }
4367
4368 /// Returns true if this is a zero-argument function.
4369 pub fn is_empty(&self) -> bool {
4370 T::ARITY == 0
4371 }
4372}
4373
4374// Base traits for function signature types.
4375pub trait JsFunction {
4376 type Ret: JsGeneric;
4377 const ARITY: usize;
4378}
4379
4380pub trait JsFunction1: JsFunction {
4381 type Arg1: JsGeneric;
4382 type Bind1: JsFunction;
4383}
4384pub trait JsFunction2: JsFunction1 {
4385 type Arg2: JsGeneric;
4386 type Bind2: JsFunction;
4387}
4388pub trait JsFunction3: JsFunction2 {
4389 type Arg3: JsGeneric;
4390 type Bind3: JsFunction;
4391}
4392pub trait JsFunction4: JsFunction3 {
4393 type Arg4: JsGeneric;
4394 type Bind4: JsFunction;
4395}
4396pub trait JsFunction5: JsFunction4 {
4397 type Arg5: JsGeneric;
4398 type Bind5: JsFunction;
4399}
4400pub trait JsFunction6: JsFunction5 {
4401 type Arg6: JsGeneric;
4402 type Bind6: JsFunction;
4403}
4404pub trait JsFunction7: JsFunction6 {
4405 type Arg7: JsGeneric;
4406 type Bind7: JsFunction;
4407}
4408pub trait JsFunction8: JsFunction7 {
4409 type Arg8: JsGeneric;
4410 type Bind8: JsFunction;
4411}
4412
4413// Manual impl for fn() -> R
4414impl<Ret: JsGeneric> JsFunction for fn() -> Ret {
4415 type Ret = Ret;
4416 const ARITY: usize = 0;
4417}
4418
4419macro_rules! impl_fn {
4420 () => {
4421 impl_fn!(@impl 1 [Arg1] [
4422 JsFunction1 Arg1 Bind1 {fn() -> Ret}
4423 ]);
4424 impl_fn!(@impl 2 [Arg1 Arg2] [
4425 JsFunction1 Arg1 Bind1 {fn(Arg2) -> Ret}
4426 JsFunction2 Arg2 Bind2 {fn() -> Ret}
4427 ]);
4428 impl_fn!(@impl 3 [Arg1 Arg2 Arg3] [
4429 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3) -> Ret}
4430 JsFunction2 Arg2 Bind2 {fn(Arg3) -> Ret}
4431 JsFunction3 Arg3 Bind3 {fn() -> Ret}
4432 ]);
4433 impl_fn!(@impl 4 [Arg1 Arg2 Arg3 Arg4] [
4434 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4) -> Ret}
4435 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4) -> Ret}
4436 JsFunction3 Arg3 Bind3 {fn(Arg4) -> Ret}
4437 JsFunction4 Arg4 Bind4 {fn() -> Ret}
4438 ]);
4439 impl_fn!(@impl 5 [Arg1 Arg2 Arg3 Arg4 Arg5] [
4440 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5) -> Ret}
4441 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5) -> Ret}
4442 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5) -> Ret}
4443 JsFunction4 Arg4 Bind4 {fn(Arg5) -> Ret}
4444 JsFunction5 Arg5 Bind5 {fn() -> Ret}
4445 ]);
4446 impl_fn!(@impl 6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [
4447 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6) -> Ret}
4448 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6) -> Ret}
4449 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6) -> Ret}
4450 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6) -> Ret}
4451 JsFunction5 Arg5 Bind5 {fn(Arg6) -> Ret}
4452 JsFunction6 Arg6 Bind6 {fn() -> Ret}
4453 ]);
4454 impl_fn!(@impl 7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [
4455 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4456 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4457 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7) -> Ret}
4458 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7) -> Ret}
4459 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7) -> Ret}
4460 JsFunction6 Arg6 Bind6 {fn(Arg7) -> Ret}
4461 JsFunction7 Arg7 Bind7 {fn() -> Ret}
4462 ]);
4463 impl_fn!(@impl 8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [
4464 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4465 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4466 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4467 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7, Arg8) -> Ret}
4468 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7, Arg8) -> Ret}
4469 JsFunction6 Arg6 Bind6 {fn(Arg7, Arg8) -> Ret}
4470 JsFunction7 Arg7 Bind7 {fn(Arg8) -> Ret}
4471 JsFunction8 Arg8 Bind8 {fn() -> Ret}
4472 ]);
4473 };
4474
4475 (@impl $arity:literal [$($A:ident)+] [$($trait:ident $arg:ident $bind:ident {$bind_ty:ty})+]) => {
4476 impl<Ret: JsGeneric $(, $A: JsGeneric)+> JsFunction for fn($($A),+) -> Ret {
4477 type Ret = Ret;
4478 const ARITY: usize = $arity;
4479 }
4480
4481 impl_fn!(@traits [$($A)+] [$($trait $arg $bind {$bind_ty})+]);
4482 };
4483
4484 (@traits [$($A:ident)+] []) => {};
4485
4486 (@traits [$($A:ident)+] [$trait:ident $arg:ident $bind:ident {$bind_ty:ty} $($rest:tt)*]) => {
4487 impl<Ret: JsGeneric $(, $A: JsGeneric)+> $trait for fn($($A),+) -> Ret {
4488 type $arg = $arg;
4489 type $bind = $bind_ty;
4490 }
4491
4492 impl_fn!(@traits [$($A)+] [$($rest)*]);
4493 };
4494}
4495
4496impl_fn!();
4497
4498/// Trait for argument tuples that can call or bind a `Function<T>`.
4499pub trait JsArgs<T: JsFunction> {
4500 type BindOutput;
4501 fn apply_call(self, func: &Function<T>, context: &JsValue) -> Result<T::Ret, JsValue>;
4502 fn apply_bind(self, func: &Function<T>, context: &JsValue) -> Self::BindOutput;
4503}
4504
4505// Manual impl for 0-arg
4506impl<Ret: JsGeneric, F: JsFunction<Ret = Ret>> JsArgs<F> for () {
4507 type BindOutput = Function<F>;
4508
4509 #[inline]
4510 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4511 func.call0(context)
4512 }
4513
4514 #[inline]
4515 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4516 func.bind0(context)
4517 }
4518}
4519
4520macro_rules! impl_js_args {
4521 ($arity:literal $trait:ident $bind_output:ident [$($A:ident)+] [$($idx:tt)+] $call:ident $bind:ident) => {
4522 impl<Ret: JsGeneric, $($A: JsGeneric,)+ F: $trait<Ret = Ret, $($A = $A,)*>> JsArgs<F> for ($(&$A,)+)
4523 {
4524 type BindOutput = Function<<F as $trait>::$bind_output>;
4525
4526 #[inline]
4527 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4528 func.$call(context, $(self.$idx),+)
4529 }
4530
4531 #[inline]
4532 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4533 func.$bind(context, $(self.$idx),+)
4534 }
4535 }
4536 };
4537}
4538
4539impl_js_args!(1 JsFunction1 Bind1 [Arg1] [0] call1 bind1);
4540impl_js_args!(2 JsFunction2 Bind2 [Arg1 Arg2] [0 1] call2 bind2);
4541impl_js_args!(3 JsFunction3 Bind3 [Arg1 Arg2 Arg3] [0 1 2] call3 bind3);
4542impl_js_args!(4 JsFunction4 Bind4 [Arg1 Arg2 Arg3 Arg4] [0 1 2 3] call4 bind4);
4543impl_js_args!(5 JsFunction5 Bind5 [Arg1 Arg2 Arg3 Arg4 Arg5] [0 1 2 3 4] call5 bind5);
4544impl_js_args!(6 JsFunction6 Bind6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [0 1 2 3 4 5] call6 bind6);
4545impl_js_args!(7 JsFunction7 Bind7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [0 1 2 3 4 5 6] call7 bind7);
4546impl_js_args!(8 JsFunction8 Bind8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [0 1 2 3 4 5 6 7] call8 bind8);
4547
4548impl<T: JsFunction> Function<T> {
4549 /// The `call()` method calls a function with a given `this` value and
4550 /// arguments provided as a tuple.
4551 ///
4552 /// This method accepts a tuple of references matching the function's
4553 /// argument types.
4554 ///
4555 /// # Example
4556 ///
4557 /// ```ignore
4558 /// // 0-arg function
4559 /// let f: Function<fn() -> Number> = get_fn();
4560 /// let result = f.call(&JsValue::NULL, ())?;
4561 ///
4562 /// // 1-arg function (note trailing comma for 1-tuple)
4563 /// let f: Function<fn(JsString) -> Number> = get_fn();
4564 /// let result = f.call(&JsValue::NULL, (&name,))?;
4565 ///
4566 /// // 2-arg function
4567 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4568 /// let result = f.call(&JsValue::NULL, (&name, &flag))?;
4569 /// ```
4570 ///
4571 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4572 #[inline]
4573 pub fn call<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Result<T::Ret, JsValue> {
4574 args.apply_call(self, context)
4575 }
4576
4577 /// The `bind()` method creates a new function that, when called, has its
4578 /// `this` keyword set to the provided value, with a given sequence of
4579 /// arguments preceding any provided when the new function is called.
4580 ///
4581 /// This method accepts a tuple of references to bind.
4582 ///
4583 /// # Example
4584 ///
4585 /// ```ignore
4586 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4587 ///
4588 /// // Bind no args - same signature
4589 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4590 ///
4591 /// // Bind one arg (use 1-tuple of references)
4592 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4593 ///
4594 /// // Bind two args - becomes 0-arg function
4595 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4596 /// ```
4597 ///
4598 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4599 #[inline]
4600 pub fn bindn<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4601 args.apply_bind(self, context)
4602 }
4603
4604 /// The `bind()` method creates a new function that, when called, has its
4605 /// `this` keyword set to the provided value, with a given sequence of
4606 /// arguments preceding any provided when the new function is called.
4607 ///
4608 /// This method accepts a tuple of references to bind.
4609 ///
4610 /// # Example
4611 ///
4612 /// ```ignore
4613 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4614 ///
4615 /// // Bind no args - same signature
4616 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4617 ///
4618 /// // Bind one arg (use 1-tuple of references)
4619 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4620 ///
4621 /// // Bind two args - becomes 0-arg function
4622 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4623 /// ```
4624 ///
4625 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4626 #[cfg(js_sys_unstable_apis)]
4627 #[inline]
4628 pub fn bind<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4629 args.apply_bind(self, context)
4630 }
4631}
4632
4633pub trait FunctionIntoClosure: JsFunction {
4634 type ClosureTypeMut: WasmClosure + ?Sized;
4635}
4636
4637macro_rules! impl_function_into_closure {
4638 ( $(($($var:ident)*))* ) => {$(
4639 impl<$($var: FromWasmAbi + JsGeneric,)* R: IntoWasmAbi + JsGeneric> FunctionIntoClosure for fn($($var),*) -> R {
4640 type ClosureTypeMut = dyn FnMut($($var),*) -> R;
4641 }
4642 )*};
4643}
4644
4645impl_function_into_closure! {
4646 ()
4647 (A)
4648 (A B)
4649 (A B C)
4650 (A B C D)
4651 (A B C D E)
4652 (A B C D E F)
4653 (A B C D E F G)
4654 (A B C D E F G H)
4655}
4656
4657impl<F: JsFunction> Function<F> {
4658 /// Convert a borrowed `ScopedClosure` into a typed JavaScript Function reference.
4659 ///
4660 /// The conversion is a direct type-safe conversion and upcast of a
4661 /// closure into its corresponding typed JavaScript Function,
4662 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4663 ///
4664 /// For transferring ownership to JS, use [`Function::from_closure`].
4665 #[inline]
4666 pub fn closure_ref<'a, C>(closure: &'a ScopedClosure<'_, C>) -> &'a Self
4667 where
4668 F: FunctionIntoClosure,
4669 C: WasmClosure + ?Sized,
4670 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4671 {
4672 closure.as_js_value().unchecked_ref()
4673 }
4674
4675 /// Convert a Rust closure into a typed JavaScript Function.
4676 ///
4677 /// This function releases ownership of the closure to JS, and provides
4678 /// an owned function handle for the same closure.
4679 ///
4680 /// The conversion is a direct type-safe conversion and upcast of a
4681 /// closure into its corresponding typed JavaScript Function,
4682 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4683 ///
4684 /// This method is only supported for static closures which do not have
4685 /// borrowed lifetime data, and thus can be released into JS.
4686 ///
4687 /// For borrowed closures, which cannot cede ownership to JS,
4688 /// instead use [`Function::closure_ref`].
4689 #[inline]
4690 pub fn from_closure<C>(closure: ScopedClosure<'static, C>) -> Self
4691 where
4692 F: FunctionIntoClosure,
4693 C: WasmClosure + ?Sized,
4694 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4695 {
4696 closure.into_js_value().unchecked_into()
4697 }
4698}
4699
4700#[cfg(not(js_sys_unstable_apis))]
4701impl Function {
4702 /// Returns the `Function` value of this JS value if it's an instance of a
4703 /// function.
4704 ///
4705 /// If this JS value is not an instance of a function then this returns
4706 /// `None`.
4707 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
4708 pub fn try_from(val: &JsValue) -> Option<&Function> {
4709 val.dyn_ref()
4710 }
4711}
4712
4713#[cfg(feature = "unsafe-eval")]
4714impl Default for Function {
4715 fn default() -> Self {
4716 Self::new_no_args("")
4717 }
4718}
4719
4720// Generator
4721#[wasm_bindgen]
4722extern "C" {
4723 #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
4724 #[derive(Clone, Debug, PartialEq, Eq)]
4725 pub type Generator<T = JsValue>;
4726
4727 /// The `next()` method returns an object with two properties done and value.
4728 /// You can also provide a parameter to the next method to send a value to the generator.
4729 ///
4730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4731 #[cfg(not(js_sys_unstable_apis))]
4732 #[wasm_bindgen(method, catch)]
4733 pub fn next<T>(this: &Generator<T>, value: &T) -> Result<JsValue, JsValue>;
4734
4735 /// The `next()` method returns an object with two properties done and value.
4736 /// You can also provide a parameter to the next method to send a value to the generator.
4737 ///
4738 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4739 #[cfg(js_sys_unstable_apis)]
4740 #[wasm_bindgen(method, catch, js_name = next)]
4741 pub fn next<T: FromWasmAbi>(this: &Generator<T>, value: &T)
4742 -> Result<IteratorNext<T>, JsValue>;
4743
4744 // Next major: deprecate
4745 /// The `next()` method returns an object with two properties done and value.
4746 /// You can also provide a parameter to the next method to send a value to the generator.
4747 ///
4748 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4749 #[wasm_bindgen(method, catch)]
4750 pub fn next_iterator<T: FromWasmAbi>(
4751 this: &Generator<T>,
4752 value: &T,
4753 ) -> Result<IteratorNext<T>, JsValue>;
4754
4755 /// The `return()` method returns the given value and finishes the generator.
4756 ///
4757 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4758 #[cfg(not(js_sys_unstable_apis))]
4759 #[wasm_bindgen(method, js_name = "return")]
4760 pub fn return_<T>(this: &Generator<T>, value: &T) -> JsValue;
4761
4762 /// The `return()` method returns the given value and finishes the generator.
4763 ///
4764 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4765 #[cfg(js_sys_unstable_apis)]
4766 #[wasm_bindgen(method, catch, js_name = "return")]
4767 pub fn return_<T: FromWasmAbi>(
4768 this: &Generator<T>,
4769 value: &T,
4770 ) -> Result<IteratorNext<T>, JsValue>;
4771
4772 // Next major: deprecate
4773 /// The `return()` method returns the given value and finishes the generator.
4774 ///
4775 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4776 #[wasm_bindgen(method, catch, js_name = "return")]
4777 pub fn try_return<T: FromWasmAbi>(
4778 this: &Generator<T>,
4779 value: &T,
4780 ) -> Result<IteratorNext<T>, JsValue>;
4781
4782 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4783 /// and returns an object with two properties done and value.
4784 ///
4785 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4786 #[cfg(not(js_sys_unstable_apis))]
4787 #[wasm_bindgen(method, catch)]
4788 pub fn throw<T>(this: &Generator<T>, error: &Error) -> Result<JsValue, JsValue>;
4789
4790 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4791 /// and returns an object with two properties done and value.
4792 ///
4793 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4794 #[cfg(js_sys_unstable_apis)]
4795 #[wasm_bindgen(method, catch, js_name = throw)]
4796 pub fn throw<T: FromWasmAbi>(
4797 this: &Generator<T>,
4798 error: &JsValue,
4799 ) -> Result<IteratorNext<T>, JsValue>;
4800
4801 // Next major: deprecate
4802 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4803 /// and returns an object with two properties done and value.
4804 ///
4805 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4806 #[wasm_bindgen(method, catch, js_name = throw)]
4807 pub fn throw_value<T: FromWasmAbi>(
4808 this: &Generator<T>,
4809 error: &JsValue,
4810 ) -> Result<IteratorNext<T>, JsValue>;
4811}
4812
4813impl<T: FromWasmAbi> Iterable for Generator<T> {
4814 type Item = T;
4815}
4816
4817// AsyncGenerator
4818#[wasm_bindgen]
4819extern "C" {
4820 #[wasm_bindgen(extends = Object, typescript_type = "AsyncGenerator<any, any, any>")]
4821 #[derive(Clone, Debug, PartialEq, Eq)]
4822 pub type AsyncGenerator<T = JsValue>;
4823
4824 /// The `next()` method returns an object with two properties done and value.
4825 /// You can also provide a parameter to the next method to send a value to the generator.
4826 ///
4827 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/next)
4828 #[wasm_bindgen(method, catch)]
4829 pub fn next<T>(
4830 this: &AsyncGenerator<T>,
4831 value: &T,
4832 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4833
4834 /// The `return()` method returns the given value and finishes the generator.
4835 ///
4836 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/return)
4837 #[wasm_bindgen(method, js_name = "return", catch)]
4838 pub fn return_<T>(
4839 this: &AsyncGenerator<T>,
4840 value: &T,
4841 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4842
4843 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4844 /// and returns an object with two properties done and value.
4845 ///
4846 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/throw)
4847 #[wasm_bindgen(method, catch)]
4848 pub fn throw<T>(
4849 this: &AsyncGenerator<T>,
4850 error: &JsValue,
4851 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4852}
4853
4854impl<T: FromWasmAbi> AsyncIterable for AsyncGenerator<T> {
4855 type Item = T;
4856}
4857
4858// Map
4859#[wasm_bindgen]
4860extern "C" {
4861 #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
4862 #[derive(Clone, Debug, PartialEq, Eq)]
4863 pub type Map<K = JsValue, V = JsValue>;
4864
4865 /// The Map object holds key-value pairs. Any value (both objects and
4866 /// primitive values) maybe used as either a key or a value.
4867 ///
4868 /// **Note:** Consider using [`Map::new_typed`] for typing support.
4869 ///
4870 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4871 #[cfg(not(js_sys_unstable_apis))]
4872 #[wasm_bindgen(constructor)]
4873 pub fn new() -> Map;
4874
4875 /// The Map object holds key-value pairs. Any value (both objects and
4876 /// primitive values) maybe used as either a key or a value.
4877 ///
4878 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4879 #[cfg(js_sys_unstable_apis)]
4880 #[wasm_bindgen(constructor)]
4881 pub fn new<K, V>() -> Map<K, V>;
4882
4883 // Next major: deprecate
4884 /// The Map object holds key-value pairs. Any value (both objects and
4885 /// primitive values) maybe used as either a key or a value.
4886 ///
4887 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4888 #[wasm_bindgen(constructor)]
4889 pub fn new_typed<K, V>() -> Map<K, V>;
4890
4891 /// The Map object holds key-value pairs. Any value (both objects and
4892 /// primitive values) maybe used as either a key or a value.
4893 ///
4894 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4895 #[wasm_bindgen(constructor, js_name = new)]
4896 pub fn new_from_entries<K, V, I: Iterable<Item = ArrayTuple<(K, V)>>>(entries: &I)
4897 -> Map<K, V>;
4898
4899 /// The `clear()` method removes all elements from a Map object.
4900 ///
4901 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
4902 #[wasm_bindgen(method)]
4903 pub fn clear<K, V>(this: &Map<K, V>);
4904
4905 /// The `delete()` method removes the specified element from a Map object.
4906 ///
4907 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
4908 #[wasm_bindgen(method)]
4909 pub fn delete<K, V>(this: &Map<K, V>, key: &K) -> bool;
4910
4911 /// The `forEach()` method executes a provided function once per each
4912 /// key/value pair in the Map object, in insertion order.
4913 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
4914 /// # Examples
4915 /// ```
4916 /// let js_map = Map::new();
4917 /// js_map.for_each(&mut |value, key| {
4918 /// // Do something here...
4919 /// })
4920 /// ```
4921 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
4922 #[wasm_bindgen(method, js_name = forEach)]
4923 pub fn for_each<K, V>(this: &Map<K, V>, callback: &mut dyn FnMut(V, K));
4924
4925 /// The `forEach()` method executes a provided function once per each
4926 /// key/value pair in the Map object, in insertion order. _(Fallible variation)_
4927 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
4928 /// # Examples
4929 /// ```
4930 /// let js_map = Map::new();
4931 /// js_map.for_each(&mut |value, key| {
4932 /// // Do something here...
4933 /// })
4934 /// ```
4935 ///
4936 /// **Note:** Consider using [`Map::try_for_each`] if the callback might throw an error.
4937 ///
4938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
4939 #[wasm_bindgen(method, js_name = forEach, catch)]
4940 pub fn try_for_each<K, V>(
4941 this: &Map<K, V>,
4942 callback: &mut dyn FnMut(V, K) -> Result<(), JsError>,
4943 ) -> Result<(), JsValue>;
4944
4945 /// The `get()` method returns a specified element from a Map object.
4946 /// Returns `undefined` if the key is not found.
4947 ///
4948 /// **Note:** Consider using [`Map::get_checked`] to get an `Option<V>` instead.
4949 ///
4950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4951 #[cfg(not(js_sys_unstable_apis))]
4952 #[wasm_bindgen(method)]
4953 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> V;
4954
4955 /// The `get()` method returns a specified element from a Map object.
4956 /// Returns `None` if the key is not found.
4957 ///
4958 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4959 #[cfg(js_sys_unstable_apis)]
4960 #[wasm_bindgen(method)]
4961 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
4962
4963 /// The `get()` method returns a specified element from a Map object.
4964 /// Returns `None` if the key is not found.
4965 ///
4966 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4967 #[wasm_bindgen(method, js_name = get)]
4968 pub fn get_checked<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
4969
4970 /// The `has()` method returns a boolean indicating whether an element with
4971 /// the specified key exists or not.
4972 ///
4973 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
4974 #[wasm_bindgen(method)]
4975 pub fn has<K, V>(this: &Map<K, V>, key: &K) -> bool;
4976
4977 /// The `set()` method adds or updates an element with a specified key
4978 /// and value to a Map object.
4979 ///
4980 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
4981 #[wasm_bindgen(method)]
4982 pub fn set<K, V>(this: &Map<K, V>, key: &K, value: &V) -> Map<K, V>;
4983
4984 /// The value of size is an integer representing how many entries
4985 /// the Map object has. A set accessor function for size is undefined;
4986 /// you can not change this property.
4987 ///
4988 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
4989 #[wasm_bindgen(method, getter)]
4990 pub fn size<K, V>(this: &Map<K, V>) -> u32;
4991}
4992
4993impl Default for Map<JsValue, JsValue> {
4994 fn default() -> Self {
4995 Self::new()
4996 }
4997}
4998
4999// Map Iterator
5000#[wasm_bindgen]
5001extern "C" {
5002 /// The `entries()` method returns a new Iterator object that contains
5003 /// the [key, value] pairs for each element in the Map object in
5004 /// insertion order.
5005 ///
5006 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5007 #[cfg(not(js_sys_unstable_apis))]
5008 #[wasm_bindgen(method)]
5009 pub fn entries<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator;
5010
5011 /// The `entries()` method returns a new Iterator object that contains
5012 /// the [key, value] pairs for each element in the Map object in
5013 /// insertion order.
5014 ///
5015 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5016 #[cfg(js_sys_unstable_apis)]
5017 #[wasm_bindgen(method, js_name = entries)]
5018 pub fn entries<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5019 this: &Map<K, V>,
5020 ) -> Iterator<ArrayTuple<(K, V)>>;
5021
5022 // Next major: deprecate
5023 /// The `entries()` method returns a new Iterator object that contains
5024 /// the [key, value] pairs for each element in the Map object in
5025 /// insertion order.
5026 ///
5027 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5028 #[wasm_bindgen(method, js_name = entries)]
5029 pub fn entries_typed<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5030 this: &Map<K, V>,
5031 ) -> Iterator<ArrayTuple<(K, V)>>;
5032
5033 /// The `keys()` method returns a new Iterator object that contains the
5034 /// keys for each element in the Map object in insertion order.
5035 ///
5036 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
5037 #[wasm_bindgen(method)]
5038 pub fn keys<K: FromWasmAbi, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<K>;
5039
5040 /// The `values()` method returns a new Iterator object that contains the
5041 /// values for each element in the Map object in insertion order.
5042 ///
5043 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values)
5044 #[wasm_bindgen(method)]
5045 pub fn values<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<V>;
5046}
5047
5048impl<K, V> Iterable for Map<K, V> {
5049 type Item = ArrayTuple<(K, V)>;
5050}
5051
5052// Iterator
5053#[wasm_bindgen]
5054extern "C" {
5055 /// Any object that conforms to the JS iterator protocol. For example,
5056 /// something returned by `myArray[Symbol.iterator]()`.
5057 ///
5058 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5059 #[derive(Clone, Debug)]
5060 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
5061 pub type Iterator<T = JsValue>;
5062
5063 /// The `next()` method always has to return an object with appropriate
5064 /// properties including done and value. If a non-object value gets returned
5065 /// (such as false or undefined), a TypeError ("iterator.next() returned a
5066 /// non-object value") will be thrown.
5067 #[wasm_bindgen(catch, method)]
5068 pub fn next<T: FromWasmAbi>(this: &Iterator<T>) -> Result<IteratorNext<T>, JsValue>;
5069}
5070
5071impl<T> UpcastFrom<Iterator<T>> for Object {}
5072
5073impl Iterator {
5074 fn looks_like_iterator(it: &JsValue) -> bool {
5075 #[wasm_bindgen]
5076 extern "C" {
5077 type MaybeIterator;
5078
5079 #[wasm_bindgen(method, getter)]
5080 fn next(this: &MaybeIterator) -> JsValue;
5081 }
5082
5083 if !it.is_object() {
5084 return false;
5085 }
5086
5087 let it = it.unchecked_ref::<MaybeIterator>();
5088
5089 it.next().is_function()
5090 }
5091}
5092
5093// iterators in JS are themselves iterable
5094impl<T> Iterable for Iterator<T> {
5095 type Item = T;
5096}
5097
5098// Async Iterator
5099#[wasm_bindgen]
5100extern "C" {
5101 /// Any object that conforms to the JS async iterator protocol. For example,
5102 /// something returned by `myObject[Symbol.asyncIterator]()`.
5103 ///
5104 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
5105 #[derive(Clone, Debug)]
5106 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>")]
5107 pub type AsyncIterator<T = JsValue>;
5108
5109 /// The `next()` method always has to return a Promise which resolves to an object
5110 /// with appropriate properties including done and value. If a non-object value
5111 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5112 /// returned a non-object value") will be thrown.
5113 #[cfg(not(js_sys_unstable_apis))]
5114 #[wasm_bindgen(catch, method)]
5115 pub fn next<T>(this: &AsyncIterator<T>) -> Result<Promise, JsValue>;
5116
5117 /// The `next()` method always has to return a Promise which resolves to an object
5118 /// with appropriate properties including done and value. If a non-object value
5119 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5120 /// returned a non-object value") will be thrown.
5121 #[cfg(js_sys_unstable_apis)]
5122 #[wasm_bindgen(catch, method, js_name = next)]
5123 pub fn next<T: FromWasmAbi>(
5124 this: &AsyncIterator<T>,
5125 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5126
5127 // Next major: deprecate
5128 /// The `next()` method always has to return a Promise which resolves to an object
5129 /// with appropriate properties including done and value. If a non-object value
5130 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5131 /// returned a non-object value") will be thrown.
5132 #[wasm_bindgen(catch, method, js_name = next)]
5133 pub fn next_iterator<T: FromWasmAbi>(
5134 this: &AsyncIterator<T>,
5135 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5136}
5137
5138impl<T> UpcastFrom<AsyncIterator<T>> for Object {}
5139
5140// iterators in JS are themselves iterable
5141impl<T> AsyncIterable for AsyncIterator<T> {
5142 type Item = T;
5143}
5144
5145/// An iterator over the JS `Symbol.iterator` iteration protocol.
5146///
5147/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
5148pub struct Iter<'a, T = JsValue> {
5149 js: &'a Iterator<T>,
5150 state: IterState,
5151}
5152
5153/// An iterator over the JS `Symbol.iterator` iteration protocol.
5154///
5155/// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
5156pub struct IntoIter<T = JsValue> {
5157 js: Iterator<T>,
5158 state: IterState,
5159}
5160
5161struct IterState {
5162 done: bool,
5163}
5164
5165impl<'a, T: FromWasmAbi + JsGeneric> IntoIterator for &'a Iterator<T> {
5166 type Item = Result<T, JsValue>;
5167 type IntoIter = Iter<'a, T>;
5168
5169 fn into_iter(self) -> Iter<'a, T> {
5170 Iter {
5171 js: self,
5172 state: IterState::new(),
5173 }
5174 }
5175}
5176
5177impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for Iter<'_, T> {
5178 type Item = Result<T, JsValue>;
5179
5180 fn next(&mut self) -> Option<Self::Item> {
5181 self.state.next(self.js)
5182 }
5183}
5184
5185impl<T: FromWasmAbi + JsGeneric> IntoIterator for Iterator<T> {
5186 type Item = Result<T, JsValue>;
5187 type IntoIter = IntoIter<T>;
5188
5189 fn into_iter(self) -> IntoIter<T> {
5190 IntoIter {
5191 js: self,
5192 state: IterState::new(),
5193 }
5194 }
5195}
5196
5197impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for IntoIter<T> {
5198 type Item = Result<T, JsValue>;
5199
5200 fn next(&mut self) -> Option<Self::Item> {
5201 self.state.next(&self.js)
5202 }
5203}
5204
5205impl IterState {
5206 fn new() -> IterState {
5207 IterState { done: false }
5208 }
5209
5210 fn next<T: FromWasmAbi + JsGeneric>(&mut self, js: &Iterator<T>) -> Option<Result<T, JsValue>> {
5211 if self.done {
5212 return None;
5213 }
5214 let next = match js.next() {
5215 Ok(val) => val,
5216 Err(e) => {
5217 self.done = true;
5218 return Some(Err(e));
5219 }
5220 };
5221 if next.done() {
5222 self.done = true;
5223 None
5224 } else {
5225 Some(Ok(next.value()))
5226 }
5227 }
5228}
5229
5230/// Create an iterator over `val` using the JS iteration protocol and
5231/// `Symbol.iterator`.
5232// #[cfg(not(js_sys_unstable_apis))]
5233pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter<JsValue>>, JsValue> {
5234 let iter_sym = Symbol::iterator();
5235
5236 let iter_fn = Reflect::get_symbol::<Object>(val.unchecked_ref(), iter_sym.as_ref())?;
5237 let iter_fn: Function = match iter_fn.dyn_into() {
5238 Ok(iter_fn) => iter_fn,
5239 Err(_) => return Ok(None),
5240 };
5241
5242 let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
5243 Ok(it) => it,
5244 Err(_) => return Ok(None),
5245 };
5246
5247 Ok(Some(it.into_iter()))
5248}
5249
5250/// Trait for JavaScript types that implement the iterable protocol via `Symbol.iterator`.
5251///
5252/// Types implementing this trait can be iterated over using JavaScript's iteration
5253/// protocol. The `Item` associated type specifies the type of values yielded.
5254///
5255/// ## Built-in Iterables
5256///
5257/// Many `js-sys` collection types implement `Iterable` out of the box:
5258///
5259/// ```ignore
5260/// use js_sys::{Array, Map, Set};
5261///
5262/// // Array<T> yields T
5263/// let arr: Array<Number> = get_numbers();
5264/// for value in arr.iter() {
5265/// let num: Number = value?;
5266/// }
5267///
5268/// // Map<K, V> yields Array (key-value pairs)
5269/// let map: Map<JsString, Number> = get_map();
5270/// for entry in map.iter() {
5271/// let pair: Array = entry?;
5272/// }
5273///
5274/// // Set<T> yields T
5275/// let set: Set<JsString> = get_set();
5276/// for value in set.iter() {
5277/// let s: JsString = value?;
5278/// }
5279/// ```
5280///
5281/// ## Typing Foreign Iterators
5282///
5283/// If you have a JavaScript value that implements the iterator protocol (has a `next()`
5284/// method) but isn't a built-in type, you can use [`JsCast`] to cast it to [`Iterator<T>`]:
5285///
5286/// ```ignore
5287/// use js_sys::Iterator;
5288/// use wasm_bindgen::JsCast;
5289///
5290/// // For a value you know implements the iterator protocol
5291/// fn process_iterator(js_iter: JsValue) {
5292/// // Checked cast - returns None if not an iterator
5293/// if let Some(iter) = js_iter.dyn_ref::<Iterator<Number>>() {
5294/// for value in iter.into_iter() {
5295/// let num: Number = value.unwrap();
5296/// // ...
5297/// }
5298/// }
5299/// }
5300///
5301/// // Or with unchecked cast when you're certain of the type
5302/// fn process_known_iterator(js_iter: JsValue) {
5303/// let iter: &Iterator<JsString> = js_iter.unchecked_ref();
5304/// for value in iter.into_iter() {
5305/// let s: JsString = value.unwrap();
5306/// // ...
5307/// }
5308/// }
5309/// ```
5310///
5311/// ## Using with `JsValue`
5312///
5313/// For dynamic or unknown iterables, use [`try_iter`] which returns an untyped iterator:
5314///
5315/// ```ignore
5316/// fn iterate_unknown(val: &JsValue) -> Result<(), JsValue> {
5317/// if let Some(iter) = js_sys::try_iter(val)? {
5318/// for item in iter {
5319/// let value: JsValue = item?;
5320/// // Handle dynamically...
5321/// }
5322/// }
5323/// Ok(())
5324/// }
5325/// ```
5326///
5327/// [`JsCast`]: wasm_bindgen::JsCast
5328/// [`Iterator<T>`]: Iterator
5329/// [`try_iter`]: crate::try_iter
5330pub trait Iterable {
5331 /// The type of values yielded by this iterable.
5332 type Item;
5333}
5334
5335impl<T: Iterable> Iterable for &T {
5336 type Item = T::Item;
5337}
5338
5339/// Trait for types known to implement the iterator protocol on Symbol.asyncIterator
5340pub trait AsyncIterable {
5341 type Item;
5342}
5343
5344impl<T: AsyncIterable> AsyncIterable for &T {
5345 type Item = T::Item;
5346}
5347
5348impl AsyncIterable for JsValue {
5349 type Item = JsValue;
5350}
5351
5352// IteratorNext
5353#[wasm_bindgen]
5354extern "C" {
5355 /// The result of calling `next()` on a JS iterator.
5356 ///
5357 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5358 #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
5359 #[derive(Clone, Debug, PartialEq, Eq)]
5360 pub type IteratorNext<T = JsValue>;
5361
5362 /// Has the value `true` if the iterator is past the end of the iterated
5363 /// sequence. In this case value optionally specifies the return value of
5364 /// the iterator.
5365 ///
5366 /// Has the value `false` if the iterator was able to produce the next value
5367 /// in the sequence. This is equivalent of not specifying the done property
5368 /// altogether.
5369 #[wasm_bindgen(method, getter)]
5370 pub fn done<T>(this: &IteratorNext<T>) -> bool;
5371
5372 /// Any JavaScript value returned by the iterator. Can be omitted when done
5373 /// is true.
5374 #[wasm_bindgen(method, getter)]
5375 pub fn value<T>(this: &IteratorNext<T>) -> T;
5376}
5377
5378#[allow(non_snake_case)]
5379pub mod Math {
5380 use super::*;
5381
5382 // Math
5383 #[wasm_bindgen]
5384 extern "C" {
5385 /// The `Math.abs()` function returns the absolute value of a number, that is
5386 /// Math.abs(x) = |x|
5387 ///
5388 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
5389 #[wasm_bindgen(js_namespace = Math)]
5390 pub fn abs(x: f64) -> f64;
5391
5392 /// The `Math.acos()` function returns the arccosine (in radians) of a
5393 /// number, that is ∀x∊[-1;1]
5394 /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
5395 ///
5396 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
5397 #[wasm_bindgen(js_namespace = Math)]
5398 pub fn acos(x: f64) -> f64;
5399
5400 /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
5401 /// number, that is ∀x ≥ 1
5402 /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
5403 ///
5404 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
5405 #[wasm_bindgen(js_namespace = Math)]
5406 pub fn acosh(x: f64) -> f64;
5407
5408 /// The `Math.asin()` function returns the arcsine (in radians) of a
5409 /// number, that is ∀x ∊ [-1;1]
5410 /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
5411 ///
5412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
5413 #[wasm_bindgen(js_namespace = Math)]
5414 pub fn asin(x: f64) -> f64;
5415
5416 /// The `Math.asinh()` function returns the hyperbolic arcsine of a
5417 /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
5418 ///
5419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
5420 #[wasm_bindgen(js_namespace = Math)]
5421 pub fn asinh(x: f64) -> f64;
5422
5423 /// The `Math.atan()` function returns the arctangent (in radians) of a
5424 /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
5425 /// tan(y) = x
5426 #[wasm_bindgen(js_namespace = Math)]
5427 pub fn atan(x: f64) -> f64;
5428
5429 /// The `Math.atan2()` function returns the arctangent of the quotient of
5430 /// its arguments.
5431 ///
5432 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
5433 #[wasm_bindgen(js_namespace = Math)]
5434 pub fn atan2(y: f64, x: f64) -> f64;
5435
5436 /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
5437 /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
5438 /// tanh(y) = x
5439 ///
5440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
5441 #[wasm_bindgen(js_namespace = Math)]
5442 pub fn atanh(x: f64) -> f64;
5443
5444 /// The `Math.cbrt() `function returns the cube root of a number, that is
5445 /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
5446 ///
5447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
5448 #[wasm_bindgen(js_namespace = Math)]
5449 pub fn cbrt(x: f64) -> f64;
5450
5451 /// The `Math.ceil()` function returns the smallest integer greater than
5452 /// or equal to a given number.
5453 ///
5454 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
5455 #[wasm_bindgen(js_namespace = Math)]
5456 pub fn ceil(x: f64) -> f64;
5457
5458 /// The `Math.clz32()` function returns the number of leading zero bits in
5459 /// the 32-bit binary representation of a number.
5460 ///
5461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
5462 #[wasm_bindgen(js_namespace = Math)]
5463 pub fn clz32(x: i32) -> u32;
5464
5465 /// The `Math.cos()` static function returns the cosine of the specified angle,
5466 /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
5467 ///
5468 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
5469 #[wasm_bindgen(js_namespace = Math)]
5470 pub fn cos(x: f64) -> f64;
5471
5472 /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
5473 /// that can be expressed using the constant e.
5474 ///
5475 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
5476 #[wasm_bindgen(js_namespace = Math)]
5477 pub fn cosh(x: f64) -> f64;
5478
5479 /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
5480 /// (also known as Napier's constant), the base of the natural logarithms.
5481 ///
5482 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
5483 #[wasm_bindgen(js_namespace = Math)]
5484 pub fn exp(x: f64) -> f64;
5485
5486 /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
5487 /// natural logarithms.
5488 ///
5489 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
5490 #[wasm_bindgen(js_namespace = Math)]
5491 pub fn expm1(x: f64) -> f64;
5492
5493 /// The `Math.floor()` function returns the largest integer less than or
5494 /// equal to a given number.
5495 ///
5496 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
5497 #[wasm_bindgen(js_namespace = Math)]
5498 pub fn floor(x: f64) -> f64;
5499
5500 /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
5501 /// of a Number.
5502 ///
5503 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
5504 #[wasm_bindgen(js_namespace = Math)]
5505 pub fn fround(x: f64) -> f32;
5506
5507 /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
5508 ///
5509 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
5510 #[wasm_bindgen(js_namespace = Math)]
5511 pub fn hypot(x: f64, y: f64) -> f64;
5512
5513 /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
5514 /// two parameters.
5515 ///
5516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
5517 #[wasm_bindgen(js_namespace = Math)]
5518 pub fn imul(x: i32, y: i32) -> i32;
5519
5520 /// The `Math.log()` function returns the natural logarithm (base e) of a number.
5521 /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
5522 ///
5523 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
5524 #[wasm_bindgen(js_namespace = Math)]
5525 pub fn log(x: f64) -> f64;
5526
5527 /// The `Math.log10()` function returns the base 10 logarithm of a number.
5528 ///
5529 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
5530 #[wasm_bindgen(js_namespace = Math)]
5531 pub fn log10(x: f64) -> f64;
5532
5533 /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
5534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
5535 #[wasm_bindgen(js_namespace = Math)]
5536 pub fn log1p(x: f64) -> f64;
5537
5538 /// The `Math.log2()` function returns the base 2 logarithm of a number.
5539 ///
5540 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
5541 #[wasm_bindgen(js_namespace = Math)]
5542 pub fn log2(x: f64) -> f64;
5543
5544 /// The `Math.max()` function returns the largest of two numbers.
5545 ///
5546 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
5547 #[wasm_bindgen(js_namespace = Math)]
5548 pub fn max(x: f64, y: f64) -> f64;
5549
5550 /// The static function `Math.min()` returns the lowest-valued number passed into it.
5551 ///
5552 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
5553 #[wasm_bindgen(js_namespace = Math)]
5554 pub fn min(x: f64, y: f64) -> f64;
5555
5556 /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
5557 ///
5558 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
5559 #[wasm_bindgen(js_namespace = Math)]
5560 pub fn pow(base: f64, exponent: f64) -> f64;
5561
5562 /// The `Math.random()` function returns a floating-point, pseudo-random number
5563 /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
5564 /// over that range — which you can then scale to your desired range.
5565 /// The implementation selects the initial seed to the random number generation algorithm;
5566 /// it cannot be chosen or reset by the user.
5567 ///
5568 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
5569 #[wasm_bindgen(js_namespace = Math)]
5570 pub fn random() -> f64;
5571
5572 /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
5573 ///
5574 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
5575 #[wasm_bindgen(js_namespace = Math)]
5576 pub fn round(x: f64) -> f64;
5577
5578 /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
5579 /// positive, negative or zero.
5580 ///
5581 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
5582 #[wasm_bindgen(js_namespace = Math)]
5583 pub fn sign(x: f64) -> f64;
5584
5585 /// The `Math.sin()` function returns the sine of a number.
5586 ///
5587 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
5588 #[wasm_bindgen(js_namespace = Math)]
5589 pub fn sin(x: f64) -> f64;
5590
5591 /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
5592 /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
5593 ///
5594 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
5595 #[wasm_bindgen(js_namespace = Math)]
5596 pub fn sinh(x: f64) -> f64;
5597
5598 /// The `Math.sqrt()` function returns the square root of a number, that is
5599 /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
5600 ///
5601 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
5602 #[wasm_bindgen(js_namespace = Math)]
5603 pub fn sqrt(x: f64) -> f64;
5604
5605 /// The `Math.tan()` function returns the tangent of a number.
5606 ///
5607 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
5608 #[wasm_bindgen(js_namespace = Math)]
5609 pub fn tan(x: f64) -> f64;
5610
5611 /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
5612 /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
5613 ///
5614 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
5615 #[wasm_bindgen(js_namespace = Math)]
5616 pub fn tanh(x: f64) -> f64;
5617
5618 /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
5619 /// digits.
5620 ///
5621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
5622 #[wasm_bindgen(js_namespace = Math)]
5623 pub fn trunc(x: f64) -> f64;
5624
5625 /// The `Math.PI` property represents the ratio of the circumference of a circle to its diameter,
5626 /// approximately 3.14159.
5627 ///
5628 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI)
5629 #[wasm_bindgen(thread_local_v2, js_namespace = Math)]
5630 pub static PI: f64;
5631 }
5632}
5633
5634// Number.
5635#[wasm_bindgen]
5636extern "C" {
5637 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
5638 #[derive(Clone, PartialEq)]
5639 pub type Number;
5640
5641 /// The `Number.isFinite()` method determines whether the passed value is a finite number.
5642 ///
5643 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
5644 #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
5645 pub fn is_finite(value: &JsValue) -> bool;
5646
5647 /// The `Number.isInteger()` method determines whether the passed value is an integer.
5648 ///
5649 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
5650 #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
5651 pub fn is_integer(value: &JsValue) -> bool;
5652
5653 /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
5654 /// It is a more robust version of the original, global isNaN().
5655 ///
5656 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
5657 #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
5658 pub fn is_nan(value: &JsValue) -> bool;
5659
5660 /// The `Number.isSafeInteger()` method determines whether the provided value is a number
5661 /// that is a safe integer.
5662 ///
5663 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
5664 #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
5665 pub fn is_safe_integer(value: &JsValue) -> bool;
5666
5667 /// The `Number` JavaScript object is a wrapper object allowing
5668 /// you to work with numerical values. A `Number` object is
5669 /// created using the `Number()` constructor.
5670 ///
5671 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
5672 #[cfg(not(js_sys_unstable_apis))]
5673 #[wasm_bindgen(constructor)]
5674 #[deprecated(note = "recommended to use `Number::from` instead")]
5675 #[allow(deprecated)]
5676 pub fn new(value: &JsValue) -> Number;
5677
5678 #[wasm_bindgen(constructor)]
5679 fn new_from_str(value: &str) -> Number;
5680
5681 /// The `Number.parseInt()` method parses a string argument and returns an
5682 /// integer of the specified radix or base.
5683 ///
5684 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
5685 #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
5686 pub fn parse_int(text: &str, radix: u8) -> f64;
5687
5688 /// The `Number.parseFloat()` method parses a string argument and returns a
5689 /// floating point number.
5690 ///
5691 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
5692 #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
5693 pub fn parse_float(text: &str) -> f64;
5694
5695 /// The `toLocaleString()` method returns a string with a language sensitive
5696 /// representation of this number.
5697 ///
5698 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
5699 #[cfg(not(js_sys_unstable_apis))]
5700 #[wasm_bindgen(method, js_name = toLocaleString)]
5701 pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
5702
5703 /// The `toLocaleString()` method returns a string with a language sensitive
5704 /// representation of this number.
5705 ///
5706 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
5707 #[cfg(js_sys_unstable_apis)]
5708 #[wasm_bindgen(method, js_name = toLocaleString)]
5709 pub fn to_locale_string(
5710 this: &Number,
5711 locales: &[JsString],
5712 options: &Intl::NumberFormatOptions,
5713 ) -> JsString;
5714
5715 /// The `toPrecision()` method returns a string representing the Number
5716 /// object to the specified precision.
5717 ///
5718 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
5719 #[wasm_bindgen(catch, method, js_name = toPrecision)]
5720 pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
5721
5722 /// The `toFixed()` method returns a string representing the Number
5723 /// object using fixed-point notation.
5724 ///
5725 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
5726 #[wasm_bindgen(catch, method, js_name = toFixed)]
5727 pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
5728
5729 /// The `toExponential()` method returns a string representing the Number
5730 /// object in exponential notation.
5731 ///
5732 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
5733 #[wasm_bindgen(catch, method, js_name = toExponential)]
5734 pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
5735
5736 /// The `toString()` method returns a string representing the
5737 /// specified Number object.
5738 ///
5739 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
5740 #[cfg(not(js_sys_unstable_apis))]
5741 #[deprecated(note = "Use `Number::to_string_with_radix` instead.")]
5742 #[allow(deprecated)]
5743 #[wasm_bindgen(catch, method, js_name = toString)]
5744 pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
5745
5746 /// The `toString()` method returns a string representing the
5747 /// specified Number object.
5748 ///
5749 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
5750 #[wasm_bindgen(catch, method, js_name = toString)]
5751 pub fn to_string_with_radix(this: &Number, radix: u8) -> Result<JsString, JsValue>;
5752
5753 /// The `valueOf()` method returns the wrapped primitive value of
5754 /// a Number object.
5755 ///
5756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
5757 #[wasm_bindgen(method, js_name = valueOf)]
5758 pub fn value_of(this: &Number) -> f64;
5759}
5760
5761impl Number {
5762 /// The smallest interval between two representable numbers.
5763 ///
5764 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
5765 pub const EPSILON: f64 = f64::EPSILON;
5766 /// The maximum safe integer in JavaScript (2^53 - 1).
5767 ///
5768 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
5769 pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
5770 /// The largest positive representable number.
5771 ///
5772 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
5773 pub const MAX_VALUE: f64 = f64::MAX;
5774 /// The minimum safe integer in JavaScript (-(2^53 - 1)).
5775 ///
5776 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
5777 pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
5778 /// The smallest positive representable number—that is, the positive number closest to zero
5779 /// (without actually being zero).
5780 ///
5781 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
5782 // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number.
5783 pub const MIN_VALUE: f64 = 5E-324;
5784 /// Special "Not a Number" value.
5785 ///
5786 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
5787 pub const NAN: f64 = f64::NAN;
5788 /// Special value representing negative infinity. Returned on overflow.
5789 ///
5790 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
5791 pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
5792 /// Special value representing infinity. Returned on overflow.
5793 ///
5794 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
5795 pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
5796
5797 /// Applies the binary `**` JS operator on the two `Number`s.
5798 ///
5799 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
5800 #[inline]
5801 pub fn pow(&self, rhs: &Self) -> Self {
5802 JsValue::as_ref(self)
5803 .pow(JsValue::as_ref(rhs))
5804 .unchecked_into()
5805 }
5806
5807 /// Applies the binary `>>>` JS operator on the two `Number`s.
5808 ///
5809 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
5810 #[inline]
5811 pub fn unsigned_shr(&self, rhs: &Self) -> Self {
5812 Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs)))
5813 }
5814}
5815
5816macro_rules! number_from {
5817 ($($x:ident)*) => ($(
5818 impl From<$x> for Number {
5819 #[inline]
5820 fn from(x: $x) -> Number {
5821 Number::unchecked_from_js(JsValue::from(x))
5822 }
5823 }
5824
5825 impl PartialEq<$x> for Number {
5826 #[inline]
5827 fn eq(&self, other: &$x) -> bool {
5828 self.value_of() == f64::from(*other)
5829 }
5830 }
5831
5832 impl UpcastFrom<$x> for Number {}
5833 )*)
5834}
5835number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
5836
5837// The only guarantee for a JS number
5838impl UpcastFrom<Number> for f64 {}
5839
5840/// The error type returned when a checked integral type conversion fails.
5841#[derive(Debug, Copy, Clone, PartialEq, Eq)]
5842pub struct TryFromIntError(());
5843
5844impl fmt::Display for TryFromIntError {
5845 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
5846 fmt.write_str("out of range integral type conversion attempted")
5847 }
5848}
5849
5850#[cfg(feature = "std")]
5851impl std::error::Error for TryFromIntError {}
5852
5853macro_rules! number_try_from {
5854 ($($x:ident)*) => ($(
5855 impl TryFrom<$x> for Number {
5856 type Error = TryFromIntError;
5857
5858 #[inline]
5859 fn try_from(x: $x) -> Result<Number, Self::Error> {
5860 let x_f64 = x as f64;
5861 if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) {
5862 Ok(Number::from(x_f64))
5863 } else {
5864 Err(TryFromIntError(()))
5865 }
5866 }
5867 }
5868 )*)
5869}
5870number_try_from!(i64 u64 i128 u128);
5871
5872impl From<&Number> for f64 {
5873 #[inline]
5874 fn from(n: &Number) -> f64 {
5875 n.value_of()
5876 }
5877}
5878
5879impl From<Number> for f64 {
5880 #[inline]
5881 fn from(n: Number) -> f64 {
5882 <f64 as From<&'_ Number>>::from(&n)
5883 }
5884}
5885
5886impl fmt::Debug for Number {
5887 #[inline]
5888 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5889 fmt::Debug::fmt(&self.value_of(), f)
5890 }
5891}
5892
5893impl fmt::Display for Number {
5894 #[inline]
5895 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5896 fmt::Display::fmt(&self.value_of(), f)
5897 }
5898}
5899
5900impl Default for Number {
5901 fn default() -> Self {
5902 Self::from(f64::default())
5903 }
5904}
5905
5906impl PartialEq<BigInt> for Number {
5907 #[inline]
5908 fn eq(&self, other: &BigInt) -> bool {
5909 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
5910 }
5911}
5912
5913impl Not for &Number {
5914 type Output = BigInt;
5915
5916 #[inline]
5917 fn not(self) -> Self::Output {
5918 JsValue::as_ref(self).bit_not().unchecked_into()
5919 }
5920}
5921
5922forward_deref_unop!(impl Not, not for Number);
5923forward_js_unop!(impl Neg, neg for Number);
5924forward_js_binop!(impl BitAnd, bitand for Number);
5925forward_js_binop!(impl BitOr, bitor for Number);
5926forward_js_binop!(impl BitXor, bitxor for Number);
5927forward_js_binop!(impl Shl, shl for Number);
5928forward_js_binop!(impl Shr, shr for Number);
5929forward_js_binop!(impl Add, add for Number);
5930forward_js_binop!(impl Sub, sub for Number);
5931forward_js_binop!(impl Div, div for Number);
5932forward_js_binop!(impl Mul, mul for Number);
5933forward_js_binop!(impl Rem, rem for Number);
5934
5935sum_product!(Number);
5936
5937impl PartialOrd for Number {
5938 #[inline]
5939 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
5940 if Number::is_nan(self) || Number::is_nan(other) {
5941 None
5942 } else if self == other {
5943 Some(Ordering::Equal)
5944 } else if self.lt(other) {
5945 Some(Ordering::Less)
5946 } else {
5947 Some(Ordering::Greater)
5948 }
5949 }
5950
5951 #[inline]
5952 fn lt(&self, other: &Self) -> bool {
5953 JsValue::as_ref(self).lt(JsValue::as_ref(other))
5954 }
5955
5956 #[inline]
5957 fn le(&self, other: &Self) -> bool {
5958 JsValue::as_ref(self).le(JsValue::as_ref(other))
5959 }
5960
5961 #[inline]
5962 fn ge(&self, other: &Self) -> bool {
5963 JsValue::as_ref(self).ge(JsValue::as_ref(other))
5964 }
5965
5966 #[inline]
5967 fn gt(&self, other: &Self) -> bool {
5968 JsValue::as_ref(self).gt(JsValue::as_ref(other))
5969 }
5970}
5971
5972#[cfg(not(js_sys_unstable_apis))]
5973impl FromStr for Number {
5974 type Err = Infallible;
5975
5976 #[allow(deprecated)]
5977 #[inline]
5978 fn from_str(s: &str) -> Result<Self, Self::Err> {
5979 Ok(Number::new_from_str(s))
5980 }
5981}
5982
5983// Date.
5984#[wasm_bindgen]
5985extern "C" {
5986 #[wasm_bindgen(extends = Object, typescript_type = "Date")]
5987 #[derive(Clone, Debug, PartialEq, Eq)]
5988 pub type Date;
5989
5990 /// The `getDate()` method returns the day of the month for the
5991 /// specified date according to local time.
5992 ///
5993 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
5994 #[wasm_bindgen(method, js_name = getDate)]
5995 pub fn get_date(this: &Date) -> u32;
5996
5997 /// The `getDay()` method returns the day of the week for the specified date according to local time,
5998 /// where 0 represents Sunday. For the day of the month see getDate().
5999 ///
6000 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
6001 #[wasm_bindgen(method, js_name = getDay)]
6002 pub fn get_day(this: &Date) -> u32;
6003
6004 /// The `getFullYear()` method returns the year of the specified date according to local time.
6005 ///
6006 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
6007 #[wasm_bindgen(method, js_name = getFullYear)]
6008 pub fn get_full_year(this: &Date) -> u32;
6009
6010 /// The `getHours()` method returns the hour for the specified date, according to local time.
6011 ///
6012 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
6013 #[wasm_bindgen(method, js_name = getHours)]
6014 pub fn get_hours(this: &Date) -> u32;
6015
6016 /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
6017 ///
6018 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
6019 #[wasm_bindgen(method, js_name = getMilliseconds)]
6020 pub fn get_milliseconds(this: &Date) -> u32;
6021
6022 /// The `getMinutes()` method returns the minutes in the specified date according to local time.
6023 ///
6024 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
6025 #[wasm_bindgen(method, js_name = getMinutes)]
6026 pub fn get_minutes(this: &Date) -> u32;
6027
6028 /// The `getMonth()` method returns the month in the specified date according to local time,
6029 /// as a zero-based value (where zero indicates the first month of the year).
6030 ///
6031 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
6032 #[wasm_bindgen(method, js_name = getMonth)]
6033 pub fn get_month(this: &Date) -> u32;
6034
6035 /// The `getSeconds()` method returns the seconds in the specified date according to local time.
6036 ///
6037 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
6038 #[wasm_bindgen(method, js_name = getSeconds)]
6039 pub fn get_seconds(this: &Date) -> u32;
6040
6041 /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
6042 /// according to universal time.
6043 ///
6044 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
6045 #[wasm_bindgen(method, js_name = getTime)]
6046 pub fn get_time(this: &Date) -> f64;
6047
6048 /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
6049 /// from current locale (host system settings) to UTC.
6050 ///
6051 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
6052 #[wasm_bindgen(method, js_name = getTimezoneOffset)]
6053 pub fn get_timezone_offset(this: &Date) -> f64;
6054
6055 /// The `getUTCDate()` method returns the day (date) of the month in the specified date
6056 /// according to universal time.
6057 ///
6058 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
6059 #[wasm_bindgen(method, js_name = getUTCDate)]
6060 pub fn get_utc_date(this: &Date) -> u32;
6061
6062 /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
6063 /// where 0 represents Sunday.
6064 ///
6065 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
6066 #[wasm_bindgen(method, js_name = getUTCDay)]
6067 pub fn get_utc_day(this: &Date) -> u32;
6068
6069 /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
6070 ///
6071 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
6072 #[wasm_bindgen(method, js_name = getUTCFullYear)]
6073 pub fn get_utc_full_year(this: &Date) -> u32;
6074
6075 /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
6076 ///
6077 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
6078 #[wasm_bindgen(method, js_name = getUTCHours)]
6079 pub fn get_utc_hours(this: &Date) -> u32;
6080
6081 /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date
6082 /// according to universal time.
6083 ///
6084 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds)
6085 #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
6086 pub fn get_utc_milliseconds(this: &Date) -> u32;
6087
6088 /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
6089 ///
6090 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
6091 #[wasm_bindgen(method, js_name = getUTCMinutes)]
6092 pub fn get_utc_minutes(this: &Date) -> u32;
6093
6094 /// The `getUTCMonth()` returns the month of the specified date according to universal time,
6095 /// as a zero-based value (where zero indicates the first month of the year).
6096 ///
6097 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
6098 #[wasm_bindgen(method, js_name = getUTCMonth)]
6099 pub fn get_utc_month(this: &Date) -> u32;
6100
6101 /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time.
6102 ///
6103 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds)
6104 #[wasm_bindgen(method, js_name = getUTCSeconds)]
6105 pub fn get_utc_seconds(this: &Date) -> u32;
6106
6107 /// Creates a JavaScript `Date` instance that represents
6108 /// a single moment in time. `Date` objects are based on a time value that is
6109 /// the number of milliseconds since 1 January 1970 UTC.
6110 ///
6111 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6112 #[wasm_bindgen(constructor)]
6113 pub fn new(init: &JsValue) -> Date;
6114
6115 /// Creates a JavaScript `Date` instance that represents the current moment in
6116 /// time.
6117 ///
6118 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6119 #[wasm_bindgen(constructor)]
6120 pub fn new_0() -> Date;
6121
6122 /// Creates a JavaScript `Date` instance that represents
6123 /// a single moment in time. `Date` objects are based on a time value that is
6124 /// the number of milliseconds since 1 January 1970 UTC.
6125 ///
6126 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6127 #[wasm_bindgen(constructor)]
6128 pub fn new_with_year_month(year: u32, month: i32) -> Date;
6129
6130 /// Creates a JavaScript `Date` instance that represents
6131 /// a single moment in time. `Date` objects are based on a time value that is
6132 /// the number of milliseconds since 1 January 1970 UTC.
6133 ///
6134 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6135 #[wasm_bindgen(constructor)]
6136 pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
6137
6138 /// Creates a JavaScript `Date` instance that represents
6139 /// a single moment in time. `Date` objects are based on a time value that is
6140 /// the number of milliseconds since 1 January 1970 UTC.
6141 ///
6142 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6143 #[wasm_bindgen(constructor)]
6144 pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
6145
6146 /// Creates a JavaScript `Date` instance that represents
6147 /// a single moment in time. `Date` objects are based on a time value that is
6148 /// the number of milliseconds since 1 January 1970 UTC.
6149 ///
6150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6151 #[wasm_bindgen(constructor)]
6152 pub fn new_with_year_month_day_hr_min(
6153 year: u32,
6154 month: i32,
6155 day: i32,
6156 hr: i32,
6157 min: i32,
6158 ) -> Date;
6159
6160 /// Creates a JavaScript `Date` instance that represents
6161 /// a single moment in time. `Date` objects are based on a time value that is
6162 /// the number of milliseconds since 1 January 1970 UTC.
6163 ///
6164 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6165 #[wasm_bindgen(constructor)]
6166 pub fn new_with_year_month_day_hr_min_sec(
6167 year: u32,
6168 month: i32,
6169 day: i32,
6170 hr: i32,
6171 min: i32,
6172 sec: i32,
6173 ) -> Date;
6174
6175 /// Creates a JavaScript `Date` instance that represents
6176 /// a single moment in time. `Date` objects are based on a time value that is
6177 /// the number of milliseconds since 1 January 1970 UTC.
6178 ///
6179 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6180 #[wasm_bindgen(constructor)]
6181 pub fn new_with_year_month_day_hr_min_sec_milli(
6182 year: u32,
6183 month: i32,
6184 day: i32,
6185 hr: i32,
6186 min: i32,
6187 sec: i32,
6188 milli: i32,
6189 ) -> Date;
6190
6191 /// The `Date.now()` method returns the number of milliseconds
6192 /// elapsed since January 1, 1970 00:00:00 UTC.
6193 ///
6194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
6195 #[wasm_bindgen(static_method_of = Date)]
6196 pub fn now() -> f64;
6197
6198 /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
6199 /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
6200 /// contains illegal date values (e.g. 2015-02-31).
6201 ///
6202 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
6203 #[wasm_bindgen(static_method_of = Date)]
6204 pub fn parse(date: &str) -> f64;
6205
6206 /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
6207 ///
6208 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
6209 #[wasm_bindgen(method, js_name = setDate)]
6210 pub fn set_date(this: &Date, day: u32) -> f64;
6211
6212 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6213 /// Returns new timestamp.
6214 ///
6215 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6216 #[wasm_bindgen(method, js_name = setFullYear)]
6217 pub fn set_full_year(this: &Date, year: u32) -> f64;
6218
6219 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6220 /// Returns new timestamp.
6221 ///
6222 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6223 #[wasm_bindgen(method, js_name = setFullYear)]
6224 pub fn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6225
6226 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6227 /// Returns new timestamp.
6228 ///
6229 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6230 #[wasm_bindgen(method, js_name = setFullYear)]
6231 pub fn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6232
6233 /// The `setHours()` method sets the hours for a specified date according to local time,
6234 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
6235 /// by the updated Date instance.
6236 ///
6237 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
6238 #[wasm_bindgen(method, js_name = setHours)]
6239 pub fn set_hours(this: &Date, hours: u32) -> f64;
6240
6241 /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
6242 ///
6243 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
6244 #[wasm_bindgen(method, js_name = setMilliseconds)]
6245 pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
6246
6247 /// The `setMinutes()` method sets the minutes for a specified date according to local time.
6248 ///
6249 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
6250 #[wasm_bindgen(method, js_name = setMinutes)]
6251 pub fn set_minutes(this: &Date, minutes: u32) -> f64;
6252
6253 /// The `setMonth()` method sets the month for a specified date according to the currently set year.
6254 ///
6255 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
6256 #[wasm_bindgen(method, js_name = setMonth)]
6257 pub fn set_month(this: &Date, month: u32) -> f64;
6258
6259 /// The `setSeconds()` method sets the seconds for a specified date according to local time.
6260 ///
6261 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
6262 #[wasm_bindgen(method, js_name = setSeconds)]
6263 pub fn set_seconds(this: &Date, seconds: u32) -> f64;
6264
6265 /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
6266 /// since January 1, 1970, 00:00:00 UTC.
6267 ///
6268 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
6269 #[wasm_bindgen(method, js_name = setTime)]
6270 pub fn set_time(this: &Date, time: f64) -> f64;
6271
6272 /// The `setUTCDate()` method sets the day of the month for a specified date
6273 /// according to universal time.
6274 ///
6275 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
6276 #[wasm_bindgen(method, js_name = setUTCDate)]
6277 pub fn set_utc_date(this: &Date, day: u32) -> f64;
6278
6279 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6280 ///
6281 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6282 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6283 pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
6284
6285 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6286 ///
6287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6288 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6289 pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6290
6291 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6292 ///
6293 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6294 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6295 pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6296
6297 /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
6298 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time
6299 /// represented by the updated Date instance.
6300 ///
6301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
6302 #[wasm_bindgen(method, js_name = setUTCHours)]
6303 pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
6304
6305 /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
6306 /// according to universal time.
6307 ///
6308 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
6309 #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
6310 pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
6311
6312 /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
6313 ///
6314 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
6315 #[wasm_bindgen(method, js_name = setUTCMinutes)]
6316 pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
6317
6318 /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
6319 ///
6320 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
6321 #[wasm_bindgen(method, js_name = setUTCMonth)]
6322 pub fn set_utc_month(this: &Date, month: u32) -> f64;
6323
6324 /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
6325 ///
6326 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
6327 #[wasm_bindgen(method, js_name = setUTCSeconds)]
6328 pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
6329
6330 /// The `toDateString()` method returns the date portion of a Date object
6331 /// in human readable form in American English.
6332 ///
6333 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
6334 #[wasm_bindgen(method, js_name = toDateString)]
6335 pub fn to_date_string(this: &Date) -> JsString;
6336
6337 /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
6338 /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
6339 /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
6340 /// as denoted by the suffix "Z"
6341 ///
6342 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
6343 #[wasm_bindgen(method, js_name = toISOString)]
6344 pub fn to_iso_string(this: &Date) -> JsString;
6345
6346 /// The `toJSON()` method returns a string representation of the Date object.
6347 ///
6348 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
6349 #[wasm_bindgen(method, js_name = toJSON)]
6350 pub fn to_json(this: &Date) -> JsString;
6351
6352 /// The `toLocaleDateString()` method returns a string with a language sensitive
6353 /// representation of the date portion of this date. The new locales and options
6354 /// arguments let applications specify the language whose formatting conventions
6355 /// should be used and allow to customize the behavior of the function.
6356 /// In older implementations, which ignore the locales and options arguments,
6357 /// the locale used and the form of the string
6358 /// returned are entirely implementation dependent.
6359 ///
6360 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6361 #[cfg(not(js_sys_unstable_apis))]
6362 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6363 pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6364
6365 /// The `toLocaleDateString()` method returns a string with a language sensitive
6366 /// representation of the date portion of this date.
6367 ///
6368 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6369 #[cfg(js_sys_unstable_apis)]
6370 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6371 pub fn to_locale_date_string(
6372 this: &Date,
6373 locales: &[JsString],
6374 options: &Intl::DateTimeFormatOptions,
6375 ) -> JsString;
6376
6377 /// The `toLocaleString()` method returns a string with a language sensitive
6378 /// representation of this date. The new locales and options arguments
6379 /// let applications specify the language whose formatting conventions
6380 /// should be used and customize the behavior of the function.
6381 /// In older implementations, which ignore the locales
6382 /// and options arguments, the locale used and the form of the string
6383 /// returned are entirely implementation dependent.
6384 ///
6385 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6386 #[cfg(not(js_sys_unstable_apis))]
6387 #[wasm_bindgen(method, js_name = toLocaleString)]
6388 pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6389
6390 /// The `toLocaleString()` method returns a string with a language sensitive
6391 /// representation of this date.
6392 ///
6393 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6394 #[cfg(js_sys_unstable_apis)]
6395 #[wasm_bindgen(method, js_name = toLocaleString)]
6396 pub fn to_locale_string(
6397 this: &Date,
6398 locales: &[JsString],
6399 options: &Intl::DateTimeFormatOptions,
6400 ) -> JsString;
6401
6402 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6403 /// representation of the time portion of this date. The new locales and options
6404 /// arguments let applications specify the language whose formatting conventions should be
6405 /// used and customize the behavior of the function. In older implementations, which ignore
6406 /// the locales and options arguments, the locale used and the form of the string
6407 /// returned are entirely implementation dependent.
6408 ///
6409 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6410 #[cfg(not(js_sys_unstable_apis))]
6411 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6412 pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
6413
6414 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6415 /// representation of the time portion of this date.
6416 ///
6417 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6418 #[cfg(js_sys_unstable_apis)]
6419 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6420 pub fn to_locale_time_string(
6421 this: &Date,
6422 locales: &[JsString],
6423 options: &Intl::DateTimeFormatOptions,
6424 ) -> JsString;
6425
6426 #[cfg(not(js_sys_unstable_apis))]
6427 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6428 pub fn to_locale_time_string_with_options(
6429 this: &Date,
6430 locale: &str,
6431 options: &JsValue,
6432 ) -> JsString;
6433
6434 /// The `toString()` method returns a string representing
6435 /// the specified Date object.
6436 ///
6437 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
6438 #[cfg(not(js_sys_unstable_apis))]
6439 #[wasm_bindgen(method, js_name = toString)]
6440 pub fn to_string(this: &Date) -> JsString;
6441
6442 /// The `toTimeString()` method returns the time portion of a Date object in human
6443 /// readable form in American English.
6444 ///
6445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
6446 #[wasm_bindgen(method, js_name = toTimeString)]
6447 pub fn to_time_string(this: &Date) -> JsString;
6448
6449 /// The `toUTCString()` method converts a date to a string,
6450 /// using the UTC time zone.
6451 ///
6452 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
6453 #[wasm_bindgen(method, js_name = toUTCString)]
6454 pub fn to_utc_string(this: &Date) -> JsString;
6455
6456 /// The `Date.UTC()` method accepts the same parameters as the
6457 /// longest form of the constructor, and returns the number of
6458 /// milliseconds in a `Date` object since January 1, 1970,
6459 /// 00:00:00, universal time.
6460 ///
6461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
6462 #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
6463 pub fn utc(year: f64, month: f64) -> f64;
6464
6465 /// The `valueOf()` method returns the primitive value of
6466 /// a Date object.
6467 ///
6468 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
6469 #[wasm_bindgen(method, js_name = valueOf)]
6470 pub fn value_of(this: &Date) -> f64;
6471
6472 /// The `toTemporalInstant()` method converts a legacy `Date` object to a
6473 /// `Temporal.Instant` object representing the same moment in time.
6474 ///
6475 /// This method is added by the Temporal proposal to facilitate migration
6476 /// from legacy `Date` to the new Temporal API.
6477 ///
6478 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTemporalInstant)
6479 #[cfg(js_sys_unstable_apis)]
6480 #[wasm_bindgen(method, js_name = toTemporalInstant)]
6481 pub fn to_temporal_instant(this: &Date) -> Temporal::Instant;
6482}
6483
6484// Property Descriptor.
6485#[wasm_bindgen]
6486extern "C" {
6487 #[wasm_bindgen(extends = Object)]
6488 #[derive(Clone, Debug)]
6489 pub type PropertyDescriptor<T = JsValue>;
6490
6491 #[wasm_bindgen(method, getter = writable)]
6492 pub fn get_writable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6493
6494 #[wasm_bindgen(method, setter = writable)]
6495 pub fn set_writable<T>(this: &PropertyDescriptor<T>, writable: bool);
6496
6497 #[wasm_bindgen(method, getter = enumerable)]
6498 pub fn get_enumerable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6499
6500 #[wasm_bindgen(method, setter = enumerable)]
6501 pub fn set_enumerable<T>(this: &PropertyDescriptor<T>, enumerable: bool);
6502
6503 #[wasm_bindgen(method, getter = configurable)]
6504 pub fn get_configurable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6505
6506 #[wasm_bindgen(method, setter = configurable)]
6507 pub fn set_configurable<T>(this: &PropertyDescriptor<T>, configurable: bool);
6508
6509 #[wasm_bindgen(method, getter = get)]
6510 pub fn get_get<T: JsGeneric>(this: &PropertyDescriptor<T>) -> Option<Function<fn() -> T>>;
6511
6512 #[wasm_bindgen(method, setter = get)]
6513 pub fn set_get<T: JsGeneric>(this: &PropertyDescriptor<T>, get: Function<fn() -> T>);
6514
6515 #[wasm_bindgen(method, getter = set)]
6516 pub fn get_set<T: JsGeneric>(
6517 this: &PropertyDescriptor<T>,
6518 ) -> Option<Function<fn(T) -> JsValue>>;
6519
6520 #[wasm_bindgen(method, setter = set)]
6521 pub fn set_set<T: JsGeneric>(this: &PropertyDescriptor<T>, set: Function<fn(T) -> JsValue>);
6522
6523 #[wasm_bindgen(method, getter = value)]
6524 pub fn get_value<T>(this: &PropertyDescriptor<T>) -> Option<T>;
6525
6526 #[wasm_bindgen(method, setter = value)]
6527 pub fn set_value<T>(this: &PropertyDescriptor<T>, value: &T);
6528}
6529
6530impl PropertyDescriptor {
6531 #[cfg(not(js_sys_unstable_apis))]
6532 pub fn new<T>() -> PropertyDescriptor<T> {
6533 JsCast::unchecked_into(Object::new())
6534 }
6535
6536 #[cfg(js_sys_unstable_apis)]
6537 pub fn new<T>() -> PropertyDescriptor<T> {
6538 JsCast::unchecked_into(Object::<JsValue>::new())
6539 }
6540
6541 #[cfg(not(js_sys_unstable_apis))]
6542 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6543 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::new());
6544 desc.set_value(value);
6545 desc
6546 }
6547
6548 #[cfg(js_sys_unstable_apis)]
6549 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6550 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::<JsValue>::new());
6551 desc.set_value(value);
6552 desc
6553 }
6554}
6555
6556impl Default for PropertyDescriptor {
6557 fn default() -> Self {
6558 PropertyDescriptor::new()
6559 }
6560}
6561
6562// Object.
6563#[wasm_bindgen]
6564extern "C" {
6565 #[wasm_bindgen(typescript_type = "object")]
6566 #[derive(Clone, Debug)]
6567 pub type Object<T = JsValue>;
6568
6569 // Next major: deprecate
6570 /// The `Object.assign()` method is used to copy the values of all enumerable
6571 /// own properties from one or more source objects to a target object. It
6572 /// will return the target object.
6573 ///
6574 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6575 ///
6576 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6577 #[wasm_bindgen(static_method_of = Object)]
6578 pub fn assign<T>(target: &Object<T>, source: &Object<T>) -> Object<T>;
6579
6580 // Next major: deprecate
6581 /// The `Object.assign()` method is used to copy the values of all enumerable
6582 /// own properties from one or more source objects to a target object. It
6583 /// will return the target object.
6584 ///
6585 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6586 ///
6587 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6588 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch)]
6589 pub fn try_assign<T>(target: &Object<T>, source: &Object<T>) -> Result<Object<T>, JsValue>;
6590
6591 /// The `Object.assign()` method is used to copy the values of all enumerable
6592 /// own properties from one or more source objects to a target object. It
6593 /// will return the target object.
6594 ///
6595 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6596 #[cfg(not(js_sys_unstable_apis))]
6597 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6598 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6599 #[allow(deprecated)]
6600 pub fn assign2<T>(target: &Object<T>, source1: &Object<T>, source2: &Object<T>) -> Object<T>;
6601
6602 /// The `Object.assign()` method is used to copy the values of all enumerable
6603 /// own properties from one or more source objects to a target object. It
6604 /// will return the target object.
6605 ///
6606 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6607 #[cfg(not(js_sys_unstable_apis))]
6608 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6609 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6610 #[allow(deprecated)]
6611 pub fn assign3<T>(
6612 target: &Object<T>,
6613 source1: &Object<T>,
6614 source2: &Object<T>,
6615 source3: &Object<T>,
6616 ) -> Object<T>;
6617
6618 /// The `Object.assign()` method is used to copy the values of all enumerable
6619 /// own properties from one or more source objects to a target object. It
6620 /// will return the target object.
6621 ///
6622 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6623 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch, variadic)]
6624 pub fn assign_many<T>(target: &Object<T>, sources: &[Object<T>]) -> Result<Object<T>, JsValue>;
6625
6626 /// The constructor property returns a reference to the `Object` constructor
6627 /// function that created the instance object.
6628 ///
6629 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
6630 #[wasm_bindgen(method, getter)]
6631 pub fn constructor<T>(this: &Object<T>) -> Function;
6632
6633 /// The `Object.create()` method creates a new object, using an existing
6634 /// object to provide the newly created object's prototype.
6635 ///
6636 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
6637 #[wasm_bindgen(static_method_of = Object)]
6638 pub fn create<T>(prototype: &Object<T>) -> Object<T>;
6639
6640 /// The static method `Object.defineProperty()` defines a new
6641 /// property directly on an object, or modifies an existing
6642 /// property on an object, and returns the object.
6643 ///
6644 /// **Note:** Consider using [`Object::define_property_str`] to support typing and error handling.
6645 ///
6646 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6647 #[cfg(not(js_sys_unstable_apis))]
6648 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
6649 pub fn define_property<T>(obj: &Object<T>, prop: &JsValue, descriptor: &Object) -> Object<T>;
6650
6651 /// The static method `Object.defineProperty()` defines a new
6652 /// property directly on an object, or modifies an existing
6653 /// property on an object, and returns the object.
6654 ///
6655 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6656 #[cfg(js_sys_unstable_apis)]
6657 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6658 pub fn define_property<T>(
6659 obj: &Object<T>,
6660 prop: &JsString,
6661 descriptor: &PropertyDescriptor<T>,
6662 ) -> Result<Object<T>, JsValue>;
6663
6664 // Next major: deprecate
6665 /// The static method `Object.defineProperty()` defines a new
6666 /// property directly on an object, or modifies an existing
6667 /// property on an object, and returns the object.
6668 ///
6669 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6670 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6671 pub fn define_property_str<T>(
6672 obj: &Object<T>,
6673 prop: &JsString,
6674 descriptor: &PropertyDescriptor<T>,
6675 ) -> Result<Object<T>, JsValue>;
6676
6677 /// The static method `Object.defineProperty()` defines a new
6678 /// property directly on an object, or modifies an existing
6679 /// property on an object, and returns the object.
6680 ///
6681 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6682 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6683 pub fn define_property_symbol<T>(
6684 obj: &Object<T>,
6685 prop: &Symbol,
6686 descriptor: &PropertyDescriptor<JsValue>,
6687 ) -> Result<Object<T>, JsValue>;
6688
6689 /// The `Object.defineProperties()` method defines new or modifies
6690 /// existing properties directly on an object, returning the
6691 /// object.
6692 ///
6693 /// **Note:** Consider using [`Object::try_define_properties`] to support typing and error handling.
6694 ///
6695 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
6696 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
6697 pub fn define_properties<T>(obj: &Object<T>, props: &Object) -> Object<T>;
6698
6699 /// The `Object.defineProperties()` method defines new or modifies
6700 /// existing properties directly on an object, returning the
6701 /// object.
6702 ///
6703 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
6704 #[cfg(js_sys_unstable_apis)]
6705 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties, catch)]
6706 pub fn try_define_properties<T>(
6707 obj: &Object<T>,
6708 props: &Object<PropertyDescriptor<T>>,
6709 ) -> Result<Object<T>, JsValue>;
6710
6711 /// The `Object.entries()` method returns an array of a given
6712 /// object's own enumerable property [key, value] pairs, in the
6713 /// same order as that provided by a for...in loop (the difference
6714 /// being that a for-in loop enumerates properties in the
6715 /// prototype chain as well).
6716 ///
6717 /// **Note:** Consider using [`Object::entries_typed`] to support typing and error handling.
6718 ///
6719 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6720 #[cfg(not(js_sys_unstable_apis))]
6721 #[wasm_bindgen(static_method_of = Object)]
6722 pub fn entries(object: &Object) -> Array;
6723
6724 /// The `Object.entries()` method returns an array of a given
6725 /// object's own enumerable property [key, value] pairs, in the
6726 /// same order as that provided by a for...in loop (the difference
6727 /// being that a for-in loop enumerates properties in the
6728 /// prototype chain as well).
6729 ///
6730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6731 #[cfg(js_sys_unstable_apis)]
6732 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
6733 pub fn entries<T: JsGeneric>(
6734 object: &Object<T>,
6735 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
6736
6737 // Next major: deprecate
6738 /// The `Object.entries()` method returns an array of a given
6739 /// object's own enumerable property [key, value] pairs, in the
6740 /// same order as that provided by a for...in loop (the difference
6741 /// being that a for-in loop enumerates properties in the
6742 /// prototype chain as well).
6743 ///
6744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6745 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
6746 pub fn entries_typed<T: JsGeneric>(
6747 object: &Object<T>,
6748 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
6749
6750 /// The `Object.freeze()` method freezes an object: that is, prevents new
6751 /// properties from being added to it; prevents existing properties from
6752 /// being removed; and prevents existing properties, or their enumerability,
6753 /// configurability, or writability, from being changed, it also prevents
6754 /// the prototype from being changed. The method returns the passed object.
6755 ///
6756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
6757 #[wasm_bindgen(static_method_of = Object)]
6758 pub fn freeze<T>(value: &Object<T>) -> Object<T>;
6759
6760 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6761 /// into an object.
6762 ///
6763 /// **Note:** Consider using [`Object::from_entries_typed`] to support typing and error handling.
6764 ///
6765 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6766 #[cfg(not(js_sys_unstable_apis))]
6767 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6768 pub fn from_entries(entries: &JsValue) -> Result<Object, JsValue>;
6769
6770 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6771 /// into an object.
6772 ///
6773 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6774 #[cfg(js_sys_unstable_apis)]
6775 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6776 pub fn from_entries<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
6777 entries: &I,
6778 ) -> Result<Object<T>, JsValue>;
6779
6780 // Next major: deprecate
6781 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6782 /// into an object.
6783 ///
6784 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6785 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6786 pub fn from_entries_typed<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
6787 entries: &I,
6788 ) -> Result<Object<T>, JsValue>;
6789
6790 /// The `Object.getOwnPropertyDescriptor()` method returns a
6791 /// property descriptor for an own property (that is, one directly
6792 /// present on an object and not in the object's prototype chain)
6793 /// of a given object.
6794 ///
6795 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6796 #[cfg(not(js_sys_unstable_apis))]
6797 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
6798 pub fn get_own_property_descriptor<T>(obj: &Object<T>, prop: &JsValue) -> JsValue;
6799
6800 /// The `Object.getOwnPropertyDescriptor()` method returns a
6801 /// property descriptor for an own property (that is, one directly
6802 /// present on an object and not in the object's prototype chain)
6803 /// of a given object.
6804 ///
6805 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6806 #[cfg(js_sys_unstable_apis)]
6807 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6808 pub fn get_own_property_descriptor<T>(
6809 obj: &Object<T>,
6810 prop: &JsString,
6811 ) -> Result<PropertyDescriptor<T>, JsValue>;
6812
6813 // Next major: deprecate
6814 /// The `Object.getOwnPropertyDescriptor()` method returns a
6815 /// property descriptor for an own property (that is, one directly
6816 /// present on an object and not in the object's prototype chain)
6817 /// of a given object.
6818 ///
6819 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6820 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6821 pub fn get_own_property_descriptor_str<T>(
6822 obj: &Object<T>,
6823 prop: &JsString,
6824 ) -> Result<PropertyDescriptor<T>, JsValue>;
6825
6826 /// The `Object.getOwnPropertyDescriptor()` method returns a
6827 /// property descriptor for an own property (that is, one directly
6828 /// present on an object and not in the object's prototype chain)
6829 /// of a given object.
6830 ///
6831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6832 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6833 pub fn get_own_property_descriptor_symbol<T>(
6834 obj: &Object<T>,
6835 prop: &Symbol,
6836 ) -> Result<PropertyDescriptor<JsValue>, JsValue>;
6837
6838 /// The `Object.getOwnPropertyDescriptors()` method returns all own
6839 /// property descriptors of a given object.
6840 ///
6841 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
6842 #[cfg(not(js_sys_unstable_apis))]
6843 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
6844 pub fn get_own_property_descriptors<T>(obj: &Object<T>) -> JsValue;
6845
6846 /// The `Object.getOwnPropertyDescriptors()` method returns all own
6847 /// property descriptors of a given object.
6848 ///
6849 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
6850 #[cfg(js_sys_unstable_apis)]
6851 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors, catch)]
6852 pub fn get_own_property_descriptors<T>(
6853 obj: &Object<T>,
6854 ) -> Result<Object<PropertyDescriptor<T>>, JsValue>;
6855
6856 /// The `Object.getOwnPropertyNames()` method returns an array of
6857 /// all properties (including non-enumerable properties except for
6858 /// those which use Symbol) found directly upon a given object.
6859 ///
6860 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
6861 #[cfg(not(js_sys_unstable_apis))]
6862 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
6863 pub fn get_own_property_names<T>(obj: &Object<T>) -> Array;
6864
6865 /// The `Object.getOwnPropertyNames()` method returns an array of
6866 /// all properties (including non-enumerable properties except for
6867 /// those which use Symbol) found directly upon a given object.
6868 ///
6869 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
6870 #[cfg(js_sys_unstable_apis)]
6871 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames, catch)]
6872 pub fn get_own_property_names<T>(obj: &Object<T>) -> Result<Array<JsString>, JsValue>;
6873
6874 /// The `Object.getOwnPropertySymbols()` method returns an array of
6875 /// all symbol properties found directly upon a given object.
6876 ///
6877 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
6878 #[cfg(not(js_sys_unstable_apis))]
6879 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
6880 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Array;
6881
6882 /// The `Object.getOwnPropertySymbols()` method returns an array of
6883 /// all symbol properties found directly upon a given object.
6884 ///
6885 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
6886 #[cfg(js_sys_unstable_apis)]
6887 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols, catch)]
6888 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Result<Array<Symbol>, JsValue>;
6889
6890 /// The `Object.getPrototypeOf()` method returns the prototype
6891 /// (i.e. the value of the internal [[Prototype]] property) of the
6892 /// specified object.
6893 ///
6894 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
6895 #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
6896 pub fn get_prototype_of(obj: &JsValue) -> Object;
6897
6898 /// The `hasOwnProperty()` method returns a boolean indicating whether the
6899 /// object has the specified property as its own property (as opposed to
6900 /// inheriting it).
6901 ///
6902 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
6903 #[deprecated(note = "Use `Object::hasOwn` instead.")]
6904 #[allow(deprecated)]
6905 #[wasm_bindgen(method, js_name = hasOwnProperty)]
6906 pub fn has_own_property<T>(this: &Object<T>, property: &JsValue) -> bool;
6907
6908 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6909 /// object passed in has the specified property as its own property (as
6910 /// opposed to inheriting it).
6911 ///
6912 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6913 #[cfg(not(js_sys_unstable_apis))]
6914 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn)]
6915 pub fn has_own<T>(instance: &Object<T>, property: &JsValue) -> bool;
6916
6917 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6918 /// object passed in has the specified property as its own property (as
6919 /// opposed to inheriting it).
6920 ///
6921 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6922 #[cfg(js_sys_unstable_apis)]
6923 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6924 pub fn has_own<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
6925
6926 // Next major: deprecate
6927 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6928 /// object passed in has the specified property as its own property (as
6929 /// opposed to inheriting it).
6930 ///
6931 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6932 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6933 pub fn has_own_str<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
6934
6935 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6936 /// object passed in has the specified property as its own property (as
6937 /// opposed to inheriting it).
6938 ///
6939 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6940 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6941 pub fn has_own_symbol<T>(instance: &Object<T>, property: &Symbol) -> Result<bool, JsValue>;
6942
6943 /// The `Object.is()` method determines whether two values are the same value.
6944 ///
6945 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
6946 #[wasm_bindgen(static_method_of = Object)]
6947 pub fn is(value1: &JsValue, value_2: &JsValue) -> bool;
6948
6949 /// The `Object.isExtensible()` method determines if an object is extensible
6950 /// (whether it can have new properties added to it).
6951 ///
6952 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
6953 #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
6954 pub fn is_extensible<T>(object: &Object<T>) -> bool;
6955
6956 /// The `Object.isFrozen()` determines if an object is frozen.
6957 ///
6958 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
6959 #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
6960 pub fn is_frozen<T>(object: &Object<T>) -> bool;
6961
6962 /// The `Object.isSealed()` method determines if an object is sealed.
6963 ///
6964 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
6965 #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
6966 pub fn is_sealed<T>(object: &Object<T>) -> bool;
6967
6968 /// The `isPrototypeOf()` method checks if an object exists in another
6969 /// object's prototype chain.
6970 ///
6971 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
6972 #[wasm_bindgen(method, js_name = isPrototypeOf)]
6973 pub fn is_prototype_of<T>(this: &Object<T>, value: &JsValue) -> bool;
6974
6975 /// The `Object.keys()` method returns an array of a given object's property
6976 /// names, in the same order as we get with a normal loop.
6977 ///
6978 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
6979 #[cfg(not(js_sys_unstable_apis))]
6980 #[wasm_bindgen(static_method_of = Object)]
6981 pub fn keys<T>(object: &Object<T>) -> Array;
6982
6983 /// The `Object.keys()` method returns an array of a given object's property
6984 /// names, in the same order as we get with a normal loop.
6985 ///
6986 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
6987 #[cfg(js_sys_unstable_apis)]
6988 #[wasm_bindgen(static_method_of = Object)]
6989 pub fn keys<T>(object: &Object<T>) -> Array<JsString>;
6990
6991 /// The [`Object`] constructor creates an object wrapper.
6992 ///
6993 /// **Note:** Consider using [`Object::new_typed`] for typed object records.
6994 ///
6995 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
6996 #[wasm_bindgen(constructor)]
6997 pub fn new() -> Object;
6998
6999 // Next major: deprecate
7000 /// The [`Object`] constructor creates an object wrapper.
7001 ///
7002 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7003 #[wasm_bindgen(constructor)]
7004 pub fn new_typed<T>() -> Object<T>;
7005
7006 /// The `Object.preventExtensions()` method prevents new properties from
7007 /// ever being added to an object (i.e. prevents future extensions to the
7008 /// object).
7009 ///
7010 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
7011 #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
7012 pub fn prevent_extensions<T>(object: &Object<T>);
7013
7014 /// The `propertyIsEnumerable()` method returns a Boolean indicating
7015 /// whether the specified property is enumerable.
7016 ///
7017 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7018 #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
7019 pub fn property_is_enumerable<T>(this: &Object<T>, property: &JsValue) -> bool;
7020
7021 /// The `Object.seal()` method seals an object, preventing new properties
7022 /// from being added to it and marking all existing properties as
7023 /// non-configurable. Values of present properties can still be changed as
7024 /// long as they are writable.
7025 ///
7026 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
7027 #[wasm_bindgen(static_method_of = Object)]
7028 pub fn seal<T>(value: &Object<T>) -> Object<T>;
7029
7030 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7031 /// internal `[[Prototype]]` property) of a specified object to another
7032 /// object or `null`.
7033 ///
7034 /// **Note:** Consider using [`Object::try_set_prototype_of`] to support errors.
7035 ///
7036 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7037 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
7038 pub fn set_prototype_of<T>(object: &Object<T>, prototype: &Object) -> Object<T>;
7039
7040 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7041 /// internal `[[Prototype]]` property) of a specified object to another
7042 /// object or `null`.
7043 ///
7044 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7045 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf, catch)]
7046 pub fn try_set_prototype_of<T>(
7047 object: &Object<T>,
7048 prototype: &Object,
7049 ) -> Result<Object<T>, JsValue>;
7050
7051 /// The `toLocaleString()` method returns a string representing the object.
7052 /// This method is meant to be overridden by derived objects for
7053 /// locale-specific purposes.
7054 ///
7055 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
7056 #[wasm_bindgen(method, js_name = toLocaleString)]
7057 pub fn to_locale_string<T>(this: &Object<T>) -> JsString;
7058
7059 // Next major: deprecate
7060 /// The `toString()` method returns a string representing the object.
7061 ///
7062 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7063 #[wasm_bindgen(method, js_name = toString)]
7064 pub fn to_string<T>(this: &Object<T>) -> JsString;
7065
7066 /// The `toString()` method returns a string representing the object.
7067 ///
7068 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7069 #[wasm_bindgen(method, js_name = toString)]
7070 pub fn to_js_string<T>(this: &Object<T>) -> JsString;
7071
7072 /// The `valueOf()` method returns the primitive value of the
7073 /// specified object.
7074 ///
7075 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
7076 #[wasm_bindgen(method, js_name = valueOf)]
7077 pub fn value_of<T>(this: &Object<T>) -> Object;
7078
7079 /// The `Object.values()` method returns an array of a given object's own
7080 /// enumerable property values, in the same order as that provided by a
7081 /// `for...in` loop (the difference being that a for-in loop enumerates
7082 /// properties in the prototype chain as well).
7083 ///
7084 /// **Note:** Consider using [`Object::try_values`] to support errors.
7085 ///
7086 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7087 #[cfg(not(js_sys_unstable_apis))]
7088 #[wasm_bindgen(static_method_of = Object)]
7089 pub fn values<T>(object: &Object<T>) -> Array<T>;
7090
7091 /// The `Object.values()` method returns an array of a given object's own
7092 /// enumerable property values, in the same order as that provided by a
7093 /// `for...in` loop (the difference being that a for-in loop enumerates
7094 /// properties in the prototype chain as well).
7095 ///
7096 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7097 #[cfg(js_sys_unstable_apis)]
7098 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7099 pub fn values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7100
7101 // Next major: deprecate
7102 /// The `Object.values()` method returns an array of a given object's own
7103 /// enumerable property values, in the same order as that provided by a
7104 /// `for...in` loop (the difference being that a for-in loop enumerates
7105 /// properties in the prototype chain as well).
7106 ///
7107 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7108 #[cfg(not(js_sys_unstable_apis))]
7109 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7110 pub fn try_values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7111}
7112
7113impl Object {
7114 /// Returns the `Object` value of this JS value if it's an instance of an
7115 /// object.
7116 ///
7117 /// If this JS value is not an instance of an object then this returns
7118 /// `None`.
7119 pub fn try_from(val: &JsValue) -> Option<&Object> {
7120 if val.is_object() {
7121 Some(val.unchecked_ref())
7122 } else {
7123 None
7124 }
7125 }
7126}
7127
7128impl PartialEq for Object {
7129 #[inline]
7130 fn eq(&self, other: &Object) -> bool {
7131 Object::is(self.as_ref(), other.as_ref())
7132 }
7133}
7134
7135impl Eq for Object {}
7136
7137impl Default for Object<JsValue> {
7138 fn default() -> Self {
7139 Self::new()
7140 }
7141}
7142
7143// Proxy
7144#[wasm_bindgen]
7145extern "C" {
7146 #[wasm_bindgen(typescript_type = "ProxyConstructor")]
7147 #[derive(Clone, Debug)]
7148 pub type Proxy;
7149
7150 /// The [`Proxy`] object is used to define custom behavior for fundamental
7151 /// operations (e.g. property lookup, assignment, enumeration, function
7152 /// invocation, etc).
7153 ///
7154 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
7155 #[wasm_bindgen(constructor)]
7156 pub fn new(target: &JsValue, handler: &Object) -> Proxy;
7157
7158 /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
7159 /// object.
7160 ///
7161 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
7162 #[wasm_bindgen(static_method_of = Proxy)]
7163 pub fn revocable(target: &JsValue, handler: &Object) -> Object;
7164}
7165
7166// RangeError
7167#[wasm_bindgen]
7168extern "C" {
7169 /// The `RangeError` object indicates an error when a value is not in the set
7170 /// or range of allowed values.
7171 ///
7172 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7173 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
7174 #[derive(Clone, Debug, PartialEq, Eq)]
7175 pub type RangeError;
7176
7177 /// The `RangeError` object indicates an error when a value is not in the set
7178 /// or range of allowed values.
7179 ///
7180 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7181 #[wasm_bindgen(constructor)]
7182 pub fn new(message: &str) -> RangeError;
7183}
7184
7185// ReferenceError
7186#[wasm_bindgen]
7187extern "C" {
7188 /// The `ReferenceError` object represents an error when a non-existent
7189 /// variable is referenced.
7190 ///
7191 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7192 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
7193 #[derive(Clone, Debug, PartialEq, Eq)]
7194 pub type ReferenceError;
7195
7196 /// The `ReferenceError` object represents an error when a non-existent
7197 /// variable is referenced.
7198 ///
7199 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7200 #[wasm_bindgen(constructor)]
7201 pub fn new(message: &str) -> ReferenceError;
7202}
7203
7204#[allow(non_snake_case)]
7205pub mod Reflect {
7206 use super::*;
7207
7208 // Reflect
7209 #[wasm_bindgen]
7210 extern "C" {
7211 /// The static `Reflect.apply()` method calls a target function with
7212 /// arguments as specified.
7213 ///
7214 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
7215 #[wasm_bindgen(js_namespace = Reflect, catch)]
7216 pub fn apply<T: JsFunction = fn() -> JsValue>(
7217 target: &Function<T>,
7218 this_argument: &JsValue,
7219 arguments_list: &Array,
7220 ) -> Result<<T as JsFunction>::Ret, JsValue>;
7221
7222 /// The static `Reflect.construct()` method acts like the new operator, but
7223 /// as a function. It is equivalent to calling `new target(...args)`. It
7224 /// gives also the added option to specify a different prototype.
7225 ///
7226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7227 #[cfg(not(js_sys_unstable_apis))]
7228 #[wasm_bindgen(js_namespace = Reflect, catch)]
7229 pub fn construct<T: JsFunction = fn() -> JsValue>(
7230 target: &Function<T>,
7231 arguments_list: &Array,
7232 ) -> Result<JsValue, JsValue>;
7233
7234 /// The static `Reflect.construct()` method acts like the new operator, but
7235 /// as a function. It is equivalent to calling `new target(...args)`. It
7236 /// gives also the added option to specify a different prototype.
7237 ///
7238 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7239 #[cfg(js_sys_unstable_apis)]
7240 #[wasm_bindgen(js_namespace = Reflect, catch)]
7241 pub fn construct<T: JsFunction = fn() -> JsValue>(
7242 target: &Function<T>,
7243 arguments_list: &ArrayTuple, // DOTO: <A1, A2, A3, A4, A5, A6, A7, A8>,
7244 ) -> Result<JsValue, JsValue>;
7245
7246 /// The static `Reflect.construct()` method acts like the new operator, but
7247 /// as a function. It is equivalent to calling `new target(...args)`. It
7248 /// gives also the added option to specify a different prototype.
7249 ///
7250 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7251 #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
7252 pub fn construct_with_new_target(
7253 target: &Function,
7254 arguments_list: &Array,
7255 new_target: &Function,
7256 ) -> Result<JsValue, JsValue>;
7257
7258 /// The static `Reflect.defineProperty()` method is like
7259 /// `Object.defineProperty()` but returns a `Boolean`.
7260 ///
7261 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7262 #[cfg(not(js_sys_unstable_apis))]
7263 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7264 pub fn define_property<T>(
7265 target: &Object<T>,
7266 property_key: &JsValue,
7267 attributes: &Object,
7268 ) -> Result<bool, JsValue>;
7269
7270 /// The static `Reflect.defineProperty()` method is like
7271 /// `Object.defineProperty()` but returns a `Boolean`.
7272 ///
7273 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7274 #[cfg(js_sys_unstable_apis)]
7275 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7276 pub fn define_property<T>(
7277 target: &Object<T>,
7278 property_key: &JsValue,
7279 attributes: &PropertyDescriptor<T>,
7280 ) -> Result<bool, JsValue>;
7281
7282 /// The static `Reflect.defineProperty()` method is like
7283 /// `Object.defineProperty()` but returns a `Boolean`.
7284 ///
7285 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7286 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7287 pub fn define_property_str<T>(
7288 target: &Object<T>,
7289 property_key: &JsString,
7290 attributes: &PropertyDescriptor<T>,
7291 ) -> Result<bool, JsValue>;
7292
7293 /// The static `Reflect.deleteProperty()` method allows to delete
7294 /// properties. It is like the `delete` operator as a function.
7295 ///
7296 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7297 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7298 pub fn delete_property<T>(target: &Object<T>, key: &JsValue) -> Result<bool, JsValue>;
7299
7300 /// The static `Reflect.deleteProperty()` method allows to delete
7301 /// properties. It is like the `delete` operator as a function.
7302 ///
7303 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7304 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7305 pub fn delete_property_str<T>(target: &Object<T>, key: &JsString) -> Result<bool, JsValue>;
7306
7307 /// The static `Reflect.get()` method works like getting a property from
7308 /// an object (`target[propertyKey]`) as a function.
7309 ///
7310 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7311 #[cfg(not(js_sys_unstable_apis))]
7312 #[wasm_bindgen(js_namespace = Reflect, catch)]
7313 pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
7314
7315 /// The static `Reflect.get()` method works like getting a property from
7316 /// an object (`target[propertyKey]`) as a function.
7317 ///
7318 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7319 #[cfg(js_sys_unstable_apis)]
7320 #[wasm_bindgen(js_namespace = Reflect, catch)]
7321 pub fn get<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7322
7323 /// The static `Reflect.get()` method works like getting a property from
7324 /// an object (`target[propertyKey]`) as a function.
7325 ///
7326 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7327 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7328 pub fn get_str<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7329
7330 /// The static `Reflect.get()` method works like getting a property from
7331 /// an object (`target[propertyKey]`) as a function.
7332 ///
7333 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7334 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7335 pub fn get_symbol<T>(target: &Object<T>, key: &Symbol) -> Result<JsValue, JsValue>;
7336
7337 /// The same as [`get`](fn.get.html)
7338 /// except the key is an `f64`, which is slightly faster.
7339 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7340 pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
7341
7342 /// The same as [`get`](fn.get.html)
7343 /// except the key is a `u32`, which is slightly faster.
7344 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7345 pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
7346
7347 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7348 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7349 /// of the given property if it exists on the object, `undefined` otherwise.
7350 ///
7351 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7352 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7353 pub fn get_own_property_descriptor<T>(
7354 target: &Object<T>,
7355 property_key: &JsValue,
7356 ) -> Result<JsValue, JsValue>;
7357
7358 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7359 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7360 /// of the given property if it exists on the object, `undefined` otherwise.
7361 ///
7362 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7363 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7364 pub fn get_own_property_descriptor_str<T>(
7365 target: &Object<T>,
7366 property_key: &JsString,
7367 ) -> Result<PropertyDescriptor<T>, JsValue>;
7368
7369 /// The static `Reflect.getPrototypeOf()` method is almost the same
7370 /// method as `Object.getPrototypeOf()`. It returns the prototype
7371 /// (i.e. the value of the internal `[[Prototype]]` property) of
7372 /// the specified object.
7373 ///
7374 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7375 #[cfg(not(js_sys_unstable_apis))]
7376 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7377 pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
7378
7379 /// The static `Reflect.getPrototypeOf()` method is almost the same
7380 /// method as `Object.getPrototypeOf()`. It returns the prototype
7381 /// (i.e. the value of the internal `[[Prototype]]` property) of
7382 /// the specified object.
7383 ///
7384 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7385 #[cfg(js_sys_unstable_apis)]
7386 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7387 pub fn get_prototype_of(target: &Object) -> Result<Object, JsValue>;
7388
7389 /// The static `Reflect.has()` method works like the in operator as a
7390 /// function.
7391 ///
7392 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7393 #[cfg(not(js_sys_unstable_apis))]
7394 #[wasm_bindgen(js_namespace = Reflect, catch)]
7395 pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
7396
7397 /// The static `Reflect.has()` method works like the in operator as a
7398 /// function.
7399 ///
7400 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7401 #[cfg(js_sys_unstable_apis)]
7402 #[wasm_bindgen(js_namespace = Reflect, catch)]
7403 pub fn has(target: &JsValue, property_key: &Symbol) -> Result<bool, JsValue>;
7404
7405 // Next major: deprecate
7406 /// The static `Reflect.has()` method works like the in operator as a
7407 /// function.
7408 ///
7409 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7410 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7411 pub fn has_str<T>(target: &Object<T>, property_key: &JsString) -> Result<bool, JsValue>;
7412
7413 /// The static `Reflect.has()` method works like the in operator as a
7414 /// function.
7415 ///
7416 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7417 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7418 pub fn has_symbol<T>(target: &Object<T>, property_key: &Symbol) -> Result<bool, JsValue>;
7419
7420 /// The static `Reflect.isExtensible()` method determines if an object is
7421 /// extensible (whether it can have new properties added to it). It is
7422 /// similar to `Object.isExtensible()`, but with some differences.
7423 ///
7424 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
7425 #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
7426 pub fn is_extensible<T>(target: &Object<T>) -> Result<bool, JsValue>;
7427
7428 /// The static `Reflect.ownKeys()` method returns an array of the
7429 /// target object's own property keys.
7430 ///
7431 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
7432 #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
7433 pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
7434
7435 /// The static `Reflect.preventExtensions()` method prevents new
7436 /// properties from ever being added to an object (i.e. prevents
7437 /// future extensions to the object). It is similar to
7438 /// `Object.preventExtensions()`, but with some differences.
7439 ///
7440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
7441 #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
7442 pub fn prevent_extensions<T>(target: &Object<T>) -> Result<bool, JsValue>;
7443
7444 /// The static `Reflect.set()` method works like setting a
7445 /// property on an object.
7446 ///
7447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7448 #[cfg(not(js_sys_unstable_apis))]
7449 #[wasm_bindgen(js_namespace = Reflect, catch)]
7450 pub fn set(
7451 target: &JsValue,
7452 property_key: &JsValue,
7453 value: &JsValue,
7454 ) -> Result<bool, JsValue>;
7455
7456 /// The static `Reflect.set()` method works like setting a
7457 /// property on an object.
7458 ///
7459 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7460 #[cfg(js_sys_unstable_apis)]
7461 #[wasm_bindgen(js_namespace = Reflect, catch)]
7462 pub fn set<T>(
7463 target: &Object<T>,
7464 property_key: &JsString,
7465 value: &T,
7466 ) -> Result<bool, JsValue>;
7467
7468 /// The static `Reflect.set()` method works like setting a
7469 /// property on an object.
7470 ///
7471 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7472 #[cfg(js_sys_unstable_apis)]
7473 #[wasm_bindgen(js_namespace = Reflect, catch)]
7474 pub fn set_symbol<T>(
7475 target: &Object<T>,
7476 property_key: &Symbol,
7477 value: &JsValue,
7478 ) -> Result<bool, JsValue>;
7479
7480 // Next major: deprecate
7481 /// The static `Reflect.set()` method works like setting a
7482 /// property on an object.
7483 ///
7484 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7485 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7486 pub fn set_str<T>(
7487 target: &Object<T>,
7488 property_key: &JsString,
7489 value: &T,
7490 ) -> Result<bool, JsValue>;
7491
7492 /// The same as [`set`](fn.set.html)
7493 /// except the key is an `f64`, which is slightly faster.
7494 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7495 pub fn set_f64(
7496 target: &JsValue,
7497 property_key: f64,
7498 value: &JsValue,
7499 ) -> Result<bool, JsValue>;
7500
7501 /// The same as [`set`](fn.set.html)
7502 /// except the key is a `u32`, which is slightly faster.
7503 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7504 pub fn set_u32(
7505 target: &JsValue,
7506 property_key: u32,
7507 value: &JsValue,
7508 ) -> Result<bool, JsValue>;
7509
7510 /// The static `Reflect.set()` method works like setting a
7511 /// property on an object.
7512 ///
7513 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7514 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7515 pub fn set_with_receiver(
7516 target: &JsValue,
7517 property_key: &JsValue,
7518 value: &JsValue,
7519 receiver: &JsValue,
7520 ) -> Result<bool, JsValue>;
7521
7522 /// The static `Reflect.setPrototypeOf()` method is the same
7523 /// method as `Object.setPrototypeOf()`. It sets the prototype
7524 /// (i.e., the internal `[[Prototype]]` property) of a specified
7525 /// object to another object or to null.
7526 ///
7527 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
7528 #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
7529 pub fn set_prototype_of<T>(
7530 target: &Object<T>,
7531 prototype: &JsValue,
7532 ) -> Result<bool, JsValue>;
7533 }
7534}
7535
7536// RegExp
7537#[wasm_bindgen]
7538extern "C" {
7539 #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
7540 #[derive(Clone, Debug, PartialEq, Eq)]
7541 pub type RegExp;
7542
7543 /// The `exec()` method executes a search for a match in a specified
7544 /// string. Returns a result array, or null.
7545 ///
7546 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7547 #[cfg(not(js_sys_unstable_apis))]
7548 #[wasm_bindgen(method)]
7549 pub fn exec(this: &RegExp, text: &str) -> Option<Array<JsString>>;
7550
7551 /// The `exec()` method executes a search for a match in a specified
7552 /// string. Returns a result array, or null.
7553 ///
7554 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7555 #[cfg(js_sys_unstable_apis)]
7556 #[wasm_bindgen(method)]
7557 pub fn exec(this: &RegExp, text: &str) -> Option<RegExpMatchArray>;
7558
7559 /// The flags property returns a string consisting of the flags of
7560 /// the current regular expression object.
7561 ///
7562 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
7563 #[wasm_bindgen(method, getter)]
7564 pub fn flags(this: &RegExp) -> JsString;
7565
7566 /// The global property indicates whether or not the "g" flag is
7567 /// used with the regular expression. global is a read-only
7568 /// property of an individual regular expression instance.
7569 ///
7570 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
7571 #[wasm_bindgen(method, getter)]
7572 pub fn global(this: &RegExp) -> bool;
7573
7574 /// The ignoreCase property indicates whether or not the "i" flag
7575 /// is used with the regular expression. ignoreCase is a read-only
7576 /// property of an individual regular expression instance.
7577 ///
7578 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
7579 #[wasm_bindgen(method, getter, js_name = ignoreCase)]
7580 pub fn ignore_case(this: &RegExp) -> bool;
7581
7582 /// The non-standard input property is a static property of
7583 /// regular expressions that contains the string against which a
7584 /// regular expression is matched. RegExp.$_ is an alias for this
7585 /// property.
7586 ///
7587 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
7588 #[wasm_bindgen(static_method_of = RegExp, getter)]
7589 pub fn input() -> JsString;
7590
7591 /// The lastIndex is a read/write integer property of regular expression
7592 /// instances that specifies the index at which to start the next match.
7593 ///
7594 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7595 #[wasm_bindgen(structural, getter = lastIndex, method)]
7596 pub fn last_index(this: &RegExp) -> u32;
7597
7598 /// The lastIndex is a read/write integer property of regular expression
7599 /// instances that specifies the index at which to start the next match.
7600 ///
7601 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7602 #[wasm_bindgen(structural, setter = lastIndex, method)]
7603 pub fn set_last_index(this: &RegExp, index: u32);
7604
7605 /// The non-standard lastMatch property is a static and read-only
7606 /// property of regular expressions that contains the last matched
7607 /// characters. `RegExp.$&` is an alias for this property.
7608 ///
7609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
7610 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
7611 pub fn last_match() -> JsString;
7612
7613 /// The non-standard lastParen property is a static and read-only
7614 /// property of regular expressions that contains the last
7615 /// parenthesized substring match, if any. `RegExp.$+` is an alias
7616 /// for this property.
7617 ///
7618 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
7619 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
7620 pub fn last_paren() -> JsString;
7621
7622 /// The non-standard leftContext property is a static and
7623 /// read-only property of regular expressions that contains the
7624 /// substring preceding the most recent match. `RegExp.$`` is an
7625 /// alias for this property.
7626 ///
7627 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
7628 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
7629 pub fn left_context() -> JsString;
7630
7631 /// The multiline property indicates whether or not the "m" flag
7632 /// is used with the regular expression. multiline is a read-only
7633 /// property of an individual regular expression instance.
7634 ///
7635 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
7636 #[wasm_bindgen(method, getter)]
7637 pub fn multiline(this: &RegExp) -> bool;
7638
7639 /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
7640 /// are static and read-only properties of regular expressions
7641 /// that contain parenthesized substring matches.
7642 ///
7643 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
7644 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
7645 pub fn n1() -> JsString;
7646 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
7647 pub fn n2() -> JsString;
7648 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
7649 pub fn n3() -> JsString;
7650 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
7651 pub fn n4() -> JsString;
7652 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
7653 pub fn n5() -> JsString;
7654 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
7655 pub fn n6() -> JsString;
7656 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
7657 pub fn n7() -> JsString;
7658 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
7659 pub fn n8() -> JsString;
7660 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
7661 pub fn n9() -> JsString;
7662
7663 /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
7664 ///
7665 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
7666 #[wasm_bindgen(constructor)]
7667 pub fn new(pattern: &str, flags: &str) -> RegExp;
7668 #[wasm_bindgen(constructor)]
7669 pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
7670
7671 /// The non-standard rightContext property is a static and
7672 /// read-only property of regular expressions that contains the
7673 /// substring following the most recent match. `RegExp.$'` is an
7674 /// alias for this property.
7675 ///
7676 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
7677 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
7678 pub fn right_context() -> JsString;
7679
7680 /// The source property returns a String containing the source
7681 /// text of the regexp object, and it doesn't contain the two
7682 /// forward slashes on both sides and any flags.
7683 ///
7684 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
7685 #[wasm_bindgen(method, getter)]
7686 pub fn source(this: &RegExp) -> JsString;
7687
7688 /// The sticky property reflects whether or not the search is
7689 /// sticky (searches in strings only from the index indicated by
7690 /// the lastIndex property of this regular expression). sticky is
7691 /// a read-only property of an individual regular expression
7692 /// object.
7693 ///
7694 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
7695 #[wasm_bindgen(method, getter)]
7696 pub fn sticky(this: &RegExp) -> bool;
7697
7698 /// The `test()` method executes a search for a match between a
7699 /// regular expression and a specified string. Returns true or
7700 /// false.
7701 ///
7702 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
7703 #[wasm_bindgen(method)]
7704 pub fn test(this: &RegExp, text: &str) -> bool;
7705
7706 /// The `toString()` method returns a string representing the
7707 /// regular expression.
7708 ///
7709 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
7710 #[cfg(not(js_sys_unstable_apis))]
7711 #[wasm_bindgen(method, js_name = toString)]
7712 pub fn to_string(this: &RegExp) -> JsString;
7713
7714 /// The unicode property indicates whether or not the "u" flag is
7715 /// used with a regular expression. unicode is a read-only
7716 /// property of an individual regular expression instance.
7717 ///
7718 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
7719 #[wasm_bindgen(method, getter)]
7720 pub fn unicode(this: &RegExp) -> bool;
7721}
7722
7723// RegExpMatchArray
7724#[wasm_bindgen]
7725extern "C" {
7726 /// The result array from `RegExp.exec()` or `String.matchAll()`.
7727 ///
7728 /// This is an array of strings with additional properties `index`, `input`, and `groups`.
7729 ///
7730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#return_value)
7731 #[wasm_bindgen(extends = Object, extends = Array, typescript_type = "RegExpMatchArray")]
7732 #[derive(Clone, Debug, PartialEq, Eq)]
7733 pub type RegExpMatchArray;
7734
7735 /// The 0-based index of the match in the string.
7736 #[wasm_bindgen(method, getter)]
7737 pub fn index(this: &RegExpMatchArray) -> u32;
7738
7739 /// The original string that was matched against.
7740 #[wasm_bindgen(method, getter)]
7741 pub fn input(this: &RegExpMatchArray) -> JsString;
7742
7743 /// An object of named capturing groups whose keys are the names and valuestype Array
7744 /// are the capturing groups, or `undefined` if no named capturing groups were defined.
7745 #[wasm_bindgen(method, getter)]
7746 pub fn groups(this: &RegExpMatchArray) -> Option<Object>;
7747
7748 /// The number of elements in the match array (full match + capture groups).
7749 #[wasm_bindgen(method, getter)]
7750 pub fn length(this: &RegExpMatchArray) -> u32;
7751
7752 /// Gets the matched string or capture group at the given index.
7753 /// Index 0 is the full match, indices 1+ are capture groups.
7754 #[wasm_bindgen(method, indexing_getter)]
7755 pub fn get(this: &RegExpMatchArray, index: u32) -> Option<JsString>;
7756}
7757
7758// Set
7759#[wasm_bindgen]
7760extern "C" {
7761 #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
7762 #[derive(Clone, Debug, PartialEq, Eq)]
7763 pub type Set<T = JsValue>;
7764
7765 /// The [`Set`] object lets you store unique values of any type, whether
7766 /// primitive values or object references.
7767 ///
7768 /// **Note:** Consider using [`Set::new_typed`] to support typing.
7769 ///
7770 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7771 #[cfg(not(js_sys_unstable_apis))]
7772 #[wasm_bindgen(constructor)]
7773 pub fn new(init: &JsValue) -> Set;
7774
7775 /// The [`Set`] object lets you store unique values of any type, whether
7776 /// primitive values or object references.
7777 ///
7778 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7779 #[cfg(js_sys_unstable_apis)]
7780 #[wasm_bindgen(constructor)]
7781 pub fn new<T>() -> Set<T>;
7782
7783 // Next major: deprecate
7784 /// The [`Set`] object lets you store unique values of any type, whether
7785 /// primitive values or object references.
7786 ///
7787 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7788 #[wasm_bindgen(constructor)]
7789 pub fn new_typed<T>() -> Set<T>;
7790
7791 /// The [`Set`] object lets you store unique values of any type, whether
7792 /// primitive values or object references.
7793 ///
7794 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7795 #[wasm_bindgen(constructor, js_name = new)]
7796 pub fn new_empty<T>() -> Set<T>;
7797
7798 /// The [`Set`] object lets you store unique values of any type, whether
7799 /// primitive values or object references.
7800 ///
7801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7802 #[wasm_bindgen(constructor, js_name = new)]
7803 pub fn new_from_items<T>(items: &[T]) -> Set<T>;
7804
7805 /// The [`Set`] object lets you store unique values of any type, whether
7806 /// primitive values or object references.
7807 ///
7808 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7809 #[wasm_bindgen(constructor, js_name = new, catch)]
7810 pub fn new_from_iterable<T, I: Iterable<Item = T>>(iterable: I) -> Result<Set<T>, JsValue>;
7811
7812 /// The `add()` method appends a new element with a specified value to the
7813 /// end of a [`Set`] object.
7814 ///
7815 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
7816 #[wasm_bindgen(method)]
7817 pub fn add<T>(this: &Set<T>, value: &T) -> Set<T>;
7818
7819 /// The `clear()` method removes all elements from a [`Set`] object.
7820 ///
7821 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
7822 #[wasm_bindgen(method)]
7823 pub fn clear<T>(this: &Set<T>);
7824
7825 /// The `delete()` method removes the specified element from a [`Set`]
7826 /// object.
7827 ///
7828 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
7829 #[wasm_bindgen(method)]
7830 pub fn delete<T>(this: &Set<T>, value: &T) -> bool;
7831
7832 /// The `forEach()` method executes a provided function once for each value
7833 /// in the Set object, in insertion order.
7834 ///
7835 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7836 #[cfg(not(js_sys_unstable_apis))]
7837 #[wasm_bindgen(method, js_name = forEach)]
7838 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T, T, Set<T>));
7839
7840 /// The `forEach()` method executes a provided function once for each value
7841 /// in the Set object, in insertion order.
7842 ///
7843 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7844 #[cfg(js_sys_unstable_apis)]
7845 #[wasm_bindgen(method, js_name = forEach)]
7846 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T));
7847
7848 /// The `forEach()` method executes a provided function once for each value
7849 /// in the Set object, in insertion order.
7850 ///
7851 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7852 #[wasm_bindgen(method, js_name = forEach, catch)]
7853 pub fn try_for_each<T>(
7854 this: &Set<T>,
7855 callback: &mut dyn FnMut(T) -> Result<(), JsError>,
7856 ) -> Result<(), JsValue>;
7857
7858 /// The `has()` method returns a boolean indicating whether an element with
7859 /// the specified value exists in a [`Set`] object or not.
7860 ///
7861 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
7862 #[wasm_bindgen(method)]
7863 pub fn has<T>(this: &Set<T>, value: &T) -> bool;
7864
7865 /// The size accessor property returns the number of elements in a [`Set`]
7866 /// object.
7867 ///
7868 /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
7869 #[wasm_bindgen(method, getter)]
7870 pub fn size<T>(this: &Set<T>) -> u32;
7871
7872 /// The `union()` method returns a new set containing elements which are in
7873 /// either or both of this set and the given set.
7874 ///
7875 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union)
7876 #[wasm_bindgen(method)]
7877 pub fn union<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7878
7879 /// The `intersection()` method returns a new set containing elements which are
7880 /// in both this set and the given set.
7881 ///
7882 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection)
7883 #[wasm_bindgen(method)]
7884 pub fn intersection<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7885
7886 /// The `difference()` method returns a new set containing elements which are
7887 /// in this set but not in the given set.
7888 ///
7889 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference)
7890 #[wasm_bindgen(method)]
7891 pub fn difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7892
7893 /// The `symmetricDifference()` method returns a new set containing elements
7894 /// which are in either this set or the given set, but not in both.
7895 ///
7896 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)
7897 #[wasm_bindgen(method, js_name = symmetricDifference)]
7898 pub fn symmetric_difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7899
7900 /// The `isSubsetOf()` method returns a boolean indicating whether all elements
7901 /// of this set are in the given set.
7902 ///
7903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSubsetOf)
7904 #[wasm_bindgen(method, js_name = isSubsetOf)]
7905 pub fn is_subset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
7906
7907 /// The `isSupersetOf()` method returns a boolean indicating whether all elements
7908 /// of the given set are in this set.
7909 ///
7910 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSupersetOf)
7911 #[wasm_bindgen(method, js_name = isSupersetOf)]
7912 pub fn is_superset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
7913
7914 /// The `isDisjointFrom()` method returns a boolean indicating whether this set
7915 /// has no elements in common with the given set.
7916 ///
7917 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom)
7918 #[wasm_bindgen(method, js_name = isDisjointFrom)]
7919 pub fn is_disjoint_from<T>(this: &Set<T>, other: &Set<T>) -> bool;
7920}
7921
7922impl Default for Set<JsValue> {
7923 fn default() -> Self {
7924 Self::new_typed()
7925 }
7926}
7927
7928impl<T> Iterable for Set<T> {
7929 type Item = T;
7930}
7931
7932// SetIterator
7933#[wasm_bindgen]
7934extern "C" {
7935 /// The `entries()` method returns a new Iterator object that contains an
7936 /// array of [value, value] for each element in the Set object, in insertion
7937 /// order. For Set objects there is no key like in Map objects. However, to
7938 /// keep the API similar to the Map object, each entry has the same value
7939 /// for its key and value here, so that an array [value, value] is returned.
7940 ///
7941 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7942 #[cfg(not(js_sys_unstable_apis))]
7943 #[wasm_bindgen(method)]
7944 pub fn entries<T>(set: &Set<T>) -> Iterator;
7945
7946 /// The `entries()` method returns a new Iterator object that contains an
7947 /// array of [value, value] for each element in the Set object, in insertion
7948 /// order. For Set objects there is no key like in Map objects. However, to
7949 /// keep the API similar to the Map object, each entry has the same value
7950 /// for its key and value here, so that an array [value, value] is returned.
7951 ///
7952 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7953 #[cfg(js_sys_unstable_apis)]
7954 #[wasm_bindgen(method, js_name = entries)]
7955 pub fn entries<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
7956
7957 // Next major: deprecate
7958 /// The `entries()` method returns a new Iterator object that contains an
7959 /// array of [value, value] for each element in the Set object, in insertion
7960 /// order. For Set objects there is no key like in Map objects. However, to
7961 /// keep the API similar to the Map object, each entry has the same value
7962 /// for its key and value here, so that an array [value, value] is returned.
7963 ///
7964 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7965 #[wasm_bindgen(method, js_name = entries)]
7966 pub fn entries_typed<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
7967
7968 /// The `keys()` method is an alias for this method (for similarity with
7969 /// Map objects); it behaves exactly the same and returns values
7970 /// of Set elements.
7971 ///
7972 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
7973 #[wasm_bindgen(method)]
7974 pub fn keys<T>(set: &Set<T>) -> Iterator<T>;
7975
7976 /// The `values()` method returns a new Iterator object that contains the
7977 /// values for each element in the Set object in insertion order.
7978 ///
7979 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
7980 #[wasm_bindgen(method)]
7981 pub fn values<T>(set: &Set<T>) -> Iterator<T>;
7982}
7983
7984// SyntaxError
7985#[wasm_bindgen]
7986extern "C" {
7987 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
7988 /// token order that does not conform to the syntax of the language when
7989 /// parsing code.
7990 ///
7991 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
7992 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
7993 #[derive(Clone, Debug, PartialEq, Eq)]
7994 pub type SyntaxError;
7995
7996 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
7997 /// token order that does not conform to the syntax of the language when
7998 /// parsing code.
7999 ///
8000 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8001 #[wasm_bindgen(constructor)]
8002 pub fn new(message: &str) -> SyntaxError;
8003}
8004
8005// TypeError
8006#[wasm_bindgen]
8007extern "C" {
8008 /// The `TypeError` object represents an error when a value is not of the
8009 /// expected type.
8010 ///
8011 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8012 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
8013 #[derive(Clone, Debug, PartialEq, Eq)]
8014 pub type TypeError;
8015
8016 /// The `TypeError` object represents an error when a value is not of the
8017 /// expected type.
8018 ///
8019 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8020 #[wasm_bindgen(constructor)]
8021 pub fn new(message: &str) -> TypeError;
8022}
8023
8024// URIError
8025#[wasm_bindgen]
8026extern "C" {
8027 /// The `URIError` object represents an error when a global URI handling
8028 /// function was used in a wrong way.
8029 ///
8030 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8031 #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
8032 #[derive(Clone, Debug, PartialEq, Eq)]
8033 pub type UriError;
8034
8035 /// The `URIError` object represents an error when a global URI handling
8036 /// function was used in a wrong way.
8037 ///
8038 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8039 #[wasm_bindgen(constructor, js_class = "URIError")]
8040 pub fn new(message: &str) -> UriError;
8041}
8042
8043// WeakMap
8044#[wasm_bindgen]
8045extern "C" {
8046 #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
8047 #[derive(Clone, Debug, PartialEq, Eq)]
8048 pub type WeakMap<K = Object, V = JsValue>;
8049
8050 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8051 /// keys are weakly referenced. The keys must be objects and the values can
8052 /// be arbitrary values.
8053 ///
8054 /// **Note:** Consider using [`WeakMap::new_typed`] to support typing.
8055 ///
8056 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8057 #[cfg(not(js_sys_unstable_apis))]
8058 #[wasm_bindgen(constructor)]
8059 pub fn new() -> WeakMap;
8060
8061 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8062 /// keys are weakly referenced. The keys must be objects and the values can
8063 /// be arbitrary values.
8064 ///
8065 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8066 #[cfg(js_sys_unstable_apis)]
8067 #[wasm_bindgen(constructor)]
8068 pub fn new<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8069
8070 // Next major: deprecate
8071 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8072 /// keys are weakly referenced. The keys must be objects and the values can
8073 /// be arbitrary values.
8074 ///
8075 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8076 #[wasm_bindgen(constructor)]
8077 pub fn new_typed<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8078
8079 /// The `set()` method sets the value for the key in the [`WeakMap`] object.
8080 /// Returns the [`WeakMap`] object.
8081 ///
8082 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
8083 #[wasm_bindgen(method, js_class = "WeakMap")]
8084 pub fn set<K, V>(this: &WeakMap<K, V>, key: &K, value: &V) -> WeakMap<K, V>;
8085
8086 /// The `get()` method returns a specified by key element
8087 /// from a [`WeakMap`] object. Returns `undefined` if the key is not found.
8088 ///
8089 /// **Note:** Consider using [`WeakMap::get_checked`] to get an `Option<V>` instead.
8090 ///
8091 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8092 #[cfg(not(js_sys_unstable_apis))]
8093 #[wasm_bindgen(method)]
8094 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> V;
8095
8096 /// The `get()` method returns a specified by key element
8097 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8098 ///
8099 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8100 #[cfg(js_sys_unstable_apis)]
8101 #[wasm_bindgen(method)]
8102 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8103
8104 /// The `get()` method returns a specified by key element
8105 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8106 ///
8107 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8108 #[wasm_bindgen(method, js_name = get)]
8109 pub fn get_checked<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8110
8111 /// The `has()` method returns a boolean indicating whether an element with
8112 /// the specified key exists in the [`WeakMap`] object or not.
8113 ///
8114 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
8115 #[wasm_bindgen(method)]
8116 pub fn has<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8117
8118 /// The `delete()` method removes the specified element from a [`WeakMap`]
8119 /// object.
8120 ///
8121 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
8122 #[wasm_bindgen(method)]
8123 pub fn delete<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8124}
8125
8126impl Default for WeakMap {
8127 fn default() -> Self {
8128 Self::new()
8129 }
8130}
8131
8132// WeakSet
8133#[wasm_bindgen]
8134extern "C" {
8135 #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
8136 #[derive(Clone, Debug, PartialEq, Eq)]
8137 pub type WeakSet<T = Object>;
8138
8139 /// The `WeakSet` object lets you store weakly held objects in a collection.
8140 ///
8141 /// **Note:** Consider using [`WeakSet::new_typed`] for typed sets.
8142 ///
8143 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8144 #[cfg(not(js_sys_unstable_apis))]
8145 #[wasm_bindgen(constructor)]
8146 pub fn new() -> WeakSet;
8147
8148 /// The `WeakSet` object lets you store weakly held objects in a collection.
8149 ///
8150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8151 #[cfg(js_sys_unstable_apis)]
8152 #[wasm_bindgen(constructor)]
8153 pub fn new<T = Object>() -> WeakSet<T>;
8154
8155 // Next major: deprecate
8156 /// The `WeakSet` object lets you store weakly held objects in a collection.
8157 ///
8158 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8159 #[wasm_bindgen(constructor)]
8160 pub fn new_typed<T = Object>() -> WeakSet<T>;
8161
8162 /// The `has()` method returns a boolean indicating whether an object exists
8163 /// in a WeakSet or not.
8164 ///
8165 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
8166 #[wasm_bindgen(method)]
8167 pub fn has<T>(this: &WeakSet<T>, value: &T) -> bool;
8168
8169 /// The `add()` method appends a new object to the end of a WeakSet object.
8170 ///
8171 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
8172 #[wasm_bindgen(method)]
8173 pub fn add<T>(this: &WeakSet<T>, value: &T) -> WeakSet<T>;
8174
8175 /// The `delete()` method removes the specified element from a WeakSet
8176 /// object.
8177 ///
8178 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
8179 #[wasm_bindgen(method)]
8180 pub fn delete<T>(this: &WeakSet<T>, value: &T) -> bool;
8181}
8182
8183impl Default for WeakSet {
8184 fn default() -> Self {
8185 Self::new()
8186 }
8187}
8188
8189// WeakRef
8190#[wasm_bindgen]
8191extern "C" {
8192 #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
8193 #[derive(Clone, Debug, PartialEq, Eq)]
8194 pub type WeakRef<T = Object>;
8195
8196 /// The `WeakRef` object contains a weak reference to an object. A weak
8197 /// reference to an object is a reference that does not prevent the object
8198 /// from being reclaimed by the garbage collector.
8199 ///
8200 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
8201 #[wasm_bindgen(constructor)]
8202 pub fn new<T = Object>(target: &T) -> WeakRef<T>;
8203
8204 /// Returns the `Object` this `WeakRef` points to, or `None` if the
8205 /// object has been garbage collected.
8206 ///
8207 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
8208 #[wasm_bindgen(method)]
8209 pub fn deref<T>(this: &WeakRef<T>) -> Option<T>;
8210}
8211
8212#[cfg(js_sys_unstable_apis)]
8213#[allow(non_snake_case)]
8214pub mod Temporal;
8215
8216#[allow(non_snake_case)]
8217pub mod WebAssembly {
8218 use super::*;
8219
8220 // WebAssembly
8221 #[wasm_bindgen]
8222 extern "C" {
8223 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8224 /// from WebAssembly binary code. This function is useful if it is
8225 /// necessary to a compile a module before it can be instantiated
8226 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8227 ///
8228 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8229 #[cfg(not(js_sys_unstable_apis))]
8230 #[wasm_bindgen(js_namespace = WebAssembly)]
8231 pub fn compile(buffer_source: &JsValue) -> Promise<JsValue>;
8232
8233 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8234 /// from WebAssembly binary code. This function is useful if it is
8235 /// necessary to a compile a module before it can be instantiated
8236 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8237 ///
8238 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8239 #[cfg(js_sys_unstable_apis)]
8240 #[wasm_bindgen(js_namespace = WebAssembly)]
8241 pub fn compile(buffer_source: &JsValue) -> Promise<Module>;
8242
8243 /// The `WebAssembly.compileStreaming()` function compiles a
8244 /// `WebAssembly.Module` module directly from a streamed underlying
8245 /// source. This function is useful if it is necessary to a compile a
8246 /// module before it can be instantiated (otherwise, the
8247 /// `WebAssembly.instantiateStreaming()` function should be used).
8248 ///
8249 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8250 #[cfg(not(js_sys_unstable_apis))]
8251 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8252 pub fn compile_streaming(response: &Promise) -> Promise<JsValue>;
8253
8254 /// The `WebAssembly.compileStreaming()` function compiles a
8255 /// `WebAssembly.Module` module directly from a streamed underlying
8256 /// source. This function is useful if it is necessary to a compile a
8257 /// module before it can be instantiated (otherwise, the
8258 /// `WebAssembly.instantiateStreaming()` function should be used).
8259 ///
8260 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8261 #[cfg(js_sys_unstable_apis)]
8262 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8263 pub fn compile_streaming(response: &Promise) -> Promise<Module>;
8264
8265 /// The `WebAssembly.instantiate()` function allows you to compile and
8266 /// instantiate WebAssembly code.
8267 ///
8268 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8269 #[cfg(not(js_sys_unstable_apis))]
8270 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8271 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<JsValue>;
8272
8273 /// The `WebAssembly.instantiate()` function allows you to compile and
8274 /// instantiate WebAssembly code.
8275 ///
8276 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8277 #[cfg(js_sys_unstable_apis)]
8278 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8279 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<Instance>;
8280
8281 /// The `WebAssembly.instantiate()` function allows you to compile and
8282 /// instantiate WebAssembly code.
8283 ///
8284 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8285 #[cfg(not(js_sys_unstable_apis))]
8286 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8287 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<JsValue>;
8288
8289 /// The `WebAssembly.instantiate()` function allows you to compile and
8290 /// instantiate WebAssembly code.
8291 ///
8292 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8293 #[cfg(js_sys_unstable_apis)]
8294 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8295 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<Instance>;
8296
8297 /// The `WebAssembly.instantiateStreaming()` function compiles and
8298 /// instantiates a WebAssembly module directly from a streamed
8299 /// underlying source. This is the most efficient, optimized way to load
8300 /// Wasm code.
8301 ///
8302 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8303 #[cfg(not(js_sys_unstable_apis))]
8304 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8305 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<JsValue>;
8306
8307 /// The `WebAssembly.instantiateStreaming()` function compiles and
8308 /// instantiates a WebAssembly module directly from a streamed
8309 /// underlying source. This is the most efficient, optimized way to load
8310 /// Wasm code.
8311 ///
8312 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8313 #[cfg(js_sys_unstable_apis)]
8314 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8315 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<Instance>;
8316
8317 /// The `WebAssembly.validate()` function validates a given typed
8318 /// array of WebAssembly binary code, returning whether the bytes
8319 /// form a valid Wasm module (`true`) or not (`false`).
8320 ///
8321 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
8322 #[wasm_bindgen(js_namespace = WebAssembly, catch)]
8323 pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
8324 }
8325
8326 // WebAssembly.CompileError
8327 #[wasm_bindgen]
8328 extern "C" {
8329 /// The `WebAssembly.CompileError()` constructor creates a new
8330 /// WebAssembly `CompileError` object, which indicates an error during
8331 /// WebAssembly decoding or validation.
8332 ///
8333 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8334 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
8335 #[derive(Clone, Debug, PartialEq, Eq)]
8336 pub type CompileError;
8337
8338 /// The `WebAssembly.CompileError()` constructor creates a new
8339 /// WebAssembly `CompileError` object, which indicates an error during
8340 /// WebAssembly decoding or validation.
8341 ///
8342 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8343 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8344 pub fn new(message: &str) -> CompileError;
8345 }
8346
8347 // WebAssembly.Instance
8348 #[wasm_bindgen]
8349 extern "C" {
8350 /// A `WebAssembly.Instance` object is a stateful, executable instance
8351 /// of a `WebAssembly.Module`. Instance objects contain all the exported
8352 /// WebAssembly functions that allow calling into WebAssembly code from
8353 /// JavaScript.
8354 ///
8355 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8356 #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
8357 #[derive(Clone, Debug, PartialEq, Eq)]
8358 pub type Instance;
8359
8360 /// The `WebAssembly.Instance()` constructor function can be called to
8361 /// synchronously instantiate a given `WebAssembly.Module`
8362 /// object. However, the primary way to get an `Instance` is through the
8363 /// asynchronous `WebAssembly.instantiateStreaming()` function.
8364 ///
8365 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8366 #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
8367 pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
8368
8369 /// The `exports` readonly property of the `WebAssembly.Instance` object
8370 /// prototype returns an object containing as its members all the
8371 /// functions exported from the WebAssembly module instance, to allow
8372 /// them to be accessed and used by JavaScript.
8373 ///
8374 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
8375 #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
8376 pub fn exports(this: &Instance) -> Object;
8377 }
8378
8379 // WebAssembly.LinkError
8380 #[wasm_bindgen]
8381 extern "C" {
8382 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8383 /// LinkError object, which indicates an error during module
8384 /// instantiation (besides traps from the start function).
8385 ///
8386 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8387 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
8388 #[derive(Clone, Debug, PartialEq, Eq)]
8389 pub type LinkError;
8390
8391 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8392 /// LinkError object, which indicates an error during module
8393 /// instantiation (besides traps from the start function).
8394 ///
8395 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8396 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8397 pub fn new(message: &str) -> LinkError;
8398 }
8399
8400 // WebAssembly.RuntimeError
8401 #[wasm_bindgen]
8402 extern "C" {
8403 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8404 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8405 /// specifies a trap.
8406 ///
8407 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8408 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
8409 #[derive(Clone, Debug, PartialEq, Eq)]
8410 pub type RuntimeError;
8411
8412 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8413 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8414 /// specifies a trap.
8415 ///
8416 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8417 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8418 pub fn new(message: &str) -> RuntimeError;
8419 }
8420
8421 // WebAssembly.Module
8422 #[wasm_bindgen]
8423 extern "C" {
8424 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8425 /// that has already been compiled by the browser and can be
8426 /// efficiently shared with Workers, and instantiated multiple times.
8427 ///
8428 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8429 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
8430 #[derive(Clone, Debug, PartialEq, Eq)]
8431 pub type Module;
8432
8433 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8434 /// that has already been compiled by the browser and can be
8435 /// efficiently shared with Workers, and instantiated multiple times.
8436 ///
8437 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8438 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8439 pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
8440
8441 /// The `WebAssembly.customSections()` function returns a copy of the
8442 /// contents of all custom sections in the given module with the given
8443 /// string name.
8444 ///
8445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
8446 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
8447 pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
8448
8449 /// The `WebAssembly.exports()` function returns an array containing
8450 /// descriptions of all the declared exports of the given `Module`.
8451 ///
8452 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
8453 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8454 pub fn exports(module: &Module) -> Array;
8455
8456 /// The `WebAssembly.imports()` function returns an array containing
8457 /// descriptions of all the declared imports of the given `Module`.
8458 ///
8459 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
8460 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8461 pub fn imports(module: &Module) -> Array;
8462 }
8463
8464 // WebAssembly.Table
8465 #[wasm_bindgen]
8466 extern "C" {
8467 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8468 /// of the given size and element type.
8469 ///
8470 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8471 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
8472 #[derive(Clone, Debug, PartialEq, Eq)]
8473 pub type Table;
8474
8475 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8476 /// of the given size and element type.
8477 ///
8478 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8479 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8480 pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
8481
8482 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8483 /// of the given size and element type.
8484 ///
8485 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8486 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8487 pub fn new_with_value(table_descriptor: &Object, value: JsValue) -> Result<Table, JsValue>;
8488
8489 /// The length prototype property of the `WebAssembly.Table` object
8490 /// returns the length of the table, i.e. the number of elements in the
8491 /// table.
8492 ///
8493 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
8494 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8495 pub fn length(this: &Table) -> u32;
8496
8497 /// The `get()` prototype method of the `WebAssembly.Table()` object
8498 /// retrieves a function reference stored at a given index.
8499 ///
8500 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8501 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8502 pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
8503
8504 /// The `get()` prototype method of the `WebAssembly.Table()` object
8505 /// retrieves a function reference stored at a given index.
8506 ///
8507 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8508 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = get)]
8509 pub fn get_raw(this: &Table, index: u32) -> Result<JsValue, JsValue>;
8510
8511 /// The `grow()` prototype method of the `WebAssembly.Table` object
8512 /// increases the size of the `Table` instance by a specified number of
8513 /// elements.
8514 ///
8515 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8516 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8517 pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
8518
8519 /// The `grow()` prototype method of the `WebAssembly.Table` object
8520 /// increases the size of the `Table` instance by a specified number of
8521 /// elements.
8522 ///
8523 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8524 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = grow)]
8525 pub fn grow_with_value(
8526 this: &Table,
8527 additional_capacity: u32,
8528 value: JsValue,
8529 ) -> Result<u32, JsValue>;
8530
8531 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8532 /// reference stored at a given index to a different value.
8533 ///
8534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8535 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8536 pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
8537
8538 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8539 /// reference stored at a given index to a different value.
8540 ///
8541 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8542 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = set)]
8543 pub fn set_raw(this: &Table, index: u32, value: &JsValue) -> Result<(), JsValue>;
8544 }
8545
8546 // WebAssembly.Tag
8547 #[wasm_bindgen]
8548 extern "C" {
8549 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8550 ///
8551 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8552 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
8553 #[derive(Clone, Debug, PartialEq, Eq)]
8554 pub type Tag;
8555
8556 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8557 ///
8558 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8559 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8560 pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
8561 }
8562
8563 // WebAssembly.Exception
8564 #[wasm_bindgen]
8565 extern "C" {
8566 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8567 ///
8568 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8569 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
8570 #[derive(Clone, Debug, PartialEq, Eq)]
8571 pub type Exception;
8572
8573 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8574 ///
8575 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8576 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8577 pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
8578
8579 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8580 ///
8581 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8582 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8583 pub fn new_with_options(
8584 tag: &Tag,
8585 payload: &Array,
8586 options: &Object,
8587 ) -> Result<Exception, JsValue>;
8588
8589 /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
8590 /// test if the Exception matches a given tag.
8591 ///
8592 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
8593 #[wasm_bindgen(method, js_namespace = WebAssembly)]
8594 pub fn is(this: &Exception, tag: &Tag) -> bool;
8595
8596 /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
8597 /// to get the value of a specified item in the exception's data arguments
8598 ///
8599 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
8600 #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
8601 pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
8602 }
8603
8604 // WebAssembly.Global
8605 #[wasm_bindgen]
8606 extern "C" {
8607 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8608 /// of the given type and value.
8609 ///
8610 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8611 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
8612 #[derive(Clone, Debug, PartialEq, Eq)]
8613 pub type Global;
8614
8615 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8616 /// of the given type and value.
8617 ///
8618 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8619 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8620 pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
8621
8622 /// The value prototype property of the `WebAssembly.Global` object
8623 /// returns the value of the global.
8624 ///
8625 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8626 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8627 pub fn value(this: &Global) -> JsValue;
8628 #[wasm_bindgen(method, setter = value, js_namespace = WebAssembly)]
8629 pub fn set_value(this: &Global, value: &JsValue);
8630 }
8631
8632 // WebAssembly.Memory
8633 #[wasm_bindgen]
8634 extern "C" {
8635 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
8636 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
8637 #[derive(Clone, Debug, PartialEq, Eq)]
8638 pub type Memory;
8639
8640 /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
8641 /// which is a resizable `ArrayBuffer` that holds the raw bytes of
8642 /// memory accessed by a WebAssembly `Instance`.
8643 ///
8644 /// A memory created by JavaScript or in WebAssembly code will be
8645 /// accessible and mutable from both JavaScript and WebAssembly.
8646 ///
8647 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
8648 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8649 pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
8650
8651 /// An accessor property that returns the buffer contained in the
8652 /// memory.
8653 ///
8654 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
8655 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8656 pub fn buffer(this: &Memory) -> JsValue;
8657
8658 /// The `grow()` prototype method of the `Memory` object increases the
8659 /// size of the memory instance by a specified number of WebAssembly
8660 /// pages.
8661 ///
8662 /// Takes the number of pages to grow (64KiB in size) and returns the
8663 /// previous size of memory, in pages.
8664 ///
8665 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
8666 #[wasm_bindgen(method, js_namespace = WebAssembly)]
8667 pub fn grow(this: &Memory, pages: u32) -> u32;
8668 }
8669}
8670
8671/// The `JSON` object contains methods for parsing [JavaScript Object
8672/// Notation (JSON)](https://json.org/) and converting values to JSON. It
8673/// can't be called or constructed, and aside from its two method
8674/// properties, it has no interesting functionality of its own.
8675#[allow(non_snake_case)]
8676pub mod JSON {
8677 use super::*;
8678
8679 // JSON
8680 #[wasm_bindgen]
8681 extern "C" {
8682 /// The `JSON.parse()` method parses a JSON string, constructing the
8683 /// JavaScript value or object described by the string.
8684 ///
8685 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
8686 #[wasm_bindgen(catch, js_namespace = JSON)]
8687 pub fn parse(text: &str) -> Result<JsValue, JsValue>;
8688
8689 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8690 ///
8691 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8692 #[wasm_bindgen(catch, js_namespace = JSON)]
8693 pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
8694
8695 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8696 ///
8697 /// The `replacer` argument is a function that alters the behavior of the stringification
8698 /// process, or an array of String and Number objects that serve as a whitelist
8699 /// for selecting/filtering the properties of the value object to be included
8700 /// in the JSON string. If this value is null or not provided, all properties
8701 /// of the object are included in the resulting JSON string.
8702 ///
8703 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8704 #[cfg(not(js_sys_unstable_apis))]
8705 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8706 pub fn stringify_with_replacer(
8707 obj: &JsValue,
8708 replacer: &JsValue,
8709 ) -> Result<JsString, JsValue>;
8710
8711 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8712 ///
8713 /// The `replacer` argument is a function that alters the behavior of the stringification
8714 /// process, or an array of String and Number objects that serve as a whitelist
8715 /// for selecting/filtering the properties of the value object to be included
8716 /// in the JSON string. If this value is null or not provided, all properties
8717 /// of the object are included in the resulting JSON string.
8718 ///
8719 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8720 #[cfg(js_sys_unstable_apis)]
8721 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8722 pub fn stringify_with_replacer<'a>(
8723 obj: &JsValue,
8724 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
8725 space: Option<u32>,
8726 ) -> Result<JsString, JsValue>;
8727
8728 // Next major: deprecate
8729 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8730 ///
8731 /// The `replacer` argument is a function that alters the behavior of the stringification
8732 /// process, or an array of String and Number objects that serve as a whitelist
8733 /// for selecting/filtering the properties of the value object to be included
8734 /// in the JSON string. If this value is null or not provided, all properties
8735 /// of the object are included in the resulting JSON string.
8736 ///
8737 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8738 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8739 pub fn stringify_with_replacer_func<'a>(
8740 obj: &JsValue,
8741 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
8742 space: Option<u32>,
8743 ) -> Result<JsString, JsValue>;
8744
8745 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8746 ///
8747 /// The `replacer` argument is a function that alters the behavior of the stringification
8748 /// process, or an array of String and Number objects that serve as a whitelist
8749 /// for selecting/filtering the properties of the value object to be included
8750 /// in the JSON string. If this value is null or not provided, all properties
8751 /// of the object are included in the resulting JSON string.
8752 ///
8753 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8754 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8755 pub fn stringify_with_replacer_list(
8756 obj: &JsValue,
8757 replacer: Vec<String>,
8758 space: Option<u32>,
8759 ) -> Result<JsString, JsValue>;
8760
8761 // Next major: deprecate
8762 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8763 ///
8764 /// The `replacer` argument is a function that alters the behavior of the stringification
8765 /// process, or an array of String and Number objects that serve as a whitelist
8766 /// for selecting/filtering the properties of the value object to be included
8767 /// in the JSON string. If this value is null or not provided, all properties
8768 /// of the object are included in the resulting JSON string.
8769 ///
8770 /// The `space` argument is a String or Number object that's used to insert white space into
8771 /// the output JSON string for readability purposes. If this is a Number, it
8772 /// indicates the number of space characters to use as white space; this number
8773 /// is capped at 10 (if it is greater, the value is just 10). Values less than
8774 /// 1 indicate that no space should be used. If this is a String, the string
8775 /// (or the first 10 characters of the string, if it's longer than that) is
8776 /// used as white space. If this parameter is not provided (or is null), no
8777 /// white space is used.
8778 ///
8779 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8780 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8781 pub fn stringify_with_replacer_and_space(
8782 obj: &JsValue,
8783 replacer: &JsValue,
8784 space: &JsValue,
8785 ) -> Result<JsString, JsValue>;
8786 }
8787}
8788// JsString
8789#[wasm_bindgen]
8790extern "C" {
8791 #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
8792 #[derive(Clone, PartialEq, Eq)]
8793 pub type JsString;
8794
8795 /// The length property of a String object indicates the length of a string,
8796 /// in UTF-16 code units.
8797 ///
8798 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
8799 #[wasm_bindgen(method, getter)]
8800 pub fn length(this: &JsString) -> u32;
8801
8802 /// The 'at()' method returns a new string consisting of the single UTF-16
8803 /// code unit located at the specified offset into the string, counting from
8804 /// the end if it's negative.
8805 ///
8806 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
8807 #[wasm_bindgen(method, js_class = "String")]
8808 pub fn at(this: &JsString, index: i32) -> Option<JsString>;
8809
8810 /// The String object's `charAt()` method returns a new string consisting of
8811 /// the single UTF-16 code unit located at the specified offset into the
8812 /// string.
8813 ///
8814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
8815 #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
8816 pub fn char_at(this: &JsString, index: u32) -> JsString;
8817
8818 /// The `charCodeAt()` method returns an integer between 0 and 65535
8819 /// representing the UTF-16 code unit at the given index (the UTF-16 code
8820 /// unit matches the Unicode code point for code points representable in a
8821 /// single UTF-16 code unit, but might also be the first code unit of a
8822 /// surrogate pair for code points not representable in a single UTF-16 code
8823 /// unit, e.g. Unicode code points > 0x10000). If you want the entire code
8824 /// point value, use `codePointAt()`.
8825 ///
8826 /// Returns `NaN` if index is out of range.
8827 ///
8828 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
8829 #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
8830 pub fn char_code_at(this: &JsString, index: u32) -> f64;
8831
8832 /// The `codePointAt()` method returns a non-negative integer that is the
8833 /// Unicode code point value.
8834 ///
8835 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8836 #[cfg(not(js_sys_unstable_apis))]
8837 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8838 pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
8839
8840 /// The `codePointAt()` method returns a non-negative integer that is the
8841 /// Unicode code point value.
8842 ///
8843 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8844 #[cfg(js_sys_unstable_apis)]
8845 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8846 pub fn code_point_at(this: &JsString, pos: u32) -> Option<u32>;
8847
8848 // Next major: deprecate
8849 /// The `codePointAt()` method returns a non-negative integer that is the
8850 /// Unicode code point value.
8851 ///
8852 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8853 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8854 pub fn try_code_point_at(this: &JsString, pos: u32) -> Option<u16>;
8855
8856 /// The `concat()` method concatenates the string arguments to the calling
8857 /// string and returns a new string.
8858 ///
8859 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8860 #[cfg(not(js_sys_unstable_apis))]
8861 #[wasm_bindgen(method, js_class = "String")]
8862 pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
8863
8864 /// The `concat()` method concatenates the string arguments to the calling
8865 /// string and returns a new string.
8866 ///
8867 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8868 #[cfg(js_sys_unstable_apis)]
8869 #[wasm_bindgen(method, js_class = "String")]
8870 pub fn concat(this: &JsString, string: &JsString) -> JsString;
8871
8872 /// The `concat()` method concatenates the string arguments to the calling
8873 /// string and returns a new string.
8874 ///
8875 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8876 #[wasm_bindgen(method, js_class = "String")]
8877 pub fn concat_many(this: &JsString, strings: &[JsString]) -> JsString;
8878
8879 /// The `endsWith()` method determines whether a string ends with the characters of a
8880 /// specified string, returning true or false as appropriate.
8881 ///
8882 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
8883 #[cfg(not(js_sys_unstable_apis))]
8884 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
8885 pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
8886
8887 /// The `endsWith()` method determines whether a string ends with the characters of a
8888 /// specified string, returning true or false as appropriate.
8889 ///
8890 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
8891 #[cfg(js_sys_unstable_apis)]
8892 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
8893 pub fn ends_with(this: &JsString, search_string: &str) -> bool;
8894
8895 /// The static `String.fromCharCode()` method returns a string created from
8896 /// the specified sequence of UTF-16 code units.
8897 ///
8898 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8899 ///
8900 /// # Notes
8901 ///
8902 /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
8903 /// with different arities.
8904 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
8905 pub fn from_char_code(char_codes: &[u16]) -> JsString;
8906
8907 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8908 #[cfg(not(js_sys_unstable_apis))]
8909 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8910 pub fn from_char_code1(a: u32) -> JsString;
8911
8912 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8913 #[cfg(js_sys_unstable_apis)]
8914 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8915 pub fn from_char_code1(a: u16) -> JsString;
8916
8917 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8918 #[cfg(not(js_sys_unstable_apis))]
8919 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8920 pub fn from_char_code2(a: u32, b: u32) -> JsString;
8921
8922 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8923 #[cfg(js_sys_unstable_apis)]
8924 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8925 pub fn from_char_code2(a: u16, b: u16) -> JsString;
8926
8927 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8928 #[cfg(not(js_sys_unstable_apis))]
8929 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8930 pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
8931
8932 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8933 #[cfg(js_sys_unstable_apis)]
8934 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8935 pub fn from_char_code3(a: u16, b: u16, c: u16) -> JsString;
8936
8937 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8938 #[cfg(not(js_sys_unstable_apis))]
8939 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8940 pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
8941
8942 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8943 #[cfg(js_sys_unstable_apis)]
8944 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8945 pub fn from_char_code4(a: u16, b: u16, c: u16, d: u16) -> JsString;
8946
8947 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8948 #[cfg(not(js_sys_unstable_apis))]
8949 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8950 pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
8951
8952 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8953 #[cfg(js_sys_unstable_apis)]
8954 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8955 pub fn from_char_code5(a: u16, b: u16, c: u16, d: u16, e: u16) -> JsString;
8956
8957 /// The static `String.fromCodePoint()` method returns a string created by
8958 /// using the specified sequence of code points.
8959 ///
8960 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8961 ///
8962 /// # Exceptions
8963 ///
8964 /// A RangeError is thrown if an invalid Unicode code point is given
8965 ///
8966 /// # Notes
8967 ///
8968 /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
8969 /// with different arities.
8970 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
8971 pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
8972
8973 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8974 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8975 pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
8976
8977 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8978 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8979 pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
8980
8981 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8982 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8983 pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
8984
8985 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8986 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8987 pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
8988
8989 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8990 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8991 pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
8992
8993 /// The `includes()` method determines whether one string may be found
8994 /// within another string, returning true or false as appropriate.
8995 ///
8996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
8997 #[wasm_bindgen(method, js_class = "String")]
8998 pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
8999
9000 /// The `indexOf()` method returns the index within the calling String
9001 /// object of the first occurrence of the specified value, starting the
9002 /// search at fromIndex. Returns -1 if the value is not found.
9003 ///
9004 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
9005 #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
9006 pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9007
9008 /// The `lastIndexOf()` method returns the index within the calling String
9009 /// object of the last occurrence of the specified value, searching
9010 /// backwards from fromIndex. Returns -1 if the value is not found.
9011 ///
9012 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
9013 #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
9014 pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9015
9016 /// The `localeCompare()` method returns a number indicating whether
9017 /// a reference string comes before or after or is the same as
9018 /// the given string in sort order.
9019 ///
9020 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9021 #[cfg(not(js_sys_unstable_apis))]
9022 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9023 pub fn locale_compare(
9024 this: &JsString,
9025 compare_string: &str,
9026 locales: &Array,
9027 options: &Object,
9028 ) -> i32;
9029
9030 /// The `localeCompare()` method returns a number indicating whether
9031 /// a reference string comes before or after or is the same as
9032 /// the given string in sort order.
9033 ///
9034 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9035 #[cfg(js_sys_unstable_apis)]
9036 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9037 pub fn locale_compare(
9038 this: &JsString,
9039 compare_string: &str,
9040 locales: &[JsString],
9041 options: &Intl::CollatorOptions,
9042 ) -> i32;
9043
9044 /// The `match()` method retrieves the matches when matching a string against a regular expression.
9045 ///
9046 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
9047 #[wasm_bindgen(method, js_class = "String", js_name = match)]
9048 pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
9049
9050 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9051 ///
9052 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9053 #[cfg(not(js_sys_unstable_apis))]
9054 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9055 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
9056
9057 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9058 ///
9059 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9060 #[cfg(js_sys_unstable_apis)]
9061 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9062 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator<RegExpMatchArray>;
9063
9064 /// The `normalize()` method returns the Unicode Normalization Form
9065 /// of a given string (if the value isn't a string, it will be converted to one first).
9066 ///
9067 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
9068 #[wasm_bindgen(method, js_class = "String")]
9069 pub fn normalize(this: &JsString, form: &str) -> JsString;
9070
9071 /// The `padEnd()` method pads the current string with a given string
9072 /// (repeated, if needed) so that the resulting string reaches a given
9073 /// length. The padding is applied from the end (right) of the current
9074 /// string.
9075 ///
9076 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
9077 #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
9078 pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9079
9080 /// The `padStart()` method pads the current string with another string
9081 /// (repeated, if needed) so that the resulting string reaches the given
9082 /// length. The padding is applied from the start (left) of the current
9083 /// string.
9084 ///
9085 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
9086 #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
9087 pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9088
9089 /// The `repeat()` method constructs and returns a new string which contains the specified
9090 /// number of copies of the string on which it was called, concatenated together.
9091 ///
9092 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
9093 #[wasm_bindgen(method, js_class = "String")]
9094 pub fn repeat(this: &JsString, count: i32) -> JsString;
9095
9096 /// The `replace()` method returns a new string with some or all matches of a pattern
9097 /// replaced by a replacement. The pattern can be a string or a RegExp, and
9098 /// the replacement can be a string or a function to be called for each match.
9099 ///
9100 /// Note: The original string will remain unchanged.
9101 ///
9102 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9103 #[wasm_bindgen(method, js_class = "String")]
9104 pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9105
9106 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9107 #[cfg(not(js_sys_unstable_apis))]
9108 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9109 pub fn replace_with_function(
9110 this: &JsString,
9111 pattern: &str,
9112 replacement: &Function,
9113 ) -> JsString;
9114
9115 /// The replacer function signature is `(match, offset, string) -> replacement`
9116 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9117 /// when capture groups are present.
9118 ///
9119 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9120 #[cfg(js_sys_unstable_apis)]
9121 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9122 pub fn replace_with_function(
9123 this: &JsString,
9124 pattern: &str,
9125 replacement: &Function<fn(JsString) -> JsString>,
9126 ) -> JsString;
9127
9128 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9129 pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
9130
9131 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9132 #[cfg(not(js_sys_unstable_apis))]
9133 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9134 pub fn replace_by_pattern_with_function(
9135 this: &JsString,
9136 pattern: &RegExp,
9137 replacement: &Function,
9138 ) -> JsString;
9139
9140 /// The replacer function signature is `(match, offset, string) -> replacement`
9141 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9142 /// when capture groups are present.
9143 ///
9144 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9145 #[cfg(js_sys_unstable_apis)]
9146 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9147 pub fn replace_by_pattern_with_function(
9148 this: &JsString,
9149 pattern: &RegExp,
9150 replacement: &Function<fn(JsString) -> JsString>,
9151 ) -> JsString;
9152
9153 /// The `replace_all()` method returns a new string with all matches of a pattern
9154 /// replaced by a replacement. The pattern can be a string or a global RegExp, and
9155 /// the replacement can be a string or a function to be called for each match.
9156 ///
9157 /// Note: The original string will remain unchanged.
9158 ///
9159 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9160 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9161 pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9162
9163 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9164 #[cfg(not(js_sys_unstable_apis))]
9165 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9166 pub fn replace_all_with_function(
9167 this: &JsString,
9168 pattern: &str,
9169 replacement: &Function,
9170 ) -> JsString;
9171
9172 /// The replacer function signature is `(match, offset, string) -> replacement`
9173 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9174 /// when capture groups are present.
9175 ///
9176 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9177 #[cfg(js_sys_unstable_apis)]
9178 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9179 pub fn replace_all_with_function(
9180 this: &JsString,
9181 pattern: &str,
9182 replacement: &Function<fn(JsString) -> JsString>,
9183 ) -> JsString;
9184
9185 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9186 pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
9187 -> JsString;
9188
9189 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9190 #[cfg(not(js_sys_unstable_apis))]
9191 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9192 pub fn replace_all_by_pattern_with_function(
9193 this: &JsString,
9194 pattern: &RegExp,
9195 replacement: &Function,
9196 ) -> JsString;
9197
9198 /// The replacer function signature is `(match, offset, string) -> replacement`
9199 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9200 /// when capture groups are present.
9201 ///
9202 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9203 #[cfg(js_sys_unstable_apis)]
9204 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9205 pub fn replace_all_by_pattern_with_function(
9206 this: &JsString,
9207 pattern: &RegExp,
9208 replacement: &Function<fn(JsString) -> JsString>,
9209 ) -> JsString;
9210
9211 /// The `search()` method executes a search for a match between
9212 /// a regular expression and this String object.
9213 ///
9214 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
9215 #[wasm_bindgen(method, js_class = "String")]
9216 pub fn search(this: &JsString, pattern: &RegExp) -> i32;
9217
9218 /// The `slice()` method extracts a section of a string and returns it as a
9219 /// new string, without modifying the original string.
9220 ///
9221 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
9222 #[wasm_bindgen(method, js_class = "String")]
9223 pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
9224
9225 /// The `split()` method splits a String object into an array of strings by separating the string
9226 /// into substrings, using a specified separator string to determine where to make each split.
9227 ///
9228 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9229 #[wasm_bindgen(method, js_class = "String")]
9230 pub fn split(this: &JsString, separator: &str) -> Array;
9231
9232 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9233 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9234 pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
9235
9236 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9237 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9238 pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
9239
9240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9241 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9242 pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
9243
9244 /// The `startsWith()` method determines whether a string begins with the
9245 /// characters of a specified string, returning true or false as
9246 /// appropriate.
9247 ///
9248 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
9249 #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
9250 pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
9251
9252 /// The `substring()` method returns the part of the string between the
9253 /// start and end indexes, or to the end of the string.
9254 ///
9255 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
9256 #[wasm_bindgen(method, js_class = "String")]
9257 pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
9258
9259 /// The `substr()` method returns the part of a string between
9260 /// the start index and a number of characters after it.
9261 ///
9262 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
9263 #[wasm_bindgen(method, js_class = "String")]
9264 pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
9265
9266 /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
9267 /// according to any locale-specific case mappings.
9268 ///
9269 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
9270 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
9271 pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
9272
9273 /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
9274 /// according to any locale-specific case mappings.
9275 ///
9276 /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
9277 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
9278 pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
9279
9280 /// The `toLowerCase()` method returns the calling string value
9281 /// converted to lower case.
9282 ///
9283 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
9284 #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
9285 pub fn to_lower_case(this: &JsString) -> JsString;
9286
9287 /// The `toString()` method returns a string representing the specified
9288 /// object.
9289 ///
9290 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
9291 #[cfg(not(js_sys_unstable_apis))]
9292 #[wasm_bindgen(method, js_class = "String", js_name = toString)]
9293 pub fn to_string(this: &JsString) -> JsString;
9294
9295 /// The `toUpperCase()` method returns the calling string value converted to
9296 /// uppercase (the value will be converted to a string if it isn't one).
9297 ///
9298 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
9299 #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
9300 pub fn to_upper_case(this: &JsString) -> JsString;
9301
9302 /// The `trim()` method removes whitespace from both ends of a string.
9303 /// Whitespace in this context is all the whitespace characters (space, tab,
9304 /// no-break space, etc.) and all the line terminator characters (LF, CR,
9305 /// etc.).
9306 ///
9307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
9308 #[wasm_bindgen(method, js_class = "String")]
9309 pub fn trim(this: &JsString) -> JsString;
9310
9311 /// The `trimEnd()` method removes whitespace from the end of a string.
9312 /// `trimRight()` is an alias of this method.
9313 ///
9314 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9315 #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
9316 pub fn trim_end(this: &JsString) -> JsString;
9317
9318 /// The `trimEnd()` method removes whitespace from the end of a string.
9319 /// `trimRight()` is an alias of this method.
9320 ///
9321 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9322 #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
9323 pub fn trim_right(this: &JsString) -> JsString;
9324
9325 /// The `trimStart()` method removes whitespace from the beginning of a
9326 /// string. `trimLeft()` is an alias of this method.
9327 ///
9328 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9329 #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
9330 pub fn trim_start(this: &JsString) -> JsString;
9331
9332 /// The `trimStart()` method removes whitespace from the beginning of a
9333 /// string. `trimLeft()` is an alias of this method.
9334 ///
9335 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9336 #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
9337 pub fn trim_left(this: &JsString) -> JsString;
9338
9339 /// The `valueOf()` method returns the primitive value of a `String` object.
9340 ///
9341 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
9342 #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
9343 pub fn value_of(this: &JsString) -> JsString;
9344
9345 /// The static `raw()` method is a tag function of template literals,
9346 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9347 ///
9348 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9349 #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
9350 pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
9351
9352 /// The static `raw()` method is a tag function of template literals,
9353 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9354 ///
9355 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9356 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9357 pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
9358
9359 /// The static `raw()` method is a tag function of template literals,
9360 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9361 ///
9362 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9363 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9364 pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
9365
9366 /// The static `raw()` method is a tag function of template literals,
9367 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9368 ///
9369 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9370 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9371 pub fn raw_2(
9372 call_site: &Object,
9373 substitutions1: &str,
9374 substitutions2: &str,
9375 ) -> Result<JsString, JsValue>;
9376
9377 /// The static `raw()` method is a tag function of template literals,
9378 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9379 ///
9380 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9381 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9382 pub fn raw_3(
9383 call_site: &Object,
9384 substitutions1: &str,
9385 substitutions2: &str,
9386 substitutions3: &str,
9387 ) -> Result<JsString, JsValue>;
9388
9389 /// The static `raw()` method is a tag function of template literals,
9390 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9391 ///
9392 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9393 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9394 pub fn raw_4(
9395 call_site: &Object,
9396 substitutions1: &str,
9397 substitutions2: &str,
9398 substitutions3: &str,
9399 substitutions4: &str,
9400 ) -> Result<JsString, JsValue>;
9401
9402 /// The static `raw()` method is a tag function of template literals,
9403 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9404 ///
9405 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9406 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9407 pub fn raw_5(
9408 call_site: &Object,
9409 substitutions1: &str,
9410 substitutions2: &str,
9411 substitutions3: &str,
9412 substitutions4: &str,
9413 substitutions5: &str,
9414 ) -> Result<JsString, JsValue>;
9415
9416 /// The static `raw()` method is a tag function of template literals,
9417 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9418 ///
9419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9420 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9421 pub fn raw_6(
9422 call_site: &Object,
9423 substitutions1: &str,
9424 substitutions2: &str,
9425 substitutions3: &str,
9426 substitutions4: &str,
9427 substitutions5: &str,
9428 substitutions6: &str,
9429 ) -> Result<JsString, JsValue>;
9430
9431 /// The static `raw()` method is a tag function of template literals,
9432 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9433 ///
9434 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9435 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9436 pub fn raw_7(
9437 call_site: &Object,
9438 substitutions1: &str,
9439 substitutions2: &str,
9440 substitutions3: &str,
9441 substitutions4: &str,
9442 substitutions5: &str,
9443 substitutions6: &str,
9444 substitutions7: &str,
9445 ) -> Result<JsString, JsValue>;
9446}
9447
9448// These upcasts are non-castable due to the constraints on the function
9449// but the UpcastFrom covariance must still extend through closure types.
9450// (impl UpcastFrom really just means CovariantGeneric relation)
9451impl UpcastFrom<String> for JsString {}
9452impl UpcastFrom<JsString> for String {}
9453
9454impl UpcastFrom<&str> for JsString {}
9455impl UpcastFrom<JsString> for &str {}
9456
9457impl UpcastFrom<char> for JsString {}
9458impl UpcastFrom<JsString> for char {}
9459
9460impl JsString {
9461 /// Returns the `JsString` value of this JS value if it's an instance of a
9462 /// string.
9463 ///
9464 /// If this JS value is not an instance of a string then this returns
9465 /// `None`.
9466 #[cfg(not(js_sys_unstable_apis))]
9467 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
9468 pub fn try_from(val: &JsValue) -> Option<&JsString> {
9469 val.dyn_ref()
9470 }
9471
9472 /// Returns whether this string is a valid UTF-16 string.
9473 ///
9474 /// This is useful for learning whether `String::from(..)` will return a
9475 /// lossless representation of the JS string. If this string contains
9476 /// unpaired surrogates then `String::from` will succeed but it will be a
9477 /// lossy representation of the JS string because unpaired surrogates will
9478 /// become replacement characters.
9479 ///
9480 /// If this function returns `false` then to get a lossless representation
9481 /// of the string you'll need to manually use the `iter` method (or the
9482 /// `char_code_at` accessor) to view the raw character codes.
9483 ///
9484 /// For more information, see the documentation on [JS strings vs Rust
9485 /// strings][docs]
9486 ///
9487 /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
9488 pub fn is_valid_utf16(&self) -> bool {
9489 core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
9490 }
9491
9492 /// Returns an iterator over the `u16` character codes that make up this JS
9493 /// string.
9494 ///
9495 /// This method will call `char_code_at` for each code in this JS string,
9496 /// returning an iterator of the codes in sequence.
9497 pub fn iter(
9498 &self,
9499 ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
9500 (0..self.length()).map(move |i| self.char_code_at(i) as u16)
9501 }
9502
9503 /// If this string consists of a single Unicode code point, then this method
9504 /// converts it into a Rust `char` without doing any allocations.
9505 ///
9506 /// If this JS value is not a valid UTF-8 or consists of more than a single
9507 /// codepoint, then this returns `None`.
9508 ///
9509 /// Note that a single Unicode code point might be represented as more than
9510 /// one code unit on the JavaScript side. For example, a JavaScript string
9511 /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
9512 /// corresponds to a character '𐐷'.
9513 pub fn as_char(&self) -> Option<char> {
9514 let len = self.length();
9515
9516 if len == 0 || len > 2 {
9517 return None;
9518 }
9519
9520 #[cfg(not(js_sys_unstable_apis))]
9521 let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
9522 #[cfg(js_sys_unstable_apis)]
9523 let cp = self.code_point_at(0)?;
9524
9525 let c = core::char::from_u32(cp)?;
9526
9527 if c.len_utf16() as u32 == len {
9528 Some(c)
9529 } else {
9530 None
9531 }
9532 }
9533}
9534
9535impl PartialEq<str> for JsString {
9536 #[allow(clippy::cmp_owned)] // prevent infinite recursion
9537 fn eq(&self, other: &str) -> bool {
9538 String::from(self) == other
9539 }
9540}
9541
9542impl<'a> PartialEq<&'a str> for JsString {
9543 fn eq(&self, other: &&'a str) -> bool {
9544 <JsString as PartialEq<str>>::eq(self, other)
9545 }
9546}
9547
9548impl PartialEq<String> for JsString {
9549 fn eq(&self, other: &String) -> bool {
9550 <JsString as PartialEq<str>>::eq(self, other)
9551 }
9552}
9553
9554impl<'a> PartialEq<&'a String> for JsString {
9555 fn eq(&self, other: &&'a String) -> bool {
9556 <JsString as PartialEq<str>>::eq(self, other)
9557 }
9558}
9559
9560impl Default for JsString {
9561 fn default() -> Self {
9562 Self::from("")
9563 }
9564}
9565
9566impl<'a> From<&'a str> for JsString {
9567 fn from(s: &'a str) -> Self {
9568 JsString::unchecked_from_js(JsValue::from_str(s))
9569 }
9570}
9571
9572impl From<String> for JsString {
9573 fn from(s: String) -> Self {
9574 From::from(&*s)
9575 }
9576}
9577
9578impl From<char> for JsString {
9579 #[inline]
9580 fn from(c: char) -> Self {
9581 JsString::from_code_point1(c as u32).unwrap_throw()
9582 }
9583}
9584
9585impl<'a> From<&'a JsString> for String {
9586 fn from(s: &'a JsString) -> Self {
9587 s.obj.as_string().unwrap_throw()
9588 }
9589}
9590
9591impl From<JsString> for String {
9592 fn from(s: JsString) -> Self {
9593 From::from(&s)
9594 }
9595}
9596
9597impl fmt::Debug for JsString {
9598 #[inline]
9599 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9600 fmt::Debug::fmt(&String::from(self), f)
9601 }
9602}
9603
9604impl fmt::Display for JsString {
9605 #[inline]
9606 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9607 fmt::Display::fmt(&String::from(self), f)
9608 }
9609}
9610
9611impl str::FromStr for JsString {
9612 type Err = convert::Infallible;
9613 fn from_str(s: &str) -> Result<Self, Self::Err> {
9614 Ok(JsString::from(s))
9615 }
9616}
9617
9618// Symbol
9619#[wasm_bindgen]
9620extern "C" {
9621 #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
9622 #[derive(Clone, Debug)]
9623 pub type Symbol;
9624
9625 /// The `Symbol.hasInstance` well-known symbol is used to determine
9626 /// if a constructor object recognizes an object as its instance.
9627 /// The `instanceof` operator's behavior can be customized by this symbol.
9628 ///
9629 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
9630 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = hasInstance)]
9631 pub fn has_instance() -> Symbol;
9632
9633 /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
9634 /// if an object should be flattened to its array elements when using the
9635 /// `Array.prototype.concat()` method.
9636 ///
9637 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
9638 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = isConcatSpreadable)]
9639 pub fn is_concat_spreadable() -> Symbol;
9640
9641 /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
9642 /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
9643 ///
9644 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
9645 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncIterator)]
9646 pub fn async_iterator() -> Symbol;
9647
9648 /// The `Symbol.iterator` well-known symbol specifies the default iterator
9649 /// for an object. Used by `for...of`.
9650 ///
9651 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
9652 #[wasm_bindgen(static_method_of = Symbol, getter)]
9653 pub fn iterator() -> Symbol;
9654
9655 /// The `Symbol.match` well-known symbol specifies the matching of a regular
9656 /// expression against a string. This function is called by the
9657 /// `String.prototype.match()` method.
9658 ///
9659 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
9660 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = match)]
9661 pub fn match_() -> Symbol;
9662
9663 /// The `Symbol.replace` well-known symbol specifies the method that
9664 /// replaces matched substrings of a string. This function is called by the
9665 /// `String.prototype.replace()` method.
9666 ///
9667 /// For more information, see `RegExp.prototype[@@replace]()` and
9668 /// `String.prototype.replace()`.
9669 ///
9670 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
9671 #[wasm_bindgen(static_method_of = Symbol, getter)]
9672 pub fn replace() -> Symbol;
9673
9674 /// The `Symbol.search` well-known symbol specifies the method that returns
9675 /// the index within a string that matches the regular expression. This
9676 /// function is called by the `String.prototype.search()` method.
9677 ///
9678 /// For more information, see `RegExp.prototype[@@search]()` and
9679 /// `String.prototype.search()`.
9680 ///
9681 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
9682 #[wasm_bindgen(static_method_of = Symbol, getter)]
9683 pub fn search() -> Symbol;
9684
9685 /// The well-known symbol `Symbol.species` specifies a function-valued
9686 /// property that the constructor function uses to create derived objects.
9687 ///
9688 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
9689 #[wasm_bindgen(static_method_of = Symbol, getter)]
9690 pub fn species() -> Symbol;
9691
9692 /// The `Symbol.split` well-known symbol specifies the method that splits a
9693 /// string at the indices that match a regular expression. This function is
9694 /// called by the `String.prototype.split()` method.
9695 ///
9696 /// For more information, see `RegExp.prototype[@@split]()` and
9697 /// `String.prototype.split()`.
9698 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
9699 #[wasm_bindgen(static_method_of = Symbol, getter)]
9700 pub fn split() -> Symbol;
9701
9702 /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
9703 /// property that is called to convert an object to a corresponding
9704 /// primitive value.
9705 ///
9706 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
9707 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toPrimitive)]
9708 pub fn to_primitive() -> Symbol;
9709
9710 /// The `Symbol.toStringTag` well-known symbol is a string valued property
9711 /// that is used in the creation of the default string description of an
9712 /// object. It is accessed internally by the `Object.prototype.toString()`
9713 /// method.
9714 ///
9715 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9716 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toStringTag)]
9717 pub fn to_string_tag() -> Symbol;
9718
9719 /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
9720 /// the given key and returns it if found.
9721 /// Otherwise a new symbol gets created in the global symbol registry with this key.
9722 ///
9723 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
9724 #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
9725 pub fn for_(key: &str) -> Symbol;
9726
9727 /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
9728 ///
9729 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
9730 #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
9731 pub fn key_for(sym: &Symbol) -> JsValue;
9732
9733 // Next major: deprecate
9734 /// The `toString()` method returns a string representing the specified Symbol object.
9735 ///
9736 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9737 #[wasm_bindgen(method, js_name = toString)]
9738 pub fn to_string(this: &Symbol) -> JsString;
9739
9740 /// The `toString()` method returns a string representing the specified Symbol object.
9741 ///
9742 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9743 #[wasm_bindgen(method, js_name = toString)]
9744 pub fn to_js_string(this: &Symbol) -> JsString;
9745
9746 /// The `Symbol.unscopables` well-known symbol is used to specify an object
9747 /// value of whose own and inherited property names are excluded from the
9748 /// with environment bindings of the associated object.
9749 ///
9750 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
9751 #[wasm_bindgen(static_method_of = Symbol, getter)]
9752 pub fn unscopables() -> Symbol;
9753
9754 /// The `valueOf()` method returns the primitive value of a Symbol object.
9755 ///
9756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
9757 #[wasm_bindgen(method, js_name = valueOf)]
9758 pub fn value_of(this: &Symbol) -> Symbol;
9759}
9760
9761#[allow(non_snake_case)]
9762pub mod Intl {
9763 use super::*;
9764
9765 // Intl
9766 #[wasm_bindgen]
9767 extern "C" {
9768 /// The `Intl.getCanonicalLocales()` method returns an array containing
9769 /// the canonical locale names. Duplicates will be omitted and elements
9770 /// will be validated as structurally valid language tags.
9771 ///
9772 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
9773 #[cfg(not(js_sys_unstable_apis))]
9774 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
9775 pub fn get_canonical_locales(s: &JsValue) -> Array;
9776
9777 /// The `Intl.getCanonicalLocales()` method returns an array containing
9778 /// the canonical locale names. Duplicates will be omitted and elements
9779 /// will be validated as structurally valid language tags.
9780 ///
9781 /// Throws a `RangeError` if any of the strings are not valid locale identifiers.
9782 ///
9783 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
9784 #[cfg(js_sys_unstable_apis)]
9785 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl, catch)]
9786 pub fn get_canonical_locales(s: &[JsString]) -> Result<Array<JsString>, JsValue>;
9787
9788 /// The `Intl.supportedValuesOf()` method returns an array containing the
9789 /// supported calendar, collation, currency, numbering system, or unit values
9790 /// supported by the implementation.
9791 ///
9792 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
9793 #[wasm_bindgen(js_name = supportedValuesOf, js_namespace = Intl)]
9794 pub fn supported_values_of(key: SupportedValuesKey) -> Array<JsString>;
9795 }
9796
9797 // Intl string enums
9798
9799 /// Key for `Intl.supportedValuesOf()`.
9800 #[wasm_bindgen]
9801 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9802 pub enum SupportedValuesKey {
9803 Calendar = "calendar",
9804 Collation = "collation",
9805 Currency = "currency",
9806 NumberingSystem = "numberingSystem",
9807 TimeZone = "timeZone",
9808 Unit = "unit",
9809 }
9810
9811 /// Locale matching algorithm for Intl constructors.
9812 #[wasm_bindgen]
9813 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9814 pub enum LocaleMatcher {
9815 Lookup = "lookup",
9816 BestFit = "best fit",
9817 }
9818
9819 /// Usage for `Intl.Collator`.
9820 #[wasm_bindgen]
9821 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9822 pub enum CollatorUsage {
9823 Sort = "sort",
9824 Search = "search",
9825 }
9826
9827 /// Sensitivity for `Intl.Collator`.
9828 #[wasm_bindgen]
9829 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9830 pub enum CollatorSensitivity {
9831 Base = "base",
9832 Accent = "accent",
9833 Case = "case",
9834 Variant = "variant",
9835 }
9836
9837 /// Case first option for `Intl.Collator`.
9838 #[wasm_bindgen]
9839 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9840 pub enum CollatorCaseFirst {
9841 Upper = "upper",
9842 Lower = "lower",
9843 False = "false",
9844 }
9845
9846 /// Style for `Intl.NumberFormat`.
9847 #[wasm_bindgen]
9848 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9849 pub enum NumberFormatStyle {
9850 Decimal = "decimal",
9851 Currency = "currency",
9852 Percent = "percent",
9853 Unit = "unit",
9854 }
9855
9856 /// Currency display for `Intl.NumberFormat`.
9857 #[wasm_bindgen]
9858 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9859 pub enum CurrencyDisplay {
9860 Code = "code",
9861 Symbol = "symbol",
9862 NarrowSymbol = "narrowSymbol",
9863 Name = "name",
9864 }
9865
9866 /// Currency sign for `Intl.NumberFormat`.
9867 #[wasm_bindgen]
9868 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9869 pub enum CurrencySign {
9870 Standard = "standard",
9871 Accounting = "accounting",
9872 }
9873
9874 /// Unit display for `Intl.NumberFormat`.
9875 #[wasm_bindgen]
9876 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9877 pub enum UnitDisplay {
9878 Short = "short",
9879 Narrow = "narrow",
9880 Long = "long",
9881 }
9882
9883 /// Notation for `Intl.NumberFormat`.
9884 #[wasm_bindgen]
9885 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9886 pub enum NumberFormatNotation {
9887 Standard = "standard",
9888 Scientific = "scientific",
9889 Engineering = "engineering",
9890 Compact = "compact",
9891 }
9892
9893 /// Compact display for `Intl.NumberFormat`.
9894 #[wasm_bindgen]
9895 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9896 pub enum CompactDisplay {
9897 Short = "short",
9898 Long = "long",
9899 }
9900
9901 /// Sign display for `Intl.NumberFormat`.
9902 #[wasm_bindgen]
9903 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9904 pub enum SignDisplay {
9905 Auto = "auto",
9906 Never = "never",
9907 Always = "always",
9908 ExceptZero = "exceptZero",
9909 }
9910
9911 /// Rounding mode for `Intl.NumberFormat`.
9912 #[wasm_bindgen]
9913 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9914 pub enum RoundingMode {
9915 Ceil = "ceil",
9916 Floor = "floor",
9917 Expand = "expand",
9918 Trunc = "trunc",
9919 HalfCeil = "halfCeil",
9920 HalfFloor = "halfFloor",
9921 HalfExpand = "halfExpand",
9922 HalfTrunc = "halfTrunc",
9923 HalfEven = "halfEven",
9924 }
9925
9926 /// Rounding priority for `Intl.NumberFormat`.
9927 #[wasm_bindgen]
9928 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9929 pub enum RoundingPriority {
9930 Auto = "auto",
9931 MorePrecision = "morePrecision",
9932 LessPrecision = "lessPrecision",
9933 }
9934
9935 /// Trailing zero display for `Intl.NumberFormat`.
9936 #[wasm_bindgen]
9937 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9938 pub enum TrailingZeroDisplay {
9939 Auto = "auto",
9940 StripIfInteger = "stripIfInteger",
9941 }
9942
9943 /// Use grouping option for `Intl.NumberFormat`.
9944 ///
9945 /// Determines whether to use grouping separators, such as thousands
9946 /// separators or thousand/lakh/crore separators.
9947 ///
9948 /// The default is `Min2` if notation is "compact", and `Auto` otherwise.
9949 ///
9950 /// Note: The string values `"true"` and `"false"` are accepted by JavaScript
9951 /// but are always converted to the default value. Use `True` and `False`
9952 /// variants for the boolean behavior.
9953 ///
9954 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#usegrouping)
9955 #[wasm_bindgen]
9956 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9957 pub enum UseGrouping {
9958 /// Display grouping separators even if the locale prefers otherwise.
9959 Always = "always",
9960 /// Display grouping separators based on the locale preference,
9961 /// which may also be dependent on the currency.
9962 Auto = "auto",
9963 /// Display grouping separators when there are at least 2 digits in a group.
9964 Min2 = "min2",
9965 /// Same as `Always`. Display grouping separators even if the locale prefers otherwise.
9966 True = "true",
9967 /// Display no grouping separators.
9968 False = "false",
9969 }
9970
9971 /// Date/time style for `Intl.DateTimeFormat`.
9972 #[wasm_bindgen]
9973 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9974 pub enum DateTimeStyle {
9975 Full = "full",
9976 Long = "long",
9977 Medium = "medium",
9978 Short = "short",
9979 }
9980
9981 /// Hour cycle for `Intl.DateTimeFormat`.
9982 #[wasm_bindgen]
9983 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9984 pub enum HourCycle {
9985 H11 = "h11",
9986 H12 = "h12",
9987 H23 = "h23",
9988 H24 = "h24",
9989 }
9990
9991 /// Weekday format for `Intl.DateTimeFormat`.
9992 #[wasm_bindgen]
9993 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9994 pub enum WeekdayFormat {
9995 Narrow = "narrow",
9996 Short = "short",
9997 Long = "long",
9998 }
9999
10000 /// Era format for `Intl.DateTimeFormat`.
10001 #[wasm_bindgen]
10002 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10003 pub enum EraFormat {
10004 Narrow = "narrow",
10005 Short = "short",
10006 Long = "long",
10007 }
10008
10009 /// Year format for `Intl.DateTimeFormat`.
10010 #[wasm_bindgen]
10011 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10012 pub enum YearFormat {
10013 Numeric = "numeric",
10014 TwoDigit = "2-digit",
10015 }
10016
10017 /// Month format for `Intl.DateTimeFormat`.
10018 #[wasm_bindgen]
10019 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10020 pub enum MonthFormat {
10021 #[wasm_bindgen]
10022 Numeric = "numeric",
10023 #[wasm_bindgen]
10024 TwoDigit = "2-digit",
10025 #[wasm_bindgen]
10026 Narrow = "narrow",
10027 #[wasm_bindgen]
10028 Short = "short",
10029 #[wasm_bindgen]
10030 Long = "long",
10031 }
10032
10033 /// Day format for `Intl.DateTimeFormat`.
10034 #[wasm_bindgen]
10035 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10036 pub enum DayFormat {
10037 #[wasm_bindgen]
10038 Numeric = "numeric",
10039 #[wasm_bindgen]
10040 TwoDigit = "2-digit",
10041 }
10042
10043 /// Hour/minute/second format for `Intl.DateTimeFormat`.
10044 #[wasm_bindgen]
10045 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10046 pub enum NumericFormat {
10047 #[wasm_bindgen]
10048 Numeric = "numeric",
10049 #[wasm_bindgen]
10050 TwoDigit = "2-digit",
10051 }
10052
10053 /// Time zone name format for `Intl.DateTimeFormat`.
10054 #[wasm_bindgen]
10055 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10056 pub enum TimeZoneNameFormat {
10057 Short = "short",
10058 Long = "long",
10059 ShortOffset = "shortOffset",
10060 LongOffset = "longOffset",
10061 ShortGeneric = "shortGeneric",
10062 LongGeneric = "longGeneric",
10063 }
10064
10065 /// Day period format for `Intl.DateTimeFormat`.
10066 #[wasm_bindgen]
10067 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10068 pub enum DayPeriodFormat {
10069 Narrow = "narrow",
10070 Short = "short",
10071 Long = "long",
10072 }
10073
10074 /// Part type for `DateTimeFormat.formatToParts()`.
10075 #[wasm_bindgen]
10076 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10077 pub enum DateTimeFormatPartType {
10078 Day = "day",
10079 DayPeriod = "dayPeriod",
10080 Era = "era",
10081 FractionalSecond = "fractionalSecond",
10082 Hour = "hour",
10083 Literal = "literal",
10084 Minute = "minute",
10085 Month = "month",
10086 RelatedYear = "relatedYear",
10087 Second = "second",
10088 TimeZoneName = "timeZoneName",
10089 Weekday = "weekday",
10090 Year = "year",
10091 YearName = "yearName",
10092 }
10093
10094 /// Part type for `NumberFormat.formatToParts()`.
10095 #[wasm_bindgen]
10096 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10097 pub enum NumberFormatPartType {
10098 Compact = "compact",
10099 Currency = "currency",
10100 Decimal = "decimal",
10101 ExponentInteger = "exponentInteger",
10102 ExponentMinusSign = "exponentMinusSign",
10103 ExponentSeparator = "exponentSeparator",
10104 Fraction = "fraction",
10105 Group = "group",
10106 Infinity = "infinity",
10107 Integer = "integer",
10108 Literal = "literal",
10109 MinusSign = "minusSign",
10110 Nan = "nan",
10111 PercentSign = "percentSign",
10112 PlusSign = "plusSign",
10113 Unit = "unit",
10114 Unknown = "unknown",
10115 }
10116
10117 /// Type for `Intl.PluralRules` (cardinal or ordinal).
10118 #[wasm_bindgen]
10119 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10120 pub enum PluralRulesType {
10121 Cardinal = "cardinal",
10122 Ordinal = "ordinal",
10123 }
10124
10125 /// Plural category returned by `PluralRules.select()`.
10126 #[wasm_bindgen]
10127 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10128 pub enum PluralCategory {
10129 Zero = "zero",
10130 One = "one",
10131 Two = "two",
10132 Few = "few",
10133 Many = "many",
10134 Other = "other",
10135 }
10136
10137 /// Numeric option for `Intl.RelativeTimeFormat`.
10138 #[wasm_bindgen]
10139 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10140 pub enum RelativeTimeFormatNumeric {
10141 Always = "always",
10142 Auto = "auto",
10143 }
10144
10145 /// Style for `Intl.RelativeTimeFormat`.
10146 #[wasm_bindgen]
10147 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10148 pub enum RelativeTimeFormatStyle {
10149 Long = "long",
10150 Short = "short",
10151 Narrow = "narrow",
10152 }
10153
10154 /// Unit for `RelativeTimeFormat.format()`.
10155 #[wasm_bindgen]
10156 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10157 pub enum RelativeTimeFormatUnit {
10158 Year = "year",
10159 Years = "years",
10160 Quarter = "quarter",
10161 Quarters = "quarters",
10162 Month = "month",
10163 Months = "months",
10164 Week = "week",
10165 Weeks = "weeks",
10166 Day = "day",
10167 Days = "days",
10168 Hour = "hour",
10169 Hours = "hours",
10170 Minute = "minute",
10171 Minutes = "minutes",
10172 Second = "second",
10173 Seconds = "seconds",
10174 }
10175
10176 /// Part type for `RelativeTimeFormat.formatToParts()`.
10177 #[wasm_bindgen]
10178 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10179 pub enum RelativeTimeFormatPartType {
10180 Literal = "literal",
10181 Integer = "integer",
10182 Decimal = "decimal",
10183 Fraction = "fraction",
10184 }
10185
10186 /// Source indicator for range format parts.
10187 ///
10188 /// Indicates which part of the range (start, end, or shared) a formatted
10189 /// part belongs to when using `formatRangeToParts()`.
10190 ///
10191 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts#description)
10192 #[wasm_bindgen]
10193 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10194 pub enum RangeSource {
10195 /// The part is from the start of the range.
10196 StartRange = "startRange",
10197 /// The part is from the end of the range.
10198 EndRange = "endRange",
10199 /// The part is shared between start and end (e.g., a separator or common element).
10200 Shared = "shared",
10201 }
10202
10203 /// Type for `Intl.ListFormat`.
10204 #[wasm_bindgen]
10205 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10206 pub enum ListFormatType {
10207 /// For lists of standalone items (default).
10208 Conjunction = "conjunction",
10209 /// For lists representing alternatives.
10210 Disjunction = "disjunction",
10211 /// For lists of values with units.
10212 Unit = "unit",
10213 }
10214
10215 /// Style for `Intl.ListFormat`.
10216 #[wasm_bindgen]
10217 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10218 pub enum ListFormatStyle {
10219 /// "A, B, and C" (default).
10220 Long = "long",
10221 /// "A, B, C".
10222 Short = "short",
10223 /// "A B C".
10224 Narrow = "narrow",
10225 }
10226
10227 /// Part type for `Intl.ListFormat.formatToParts()`.
10228 #[wasm_bindgen]
10229 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10230 pub enum ListFormatPartType {
10231 /// A value from the list.
10232 Element = "element",
10233 /// A linguistic construct (e.g., ", ", " and ").
10234 Literal = "literal",
10235 }
10236
10237 /// Type for `Intl.Segmenter`.
10238 #[wasm_bindgen]
10239 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10240 pub enum SegmenterGranularity {
10241 /// Segment by grapheme clusters (user-perceived characters).
10242 Grapheme = "grapheme",
10243 /// Segment by words.
10244 Word = "word",
10245 /// Segment by sentences.
10246 Sentence = "sentence",
10247 }
10248
10249 /// Type for `Intl.DisplayNames`.
10250 #[wasm_bindgen]
10251 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10252 pub enum DisplayNamesType {
10253 /// Language display names.
10254 Language = "language",
10255 /// Region display names.
10256 Region = "region",
10257 /// Script display names.
10258 Script = "script",
10259 /// Currency display names.
10260 Currency = "currency",
10261 /// Calendar display names.
10262 Calendar = "calendar",
10263 /// Date/time field display names.
10264 DateTimeField = "dateTimeField",
10265 }
10266
10267 /// Style for `Intl.DisplayNames`.
10268 #[wasm_bindgen]
10269 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10270 pub enum DisplayNamesStyle {
10271 /// Full display name (default).
10272 Long = "long",
10273 /// Abbreviated display name.
10274 Short = "short",
10275 /// Minimal display name.
10276 Narrow = "narrow",
10277 }
10278
10279 /// Fallback for `Intl.DisplayNames`.
10280 #[wasm_bindgen]
10281 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10282 pub enum DisplayNamesFallback {
10283 /// Return the input code if no display name is available (default).
10284 Code = "code",
10285 /// Return undefined if no display name is available.
10286 None = "none",
10287 }
10288
10289 /// Language display for `Intl.DisplayNames`.
10290 #[wasm_bindgen]
10291 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10292 pub enum DisplayNamesLanguageDisplay {
10293 /// Use dialect names (e.g., "British English").
10294 Dialect = "dialect",
10295 /// Use standard names (e.g., "English (United Kingdom)").
10296 Standard = "standard",
10297 }
10298
10299 // Intl.RelativeTimeFormatOptions
10300 #[wasm_bindgen]
10301 extern "C" {
10302 /// Options for `Intl.RelativeTimeFormat` constructor.
10303 ///
10304 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#options)
10305 #[wasm_bindgen(extends = Object)]
10306 #[derive(Clone, Debug)]
10307 pub type RelativeTimeFormatOptions;
10308
10309 #[wasm_bindgen(method, getter = localeMatcher)]
10310 pub fn get_locale_matcher(this: &RelativeTimeFormatOptions) -> Option<LocaleMatcher>;
10311 #[wasm_bindgen(method, setter = localeMatcher)]
10312 pub fn set_locale_matcher(this: &RelativeTimeFormatOptions, value: LocaleMatcher);
10313
10314 #[wasm_bindgen(method, getter = numeric)]
10315 pub fn get_numeric(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatNumeric>;
10316 #[wasm_bindgen(method, setter = numeric)]
10317 pub fn set_numeric(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatNumeric);
10318
10319 #[wasm_bindgen(method, getter = style)]
10320 pub fn get_style(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatStyle>;
10321 #[wasm_bindgen(method, setter = style)]
10322 pub fn set_style(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatStyle);
10323 }
10324
10325 impl RelativeTimeFormatOptions {
10326 pub fn new() -> RelativeTimeFormatOptions {
10327 JsCast::unchecked_into(Object::new())
10328 }
10329 }
10330
10331 impl Default for RelativeTimeFormatOptions {
10332 fn default() -> Self {
10333 RelativeTimeFormatOptions::new()
10334 }
10335 }
10336
10337 // Intl.ResolvedRelativeTimeFormatOptions
10338 #[wasm_bindgen]
10339 extern "C" {
10340 /// Resolved options returned by `Intl.RelativeTimeFormat.prototype.resolvedOptions()`.
10341 ///
10342 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
10343 #[wasm_bindgen(extends = RelativeTimeFormatOptions)]
10344 #[derive(Clone, Debug)]
10345 pub type ResolvedRelativeTimeFormatOptions;
10346
10347 /// The resolved locale string.
10348 #[wasm_bindgen(method, getter = locale)]
10349 pub fn get_locale(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10350
10351 /// The numbering system used.
10352 #[wasm_bindgen(method, getter = numberingSystem)]
10353 pub fn get_numbering_system(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10354 }
10355
10356 // Intl.RelativeTimeFormatPart
10357 #[wasm_bindgen]
10358 extern "C" {
10359 /// A part of the formatted relative time returned by `formatToParts()`.
10360 ///
10361 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
10362 #[wasm_bindgen(extends = Object)]
10363 #[derive(Clone, Debug)]
10364 pub type RelativeTimeFormatPart;
10365
10366 /// The type of this part.
10367 #[wasm_bindgen(method, getter = type)]
10368 pub fn type_(this: &RelativeTimeFormatPart) -> RelativeTimeFormatPartType;
10369
10370 /// The string value of this part.
10371 #[wasm_bindgen(method, getter = value)]
10372 pub fn value(this: &RelativeTimeFormatPart) -> JsString;
10373
10374 /// The unit used in this part (only for integer parts).
10375 #[wasm_bindgen(method, getter = unit)]
10376 pub fn unit(this: &RelativeTimeFormatPart) -> Option<JsString>;
10377 }
10378
10379 // Intl.LocaleMatcherOptions
10380 #[wasm_bindgen]
10381 extern "C" {
10382 /// Options for `supportedLocalesOf` methods.
10383 #[wasm_bindgen(extends = Object)]
10384 #[derive(Clone, Debug)]
10385 pub type LocaleMatcherOptions;
10386
10387 #[wasm_bindgen(method, getter = localeMatcher)]
10388 pub fn get_locale_matcher(this: &LocaleMatcherOptions) -> Option<LocaleMatcher>;
10389
10390 #[wasm_bindgen(method, setter = localeMatcher)]
10391 pub fn set_locale_matcher(this: &LocaleMatcherOptions, value: LocaleMatcher);
10392 }
10393
10394 impl LocaleMatcherOptions {
10395 pub fn new() -> LocaleMatcherOptions {
10396 JsCast::unchecked_into(Object::new())
10397 }
10398 }
10399
10400 impl Default for LocaleMatcherOptions {
10401 fn default() -> Self {
10402 LocaleMatcherOptions::new()
10403 }
10404 }
10405
10406 // Intl.Collator Options
10407 #[wasm_bindgen]
10408 extern "C" {
10409 /// Options for `Intl.Collator` and `String.prototype.localeCompare`.
10410 ///
10411 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options)
10412 #[wasm_bindgen(extends = Object)]
10413 #[derive(Clone, Debug)]
10414 pub type CollatorOptions;
10415
10416 #[wasm_bindgen(method, getter = localeMatcher)]
10417 pub fn get_locale_matcher(this: &CollatorOptions) -> Option<LocaleMatcher>;
10418 #[wasm_bindgen(method, setter = localeMatcher)]
10419 pub fn set_locale_matcher(this: &CollatorOptions, value: LocaleMatcher);
10420
10421 #[wasm_bindgen(method, getter = usage)]
10422 pub fn get_usage(this: &CollatorOptions) -> Option<CollatorUsage>;
10423 #[wasm_bindgen(method, setter = usage)]
10424 pub fn set_usage(this: &CollatorOptions, value: CollatorUsage);
10425
10426 #[wasm_bindgen(method, getter = sensitivity)]
10427 pub fn get_sensitivity(this: &CollatorOptions) -> Option<CollatorSensitivity>;
10428 #[wasm_bindgen(method, setter = sensitivity)]
10429 pub fn set_sensitivity(this: &CollatorOptions, value: CollatorSensitivity);
10430
10431 #[wasm_bindgen(method, getter = ignorePunctuation)]
10432 pub fn get_ignore_punctuation(this: &CollatorOptions) -> Option<bool>;
10433 #[wasm_bindgen(method, setter = ignorePunctuation)]
10434 pub fn set_ignore_punctuation(this: &CollatorOptions, value: bool);
10435
10436 #[wasm_bindgen(method, getter = numeric)]
10437 pub fn get_numeric(this: &CollatorOptions) -> Option<bool>;
10438 #[wasm_bindgen(method, setter = numeric)]
10439 pub fn set_numeric(this: &CollatorOptions, value: bool);
10440
10441 #[wasm_bindgen(method, getter = caseFirst)]
10442 pub fn get_case_first(this: &CollatorOptions) -> Option<CollatorCaseFirst>;
10443 #[wasm_bindgen(method, setter = caseFirst)]
10444 pub fn set_case_first(this: &CollatorOptions, value: CollatorCaseFirst);
10445 }
10446 impl CollatorOptions {
10447 pub fn new() -> CollatorOptions {
10448 JsCast::unchecked_into(Object::new())
10449 }
10450 }
10451 impl Default for CollatorOptions {
10452 fn default() -> Self {
10453 CollatorOptions::new()
10454 }
10455 }
10456
10457 // Intl.Collator ResolvedCollatorOptions
10458 #[wasm_bindgen]
10459 extern "C" {
10460 #[wasm_bindgen(extends = CollatorOptions)]
10461 pub type ResolvedCollatorOptions;
10462
10463 #[wasm_bindgen(method, getter = locale)]
10464 pub fn get_locale(this: &ResolvedCollatorOptions) -> JsString; // not Option, always present
10465 #[wasm_bindgen(method, getter = collation)]
10466 pub fn get_collation(this: &ResolvedCollatorOptions) -> JsString;
10467 }
10468
10469 // Intl.Collator
10470 #[wasm_bindgen]
10471 extern "C" {
10472 /// The `Intl.Collator` object is a constructor for collators, objects
10473 /// that enable language sensitive string comparison.
10474 ///
10475 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10476 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
10477 #[derive(Clone, Debug)]
10478 pub type Collator;
10479
10480 /// The `Intl.Collator` object is a constructor for collators, objects
10481 /// that enable language sensitive string comparison.
10482 ///
10483 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10484 #[cfg(not(js_sys_unstable_apis))]
10485 #[wasm_bindgen(constructor, js_namespace = Intl)]
10486 pub fn new(locales: &Array, options: &Object) -> Collator;
10487
10488 /// The `Intl.Collator` object is a constructor for collators, objects
10489 /// that enable language sensitive string comparison.
10490 ///
10491 /// Throws a `RangeError` if locales contain invalid values.
10492 ///
10493 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10494 #[cfg(js_sys_unstable_apis)]
10495 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10496 pub fn new(locales: &[JsString], options: &CollatorOptions) -> Result<Collator, JsValue>;
10497
10498 /// The Intl.Collator.prototype.compare property returns a function that
10499 /// compares two strings according to the sort order of this Collator
10500 /// object.
10501 ///
10502 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
10503 #[cfg(not(js_sys_unstable_apis))]
10504 #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
10505 pub fn compare(this: &Collator) -> Function;
10506
10507 /// Compares two strings according to the sort order of this Collator.
10508 ///
10509 /// Returns a negative value if `a` comes before `b`, positive if `a` comes
10510 /// after `b`, and zero if they are equal.
10511 ///
10512 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare)
10513 #[cfg(js_sys_unstable_apis)]
10514 #[wasm_bindgen(method, js_class = "Intl.Collator")]
10515 pub fn compare(this: &Collator, a: &str, b: &str) -> i32;
10516
10517 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10518 /// object with properties reflecting the locale and collation options
10519 /// computed during initialization of this Collator object.
10520 ///
10521 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10522 #[cfg(not(js_sys_unstable_apis))]
10523 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10524 pub fn resolved_options(this: &Collator) -> Object;
10525
10526 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10527 /// object with properties reflecting the locale and collation options
10528 /// computed during initialization of this Collator object.
10529 ///
10530 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10531 #[cfg(js_sys_unstable_apis)]
10532 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10533 pub fn resolved_options(this: &Collator) -> ResolvedCollatorOptions;
10534
10535 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10536 /// containing those of the provided locales that are supported in
10537 /// collation without having to fall back to the runtime's default
10538 /// locale.
10539 ///
10540 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10541 #[cfg(not(js_sys_unstable_apis))]
10542 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
10543 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10544
10545 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10546 /// containing those of the provided locales that are supported in
10547 /// collation without having to fall back to the runtime's default
10548 /// locale.
10549 ///
10550 /// Throws a `RangeError` if locales contain invalid values.
10551 ///
10552 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10553 #[cfg(js_sys_unstable_apis)]
10554 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10555 pub fn supported_locales_of(
10556 locales: &[JsString],
10557 options: &LocaleMatcherOptions,
10558 ) -> Result<Array<JsString>, JsValue>;
10559 }
10560
10561 #[cfg(not(js_sys_unstable_apis))]
10562 impl Default for Collator {
10563 fn default() -> Self {
10564 Self::new(
10565 &JsValue::UNDEFINED.unchecked_into(),
10566 &JsValue::UNDEFINED.unchecked_into(),
10567 )
10568 }
10569 }
10570
10571 #[cfg(js_sys_unstable_apis)]
10572 impl Default for Collator {
10573 fn default() -> Self {
10574 Self::new(&[], &Default::default()).unwrap()
10575 }
10576 }
10577
10578 // Intl.DateTimeFormatOptions
10579 #[wasm_bindgen]
10580 extern "C" {
10581 /// Options for `Intl.DateTimeFormat` constructor.
10582 ///
10583 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)
10584 #[wasm_bindgen(extends = Object)]
10585 #[derive(Clone, Debug)]
10586 pub type DateTimeFormatOptions;
10587
10588 // Locale matching
10589 #[wasm_bindgen(method, getter = localeMatcher)]
10590 pub fn get_locale_matcher(this: &DateTimeFormatOptions) -> Option<LocaleMatcher>;
10591 #[wasm_bindgen(method, setter = localeMatcher)]
10592 pub fn set_locale_matcher(this: &DateTimeFormatOptions, value: LocaleMatcher);
10593
10594 // Calendar/numbering (free-form strings, no enum)
10595 #[wasm_bindgen(method, getter = calendar)]
10596 pub fn get_calendar(this: &DateTimeFormatOptions) -> Option<JsString>;
10597 #[wasm_bindgen(method, setter = calendar)]
10598 pub fn set_calendar(this: &DateTimeFormatOptions, value: &str);
10599
10600 #[wasm_bindgen(method, getter = numberingSystem)]
10601 pub fn get_numbering_system(this: &DateTimeFormatOptions) -> Option<JsString>;
10602 #[wasm_bindgen(method, setter = numberingSystem)]
10603 pub fn set_numbering_system(this: &DateTimeFormatOptions, value: &str);
10604
10605 // Timezone (free-form string)
10606 #[wasm_bindgen(method, getter = timeZone)]
10607 pub fn get_time_zone(this: &DateTimeFormatOptions) -> Option<JsString>;
10608 #[wasm_bindgen(method, setter = timeZone)]
10609 pub fn set_time_zone(this: &DateTimeFormatOptions, value: &str);
10610
10611 // Hour cycle
10612 #[wasm_bindgen(method, getter = hour12)]
10613 pub fn get_hour12(this: &DateTimeFormatOptions) -> Option<bool>;
10614 #[wasm_bindgen(method, setter = hour12)]
10615 pub fn set_hour12(this: &DateTimeFormatOptions, value: bool);
10616
10617 #[wasm_bindgen(method, getter = hourCycle)]
10618 pub fn get_hour_cycle(this: &DateTimeFormatOptions) -> Option<HourCycle>;
10619 #[wasm_bindgen(method, setter = hourCycle)]
10620 pub fn set_hour_cycle(this: &DateTimeFormatOptions, value: HourCycle);
10621
10622 // Style shortcuts
10623 #[wasm_bindgen(method, getter = dateStyle)]
10624 pub fn get_date_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10625 #[wasm_bindgen(method, setter = dateStyle)]
10626 pub fn set_date_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10627
10628 #[wasm_bindgen(method, getter = timeStyle)]
10629 pub fn get_time_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10630 #[wasm_bindgen(method, setter = timeStyle)]
10631 pub fn set_time_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10632
10633 // Component options
10634 #[wasm_bindgen(method, getter = weekday)]
10635 pub fn get_weekday(this: &DateTimeFormatOptions) -> Option<WeekdayFormat>;
10636 #[wasm_bindgen(method, setter = weekday)]
10637 pub fn set_weekday(this: &DateTimeFormatOptions, value: WeekdayFormat);
10638
10639 #[wasm_bindgen(method, getter = era)]
10640 pub fn get_era(this: &DateTimeFormatOptions) -> Option<EraFormat>;
10641 #[wasm_bindgen(method, setter = era)]
10642 pub fn set_era(this: &DateTimeFormatOptions, value: EraFormat);
10643
10644 #[wasm_bindgen(method, getter = year)]
10645 pub fn get_year(this: &DateTimeFormatOptions) -> Option<YearFormat>;
10646 #[wasm_bindgen(method, setter = year)]
10647 pub fn set_year(this: &DateTimeFormatOptions, value: YearFormat);
10648
10649 #[wasm_bindgen(method, getter = month)]
10650 pub fn get_month(this: &DateTimeFormatOptions) -> Option<MonthFormat>;
10651 #[wasm_bindgen(method, setter = month)]
10652 pub fn set_month(this: &DateTimeFormatOptions, value: MonthFormat);
10653
10654 #[wasm_bindgen(method, getter = day)]
10655 pub fn get_day(this: &DateTimeFormatOptions) -> Option<DayFormat>;
10656 #[wasm_bindgen(method, setter = day)]
10657 pub fn set_day(this: &DateTimeFormatOptions, value: DayFormat);
10658
10659 #[wasm_bindgen(method, getter = hour)]
10660 pub fn get_hour(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10661 #[wasm_bindgen(method, setter = hour)]
10662 pub fn set_hour(this: &DateTimeFormatOptions, value: NumericFormat);
10663
10664 #[wasm_bindgen(method, getter = minute)]
10665 pub fn get_minute(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10666 #[wasm_bindgen(method, setter = minute)]
10667 pub fn set_minute(this: &DateTimeFormatOptions, value: NumericFormat);
10668
10669 #[wasm_bindgen(method, getter = second)]
10670 pub fn get_second(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10671 #[wasm_bindgen(method, setter = second)]
10672 pub fn set_second(this: &DateTimeFormatOptions, value: NumericFormat);
10673
10674 #[wasm_bindgen(method, getter = fractionalSecondDigits)]
10675 pub fn get_fractional_second_digits(this: &DateTimeFormatOptions) -> Option<u8>;
10676 #[wasm_bindgen(method, setter = fractionalSecondDigits)]
10677 pub fn set_fractional_second_digits(this: &DateTimeFormatOptions, value: u8);
10678
10679 #[wasm_bindgen(method, getter = timeZoneName)]
10680 pub fn get_time_zone_name(this: &DateTimeFormatOptions) -> Option<TimeZoneNameFormat>;
10681 #[wasm_bindgen(method, setter = timeZoneName)]
10682 pub fn set_time_zone_name(this: &DateTimeFormatOptions, value: TimeZoneNameFormat);
10683
10684 #[wasm_bindgen(method, getter = dayPeriod)]
10685 pub fn get_day_period(this: &DateTimeFormatOptions) -> Option<DayPeriodFormat>;
10686 #[wasm_bindgen(method, setter = dayPeriod)]
10687 pub fn set_day_period(this: &DateTimeFormatOptions, value: DayPeriodFormat);
10688 }
10689
10690 impl DateTimeFormatOptions {
10691 pub fn new() -> DateTimeFormatOptions {
10692 JsCast::unchecked_into(Object::new())
10693 }
10694 }
10695
10696 impl Default for DateTimeFormatOptions {
10697 fn default() -> Self {
10698 DateTimeFormatOptions::new()
10699 }
10700 }
10701
10702 // Intl.ResolvedDateTimeFormatOptions
10703 #[wasm_bindgen]
10704 extern "C" {
10705 /// Resolved options returned by `Intl.DateTimeFormat.prototype.resolvedOptions()`.
10706 ///
10707 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions)
10708 #[wasm_bindgen(extends = DateTimeFormatOptions)]
10709 #[derive(Clone, Debug)]
10710 pub type ResolvedDateTimeFormatOptions;
10711
10712 /// The resolved locale string.
10713 #[wasm_bindgen(method, getter = locale)]
10714 pub fn get_locale(this: &ResolvedDateTimeFormatOptions) -> JsString;
10715 }
10716
10717 // Intl.DateTimeFormatPart
10718 #[wasm_bindgen]
10719 extern "C" {
10720 /// A part of the formatted date returned by `formatToParts()`.
10721 ///
10722 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
10723 #[wasm_bindgen(extends = Object)]
10724 #[derive(Clone, Debug)]
10725 pub type DateTimeFormatPart;
10726
10727 /// The type of the part (e.g., "day", "month", "year", "literal", etc.)
10728 #[wasm_bindgen(method, getter = type)]
10729 pub fn type_(this: &DateTimeFormatPart) -> DateTimeFormatPartType;
10730
10731 /// The value of the part.
10732 #[wasm_bindgen(method, getter)]
10733 pub fn value(this: &DateTimeFormatPart) -> JsString;
10734 }
10735
10736 // Intl.DateTimeRangeFormatPart
10737 #[wasm_bindgen]
10738 extern "C" {
10739 /// A part of the formatted date range returned by `formatRangeToParts()`.
10740 ///
10741 /// Extends `DateTimeFormatPart` with a `source` property indicating whether
10742 /// the part is from the start date, end date, or shared between them.
10743 ///
10744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
10745 #[wasm_bindgen(extends = DateTimeFormatPart)]
10746 #[derive(Clone, Debug)]
10747 pub type DateTimeRangeFormatPart;
10748
10749 /// The source of the part: "startRange", "endRange", or "shared".
10750 #[wasm_bindgen(method, getter)]
10751 pub fn source(this: &DateTimeRangeFormatPart) -> RangeSource;
10752 }
10753
10754 // Intl.DateTimeFormat
10755 #[wasm_bindgen]
10756 extern "C" {
10757 /// The `Intl.DateTimeFormat` object is a constructor for objects
10758 /// that enable language-sensitive date and time formatting.
10759 ///
10760 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10761 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
10762 #[derive(Clone, Debug)]
10763 pub type DateTimeFormat;
10764
10765 /// The `Intl.DateTimeFormat` object is a constructor for objects
10766 /// that enable language-sensitive date and time formatting.
10767 ///
10768 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10769 #[cfg(not(js_sys_unstable_apis))]
10770 #[wasm_bindgen(constructor, js_namespace = Intl)]
10771 pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
10772
10773 /// The `Intl.DateTimeFormat` object is a constructor for objects
10774 /// that enable language-sensitive date and time formatting.
10775 ///
10776 /// Throws a `RangeError` if locales contain invalid values.
10777 ///
10778 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10779 #[cfg(js_sys_unstable_apis)]
10780 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10781 pub fn new(
10782 locales: &[JsString],
10783 options: &DateTimeFormatOptions,
10784 ) -> Result<DateTimeFormat, JsValue>;
10785
10786 /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
10787 /// formats a date according to the locale and formatting options of this
10788 /// Intl.DateTimeFormat object.
10789 ///
10790 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
10791 #[cfg(not(js_sys_unstable_apis))]
10792 #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
10793 pub fn format(this: &DateTimeFormat) -> Function;
10794
10795 /// Formats a date according to the locale and formatting options of this
10796 /// `Intl.DateTimeFormat` object.
10797 ///
10798 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format)
10799 #[cfg(js_sys_unstable_apis)]
10800 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat")]
10801 pub fn format(this: &DateTimeFormat, date: &Date) -> JsString;
10802
10803 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
10804 /// formatting of strings produced by DateTimeFormat formatters.
10805 ///
10806 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
10807 #[cfg(not(js_sys_unstable_apis))]
10808 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
10809 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
10810
10811 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
10812 /// formatting of strings produced by DateTimeFormat formatters.
10813 ///
10814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
10815 #[cfg(js_sys_unstable_apis)]
10816 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
10817 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array<DateTimeFormatPart>;
10818
10819 /// The `Intl.DateTimeFormat.prototype.formatRange()` method formats a date range
10820 /// in the most concise way based on the locales and options provided when
10821 /// instantiating this `Intl.DateTimeFormat` object.
10822 ///
10823 /// Throws a `TypeError` if the dates are invalid.
10824 ///
10825 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange)
10826 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRange, catch)]
10827 pub fn format_range(
10828 this: &DateTimeFormat,
10829 start_date: &Date,
10830 end_date: &Date,
10831 ) -> Result<JsString, JsValue>;
10832
10833 /// The `Intl.DateTimeFormat.prototype.formatRangeToParts()` method returns an array
10834 /// of locale-specific tokens representing each part of the formatted date range
10835 /// produced by `Intl.DateTimeFormat` formatters.
10836 ///
10837 /// Throws a `TypeError` if the dates are invalid.
10838 ///
10839 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
10840 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRangeToParts, catch)]
10841 pub fn format_range_to_parts(
10842 this: &DateTimeFormat,
10843 start_date: &Date,
10844 end_date: &Date,
10845 ) -> Result<Array<DateTimeRangeFormatPart>, JsValue>;
10846
10847 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
10848 /// object with properties reflecting the locale and date and time formatting
10849 /// options computed during initialization of this DateTimeFormat object.
10850 ///
10851 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
10852 #[cfg(not(js_sys_unstable_apis))]
10853 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10854 pub fn resolved_options(this: &DateTimeFormat) -> Object;
10855
10856 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
10857 /// object with properties reflecting the locale and date and time formatting
10858 /// options computed during initialization of this DateTimeFormat object.
10859 ///
10860 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
10861 #[cfg(js_sys_unstable_apis)]
10862 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10863 pub fn resolved_options(this: &DateTimeFormat) -> ResolvedDateTimeFormatOptions;
10864
10865 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
10866 /// containing those of the provided locales that are supported in date
10867 /// and time formatting without having to fall back to the runtime's default
10868 /// locale.
10869 ///
10870 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
10871 #[cfg(not(js_sys_unstable_apis))]
10872 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
10873 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10874
10875 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
10876 /// containing those of the provided locales that are supported in date
10877 /// and time formatting without having to fall back to the runtime's default
10878 /// locale.
10879 ///
10880 /// Throws a `RangeError` if locales contain invalid values.
10881 ///
10882 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
10883 #[cfg(js_sys_unstable_apis)]
10884 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10885 pub fn supported_locales_of(
10886 locales: &[JsString],
10887 options: &LocaleMatcherOptions,
10888 ) -> Result<Array<JsString>, JsValue>;
10889 }
10890
10891 #[cfg(not(js_sys_unstable_apis))]
10892 impl Default for DateTimeFormat {
10893 fn default() -> Self {
10894 Self::new(
10895 &JsValue::UNDEFINED.unchecked_into(),
10896 &JsValue::UNDEFINED.unchecked_into(),
10897 )
10898 }
10899 }
10900
10901 #[cfg(js_sys_unstable_apis)]
10902 impl Default for DateTimeFormat {
10903 fn default() -> Self {
10904 Self::new(&[], &Default::default()).unwrap()
10905 }
10906 }
10907
10908 // Intl.NumberFormatOptions
10909 #[wasm_bindgen]
10910 extern "C" {
10911 /// Options for `Intl.NumberFormat` constructor.
10912 ///
10913 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options)
10914 #[wasm_bindgen(extends = Object)]
10915 #[derive(Clone, Debug)]
10916 pub type NumberFormatOptions;
10917
10918 // Locale matching
10919 #[wasm_bindgen(method, getter = localeMatcher)]
10920 pub fn get_locale_matcher(this: &NumberFormatOptions) -> Option<LocaleMatcher>;
10921 #[wasm_bindgen(method, setter = localeMatcher)]
10922 pub fn set_locale_matcher(this: &NumberFormatOptions, value: LocaleMatcher);
10923
10924 // Numbering system (free-form string)
10925 #[wasm_bindgen(method, getter = numberingSystem)]
10926 pub fn get_numbering_system(this: &NumberFormatOptions) -> Option<JsString>;
10927 #[wasm_bindgen(method, setter = numberingSystem)]
10928 pub fn set_numbering_system(this: &NumberFormatOptions, value: &str);
10929
10930 // Style
10931 #[wasm_bindgen(method, getter = style)]
10932 pub fn get_style(this: &NumberFormatOptions) -> Option<NumberFormatStyle>;
10933 #[wasm_bindgen(method, setter = style)]
10934 pub fn set_style(this: &NumberFormatOptions, value: NumberFormatStyle);
10935
10936 // Currency options (currency code is free-form ISO 4217 string)
10937 #[wasm_bindgen(method, getter = currency)]
10938 pub fn get_currency(this: &NumberFormatOptions) -> Option<JsString>;
10939 #[wasm_bindgen(method, setter = currency)]
10940 pub fn set_currency(this: &NumberFormatOptions, value: &str);
10941
10942 #[wasm_bindgen(method, getter = currencyDisplay)]
10943 pub fn get_currency_display(this: &NumberFormatOptions) -> Option<CurrencyDisplay>;
10944 #[wasm_bindgen(method, setter = currencyDisplay)]
10945 pub fn set_currency_display(this: &NumberFormatOptions, value: CurrencyDisplay);
10946
10947 #[wasm_bindgen(method, getter = currencySign)]
10948 pub fn get_currency_sign(this: &NumberFormatOptions) -> Option<CurrencySign>;
10949 #[wasm_bindgen(method, setter = currencySign)]
10950 pub fn set_currency_sign(this: &NumberFormatOptions, value: CurrencySign);
10951
10952 // Unit options (unit name is free-form string)
10953 #[wasm_bindgen(method, getter = unit)]
10954 pub fn get_unit(this: &NumberFormatOptions) -> Option<JsString>;
10955 #[wasm_bindgen(method, setter = unit)]
10956 pub fn set_unit(this: &NumberFormatOptions, value: &str);
10957
10958 #[wasm_bindgen(method, getter = unitDisplay)]
10959 pub fn get_unit_display(this: &NumberFormatOptions) -> Option<UnitDisplay>;
10960 #[wasm_bindgen(method, setter = unitDisplay)]
10961 pub fn set_unit_display(this: &NumberFormatOptions, value: UnitDisplay);
10962
10963 // Notation
10964 #[wasm_bindgen(method, getter = notation)]
10965 pub fn get_notation(this: &NumberFormatOptions) -> Option<NumberFormatNotation>;
10966 #[wasm_bindgen(method, setter = notation)]
10967 pub fn set_notation(this: &NumberFormatOptions, value: NumberFormatNotation);
10968
10969 #[wasm_bindgen(method, getter = compactDisplay)]
10970 pub fn get_compact_display(this: &NumberFormatOptions) -> Option<CompactDisplay>;
10971 #[wasm_bindgen(method, setter = compactDisplay)]
10972 pub fn set_compact_display(this: &NumberFormatOptions, value: CompactDisplay);
10973
10974 // Sign display
10975 #[wasm_bindgen(method, getter = signDisplay)]
10976 pub fn get_sign_display(this: &NumberFormatOptions) -> Option<SignDisplay>;
10977 #[wasm_bindgen(method, setter = signDisplay)]
10978 pub fn set_sign_display(this: &NumberFormatOptions, value: SignDisplay);
10979
10980 // Digit options
10981 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
10982 pub fn get_minimum_integer_digits(this: &NumberFormatOptions) -> Option<u8>;
10983 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
10984 pub fn set_minimum_integer_digits(this: &NumberFormatOptions, value: u8);
10985
10986 #[wasm_bindgen(method, getter = minimumFractionDigits)]
10987 pub fn get_minimum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
10988 #[wasm_bindgen(method, setter = minimumFractionDigits)]
10989 pub fn set_minimum_fraction_digits(this: &NumberFormatOptions, value: u8);
10990
10991 #[wasm_bindgen(method, getter = maximumFractionDigits)]
10992 pub fn get_maximum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
10993 #[wasm_bindgen(method, setter = maximumFractionDigits)]
10994 pub fn set_maximum_fraction_digits(this: &NumberFormatOptions, value: u8);
10995
10996 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
10997 pub fn get_minimum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
10998 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
10999 pub fn set_minimum_significant_digits(this: &NumberFormatOptions, value: u8);
11000
11001 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11002 pub fn get_maximum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11003 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11004 pub fn set_maximum_significant_digits(this: &NumberFormatOptions, value: u8);
11005
11006 // Grouping
11007 #[wasm_bindgen(method, getter = useGrouping)]
11008 pub fn get_use_grouping(this: &NumberFormatOptions) -> Option<UseGrouping>;
11009 #[wasm_bindgen(method, setter = useGrouping)]
11010 pub fn set_use_grouping(this: &NumberFormatOptions, value: UseGrouping);
11011
11012 // Rounding
11013 #[wasm_bindgen(method, getter = roundingMode)]
11014 pub fn get_rounding_mode(this: &NumberFormatOptions) -> Option<RoundingMode>;
11015 #[wasm_bindgen(method, setter = roundingMode)]
11016 pub fn set_rounding_mode(this: &NumberFormatOptions, value: RoundingMode);
11017
11018 #[wasm_bindgen(method, getter = roundingPriority)]
11019 pub fn get_rounding_priority(this: &NumberFormatOptions) -> Option<RoundingPriority>;
11020 #[wasm_bindgen(method, setter = roundingPriority)]
11021 pub fn set_rounding_priority(this: &NumberFormatOptions, value: RoundingPriority);
11022
11023 #[wasm_bindgen(method, getter = roundingIncrement)]
11024 pub fn get_rounding_increment(this: &NumberFormatOptions) -> Option<u32>;
11025 #[wasm_bindgen(method, setter = roundingIncrement)]
11026 pub fn set_rounding_increment(this: &NumberFormatOptions, value: u32);
11027
11028 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11029 pub fn get_trailing_zero_display(this: &NumberFormatOptions)
11030 -> Option<TrailingZeroDisplay>;
11031 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11032 pub fn set_trailing_zero_display(this: &NumberFormatOptions, value: TrailingZeroDisplay);
11033 }
11034
11035 impl NumberFormatOptions {
11036 pub fn new() -> NumberFormatOptions {
11037 JsCast::unchecked_into(Object::new())
11038 }
11039 }
11040
11041 impl Default for NumberFormatOptions {
11042 fn default() -> Self {
11043 NumberFormatOptions::new()
11044 }
11045 }
11046
11047 // Intl.ResolvedNumberFormatOptions
11048 #[wasm_bindgen]
11049 extern "C" {
11050 /// Resolved options returned by `Intl.NumberFormat.prototype.resolvedOptions()`.
11051 ///
11052 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions)
11053 #[wasm_bindgen(extends = NumberFormatOptions)]
11054 #[derive(Clone, Debug)]
11055 pub type ResolvedNumberFormatOptions;
11056
11057 /// The resolved locale string.
11058 #[wasm_bindgen(method, getter = locale)]
11059 pub fn get_locale(this: &ResolvedNumberFormatOptions) -> JsString;
11060 }
11061
11062 // Intl.NumberFormatPart
11063 #[wasm_bindgen]
11064 extern "C" {
11065 /// A part of the formatted number returned by `formatToParts()`.
11066 ///
11067 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11068 #[wasm_bindgen(extends = Object)]
11069 #[derive(Clone, Debug)]
11070 pub type NumberFormatPart;
11071
11072 /// The type of the part (e.g., "integer", "decimal", "fraction", "currency", etc.)
11073 #[wasm_bindgen(method, getter = type)]
11074 pub fn type_(this: &NumberFormatPart) -> NumberFormatPartType;
11075
11076 /// The value of the part.
11077 #[wasm_bindgen(method, getter)]
11078 pub fn value(this: &NumberFormatPart) -> JsString;
11079 }
11080
11081 // Intl.NumberRangeFormatPart
11082 #[wasm_bindgen]
11083 extern "C" {
11084 /// A part of the formatted number range returned by `formatRangeToParts()`.
11085 ///
11086 /// Extends `NumberFormatPart` with a `source` property indicating whether
11087 /// the part is from the start number, end number, or shared between them.
11088 ///
11089 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11090 #[wasm_bindgen(extends = NumberFormatPart)]
11091 #[derive(Clone, Debug)]
11092 pub type NumberRangeFormatPart;
11093
11094 /// The source of the part: "startRange", "endRange", or "shared".
11095 #[wasm_bindgen(method, getter)]
11096 pub fn source(this: &NumberRangeFormatPart) -> RangeSource;
11097 }
11098
11099 // Intl.NumberFormat
11100 #[wasm_bindgen]
11101 extern "C" {
11102 /// The `Intl.NumberFormat` object is a constructor for objects
11103 /// that enable language sensitive number formatting.
11104 ///
11105 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11106 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
11107 #[derive(Clone, Debug)]
11108 pub type NumberFormat;
11109
11110 /// The `Intl.NumberFormat` object is a constructor for objects
11111 /// that enable language sensitive number formatting.
11112 ///
11113 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11114 #[cfg(not(js_sys_unstable_apis))]
11115 #[wasm_bindgen(constructor, js_namespace = Intl)]
11116 pub fn new(locales: &Array, options: &Object) -> NumberFormat;
11117
11118 /// The `Intl.NumberFormat` object is a constructor for objects
11119 /// that enable language sensitive number formatting.
11120 ///
11121 /// Throws a `RangeError` if locales contain invalid values.
11122 ///
11123 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11124 #[cfg(js_sys_unstable_apis)]
11125 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11126 pub fn new(
11127 locales: &[JsString],
11128 options: &NumberFormatOptions,
11129 ) -> Result<NumberFormat, JsValue>;
11130
11131 /// The Intl.NumberFormat.prototype.format property returns a getter function that
11132 /// formats a number according to the locale and formatting options of this
11133 /// NumberFormat object.
11134 ///
11135 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
11136 #[cfg(not(js_sys_unstable_apis))]
11137 #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
11138 pub fn format(this: &NumberFormat) -> Function;
11139
11140 /// Formats a number according to the locale and formatting options of this
11141 /// `Intl.NumberFormat` object.
11142 ///
11143 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11144 /// or use E notation: `"1000000E-6"` → `"1"`).
11145 ///
11146 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format)
11147 #[cfg(js_sys_unstable_apis)]
11148 #[wasm_bindgen(method, js_class = "Intl.NumberFormat")]
11149 pub fn format(this: &NumberFormat, value: &JsString) -> JsString;
11150
11151 /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
11152 /// formatting of strings produced by NumberTimeFormat formatters.
11153 ///
11154 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
11155 #[cfg(not(js_sys_unstable_apis))]
11156 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11157 pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
11158
11159 /// The `Intl.NumberFormat.prototype.formatToParts()` method allows locale-aware
11160 /// formatting of strings produced by `Intl.NumberFormat` formatters.
11161 ///
11162 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11163 /// or use E notation: `"1000000E-6"` → `"1"`).
11164 ///
11165 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11166 #[cfg(js_sys_unstable_apis)]
11167 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11168 pub fn format_to_parts(this: &NumberFormat, value: &JsString) -> Array<NumberFormatPart>;
11169
11170 /// Formats a range of numbers according to the locale and formatting options
11171 /// of this `Intl.NumberFormat` object.
11172 ///
11173 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11174 /// or use E notation: `"1000000E-6"` → `"1"`).
11175 ///
11176 /// Throws a `TypeError` if the values are invalid.
11177 ///
11178 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange)
11179 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRange, catch)]
11180 pub fn format_range(
11181 this: &NumberFormat,
11182 start: &JsString,
11183 end: &JsString,
11184 ) -> Result<JsString, JsValue>;
11185
11186 /// Returns an array of locale-specific tokens representing each part of
11187 /// the formatted number range.
11188 ///
11189 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11190 /// or use E notation: `"1000000E-6"` → `"1"`).
11191 ///
11192 /// Throws a `TypeError` if the values are invalid.
11193 ///
11194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11195 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRangeToParts, catch)]
11196 pub fn format_range_to_parts(
11197 this: &NumberFormat,
11198 start: &JsString,
11199 end: &JsString,
11200 ) -> Result<Array<NumberRangeFormatPart>, JsValue>;
11201
11202 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11203 /// object with properties reflecting the locale and number formatting
11204 /// options computed during initialization of this NumberFormat object.
11205 ///
11206 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11207 #[cfg(not(js_sys_unstable_apis))]
11208 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11209 pub fn resolved_options(this: &NumberFormat) -> Object;
11210
11211 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11212 /// object with properties reflecting the locale and number formatting
11213 /// options computed during initialization of this NumberFormat object.
11214 ///
11215 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11216 #[cfg(js_sys_unstable_apis)]
11217 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11218 pub fn resolved_options(this: &NumberFormat) -> ResolvedNumberFormatOptions;
11219
11220 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11221 /// containing those of the provided locales that are supported in number
11222 /// formatting without having to fall back to the runtime's default locale.
11223 ///
11224 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11225 #[cfg(not(js_sys_unstable_apis))]
11226 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11227 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11228
11229 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11230 /// containing those of the provided locales that are supported in number
11231 /// formatting without having to fall back to the runtime's default locale.
11232 ///
11233 /// Throws a `RangeError` if locales contain invalid values.
11234 ///
11235 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11236 #[cfg(js_sys_unstable_apis)]
11237 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11238 pub fn supported_locales_of(
11239 locales: &[JsString],
11240 options: &LocaleMatcherOptions,
11241 ) -> Result<Array<JsString>, JsValue>;
11242 }
11243
11244 #[cfg(not(js_sys_unstable_apis))]
11245 impl Default for NumberFormat {
11246 fn default() -> Self {
11247 Self::new(
11248 &JsValue::UNDEFINED.unchecked_into(),
11249 &JsValue::UNDEFINED.unchecked_into(),
11250 )
11251 }
11252 }
11253
11254 #[cfg(js_sys_unstable_apis)]
11255 impl Default for NumberFormat {
11256 fn default() -> Self {
11257 Self::new(&[], &Default::default()).unwrap()
11258 }
11259 }
11260
11261 // Intl.PluralRulesOptions
11262 #[wasm_bindgen]
11263 extern "C" {
11264 /// Options for `Intl.PluralRules` constructor.
11265 ///
11266 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#options)
11267 #[wasm_bindgen(extends = Object)]
11268 #[derive(Clone, Debug)]
11269 pub type PluralRulesOptions;
11270
11271 #[wasm_bindgen(method, getter = localeMatcher)]
11272 pub fn get_locale_matcher(this: &PluralRulesOptions) -> Option<LocaleMatcher>;
11273 #[wasm_bindgen(method, setter = localeMatcher)]
11274 pub fn set_locale_matcher(this: &PluralRulesOptions, value: LocaleMatcher);
11275
11276 #[wasm_bindgen(method, getter = type)]
11277 pub fn get_type(this: &PluralRulesOptions) -> Option<PluralRulesType>;
11278 #[wasm_bindgen(method, setter = type)]
11279 pub fn set_type(this: &PluralRulesOptions, value: PluralRulesType);
11280
11281 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11282 pub fn get_minimum_integer_digits(this: &PluralRulesOptions) -> Option<u8>;
11283 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11284 pub fn set_minimum_integer_digits(this: &PluralRulesOptions, value: u8);
11285
11286 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11287 pub fn get_minimum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11288 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11289 pub fn set_minimum_fraction_digits(this: &PluralRulesOptions, value: u8);
11290
11291 #[wasm_bindgen(method, getter = maximumFractionDigits)]
11292 pub fn get_maximum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11293 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11294 pub fn set_maximum_fraction_digits(this: &PluralRulesOptions, value: u8);
11295
11296 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11297 pub fn get_minimum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11298 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11299 pub fn set_minimum_significant_digits(this: &PluralRulesOptions, value: u8);
11300
11301 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11302 pub fn get_maximum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11303 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11304 pub fn set_maximum_significant_digits(this: &PluralRulesOptions, value: u8);
11305
11306 #[wasm_bindgen(method, getter = roundingPriority)]
11307 pub fn get_rounding_priority(this: &PluralRulesOptions) -> Option<RoundingPriority>;
11308 #[wasm_bindgen(method, setter = roundingPriority)]
11309 pub fn set_rounding_priority(this: &PluralRulesOptions, value: RoundingPriority);
11310
11311 #[wasm_bindgen(method, getter = roundingIncrement)]
11312 pub fn get_rounding_increment(this: &PluralRulesOptions) -> Option<u32>;
11313 #[wasm_bindgen(method, setter = roundingIncrement)]
11314 pub fn set_rounding_increment(this: &PluralRulesOptions, value: u32);
11315
11316 #[wasm_bindgen(method, getter = roundingMode)]
11317 pub fn get_rounding_mode(this: &PluralRulesOptions) -> Option<RoundingMode>;
11318 #[wasm_bindgen(method, setter = roundingMode)]
11319 pub fn set_rounding_mode(this: &PluralRulesOptions, value: RoundingMode);
11320
11321 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11322 pub fn get_trailing_zero_display(this: &PluralRulesOptions) -> Option<TrailingZeroDisplay>;
11323 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11324 pub fn set_trailing_zero_display(this: &PluralRulesOptions, value: TrailingZeroDisplay);
11325 }
11326
11327 impl PluralRulesOptions {
11328 pub fn new() -> PluralRulesOptions {
11329 JsCast::unchecked_into(Object::new())
11330 }
11331 }
11332
11333 impl Default for PluralRulesOptions {
11334 fn default() -> Self {
11335 PluralRulesOptions::new()
11336 }
11337 }
11338
11339 // Intl.ResolvedPluralRulesOptions
11340 #[wasm_bindgen]
11341 extern "C" {
11342 /// Resolved options returned by `Intl.PluralRules.prototype.resolvedOptions()`.
11343 ///
11344 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/resolvedOptions)
11345 #[wasm_bindgen(extends = PluralRulesOptions)]
11346 #[derive(Clone, Debug)]
11347 pub type ResolvedPluralRulesOptions;
11348
11349 /// The resolved locale string.
11350 #[wasm_bindgen(method, getter = locale)]
11351 pub fn get_locale(this: &ResolvedPluralRulesOptions) -> JsString;
11352
11353 /// The plural categories used by the locale.
11354 #[wasm_bindgen(method, getter = pluralCategories)]
11355 pub fn get_plural_categories(this: &ResolvedPluralRulesOptions) -> Array<JsString>;
11356 }
11357
11358 // Intl.PluralRules
11359 #[wasm_bindgen]
11360 extern "C" {
11361 /// The `Intl.PluralRules` object is a constructor for objects
11362 /// that enable plural sensitive formatting and plural language rules.
11363 ///
11364 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11365 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
11366 #[derive(Clone, Debug)]
11367 pub type PluralRules;
11368
11369 /// The `Intl.PluralRules` object is a constructor for objects
11370 /// that enable plural sensitive formatting and plural language rules.
11371 ///
11372 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11373 #[cfg(not(js_sys_unstable_apis))]
11374 #[wasm_bindgen(constructor, js_namespace = Intl)]
11375 pub fn new(locales: &Array, options: &Object) -> PluralRules;
11376
11377 /// The `Intl.PluralRules` object is a constructor for objects
11378 /// that enable plural sensitive formatting and plural language rules.
11379 ///
11380 /// Throws a `RangeError` if locales contain invalid values.
11381 ///
11382 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11383 #[cfg(js_sys_unstable_apis)]
11384 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11385 pub fn new(
11386 locales: &[JsString],
11387 options: &PluralRulesOptions,
11388 ) -> Result<PluralRules, JsValue>;
11389
11390 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11391 /// object with properties reflecting the locale and plural formatting
11392 /// options computed during initialization of this PluralRules object.
11393 ///
11394 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11395 #[cfg(not(js_sys_unstable_apis))]
11396 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11397 pub fn resolved_options(this: &PluralRules) -> Object;
11398
11399 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11400 /// object with properties reflecting the locale and plural formatting
11401 /// options computed during initialization of this PluralRules object.
11402 ///
11403 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11404 #[cfg(js_sys_unstable_apis)]
11405 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11406 pub fn resolved_options(this: &PluralRules) -> ResolvedPluralRulesOptions;
11407
11408 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11409 /// which plural rule to use for locale-aware formatting.
11410 ///
11411 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11412 #[cfg(not(js_sys_unstable_apis))]
11413 #[wasm_bindgen(method, js_namespace = Intl)]
11414 pub fn select(this: &PluralRules, number: f64) -> JsString;
11415
11416 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11417 /// which plural rule to use for locale-aware formatting.
11418 ///
11419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11420 #[cfg(js_sys_unstable_apis)]
11421 #[wasm_bindgen(method, js_namespace = Intl)]
11422 pub fn select(this: &PluralRules, number: f64) -> PluralCategory;
11423
11424 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11425 /// which plural rule to use for locale-aware formatting of a range of numbers.
11426 ///
11427 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11428 #[cfg(not(js_sys_unstable_apis))]
11429 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11430 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> JsString;
11431
11432 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11433 /// which plural rule to use for locale-aware formatting of a range of numbers.
11434 ///
11435 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11436 #[cfg(js_sys_unstable_apis)]
11437 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11438 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> PluralCategory;
11439
11440 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11441 /// containing those of the provided locales that are supported in plural
11442 /// formatting without having to fall back to the runtime's default locale.
11443 ///
11444 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11445 #[cfg(not(js_sys_unstable_apis))]
11446 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
11447 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11448
11449 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11450 /// containing those of the provided locales that are supported in plural
11451 /// formatting without having to fall back to the runtime's default locale.
11452 ///
11453 /// Throws a `RangeError` if locales contain invalid values.
11454 ///
11455 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11456 #[cfg(js_sys_unstable_apis)]
11457 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11458 pub fn supported_locales_of(
11459 locales: &[JsString],
11460 options: &LocaleMatcherOptions,
11461 ) -> Result<Array<JsString>, JsValue>;
11462 }
11463
11464 #[cfg(not(js_sys_unstable_apis))]
11465 impl Default for PluralRules {
11466 fn default() -> Self {
11467 Self::new(
11468 &JsValue::UNDEFINED.unchecked_into(),
11469 &JsValue::UNDEFINED.unchecked_into(),
11470 )
11471 }
11472 }
11473
11474 #[cfg(js_sys_unstable_apis)]
11475 impl Default for PluralRules {
11476 fn default() -> Self {
11477 Self::new(&[], &Default::default()).unwrap()
11478 }
11479 }
11480
11481 // Intl.RelativeTimeFormat
11482 #[wasm_bindgen]
11483 extern "C" {
11484 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11485 /// that enable language-sensitive relative time formatting.
11486 ///
11487 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11488 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
11489 #[derive(Clone, Debug)]
11490 pub type RelativeTimeFormat;
11491
11492 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11493 /// that enable language-sensitive relative time formatting.
11494 ///
11495 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11496 #[cfg(not(js_sys_unstable_apis))]
11497 #[wasm_bindgen(constructor, js_namespace = Intl)]
11498 pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
11499
11500 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11501 /// that enable language-sensitive relative time formatting.
11502 ///
11503 /// Throws a `RangeError` if locales contain invalid values.
11504 ///
11505 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11506 #[cfg(js_sys_unstable_apis)]
11507 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11508 pub fn new(locales: &[JsString]) -> Result<RelativeTimeFormat, JsValue>;
11509
11510 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11511 /// that enable language-sensitive relative time formatting.
11512 ///
11513 /// Throws a `RangeError` if locales or options contain invalid values.
11514 ///
11515 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11516 #[cfg(js_sys_unstable_apis)]
11517 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11518 pub fn new_with_options(
11519 locales: &[JsString],
11520 options: &RelativeTimeFormatOptions,
11521 ) -> Result<RelativeTimeFormat, JsValue>;
11522
11523 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11524 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11525 ///
11526 /// Throws a `RangeError` if unit is invalid.
11527 ///
11528 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11529 #[cfg(not(js_sys_unstable_apis))]
11530 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11531 pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
11532
11533 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11534 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11535 ///
11536 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11537 #[cfg(js_sys_unstable_apis)]
11538 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11539 pub fn format(
11540 this: &RelativeTimeFormat,
11541 value: f64,
11542 unit: RelativeTimeFormatUnit,
11543 ) -> JsString;
11544
11545 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11546 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11547 ///
11548 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11549 #[cfg(not(js_sys_unstable_apis))]
11550 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11551 pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
11552
11553 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11554 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11555 ///
11556 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11557 #[cfg(js_sys_unstable_apis)]
11558 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11559 pub fn format_to_parts(
11560 this: &RelativeTimeFormat,
11561 value: f64,
11562 unit: RelativeTimeFormatUnit,
11563 ) -> Array<RelativeTimeFormatPart>;
11564
11565 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11566 /// object with properties reflecting the locale and relative time formatting
11567 /// options computed during initialization of this RelativeTimeFormat object.
11568 ///
11569 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11570 #[cfg(not(js_sys_unstable_apis))]
11571 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11572 pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
11573
11574 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11575 /// object with properties reflecting the locale and relative time formatting
11576 /// options computed during initialization of this RelativeTimeFormat object.
11577 ///
11578 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11579 #[cfg(js_sys_unstable_apis)]
11580 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11581 pub fn resolved_options(this: &RelativeTimeFormat) -> ResolvedRelativeTimeFormatOptions;
11582
11583 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11584 /// containing those of the provided locales that are supported in date and time
11585 /// formatting without having to fall back to the runtime's default locale.
11586 ///
11587 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11588 #[cfg(not(js_sys_unstable_apis))]
11589 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11590 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11591
11592 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11593 /// containing those of the provided locales that are supported in date and time
11594 /// formatting without having to fall back to the runtime's default locale.
11595 ///
11596 /// Throws a `RangeError` if locales contain invalid values.
11597 ///
11598 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11599 #[cfg(js_sys_unstable_apis)]
11600 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11601 pub fn supported_locales_of(
11602 locales: &[JsString],
11603 options: &LocaleMatcherOptions,
11604 ) -> Result<Array<JsString>, JsValue>;
11605 }
11606
11607 #[cfg(not(js_sys_unstable_apis))]
11608 impl Default for RelativeTimeFormat {
11609 fn default() -> Self {
11610 Self::new(
11611 &JsValue::UNDEFINED.unchecked_into(),
11612 &JsValue::UNDEFINED.unchecked_into(),
11613 )
11614 }
11615 }
11616
11617 #[cfg(js_sys_unstable_apis)]
11618 impl Default for RelativeTimeFormat {
11619 fn default() -> Self {
11620 Self::new(&[]).unwrap()
11621 }
11622 }
11623
11624 // Intl.ListFormatOptions
11625 #[wasm_bindgen]
11626 extern "C" {
11627 /// Options for `Intl.ListFormat` constructor.
11628 ///
11629 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#options)
11630 #[wasm_bindgen(extends = Object)]
11631 #[derive(Clone, Debug)]
11632 pub type ListFormatOptions;
11633
11634 #[wasm_bindgen(method, getter = localeMatcher)]
11635 pub fn get_locale_matcher(this: &ListFormatOptions) -> Option<LocaleMatcher>;
11636 #[wasm_bindgen(method, setter = localeMatcher)]
11637 pub fn set_locale_matcher(this: &ListFormatOptions, value: LocaleMatcher);
11638
11639 #[wasm_bindgen(method, getter = type)]
11640 pub fn get_type(this: &ListFormatOptions) -> Option<ListFormatType>;
11641 #[wasm_bindgen(method, setter = type)]
11642 pub fn set_type(this: &ListFormatOptions, value: ListFormatType);
11643
11644 #[wasm_bindgen(method, getter = style)]
11645 pub fn get_style(this: &ListFormatOptions) -> Option<ListFormatStyle>;
11646 #[wasm_bindgen(method, setter = style)]
11647 pub fn set_style(this: &ListFormatOptions, value: ListFormatStyle);
11648 }
11649
11650 impl ListFormatOptions {
11651 pub fn new() -> ListFormatOptions {
11652 JsCast::unchecked_into(Object::new())
11653 }
11654 }
11655
11656 impl Default for ListFormatOptions {
11657 fn default() -> Self {
11658 ListFormatOptions::new()
11659 }
11660 }
11661
11662 // Intl.ResolvedListFormatOptions
11663 #[wasm_bindgen]
11664 extern "C" {
11665 /// Resolved options returned by `Intl.ListFormat.prototype.resolvedOptions()`.
11666 ///
11667 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11668 #[wasm_bindgen(extends = ListFormatOptions)]
11669 #[derive(Clone, Debug)]
11670 pub type ResolvedListFormatOptions;
11671
11672 /// The resolved locale string.
11673 #[wasm_bindgen(method, getter = locale)]
11674 pub fn get_locale(this: &ResolvedListFormatOptions) -> JsString;
11675 }
11676
11677 // Intl.ListFormatPart
11678 #[wasm_bindgen]
11679 extern "C" {
11680 /// A part of the formatted list returned by `formatToParts()`.
11681 ///
11682 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11683 #[wasm_bindgen(extends = Object)]
11684 #[derive(Clone, Debug)]
11685 pub type ListFormatPart;
11686
11687 /// The type of the part ("element" or "literal").
11688 #[wasm_bindgen(method, getter = type)]
11689 pub fn type_(this: &ListFormatPart) -> ListFormatPartType;
11690
11691 /// The value of the part.
11692 #[wasm_bindgen(method, getter)]
11693 pub fn value(this: &ListFormatPart) -> JsString;
11694 }
11695
11696 // Intl.ListFormat
11697 #[wasm_bindgen]
11698 extern "C" {
11699 /// The `Intl.ListFormat` object enables language-sensitive list formatting.
11700 ///
11701 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat)
11702 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.ListFormat")]
11703 #[derive(Clone, Debug)]
11704 pub type ListFormat;
11705
11706 /// Creates a new `Intl.ListFormat` object.
11707 ///
11708 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
11709 #[cfg(not(js_sys_unstable_apis))]
11710 #[wasm_bindgen(constructor, js_namespace = Intl)]
11711 pub fn new(locales: &Array, options: &Object) -> ListFormat;
11712
11713 /// Creates a new `Intl.ListFormat` object.
11714 ///
11715 /// Throws a `RangeError` if locales or options contain invalid values.
11716 ///
11717 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
11718 #[cfg(js_sys_unstable_apis)]
11719 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11720 pub fn new(
11721 locales: &[JsString],
11722 options: &ListFormatOptions,
11723 ) -> Result<ListFormat, JsValue>;
11724
11725 /// Formats a list of strings according to the locale and options.
11726 ///
11727 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
11728 #[cfg(not(js_sys_unstable_apis))]
11729 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
11730 pub fn format(this: &ListFormat, list: &Array) -> JsString;
11731
11732 /// Formats a list of strings according to the locale and options.
11733 ///
11734 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
11735 #[cfg(js_sys_unstable_apis)]
11736 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
11737 pub fn format(this: &ListFormat, list: &[JsString]) -> JsString;
11738
11739 /// Returns an array of objects representing the list in parts.
11740 ///
11741 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11742 #[cfg(not(js_sys_unstable_apis))]
11743 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
11744 pub fn format_to_parts(this: &ListFormat, list: &Array) -> Array;
11745
11746 /// Returns an array of objects representing the list in parts.
11747 ///
11748 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11749 #[cfg(js_sys_unstable_apis)]
11750 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
11751 pub fn format_to_parts(this: &ListFormat, list: &[JsString]) -> Array<ListFormatPart>;
11752
11753 /// Returns an object with properties reflecting the options used.
11754 ///
11755 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11756 #[cfg(not(js_sys_unstable_apis))]
11757 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11758 pub fn resolved_options(this: &ListFormat) -> Object;
11759
11760 /// Returns an object with properties reflecting the options used.
11761 ///
11762 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11763 #[cfg(js_sys_unstable_apis)]
11764 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11765 pub fn resolved_options(this: &ListFormat) -> ResolvedListFormatOptions;
11766
11767 /// Returns an array of supported locales.
11768 ///
11769 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
11770 #[cfg(not(js_sys_unstable_apis))]
11771 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11772 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11773
11774 /// Returns an array of supported locales.
11775 ///
11776 /// Throws a `RangeError` if locales contain invalid values.
11777 ///
11778 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
11779 #[cfg(js_sys_unstable_apis)]
11780 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11781 pub fn supported_locales_of(
11782 locales: &[JsString],
11783 options: &LocaleMatcherOptions,
11784 ) -> Result<Array<JsString>, JsValue>;
11785 }
11786
11787 #[cfg(not(js_sys_unstable_apis))]
11788 impl Default for ListFormat {
11789 fn default() -> Self {
11790 Self::new(
11791 &JsValue::UNDEFINED.unchecked_into(),
11792 &JsValue::UNDEFINED.unchecked_into(),
11793 )
11794 }
11795 }
11796
11797 #[cfg(js_sys_unstable_apis)]
11798 impl Default for ListFormat {
11799 fn default() -> Self {
11800 Self::new(&[], &Default::default()).unwrap()
11801 }
11802 }
11803
11804 // Intl.SegmenterOptions
11805 #[wasm_bindgen]
11806 extern "C" {
11807 /// Options for `Intl.Segmenter` constructor.
11808 ///
11809 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#options)
11810 #[wasm_bindgen(extends = Object)]
11811 #[derive(Clone, Debug)]
11812 pub type SegmenterOptions;
11813
11814 #[wasm_bindgen(method, getter = localeMatcher)]
11815 pub fn get_locale_matcher(this: &SegmenterOptions) -> Option<LocaleMatcher>;
11816 #[wasm_bindgen(method, setter = localeMatcher)]
11817 pub fn set_locale_matcher(this: &SegmenterOptions, value: LocaleMatcher);
11818
11819 #[wasm_bindgen(method, getter = granularity)]
11820 pub fn get_granularity(this: &SegmenterOptions) -> Option<SegmenterGranularity>;
11821 #[wasm_bindgen(method, setter = granularity)]
11822 pub fn set_granularity(this: &SegmenterOptions, value: SegmenterGranularity);
11823 }
11824
11825 impl SegmenterOptions {
11826 pub fn new() -> SegmenterOptions {
11827 JsCast::unchecked_into(Object::new())
11828 }
11829 }
11830
11831 impl Default for SegmenterOptions {
11832 fn default() -> Self {
11833 SegmenterOptions::new()
11834 }
11835 }
11836
11837 // Intl.ResolvedSegmenterOptions
11838 #[wasm_bindgen]
11839 extern "C" {
11840 /// Resolved options returned by `Intl.Segmenter.prototype.resolvedOptions()`.
11841 ///
11842 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11843 #[wasm_bindgen(extends = SegmenterOptions)]
11844 #[derive(Clone, Debug)]
11845 pub type ResolvedSegmenterOptions;
11846
11847 /// The resolved locale string.
11848 #[wasm_bindgen(method, getter = locale)]
11849 pub fn get_locale(this: &ResolvedSegmenterOptions) -> JsString;
11850 }
11851
11852 // Intl.SegmentData
11853 #[wasm_bindgen]
11854 extern "C" {
11855 /// Data about a segment returned by the Segments iterator.
11856 ///
11857 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments#segment_data)
11858 #[wasm_bindgen(extends = Object)]
11859 #[derive(Clone, Debug)]
11860 pub type SegmentData;
11861
11862 /// The segment string.
11863 #[wasm_bindgen(method, getter)]
11864 pub fn segment(this: &SegmentData) -> JsString;
11865
11866 /// The index of the segment in the original string.
11867 #[wasm_bindgen(method, getter)]
11868 pub fn index(this: &SegmentData) -> u32;
11869
11870 /// The original input string.
11871 #[wasm_bindgen(method, getter)]
11872 pub fn input(this: &SegmentData) -> JsString;
11873
11874 /// Whether the segment is word-like (only for word granularity).
11875 #[wasm_bindgen(method, getter = isWordLike)]
11876 pub fn is_word_like(this: &SegmentData) -> Option<bool>;
11877 }
11878
11879 // Intl.Segments
11880 #[wasm_bindgen]
11881 extern "C" {
11882 /// The Segments object is an iterable collection of segments of a string.
11883 ///
11884 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments)
11885 #[wasm_bindgen(extends = Object)]
11886 #[derive(Clone, Debug)]
11887 pub type Segments;
11888
11889 /// Returns segment data for the segment containing the character at the given index.
11890 ///
11891 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments/containing)
11892 #[wasm_bindgen(method)]
11893 pub fn containing(this: &Segments, index: u32) -> Option<SegmentData>;
11894 }
11895
11896 // Intl.Segmenter
11897 #[wasm_bindgen]
11898 extern "C" {
11899 /// The `Intl.Segmenter` object enables locale-sensitive text segmentation.
11900 ///
11901 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter)
11902 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Segmenter")]
11903 #[derive(Clone, Debug)]
11904 pub type Segmenter;
11905
11906 /// Creates a new `Intl.Segmenter` object.
11907 ///
11908 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
11909 #[cfg(not(js_sys_unstable_apis))]
11910 #[wasm_bindgen(constructor, js_namespace = Intl)]
11911 pub fn new(locales: &Array, options: &Object) -> Segmenter;
11912
11913 /// Creates a new `Intl.Segmenter` object.
11914 ///
11915 /// Throws a `RangeError` if locales or options contain invalid values.
11916 ///
11917 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
11918 #[cfg(js_sys_unstable_apis)]
11919 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11920 pub fn new(locales: &[JsString], options: &SegmenterOptions) -> Result<Segmenter, JsValue>;
11921
11922 /// Returns a Segments object containing the segments of the input string.
11923 ///
11924 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment)
11925 #[wasm_bindgen(method, js_class = "Intl.Segmenter")]
11926 pub fn segment(this: &Segmenter, input: &str) -> Segments;
11927
11928 /// Returns an object with properties reflecting the options used.
11929 ///
11930 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11931 #[cfg(not(js_sys_unstable_apis))]
11932 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11933 pub fn resolved_options(this: &Segmenter) -> Object;
11934
11935 /// Returns an object with properties reflecting the options used.
11936 ///
11937 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11938 #[cfg(js_sys_unstable_apis)]
11939 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11940 pub fn resolved_options(this: &Segmenter) -> ResolvedSegmenterOptions;
11941
11942 /// Returns an array of supported locales.
11943 ///
11944 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
11945 #[cfg(not(js_sys_unstable_apis))]
11946 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf)]
11947 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11948
11949 /// Returns an array of supported locales.
11950 ///
11951 /// Throws a `RangeError` if locales contain invalid values.
11952 ///
11953 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
11954 #[cfg(js_sys_unstable_apis)]
11955 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11956 pub fn supported_locales_of(
11957 locales: &[JsString],
11958 options: &LocaleMatcherOptions,
11959 ) -> Result<Array<JsString>, JsValue>;
11960 }
11961
11962 #[cfg(not(js_sys_unstable_apis))]
11963 impl Default for Segmenter {
11964 fn default() -> Self {
11965 Self::new(
11966 &JsValue::UNDEFINED.unchecked_into(),
11967 &JsValue::UNDEFINED.unchecked_into(),
11968 )
11969 }
11970 }
11971
11972 #[cfg(js_sys_unstable_apis)]
11973 impl Default for Segmenter {
11974 fn default() -> Self {
11975 Self::new(&[], &Default::default()).unwrap()
11976 }
11977 }
11978
11979 // Intl.DisplayNamesOptions
11980 #[wasm_bindgen]
11981 extern "C" {
11982 /// Options for `Intl.DisplayNames` constructor.
11983 ///
11984 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options)
11985 #[wasm_bindgen(extends = Object)]
11986 #[derive(Clone, Debug)]
11987 pub type DisplayNamesOptions;
11988
11989 #[wasm_bindgen(method, getter = localeMatcher)]
11990 pub fn get_locale_matcher(this: &DisplayNamesOptions) -> Option<LocaleMatcher>;
11991 #[wasm_bindgen(method, setter = localeMatcher)]
11992 pub fn set_locale_matcher(this: &DisplayNamesOptions, value: LocaleMatcher);
11993
11994 #[wasm_bindgen(method, getter = type)]
11995 pub fn get_type(this: &DisplayNamesOptions) -> Option<DisplayNamesType>;
11996 #[wasm_bindgen(method, setter = type)]
11997 pub fn set_type(this: &DisplayNamesOptions, value: DisplayNamesType);
11998
11999 #[wasm_bindgen(method, getter = style)]
12000 pub fn get_style(this: &DisplayNamesOptions) -> Option<DisplayNamesStyle>;
12001 #[wasm_bindgen(method, setter = style)]
12002 pub fn set_style(this: &DisplayNamesOptions, value: DisplayNamesStyle);
12003
12004 #[wasm_bindgen(method, getter = fallback)]
12005 pub fn get_fallback(this: &DisplayNamesOptions) -> Option<DisplayNamesFallback>;
12006 #[wasm_bindgen(method, setter = fallback)]
12007 pub fn set_fallback(this: &DisplayNamesOptions, value: DisplayNamesFallback);
12008
12009 #[wasm_bindgen(method, getter = languageDisplay)]
12010 pub fn get_language_display(
12011 this: &DisplayNamesOptions,
12012 ) -> Option<DisplayNamesLanguageDisplay>;
12013 #[wasm_bindgen(method, setter = languageDisplay)]
12014 pub fn set_language_display(this: &DisplayNamesOptions, value: DisplayNamesLanguageDisplay);
12015 }
12016
12017 impl DisplayNamesOptions {
12018 pub fn new() -> DisplayNamesOptions {
12019 JsCast::unchecked_into(Object::new())
12020 }
12021 }
12022
12023 impl Default for DisplayNamesOptions {
12024 fn default() -> Self {
12025 DisplayNamesOptions::new()
12026 }
12027 }
12028
12029 // Intl.ResolvedDisplayNamesOptions
12030 #[wasm_bindgen]
12031 extern "C" {
12032 /// Resolved options returned by `Intl.DisplayNames.prototype.resolvedOptions()`.
12033 ///
12034 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12035 #[wasm_bindgen(extends = DisplayNamesOptions)]
12036 #[derive(Clone, Debug)]
12037 pub type ResolvedDisplayNamesOptions;
12038
12039 /// The resolved locale string.
12040 #[wasm_bindgen(method, getter = locale)]
12041 pub fn get_locale(this: &ResolvedDisplayNamesOptions) -> JsString;
12042 }
12043
12044 // Intl.DisplayNames
12045 #[wasm_bindgen]
12046 extern "C" {
12047 /// The `Intl.DisplayNames` object enables the consistent translation of
12048 /// language, region, and script display names.
12049 ///
12050 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
12051 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DisplayNames")]
12052 #[derive(Clone, Debug)]
12053 pub type DisplayNames;
12054
12055 /// Creates a new `Intl.DisplayNames` object.
12056 ///
12057 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12058 #[cfg(not(js_sys_unstable_apis))]
12059 #[wasm_bindgen(constructor, js_namespace = Intl)]
12060 pub fn new(locales: &Array, options: &Object) -> DisplayNames;
12061
12062 /// Creates a new `Intl.DisplayNames` object.
12063 ///
12064 /// Throws a `RangeError` if locales or options contain invalid values.
12065 ///
12066 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12067 #[cfg(js_sys_unstable_apis)]
12068 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12069 pub fn new(
12070 locales: &[JsString],
12071 options: &DisplayNamesOptions,
12072 ) -> Result<DisplayNames, JsValue>;
12073
12074 /// Returns the display name for the given code.
12075 ///
12076 /// Returns `undefined` if fallback is "none" and no name is available.
12077 ///
12078 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of)
12079 #[wasm_bindgen(method, js_class = "Intl.DisplayNames")]
12080 pub fn of(this: &DisplayNames, code: &str) -> Option<JsString>;
12081
12082 /// Returns an object with properties reflecting the options used.
12083 ///
12084 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12085 #[cfg(not(js_sys_unstable_apis))]
12086 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12087 pub fn resolved_options(this: &DisplayNames) -> Object;
12088
12089 /// Returns an object with properties reflecting the options used.
12090 ///
12091 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12092 #[cfg(js_sys_unstable_apis)]
12093 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12094 pub fn resolved_options(this: &DisplayNames) -> ResolvedDisplayNamesOptions;
12095
12096 /// Returns an array of supported locales.
12097 ///
12098 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12099 #[cfg(not(js_sys_unstable_apis))]
12100 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf)]
12101 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12102
12103 /// Returns an array of supported locales.
12104 ///
12105 /// Throws a `RangeError` if locales contain invalid values.
12106 ///
12107 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12108 #[cfg(js_sys_unstable_apis)]
12109 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12110 pub fn supported_locales_of(
12111 locales: &[JsString],
12112 options: &LocaleMatcherOptions,
12113 ) -> Result<Array<JsString>, JsValue>;
12114 }
12115
12116 // Intl.Locale
12117 #[wasm_bindgen]
12118 extern "C" {
12119 /// The `Intl.Locale` object is a standard built-in property of the Intl object
12120 /// that represents a Unicode locale identifier.
12121 ///
12122 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
12123 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Locale")]
12124 #[derive(Clone, Debug)]
12125 pub type Locale;
12126
12127 /// Creates a new `Intl.Locale` object.
12128 ///
12129 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12130 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12131 pub fn new(tag: &str) -> Result<Locale, JsValue>;
12132
12133 /// Creates a new `Intl.Locale` object with options.
12134 ///
12135 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12136 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12137 pub fn new_with_options(tag: &str, options: &Object) -> Result<Locale, JsValue>;
12138
12139 /// The base name of the locale (language + region + script).
12140 ///
12141 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName)
12142 #[wasm_bindgen(method, getter = baseName)]
12143 pub fn base_name(this: &Locale) -> JsString;
12144
12145 /// The calendar type for the locale.
12146 ///
12147 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar)
12148 #[wasm_bindgen(method, getter)]
12149 pub fn calendar(this: &Locale) -> Option<JsString>;
12150
12151 /// The case first sorting option.
12152 ///
12153 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst)
12154 #[wasm_bindgen(method, getter = caseFirst)]
12155 pub fn case_first(this: &Locale) -> Option<JsString>;
12156
12157 /// The collation type for the locale.
12158 ///
12159 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation)
12160 #[wasm_bindgen(method, getter)]
12161 pub fn collation(this: &Locale) -> Option<JsString>;
12162
12163 /// The hour cycle for the locale.
12164 ///
12165 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle)
12166 #[wasm_bindgen(method, getter = hourCycle)]
12167 pub fn hour_cycle(this: &Locale) -> Option<JsString>;
12168
12169 /// The language code for the locale.
12170 ///
12171 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language)
12172 #[wasm_bindgen(method, getter)]
12173 pub fn language(this: &Locale) -> JsString;
12174
12175 /// The numbering system for the locale.
12176 ///
12177 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem)
12178 #[wasm_bindgen(method, getter = numberingSystem)]
12179 pub fn numbering_system(this: &Locale) -> Option<JsString>;
12180
12181 /// Whether the locale uses numeric collation.
12182 ///
12183 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric)
12184 #[wasm_bindgen(method, getter)]
12185 pub fn numeric(this: &Locale) -> bool;
12186
12187 /// The region code for the locale.
12188 ///
12189 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/region)
12190 #[wasm_bindgen(method, getter)]
12191 pub fn region(this: &Locale) -> Option<JsString>;
12192
12193 /// The script code for the locale.
12194 ///
12195 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/script)
12196 #[wasm_bindgen(method, getter)]
12197 pub fn script(this: &Locale) -> Option<JsString>;
12198
12199 /// Returns an array of available calendars for the locale.
12200 ///
12201 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars)
12202 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCalendars)]
12203 pub fn get_calendars(this: &Locale) -> Array<JsString>;
12204
12205 /// Returns an array of available collations for the locale.
12206 ///
12207 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations)
12208 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCollations)]
12209 pub fn get_collations(this: &Locale) -> Array<JsString>;
12210
12211 /// Returns an array of available hour cycles for the locale.
12212 ///
12213 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles)
12214 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getHourCycles)]
12215 pub fn get_hour_cycles(this: &Locale) -> Array<JsString>;
12216
12217 /// Returns an array of available numbering systems for the locale.
12218 ///
12219 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems)
12220 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getNumberingSystems)]
12221 pub fn get_numbering_systems(this: &Locale) -> Array<JsString>;
12222
12223 /// Returns an array of available time zones for the locale's region.
12224 ///
12225 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones)
12226 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTimeZones)]
12227 pub fn get_time_zones(this: &Locale) -> Option<Array<JsString>>;
12228
12229 /// Returns week information for the locale.
12230 ///
12231 /// May not be available in all environments.
12232 ///
12233 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12234 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getWeekInfo, catch)]
12235 pub fn get_week_info(this: &Locale) -> Result<WeekInfo, JsValue>;
12236
12237 /// Returns text layout information for the locale.
12238 ///
12239 /// May not be available in all environments.
12240 ///
12241 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12242 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTextInfo, catch)]
12243 pub fn get_text_info(this: &Locale) -> Result<TextInfo, JsValue>;
12244
12245 /// Returns a new Locale with the specified calendar.
12246 ///
12247 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize)
12248 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12249 pub fn maximize(this: &Locale) -> Locale;
12250
12251 /// Returns a new Locale with the minimal subtags.
12252 ///
12253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize)
12254 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12255 pub fn minimize(this: &Locale) -> Locale;
12256 }
12257
12258 // Intl.Locale WeekInfo
12259 #[wasm_bindgen]
12260 extern "C" {
12261 /// Week information for a locale.
12262 ///
12263 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12264 #[wasm_bindgen(extends = Object)]
12265 #[derive(Clone, Debug)]
12266 pub type WeekInfo;
12267
12268 /// The first day of the week (1 = Monday, 7 = Sunday).
12269 #[wasm_bindgen(method, getter = firstDay)]
12270 pub fn first_day(this: &WeekInfo) -> u8;
12271
12272 /// Array of weekend days.
12273 #[wasm_bindgen(method, getter)]
12274 pub fn weekend(this: &WeekInfo) -> Array<Number>;
12275
12276 /// Minimal days in the first week of the year.
12277 #[wasm_bindgen(method, getter = minimalDays)]
12278 pub fn minimal_days(this: &WeekInfo) -> u8;
12279 }
12280
12281 // Intl.Locale TextInfo
12282 #[wasm_bindgen]
12283 extern "C" {
12284 /// Text layout information for a locale.
12285 ///
12286 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12287 #[wasm_bindgen(extends = Object)]
12288 #[derive(Clone, Debug)]
12289 pub type TextInfo;
12290
12291 /// The text direction ("ltr" or "rtl").
12292 #[wasm_bindgen(method, getter)]
12293 pub fn direction(this: &TextInfo) -> JsString;
12294 }
12295
12296 // Intl.DurationFormat enums
12297
12298 /// The style for duration formatting.
12299 ///
12300 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style)
12301 #[wasm_bindgen]
12302 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12303 pub enum DurationFormatStyle {
12304 Long = "long",
12305 Short = "short",
12306 Narrow = "narrow",
12307 Digital = "digital",
12308 }
12309
12310 /// The display style for individual duration units.
12311 ///
12312 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#years)
12313 #[wasm_bindgen]
12314 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12315 pub enum DurationUnitStyle {
12316 Long = "long",
12317 Short = "short",
12318 Narrow = "narrow",
12319 }
12320
12321 /// The display style for time duration units (hours, minutes, seconds).
12322 ///
12323 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#hours)
12324 #[wasm_bindgen]
12325 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12326 pub enum DurationTimeUnitStyle {
12327 Long = "long",
12328 Short = "short",
12329 Narrow = "narrow",
12330 Numeric = "numeric",
12331 #[wasm_bindgen(js_name = "2-digit")]
12332 TwoDigit = "2-digit",
12333 }
12334
12335 /// The display option for duration units.
12336 ///
12337 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#yearsdisplay)
12338 #[wasm_bindgen]
12339 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12340 pub enum DurationUnitDisplay {
12341 Auto = "auto",
12342 Always = "always",
12343 }
12344
12345 /// The type of a duration format part.
12346 ///
12347 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts#type)
12348 #[wasm_bindgen]
12349 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12350 pub enum DurationFormatPartType {
12351 Years = "years",
12352 Months = "months",
12353 Weeks = "weeks",
12354 Days = "days",
12355 Hours = "hours",
12356 Minutes = "minutes",
12357 Seconds = "seconds",
12358 Milliseconds = "milliseconds",
12359 Microseconds = "microseconds",
12360 Nanoseconds = "nanoseconds",
12361 Literal = "literal",
12362 Integer = "integer",
12363 Decimal = "decimal",
12364 Fraction = "fraction",
12365 }
12366
12367 // Intl.DurationFormatOptions
12368 #[wasm_bindgen]
12369 extern "C" {
12370 /// Options for `Intl.DurationFormat` constructor.
12371 ///
12372 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#options)
12373 #[wasm_bindgen(extends = Object)]
12374 #[derive(Clone, Debug)]
12375 pub type DurationFormatOptions;
12376
12377 #[wasm_bindgen(method, getter = localeMatcher)]
12378 pub fn get_locale_matcher(this: &DurationFormatOptions) -> Option<LocaleMatcher>;
12379 #[wasm_bindgen(method, setter = localeMatcher)]
12380 pub fn set_locale_matcher(this: &DurationFormatOptions, value: LocaleMatcher);
12381
12382 #[wasm_bindgen(method, getter = style)]
12383 pub fn get_style(this: &DurationFormatOptions) -> Option<DurationFormatStyle>;
12384 #[wasm_bindgen(method, setter = style)]
12385 pub fn set_style(this: &DurationFormatOptions, value: DurationFormatStyle);
12386
12387 #[wasm_bindgen(method, getter = years)]
12388 pub fn get_years(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12389 #[wasm_bindgen(method, setter = years)]
12390 pub fn set_years(this: &DurationFormatOptions, value: DurationUnitStyle);
12391
12392 #[wasm_bindgen(method, getter = yearsDisplay)]
12393 pub fn get_years_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12394 #[wasm_bindgen(method, setter = yearsDisplay)]
12395 pub fn set_years_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12396
12397 #[wasm_bindgen(method, getter = months)]
12398 pub fn get_months(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12399 #[wasm_bindgen(method, setter = months)]
12400 pub fn set_months(this: &DurationFormatOptions, value: DurationUnitStyle);
12401
12402 #[wasm_bindgen(method, getter = monthsDisplay)]
12403 pub fn get_months_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12404 #[wasm_bindgen(method, setter = monthsDisplay)]
12405 pub fn set_months_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12406
12407 #[wasm_bindgen(method, getter = weeks)]
12408 pub fn get_weeks(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12409 #[wasm_bindgen(method, setter = weeks)]
12410 pub fn set_weeks(this: &DurationFormatOptions, value: DurationUnitStyle);
12411
12412 #[wasm_bindgen(method, getter = weeksDisplay)]
12413 pub fn get_weeks_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12414 #[wasm_bindgen(method, setter = weeksDisplay)]
12415 pub fn set_weeks_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12416
12417 #[wasm_bindgen(method, getter = days)]
12418 pub fn get_days(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12419 #[wasm_bindgen(method, setter = days)]
12420 pub fn set_days(this: &DurationFormatOptions, value: DurationUnitStyle);
12421
12422 #[wasm_bindgen(method, getter = daysDisplay)]
12423 pub fn get_days_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12424 #[wasm_bindgen(method, setter = daysDisplay)]
12425 pub fn set_days_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12426
12427 #[wasm_bindgen(method, getter = hours)]
12428 pub fn get_hours(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12429 #[wasm_bindgen(method, setter = hours)]
12430 pub fn set_hours(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12431
12432 #[wasm_bindgen(method, getter = hoursDisplay)]
12433 pub fn get_hours_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12434 #[wasm_bindgen(method, setter = hoursDisplay)]
12435 pub fn set_hours_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12436
12437 #[wasm_bindgen(method, getter = minutes)]
12438 pub fn get_minutes(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12439 #[wasm_bindgen(method, setter = minutes)]
12440 pub fn set_minutes(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12441
12442 #[wasm_bindgen(method, getter = minutesDisplay)]
12443 pub fn get_minutes_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12444 #[wasm_bindgen(method, setter = minutesDisplay)]
12445 pub fn set_minutes_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12446
12447 #[wasm_bindgen(method, getter = seconds)]
12448 pub fn get_seconds(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12449 #[wasm_bindgen(method, setter = seconds)]
12450 pub fn set_seconds(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12451
12452 #[wasm_bindgen(method, getter = secondsDisplay)]
12453 pub fn get_seconds_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12454 #[wasm_bindgen(method, setter = secondsDisplay)]
12455 pub fn set_seconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12456
12457 #[wasm_bindgen(method, getter = milliseconds)]
12458 pub fn get_milliseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12459 #[wasm_bindgen(method, setter = milliseconds)]
12460 pub fn set_milliseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12461
12462 #[wasm_bindgen(method, getter = millisecondsDisplay)]
12463 pub fn get_milliseconds_display(
12464 this: &DurationFormatOptions,
12465 ) -> Option<DurationUnitDisplay>;
12466 #[wasm_bindgen(method, setter = millisecondsDisplay)]
12467 pub fn set_milliseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12468
12469 #[wasm_bindgen(method, getter = microseconds)]
12470 pub fn get_microseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12471 #[wasm_bindgen(method, setter = microseconds)]
12472 pub fn set_microseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12473
12474 #[wasm_bindgen(method, getter = microsecondsDisplay)]
12475 pub fn get_microseconds_display(
12476 this: &DurationFormatOptions,
12477 ) -> Option<DurationUnitDisplay>;
12478 #[wasm_bindgen(method, setter = microsecondsDisplay)]
12479 pub fn set_microseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12480
12481 #[wasm_bindgen(method, getter = nanoseconds)]
12482 pub fn get_nanoseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12483 #[wasm_bindgen(method, setter = nanoseconds)]
12484 pub fn set_nanoseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12485
12486 #[wasm_bindgen(method, getter = nanosecondsDisplay)]
12487 pub fn get_nanoseconds_display(this: &DurationFormatOptions)
12488 -> Option<DurationUnitDisplay>;
12489 #[wasm_bindgen(method, setter = nanosecondsDisplay)]
12490 pub fn set_nanoseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12491
12492 #[wasm_bindgen(method, getter = fractionalDigits)]
12493 pub fn get_fractional_digits(this: &DurationFormatOptions) -> Option<u8>;
12494 #[wasm_bindgen(method, setter = fractionalDigits)]
12495 pub fn set_fractional_digits(this: &DurationFormatOptions, value: u8);
12496 }
12497
12498 impl DurationFormatOptions {
12499 pub fn new() -> DurationFormatOptions {
12500 JsCast::unchecked_into(Object::new())
12501 }
12502 }
12503
12504 impl Default for DurationFormatOptions {
12505 fn default() -> Self {
12506 DurationFormatOptions::new()
12507 }
12508 }
12509
12510 // Intl.ResolvedDurationFormatOptions
12511 #[wasm_bindgen]
12512 extern "C" {
12513 /// Resolved options returned by `Intl.DurationFormat.prototype.resolvedOptions()`.
12514 ///
12515 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12516 #[wasm_bindgen(extends = DurationFormatOptions)]
12517 #[derive(Clone, Debug)]
12518 pub type ResolvedDurationFormatOptions;
12519
12520 /// The resolved locale string.
12521 #[wasm_bindgen(method, getter = locale)]
12522 pub fn get_locale(this: &ResolvedDurationFormatOptions) -> JsString;
12523
12524 /// The resolved numbering system.
12525 #[wasm_bindgen(method, getter = numberingSystem)]
12526 pub fn get_numbering_system(this: &ResolvedDurationFormatOptions) -> JsString;
12527 }
12528
12529 // Intl.Duration (input object for DurationFormat)
12530 #[wasm_bindgen]
12531 extern "C" {
12532 /// A duration object used as input to `Intl.DurationFormat.format()`.
12533 ///
12534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration)
12535 #[wasm_bindgen(extends = Object)]
12536 #[derive(Clone, Debug)]
12537 pub type Duration;
12538
12539 #[wasm_bindgen(method, getter)]
12540 pub fn years(this: &Duration) -> Option<f64>;
12541 #[wasm_bindgen(method, setter)]
12542 pub fn set_years(this: &Duration, value: f64);
12543
12544 #[wasm_bindgen(method, getter)]
12545 pub fn months(this: &Duration) -> Option<f64>;
12546 #[wasm_bindgen(method, setter)]
12547 pub fn set_months(this: &Duration, value: f64);
12548
12549 #[wasm_bindgen(method, getter)]
12550 pub fn weeks(this: &Duration) -> Option<f64>;
12551 #[wasm_bindgen(method, setter)]
12552 pub fn set_weeks(this: &Duration, value: f64);
12553
12554 #[wasm_bindgen(method, getter)]
12555 pub fn days(this: &Duration) -> Option<f64>;
12556 #[wasm_bindgen(method, setter)]
12557 pub fn set_days(this: &Duration, value: f64);
12558
12559 #[wasm_bindgen(method, getter)]
12560 pub fn hours(this: &Duration) -> Option<f64>;
12561 #[wasm_bindgen(method, setter)]
12562 pub fn set_hours(this: &Duration, value: f64);
12563
12564 #[wasm_bindgen(method, getter)]
12565 pub fn minutes(this: &Duration) -> Option<f64>;
12566 #[wasm_bindgen(method, setter)]
12567 pub fn set_minutes(this: &Duration, value: f64);
12568
12569 #[wasm_bindgen(method, getter)]
12570 pub fn seconds(this: &Duration) -> Option<f64>;
12571 #[wasm_bindgen(method, setter)]
12572 pub fn set_seconds(this: &Duration, value: f64);
12573
12574 #[wasm_bindgen(method, getter)]
12575 pub fn milliseconds(this: &Duration) -> Option<f64>;
12576 #[wasm_bindgen(method, setter)]
12577 pub fn set_milliseconds(this: &Duration, value: f64);
12578
12579 #[wasm_bindgen(method, getter)]
12580 pub fn microseconds(this: &Duration) -> Option<f64>;
12581 #[wasm_bindgen(method, setter)]
12582 pub fn set_microseconds(this: &Duration, value: f64);
12583
12584 #[wasm_bindgen(method, getter)]
12585 pub fn nanoseconds(this: &Duration) -> Option<f64>;
12586 #[wasm_bindgen(method, setter)]
12587 pub fn set_nanoseconds(this: &Duration, value: f64);
12588 }
12589
12590 impl Duration {
12591 pub fn new() -> Duration {
12592 JsCast::unchecked_into(Object::new())
12593 }
12594 }
12595
12596 impl Default for Duration {
12597 fn default() -> Self {
12598 Duration::new()
12599 }
12600 }
12601
12602 // Intl.DurationFormatPart
12603 #[wasm_bindgen]
12604 extern "C" {
12605 /// A part of the formatted duration returned by `formatToParts()`.
12606 ///
12607 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12608 #[wasm_bindgen(extends = Object)]
12609 #[derive(Clone, Debug)]
12610 pub type DurationFormatPart;
12611
12612 /// The type of the part.
12613 #[wasm_bindgen(method, getter = type)]
12614 pub fn type_(this: &DurationFormatPart) -> DurationFormatPartType;
12615
12616 /// The value of the part.
12617 #[wasm_bindgen(method, getter)]
12618 pub fn value(this: &DurationFormatPart) -> JsString;
12619
12620 /// The unit this part represents (if applicable).
12621 #[wasm_bindgen(method, getter)]
12622 pub fn unit(this: &DurationFormatPart) -> Option<JsString>;
12623 }
12624
12625 // Intl.DurationFormat
12626 #[wasm_bindgen]
12627 extern "C" {
12628 /// The `Intl.DurationFormat` object enables language-sensitive duration formatting.
12629 ///
12630 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat)
12631 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DurationFormat")]
12632 #[derive(Clone, Debug)]
12633 pub type DurationFormat;
12634
12635 /// Creates a new `Intl.DurationFormat` object.
12636 ///
12637 /// Throws a `RangeError` if locales or options contain invalid values.
12638 ///
12639 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat)
12640 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12641 pub fn new(
12642 locales: &[JsString],
12643 options: &DurationFormatOptions,
12644 ) -> Result<DurationFormat, JsValue>;
12645
12646 /// Formats a duration according to the locale and formatting options.
12647 ///
12648 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format)
12649 #[wasm_bindgen(method, js_class = "Intl.DurationFormat")]
12650 pub fn format(this: &DurationFormat, duration: &Duration) -> JsString;
12651
12652 /// Returns an array of objects representing the formatted duration in parts.
12653 ///
12654 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12655 #[wasm_bindgen(method, js_class = "Intl.DurationFormat", js_name = formatToParts)]
12656 pub fn format_to_parts(
12657 this: &DurationFormat,
12658 duration: &Duration,
12659 ) -> Array<DurationFormatPart>;
12660
12661 /// Returns an object with properties reflecting the options used.
12662 ///
12663 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12664 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12665 pub fn resolved_options(this: &DurationFormat) -> ResolvedDurationFormatOptions;
12666
12667 /// Returns an array of supported locales.
12668 ///
12669 /// Throws a `RangeError` if locales contain invalid values.
12670 ///
12671 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf)
12672 #[wasm_bindgen(static_method_of = DurationFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12673 pub fn supported_locales_of(
12674 locales: &[JsString],
12675 options: &LocaleMatcherOptions,
12676 ) -> Result<Array<JsString>, JsValue>;
12677 }
12678
12679 impl Default for DurationFormat {
12680 fn default() -> Self {
12681 Self::new(&[], &Default::default()).unwrap()
12682 }
12683 }
12684}
12685
12686#[wasm_bindgen]
12687extern "C" {
12688 /// The `PromiseState` object represents the the status of the promise,
12689 /// as used in `allSettled`.
12690 ///
12691 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12692 #[must_use]
12693 #[wasm_bindgen(extends = Object, typescript_type = "any")]
12694 #[derive(Clone, Debug)]
12695 pub type PromiseState<T = JsValue>;
12696
12697 /// A string, either "fulfilled" or "rejected", indicating the eventual state of the promise.
12698 #[wasm_bindgen(method, getter = status)]
12699 pub fn get_status<T>(this: &PromiseState<T>) -> String;
12700
12701 /// Only present if status is "fulfilled". The value that the promise was fulfilled with.
12702 #[wasm_bindgen(method, getter = value)]
12703 pub fn get_value<T>(this: &PromiseState<T>) -> Option<T>;
12704
12705 /// Only present if status is "rejected". The reason that the promise was rejected with.
12706 #[wasm_bindgen(method, getter = reason)]
12707 pub fn get_reason<T>(this: &PromiseState<T>) -> Option<JsValue>;
12708}
12709
12710impl<T> PromiseState<T> {
12711 pub fn is_fulfilled(&self) -> bool {
12712 self.get_status() == "fulfilled"
12713 }
12714
12715 pub fn is_rejected(&self) -> bool {
12716 self.get_status() == "rejected"
12717 }
12718}
12719
12720// Promise
12721#[wasm_bindgen]
12722extern "C" {
12723 /// The `Promise` object represents the eventual completion (or failure) of
12724 /// an asynchronous operation, and its resulting value.
12725 ///
12726 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12727 #[must_use]
12728 #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>", no_promising)]
12729 #[derive(Clone, Debug)]
12730 pub type Promise<T = JsValue>;
12731
12732 /// Creates a new `Promise` with the provided executor `cb`
12733 ///
12734 /// The `cb` is a function that is passed with the arguments `resolve` and
12735 /// `reject`. The `cb` function is executed immediately by the `Promise`
12736 /// implementation, passing `resolve` and `reject` functions (the executor
12737 /// is called before the `Promise` constructor even returns the created
12738 /// object). The `resolve` and `reject` functions, when called, resolve or
12739 /// reject the promise, respectively. The executor normally initiates
12740 /// some asynchronous work, and then, once that completes, either calls
12741 /// the `resolve` function to resolve the promise or else rejects it if an
12742 /// error occurred.
12743 ///
12744 /// If an error is thrown in the executor function, the promise is rejected.
12745 /// The return value of the executor is ignored.
12746 ///
12747 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12748 #[cfg(not(js_sys_unstable_apis))]
12749 #[wasm_bindgen(constructor)]
12750 pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
12751
12752 /// Creates a new `Promise` with the provided executor `cb`
12753 ///
12754 /// The `cb` is a function that is passed with the arguments `resolve` and
12755 /// `reject`. The `cb` function is executed immediately by the `Promise`
12756 /// implementation, passing `resolve` and `reject` functions (the executor
12757 /// is called before the `Promise` constructor even returns the created
12758 /// object). The `resolve` and `reject` functions, when called, resolve or
12759 /// reject the promise, respectively. The executor normally initiates
12760 /// some asynchronous work, and then, once that completes, either calls
12761 /// the `resolve` function to resolve the promise or else rejects it if an
12762 /// error occurred.
12763 ///
12764 /// If an error is thrown in the executor function, the promise is rejected.
12765 /// The return value of the executor is ignored.
12766 ///
12767 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12768 #[cfg(js_sys_unstable_apis)]
12769 #[wasm_bindgen(constructor)]
12770 pub fn new<T: JsGeneric>(
12771 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
12772 ) -> Promise<T>;
12773
12774 // Next major: deprecate
12775 /// Creates a new `Promise` with the provided executor `cb`
12776 ///
12777 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12778 #[wasm_bindgen(constructor)]
12779 pub fn new_typed<T: JsGeneric>(
12780 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
12781 ) -> Promise<T>;
12782
12783 /// The `Promise.all(iterable)` method returns a single `Promise` that
12784 /// resolves when all of the promises in the iterable argument have resolved
12785 /// or when the iterable argument contains no promises. It rejects with the
12786 /// reason of the first promise that rejects.
12787 ///
12788 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12789 #[cfg(not(js_sys_unstable_apis))]
12790 #[wasm_bindgen(static_method_of = Promise)]
12791 pub fn all(obj: &JsValue) -> Promise;
12792
12793 /// The `Promise.all(iterable)` method returns a single `Promise` that
12794 /// resolves when all of the promises in the iterable argument have resolved
12795 /// or when the iterable argument contains no promises. It rejects with the
12796 /// reason of the first promise that rejects.
12797 ///
12798 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12799 #[cfg(js_sys_unstable_apis)]
12800 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
12801 pub fn all<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
12802 where
12803 I::Item: Promising;
12804
12805 // Next major: deprecate
12806 /// The `Promise.all(iterable)` method returns a single `Promise` that
12807 /// resolves when all of the promises in the iterable argument have resolved
12808 /// or when the iterable argument contains no promises. It rejects with the
12809 /// reason of the first promise that rejects.
12810 ///
12811 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12812 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
12813 pub fn all_iterable<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
12814 where
12815 I::Item: Promising;
12816
12817 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12818 /// resolves when all of the promises in the iterable argument have either
12819 /// fulfilled or rejected or when the iterable argument contains no promises.
12820 ///
12821 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12822 #[cfg(not(js_sys_unstable_apis))]
12823 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12824 pub fn all_settled(obj: &JsValue) -> Promise;
12825
12826 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12827 /// resolves when all of the promises in the iterable argument have either
12828 /// fulfilled or rejected or when the iterable argument contains no promises.
12829 ///
12830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12831 #[cfg(js_sys_unstable_apis)]
12832 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12833 pub fn all_settled<I: Iterable>(
12834 obj: &I,
12835 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
12836 where
12837 I::Item: Promising;
12838
12839 // Next major: deprecate
12840 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12841 /// resolves when all of the promises in the iterable argument have either
12842 /// fulfilled or rejected or when the iterable argument contains no promises.
12843 ///
12844 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12845 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12846 pub fn all_settled_iterable<I: Iterable>(
12847 obj: &I,
12848 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
12849 where
12850 I::Item: Promising;
12851
12852 /// The `Promise.any(iterable)` method returns a single `Promise` that
12853 /// resolves when any of the promises in the iterable argument have resolved
12854 /// or when the iterable argument contains no promises. It rejects with an
12855 /// `AggregateError` if all promises in the iterable rejected.
12856 ///
12857 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12858 #[cfg(not(js_sys_unstable_apis))]
12859 #[wasm_bindgen(static_method_of = Promise)]
12860 pub fn any(obj: &JsValue) -> Promise;
12861
12862 /// The `Promise.any(iterable)` method returns a single `Promise` that
12863 /// resolves when any of the promises in the iterable argument have resolved
12864 /// or when the iterable argument contains no promises. It rejects with an
12865 /// `AggregateError` if all promises in the iterable rejected.
12866 ///
12867 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12868 #[cfg(js_sys_unstable_apis)]
12869 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
12870 pub fn any<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12871 where
12872 I::Item: Promising;
12873
12874 // Next major: deprecate
12875 /// The `Promise.any(iterable)` method returns a single `Promise` that
12876 /// resolves when any of the promises in the iterable argument have resolved
12877 /// or when the iterable argument contains no promises. It rejects with an
12878 /// `AggregateError` if all promises in the iterable rejected.
12879 ///
12880 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12881 #[cfg(not(js_sys_unstable_apis))]
12882 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
12883 pub fn any_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12884 where
12885 I::Item: Promising;
12886
12887 /// The `Promise.race(iterable)` method returns a promise that resolves or
12888 /// rejects as soon as one of the promises in the iterable resolves or
12889 /// rejects, with the value or reason from that promise.
12890 ///
12891 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12892 #[cfg(not(js_sys_unstable_apis))]
12893 #[wasm_bindgen(static_method_of = Promise)]
12894 pub fn race(obj: &JsValue) -> Promise;
12895
12896 /// The `Promise.race(iterable)` method returns a promise that resolves or
12897 /// rejects as soon as one of the promises in the iterable resolves or
12898 /// rejects, with the value or reason from that promise.
12899 ///
12900 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12901 #[cfg(js_sys_unstable_apis)]
12902 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
12903 pub fn race<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12904 where
12905 I::Item: Promising;
12906
12907 // Next major: deprecate
12908 /// The `Promise.race(iterable)` method returns a promise that resolves or
12909 /// rejects as soon as one of the promises in the iterable resolves or
12910 /// rejects, with the value or reason from that promise.
12911 ///
12912 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12913 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
12914 pub fn race_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12915 where
12916 I::Item: Promising;
12917
12918 /// The `Promise.reject(reason)` method returns a `Promise` object that is
12919 /// rejected with the given reason.
12920 ///
12921 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12922 #[cfg(not(js_sys_unstable_apis))]
12923 #[wasm_bindgen(static_method_of = Promise)]
12924 pub fn reject(obj: &JsValue) -> Promise;
12925
12926 /// The `Promise.reject(reason)` method returns a `Promise` object that is
12927 /// rejected with the given reason.
12928 ///
12929 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12930 #[cfg(js_sys_unstable_apis)]
12931 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
12932 pub fn reject<T>(obj: &JsValue) -> Promise<T>;
12933
12934 // Next major: deprecate
12935 /// The `Promise.reject(reason)` method returns a `Promise` object that is
12936 /// rejected with the given reason.
12937 ///
12938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12939 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
12940 pub fn reject_typed<T>(obj: &JsValue) -> Promise<T>;
12941
12942 /// The `Promise.resolve(value)` method returns a `Promise` object that is
12943 /// resolved with the given value. If the value is a promise, that promise
12944 /// is returned; if the value is a thenable (i.e. has a "then" method), the
12945 /// returned promise will "follow" that thenable, adopting its eventual
12946 /// state; otherwise the returned promise will be fulfilled with the value.
12947 ///
12948 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
12949 #[wasm_bindgen(static_method_of = Promise, js_name = resolve)]
12950 pub fn resolve<U: Promising>(obj: &U) -> Promise<U::Resolution>;
12951
12952 /// The `catch()` method returns a `Promise` and deals with rejected cases
12953 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
12954 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
12955 /// `obj.then(undefined, onRejected)`).
12956 ///
12957 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
12958 #[cfg(not(js_sys_unstable_apis))]
12959 #[wasm_bindgen(method)]
12960 pub fn catch<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut(JsValue)>) -> Promise<JsValue>;
12961
12962 /// The `catch()` method returns a `Promise` and deals with rejected cases
12963 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
12964 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
12965 /// `obj.then(undefined, onRejected)`).
12966 ///
12967 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
12968 #[cfg(js_sys_unstable_apis)]
12969 #[wasm_bindgen(method, js_name = catch)]
12970 pub fn catch<'a, T, R: Promising>(
12971 this: &Promise<T>,
12972 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
12973 ) -> Promise<R::Resolution>;
12974
12975 // Next major: deprecate
12976 /// Same as `catch`, but returning a result to become the new Promise value.
12977 #[wasm_bindgen(method, js_name = catch)]
12978 pub fn catch_map<'a, T, R: Promising>(
12979 this: &Promise<T>,
12980 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
12981 ) -> Promise<R::Resolution>;
12982
12983 /// The `then()` method returns a `Promise`. It takes up to two arguments:
12984 /// callback functions for the success and failure cases of the `Promise`.
12985 ///
12986 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
12987 #[cfg(not(js_sys_unstable_apis))]
12988 #[wasm_bindgen(method)]
12989 pub fn then<'a, T>(this: &Promise<T>, cb: &ScopedClosure<'a, dyn FnMut(T)>)
12990 -> Promise<JsValue>;
12991
12992 /// The `then()` method returns a `Promise`. It takes up to two arguments:
12993 /// callback functions for the success and failure cases of the `Promise`.
12994 ///
12995 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
12996 #[cfg(js_sys_unstable_apis)]
12997 #[wasm_bindgen(method, js_name = then)]
12998 pub fn then<'a, T, R: Promising>(
12999 this: &Promise<T>,
13000 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13001 ) -> Promise<R::Resolution>;
13002
13003 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13004 /// callback functions for the success and failure cases of the `Promise`.
13005 ///
13006 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13007 #[wasm_bindgen(method, js_name = then)]
13008 pub fn then_with_reject<'a, T, R: Promising>(
13009 this: &Promise<T>,
13010 resolve: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13011 reject: &ScopedClosure<'a, dyn FnMut(JsValue) -> Result<R, JsError>>,
13012 ) -> Promise<R::Resolution>;
13013
13014 // Next major: deprecate
13015 /// Alias for `then()` with a return value.
13016 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13017 /// callback functions for the success and failure cases of the `Promise`.
13018 ///
13019 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13020 #[wasm_bindgen(method, js_name = then)]
13021 pub fn then_map<'a, T, R: Promising>(
13022 this: &Promise<T>,
13023 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13024 ) -> Promise<R::Resolution>;
13025
13026 /// Same as `then`, only with both arguments provided.
13027 ///
13028 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13029 #[wasm_bindgen(method, js_name = then)]
13030 pub fn then2(
13031 this: &Promise,
13032 resolve: &ScopedClosure<dyn FnMut(JsValue)>,
13033 reject: &ScopedClosure<dyn FnMut(JsValue)>,
13034 ) -> Promise;
13035
13036 /// The `finally()` method returns a `Promise`. When the promise is settled,
13037 /// whether fulfilled or rejected, the specified callback function is
13038 /// executed. This provides a way for code that must be executed once the
13039 /// `Promise` has been dealt with to be run whether the promise was
13040 /// fulfilled successfully or rejected.
13041 ///
13042 /// This lets you avoid duplicating code in both the promise's `then()` and
13043 /// `catch()` handlers.
13044 ///
13045 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
13046 #[wasm_bindgen(method)]
13047 pub fn finally<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut()>) -> Promise<JsValue>;
13048}
13049
13050impl<T: JsGeneric> Promising for Promise<T> {
13051 type Resolution = T;
13052}
13053
13054/// Returns a handle to the global scope object.
13055///
13056/// This allows access to the global properties and global names by accessing
13057/// the `Object` returned.
13058pub fn global() -> Object {
13059 use once_cell::unsync::Lazy;
13060
13061 struct Wrapper<T>(Lazy<T>);
13062
13063 #[cfg(not(target_feature = "atomics"))]
13064 unsafe impl<T> Sync for Wrapper<T> {}
13065
13066 #[cfg(not(target_feature = "atomics"))]
13067 unsafe impl<T> Send for Wrapper<T> {}
13068
13069 #[cfg_attr(target_feature = "atomics", thread_local)]
13070 static GLOBAL: Wrapper<Object> = Wrapper(Lazy::new(get_global_object));
13071
13072 return GLOBAL.0.clone();
13073
13074 fn get_global_object() -> Object {
13075 // Accessing the global object is not an easy thing to do, and what we
13076 // basically want is `globalThis` but we can't rely on that existing
13077 // everywhere. In the meantime we've got the fallbacks mentioned in:
13078 //
13079 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
13080 //
13081 // Note that this is pretty heavy code-size wise but it at least gets
13082 // the job largely done for now and avoids the `Function` constructor at
13083 // the end which triggers CSP errors.
13084 #[wasm_bindgen]
13085 extern "C" {
13086 type Global;
13087
13088 #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
13089 static GLOBAL_THIS: Option<Object>;
13090
13091 #[wasm_bindgen(thread_local_v2, js_name = self)]
13092 static SELF: Option<Object>;
13093
13094 #[wasm_bindgen(thread_local_v2, js_name = window)]
13095 static WINDOW: Option<Object>;
13096
13097 #[wasm_bindgen(thread_local_v2, js_name = global)]
13098 static GLOBAL: Option<Object>;
13099 }
13100
13101 // The order is important: in Firefox Extension Content Scripts `globalThis`
13102 // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
13103 let static_object = SELF
13104 .with(Option::clone)
13105 .or_else(|| WINDOW.with(Option::clone))
13106 .or_else(|| GLOBAL_THIS.with(Option::clone))
13107 .or_else(|| GLOBAL.with(Option::clone));
13108 if let Some(obj) = static_object {
13109 if !obj.is_undefined() {
13110 return obj;
13111 }
13112 }
13113
13114 // Global object not found
13115 JsValue::undefined().unchecked_into()
13116 }
13117}
13118
13119macro_rules! arrays {
13120 ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
13121 #[wasm_bindgen]
13122 extern "C" {
13123 #[wasm_bindgen(extends = Object, typescript_type = $name)]
13124 #[derive(Clone, Debug)]
13125 pub type $name;
13126
13127 /// The
13128 #[doc = $ctor]
13129 /// constructor creates a new array.
13130 ///
13131 /// [MDN documentation](
13132 #[doc = $mdn]
13133 /// )
13134 #[wasm_bindgen(constructor)]
13135 pub fn new(constructor_arg: &JsValue) -> $name;
13136
13137 /// An
13138 #[doc = $ctor]
13139 /// which creates an array with an internal buffer large
13140 /// enough for `length` elements.
13141 ///
13142 /// [MDN documentation](
13143 #[doc = $mdn]
13144 /// )
13145 #[wasm_bindgen(constructor)]
13146 pub fn new_with_length(length: u32) -> $name;
13147
13148 /// An
13149 #[doc = $ctor]
13150 /// which creates an array from a Rust slice.
13151 ///
13152 /// [MDN documentation](
13153 #[doc = $mdn]
13154 /// )
13155 #[wasm_bindgen(constructor)]
13156 pub fn new_from_slice(slice: &[$ty]) -> $name;
13157
13158 /// An
13159 #[doc = $ctor]
13160 /// which creates an array with the given buffer but is a
13161 /// view starting at `byte_offset`.
13162 ///
13163 /// [MDN documentation](
13164 #[doc = $mdn]
13165 /// )
13166 #[wasm_bindgen(constructor)]
13167 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
13168
13169 /// An
13170 #[doc = $ctor]
13171 /// which creates an array with the given buffer but is a
13172 /// view starting at `byte_offset` for `length` elements.
13173 ///
13174 /// [MDN documentation](
13175 #[doc = $mdn]
13176 /// )
13177 #[wasm_bindgen(constructor)]
13178 pub fn new_with_byte_offset_and_length(
13179 buffer: &JsValue,
13180 byte_offset: u32,
13181 length: u32,
13182 ) -> $name;
13183
13184 /// The `fill()` method fills all the elements of an array from a start index
13185 /// to an end index with a static value. The end index is not included.
13186 ///
13187 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
13188 #[wasm_bindgen(method)]
13189 pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
13190
13191 /// The buffer accessor property represents the `ArrayBuffer` referenced
13192 /// by a `TypedArray` at construction time.
13193 #[wasm_bindgen(getter, method)]
13194 pub fn buffer(this: &$name) -> ArrayBuffer;
13195
13196 /// The `subarray()` method returns a new `TypedArray` on the same
13197 /// `ArrayBuffer` store and with the same element types as for this
13198 /// `TypedArray` object.
13199 #[wasm_bindgen(method)]
13200 pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
13201
13202 /// The `slice()` method returns a shallow copy of a portion of a typed
13203 /// array into a new typed array object. This method has the same algorithm
13204 /// as `Array.prototype.slice()`.
13205 #[wasm_bindgen(method)]
13206 pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
13207
13208 /// The `forEach()` method executes a provided function once per array
13209 /// element. This method has the same algorithm as
13210 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13211 /// types here.
13212 #[wasm_bindgen(method, js_name = forEach)]
13213 pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
13214
13215 /// The `forEach()` method executes a provided function once per array
13216 /// element. This method has the same algorithm as
13217 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13218 /// types here.
13219 #[wasm_bindgen(method, js_name = forEach, catch)]
13220 pub fn try_for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name) -> Result<(), JsError>) -> Result<(), JsValue>;
13221
13222 /// The length accessor property represents the length (in elements) of a
13223 /// typed array.
13224 #[wasm_bindgen(method, getter)]
13225 pub fn length(this: &$name) -> u32;
13226
13227 /// The byteLength accessor property represents the length (in bytes) of a
13228 /// typed array.
13229 #[wasm_bindgen(method, getter, js_name = byteLength)]
13230 pub fn byte_length(this: &$name) -> u32;
13231
13232 /// The byteOffset accessor property represents the offset (in bytes) of a
13233 /// typed array from the start of its `ArrayBuffer`.
13234 #[wasm_bindgen(method, getter, js_name = byteOffset)]
13235 pub fn byte_offset(this: &$name) -> u32;
13236
13237 /// The `set()` method stores multiple values in the typed array, reading
13238 /// input values from a specified array.
13239 #[wasm_bindgen(method)]
13240 pub fn set(this: &$name, src: &JsValue, offset: u32);
13241
13242 /// Gets the value at `idx`, counting from the end if negative.
13243 #[wasm_bindgen(method)]
13244 pub fn at(this: &$name, idx: i32) -> Option<$ty>;
13245
13246 /// The `copyWithin()` method shallow copies part of a typed array to another
13247 /// location in the same typed array and returns it, without modifying its size.
13248 ///
13249 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
13250 #[wasm_bindgen(method, js_name = copyWithin)]
13251 pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
13252
13253 /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
13254 #[wasm_bindgen(method, indexing_getter)]
13255 pub fn get_index(this: &$name, idx: u32) -> $ty;
13256
13257 /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
13258 #[wasm_bindgen(method, indexing_setter)]
13259 pub fn set_index(this: &$name, idx: u32, value: $ty);
13260
13261 /// Copies the Rust slice's data to self.
13262 ///
13263 /// This method is not expected to be public. It requires the length of the
13264 /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
13265 #[wasm_bindgen(method, js_name = set)]
13266 fn copy_from_slice(this: &$name, slice: &[$ty]);
13267
13268 /// Copies this TypedArray's data to Rust slice;
13269 ///
13270 /// This method is not expected to be public. It requires the length of the
13271 /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
13272 ///
13273 /// # Workaround
13274 ///
13275 /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
13276 /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
13277 /// us to specify the `this` value inside the function.
13278 ///
13279 /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
13280 /// `slice.set(typed_array)`.
13281 #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
13282 fn copy_to_slice(slice: &mut [$ty], this: &$name);
13283 }
13284
13285 impl $name {
13286 /// Creates a JS typed array which is a view into wasm's linear
13287 /// memory at the slice specified.
13288 ///
13289 /// This function returns a new typed array which is a view into
13290 /// wasm's memory. This view does not copy the underlying data.
13291 ///
13292 /// # Safety
13293 ///
13294 /// Views into WebAssembly memory are only valid so long as the
13295 /// backing buffer isn't resized in JS. Once this function is called
13296 /// any future calls to `Box::new` (or malloc of any form) may cause
13297 /// the returned value here to be invalidated. Use with caution!
13298 ///
13299 /// Additionally the returned object can be safely mutated but the
13300 /// input slice isn't guaranteed to be mutable.
13301 ///
13302 /// Finally, the returned object is disconnected from the input
13303 /// slice's lifetime, so there's no guarantee that the data is read
13304 /// at the right time.
13305 pub unsafe fn view(rust: &[$ty]) -> $name {
13306 wasm_bindgen::__rt::wbg_cast(rust)
13307 }
13308
13309 /// Creates a JS typed array which is a view into wasm's linear
13310 /// memory at the specified pointer with specified length.
13311 ///
13312 /// This function returns a new typed array which is a view into
13313 /// wasm's memory. This view does not copy the underlying data.
13314 ///
13315 /// # Safety
13316 ///
13317 /// Views into WebAssembly memory are only valid so long as the
13318 /// backing buffer isn't resized in JS. Once this function is called
13319 /// any future calls to `Box::new` (or malloc of any form) may cause
13320 /// the returned value here to be invalidated. Use with caution!
13321 ///
13322 /// Additionally the returned object can be safely mutated,
13323 /// the changes are guaranteed to be reflected in the input array.
13324 pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
13325 let slice = core::slice::from_raw_parts_mut(ptr, length);
13326 Self::view(slice)
13327 }
13328
13329 /// Copy the contents of this JS typed array into the destination
13330 /// Rust pointer.
13331 ///
13332 /// This function will efficiently copy the memory from a typed
13333 /// array into this Wasm module's own linear memory, initializing
13334 /// the memory destination provided.
13335 ///
13336 /// # Safety
13337 ///
13338 /// This function requires `dst` to point to a buffer
13339 /// large enough to fit this array's contents.
13340 pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
13341 let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
13342 self.copy_to(slice);
13343 }
13344
13345 /// Copy the contents of this JS typed array into the destination
13346 /// Rust slice.
13347 ///
13348 /// This function will efficiently copy the memory from a typed
13349 /// array into this Wasm module's own linear memory, initializing
13350 /// the memory destination provided.
13351 ///
13352 /// # Panics
13353 ///
13354 /// This function will panic if this typed array's length is
13355 /// different than the length of the provided `dst` array.
13356 pub fn copy_to(&self, dst: &mut [$ty]) {
13357 core::assert_eq!(self.length() as usize, dst.len());
13358 $name::copy_to_slice(dst, self);
13359 }
13360
13361 /// Copy the contents of this JS typed array into the destination
13362 /// Rust slice.
13363 ///
13364 /// This function will efficiently copy the memory from a typed
13365 /// array into this Wasm module's own linear memory, initializing
13366 /// the memory destination provided.
13367 ///
13368 /// # Panics
13369 ///
13370 /// This function will panic if this typed array's length is
13371 /// different than the length of the provided `dst` array.
13372 pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
13373 core::assert_eq!(self.length() as usize, dst.len());
13374 let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
13375 self.copy_to(dst);
13376 dst
13377 }
13378
13379 /// Copy the contents of the source Rust slice into this
13380 /// JS typed array.
13381 ///
13382 /// This function will efficiently copy the memory from within
13383 /// the Wasm module's own linear memory to this typed array.
13384 ///
13385 /// # Panics
13386 ///
13387 /// This function will panic if this typed array's length is
13388 /// different than the length of the provided `src` array.
13389 pub fn copy_from(&self, src: &[$ty]) {
13390 core::assert_eq!(self.length() as usize, src.len());
13391 self.copy_from_slice(src);
13392 }
13393
13394 /// Efficiently copies the contents of this JS typed array into a new Vec.
13395 pub fn to_vec(&self) -> Vec<$ty> {
13396 let len = self.length() as usize;
13397 let mut output = Vec::with_capacity(len);
13398 // Safety: the capacity has been set
13399 unsafe {
13400 self.raw_copy_to_ptr(output.as_mut_ptr());
13401 output.set_len(len);
13402 }
13403 output
13404 }
13405 }
13406
13407 impl<'a> From<&'a [$ty]> for $name {
13408 #[inline]
13409 fn from(slice: &'a [$ty]) -> $name {
13410 // This is safe because the `new` function makes a copy if its argument is a TypedArray
13411 $name::new_from_slice(slice)
13412 }
13413 }
13414
13415 impl Default for $name {
13416 fn default() -> Self {
13417 Self::new(&JsValue::UNDEFINED.unchecked_into())
13418 }
13419 }
13420
13421 impl TypedArray for $name {}
13422
13423
13424 )*);
13425}
13426
13427arrays! {
13428 /// `Int8Array()`
13429 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
13430 Int8Array: i8,
13431
13432 /// `Int16Array()`
13433 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
13434 Int16Array: i16,
13435
13436 /// `Int32Array()`
13437 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
13438 Int32Array: i32,
13439
13440 /// `Uint8Array()`
13441 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
13442 Uint8Array: u8,
13443
13444 /// `Uint8ClampedArray()`
13445 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
13446 Uint8ClampedArray: u8,
13447
13448 /// `Uint16Array()`
13449 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
13450 Uint16Array: u16,
13451
13452 /// `Uint32Array()`
13453 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
13454 Uint32Array: u32,
13455
13456 /// `Float32Array()`
13457 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
13458 Float32Array: f32,
13459
13460 /// `Float64Array()`
13461 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
13462 Float64Array: f64,
13463
13464 /// `BigInt64Array()`
13465 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
13466 BigInt64Array: i64,
13467
13468 /// `BigUint64Array()`
13469 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
13470 BigUint64Array: u64,
13471}