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#![cfg_attr(target_feature = "atomics", feature(stdarch_wasm_atomic_wait))]
31#![cfg_attr(
32 all(target_feature = "atomics", target_arch = "wasm64"),
33 feature(simd_wasm64)
34)]
35
36extern crate alloc;
37
38use alloc::string::String;
39use alloc::vec::Vec;
40use core::cmp::Ordering;
41#[cfg(not(js_sys_unstable_apis))]
42use core::convert::Infallible;
43use core::convert::{self, TryFrom};
44use core::fmt;
45use core::iter::{self, Product, Sum};
46use core::marker::PhantomData;
47use core::mem::MaybeUninit;
48use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub};
49use core::str;
50use core::str::FromStr;
51pub use wasm_bindgen;
52use wasm_bindgen::closure::{ScopedClosure, WasmClosure};
53use wasm_bindgen::convert::{FromWasmAbi, IntoWasmAbi, Upcast, UpcastFrom};
54use wasm_bindgen::prelude::*;
55use wasm_bindgen::JsError;
56
57// Re-export sys types as js-sys types
58pub use wasm_bindgen::sys::{JsNullable, JsOption, Null, Promising, Undefined};
59pub use wasm_bindgen::{IntoJsGeneric, JsGeneric};
60
61// When adding new imports:
62//
63// * Keep imports in alphabetical order.
64//
65// * Rename imports with `js_name = ...` according to the note about `camelCase`
66// and `snake_case` in the module's documentation above.
67//
68// * Include the one sentence summary of the import from the MDN link in the
69// module's documentation above, and the MDN link itself.
70//
71// * If a function or method can throw an exception, make it catchable by adding
72// `#[wasm_bindgen(catch)]`.
73//
74// * Add a new `#[test]` into the appropriate file in the
75// `crates/js-sys/tests/wasm/` directory. If the imported function or method
76// can throw an exception, make sure to also add test coverage for that case.
77//
78// * Arguments that are `JsValue`s or imported JavaScript types should be taken
79// by reference.
80//
81// * Name JavaScript's `toString()` method as `to_js_string()` to avoid conflict
82// with Rust's `ToString` trait.
83
84macro_rules! forward_deref_unop {
85 (impl $imp:ident, $method:ident for $t:ty) => {
86 impl $imp for $t {
87 type Output = <&'static $t as $imp>::Output;
88
89 #[inline]
90 fn $method(self) -> Self::Output {
91 $imp::$method(&self)
92 }
93 }
94 };
95 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
96 impl<$($gen),+> $imp for $t {
97 type Output = <&'static $t as $imp>::Output;
98
99 #[inline]
100 fn $method(self) -> Self::Output {
101 $imp::$method(&self)
102 }
103 }
104 };
105}
106
107macro_rules! forward_deref_binop {
108 (impl $imp:ident, $method:ident for $t:ty) => {
109 impl<'a> $imp<$t> for &'a $t {
110 type Output = <&'static $t as $imp<&'static $t>>::Output;
111
112 #[inline]
113 fn $method(self, other: $t) -> Self::Output {
114 $imp::$method(self, &other)
115 }
116 }
117
118 impl $imp<&$t> for $t {
119 type Output = <&'static $t as $imp<&'static $t>>::Output;
120
121 #[inline]
122 fn $method(self, other: &$t) -> Self::Output {
123 $imp::$method(&self, other)
124 }
125 }
126
127 impl $imp<$t> for $t {
128 type Output = <&'static $t as $imp<&'static $t>>::Output;
129
130 #[inline]
131 fn $method(self, other: $t) -> Self::Output {
132 $imp::$method(&self, &other)
133 }
134 }
135 };
136 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
137 impl<'a, $($gen),+> $imp<$t> for &'a $t {
138 type Output = <&'static $t as $imp<&'static $t>>::Output;
139
140 #[inline]
141 fn $method(self, other: $t) -> Self::Output {
142 $imp::$method(self, &other)
143 }
144 }
145
146 impl<$($gen),+> $imp<&$t> for $t {
147 type Output = <&'static $t as $imp<&'static $t>>::Output;
148
149 #[inline]
150 fn $method(self, other: &$t) -> Self::Output {
151 $imp::$method(&self, other)
152 }
153 }
154
155 impl<$($gen),+> $imp<$t> for $t {
156 type Output = <&'static $t as $imp<&'static $t>>::Output;
157
158 #[inline]
159 fn $method(self, other: $t) -> Self::Output {
160 $imp::$method(&self, &other)
161 }
162 }
163 };
164}
165
166macro_rules! forward_js_unop {
167 (impl $imp:ident, $method:ident for $t:ty) => {
168 impl $imp for &$t {
169 type Output = $t;
170
171 #[inline]
172 fn $method(self) -> Self::Output {
173 $imp::$method(JsValue::as_ref(self)).unchecked_into()
174 }
175 }
176
177 forward_deref_unop!(impl $imp, $method for $t);
178 };
179 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
180 impl<$($gen),+> $imp for &$t {
181 type Output = $t;
182
183 #[inline]
184 fn $method(self) -> Self::Output {
185 $imp::$method(JsValue::as_ref(self)).unchecked_into()
186 }
187 }
188
189 forward_deref_unop!(impl<$($gen),+> $imp, $method for $t);
190 };
191}
192
193macro_rules! forward_js_binop {
194 (impl $imp:ident, $method:ident for $t:ty) => {
195 impl $imp<&$t> for &$t {
196 type Output = $t;
197
198 #[inline]
199 fn $method(self, other: &$t) -> Self::Output {
200 $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
201 }
202 }
203
204 forward_deref_binop!(impl $imp, $method for $t);
205 };
206 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
207 impl<$($gen),+> $imp<&$t> for &$t {
208 type Output = $t;
209
210 #[inline]
211 fn $method(self, other: &$t) -> Self::Output {
212 $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
213 }
214 }
215
216 forward_deref_binop!(impl<$($gen),+> $imp, $method for $t);
217 };
218}
219
220macro_rules! sum_product {
221 ($($a:ident)*) => ($(
222 impl Sum for $a {
223 #[inline]
224 fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
225 iter.fold(
226 $a::from(0),
227 |a, b| a + b,
228 )
229 }
230 }
231
232 impl Product for $a {
233 #[inline]
234 fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
235 iter.fold(
236 $a::from(1),
237 |a, b| a * b,
238 )
239 }
240 }
241
242 impl<'a> Sum<&'a $a> for $a {
243 fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
244 iter.fold(
245 $a::from(0),
246 |a, b| a + b,
247 )
248 }
249 }
250
251 impl<'a> Product<&'a $a> for $a {
252 #[inline]
253 fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
254 iter.fold(
255 $a::from(1),
256 |a, b| a * b,
257 )
258 }
259 }
260 )*);
261 // Generic variant: impl<T> for Type<T>
262 (impl<$gen:ident> $a:ident<$g2:ident>) => {
263 impl<$gen> Sum for $a<$g2>
264 where
265 $a<$g2>: From<$gen>,
266 $g2: From<u32>
267 {
268 #[inline]
269 fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
270 iter.fold(
271 $a::from($g2::from(0)),
272 |a, b| a + b,
273 )
274 }
275 }
276
277 impl<$gen> Product for $a<$g2>
278 where
279 $a<$g2>: From<$gen>,
280 $g2: From<u32>
281 {
282 #[inline]
283 fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
284 iter.fold(
285 $a::from($g2::from(1)),
286 |a, b| a * b,
287 )
288 }
289 }
290
291 impl<'a, $gen> Sum<&'a $a<$g2>> for $a<$g2>
292 where
293 $a<$g2>: From<$gen>,
294 $g2: From<u32>
295 {
296 fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
297 iter.fold(
298 $a::from($g2::from(0)),
299 |a, b| a + b,
300 )
301 }
302 }
303
304 impl<'a, $gen> Product<&'a $a<$g2>> for $a<$g2>
305 where
306 $a<$g2>: From<$gen>,
307 $g2: From<u32>
308 {
309 #[inline]
310 fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
311 iter.fold(
312 $a::from($g2::from(1)),
313 |a, b| a * b,
314 )
315 }
316 }
317 };
318}
319
320macro_rules! partialord_ord {
321 ($t:ident) => {
322 impl PartialOrd for $t {
323 #[inline]
324 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
325 Some(self.cmp(other))
326 }
327
328 #[inline]
329 fn lt(&self, other: &Self) -> bool {
330 JsValue::as_ref(self).lt(JsValue::as_ref(other))
331 }
332
333 #[inline]
334 fn le(&self, other: &Self) -> bool {
335 JsValue::as_ref(self).le(JsValue::as_ref(other))
336 }
337
338 #[inline]
339 fn ge(&self, other: &Self) -> bool {
340 JsValue::as_ref(self).ge(JsValue::as_ref(other))
341 }
342
343 #[inline]
344 fn gt(&self, other: &Self) -> bool {
345 JsValue::as_ref(self).gt(JsValue::as_ref(other))
346 }
347 }
348
349 impl Ord for $t {
350 #[inline]
351 fn cmp(&self, other: &Self) -> Ordering {
352 if self == other {
353 Ordering::Equal
354 } else if self.lt(other) {
355 Ordering::Less
356 } else {
357 Ordering::Greater
358 }
359 }
360 }
361 };
362}
363
364#[wasm_bindgen]
365extern "C" {
366 /// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
367 /// previously created by `encodeURI` or by a similar routine.
368 ///
369 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI)
370 #[wasm_bindgen(catch, js_name = decodeURI)]
371 pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
372
373 /// The `decodeURIComponent()` function decodes a Uniform Resource Identifier (URI) component
374 /// previously created by `encodeURIComponent` or by a similar routine.
375 ///
376 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
377 #[wasm_bindgen(catch, js_name = decodeURIComponent)]
378 pub fn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>;
379
380 /// The `encodeURI()` function encodes a Uniform Resource Identifier (URI)
381 /// by replacing each instance of certain characters by one, two, three, or
382 /// four escape sequences representing the UTF-8 encoding of the character
383 /// (will only be four escape sequences for characters composed of two
384 /// "surrogate" characters).
385 ///
386 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
387 #[wasm_bindgen(js_name = encodeURI)]
388 pub fn encode_uri(decoded: &str) -> JsString;
389
390 /// The `encodeURIComponent()` function encodes a Uniform Resource Identifier (URI) component
391 /// by replacing each instance of certain characters by one, two, three, or four escape sequences
392 /// representing the UTF-8 encoding of the character
393 /// (will only be four escape sequences for characters composed of two "surrogate" characters).
394 ///
395 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
396 #[wasm_bindgen(js_name = encodeURIComponent)]
397 pub fn encode_uri_component(decoded: &str) -> JsString;
398
399 /// The `eval()` function evaluates JavaScript code represented as a string.
400 ///
401 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)
402 #[cfg(feature = "unsafe-eval")]
403 #[wasm_bindgen(catch)]
404 pub fn eval(js_source_text: &str) -> Result<JsValue, JsValue>;
405
406 /// The global `isFinite()` function determines whether the passed value is a finite number.
407 /// If needed, the parameter is first converted to a number.
408 ///
409 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
410 #[wasm_bindgen(js_name = isFinite)]
411 pub fn is_finite(value: &JsValue) -> bool;
412
413 /// The `parseInt()` function parses a string argument and returns an integer
414 /// of the specified radix (the base in mathematical numeral systems), or NaN on error.
415 ///
416 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
417 #[wasm_bindgen(js_name = parseInt)]
418 pub fn parse_int(text: &str, radix: u8) -> f64;
419
420 /// The `parseFloat()` function parses an argument and returns a floating point number,
421 /// or NaN on error.
422 ///
423 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
424 #[wasm_bindgen(js_name = parseFloat)]
425 pub fn parse_float(text: &str) -> f64;
426
427 /// The `escape()` function computes a new string in which certain characters have been
428 /// replaced by a hexadecimal escape sequence.
429 ///
430 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape)
431 #[wasm_bindgen]
432 pub fn escape(string: &str) -> JsString;
433
434 /// The `unescape()` function computes a new string in which hexadecimal escape
435 /// sequences are replaced with the character that it represents. The escape sequences might
436 /// be introduced by a function like `escape`. Usually, `decodeURI` or `decodeURIComponent`
437 /// are preferred over `unescape`.
438 ///
439 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape)
440 #[wasm_bindgen]
441 pub fn unescape(string: &str) -> JsString;
442}
443
444// AggregateError
445#[wasm_bindgen]
446extern "C" {
447 /// The `AggregateError` object represents an error when several errors need
448 /// to be wrapped in a single error. It is thrown when multiple errors need
449 /// to be reported by an operation, for example by [`Promise::any`], when
450 /// all promises passed to it reject.
451 ///
452 /// `AggregateError` is a subclass of [`Error`].
453 ///
454 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError)
455 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "AggregateError")]
456 #[derive(Clone, Debug, PartialEq, Eq)]
457 pub type AggregateError;
458
459 /// Creates a new `AggregateError` from the given iterable of errors.
460 ///
461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError/AggregateError)
462 #[wasm_bindgen(constructor)]
463 pub fn new(errors: &[JsValue]) -> AggregateError;
464
465 /// Creates a new `AggregateError` from the given iterable of errors with a
466 /// human-readable description of the aggregate error.
467 ///
468 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError/AggregateError)
469 #[wasm_bindgen(constructor)]
470 pub fn new_with_message(errors: &[JsValue], message: &str) -> AggregateError;
471
472 /// Creates a new `AggregateError` from the given iterable of errors, a
473 /// human-readable description of the aggregate error, and an
474 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
475 /// original cause of the error.
476 ///
477 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError/AggregateError)
478 #[wasm_bindgen(constructor)]
479 pub fn new_with_options(
480 errors: &[JsValue],
481 message: &str,
482 options: &ErrorOptions,
483 ) -> AggregateError;
484
485 /// The `errors` property of an `AggregateError` instance is an array
486 /// representing the errors that were aggregated.
487 ///
488 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError/errors)
489 #[wasm_bindgen(method, getter)]
490 pub fn errors(this: &AggregateError) -> Array;
491}
492
493// ErrorOptions
494#[wasm_bindgen]
495extern "C" {
496 /// The options dictionary accepted as the second argument to the
497 /// [`Error`] constructor (and other built-in error constructors such as
498 /// [`AggregateError`]). Its sole standard property is `cause`, which
499 /// indicates the original cause of the error.
500 ///
501 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
502 #[wasm_bindgen(extends = Object, typescript_type = "ErrorOptions")]
503 #[derive(Clone, Debug, PartialEq, Eq)]
504 pub type ErrorOptions;
505
506 /// The `cause` property indicates the underlying cause of an error.
507 ///
508 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause)
509 #[wasm_bindgen(method, getter = "cause")]
510 pub fn get_cause(this: &ErrorOptions) -> JsValue;
511
512 /// Sets the `cause` property of this `ErrorOptions` dictionary.
513 ///
514 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause)
515 #[wasm_bindgen(method, setter = "cause")]
516 pub fn set_cause(this: &ErrorOptions, cause: &JsValue);
517}
518
519impl ErrorOptions {
520 /// Construct a new `ErrorOptions` dictionary with the given `cause`.
521 pub fn new(cause: &JsValue) -> Self {
522 let ret: Self = ::wasm_bindgen::JsCast::unchecked_into(Object::new());
523 ret.set_cause(cause);
524 ret
525 }
526}
527
528// Array
529#[wasm_bindgen]
530extern "C" {
531 #[wasm_bindgen(extends = Object, is_type_of = Array::is_array, typescript_type = "Array<any>")]
532 #[derive(Clone, Debug, PartialEq, Eq)]
533 pub type Array<T = JsValue>;
534
535 /// Creates a new empty array.
536 ///
537 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
538 #[cfg(not(js_sys_unstable_apis))]
539 #[wasm_bindgen(constructor)]
540 pub fn new() -> Array;
541
542 /// Creates a new empty array.
543 ///
544 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
545 #[cfg(js_sys_unstable_apis)]
546 #[wasm_bindgen(constructor)]
547 pub fn new<T>() -> Array<T>;
548
549 // Next major: deprecate
550 /// Creates a new empty array.
551 ///
552 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
553 #[wasm_bindgen(constructor)]
554 pub fn new_typed<T>() -> Array<T>;
555
556 /// Creates a new array with the specified length (elements are initialized to `undefined`).
557 ///
558 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
559 #[cfg(not(js_sys_unstable_apis))]
560 #[wasm_bindgen(constructor)]
561 pub fn new_with_length(len: u32) -> Array;
562
563 /// Creates a new array with the specified length (elements are initialized to `undefined`).
564 ///
565 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
566 #[cfg(js_sys_unstable_apis)]
567 #[wasm_bindgen(constructor)]
568 pub fn new_with_length<T>(len: u32) -> Array<T>;
569
570 // Next major: deprecate
571 /// Creates a new array with the specified length (elements are initialized to `undefined`).
572 ///
573 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
574 #[wasm_bindgen(constructor)]
575 pub fn new_with_length_typed<T>(len: u32) -> Array<T>;
576
577 /// Retrieves the element at the index, counting from the end if negative
578 /// (returns `undefined` if the index is out of range).
579 ///
580 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
581 #[cfg(not(js_sys_unstable_apis))]
582 #[wasm_bindgen(method)]
583 pub fn at<T>(this: &Array<T>, index: i32) -> T;
584
585 /// Retrieves the element at the index, counting from the end if negative
586 /// (returns `None` if the index is out of range).
587 ///
588 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
589 #[cfg(js_sys_unstable_apis)]
590 #[wasm_bindgen(method)]
591 pub fn at<T>(this: &Array<T>, index: i32) -> Option<T>;
592
593 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
594 ///
595 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
596 #[cfg(not(js_sys_unstable_apis))]
597 #[wasm_bindgen(method, indexing_getter)]
598 pub fn get<T>(this: &Array<T>, index: u32) -> T;
599
600 /// Retrieves the element at the index (returns `None` if the index is out of range).
601 ///
602 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
603 #[cfg(js_sys_unstable_apis)]
604 #[wasm_bindgen(method, indexing_getter)]
605 pub fn get<T>(this: &Array<T>, index: u32) -> Option<T>;
606
607 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
608 ///
609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
610 #[wasm_bindgen(method, indexing_getter)]
611 pub fn get_unchecked<T>(this: &Array<T>, index: u32) -> T;
612
613 // Next major: deprecate
614 /// Retrieves the element at the index (returns `None` if the index is out of range,
615 /// or if the element is explicitly `undefined`).
616 #[wasm_bindgen(method, indexing_getter)]
617 pub fn get_checked<T>(this: &Array<T>, index: u32) -> Option<T>;
618
619 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
620 #[cfg(not(js_sys_unstable_apis))]
621 #[wasm_bindgen(method, indexing_setter)]
622 pub fn set<T>(this: &Array<T>, index: u32, value: T);
623
624 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
625 #[cfg(js_sys_unstable_apis)]
626 #[wasm_bindgen(method, indexing_setter)]
627 pub fn set<T>(this: &Array<T>, index: u32, value: &T);
628
629 // Next major: deprecate
630 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
631 #[wasm_bindgen(method, indexing_setter)]
632 pub fn set_ref<T>(this: &Array<T>, index: u32, value: &T);
633
634 /// Deletes the element at the index (does nothing if the index is out of range).
635 ///
636 /// The element at the index is set to `undefined`.
637 ///
638 /// This does not resize the array, the array will still be the same length.
639 #[wasm_bindgen(method, indexing_deleter)]
640 pub fn delete<T>(this: &Array<T>, index: u32);
641
642 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
643 /// from an array-like or iterable object.
644 ///
645 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
646 #[cfg(not(js_sys_unstable_apis))]
647 #[wasm_bindgen(static_method_of = Array)]
648 pub fn from(val: &JsValue) -> Array;
649
650 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
651 /// from an array-like or iterable object.
652 ///
653 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
654 #[cfg(js_sys_unstable_apis)]
655 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
656 pub fn from<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
657
658 // Next major: deprecate
659 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
660 /// from an array-like or iterable object.
661 ///
662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
663 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
664 pub fn from_iterable<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
665
666 /// The `Array.from()` static method with a map function creates a new, shallow-copied
667 /// `Array` instance from an array-like or iterable object, applying the map function
668 /// to each value.
669 ///
670 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
671 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
672 pub fn from_iterable_map<I: Iterable, U>(
673 val: &I,
674 map: &mut dyn FnMut(I::Item, u32) -> Result<U, JsError>,
675 ) -> Result<Array<U>, JsValue>;
676
677 /// The `Array.fromAsync()` static method creates a new, shallow-copied `Array` instance
678 /// from an async iterable, iterable or array-like object.
679 ///
680 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
681 #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
682 pub fn from_async<I: AsyncIterable>(val: &I) -> Result<Promise<Array<I::Item>>, JsValue>;
683
684 /// The `Array.fromAsync()` static method with a map function creates a new, shallow-copied
685 /// `Array` instance from an async iterable, iterable or array-like object, applying the map
686 /// function to each value.
687 ///
688 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
689 #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
690 pub fn from_async_map<'a, I: AsyncIterable, R: Promising>(
691 val: &I,
692 map: &ScopedClosure<'a, dyn FnMut(I::Item, u32) -> Result<R, JsError>>,
693 ) -> Result<Promise<Array<R::Resolution>>, JsValue>;
694
695 /// The `copyWithin()` method shallow copies part of an array to another
696 /// location in the same array and returns it, without modifying its size.
697 ///
698 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)
699 #[wasm_bindgen(method, js_name = copyWithin)]
700 pub fn copy_within<T>(this: &Array<T>, target: i32, start: i32, end: i32) -> Array<T>;
701
702 /// The `concat()` method is used to merge two or more arrays. This method
703 /// does not change the existing arrays, but instead returns a new array.
704 ///
705 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
706 #[wasm_bindgen(method)]
707 pub fn concat<T, U: Upcast<T>>(this: &Array<T>, array: &Array<U>) -> Array<T>;
708
709 /// The `concat()` method is used to merge two or more arrays. This method
710 /// does not change the existing arrays, but instead returns a new array.
711 ///
712 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
713 #[wasm_bindgen(method)]
714 pub fn concat_many<T, U: Upcast<T>>(this: &Array<T>, array: &[Array<U>]) -> Array<T>;
715
716 /// The `every()` method tests whether all elements in the array pass the test
717 /// implemented by the provided function.
718 ///
719 /// **Note:** Consider using [`Array::try_every`] if the predicate might throw an error.
720 ///
721 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
722 #[wasm_bindgen(method)]
723 pub fn every<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> bool;
724
725 /// The `every()` method tests whether all elements in the array pass the test
726 /// implemented by the provided function. _(Fallible variation)_
727 ///
728 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
729 #[wasm_bindgen(method, js_name = every, catch)]
730 pub fn try_every<T>(
731 this: &Array<T>,
732 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
733 ) -> Result<bool, JsValue>;
734
735 /// The `fill()` method fills all the elements of an array from a start index
736 /// to an end index with a static value. The end index is not included.
737 ///
738 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
739 #[wasm_bindgen(method)]
740 pub fn fill<T>(this: &Array<T>, value: &T, start: u32, end: u32) -> Array<T>;
741
742 /// The `filter()` method creates a new array with all elements that pass the
743 /// test implemented by the provided function.
744 ///
745 /// **Note:** Consider using [`Array::try_filter`] if the predicate might throw an error.
746 ///
747 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
748 #[wasm_bindgen(method)]
749 pub fn filter<T>(
750 this: &Array<T>,
751 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
752 ) -> Array<T>;
753
754 /// The `filter()` method creates a new array with all elements that pass the
755 /// test implemented by the provided function. _(Fallible variation)_
756 ///
757 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
758 #[wasm_bindgen(method, js_name = filter, catch)]
759 pub fn try_filter<T>(
760 this: &Array<T>,
761 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
762 ) -> Result<Array<T>, JsValue>;
763
764 /// The `find()` method returns the value of the first element in the array that satisfies
765 /// the provided testing function. Otherwise `undefined` is returned.
766 ///
767 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
768 #[cfg(not(js_sys_unstable_apis))]
769 #[wasm_bindgen(method)]
770 pub fn find<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
771
772 /// The `find()` method returns the value of the first element in the array that satisfies
773 /// the provided testing function. Returns `None` if no element matches.
774 ///
775 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
776 #[cfg(js_sys_unstable_apis)]
777 #[wasm_bindgen(method)]
778 pub fn find<T>(
779 this: &Array<T>,
780 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
781 ) -> Option<T>;
782
783 /// The `find()` method returns the value of the first element in the array that satisfies
784 /// the provided testing function. Otherwise `undefined` is returned. _(Fallible variation)_
785 ///
786 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
787 #[wasm_bindgen(method, js_name = find, catch)]
788 pub fn try_find<T>(
789 this: &Array<T>,
790 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
791 ) -> Result<Option<T>, JsValue>;
792
793 /// The `findIndex()` method returns the index of the first element in the array that
794 /// satisfies the provided testing function. Otherwise -1 is returned.
795 ///
796 /// **Note:** Consider using [`Array::try_find_index`] if the predicate might throw an error.
797 ///
798 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
799 #[wasm_bindgen(method, js_name = findIndex)]
800 pub fn find_index<T>(
801 this: &Array<T>,
802 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
803 ) -> i32;
804
805 /// The `findIndex()` method returns the index of the first element in the array that
806 /// satisfies the provided testing function. Otherwise -1 is returned. _(Fallible variation)_
807 ///
808 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
809 #[wasm_bindgen(method, js_name = findIndex, catch)]
810 pub fn try_find_index<T>(
811 this: &Array<T>,
812 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
813 ) -> Result<i32, JsValue>;
814
815 /// The `findLast()` method of Array instances iterates the array in reverse order
816 /// and returns the value of the first element that satisfies the provided testing function.
817 /// If no elements satisfy the testing function, undefined is returned.
818 ///
819 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
820 #[cfg(not(js_sys_unstable_apis))]
821 #[wasm_bindgen(method, js_name = findLast)]
822 pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
823
824 /// The `findLast()` method of Array instances iterates the array in reverse order
825 /// and returns the value of the first element that satisfies the provided testing function.
826 /// Returns `None` if no element matches.
827 ///
828 /// **Note:** Consider using [`Array::try_find_last`] if the predicate might throw an error.
829 ///
830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
831 #[cfg(js_sys_unstable_apis)]
832 #[wasm_bindgen(method, js_name = findLast)]
833 pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32) -> bool) -> Option<T>;
834
835 /// The `findLast()` method of Array instances iterates the array in reverse order
836 /// and returns the value of the first element that satisfies the provided testing function.
837 /// If no elements satisfy the testing function, undefined is returned. _(Fallible variation)_
838 ///
839 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
840 #[wasm_bindgen(method, js_name = findLast, catch)]
841 pub fn try_find_last<T>(
842 this: &Array<T>,
843 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
844 ) -> Result<Option<T>, JsValue>;
845
846 /// The `findLastIndex()` method of Array instances iterates the array in reverse order
847 /// and returns the index of the first element that satisfies the provided testing function.
848 /// If no elements satisfy the testing function, -1 is returned.
849 ///
850 /// **Note:** Consider using [`Array::try_find_last_index`] if the predicate might throw an error.
851 ///
852 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
853 #[wasm_bindgen(method, js_name = findLastIndex)]
854 pub fn find_last_index<T>(
855 this: &Array<T>,
856 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
857 ) -> i32;
858
859 /// The `findLastIndex()` method of Array instances iterates the array in reverse order
860 /// and returns the index of the first element that satisfies the provided testing function.
861 /// If no elements satisfy the testing function, -1 is returned. _(Fallible variation)_
862 ///
863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
864 #[wasm_bindgen(method, js_name = findLastIndex, catch)]
865 pub fn try_find_last_index<T>(
866 this: &Array<T>,
867 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
868 ) -> Result<i32, JsValue>;
869
870 /// The `flat()` method creates a new array with all sub-array elements concatenated into it
871 /// recursively up to the specified depth.
872 ///
873 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
874 #[wasm_bindgen(method)]
875 pub fn flat<T>(this: &Array<T>, depth: i32) -> Array<JsValue>;
876
877 /// The `flatMap()` method first maps each element using a mapping function, then flattens
878 /// the result into a new array.
879 ///
880 /// **Note:** Consider using [`Array::try_flat_map`] for safer fallible handling.
881 ///
882 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
883 #[wasm_bindgen(method, js_name = flatMap)]
884 pub fn flat_map<T, U>(
885 this: &Array<T>,
886 callback: &mut dyn FnMut(T, u32, Array<T>) -> Vec<U>,
887 ) -> Array<U>;
888
889 /// The `flatMap()` method first maps each element using a mapping function, then flattens
890 /// the result into a new array.
891 ///
892 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
893 #[wasm_bindgen(method, js_name = flatMap, catch)]
894 pub fn try_flat_map<T, U>(
895 this: &Array<T>,
896 callback: &mut dyn FnMut(T, u32) -> Vec<U>,
897 ) -> Result<Array<U>, JsValue>;
898
899 /// The `forEach()` method executes a provided function once for each array element.
900 ///
901 /// **Note:** Consider using [`Array::try_for_each`] if the callback might throw an error.
902 ///
903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
904 #[wasm_bindgen(method, js_name = forEach)]
905 pub fn for_each<T: JsGeneric>(this: &Array<T>, callback: &mut dyn FnMut(T, u32, Array<T>));
906
907 /// The `forEach()` method executes a provided function once for each array element. _(Fallible variation)_
908 ///
909 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
910 #[wasm_bindgen(method, js_name = forEach, catch)]
911 pub fn try_for_each<T>(
912 this: &Array<T>,
913 callback: &mut dyn FnMut(T, u32) -> Result<(), JsError>,
914 ) -> Result<(), JsValue>;
915
916 /// The `includes()` method determines whether an array includes a certain
917 /// element, returning true or false as appropriate.
918 ///
919 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
920 #[wasm_bindgen(method)]
921 pub fn includes<T>(this: &Array<T>, value: &T, from_index: i32) -> bool;
922
923 /// The `indexOf()` method returns the first index at which a given element
924 /// can be found in the array, or -1 if it is not present.
925 ///
926 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
927 #[wasm_bindgen(method, js_name = indexOf)]
928 pub fn index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
929
930 /// The `Array.isArray()` method determines whether the passed value is an Array.
931 ///
932 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)
933 #[wasm_bindgen(static_method_of = Array, js_name = isArray)]
934 pub fn is_array(value: &JsValue) -> bool;
935
936 /// The `join()` method joins all elements of an array (or an array-like object)
937 /// into a string and returns this string.
938 ///
939 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
940 #[wasm_bindgen(method)]
941 pub fn join<T>(this: &Array<T>, delimiter: &str) -> JsString;
942
943 /// The `lastIndexOf()` method returns the last index at which a given element
944 /// can be found in the array, or -1 if it is not present. The array is
945 /// searched backwards, starting at fromIndex.
946 ///
947 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
948 #[wasm_bindgen(method, js_name = lastIndexOf)]
949 pub fn last_index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
950
951 /// The length property of an object which is an instance of type Array
952 /// sets or returns the number of elements in that array. The value is an
953 /// unsigned, 32-bit integer that is always numerically greater than the
954 /// highest index in the array.
955 ///
956 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
957 #[wasm_bindgen(method, getter)]
958 pub fn length<T>(this: &Array<T>) -> u32;
959
960 /// Sets the length of the array.
961 ///
962 /// If it is set to less than the current length of the array, it will
963 /// shrink the array.
964 ///
965 /// If it is set to more than the current length of the array, it will
966 /// increase the length of the array, filling the new space with empty
967 /// slots.
968 ///
969 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
970 #[wasm_bindgen(method, setter)]
971 pub fn set_length<T>(this: &Array<T>, value: u32);
972
973 /// `map()` calls a provided callback function once for each element in an array,
974 /// in order, and constructs a new array from the results. callback is invoked
975 /// only for indexes of the array which have assigned values, including undefined.
976 /// It is not called for missing elements of the array (that is, indexes that have
977 /// never been set, which have been deleted or which have never been assigned a value).
978 ///
979 /// **Note:** Consider using [`Array::try_map`] for safer fallible handling.
980 ///
981 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
982 #[wasm_bindgen(method)]
983 pub fn map<T, U>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> U)
984 -> Array<U>;
985
986 /// `map()` calls a provided callback function once for each element in an array,
987 /// in order, and constructs a new array from the results. callback is invoked
988 /// only for indexes of the array which have assigned values, including undefined.
989 /// It is not called for missing elements of the array (that is, indexes that have
990 /// never been set, which have been deleted or which have never been assigned a value).
991 /// _(Fallible variation)_
992 ///
993 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
994 #[wasm_bindgen(method, js_name = map, catch)]
995 pub fn try_map<T, U>(
996 this: &Array<T>,
997 predicate: &mut dyn FnMut(T, u32) -> Result<U, JsError>,
998 ) -> Result<Array<U>, JsValue>;
999
1000 /// The `Array.of()` method creates a new Array instance with a variable
1001 /// number of arguments, regardless of number or type of the arguments.
1002 ///
1003 /// Note: For type inference use `Array::<T>::of(&[T])`.
1004 ///
1005 /// The difference between `Array.of()` and the `Array` constructor is in the
1006 /// handling of integer arguments: `Array.of(7)` creates an array with a single
1007 /// element, `7`, whereas `Array(7)` creates an empty array with a `length`
1008 /// property of `7` (Note: this implies an array of 7 empty slots, not slots
1009 /// with actual undefined values).
1010 ///
1011 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1012 #[wasm_bindgen(static_method_of = Array, js_name = of, variadic)]
1013 pub fn of<T>(values: &[T]) -> Array<T>;
1014
1015 // Next major: deprecate these
1016 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1017 #[wasm_bindgen(static_method_of = Array, js_name = of)]
1018 pub fn of1(a: &JsValue) -> Array;
1019
1020 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1021 #[wasm_bindgen(static_method_of = Array, js_name = of)]
1022 pub fn of2(a: &JsValue, b: &JsValue) -> Array;
1023
1024 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1025 #[wasm_bindgen(static_method_of = Array, js_name = of)]
1026 pub fn of3(a: &JsValue, b: &JsValue, c: &JsValue) -> Array;
1027
1028 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1029 #[wasm_bindgen(static_method_of = Array, js_name = of)]
1030 pub fn of4(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue) -> Array;
1031
1032 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1033 #[wasm_bindgen(static_method_of = Array, js_name = of)]
1034 pub fn of5(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue, e: &JsValue) -> Array;
1035
1036 /// The `pop()` method removes the last element from an array and returns that
1037 /// element. This method changes the length of the array.
1038 ///
1039 /// **Note:** Consider using [`Array::pop_checked`] for handling empty arrays.
1040 ///
1041 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
1042 #[cfg(not(js_sys_unstable_apis))]
1043 #[wasm_bindgen(method)]
1044 pub fn pop<T>(this: &Array<T>) -> T;
1045
1046 /// The `pop()` method removes the last element from an array and returns that
1047 /// element. This method changes the length of the array.
1048 /// Returns `None` if the array is empty.
1049 ///
1050 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
1051 #[cfg(js_sys_unstable_apis)]
1052 #[wasm_bindgen(method)]
1053 pub fn pop<T>(this: &Array<T>) -> Option<T>;
1054
1055 // Next major: deprecate
1056 /// The `pop()` method removes the last element from an array and returns that
1057 /// element. This method changes the length of the array.
1058 ///
1059 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
1060 #[wasm_bindgen(method, js_name = pop)]
1061 pub fn pop_checked<T>(this: &Array<T>) -> Option<T>;
1062
1063 /// The `push()` method adds one element to the end of an array and
1064 /// returns the new length of the array.
1065 ///
1066 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
1067 #[wasm_bindgen(method)]
1068 pub fn push<T>(this: &Array<T>, value: &T) -> u32;
1069
1070 /// The `push()` method adds one or more elements to the end of an array and
1071 /// returns the new length of the array.
1072 ///
1073 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
1074 #[wasm_bindgen(method, js_name = push, variadic)]
1075 pub fn push_many<T>(this: &Array<T>, values: &[T]) -> u32;
1076
1077 /// The `reduce()` method applies a function against an accumulator and each element in
1078 /// the array (from left to right) to reduce it to a single value.
1079 ///
1080 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1081 #[cfg(not(js_sys_unstable_apis))]
1082 #[wasm_bindgen(method)]
1083 pub fn reduce<T>(
1084 this: &Array<T>,
1085 predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
1086 initial_value: &JsValue,
1087 ) -> JsValue;
1088
1089 /// The `reduce()` method applies a function against an accumulator and each element in
1090 /// the array (from left to right) to reduce it to a single value.
1091 ///
1092 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1093 #[cfg(js_sys_unstable_apis)]
1094 #[wasm_bindgen(method)]
1095 pub fn reduce<T, A>(
1096 this: &Array<T>,
1097 predicate: &mut dyn FnMut(A, T, u32, Array<T>) -> A,
1098 initial_value: &A,
1099 ) -> A;
1100
1101 /// The `reduce()` method applies a function against an accumulator and each element in
1102 /// the array (from left to right) to reduce it to a single value. _(Fallible variation)_
1103 ///
1104 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1105 #[wasm_bindgen(method, js_name = reduce, catch)]
1106 pub fn try_reduce<T, A>(
1107 this: &Array<T>,
1108 predicate: &mut dyn FnMut(A, T, u32) -> Result<A, JsError>,
1109 initial_value: &A,
1110 ) -> Result<A, JsValue>;
1111
1112 /// The `reduceRight()` method applies a function against an accumulator and each value
1113 /// of the array (from right-to-left) to reduce it to a single value.
1114 ///
1115 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1116 #[cfg(not(js_sys_unstable_apis))]
1117 #[wasm_bindgen(method, js_name = reduceRight)]
1118 pub fn reduce_right<T>(
1119 this: &Array<T>,
1120 predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
1121 initial_value: &JsValue,
1122 ) -> JsValue;
1123
1124 /// The `reduceRight()` method applies a function against an accumulator and each value
1125 /// of the array (from right-to-left) to reduce it to a single value.
1126 ///
1127 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1128 #[cfg(js_sys_unstable_apis)]
1129 #[wasm_bindgen(method, js_name = reduceRight)]
1130 pub fn reduce_right<T, A>(
1131 this: &Array<T>,
1132 predicate: &mut dyn FnMut(A, T, u32, Array<T>) -> A,
1133 initial_value: &A,
1134 ) -> A;
1135
1136 /// The `reduceRight()` method applies a function against an accumulator and each value
1137 /// of the array (from right-to-left) to reduce it to a single value. _(Fallible variation)_
1138 ///
1139 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1140 #[wasm_bindgen(method, js_name = reduceRight, catch)]
1141 pub fn try_reduce_right<T, A>(
1142 this: &Array<T>,
1143 predicate: &mut dyn FnMut(JsValue, T, u32) -> Result<A, JsError>,
1144 initial_value: &A,
1145 ) -> Result<A, JsValue>;
1146
1147 /// The `reverse()` method reverses an array in place. The first array
1148 /// element becomes the last, and the last array element becomes the first.
1149 ///
1150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
1151 #[wasm_bindgen(method)]
1152 pub fn reverse<T>(this: &Array<T>) -> Array<T>;
1153
1154 /// The `shift()` method removes the first element from an array and returns
1155 /// that removed element. This method changes the length of the array.
1156 ///
1157 /// **Note:** Consider using [`Array::shift_checked`] for handling empty arrays.
1158 ///
1159 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1160 #[cfg(not(js_sys_unstable_apis))]
1161 #[wasm_bindgen(method)]
1162 pub fn shift<T>(this: &Array<T>) -> T;
1163
1164 /// The `shift()` method removes the first element from an array and returns
1165 /// that removed element. This method changes the length of the array.
1166 /// Returns `None` if the array is empty.
1167 ///
1168 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1169 #[cfg(js_sys_unstable_apis)]
1170 #[wasm_bindgen(method)]
1171 pub fn shift<T>(this: &Array<T>) -> Option<T>;
1172
1173 // Next major: deprecate
1174 /// The `shift()` method removes the first element from an array and returns
1175 /// that removed element. This method changes the length of the array.
1176 ///
1177 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1178 #[wasm_bindgen(method, js_name = shift)]
1179 pub fn shift_checked<T>(this: &Array<T>) -> Option<T>;
1180
1181 /// The `slice()` method returns a shallow copy of a portion of an array into
1182 /// a new array object selected from begin to end (end not included).
1183 /// The original array will not be modified.
1184 ///
1185 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1186 #[cfg(not(js_sys_unstable_apis))]
1187 #[wasm_bindgen(method)]
1188 pub fn slice<T>(this: &Array<T>, start: u32, end: u32) -> Array<T>;
1189
1190 /// The `slice()` method returns a shallow copy of a portion of an array into
1191 /// a new array object selected from begin to end (end not included).
1192 /// The original array will not be modified. Negative indices count from the end.
1193 ///
1194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1195 #[cfg(js_sys_unstable_apis)]
1196 #[wasm_bindgen(method)]
1197 pub fn slice<T>(this: &Array<T>, start: i32, end: i32) -> Array<T>;
1198
1199 /// The `slice()` method returns a shallow copy of a portion of an array into
1200 /// a new array object selected from the given index to the end.
1201 /// The original array will not be modified.
1202 ///
1203 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1204 #[cfg(not(js_sys_unstable_apis))]
1205 #[wasm_bindgen(method, js_name = slice)]
1206 pub fn slice_from<T>(this: &Array<T>, start: u32) -> Array<T>;
1207
1208 /// The `slice()` method returns a shallow copy of a portion of an array into
1209 /// a new array object selected from the given index to the end.
1210 /// The original array will not be modified. Negative indices count from the end.
1211 ///
1212 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1213 #[cfg(js_sys_unstable_apis)]
1214 #[wasm_bindgen(method, js_name = slice)]
1215 pub fn slice_from<T>(this: &Array<T>, start: i32) -> Array<T>;
1216
1217 /// The `some()` method tests whether at least one element in the array passes the test implemented
1218 /// by the provided function.
1219 /// Note: This method returns false for any condition put on an empty array.
1220 ///
1221 /// **Note:** Consider using [`Array::try_some`] if the predicate might throw an error.
1222 ///
1223 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1224 #[wasm_bindgen(method)]
1225 pub fn some<T>(this: &Array<T>, predicate: &mut dyn FnMut(T) -> bool) -> bool;
1226
1227 /// The `some()` method tests whether at least one element in the array passes the test implemented
1228 /// by the provided function. _(Fallible variation)_
1229 /// Note: This method returns false for any condition put on an empty array.
1230 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1231 #[wasm_bindgen(method, js_name = some, catch)]
1232 pub fn try_some<T>(
1233 this: &Array<T>,
1234 predicate: &mut dyn FnMut(T) -> Result<bool, JsError>,
1235 ) -> Result<bool, JsValue>;
1236
1237 /// The `sort()` method sorts the elements of an array in place and returns
1238 /// the array. The sort is not necessarily stable. The default sort
1239 /// order is according to string Unicode code points.
1240 ///
1241 /// The time and space complexity of the sort cannot be guaranteed as it
1242 /// is implementation dependent.
1243 ///
1244 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1245 #[wasm_bindgen(method)]
1246 pub fn sort<T>(this: &Array<T>) -> Array<T>;
1247
1248 /// The `sort()` method with a custom compare function.
1249 ///
1250 /// **Note:** Consider using [`Array::try_sort_by`] if the predicate might throw an error.
1251 ///
1252 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1253 #[wasm_bindgen(method, js_name = sort)]
1254 pub fn sort_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1255
1256 /// The `sort()` method with a custom compare function. _(Fallible variation)_
1257 ///
1258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1259 #[wasm_bindgen(method, js_name = sort, catch)]
1260 pub fn try_sort_by<T>(
1261 this: &Array<T>,
1262 compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>,
1263 ) -> Result<Array<T>, JsValue>;
1264
1265 /// The `splice()` method changes the contents of an array by removing existing elements and/or
1266 /// adding new elements.
1267 ///
1268 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1269 #[wasm_bindgen(method)]
1270 pub fn splice<T>(this: &Array<T>, start: u32, delete_count: u32, item: &T) -> Array<T>;
1271
1272 /// The `splice()` method changes the contents of an array by removing existing elements and/or
1273 /// adding new elements.
1274 ///
1275 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1276 #[wasm_bindgen(method, js_name = splice, variadic)]
1277 pub fn splice_many<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1278
1279 /// The `toLocaleString()` method returns a string representing the elements of the array.
1280 /// The elements are converted to Strings using their toLocaleString methods and these
1281 /// Strings are separated by a locale-specific String (such as a comma ",").
1282 ///
1283 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1284 #[cfg(not(js_sys_unstable_apis))]
1285 #[wasm_bindgen(method, js_name = toLocaleString)]
1286 pub fn to_locale_string<T>(this: &Array<T>, locales: &JsValue, options: &JsValue) -> JsString;
1287
1288 /// The `toLocaleString()` method returns a string representing the elements of the array.
1289 /// The elements are converted to Strings using their toLocaleString methods and these
1290 /// Strings are separated by a locale-specific String (such as a comma ",").
1291 ///
1292 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1293 #[cfg(js_sys_unstable_apis)]
1294 #[wasm_bindgen(method, js_name = toLocaleString)]
1295 pub fn to_locale_string<T>(
1296 this: &Array<T>,
1297 locales: &[JsString],
1298 options: &Intl::NumberFormatOptions,
1299 ) -> JsString;
1300
1301 /// The `toReversed()` method returns a new array with the elements in reversed order,
1302 /// without modifying the original array.
1303 ///
1304 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed)
1305 #[wasm_bindgen(method, js_name = toReversed)]
1306 pub fn to_reversed<T>(this: &Array<T>) -> Array<T>;
1307
1308 /// The `toSorted()` method returns a new array with the elements sorted in ascending order,
1309 /// without modifying the original array.
1310 ///
1311 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1312 #[wasm_bindgen(method, js_name = toSorted)]
1313 pub fn to_sorted<T>(this: &Array<T>) -> Array<T>;
1314
1315 /// The `toSorted()` method with a custom compare function.
1316 ///
1317 /// **Note:** Consider using [`Array::try_to_sorted_by`] if the predicate might throw an error.
1318 ///
1319 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1320 #[wasm_bindgen(method, js_name = toSorted)]
1321 pub fn to_sorted_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1322
1323 /// The `toSorted()` method with a custom compare function. _(Fallible variation)_
1324 ///
1325 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1326 #[wasm_bindgen(method, js_name = toSorted, catch)]
1327 pub fn try_to_sorted_by<T>(
1328 this: &Array<T>,
1329 compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>,
1330 ) -> Result<Array<T>, JsValue>;
1331
1332 /// The `toSpliced()` method returns a new array with some elements removed and/or
1333 /// replaced at a given index, without modifying the original array.
1334 ///
1335 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced)
1336 #[wasm_bindgen(method, js_name = toSpliced, variadic)]
1337 pub fn to_spliced<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1338
1339 /// The `toString()` method returns a string representing the specified array
1340 /// and its elements.
1341 ///
1342 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)
1343 #[cfg(not(js_sys_unstable_apis))]
1344 #[wasm_bindgen(method, js_name = toString)]
1345 pub fn to_string<T>(this: &Array<T>) -> JsString;
1346
1347 /// Converts the Array into a Vector.
1348 #[wasm_bindgen(method, js_name = slice)]
1349 pub fn to_vec<T>(this: &Array<T>) -> Vec<T>;
1350
1351 /// The `unshift()` method adds one element to the beginning of an
1352 /// array and returns the new length of the array.
1353 ///
1354 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1355 #[wasm_bindgen(method)]
1356 pub fn unshift<T>(this: &Array<T>, value: &T) -> u32;
1357
1358 /// The `unshift()` method adds one or more elements to the beginning of an
1359 /// array and returns the new length of the array.
1360 ///
1361 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1362 #[wasm_bindgen(method, js_name = unshift, variadic)]
1363 pub fn unshift_many<T>(this: &Array<T>, values: &[T]) -> u32;
1364
1365 /// The `with()` method returns a new array with the element at the given index
1366 /// replaced with the given value, without modifying the original array.
1367 ///
1368 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/with)
1369 #[wasm_bindgen(method, js_name = with)]
1370 pub fn with<T>(this: &Array<T>, index: u32, value: &T) -> Array<T>;
1371}
1372
1373// Tuples as a typed array variant
1374#[wasm_bindgen]
1375extern "C" {
1376 #[wasm_bindgen(extends = Object, js_name = Array, is_type_of = Array::is_array, no_upcast, typescript_type = "Array<any>")]
1377 #[derive(Clone, Debug)]
1378 pub type ArrayTuple<T: JsTuple = (JsValue,)>;
1379
1380 /// Creates a new JS array typed as a 1-tuple.
1381 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1382 pub fn new1<T1>(t1: &T1) -> ArrayTuple<(T1,)>;
1383
1384 /// Creates a new JS array typed as a 2-tuple.
1385 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1386 pub fn new2<T1, T2>(t1: &T1, t2: &T2) -> ArrayTuple<(T1, T2)>;
1387
1388 /// Creates a new JS array typed as a 3-tuple.
1389 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1390 pub fn new3<T1, T2, T3>(t1: &T1, t2: &T2, t3: &T3) -> ArrayTuple<(T1, T2, T3)>;
1391
1392 /// Creates a new JS array typed as a 4-tuple.
1393 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1394 pub fn new4<T1, T2, T3, T4>(t1: &T1, t2: &T2, t3: &T3, t4: &T4)
1395 -> ArrayTuple<(T1, T2, T3, T4)>;
1396
1397 /// Creates a new JS array typed as a 5-tuple.
1398 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1399 pub fn new5<T1, T2, T3, T4, T5>(
1400 t1: &T1,
1401 t2: &T2,
1402 t3: &T3,
1403 t4: &T4,
1404 t5: &T5,
1405 ) -> ArrayTuple<(T1, T2, T3, T4, T5)>;
1406
1407 /// Creates a new JS array typed as a 6-tuple.
1408 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1409 pub fn new6<T1, T2, T3, T4, T5, T6>(
1410 t1: &T1,
1411 t2: &T2,
1412 t3: &T3,
1413 t4: &T4,
1414 t5: &T5,
1415 t6: &T6,
1416 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6)>;
1417
1418 /// Creates a new JS array typed as a 7-tuple.
1419 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1420 pub fn new7<T1, T2, T3, T4, T5, T6, T7>(
1421 t1: &T1,
1422 t2: &T2,
1423 t3: &T3,
1424 t4: &T4,
1425 t5: &T5,
1426 t6: &T6,
1427 t7: &T7,
1428 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7)>;
1429
1430 /// Creates a new JS array typed as a 8-tuple.
1431 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1432 pub fn new8<T1, T2, T3, T4, T5, T6, T7, T8>(
1433 t1: &T1,
1434 t2: &T2,
1435 t3: &T3,
1436 t4: &T4,
1437 t5: &T5,
1438 t6: &T6,
1439 t7: &T7,
1440 t8: &T8,
1441 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7, T8)>;
1442
1443 /// Gets the 1st item
1444 #[wasm_bindgen(
1445 method,
1446 js_class = Array,
1447 getter,
1448 js_name = "0"
1449 )]
1450 pub fn get0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>) -> <T as JsTuple1>::T1;
1451
1452 /// Gets the 2nd item
1453 #[wasm_bindgen(
1454 method,
1455 js_class = Array,
1456 getter,
1457 js_name = "1"
1458 )]
1459 pub fn get1<T: JsTuple2 = (JsValue, JsValue)>(this: &ArrayTuple<T>) -> <T as JsTuple2>::T2;
1460
1461 /// Gets the 3rd item
1462 #[wasm_bindgen(
1463 method,
1464 js_class = Array,
1465 getter,
1466 js_name = "2"
1467 )]
1468 pub fn get2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1469 this: &ArrayTuple<T>,
1470 ) -> <T as JsTuple3>::T3;
1471
1472 /// Gets the 4th item
1473 #[wasm_bindgen(
1474 method,
1475 js_class = Array,
1476 getter,
1477 js_name = "3"
1478 )]
1479 pub fn get3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1480 this: &ArrayTuple<T>,
1481 ) -> <T as JsTuple4>::T4;
1482
1483 /// Gets the 5th item
1484 #[wasm_bindgen(
1485 method,
1486 js_class = Array,
1487 getter,
1488 js_name = "4"
1489 )]
1490 pub fn get4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1491 this: &ArrayTuple<T>,
1492 ) -> <T as JsTuple5>::T5;
1493
1494 /// Gets the 6th item
1495 #[wasm_bindgen(
1496 method,
1497 js_class = Array,
1498 getter,
1499 js_name = "5"
1500 )]
1501 pub fn get5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1502 this: &ArrayTuple<T>,
1503 ) -> <T as JsTuple6>::T6;
1504
1505 /// Gets the 7th item
1506 #[wasm_bindgen(
1507 method,
1508 js_class = Array,
1509 getter,
1510 js_name = "6"
1511 )]
1512 pub fn get6<
1513 T: JsTuple7 = (
1514 JsValue,
1515 JsValue,
1516 JsValue,
1517 JsValue,
1518 JsValue,
1519 JsValue,
1520 JsValue,
1521 ),
1522 >(
1523 this: &ArrayTuple<T>,
1524 ) -> <T as JsTuple7>::T7;
1525
1526 /// Gets the 8th item
1527 #[wasm_bindgen(
1528 method,
1529 js_class = Array,
1530 getter,
1531 js_name = "7"
1532 )]
1533 pub fn get7<
1534 T: JsTuple8 = (
1535 JsValue,
1536 JsValue,
1537 JsValue,
1538 JsValue,
1539 JsValue,
1540 JsValue,
1541 JsValue,
1542 JsValue,
1543 ),
1544 >(
1545 this: &ArrayTuple<T>,
1546 ) -> <T as JsTuple8>::T8;
1547
1548 /// Sets the 1st item
1549 #[wasm_bindgen(
1550 method,
1551 js_class = Array,
1552 setter,
1553 js_name = "0"
1554 )]
1555 pub fn set0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>, value: &<T as JsTuple1>::T1);
1556
1557 /// Sets the 2nd item
1558 #[wasm_bindgen(
1559 method,
1560 js_class = Array,
1561 setter,
1562 js_name = "1"
1563 )]
1564 pub fn set1<T: JsTuple2 = (JsValue, JsValue)>(
1565 this: &ArrayTuple<T>,
1566 value: &<T as JsTuple2>::T2,
1567 );
1568
1569 /// Sets the 3rd item
1570 #[wasm_bindgen(
1571 method,
1572 js_class = Array,
1573 setter,
1574 js_name = "2"
1575 )]
1576 pub fn set2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1577 this: &ArrayTuple<T>,
1578 value: &<T as JsTuple3>::T3,
1579 );
1580
1581 /// Sets the 4th item
1582 #[wasm_bindgen(
1583 method,
1584 js_class = Array,
1585 setter,
1586 js_name = "3"
1587 )]
1588 pub fn set3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1589 this: &ArrayTuple<T>,
1590 value: &<T as JsTuple4>::T4,
1591 );
1592
1593 /// Sets the 5th item
1594 #[wasm_bindgen(
1595 method,
1596 js_class = Array,
1597 setter,
1598 js_name = "4"
1599 )]
1600 pub fn set4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1601 this: &ArrayTuple<T>,
1602 value: &<T as JsTuple5>::T5,
1603 );
1604
1605 /// Sets the 6th item
1606 #[wasm_bindgen(
1607 method,
1608 js_class = Array,
1609 setter,
1610 js_name = "5"
1611 )]
1612 pub fn set5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1613 this: &ArrayTuple<T>,
1614 value: &<T as JsTuple6>::T6,
1615 );
1616
1617 /// Sets the 7th item
1618 #[wasm_bindgen(
1619 method,
1620 js_class = Array,
1621 setter,
1622 js_name = "6"
1623 )]
1624 pub fn set6<
1625 T: JsTuple7 = (
1626 JsValue,
1627 JsValue,
1628 JsValue,
1629 JsValue,
1630 JsValue,
1631 JsValue,
1632 JsValue,
1633 ),
1634 >(
1635 this: &ArrayTuple<T>,
1636 value: &<T as JsTuple7>::T7,
1637 );
1638
1639 /// Sets the 8th item
1640 #[wasm_bindgen(
1641 method,
1642 js_class = Array,
1643 setter,
1644 js_name = "7"
1645 )]
1646 pub fn set7<
1647 T: JsTuple8 = (
1648 JsValue,
1649 JsValue,
1650 JsValue,
1651 JsValue,
1652 JsValue,
1653 JsValue,
1654 JsValue,
1655 JsValue,
1656 ),
1657 >(
1658 this: &ArrayTuple<T>,
1659 value: &<T as JsTuple8>::T8,
1660 );
1661}
1662
1663/// Base trait for tuple types.
1664pub trait JsTuple {
1665 const ARITY: usize;
1666}
1667
1668macro_rules! impl_tuple_traits {
1669 // Base case: first trait has no parent (besides JsTuple)
1670 ($name:ident $ty:tt) => {
1671 pub trait $name: JsTuple {
1672 type $ty;
1673 }
1674 };
1675
1676 // Recursive case: define trait with parent, then recurse
1677 ($name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1678 pub trait $name: JsTuple {
1679 type $ty;
1680 }
1681
1682 impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1683 };
1684
1685 // Internal: traits that have a parent
1686 (@with_parent $trait:ident $name:ident $ty:tt) => {
1687 pub trait $name: $trait {
1688 type $ty;
1689 }
1690 };
1691
1692 (@with_parent $trait:ident $name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1693 pub trait $name: $trait {
1694 type $ty;
1695 }
1696
1697 impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1698 };
1699}
1700
1701macro_rules! impl_parent_traits {
1702 ([$($types:tt),+] [] []) => {};
1703
1704 ([$($types:tt),+] [$trait:ident $($rest_traits:ident)*] [$ty:tt $($rest_tys:tt)*]) => {
1705 impl<$($types),+> $trait for ($($types),+,) {
1706 type $ty = $ty;
1707 }
1708
1709 impl_parent_traits!([$($types),+] [$($rest_traits)*] [$($rest_tys)*]);
1710 };
1711}
1712
1713// Define the trait hierarchy once
1714impl_tuple_traits!(
1715 JsTuple1 T1
1716 JsTuple2 T2
1717 JsTuple3 T3
1718 JsTuple4 T4
1719 JsTuple5 T5
1720 JsTuple6 T6
1721 JsTuple7 T7
1722 JsTuple8 T8
1723);
1724
1725impl<T: JsTuple> ArrayTuple<T> {
1726 /// Get the static arity of the ArrayTuple type.
1727 #[allow(clippy::len_without_is_empty)]
1728 pub fn len(&self) -> usize {
1729 <T as JsTuple>::ARITY
1730 }
1731}
1732
1733macro_rules! impl_tuple {
1734 ($arity:literal [$($traits:ident)*] [$($T:tt)+] [$($vars:tt)+] $new:ident $last:ident $last_ty:tt) => {
1735 impl<$($T),+> JsTuple for ($($T),+,) {
1736 const ARITY: usize = $arity;
1737 }
1738
1739 impl_parent_traits!([$($T),+] [$($traits)*] [$($T)*]);
1740
1741 impl<$($T: JsGeneric),+> From<($($T,)+)> for ArrayTuple<($($T),+,)> {
1742 fn from(($($vars,)+): ($($T,)+)) -> Self {
1743 $(let $vars: JsValue = $vars.upcast_into();)+
1744 Array::of(&[$($vars),+]).unchecked_into()
1745 }
1746 }
1747
1748 impl<$($T: JsGeneric + Default),+> Default for ArrayTuple<($($T),+,)> {
1749 fn default() -> Self {
1750 (
1751 $($T::default(),)+
1752 ).into()
1753 }
1754 }
1755
1756 impl<$($T: JsGeneric),+> ArrayTuple<($($T),+,)> {
1757 /// Get the first element of the ArrayTuple
1758 pub fn first(&self) -> T1 {
1759 self.get0()
1760 }
1761
1762 /// Get the last element of the ArrayTuple
1763 pub fn last(&self) -> $last_ty {
1764 self.$last()
1765 }
1766
1767 /// Convert the ArrayTuple into its corresponding Rust tuple.
1768 pub fn into_tuple(self) -> ($($T,)+) {
1769 ($(self.$vars(),)+)
1770 }
1771
1772 /// Deprecated alias for [`ArrayTuple::into_tuple`].
1773 #[deprecated(note = "renamed to `into_tuple`")]
1774 pub fn into_parts(self) -> ($($T,)+) {
1775 self.into_tuple()
1776 }
1777
1778 /// Create a new ArrayTuple from the corresponding parts.
1779 ///
1780 /// # Example
1781 ///
1782 /// ```
1783 /// use js_sys::{ArrayTuple, JsString};
1784 ///
1785 /// let tuple = ArrayTuple::<JsString, JsString>::new(&"a".into(), &"b".into());
1786 /// ```
1787 ///
1788 /// Note: You must specify the T using `::<...>` syntax on `ArrayTuple`.
1789 /// Alternatively, use `new1`, `new2`, etc. for type inference from the left-hand side.
1790 pub fn new($($vars: &$T),+) -> ArrayTuple<($($T),+,)> {
1791 ArrayTuple::$new($($vars),+)
1792 }
1793 }
1794 };
1795}
1796
1797// Implement for each tuple size
1798impl_tuple!(1 [JsTuple1] [T1] [get0] new1 get0 T1);
1799impl_tuple!(2 [JsTuple1 JsTuple2] [T1 T2] [get0 get1] new2 get1 T2);
1800impl_tuple!(3 [JsTuple1 JsTuple2 JsTuple3] [T1 T2 T3] [get0 get1 get2] new3 get2 T3);
1801impl_tuple!(4 [JsTuple1 JsTuple2 JsTuple3 JsTuple4] [T1 T2 T3 T4] [get0 get1 get2 get3] new4 get3 T4);
1802impl_tuple!(5 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5] [T1 T2 T3 T4 T5] [get0 get1 get2 get3 get4] new5 get4 T5);
1803impl_tuple!(6 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5 JsTuple6] [T1 T2 T3 T4 T5 T6] [get0 get1 get2 get3 get4 get5] new6 get5 T6);
1804impl_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);
1805impl_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);
1806
1807// Macro to generate structural covariance impls for each arity
1808macro_rules! impl_tuple_covariance {
1809 ([$($T:ident)+] [$($Target:ident)+]) => {
1810 // ArrayTuple -> Array
1811 // Allows (T1, T2, ...) to be used where (Target) is expected
1812 // when all T1, T2, ... are covariant to Target
1813 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for Array<Target>
1814 where
1815 $(Target: UpcastFrom<$T>,)+
1816 {
1817 }
1818 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for JsOption<Array<Target>>
1819 where
1820 $(Target: UpcastFrom<$T>,)+
1821 {}
1822 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for JsNullable<Array<Target>>
1823 where
1824 $(Target: UpcastFrom<$T>,)+
1825 {}
1826 };
1827}
1828
1829impl_tuple_covariance!([T1][Target1]);
1830impl_tuple_covariance!([T1 T2] [Target1 Target2]);
1831impl_tuple_covariance!([T1 T2 T3] [Target1 Target2 Target3]);
1832impl_tuple_covariance!([T1 T2 T3 T4] [Target1 Target2 Target3 Target4]);
1833impl_tuple_covariance!([T1 T2 T3 T4 T5] [Target1 Target2 Target3 Target4 Target5]);
1834impl_tuple_covariance!([T1 T2 T3 T4 T5 T6] [Target1 Target2 Target3 Target4 Target5 Target6]);
1835impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7] [Target1 Target2 Target3 Target4 Target5 Target6 Target7]);
1836impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7 T8] [Target1 Target2 Target3 Target4 Target5 Target6 Target7 Target8]);
1837
1838// Tuple casting is implemented in core
1839impl<T: JsTuple, U: JsTuple> UpcastFrom<ArrayTuple<T>> for ArrayTuple<U> where U: UpcastFrom<T> {}
1840impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsValue {}
1841impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsOption<JsValue> {}
1842impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsNullable<JsValue> {}
1843
1844/// Iterator returned by `Array::into_iter`
1845#[derive(Debug, Clone)]
1846pub struct ArrayIntoIter<T: JsGeneric = JsValue> {
1847 range: core::ops::Range<u32>,
1848 array: Array<T>,
1849}
1850
1851#[cfg(not(js_sys_unstable_apis))]
1852impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1853 type Item = T;
1854
1855 fn next(&mut self) -> Option<Self::Item> {
1856 let index = self.range.next()?;
1857 Some(self.array.get(index))
1858 }
1859
1860 #[inline]
1861 fn size_hint(&self) -> (usize, Option<usize>) {
1862 self.range.size_hint()
1863 }
1864
1865 #[inline]
1866 fn count(self) -> usize
1867 where
1868 Self: Sized,
1869 {
1870 self.range.count()
1871 }
1872
1873 #[inline]
1874 fn last(self) -> Option<Self::Item>
1875 where
1876 Self: Sized,
1877 {
1878 let Self { range, array } = self;
1879 range.last().map(|index| array.get(index))
1880 }
1881
1882 #[inline]
1883 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1884 self.range.nth(n).map(|index| self.array.get(index))
1885 }
1886}
1887
1888#[cfg(js_sys_unstable_apis)]
1889impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1890 type Item = T;
1891
1892 fn next(&mut self) -> Option<Self::Item> {
1893 let index = self.range.next()?;
1894 self.array.get(index)
1895 }
1896
1897 #[inline]
1898 fn size_hint(&self) -> (usize, Option<usize>) {
1899 self.range.size_hint()
1900 }
1901
1902 #[inline]
1903 fn count(self) -> usize
1904 where
1905 Self: Sized,
1906 {
1907 self.range.count()
1908 }
1909
1910 #[inline]
1911 fn last(self) -> Option<Self::Item>
1912 where
1913 Self: Sized,
1914 {
1915 let Self { range, array } = self;
1916 range.last().and_then(|index| array.get(index))
1917 }
1918
1919 #[inline]
1920 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1921 self.range.nth(n).and_then(|index| self.array.get(index))
1922 }
1923}
1924
1925#[cfg(not(js_sys_unstable_apis))]
1926impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1927 fn next_back(&mut self) -> Option<Self::Item> {
1928 let index = self.range.next_back()?;
1929 Some(self.array.get(index))
1930 }
1931
1932 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1933 self.range.nth_back(n).map(|index| self.array.get(index))
1934 }
1935}
1936
1937#[cfg(js_sys_unstable_apis)]
1938impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1939 fn next_back(&mut self) -> Option<Self::Item> {
1940 let index = self.range.next_back()?;
1941 self.array.get(index)
1942 }
1943
1944 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1945 self.range
1946 .nth_back(n)
1947 .and_then(|index| self.array.get(index))
1948 }
1949}
1950
1951impl<T: JsGeneric> core::iter::FusedIterator for ArrayIntoIter<T> {}
1952
1953impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIntoIter<T> {}
1954
1955/// Iterator returned by `Array::iter`
1956#[derive(Debug, Clone)]
1957pub struct ArrayIter<'a, T: JsGeneric = JsValue> {
1958 range: core::ops::Range<u32>,
1959 array: &'a Array<T>,
1960}
1961
1962impl<T: JsGeneric> core::iter::Iterator for ArrayIter<'_, T> {
1963 type Item = T;
1964
1965 fn next(&mut self) -> Option<Self::Item> {
1966 let index = self.range.next()?;
1967 Some(self.array.get_unchecked(index))
1968 }
1969
1970 #[inline]
1971 fn size_hint(&self) -> (usize, Option<usize>) {
1972 self.range.size_hint()
1973 }
1974
1975 #[inline]
1976 fn count(self) -> usize
1977 where
1978 Self: Sized,
1979 {
1980 self.range.count()
1981 }
1982
1983 #[inline]
1984 fn last(self) -> Option<Self::Item>
1985 where
1986 Self: Sized,
1987 {
1988 let Self { range, array } = self;
1989 range.last().map(|index| array.get_unchecked(index))
1990 }
1991
1992 #[inline]
1993 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1994 self.range
1995 .nth(n)
1996 .map(|index| self.array.get_unchecked(index))
1997 }
1998}
1999
2000impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIter<'_, T> {
2001 fn next_back(&mut self) -> Option<Self::Item> {
2002 let index = self.range.next_back()?;
2003 Some(self.array.get_unchecked(index))
2004 }
2005
2006 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
2007 self.range
2008 .nth_back(n)
2009 .map(|index| self.array.get_unchecked(index))
2010 }
2011}
2012
2013impl<T: JsGeneric> core::iter::FusedIterator for ArrayIter<'_, T> {}
2014
2015impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIter<'_, T> {}
2016
2017impl<T: JsGeneric> Array<T> {
2018 /// Returns an iterator over the values of the JS array.
2019 pub fn iter(&self) -> ArrayIter<'_, T> {
2020 ArrayIter {
2021 range: 0..self.length(),
2022 array: self,
2023 }
2024 }
2025}
2026
2027impl<T: JsGeneric> core::iter::IntoIterator for Array<T> {
2028 type Item = T;
2029 type IntoIter = ArrayIntoIter<T>;
2030
2031 fn into_iter(self) -> Self::IntoIter {
2032 ArrayIntoIter {
2033 range: 0..self.length(),
2034 array: self,
2035 }
2036 }
2037}
2038
2039// `FromIterator` / `Extend` for `Array` (= `Array<JsValue>` via the default
2040// type parameter) preserve the long-standing stable behaviour: any iterator
2041// of items convertible to `&JsValue` collects into an erased `Array<JsValue>`.
2042//
2043// Typed collection (where the element type is inferred from the iterator
2044// item via [`IntoJsGeneric`]) is exposed as the inherent constructor
2045// [`Array::from_iter_typed`] rather than a second `FromIterator` impl. A
2046// blanket `impl<A: IntoJsGeneric> FromIterator<A> for Array<A::JsCanon>`
2047// would overlap with the stable `AsRef<JsValue>` impl on `Array<JsValue>`
2048// (since `JsValue: IntoJsGeneric` with `JsCanon = JsValue`), so the two
2049// cannot coexist as `FromIterator` impls without coherence violations.
2050//
2051// TODO(next major): deprecate this `FromIterator`/`Extend` pair in favour
2052// of a single `IntoJsGeneric`-based impl, and rename `from_iter_typed` to
2053// take its place. That migration is source-breaking for callers relying on
2054// `.collect::<Array>()` implicit erasure of typed items, so it is deferred.
2055
2056impl<A> core::iter::FromIterator<A> for Array
2057where
2058 A: AsRef<JsValue>,
2059{
2060 fn from_iter<I>(iter: I) -> Array
2061 where
2062 I: IntoIterator<Item = A>,
2063 {
2064 let mut out = Array::new();
2065 out.extend(iter);
2066 out
2067 }
2068}
2069
2070impl<A> core::iter::Extend<A> for Array
2071where
2072 A: AsRef<JsValue>,
2073{
2074 fn extend<I>(&mut self, iter: I)
2075 where
2076 I: IntoIterator<Item = A>,
2077 {
2078 for value in iter {
2079 self.push(value.as_ref());
2080 }
2081 }
2082}
2083
2084impl<T: JsGeneric> Array<T> {
2085 /// Collect an iterator into a typed `Array<T>`, projecting each item
2086 /// through its canonical [`JsGeneric`] via [`IntoJsGeneric`].
2087 ///
2088 /// This is the typed counterpart to the stable
2089 /// `impl FromIterator<A> for Array where A: AsRef<JsValue>`, which always
2090 /// produces an erased `Array<JsValue>`. Use `from_iter_typed` when you
2091 /// want the element type inferred from the iterator item:
2092 ///
2093 /// ```ignore
2094 /// use js_sys::{Array, Number};
2095 ///
2096 /// let arr = Array::from_iter_typed((0..10).map(Number::from));
2097 /// // arr: Array<Number>
2098 /// ```
2099 ///
2100 /// Reference iteration (`Item = &U`) is supported transparently via the
2101 /// `&U: IntoJsGeneric` blanket in `wasm-bindgen` core.
2102 //
2103 // TODO(next major): replace the stable `FromIterator` impl above with
2104 // this behaviour and remove `from_iter_typed`.
2105 pub fn from_iter_typed<A, I>(iter: I) -> Array<T>
2106 where
2107 A: IntoJsGeneric<JsCanon = T>,
2108 I: IntoIterator<Item = A>,
2109 {
2110 let mut out = Array::<T>::new_typed();
2111 out.extend_typed(iter);
2112 out
2113 }
2114
2115 /// Extend a typed `Array<T>` with an iterator of items convertible to
2116 /// `T` via [`IntoJsGeneric`]. Companion to [`Array::from_iter_typed`].
2117 //
2118 // TODO(next major): replace the stable `Extend` impl above with this
2119 // behaviour and remove `extend_typed`.
2120 pub fn extend_typed<A, I>(&mut self, iter: I)
2121 where
2122 A: IntoJsGeneric<JsCanon = T>,
2123 I: IntoIterator<Item = A>,
2124 {
2125 for value in iter {
2126 self.push(&value.to_js());
2127 }
2128 }
2129}
2130
2131impl Default for Array<JsValue> {
2132 fn default() -> Self {
2133 Self::new()
2134 }
2135}
2136
2137impl<T> Iterable for Array<T> {
2138 type Item = T;
2139}
2140
2141impl<T: JsTuple> Iterable for ArrayTuple<T> {
2142 type Item = JsValue;
2143}
2144
2145// ArrayBufferOptions
2146#[wasm_bindgen]
2147extern "C" {
2148 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBufferOptions")]
2149 #[derive(Clone, Debug, PartialEq, Eq)]
2150 pub type ArrayBufferOptions;
2151
2152 /// The maximum size, in bytes, that the array buffer can be resized to.
2153 #[wasm_bindgen(method, setter, js_name = maxByteLength)]
2154 pub fn set_max_byte_length(this: &ArrayBufferOptions, max_byte_length: usize);
2155
2156 /// The maximum size, in bytes, that the array buffer can be resized to.
2157 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2158 pub fn get_max_byte_length(this: &ArrayBufferOptions) -> usize;
2159}
2160
2161impl ArrayBufferOptions {
2162 #[cfg(not(js_sys_unstable_apis))]
2163 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2164 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::new());
2165 options.set_max_byte_length(max_byte_length);
2166 options
2167 }
2168
2169 #[cfg(js_sys_unstable_apis)]
2170 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2171 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::<JsValue>::new());
2172 options.set_max_byte_length(max_byte_length);
2173 options
2174 }
2175}
2176
2177// ArrayBuffer
2178#[wasm_bindgen]
2179extern "C" {
2180 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBuffer")]
2181 #[derive(Clone, Debug, PartialEq, Eq)]
2182 pub type ArrayBuffer;
2183
2184 /// The `ArrayBuffer` object is used to represent a generic,
2185 /// fixed-length raw binary data buffer. You cannot directly
2186 /// manipulate the contents of an `ArrayBuffer`; instead, you
2187 /// create one of the typed array objects or a `DataView` object
2188 /// which represents the buffer in a specific format, and use that
2189 /// to read and write the contents of the buffer.
2190 ///
2191 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2192 #[cfg(not(js_sys_unstable_apis))]
2193 #[wasm_bindgen(constructor)]
2194 pub fn new(length: u32) -> ArrayBuffer;
2195
2196 /// The `ArrayBuffer` object is used to represent a generic,
2197 /// fixed-length raw binary data buffer. You cannot directly
2198 /// manipulate the contents of an `ArrayBuffer`; instead, you
2199 /// create one of the typed array objects or a `DataView` object
2200 /// which represents the buffer in a specific format, and use that
2201 /// to read and write the contents of the buffer.
2202 ///
2203 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2204 #[cfg(js_sys_unstable_apis)]
2205 #[wasm_bindgen(constructor)]
2206 pub fn new(length: usize) -> ArrayBuffer;
2207
2208 /// The `ArrayBuffer` object is used to represent a generic,
2209 /// fixed-length raw binary data buffer. You cannot directly
2210 /// manipulate the contents of an `ArrayBuffer`; instead, you
2211 /// create one of the typed array objects or a `DataView` object
2212 /// which represents the buffer in a specific format, and use that
2213 /// to read and write the contents of the buffer.
2214 ///
2215 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2216 #[wasm_bindgen(constructor)]
2217 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> ArrayBuffer;
2218
2219 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2220 /// it's an accessor property whose set accessor function is undefined,
2221 /// meaning that you can only read this property.
2222 /// The value is established when the array is constructed and cannot be changed.
2223 /// This property returns 0 if this ArrayBuffer has been detached.
2224 ///
2225 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2226 #[cfg(not(js_sys_unstable_apis))]
2227 #[wasm_bindgen(method, getter, js_name = byteLength)]
2228 pub fn byte_length(this: &ArrayBuffer) -> u32;
2229
2230 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2231 /// it's an accessor property whose set accessor function is undefined,
2232 /// meaning that you can only read this property.
2233 /// The value is established when the array is constructed and cannot be changed.
2234 /// This property returns 0 if this ArrayBuffer has been detached.
2235 ///
2236 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2237 #[cfg(js_sys_unstable_apis)]
2238 #[wasm_bindgen(method, getter, js_name = byteLength)]
2239 pub fn byte_length(this: &ArrayBuffer) -> usize;
2240
2241 /// The `detached` accessor property of `ArrayBuffer` instances returns a boolean indicating
2242 /// whether or not this buffer has been detached (transferred).
2243 ///
2244 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/detached)
2245 #[wasm_bindgen(method, getter)]
2246 pub fn detached(this: &ArrayBuffer) -> bool;
2247
2248 /// The `isView()` method returns true if arg is one of the `ArrayBuffer`
2249 /// views, such as typed array objects or a DataView; false otherwise.
2250 ///
2251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView)
2252 #[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
2253 pub fn is_view(value: &JsValue) -> bool;
2254
2255 /// The `maxByteLength` accessor property of ArrayBuffer instances returns the maximum
2256 /// length (in bytes) that this array buffer can be resized to.
2257 ///
2258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/maxByteLength)
2259 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2260 pub fn max_byte_length(this: &ArrayBuffer) -> usize;
2261
2262 /// The `resizable` accessor property of `ArrayBuffer` instances returns whether this array buffer
2263 /// can be resized or not.
2264 ///
2265 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resizable)
2266 #[wasm_bindgen(method, getter)]
2267 pub fn resizable(this: &ArrayBuffer) -> bool;
2268
2269 /// The `resize()` method of ArrayBuffer instances resizes the ArrayBuffer to the
2270 /// specified size, in bytes.
2271 ///
2272 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resize)
2273 #[wasm_bindgen(method, catch)]
2274 pub fn resize(this: &ArrayBuffer, new_len: usize) -> Result<(), JsValue>;
2275
2276 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2277 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2278 /// up to end, exclusive.
2279 ///
2280 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2281 #[cfg(not(js_sys_unstable_apis))]
2282 #[wasm_bindgen(method)]
2283 pub fn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer;
2284
2285 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2286 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2287 /// up to end, exclusive. Negative indices count from the end.
2288 ///
2289 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2290 #[cfg(js_sys_unstable_apis)]
2291 #[wasm_bindgen(method)]
2292 pub fn slice(this: &ArrayBuffer, begin: isize, end: isize) -> ArrayBuffer;
2293
2294 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2295 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2296 /// up to end, exclusive.
2297 ///
2298 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2299 #[cfg(not(js_sys_unstable_apis))]
2300 #[wasm_bindgen(method, js_name = slice)]
2301 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2302
2303 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2304 /// are a copy of this `ArrayBuffer`'s bytes from begin to the end.
2305 /// Negative indices count from the end.
2306 ///
2307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2308 #[cfg(js_sys_unstable_apis)]
2309 #[wasm_bindgen(method, js_name = slice)]
2310 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2311
2312 // Next major: deprecate
2313 /// Like `slice()` but with the `end` argument.
2314 ///
2315 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2316 #[wasm_bindgen(method, js_name = slice)]
2317 pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer;
2318
2319 /// The `transfer()` method of ArrayBuffer instances creates a new `ArrayBuffer`
2320 /// with the same byte content as this buffer, then detaches this buffer.
2321 ///
2322 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2323 #[wasm_bindgen(method, catch)]
2324 pub fn transfer(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2325
2326 /// The `transfer()` method of `ArrayBuffer` instances creates a new `ArrayBuffer`
2327 /// with the same byte content as this buffer, then detaches this buffer.
2328 ///
2329 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2330 #[wasm_bindgen(method, catch, js_name = transfer)]
2331 pub fn transfer_with_length(
2332 this: &ArrayBuffer,
2333 new_byte_length: usize,
2334 ) -> Result<ArrayBuffer, JsValue>;
2335
2336 /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2337 /// ArrayBuffer with the same byte content as this buffer, then detaches this buffer.
2338 ///
2339 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2340 #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2341 pub fn transfer_to_fixed_length(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2342
2343 /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2344 /// `ArrayBuffer` with the same byte content as this buffer, then detaches this buffer.
2345 ///
2346 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2347 #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2348 pub fn transfer_to_fixed_length_with_length(
2349 this: &ArrayBuffer,
2350 new_byte_length: usize,
2351 ) -> Result<ArrayBuffer, JsValue>;
2352}
2353
2354impl UpcastFrom<&[u8]> for ArrayBuffer {}
2355
2356// SharedArrayBuffer
2357#[wasm_bindgen]
2358extern "C" {
2359 #[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
2360 #[derive(Clone, Debug)]
2361 pub type SharedArrayBuffer;
2362
2363 /// The `SharedArrayBuffer` object is used to represent a generic,
2364 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2365 /// object, but in a way that they can be used to create views
2366 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2367 /// cannot become detached.
2368 ///
2369 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2370 #[cfg(not(js_sys_unstable_apis))]
2371 #[wasm_bindgen(constructor)]
2372 pub fn new(length: u32) -> SharedArrayBuffer;
2373
2374 /// The `SharedArrayBuffer` object is used to represent a generic,
2375 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2376 /// object, but in a way that they can be used to create views
2377 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2378 /// cannot become detached.
2379 ///
2380 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2381 #[cfg(js_sys_unstable_apis)]
2382 #[wasm_bindgen(constructor)]
2383 pub fn new(length: usize) -> SharedArrayBuffer;
2384
2385 /// The `SharedArrayBuffer` object is used to represent a generic,
2386 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2387 /// object, but in a way that they can be used to create views
2388 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2389 /// cannot become detached.
2390 ///
2391 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2392 #[wasm_bindgen(constructor)]
2393 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> SharedArrayBuffer;
2394
2395 /// The `byteLength` accessor property represents the length of
2396 /// an `SharedArrayBuffer` in bytes. This is established when
2397 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2398 ///
2399 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2400 #[cfg(not(js_sys_unstable_apis))]
2401 #[wasm_bindgen(method, getter, js_name = byteLength)]
2402 pub fn byte_length(this: &SharedArrayBuffer) -> u32;
2403
2404 /// The `byteLength` accessor property represents the length of
2405 /// an `SharedArrayBuffer` in bytes. This is established when
2406 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2407 ///
2408 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2409 #[cfg(js_sys_unstable_apis)]
2410 #[wasm_bindgen(method, getter, js_name = byteLength)]
2411 pub fn byte_length(this: &SharedArrayBuffer) -> usize;
2412
2413 /// The `growable` accessor property of `SharedArrayBuffer` instances returns whether
2414 /// this `SharedArrayBuffer` can be grown or not.
2415 ///
2416 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/growable)
2417 #[wasm_bindgen(method, getter)]
2418 pub fn growable(this: &SharedArrayBuffer) -> bool;
2419
2420 /// The `grow()` method of `SharedArrayBuffer` instances grows the
2421 /// `SharedArrayBuffer` to the specified size, in bytes.
2422 ///
2423 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/grow)
2424 #[wasm_bindgen(method, catch)]
2425 pub fn grow(this: &SharedArrayBuffer, new_byte_length: usize) -> Result<(), JsValue>;
2426
2427 /// The `maxByteLength` accessor property of `SharedArrayBuffer` instances returns the maximum
2428 /// length (in bytes) that this `SharedArrayBuffer` can be resized to.
2429 ///
2430 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/maxByteLength)
2431 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2432 pub fn max_byte_length(this: &SharedArrayBuffer) -> usize;
2433
2434 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2435 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2436 /// up to end, exclusive.
2437 ///
2438 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2439 #[cfg(not(js_sys_unstable_apis))]
2440 #[wasm_bindgen(method)]
2441 pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer;
2442
2443 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2444 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2445 /// up to end, exclusive. Negative indices count from the end.
2446 ///
2447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2448 #[cfg(js_sys_unstable_apis)]
2449 #[wasm_bindgen(method)]
2450 pub fn slice(this: &SharedArrayBuffer, begin: isize, end: isize) -> SharedArrayBuffer;
2451
2452 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2453 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2454 /// up to end, exclusive.
2455 ///
2456 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2457 #[cfg(not(js_sys_unstable_apis))]
2458 #[wasm_bindgen(method)]
2459 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2460
2461 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2462 /// are a copy of this `SharedArrayBuffer`'s bytes from begin to end.
2463 /// Negative indices count from the end.
2464 ///
2465 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2466 #[cfg(js_sys_unstable_apis)]
2467 #[wasm_bindgen(method)]
2468 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2469
2470 // Next major: deprecate
2471 /// Like `slice()` but with the `end` argument.
2472 ///
2473 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2474 #[wasm_bindgen(method, js_name = slice)]
2475 pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer;
2476}
2477
2478// Array Iterator
2479#[wasm_bindgen]
2480extern "C" {
2481 /// The `keys()` method returns a new Array Iterator object that contains the
2482 /// keys for each index in the array.
2483 ///
2484 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys)
2485 #[wasm_bindgen(method)]
2486 pub fn keys<T>(this: &Array<T>) -> Iterator<T>;
2487
2488 /// The `entries()` method returns a new Array Iterator object that contains
2489 /// the key/value pairs for each index in the array.
2490 ///
2491 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2492 #[cfg(not(js_sys_unstable_apis))]
2493 #[wasm_bindgen(method)]
2494 #[deprecated(note = "recommended to use `Array::entries_typed` instead for typing")]
2495 #[allow(deprecated)]
2496 pub fn entries<T>(this: &Array<T>) -> Iterator<T>;
2497
2498 /// The `entries()` method returns a new Array Iterator object that contains
2499 /// the key/value pairs for each index in the array.
2500 ///
2501 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2502 #[cfg(js_sys_unstable_apis)]
2503 #[wasm_bindgen(method)]
2504 pub fn entries<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2505
2506 // Next major: deprecate
2507 /// The `entries()` method returns a new Array Iterator object that contains
2508 /// the key/value pairs for each index in the array.
2509 ///
2510 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2511 #[wasm_bindgen(method, js_name = entries)]
2512 pub fn entries_typed<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2513
2514 /// The `values()` method returns a new Array Iterator object that
2515 /// contains the values for each index in the array.
2516 ///
2517 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
2518 #[wasm_bindgen(method)]
2519 pub fn values<T>(this: &Array<T>) -> Iterator<T>;
2520}
2521
2522// FIXME(next-major): rename this trait to `ArrayBufferView`. The DOM/WebIDL
2523// spec name `ArrayBufferView` covers both `DataView` and the typed-array
2524// types, which more accurately reflects the set of types that implement this
2525// trait. The `TypedArray` name is kept for now to avoid a breaking change.
2526pub trait TypedArray: JsGeneric {}
2527
2528impl TypedArray for DataView {}
2529
2530// Next major: use usize/isize for indices
2531/// The `Atomics` object provides atomic operations as static methods.
2532/// They are used with `SharedArrayBuffer` objects.
2533///
2534/// The Atomic operations are installed on an `Atomics` module. Unlike
2535/// the other global objects, `Atomics` is not a constructor. You cannot
2536/// use it with a new operator or invoke the `Atomics` object as a
2537/// function. All properties and methods of `Atomics` are static
2538/// (as is the case with the Math object, for example).
2539/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
2540#[allow(non_snake_case)]
2541pub mod Atomics {
2542 use super::*;
2543
2544 #[wasm_bindgen]
2545 extern "C" {
2546 /// The static `Atomics.add()` method adds a given value at a given
2547 /// position in the array and returns the old value at that position.
2548 /// This atomic operation guarantees that no other write happens
2549 /// until the modified value is written back.
2550 ///
2551 /// You should use `add_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/add)
2554 #[wasm_bindgen(js_namespace = Atomics, catch)]
2555 pub fn add<T: TypedArray = Int32Array>(
2556 typed_array: &T,
2557 index: u32,
2558 value: i32,
2559 ) -> Result<i32, JsValue>;
2560
2561 /// The static `Atomics.add()` method adds a given value at a given
2562 /// position in the array and returns the old value at that position.
2563 /// This atomic operation guarantees that no other write happens
2564 /// until the modified value is written back.
2565 ///
2566 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2567 ///
2568 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2569 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = add)]
2570 pub fn add_bigint<T: TypedArray = Int32Array>(
2571 typed_array: &T,
2572 index: u32,
2573 value: i64,
2574 ) -> Result<i64, JsValue>;
2575
2576 /// The static `Atomics.and()` method computes a bitwise AND with a given
2577 /// value at a given position in the array, and returns the old value
2578 /// at that position.
2579 /// This atomic operation guarantees that no other write happens
2580 /// until the modified value is written back.
2581 ///
2582 /// You should use `and_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2583 ///
2584 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2585 #[wasm_bindgen(js_namespace = Atomics, catch)]
2586 pub fn and<T: TypedArray = Int32Array>(
2587 typed_array: &T,
2588 index: u32,
2589 value: i32,
2590 ) -> Result<i32, JsValue>;
2591
2592 /// The static `Atomics.and()` method computes a bitwise AND with a given
2593 /// value at a given position in the array, and returns the old value
2594 /// at that position.
2595 /// This atomic operation guarantees that no other write happens
2596 /// until the modified value is written back.
2597 ///
2598 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2599 ///
2600 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2601 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = and)]
2602 pub fn and_bigint<T: TypedArray = Int32Array>(
2603 typed_array: &T,
2604 index: u32,
2605 value: i64,
2606 ) -> Result<i64, JsValue>;
2607
2608 /// The static `Atomics.compareExchange()` method exchanges a given
2609 /// replacement value at a given position in the array, if a given expected
2610 /// value equals the old value. It returns the old value at that position
2611 /// whether it was equal to the expected value or not.
2612 /// This atomic operation guarantees that no other write happens
2613 /// until the modified value is written back.
2614 ///
2615 /// You should use `compare_exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2616 ///
2617 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2618 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2619 pub fn compare_exchange<T: TypedArray = Int32Array>(
2620 typed_array: &T,
2621 index: u32,
2622 expected_value: i32,
2623 replacement_value: i32,
2624 ) -> Result<i32, JsValue>;
2625
2626 /// The static `Atomics.compareExchange()` method exchanges a given
2627 /// replacement value at a given position in the array, if a given expected
2628 /// value equals the old value. It returns the old value at that position
2629 /// whether it was equal to the expected value or not.
2630 /// This atomic operation guarantees that no other write happens
2631 /// until the modified value is written back.
2632 ///
2633 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2634 ///
2635 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2636 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2637 pub fn compare_exchange_bigint<T: TypedArray = Int32Array>(
2638 typed_array: &T,
2639 index: u32,
2640 expected_value: i64,
2641 replacement_value: i64,
2642 ) -> Result<i64, JsValue>;
2643
2644 /// The static `Atomics.exchange()` method stores a given value at a given
2645 /// position in the array and returns the old value at that position.
2646 /// This atomic operation guarantees that no other write happens
2647 /// until the modified value is written back.
2648 ///
2649 /// You should use `exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2650 ///
2651 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2652 #[wasm_bindgen(js_namespace = Atomics, catch)]
2653 pub fn exchange<T: TypedArray = Int32Array>(
2654 typed_array: &T,
2655 index: u32,
2656 value: i32,
2657 ) -> Result<i32, JsValue>;
2658
2659 /// The static `Atomics.exchange()` method stores a given value at a given
2660 /// position in the array and returns the old value at that position.
2661 /// This atomic operation guarantees that no other write happens
2662 /// until the modified value is written back.
2663 ///
2664 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2665 ///
2666 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2667 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = exchange)]
2668 pub fn exchange_bigint<T: TypedArray = Int32Array>(
2669 typed_array: &T,
2670 index: u32,
2671 value: i64,
2672 ) -> Result<i64, JsValue>;
2673
2674 /// The static `Atomics.isLockFree()` method is used to determine
2675 /// whether to use locks or atomic operations. It returns true,
2676 /// if the given size is one of the `BYTES_PER_ELEMENT` property
2677 /// of integer `TypedArray` types.
2678 ///
2679 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree)
2680 #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)]
2681 pub fn is_lock_free(size: u32) -> bool;
2682
2683 /// The static `Atomics.load()` method returns a value at a given
2684 /// position in the array.
2685 ///
2686 /// You should use `load_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2687 ///
2688 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2689 #[wasm_bindgen(js_namespace = Atomics, catch)]
2690 pub fn load<T: TypedArray = Int32Array>(
2691 typed_array: &T,
2692 index: u32,
2693 ) -> Result<i32, JsValue>;
2694
2695 /// The static `Atomics.load()` method returns a value at a given
2696 /// position in the array.
2697 ///
2698 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2699 ///
2700 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2701 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = load)]
2702 pub fn load_bigint<T: TypedArray = Int32Array>(
2703 typed_array: &T,
2704 index: i64,
2705 ) -> Result<i64, JsValue>;
2706
2707 /// The static `Atomics.notify()` method notifies up some agents that
2708 /// are sleeping in the wait queue.
2709 /// Note: This operation works with a shared `Int32Array` only.
2710 /// If `count` is not provided, notifies all the agents in the queue.
2711 ///
2712 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2713 #[wasm_bindgen(js_namespace = Atomics, catch)]
2714 pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>;
2715
2716 /// The static `Atomics.notify()` method notifies up some agents that
2717 /// are sleeping in the wait queue.
2718 /// Note: This operation works with a shared `Int32Array` only.
2719 /// If `count` is not provided, notifies all the agents in the queue.
2720 ///
2721 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2722 #[wasm_bindgen(js_namespace = Atomics, catch)]
2723 pub fn notify_bigint(typed_array: &BigInt64Array, index: u32) -> Result<u32, JsValue>;
2724
2725 /// Notifies up to `count` agents in the wait queue.
2726 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2727 pub fn notify_with_count(
2728 typed_array: &Int32Array,
2729 index: u32,
2730 count: u32,
2731 ) -> Result<u32, JsValue>;
2732
2733 /// Notifies up to `count` agents in the wait queue.
2734 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2735 pub fn notify_bigint_with_count(
2736 typed_array: &BigInt64Array,
2737 index: u32,
2738 count: u32,
2739 ) -> Result<u32, JsValue>;
2740
2741 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2742 /// at a given position in the array, and returns the old value at that position.
2743 /// This atomic operation guarantees that no other write happens
2744 /// until the modified value is written back.
2745 ///
2746 /// You should use `or_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2747 ///
2748 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2749 #[wasm_bindgen(js_namespace = Atomics, catch)]
2750 pub fn or<T: TypedArray = Int32Array>(
2751 typed_array: &T,
2752 index: u32,
2753 value: i32,
2754 ) -> Result<i32, JsValue>;
2755
2756 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2757 /// at a given position in the array, and returns the old value at that position.
2758 /// This atomic operation guarantees that no other write happens
2759 /// until the modified value is written back.
2760 ///
2761 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2762 ///
2763 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2764 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = or)]
2765 pub fn or_bigint<T: TypedArray = Int32Array>(
2766 typed_array: &T,
2767 index: u32,
2768 value: i64,
2769 ) -> Result<i64, JsValue>;
2770
2771 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2772 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2773 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2774 /// current thread.
2775 ///
2776 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2777 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2778 /// per Intel's optimization manual. It could be a no-op in certain platforms.
2779 ///
2780 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2781 ///
2782 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2783 #[wasm_bindgen(js_namespace = Atomics)]
2784 pub fn pause();
2785
2786 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2787 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2788 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2789 /// current thread.
2790 ///
2791 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2792 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2793 /// per Intel's optimization manual. It could be a no-op in certain platforms.
2794 ///
2795 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2796 ///
2797 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2798 #[wasm_bindgen(js_namespace = Atomics)]
2799 pub fn pause_with_hint(duration_hint: u32);
2800
2801 /// The static `Atomics.store()` method stores a given value at the given
2802 /// position in the array and returns that value.
2803 ///
2804 /// You should use `store_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2805 ///
2806 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2807 #[wasm_bindgen(js_namespace = Atomics, catch)]
2808 pub fn store<T: TypedArray = Int32Array>(
2809 typed_array: &T,
2810 index: u32,
2811 value: i32,
2812 ) -> Result<i32, JsValue>;
2813
2814 /// The static `Atomics.store()` method stores a given value at the given
2815 /// position in the array and returns that value.
2816 ///
2817 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2818 ///
2819 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2820 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = store)]
2821 pub fn store_bigint<T: TypedArray = Int32Array>(
2822 typed_array: &T,
2823 index: u32,
2824 value: i64,
2825 ) -> Result<i64, JsValue>;
2826
2827 /// The static `Atomics.sub()` method subtracts a given value at a
2828 /// given position in the array and returns the old value at that position.
2829 /// This atomic operation guarantees that no other write happens
2830 /// until the modified value is written back.
2831 ///
2832 /// You should use `sub_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2833 ///
2834 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2835 #[wasm_bindgen(js_namespace = Atomics, catch)]
2836 pub fn sub<T: TypedArray = Int32Array>(
2837 typed_array: &T,
2838 index: u32,
2839 value: i32,
2840 ) -> Result<i32, JsValue>;
2841
2842 /// The static `Atomics.sub()` method subtracts a given value at a
2843 /// given position in the array and returns the old value at that position.
2844 /// This atomic operation guarantees that no other write happens
2845 /// until the modified value is written back.
2846 ///
2847 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2848 ///
2849 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2850 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = sub)]
2851 pub fn sub_bigint<T: TypedArray = Int32Array>(
2852 typed_array: &T,
2853 index: u32,
2854 value: i64,
2855 ) -> Result<i64, JsValue>;
2856
2857 /// The static `Atomics.wait()` method verifies that a given
2858 /// position in an `Int32Array` still contains a given value
2859 /// and if so sleeps, awaiting a wakeup or a timeout.
2860 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2861 /// Note: This operation only works with a shared `Int32Array`
2862 /// and may not be allowed on the main thread.
2863 ///
2864 /// You should use `wait_bigint` to operate on a `BigInt64Array`.
2865 ///
2866 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2867 #[wasm_bindgen(js_namespace = Atomics, catch)]
2868 pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>;
2869
2870 /// The static `Atomics.wait()` method verifies that a given
2871 /// position in an `BigInt64Array` still contains a given value
2872 /// and if so sleeps, awaiting a wakeup or a timeout.
2873 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2874 /// Note: This operation only works with a shared `BigInt64Array`
2875 /// and may not be allowed on the main thread.
2876 ///
2877 /// You should use `wait` to operate on a `Int32Array`.
2878 ///
2879 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2880 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2881 pub fn wait_bigint(
2882 typed_array: &BigInt64Array,
2883 index: u32,
2884 value: i64,
2885 ) -> Result<JsString, JsValue>;
2886
2887 /// Like `wait()`, but with timeout
2888 ///
2889 /// You should use `wait_with_timeout_bigint` to operate on a `BigInt64Array`.
2890 ///
2891 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2892 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2893 pub fn wait_with_timeout(
2894 typed_array: &Int32Array,
2895 index: u32,
2896 value: i32,
2897 timeout: f64,
2898 ) -> Result<JsString, JsValue>;
2899
2900 /// Like `wait()`, but with timeout
2901 ///
2902 /// You should use `wait_with_timeout` to operate on a `Int32Array`.
2903 ///
2904 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2905 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2906 pub fn wait_with_timeout_bigint(
2907 typed_array: &BigInt64Array,
2908 index: u32,
2909 value: i64,
2910 timeout: f64,
2911 ) -> Result<JsString, JsValue>;
2912
2913 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2914 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2915 /// wakeup or a timeout. It returns an object with two properties. The first
2916 /// property `async` is a boolean which if true indicates that the second
2917 /// property `value` is a promise. If `async` is false then value is a string
2918 /// whether equal to either "not-equal" or "timed-out".
2919 /// Note: This operation only works with a shared `Int32Array` and may be used
2920 /// on the main thread.
2921 ///
2922 /// You should use `wait_async_bigint` to operate on a `BigInt64Array`.
2923 ///
2924 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2925 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2926 pub fn wait_async(
2927 typed_array: &Int32Array,
2928 index: u32,
2929 value: i32,
2930 ) -> Result<Object, JsValue>;
2931
2932 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2933 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2934 /// wakeup or a timeout. It returns an object with two properties. The first
2935 /// property `async` is a boolean which if true indicates that the second
2936 /// property `value` is a promise. If `async` is false then value is a string
2937 /// whether equal to either "not-equal" or "timed-out".
2938 /// Note: This operation only works with a shared `BigInt64Array` and may be used
2939 /// on the main thread.
2940 ///
2941 /// You should use `wait_async` to operate on a `Int32Array`.
2942 ///
2943 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2944 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2945 pub fn wait_async_bigint(
2946 typed_array: &BigInt64Array,
2947 index: u32,
2948 value: i64,
2949 ) -> Result<Object, JsValue>;
2950
2951 /// Like `waitAsync()`, but with timeout
2952 ///
2953 /// You should use `wait_async_with_timeout_bigint` to operate on a `BigInt64Array`.
2954 ///
2955 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2956 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2957 pub fn wait_async_with_timeout(
2958 typed_array: &Int32Array,
2959 index: u32,
2960 value: i32,
2961 timeout: f64,
2962 ) -> Result<Object, JsValue>;
2963
2964 /// Like `waitAsync()`, but with timeout
2965 ///
2966 /// You should use `wait_async_with_timeout` to operate on a `Int32Array`.
2967 ///
2968 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2969 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2970 pub fn wait_async_with_timeout_bigint(
2971 typed_array: &BigInt64Array,
2972 index: u32,
2973 value: i64,
2974 timeout: f64,
2975 ) -> Result<Object, JsValue>;
2976
2977 /// The static `Atomics.xor()` method computes a bitwise XOR
2978 /// with a given value at a given position in the array,
2979 /// and returns the old value at that position.
2980 /// This atomic operation guarantees that no other write happens
2981 /// until the modified value is written back.
2982 ///
2983 /// You should use `xor_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2984 ///
2985 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2986 #[wasm_bindgen(js_namespace = Atomics, catch)]
2987 pub fn xor<T: TypedArray = Int32Array>(
2988 typed_array: &T,
2989 index: u32,
2990 value: i32,
2991 ) -> Result<i32, JsValue>;
2992
2993 /// The static `Atomics.xor()` method computes a bitwise XOR
2994 /// with a given value at a given position in the array,
2995 /// and returns the old value at that position.
2996 /// This atomic operation guarantees that no other write happens
2997 /// until the modified value is written back.
2998 ///
2999 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
3000 ///
3001 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
3002 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = xor)]
3003 pub fn xor_bigint<T: TypedArray = Int32Array>(
3004 typed_array: &T,
3005 index: u32,
3006 value: i64,
3007 ) -> Result<i64, JsValue>;
3008 }
3009}
3010
3011// BigInt
3012#[wasm_bindgen]
3013extern "C" {
3014 #[wasm_bindgen(extends = Object, is_type_of = |v| v.is_bigint(), typescript_type = "bigint")]
3015 #[derive(Clone, PartialEq, Eq)]
3016 pub type BigInt;
3017
3018 #[wasm_bindgen(catch, js_name = BigInt)]
3019 fn new_bigint(value: &JsValue) -> Result<BigInt, Error>;
3020
3021 #[wasm_bindgen(js_name = BigInt)]
3022 fn new_bigint_unchecked(value: &JsValue) -> BigInt;
3023
3024 /// Clamps a BigInt value to a signed integer value, and returns that value.
3025 ///
3026 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)
3027 #[wasm_bindgen(static_method_of = BigInt, js_name = asIntN)]
3028 pub fn as_int_n(bits: f64, bigint: &BigInt) -> BigInt;
3029
3030 /// Clamps a BigInt value to an unsigned integer value, and returns that value.
3031 ///
3032 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)
3033 #[wasm_bindgen(static_method_of = BigInt, js_name = asUintN)]
3034 pub fn as_uint_n(bits: f64, bigint: &BigInt) -> BigInt;
3035
3036 /// 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.
3037 ///
3038 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
3039 #[cfg(not(js_sys_unstable_apis))]
3040 #[wasm_bindgen(method, js_name = toLocaleString)]
3041 pub fn to_locale_string(this: &BigInt, locales: &JsValue, options: &JsValue) -> JsString;
3042
3043 /// 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.
3044 ///
3045 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
3046 #[cfg(js_sys_unstable_apis)]
3047 #[wasm_bindgen(method, js_name = toLocaleString)]
3048 pub fn to_locale_string(
3049 this: &BigInt,
3050 locales: &[JsString],
3051 options: &Intl::NumberFormatOptions,
3052 ) -> JsString;
3053
3054 // Next major: deprecate
3055 /// 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.
3056 ///
3057 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
3058 #[wasm_bindgen(catch, method, js_name = toString)]
3059 pub fn to_string(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
3060
3061 /// Returns a string representing this BigInt value in the specified radix (base).
3062 ///
3063 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
3064 #[cfg(js_sys_unstable_apis)]
3065 #[wasm_bindgen(catch, method, js_name = toString)]
3066 pub fn to_string_with_radix(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
3067
3068 #[wasm_bindgen(method, js_name = toString)]
3069 fn to_string_unchecked(this: &BigInt, radix: u8) -> String;
3070
3071 /// Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method.
3072 ///
3073 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)
3074 #[wasm_bindgen(method, js_name = valueOf)]
3075 pub fn value_of(this: &BigInt, radix: u8) -> BigInt;
3076}
3077
3078impl BigInt {
3079 /// Creates a new BigInt value.
3080 ///
3081 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)
3082 #[inline]
3083 pub fn new(value: &JsValue) -> Result<BigInt, Error> {
3084 new_bigint(value)
3085 }
3086
3087 /// Applies the binary `/` JS operator on two `BigInt`s, catching and returning any `RangeError` thrown.
3088 ///
3089 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division)
3090 pub fn checked_div(&self, rhs: &Self) -> Result<Self, RangeError> {
3091 let result = JsValue::as_ref(self).checked_div(JsValue::as_ref(rhs));
3092
3093 if result.is_instance_of::<RangeError>() {
3094 Err(result.unchecked_into())
3095 } else {
3096 Ok(result.unchecked_into())
3097 }
3098 }
3099
3100 /// Applies the binary `**` JS operator on the two `BigInt`s.
3101 ///
3102 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
3103 #[inline]
3104 pub fn pow(&self, rhs: &Self) -> Self {
3105 JsValue::as_ref(self)
3106 .pow(JsValue::as_ref(rhs))
3107 .unchecked_into()
3108 }
3109
3110 /// Returns a tuple of this [`BigInt`]'s absolute value along with a
3111 /// [`bool`] indicating whether the [`BigInt`] was negative.
3112 fn abs(&self) -> (Self, bool) {
3113 if self < &BigInt::from(0) {
3114 (-self, true)
3115 } else {
3116 (self.clone(), false)
3117 }
3118 }
3119}
3120
3121macro_rules! bigint_from {
3122 ($($x:ident)*) => ($(
3123 impl From<$x> for BigInt {
3124 #[inline]
3125 fn from(x: $x) -> BigInt {
3126 new_bigint_unchecked(&JsValue::from(x))
3127 }
3128 }
3129
3130 impl PartialEq<$x> for BigInt {
3131 #[inline]
3132 fn eq(&self, other: &$x) -> bool {
3133 JsValue::from(self) == JsValue::from(BigInt::from(*other))
3134 }
3135 }
3136 )*)
3137}
3138bigint_from!(i8 u8 i16 u16 i32 u32 isize usize);
3139
3140macro_rules! bigint_from_big {
3141 ($($x:ident)*) => ($(
3142 impl From<$x> for BigInt {
3143 #[inline]
3144 fn from(x: $x) -> BigInt {
3145 JsValue::from(x).unchecked_into()
3146 }
3147 }
3148
3149 impl PartialEq<$x> for BigInt {
3150 #[inline]
3151 fn eq(&self, other: &$x) -> bool {
3152 self == &BigInt::from(*other)
3153 }
3154 }
3155
3156 impl TryFrom<BigInt> for $x {
3157 type Error = BigInt;
3158
3159 #[inline]
3160 fn try_from(x: BigInt) -> Result<Self, BigInt> {
3161 Self::try_from(JsValue::from(x)).map_err(JsCast::unchecked_into)
3162 }
3163 }
3164 )*)
3165}
3166bigint_from_big!(i64 u64 i128 u128);
3167
3168impl PartialEq<Number> for BigInt {
3169 #[inline]
3170 fn eq(&self, other: &Number) -> bool {
3171 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
3172 }
3173}
3174
3175impl Not for &BigInt {
3176 type Output = BigInt;
3177
3178 #[inline]
3179 fn not(self) -> Self::Output {
3180 JsValue::as_ref(self).bit_not().unchecked_into()
3181 }
3182}
3183
3184forward_deref_unop!(impl Not, not for BigInt);
3185forward_js_unop!(impl Neg, neg for BigInt);
3186forward_js_binop!(impl BitAnd, bitand for BigInt);
3187forward_js_binop!(impl BitOr, bitor for BigInt);
3188forward_js_binop!(impl BitXor, bitxor for BigInt);
3189forward_js_binop!(impl Shl, shl for BigInt);
3190forward_js_binop!(impl Shr, shr for BigInt);
3191forward_js_binop!(impl Add, add for BigInt);
3192forward_js_binop!(impl Sub, sub for BigInt);
3193forward_js_binop!(impl Div, div for BigInt);
3194forward_js_binop!(impl Mul, mul for BigInt);
3195forward_js_binop!(impl Rem, rem for BigInt);
3196sum_product!(BigInt);
3197
3198partialord_ord!(BigInt);
3199
3200impl Default for BigInt {
3201 fn default() -> Self {
3202 BigInt::from(i32::default())
3203 }
3204}
3205
3206impl FromStr for BigInt {
3207 type Err = Error;
3208
3209 #[inline]
3210 fn from_str(s: &str) -> Result<Self, Self::Err> {
3211 BigInt::new(&s.into())
3212 }
3213}
3214
3215impl fmt::Debug for BigInt {
3216 #[inline]
3217 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3218 fmt::Display::fmt(self, f)
3219 }
3220}
3221
3222impl fmt::Display for BigInt {
3223 #[inline]
3224 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3225 let (abs, is_neg) = self.abs();
3226 f.pad_integral(!is_neg, "", &abs.to_string_unchecked(10))
3227 }
3228}
3229
3230impl fmt::Binary for BigInt {
3231 #[inline]
3232 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3233 let (abs, is_neg) = self.abs();
3234 f.pad_integral(!is_neg, "0b", &abs.to_string_unchecked(2))
3235 }
3236}
3237
3238impl fmt::Octal for BigInt {
3239 #[inline]
3240 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3241 let (abs, is_neg) = self.abs();
3242 f.pad_integral(!is_neg, "0o", &abs.to_string_unchecked(8))
3243 }
3244}
3245
3246impl fmt::LowerHex for BigInt {
3247 #[inline]
3248 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3249 let (abs, is_neg) = self.abs();
3250 f.pad_integral(!is_neg, "0x", &abs.to_string_unchecked(16))
3251 }
3252}
3253
3254impl fmt::UpperHex for BigInt {
3255 #[inline]
3256 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3257 let (abs, is_neg) = self.abs();
3258 let mut s: String = abs.to_string_unchecked(16);
3259 s.make_ascii_uppercase();
3260 f.pad_integral(!is_neg, "0x", &s)
3261 }
3262}
3263
3264// Boolean
3265#[wasm_bindgen]
3266extern "C" {
3267 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
3268 #[derive(Clone, PartialEq, Eq)]
3269 pub type Boolean;
3270
3271 /// The `Boolean()` constructor creates an object wrapper for a boolean value.
3272 ///
3273 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
3274 #[cfg(not(js_sys_unstable_apis))]
3275 #[wasm_bindgen(constructor)]
3276 #[deprecated(note = "recommended to use `Boolean::from` instead")]
3277 #[allow(deprecated)]
3278 pub fn new(value: &JsValue) -> Boolean;
3279
3280 /// The `valueOf()` method returns the primitive value of a `Boolean` object.
3281 ///
3282 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf)
3283 #[wasm_bindgen(method, js_name = valueOf)]
3284 pub fn value_of(this: &Boolean) -> bool;
3285}
3286
3287impl UpcastFrom<bool> for Boolean {}
3288impl UpcastFrom<Boolean> for bool {}
3289
3290impl Boolean {
3291 /// Typed Boolean true constant.
3292 pub const TRUE: Boolean = Self {
3293 obj: Object {
3294 obj: JsValue::TRUE,
3295 generics: PhantomData,
3296 },
3297 };
3298
3299 /// Typed Boolean false constant.
3300 pub const FALSE: Boolean = Self {
3301 obj: Object {
3302 obj: JsValue::FALSE,
3303 generics: PhantomData,
3304 },
3305 };
3306}
3307
3308impl From<bool> for Boolean {
3309 #[inline]
3310 fn from(b: bool) -> Boolean {
3311 Boolean::unchecked_from_js(JsValue::from(b))
3312 }
3313}
3314
3315impl From<Boolean> for bool {
3316 #[inline]
3317 fn from(b: Boolean) -> bool {
3318 b.value_of()
3319 }
3320}
3321
3322impl PartialEq<bool> for Boolean {
3323 #[inline]
3324 fn eq(&self, other: &bool) -> bool {
3325 self.value_of() == *other
3326 }
3327}
3328
3329impl fmt::Debug for Boolean {
3330 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3331 fmt::Debug::fmt(&self.value_of(), f)
3332 }
3333}
3334
3335impl fmt::Display for Boolean {
3336 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3337 fmt::Display::fmt(&self.value_of(), f)
3338 }
3339}
3340
3341impl Default for Boolean {
3342 fn default() -> Self {
3343 Self::from(bool::default())
3344 }
3345}
3346
3347impl Not for &Boolean {
3348 type Output = Boolean;
3349
3350 #[inline]
3351 fn not(self) -> Self::Output {
3352 (!JsValue::as_ref(self)).into()
3353 }
3354}
3355
3356forward_deref_unop!(impl Not, not for Boolean);
3357
3358partialord_ord!(Boolean);
3359
3360// DataView
3361#[wasm_bindgen]
3362extern "C" {
3363 #[wasm_bindgen(extends = Object, typescript_type = "DataView")]
3364 #[derive(Clone, Debug, PartialEq, Eq)]
3365 pub type DataView;
3366
3367 /// The `DataView` view provides a low-level interface for reading and
3368 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3369 /// platform's endianness.
3370 ///
3371 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3372 #[wasm_bindgen(constructor)]
3373 pub fn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView;
3374
3375 /// The `DataView` view provides a low-level interface for reading and
3376 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3377 /// platform's endianness.
3378 ///
3379 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3380 #[wasm_bindgen(constructor)]
3381 pub fn new_with_shared_array_buffer(
3382 buffer: &SharedArrayBuffer,
3383 byteOffset: usize,
3384 byteLength: usize,
3385 ) -> DataView;
3386
3387 /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
3388 ///
3389 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer)
3390 #[wasm_bindgen(method, getter)]
3391 pub fn buffer(this: &DataView) -> ArrayBuffer;
3392
3393 /// The length (in bytes) of this view from the start of its ArrayBuffer.
3394 /// Fixed at construction time and thus read only.
3395 ///
3396 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength)
3397 #[wasm_bindgen(method, getter, js_name = byteLength)]
3398 pub fn byte_length(this: &DataView) -> usize;
3399
3400 /// The offset (in bytes) of this view from the start of its ArrayBuffer.
3401 /// Fixed at construction time and thus read only.
3402 ///
3403 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset)
3404 #[wasm_bindgen(method, getter, js_name = byteOffset)]
3405 pub fn byte_offset(this: &DataView) -> usize;
3406
3407 /// The `getInt8()` method gets a signed 8-bit integer (byte) at the
3408 /// specified byte offset from the start of the DataView.
3409 ///
3410 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8)
3411 #[wasm_bindgen(method, js_name = getInt8)]
3412 pub fn get_int8(this: &DataView, byte_offset: usize) -> i8;
3413
3414 /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified
3415 /// byte offset from the start of the DataView.
3416 ///
3417 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8)
3418 #[wasm_bindgen(method, js_name = getUint8)]
3419 pub fn get_uint8(this: &DataView, byte_offset: usize) -> u8;
3420
3421 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3422 /// byte offset from the start of the DataView.
3423 ///
3424 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3425 #[wasm_bindgen(method, js_name = getInt16)]
3426 pub fn get_int16(this: &DataView, byte_offset: usize) -> i16;
3427
3428 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3429 /// byte offset from the start of the DataView.
3430 ///
3431 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3432 #[wasm_bindgen(method, js_name = getInt16)]
3433 pub fn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16;
3434
3435 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3436 /// byte offset from the start of the view.
3437 ///
3438 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3439 #[wasm_bindgen(method, js_name = getUint16)]
3440 pub fn get_uint16(this: &DataView, byte_offset: usize) -> u16;
3441
3442 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3443 /// byte offset from the start of the view.
3444 ///
3445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3446 #[wasm_bindgen(method, js_name = getUint16)]
3447 pub fn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16;
3448
3449 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3450 /// byte offset from the start of the DataView.
3451 ///
3452 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3453 #[wasm_bindgen(method, js_name = getInt32)]
3454 pub fn get_int32(this: &DataView, byte_offset: usize) -> i32;
3455
3456 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3457 /// byte offset from the start of the DataView.
3458 ///
3459 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3460 #[wasm_bindgen(method, js_name = getInt32)]
3461 pub fn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32;
3462
3463 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3464 /// byte offset from the start of the view.
3465 ///
3466 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3467 #[wasm_bindgen(method, js_name = getUint32)]
3468 pub fn get_uint32(this: &DataView, byte_offset: usize) -> u32;
3469
3470 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3471 /// byte offset from the start of the view.
3472 ///
3473 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3474 #[wasm_bindgen(method, js_name = getUint32)]
3475 pub fn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32;
3476
3477 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3478 /// byte offset from the start of the DataView.
3479 ///
3480 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3481 #[wasm_bindgen(method, js_name = getFloat32)]
3482 pub fn get_float32(this: &DataView, byte_offset: usize) -> f32;
3483
3484 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3485 /// byte offset from the start of the DataView.
3486 ///
3487 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3488 #[wasm_bindgen(method, js_name = getFloat32)]
3489 pub fn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32;
3490
3491 /// The `getFloat16()` method gets a signed 16-bit float at the specified
3492 /// byte offset from the start of the DataView as an `f32`.
3493 ///
3494 /// The unsuffixed `get_float16` name is reserved for a future native
3495 /// `f16` binding once Rust stabilizes the type.
3496 ///
3497 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16)
3498 #[wasm_bindgen(method, js_name = getFloat16)]
3499 pub fn get_float16_as_f32(this: &DataView, byte_offset: usize) -> f32;
3500
3501 /// The `getFloat16()` method gets a signed 16-bit float at the specified
3502 /// byte offset from the start of the DataView as an `f32`.
3503 ///
3504 /// The unsuffixed `get_float16_endian` name is reserved for a future
3505 /// native `f16` binding once Rust stabilizes the type.
3506 ///
3507 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16)
3508 #[wasm_bindgen(method, js_name = getFloat16)]
3509 pub fn get_float16_endian_as_f32(
3510 this: &DataView,
3511 byte_offset: usize,
3512 little_endian: bool,
3513 ) -> f32;
3514
3515 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3516 /// byte offset from the start of the DataView.
3517 ///
3518 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3519 #[wasm_bindgen(method, js_name = getFloat64)]
3520 pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
3521
3522 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3523 /// byte offset from the start of the DataView.
3524 ///
3525 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3526 #[wasm_bindgen(method, js_name = getFloat64)]
3527 pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
3528
3529 /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
3530 /// specified byte offset from the start of the DataView.
3531 ///
3532 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
3533 #[wasm_bindgen(method, js_name = setInt8)]
3534 pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
3535
3536 /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
3537 /// specified byte offset from the start of the DataView.
3538 ///
3539 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
3540 #[wasm_bindgen(method, js_name = setUint8)]
3541 pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
3542
3543 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3544 /// specified byte offset from the start of the DataView.
3545 ///
3546 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3547 #[wasm_bindgen(method, js_name = setInt16)]
3548 pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
3549
3550 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3551 /// specified byte offset from the start of the DataView.
3552 ///
3553 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3554 #[wasm_bindgen(method, js_name = setInt16)]
3555 pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
3556
3557 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3558 /// specified byte offset from the start of the DataView.
3559 ///
3560 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3561 #[wasm_bindgen(method, js_name = setUint16)]
3562 pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
3563
3564 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3565 /// specified byte offset from the start of the DataView.
3566 ///
3567 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3568 #[wasm_bindgen(method, js_name = setUint16)]
3569 pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
3570
3571 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3572 /// specified byte offset from the start of the DataView.
3573 ///
3574 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3575 #[wasm_bindgen(method, js_name = setInt32)]
3576 pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
3577
3578 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3579 /// specified byte offset from the start of the DataView.
3580 ///
3581 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3582 #[wasm_bindgen(method, js_name = setInt32)]
3583 pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
3584
3585 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3586 /// specified byte offset from the start of the DataView.
3587 ///
3588 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3589 #[wasm_bindgen(method, js_name = setUint32)]
3590 pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
3591
3592 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3593 /// specified byte offset from the start of the DataView.
3594 ///
3595 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3596 #[wasm_bindgen(method, js_name = setUint32)]
3597 pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
3598
3599 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3600 /// specified byte offset from the start of the DataView.
3601 ///
3602 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3603 #[wasm_bindgen(method, js_name = setFloat32)]
3604 pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
3605
3606 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3607 /// specified byte offset from the start of the DataView.
3608 ///
3609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3610 #[wasm_bindgen(method, js_name = setFloat32)]
3611 pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
3612
3613 /// The `setFloat16()` method stores a signed 16-bit float value from an
3614 /// `f32` at the specified byte offset from the start of the DataView.
3615 ///
3616 /// The unsuffixed `set_float16` name is reserved for a future native
3617 /// `f16` binding once Rust stabilizes the type.
3618 ///
3619 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16)
3620 #[wasm_bindgen(method, js_name = setFloat16)]
3621 pub fn set_float16_from_f32(this: &DataView, byte_offset: usize, value: f32);
3622
3623 /// The `setFloat16()` method stores a signed 16-bit float value from an
3624 /// `f32` at the specified byte offset from the start of the DataView.
3625 ///
3626 /// The unsuffixed `set_float16_endian` name is reserved for a future
3627 /// native `f16` binding once Rust stabilizes the type.
3628 ///
3629 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16)
3630 #[wasm_bindgen(method, js_name = setFloat16)]
3631 pub fn set_float16_endian_from_f32(
3632 this: &DataView,
3633 byte_offset: usize,
3634 value: f32,
3635 little_endian: bool,
3636 );
3637
3638 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3639 /// specified byte offset from the start of the DataView.
3640 ///
3641 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3642 #[wasm_bindgen(method, js_name = setFloat64)]
3643 pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
3644
3645 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3646 /// specified byte offset from the start of the DataView.
3647 ///
3648 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3649 #[wasm_bindgen(method, js_name = setFloat64)]
3650 pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
3651}
3652
3653// Error
3654#[wasm_bindgen]
3655extern "C" {
3656 #[wasm_bindgen(extends = Object, typescript_type = "Error")]
3657 #[derive(Clone, Debug, PartialEq, Eq)]
3658 pub type Error;
3659
3660 /// The Error constructor creates an error object.
3661 /// Instances of Error objects are thrown when runtime errors occur.
3662 /// The Error object can also be used as a base object for user-defined exceptions.
3663 /// See below for standard built-in error types.
3664 ///
3665 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
3666 #[wasm_bindgen(constructor)]
3667 pub fn new(message: &str) -> Error;
3668
3669 /// Creates a new `Error` with the given message and an untyped options
3670 /// object whose `cause` property indicates the original cause of the
3671 /// error.
3672 ///
3673 /// New code should prefer [`Error::new_with_error_options`], which takes
3674 /// a typed [`ErrorOptions`] dictionary.
3675 ///
3676 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
3677 #[wasm_bindgen(constructor)]
3678 pub fn new_with_options(message: &str, options: &Object) -> Error;
3679
3680 /// Creates a new `Error` with the given message and a typed
3681 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
3682 /// original cause of the error.
3683 ///
3684 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
3685 #[wasm_bindgen(constructor)]
3686 pub fn new_with_error_options(message: &str, options: &ErrorOptions) -> Error;
3687
3688 /// The cause property is the underlying cause of the error.
3689 /// Usually this is used to add context to re-thrown errors.
3690 ///
3691 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors)
3692 #[wasm_bindgen(method, getter)]
3693 pub fn cause(this: &Error) -> JsValue;
3694 #[wasm_bindgen(method, setter)]
3695 pub fn set_cause(this: &Error, cause: &JsValue);
3696
3697 /// The message property is a human-readable description of the error.
3698 ///
3699 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
3700 #[wasm_bindgen(method, getter)]
3701 pub fn message(this: &Error) -> JsString;
3702 #[wasm_bindgen(method, setter)]
3703 pub fn set_message(this: &Error, message: &str);
3704
3705 /// The name property represents a name for the type of error. The initial value is "Error".
3706 ///
3707 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
3708 #[wasm_bindgen(method, getter)]
3709 pub fn name(this: &Error) -> JsString;
3710 #[wasm_bindgen(method, setter)]
3711 pub fn set_name(this: &Error, name: &str);
3712
3713 /// The `toString()` method returns a string representing the specified Error object
3714 ///
3715 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
3716 #[cfg(not(js_sys_unstable_apis))]
3717 #[wasm_bindgen(method, js_name = toString)]
3718 pub fn to_string(this: &Error) -> JsString;
3719
3720 /// The `Error.stackTraceLimit` property controls the number of stack
3721 /// frames collected by a stack trace.
3722 ///
3723 /// This is a non-standard V8/Node.js API.
3724 ///
3725 /// [V8 documentation](https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions)
3726 #[wasm_bindgen(static_method_of = Error, getter, js_name = stackTraceLimit)]
3727 pub fn stack_trace_limit() -> JsValue;
3728
3729 /// Set `Error.stackTraceLimit` to control the number of stack frames
3730 /// collected by a stack trace.
3731 ///
3732 /// This is a non-standard V8/Node.js API.
3733 ///
3734 /// [V8 documentation](https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions)
3735 #[wasm_bindgen(static_method_of = Error, setter, js_name = stackTraceLimit)]
3736 pub fn set_stack_trace_limit(value: &JsValue);
3737}
3738
3739partialord_ord!(JsString);
3740
3741// EvalError
3742#[wasm_bindgen]
3743extern "C" {
3744 #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
3745 #[derive(Clone, Debug, PartialEq, Eq)]
3746 pub type EvalError;
3747
3748 /// The `EvalError` object indicates an error regarding the global eval() function. This
3749 /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
3750 /// compatibility.
3751 ///
3752 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
3753 #[wasm_bindgen(constructor)]
3754 pub fn new(message: &str) -> EvalError;
3755
3756 /// Creates a new `EvalError` with the given message and a typed
3757 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
3758 /// original cause of the error.
3759 ///
3760 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError/EvalError)
3761 #[wasm_bindgen(constructor)]
3762 pub fn new_with_options(message: &str, options: &ErrorOptions) -> EvalError;
3763}
3764
3765#[wasm_bindgen]
3766extern "C" {
3767 #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, no_upcast, typescript_type = "Function")]
3768 #[derive(Clone, Debug, PartialEq, Eq)]
3769 /// `Function` represents any generic Function in JS, by treating all arguments as `JsValue`.
3770 ///
3771 /// It takes a generic parameter of phantom type `fn (Arg1, ..., Argn) -> Ret` which
3772 /// is used to type the JS function. For example, `Function<fn () -> Number>` represents
3773 /// a function taking no arguments that returns a number.
3774 ///
3775 /// The 8 generic argument parameters (`Arg1` through `Arg8`) are the argument
3776 /// types. Arguments not provided enable strict arity checking at compile time.
3777 ///
3778 /// A void function is represented by `fn (Arg) -> Undefined`, and **not** the `()` unit
3779 /// type. This is because generics must be based on JS values in the JS generic type system.
3780 ///
3781 /// _The default without any parameters is as a void function - no arguments, `Undefined` return._
3782 ///
3783 /// _The default generic for `Function` is `fn (JsValue, JsValue, ...) -> JsValue`,
3784 /// representing any function, since all functions safely upcast into this function._
3785 ///
3786 /// ### Arity Enforcement
3787 ///
3788 /// It is not possible to use `call4` or `bind4` on a function that does not have
3789 /// at least 4 arguments — the compiler will reject this because only arguments that
3790 /// are not `None` support the trait bound for `ErasableGeneric`.
3791 ///
3792 /// ### Examples
3793 ///
3794 /// ```ignore
3795 /// // A function taking no args, returning Number
3796 /// let f: Function<Number> = get_some_fn();
3797 ///
3798 /// // A function taking (String, Number) and returning Boolean
3799 /// let f: Function<Boolean, String, Number> = get_some_fn();
3800 ///
3801 /// ### Upcasting
3802 ///
3803 /// To pass a typed `Function` where a different generic Function is expected, `upcast()` may be used
3804 /// to convert into any generic `Function` at zero cost with type-safety.
3805 ///
3806 /// MDN documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3807 pub type Function<
3808 T: JsFunction = fn(
3809 JsValue,
3810 JsValue,
3811 JsValue,
3812 JsValue,
3813 JsValue,
3814 JsValue,
3815 JsValue,
3816 JsValue,
3817 ) -> JsValue,
3818 >;
3819}
3820
3821#[wasm_bindgen]
3822extern "C" {
3823 /// The `Function` constructor creates a new `Function` object. Calling the
3824 /// constructor directly can create functions dynamically, but suffers from
3825 /// security and similar (but far less significant) performance issues
3826 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3827 /// allows executing code in the global scope, prompting better programming
3828 /// habits and allowing for more efficient code minification.
3829 ///
3830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3831 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3832 #[wasm_bindgen(constructor)]
3833 pub fn new_with_args(args: &str, body: &str) -> Function;
3834
3835 /// The `Function` constructor creates a new `Function` object. Calling the
3836 /// constructor directly can create functions dynamically, but suffers from
3837 /// security and similar (but far less significant) performance issues
3838 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3839 /// allows executing code in the global scope, prompting better programming
3840 /// habits and allowing for more efficient code minification.
3841 ///
3842 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3843 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3844 #[wasm_bindgen(constructor)]
3845 pub fn new_with_args<T: JsFunction = fn() -> JsValue>(args: &str, body: &str) -> Function<T>;
3846
3847 // Next major: deprecate
3848 /// The `Function` constructor creates a new `Function` object. Calling the
3849 /// constructor directly can create functions dynamically, but suffers from
3850 /// security and similar (but far less significant) performance issues
3851 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3852 /// allows executing code in the global scope, prompting better programming
3853 /// habits and allowing for more efficient code minification.
3854 ///
3855 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3856 #[cfg(feature = "unsafe-eval")]
3857 #[wasm_bindgen(constructor)]
3858 pub fn new_with_args_typed<T: JsFunction = fn() -> JsValue>(
3859 args: &str,
3860 body: &str,
3861 ) -> Function<T>;
3862
3863 /// The `Function` constructor creates a new `Function` object. Calling the
3864 /// constructor directly can create functions dynamically, but suffers from
3865 /// security and similar (but far less significant) performance issues
3866 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3867 /// allows executing code in the global scope, prompting better programming
3868 /// habits and allowing for more efficient code minification.
3869 ///
3870 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3871 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3872 #[wasm_bindgen(constructor)]
3873 pub fn new_no_args(body: &str) -> Function;
3874
3875 /// The `Function` constructor creates a new `Function` object. Calling the
3876 /// constructor directly can create functions dynamically, but suffers from
3877 /// security and similar (but far less significant) performance issues
3878 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3879 /// allows executing code in the global scope, prompting better programming
3880 /// habits and allowing for more efficient code minification.
3881 ///
3882 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3883 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3884 #[wasm_bindgen(constructor)]
3885 pub fn new_no_args<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3886
3887 // Next major: deprecate
3888 /// The `Function` constructor creates a new `Function` object.
3889 ///
3890 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3891 #[cfg(feature = "unsafe-eval")]
3892 #[wasm_bindgen(constructor)]
3893 pub fn new_no_args_typed<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3894
3895 /// The `apply()` method calls a function with a given this value, and arguments provided as an array
3896 /// (or an array-like object).
3897 ///
3898 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
3899 #[wasm_bindgen(method, catch)]
3900 pub fn apply<T: JsFunction = fn() -> JsValue>(
3901 this: &Function<T>,
3902 context: &JsValue,
3903 args: &Array,
3904 ) -> Result<<T as JsFunction>::Ret, JsValue>;
3905
3906 // Next major: Deprecate, and separately provide provide impl
3907 /// The `call()` method calls a function with a given this value and
3908 /// arguments provided individually.
3909 ///
3910 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3911 ///
3912 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3913 #[wasm_bindgen(method, catch, js_name = call)]
3914 pub fn call0<Ret: JsGeneric, F: JsFunction<Ret = Ret> = fn() -> JsValue>(
3915 this: &Function<F>,
3916 context: &JsValue,
3917 ) -> Result<Ret, JsValue>;
3918
3919 // Next major: Deprecate, and separately provide provide impl
3920 /// The `call()` method calls a function with a given this value and
3921 /// arguments provided individually.
3922 ///
3923 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3924 ///
3925 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3926 #[wasm_bindgen(method, catch, js_name = call)]
3927 pub fn call1<
3928 Ret: JsGeneric,
3929 Arg1: JsGeneric,
3930 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> = fn(JsValue) -> JsValue,
3931 >(
3932 this: &Function<F>,
3933 context: &JsValue,
3934 arg1: &Arg1,
3935 ) -> Result<Ret, JsValue>;
3936
3937 // Next major: Deprecate, and separately provide provide impl
3938 /// The `call()` method calls a function with a given this value and
3939 /// arguments provided individually.
3940 ///
3941 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3942 ///
3943 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3944 #[wasm_bindgen(method, catch, js_name = call)]
3945 pub fn call2<
3946 Ret: JsGeneric,
3947 Arg1: JsGeneric,
3948 Arg2: JsGeneric,
3949 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> + JsFunction2<Arg2 = Arg2> = fn(
3950 JsValue,
3951 JsValue,
3952 ) -> JsValue,
3953 >(
3954 this: &Function<F>,
3955 context: &JsValue,
3956 arg1: &Arg1,
3957 arg2: &Arg2,
3958 ) -> Result<Ret, JsValue>;
3959
3960 // Next major: Deprecate, and separately provide provide impl
3961 /// The `call()` method calls a function with a given this value and
3962 /// arguments provided individually.
3963 ///
3964 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3965 ///
3966 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3967 #[wasm_bindgen(method, catch, js_name = call)]
3968 pub fn call3<
3969 Ret: JsGeneric,
3970 Arg1: JsGeneric,
3971 Arg2: JsGeneric,
3972 Arg3: JsGeneric,
3973 F: JsFunction<Ret = Ret> + JsFunction3<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
3974 JsValue,
3975 JsValue,
3976 JsValue,
3977 ) -> JsValue,
3978 >(
3979 this: &Function<F>,
3980 context: &JsValue,
3981 arg1: &Arg1,
3982 arg2: &Arg2,
3983 arg3: &Arg3,
3984 ) -> Result<Ret, JsValue>;
3985
3986 // Next major: Deprecate, and separately provide provide impl
3987 /// The `call()` method calls a function with a given this value and
3988 /// arguments provided individually.
3989 ///
3990 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3991 ///
3992 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3993 #[wasm_bindgen(method, catch, js_name = call)]
3994 pub fn call4<
3995 Ret: JsGeneric,
3996 Arg1: JsGeneric,
3997 Arg2: JsGeneric,
3998 Arg3: JsGeneric,
3999 Arg4: JsGeneric,
4000 F: JsFunction<Ret = Ret> + JsFunction4<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
4001 JsValue,
4002 JsValue,
4003 JsValue,
4004 JsValue,
4005 ) -> JsValue,
4006 >(
4007 this: &Function<F>,
4008 context: &JsValue,
4009 arg1: &Arg1,
4010 arg2: &Arg2,
4011 arg3: &Arg3,
4012 arg4: &Arg4,
4013 ) -> Result<Ret, JsValue>;
4014
4015 // Next major: Deprecate, and separately provide provide impl
4016 /// The `call()` method calls a function with a given this value and
4017 /// arguments provided individually.
4018 ///
4019 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4020 ///
4021 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4022 #[wasm_bindgen(method, catch, js_name = call)]
4023 pub fn call5<
4024 Ret: JsGeneric,
4025 Arg1: JsGeneric,
4026 Arg2: JsGeneric,
4027 Arg3: JsGeneric,
4028 Arg4: JsGeneric,
4029 Arg5: JsGeneric,
4030 F: JsFunction<Ret = Ret>
4031 + JsFunction5<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4032 JsValue,
4033 JsValue,
4034 JsValue,
4035 JsValue,
4036 JsValue,
4037 ) -> JsValue,
4038 >(
4039 this: &Function<F>,
4040 context: &JsValue,
4041 arg1: &Arg1,
4042 arg2: &Arg2,
4043 arg3: &Arg3,
4044 arg4: &Arg4,
4045 arg5: &Arg5,
4046 ) -> Result<Ret, JsValue>;
4047
4048 // Next major: Deprecate, and separately provide provide impl
4049 /// The `call()` method calls a function with a given this value and
4050 /// arguments provided individually.
4051 ///
4052 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4053 ///
4054 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4055 #[wasm_bindgen(method, catch, js_name = call)]
4056 pub fn call6<
4057 Ret: JsGeneric,
4058 Arg1: JsGeneric,
4059 Arg2: JsGeneric,
4060 Arg3: JsGeneric,
4061 Arg4: JsGeneric,
4062 Arg5: JsGeneric,
4063 Arg6: JsGeneric,
4064 F: JsFunction<Ret = Ret>
4065 + JsFunction6<
4066 Arg1 = Arg1,
4067 Arg2 = Arg2,
4068 Arg3 = Arg3,
4069 Arg4 = Arg4,
4070 Arg5 = Arg5,
4071 Arg6 = Arg6,
4072 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4073 >(
4074 this: &Function<F>,
4075 context: &JsValue,
4076 arg1: &Arg1,
4077 arg2: &Arg2,
4078 arg3: &Arg3,
4079 arg4: &Arg4,
4080 arg5: &Arg5,
4081 arg6: &Arg6,
4082 ) -> Result<Ret, JsValue>;
4083
4084 // Next major: Deprecate, and separately provide provide impl
4085 /// The `call()` method calls a function with a given this value and
4086 /// arguments provided individually.
4087 ///
4088 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4089 ///
4090 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4091 #[wasm_bindgen(method, catch, js_name = call)]
4092 pub fn call7<
4093 Ret: JsGeneric,
4094 Arg1: JsGeneric,
4095 Arg2: JsGeneric,
4096 Arg3: JsGeneric,
4097 Arg4: JsGeneric,
4098 Arg5: JsGeneric,
4099 Arg6: JsGeneric,
4100 Arg7: JsGeneric,
4101 F: JsFunction<Ret = Ret>
4102 + JsFunction7<
4103 Arg1 = Arg1,
4104 Arg2 = Arg2,
4105 Arg3 = Arg3,
4106 Arg4 = Arg4,
4107 Arg5 = Arg5,
4108 Arg6 = Arg6,
4109 Arg7 = Arg7,
4110 > = fn(
4111 JsValue,
4112 JsValue,
4113 JsValue,
4114 JsValue,
4115 JsValue,
4116 JsValue,
4117 JsValue,
4118 ) -> JsValue,
4119 >(
4120 this: &Function<F>,
4121 context: &JsValue,
4122 arg1: &Arg1,
4123 arg2: &Arg2,
4124 arg3: &Arg3,
4125 arg4: &Arg4,
4126 arg5: &Arg5,
4127 arg6: &Arg6,
4128 arg7: &Arg7,
4129 ) -> Result<Ret, JsValue>;
4130
4131 // Next major: Deprecate, and separately provide provide impl
4132 /// The `call()` method calls a function with a given this value and
4133 /// arguments provided individually.
4134 ///
4135 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4136 ///
4137 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4138 #[wasm_bindgen(method, catch, js_name = call)]
4139 pub fn call8<
4140 Ret: JsGeneric,
4141 Arg1: JsGeneric,
4142 Arg2: JsGeneric,
4143 Arg3: JsGeneric,
4144 Arg4: JsGeneric,
4145 Arg5: JsGeneric,
4146 Arg6: JsGeneric,
4147 Arg7: JsGeneric,
4148 Arg8: JsGeneric,
4149 F: JsFunction8<
4150 Ret = Ret,
4151 Arg1 = Arg1,
4152 Arg2 = Arg2,
4153 Arg3 = Arg3,
4154 Arg4 = Arg4,
4155 Arg5 = Arg5,
4156 Arg6 = Arg6,
4157 Arg7 = Arg7,
4158 Arg8 = Arg8,
4159 > = fn(
4160 JsValue,
4161 JsValue,
4162 JsValue,
4163 JsValue,
4164 JsValue,
4165 JsValue,
4166 JsValue,
4167 JsValue,
4168 ) -> JsValue,
4169 >(
4170 this: &Function<F>,
4171 context: &JsValue,
4172 arg1: &Arg1,
4173 arg2: &Arg2,
4174 arg3: &Arg3,
4175 arg4: &Arg4,
4176 arg5: &Arg5,
4177 arg6: &Arg6,
4178 arg7: &Arg7,
4179 arg8: &Arg8,
4180 ) -> Result<Ret, JsValue>;
4181
4182 /// The `call()` method calls a function with a given this value and
4183 /// arguments provided individually.
4184 ///
4185 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4186 ///
4187 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4188 #[deprecated]
4189 #[allow(deprecated)]
4190 #[wasm_bindgen(method, catch, js_name = call)]
4191 pub fn call9<
4192 Ret: JsGeneric,
4193 Arg1: JsGeneric,
4194 Arg2: JsGeneric,
4195 Arg3: JsGeneric,
4196 Arg4: JsGeneric,
4197 Arg5: JsGeneric,
4198 Arg6: JsGeneric,
4199 Arg7: JsGeneric,
4200 Arg8: JsGeneric,
4201 F: JsFunction8<
4202 Ret = Ret,
4203 Arg1 = Arg1,
4204 Arg2 = Arg2,
4205 Arg3 = Arg3,
4206 Arg4 = Arg4,
4207 Arg5 = Arg5,
4208 Arg6 = Arg6,
4209 Arg7 = Arg7,
4210 Arg8 = Arg8,
4211 > = fn(
4212 JsValue,
4213 JsValue,
4214 JsValue,
4215 JsValue,
4216 JsValue,
4217 JsValue,
4218 JsValue,
4219 JsValue,
4220 ) -> JsValue,
4221 >(
4222 this: &Function<F>,
4223 context: &JsValue,
4224 arg1: &Arg1,
4225 arg2: &Arg2,
4226 arg3: &Arg3,
4227 arg4: &Arg4,
4228 arg5: &Arg5,
4229 arg6: &Arg6,
4230 arg7: &Arg7,
4231 arg8: &Arg8,
4232 arg9: &JsValue,
4233 ) -> Result<Ret, JsValue>;
4234
4235 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4236 /// with a given sequence of arguments preceding any provided when the new function is called.
4237 ///
4238 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4239 #[cfg(not(js_sys_unstable_apis))]
4240 #[deprecated(note = "Use `Function::bind0` instead.")]
4241 #[allow(deprecated)]
4242 #[wasm_bindgen(method, js_name = bind)]
4243 pub fn bind<T: JsFunction = fn() -> JsValue>(
4244 this: &Function<T>,
4245 context: &JsValue,
4246 ) -> Function<T>;
4247
4248 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4249 /// with a given sequence of arguments preceding any provided when the new function is called.
4250 ///
4251 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4252 ///
4253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4254 #[wasm_bindgen(method, js_name = bind)]
4255 pub fn bind0<T: JsFunction = fn() -> JsValue>(
4256 this: &Function<T>,
4257 context: &JsValue,
4258 ) -> Function<T>;
4259
4260 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4261 /// with a given sequence of arguments preceding any provided when the new function is called.
4262 ///
4263 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4264 ///
4265 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4266 #[wasm_bindgen(method, js_name = bind)]
4267 pub fn bind1<
4268 Ret: JsGeneric,
4269 Arg1: JsGeneric,
4270 F: JsFunction1<Ret = Ret, Arg1 = Arg1> = fn(JsValue) -> JsValue,
4271 >(
4272 this: &Function<F>,
4273 context: &JsValue,
4274 arg1: &Arg1,
4275 ) -> Function<<F as JsFunction1>::Bind1>;
4276
4277 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4278 /// with a given sequence of arguments preceding any provided when the new function is called.
4279 ///
4280 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4281 ///
4282 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4283 #[wasm_bindgen(method, js_name = bind)]
4284 pub fn bind2<
4285 Ret: JsGeneric,
4286 Arg1: JsGeneric,
4287 Arg2: JsGeneric,
4288 F: JsFunction2<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2> = fn(JsValue, JsValue) -> JsValue,
4289 >(
4290 this: &Function<F>,
4291 context: &JsValue,
4292 arg1: &Arg1,
4293 arg2: &Arg2,
4294 ) -> Function<<F as JsFunction2>::Bind2>;
4295
4296 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4297 /// with a given sequence of arguments preceding any provided when the new function is called.
4298 ///
4299 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4300 ///
4301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4302 #[wasm_bindgen(method, js_name = bind)]
4303 pub fn bind3<
4304 Ret: JsGeneric,
4305 Arg1: JsGeneric,
4306 Arg2: JsGeneric,
4307 Arg3: JsGeneric,
4308 F: JsFunction3<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
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 ) -> Function<<F as JsFunction3>::Bind3>;
4320
4321 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4322 /// with a given sequence of arguments preceding any provided when the new function is called.
4323 ///
4324 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4325 ///
4326 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4327 #[wasm_bindgen(method, js_name = bind)]
4328 pub fn bind4<
4329 Ret: JsGeneric,
4330 Arg1: JsGeneric,
4331 Arg2: JsGeneric,
4332 Arg3: JsGeneric,
4333 Arg4: JsGeneric,
4334 F: JsFunction4<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
4335 JsValue,
4336 JsValue,
4337 JsValue,
4338 JsValue,
4339 ) -> JsValue,
4340 >(
4341 this: &Function<F>,
4342 context: &JsValue,
4343 arg1: &Arg1,
4344 arg2: &Arg2,
4345 arg3: &Arg3,
4346 arg4: &Arg4,
4347 ) -> Function<<F as JsFunction4>::Bind4>;
4348
4349 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4350 /// with a given sequence of arguments preceding any provided when the new function is called.
4351 ///
4352 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4353 ///
4354 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4355 #[wasm_bindgen(method, js_name = bind)]
4356 pub fn bind5<
4357 Ret: JsGeneric,
4358 Arg1: JsGeneric,
4359 Arg2: JsGeneric,
4360 Arg3: JsGeneric,
4361 Arg4: JsGeneric,
4362 Arg5: JsGeneric,
4363 F: JsFunction5<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4364 JsValue,
4365 JsValue,
4366 JsValue,
4367 JsValue,
4368 JsValue,
4369 ) -> JsValue,
4370 >(
4371 this: &Function<F>,
4372 context: &JsValue,
4373 arg1: &Arg1,
4374 arg2: &Arg2,
4375 arg3: &Arg3,
4376 arg4: &Arg4,
4377 arg5: &Arg5,
4378 ) -> Function<<F as JsFunction5>::Bind5>;
4379
4380 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4381 /// with a given sequence of arguments preceding any provided when the new function is called.
4382 ///
4383 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4384 ///
4385 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4386 #[wasm_bindgen(method, js_name = bind)]
4387 pub fn bind6<
4388 Ret: JsGeneric,
4389 Arg1: JsGeneric,
4390 Arg2: JsGeneric,
4391 Arg3: JsGeneric,
4392 Arg4: JsGeneric,
4393 Arg5: JsGeneric,
4394 Arg6: JsGeneric,
4395 F: JsFunction6<
4396 Ret = Ret,
4397 Arg1 = Arg1,
4398 Arg2 = Arg2,
4399 Arg3 = Arg3,
4400 Arg4 = Arg4,
4401 Arg5 = Arg5,
4402 Arg6 = Arg6,
4403 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4404 >(
4405 this: &Function<F>,
4406 context: &JsValue,
4407 arg1: &Arg1,
4408 arg2: &Arg2,
4409 arg3: &Arg3,
4410 arg4: &Arg4,
4411 arg5: &Arg5,
4412 arg6: &Arg6,
4413 ) -> Function<<F as JsFunction6>::Bind6>;
4414
4415 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4416 /// with a given sequence of arguments preceding any provided when the new function is called.
4417 ///
4418 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4419 ///
4420 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4421 #[wasm_bindgen(method, js_name = bind)]
4422 pub fn bind7<
4423 Ret: JsGeneric,
4424 Arg1: JsGeneric,
4425 Arg2: JsGeneric,
4426 Arg3: JsGeneric,
4427 Arg4: JsGeneric,
4428 Arg5: JsGeneric,
4429 Arg6: JsGeneric,
4430 Arg7: JsGeneric,
4431 F: JsFunction7<
4432 Ret = Ret,
4433 Arg1 = Arg1,
4434 Arg2 = Arg2,
4435 Arg3 = Arg3,
4436 Arg4 = Arg4,
4437 Arg5 = Arg5,
4438 Arg6 = Arg6,
4439 Arg7 = Arg7,
4440 > = fn(
4441 JsValue,
4442 JsValue,
4443 JsValue,
4444 JsValue,
4445 JsValue,
4446 JsValue,
4447 JsValue,
4448 ) -> JsValue,
4449 >(
4450 this: &Function<F>,
4451 context: &JsValue,
4452 arg1: &Arg1,
4453 arg2: &Arg2,
4454 arg3: &Arg3,
4455 arg4: &Arg4,
4456 arg5: &Arg5,
4457 arg6: &Arg6,
4458 arg7: &Arg7,
4459 ) -> Function<<F as JsFunction7>::Bind7>;
4460
4461 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4462 /// with a given sequence of arguments preceding any provided when the new function is called.
4463 ///
4464 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4465 ///
4466 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4467 #[wasm_bindgen(method, js_name = bind)]
4468 pub fn bind8<
4469 Ret: JsGeneric,
4470 Arg1: JsGeneric,
4471 Arg2: JsGeneric,
4472 Arg3: JsGeneric,
4473 Arg4: JsGeneric,
4474 Arg5: JsGeneric,
4475 Arg6: JsGeneric,
4476 Arg7: JsGeneric,
4477 Arg8: JsGeneric,
4478 F: JsFunction8<
4479 Ret = Ret,
4480 Arg1 = Arg1,
4481 Arg2 = Arg2,
4482 Arg3 = Arg3,
4483 Arg4 = Arg4,
4484 Arg5 = Arg5,
4485 Arg6 = Arg6,
4486 Arg7 = Arg7,
4487 Arg8 = Arg8,
4488 > = fn(
4489 JsValue,
4490 JsValue,
4491 JsValue,
4492 JsValue,
4493 JsValue,
4494 JsValue,
4495 JsValue,
4496 JsValue,
4497 ) -> JsValue,
4498 >(
4499 this: &Function<F>,
4500 context: &JsValue,
4501 arg1: &Arg1,
4502 arg2: &Arg2,
4503 arg3: &Arg3,
4504 arg4: &Arg4,
4505 arg5: &Arg5,
4506 arg6: &Arg6,
4507 arg7: &Arg7,
4508 arg8: &Arg8,
4509 ) -> Function<<F as JsFunction8>::Bind8>;
4510
4511 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4512 /// with a given sequence of arguments preceding any provided when the new function is called.
4513 ///
4514 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4515 ///
4516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4517 #[deprecated]
4518 #[allow(deprecated)]
4519 #[wasm_bindgen(method, js_name = bind)]
4520 pub fn bind9<
4521 Ret: JsGeneric,
4522 Arg1: JsGeneric,
4523 Arg2: JsGeneric,
4524 Arg3: JsGeneric,
4525 Arg4: JsGeneric,
4526 Arg5: JsGeneric,
4527 Arg6: JsGeneric,
4528 Arg7: JsGeneric,
4529 Arg8: JsGeneric,
4530 F: JsFunction8<
4531 Ret = Ret,
4532 Arg1 = Arg1,
4533 Arg2 = Arg2,
4534 Arg3 = Arg3,
4535 Arg4 = Arg4,
4536 Arg5 = Arg5,
4537 Arg6 = Arg6,
4538 Arg7 = Arg7,
4539 Arg8 = Arg8,
4540 > = fn(
4541 JsValue,
4542 JsValue,
4543 JsValue,
4544 JsValue,
4545 JsValue,
4546 JsValue,
4547 JsValue,
4548 JsValue,
4549 ) -> JsValue,
4550 >(
4551 this: &Function<F>,
4552 context: &JsValue,
4553 arg1: &Arg1,
4554 arg2: &Arg2,
4555 arg3: &Arg3,
4556 arg4: &Arg4,
4557 arg5: &Arg5,
4558 arg6: &Arg6,
4559 arg7: &Arg7,
4560 arg8: &Arg8,
4561 arg9: &JsValue,
4562 ) -> Function<fn() -> Ret>;
4563
4564 /// The length property indicates the number of arguments expected by the function.
4565 ///
4566 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
4567 #[wasm_bindgen(method, getter)]
4568 pub fn length<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> u32;
4569
4570 /// A Function object's read-only name property indicates the function's
4571 /// name as specified when it was created or "anonymous" for functions
4572 /// created anonymously.
4573 ///
4574 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
4575 #[wasm_bindgen(method, getter)]
4576 pub fn name<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4577
4578 /// The `toString()` method returns a string representing the source code of the function.
4579 ///
4580 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
4581 #[cfg(not(js_sys_unstable_apis))]
4582 #[wasm_bindgen(method, js_name = toString)]
4583 pub fn to_string<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4584}
4585
4586// Basic UpcastFrom impls for Function<T>
4587impl<T: JsFunction> UpcastFrom<Function<T>> for JsValue {}
4588impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<JsValue> {}
4589impl<T: JsFunction> UpcastFrom<Function<T>> for JsNullable<JsValue> {}
4590impl<T: JsFunction> UpcastFrom<Function<T>> for Object {}
4591impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<Object> {}
4592impl<T: JsFunction> UpcastFrom<Function<T>> for JsNullable<Object> {}
4593
4594// Blanket trait for Function upcast
4595// Function<T> upcasts to Function<U> when the underlying fn type T upcasts to U.
4596// The fn signature UpcastFrom impls already encode correct variance (covariant return, contravariant args).
4597impl<T: JsFunction, U: JsFunction> UpcastFrom<Function<T>> for Function<U> where U: UpcastFrom<T> {}
4598
4599// len() method for Function<T> using JsFunction::ARITY
4600impl<T: JsFunction> Function<T> {
4601 /// Get the static arity of this function type.
4602 #[allow(clippy::len_without_is_empty)]
4603 pub fn len(&self) -> usize {
4604 T::ARITY
4605 }
4606
4607 /// Returns true if this is a zero-argument function.
4608 pub fn is_empty(&self) -> bool {
4609 T::ARITY == 0
4610 }
4611}
4612
4613// Base traits for function signature types.
4614pub trait JsFunction {
4615 type Ret: JsGeneric;
4616 const ARITY: usize;
4617}
4618
4619pub trait JsFunction1: JsFunction {
4620 type Arg1: JsGeneric;
4621 type Bind1: JsFunction;
4622}
4623pub trait JsFunction2: JsFunction1 {
4624 type Arg2: JsGeneric;
4625 type Bind2: JsFunction;
4626}
4627pub trait JsFunction3: JsFunction2 {
4628 type Arg3: JsGeneric;
4629 type Bind3: JsFunction;
4630}
4631pub trait JsFunction4: JsFunction3 {
4632 type Arg4: JsGeneric;
4633 type Bind4: JsFunction;
4634}
4635pub trait JsFunction5: JsFunction4 {
4636 type Arg5: JsGeneric;
4637 type Bind5: JsFunction;
4638}
4639pub trait JsFunction6: JsFunction5 {
4640 type Arg6: JsGeneric;
4641 type Bind6: JsFunction;
4642}
4643pub trait JsFunction7: JsFunction6 {
4644 type Arg7: JsGeneric;
4645 type Bind7: JsFunction;
4646}
4647pub trait JsFunction8: JsFunction7 {
4648 type Arg8: JsGeneric;
4649 type Bind8: JsFunction;
4650}
4651
4652// Manual impl for fn() -> R
4653impl<Ret: JsGeneric> JsFunction for fn() -> Ret {
4654 type Ret = Ret;
4655 const ARITY: usize = 0;
4656}
4657
4658macro_rules! impl_fn {
4659 () => {
4660 impl_fn!(@impl 1 [Arg1] [
4661 JsFunction1 Arg1 Bind1 {fn() -> Ret}
4662 ]);
4663 impl_fn!(@impl 2 [Arg1 Arg2] [
4664 JsFunction1 Arg1 Bind1 {fn(Arg2) -> Ret}
4665 JsFunction2 Arg2 Bind2 {fn() -> Ret}
4666 ]);
4667 impl_fn!(@impl 3 [Arg1 Arg2 Arg3] [
4668 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3) -> Ret}
4669 JsFunction2 Arg2 Bind2 {fn(Arg3) -> Ret}
4670 JsFunction3 Arg3 Bind3 {fn() -> Ret}
4671 ]);
4672 impl_fn!(@impl 4 [Arg1 Arg2 Arg3 Arg4] [
4673 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4) -> Ret}
4674 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4) -> Ret}
4675 JsFunction3 Arg3 Bind3 {fn(Arg4) -> Ret}
4676 JsFunction4 Arg4 Bind4 {fn() -> Ret}
4677 ]);
4678 impl_fn!(@impl 5 [Arg1 Arg2 Arg3 Arg4 Arg5] [
4679 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5) -> Ret}
4680 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5) -> Ret}
4681 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5) -> Ret}
4682 JsFunction4 Arg4 Bind4 {fn(Arg5) -> Ret}
4683 JsFunction5 Arg5 Bind5 {fn() -> Ret}
4684 ]);
4685 impl_fn!(@impl 6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [
4686 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6) -> Ret}
4687 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6) -> Ret}
4688 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6) -> Ret}
4689 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6) -> Ret}
4690 JsFunction5 Arg5 Bind5 {fn(Arg6) -> Ret}
4691 JsFunction6 Arg6 Bind6 {fn() -> Ret}
4692 ]);
4693 impl_fn!(@impl 7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [
4694 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4695 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4696 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7) -> Ret}
4697 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7) -> Ret}
4698 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7) -> Ret}
4699 JsFunction6 Arg6 Bind6 {fn(Arg7) -> Ret}
4700 JsFunction7 Arg7 Bind7 {fn() -> Ret}
4701 ]);
4702 impl_fn!(@impl 8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [
4703 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4704 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4705 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4706 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7, Arg8) -> Ret}
4707 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7, Arg8) -> Ret}
4708 JsFunction6 Arg6 Bind6 {fn(Arg7, Arg8) -> Ret}
4709 JsFunction7 Arg7 Bind7 {fn(Arg8) -> Ret}
4710 JsFunction8 Arg8 Bind8 {fn() -> Ret}
4711 ]);
4712 };
4713
4714 (@impl $arity:literal [$($A:ident)+] [$($trait:ident $arg:ident $bind:ident {$bind_ty:ty})+]) => {
4715 impl<Ret: JsGeneric $(, $A: JsGeneric)+> JsFunction for fn($($A),+) -> Ret {
4716 type Ret = Ret;
4717 const ARITY: usize = $arity;
4718 }
4719
4720 impl_fn!(@traits [$($A)+] [$($trait $arg $bind {$bind_ty})+]);
4721 };
4722
4723 (@traits [$($A:ident)+] []) => {};
4724
4725 (@traits [$($A:ident)+] [$trait:ident $arg:ident $bind:ident {$bind_ty:ty} $($rest:tt)*]) => {
4726 impl<Ret: JsGeneric $(, $A: JsGeneric)+> $trait for fn($($A),+) -> Ret {
4727 type $arg = $arg;
4728 type $bind = $bind_ty;
4729 }
4730
4731 impl_fn!(@traits [$($A)+] [$($rest)*]);
4732 };
4733}
4734
4735impl_fn!();
4736
4737/// Trait for argument tuples that can call or bind a `Function<T>`.
4738pub trait JsArgs<T: JsFunction> {
4739 type BindOutput;
4740 fn apply_call(self, func: &Function<T>, context: &JsValue) -> Result<T::Ret, JsValue>;
4741 fn apply_bind(self, func: &Function<T>, context: &JsValue) -> Self::BindOutput;
4742}
4743
4744// Manual impl for 0-arg
4745impl<Ret: JsGeneric, F: JsFunction<Ret = Ret>> JsArgs<F> for () {
4746 type BindOutput = Function<F>;
4747
4748 #[inline]
4749 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4750 func.call0(context)
4751 }
4752
4753 #[inline]
4754 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4755 func.bind0(context)
4756 }
4757}
4758
4759macro_rules! impl_js_args {
4760 ($arity:literal $trait:ident $bind_output:ident [$($A:ident)+] [$($idx:tt)+] $call:ident $bind:ident) => {
4761 impl<Ret: JsGeneric, $($A: JsGeneric,)+ F: $trait<Ret = Ret, $($A = $A,)*>> JsArgs<F> for ($(&$A,)+)
4762 {
4763 type BindOutput = Function<<F as $trait>::$bind_output>;
4764
4765 #[inline]
4766 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4767 func.$call(context, $(self.$idx),+)
4768 }
4769
4770 #[inline]
4771 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4772 func.$bind(context, $(self.$idx),+)
4773 }
4774 }
4775 };
4776}
4777
4778impl_js_args!(1 JsFunction1 Bind1 [Arg1] [0] call1 bind1);
4779impl_js_args!(2 JsFunction2 Bind2 [Arg1 Arg2] [0 1] call2 bind2);
4780impl_js_args!(3 JsFunction3 Bind3 [Arg1 Arg2 Arg3] [0 1 2] call3 bind3);
4781impl_js_args!(4 JsFunction4 Bind4 [Arg1 Arg2 Arg3 Arg4] [0 1 2 3] call4 bind4);
4782impl_js_args!(5 JsFunction5 Bind5 [Arg1 Arg2 Arg3 Arg4 Arg5] [0 1 2 3 4] call5 bind5);
4783impl_js_args!(6 JsFunction6 Bind6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [0 1 2 3 4 5] call6 bind6);
4784impl_js_args!(7 JsFunction7 Bind7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [0 1 2 3 4 5 6] call7 bind7);
4785impl_js_args!(8 JsFunction8 Bind8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [0 1 2 3 4 5 6 7] call8 bind8);
4786
4787impl<T: JsFunction> Function<T> {
4788 /// The `call()` method calls a function with a given `this` value and
4789 /// arguments provided as a tuple.
4790 ///
4791 /// This method accepts a tuple of references matching the function's
4792 /// argument types.
4793 ///
4794 /// # Example
4795 ///
4796 /// ```ignore
4797 /// // 0-arg function
4798 /// let f: Function<fn() -> Number> = get_fn();
4799 /// let result = f.call(&JsValue::NULL, ())?;
4800 ///
4801 /// // 1-arg function (note trailing comma for 1-tuple)
4802 /// let f: Function<fn(JsString) -> Number> = get_fn();
4803 /// let result = f.call(&JsValue::NULL, (&name,))?;
4804 ///
4805 /// // 2-arg function
4806 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4807 /// let result = f.call(&JsValue::NULL, (&name, &flag))?;
4808 /// ```
4809 ///
4810 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4811 #[inline]
4812 pub fn call<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Result<T::Ret, JsValue> {
4813 args.apply_call(self, context)
4814 }
4815
4816 /// The `bind()` method creates a new function that, when called, has its
4817 /// `this` keyword set to the provided value, with a given sequence of
4818 /// arguments preceding any provided when the new function is called.
4819 ///
4820 /// This method accepts a tuple of references to bind.
4821 ///
4822 /// # Example
4823 ///
4824 /// ```ignore
4825 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4826 ///
4827 /// // Bind no args - same signature
4828 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4829 ///
4830 /// // Bind one arg (use 1-tuple of references)
4831 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4832 ///
4833 /// // Bind two args - becomes 0-arg function
4834 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4835 /// ```
4836 ///
4837 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4838 #[inline]
4839 pub fn bindn<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4840 args.apply_bind(self, context)
4841 }
4842
4843 /// The `bind()` method creates a new function that, when called, has its
4844 /// `this` keyword set to the provided value, with a given sequence of
4845 /// arguments preceding any provided when the new function is called.
4846 ///
4847 /// This method accepts a tuple of references to bind.
4848 ///
4849 /// # Example
4850 ///
4851 /// ```ignore
4852 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4853 ///
4854 /// // Bind no args - same signature
4855 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4856 ///
4857 /// // Bind one arg (use 1-tuple of references)
4858 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4859 ///
4860 /// // Bind two args - becomes 0-arg function
4861 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4862 /// ```
4863 ///
4864 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4865 #[cfg(js_sys_unstable_apis)]
4866 #[inline]
4867 pub fn bind<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4868 args.apply_bind(self, context)
4869 }
4870}
4871
4872pub trait FunctionIntoClosure: JsFunction {
4873 type ClosureTypeMut: WasmClosure + ?Sized;
4874}
4875
4876macro_rules! impl_function_into_closure {
4877 ( $(($($var:ident)*))* ) => {$(
4878 impl<$($var: FromWasmAbi + JsGeneric,)* R: IntoWasmAbi + JsGeneric> FunctionIntoClosure for fn($($var),*) -> R {
4879 type ClosureTypeMut = dyn FnMut($($var),*) -> R;
4880 }
4881 )*};
4882}
4883
4884impl_function_into_closure! {
4885 ()
4886 (A)
4887 (A B)
4888 (A B C)
4889 (A B C D)
4890 (A B C D E)
4891 (A B C D E F)
4892 (A B C D E F G)
4893 (A B C D E F G H)
4894}
4895
4896impl<F: JsFunction> Function<F> {
4897 /// Convert a borrowed `ScopedClosure` into a typed JavaScript Function reference.
4898 ///
4899 /// The conversion is a direct type-safe conversion and upcast of a
4900 /// closure into its corresponding typed JavaScript Function,
4901 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4902 ///
4903 /// For transferring ownership to JS, use [`Function::from_closure`].
4904 #[inline]
4905 pub fn closure_ref<'a, C>(closure: &'a ScopedClosure<'_, C>) -> &'a Self
4906 where
4907 F: FunctionIntoClosure,
4908 C: WasmClosure + ?Sized,
4909 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4910 {
4911 closure.as_js_value().unchecked_ref()
4912 }
4913
4914 /// Convert a Rust closure into a typed JavaScript Function.
4915 ///
4916 /// This function releases ownership of the closure to JS, and provides
4917 /// an owned function handle for the same closure.
4918 ///
4919 /// The conversion is a direct type-safe conversion and upcast of a
4920 /// closure into its corresponding typed JavaScript Function,
4921 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4922 ///
4923 /// This method is only supported for static closures which do not have
4924 /// borrowed lifetime data, and thus can be released into JS.
4925 ///
4926 /// For borrowed closures, which cannot cede ownership to JS,
4927 /// instead use [`Function::closure_ref`].
4928 #[inline]
4929 pub fn from_closure<C>(closure: ScopedClosure<'static, C>) -> Self
4930 where
4931 F: FunctionIntoClosure,
4932 C: WasmClosure + ?Sized,
4933 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4934 {
4935 closure.into_js_value().unchecked_into()
4936 }
4937}
4938
4939#[cfg(not(js_sys_unstable_apis))]
4940impl Function {
4941 /// Returns the `Function` value of this JS value if it's an instance of a
4942 /// function.
4943 ///
4944 /// If this JS value is not an instance of a function then this returns
4945 /// `None`.
4946 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
4947 pub fn try_from(val: &JsValue) -> Option<&Function> {
4948 val.dyn_ref()
4949 }
4950}
4951
4952#[cfg(feature = "unsafe-eval")]
4953impl Default for Function {
4954 fn default() -> Self {
4955 Self::new_no_args("")
4956 }
4957}
4958
4959// FinalizationRegistry
4960#[wasm_bindgen]
4961extern "C" {
4962 /// The `FinalizationRegistry` object lets you request a callback when an
4963 /// object is garbage-collected.
4964 ///
4965 /// `FinalizationRegistry` provides a way to request that a cleanup
4966 /// callback get called at some point when an object registered with the
4967 /// registry has been reclaimed (garbage-collected). Cleanup callbacks
4968 /// are sometimes called *finalizers*.
4969 ///
4970 /// Avoid where possible: cleanup callbacks should not be relied upon for
4971 /// anything essential. They are best used to reduce memory usage over the
4972 /// course of a program for objects that benefit from cleanup. Whether,
4973 /// when, and in what order callbacks fire is implementation-defined.
4974 ///
4975 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry)
4976 #[wasm_bindgen(extends = Object, typescript_type = "FinalizationRegistry<any>")]
4977 #[derive(Clone, Debug, PartialEq, Eq)]
4978 pub type FinalizationRegistry;
4979
4980 /// Creates a new `FinalizationRegistry` with the given cleanup callback.
4981 ///
4982 /// The cleanup callback is invoked, at some point after a registered
4983 /// target is garbage-collected, with the `held_value` that was passed to
4984 /// [`FinalizationRegistry::register`]. Because callbacks may be deferred
4985 /// or skipped entirely, the callback should normally outlive the
4986 /// `FinalizationRegistry` (for example by being created via
4987 /// [`Function::from_closure`]).
4988 ///
4989 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/FinalizationRegistry)
4990 #[wasm_bindgen(constructor)]
4991 pub fn new(cleanup_callback: &Function<fn(JsValue) -> Undefined>) -> FinalizationRegistry;
4992
4993 /// Registers `target` with this `FinalizationRegistry`. When `target` is
4994 /// reclaimed by the garbage collector the cleanup callback may be called
4995 /// with `held_value`.
4996 ///
4997 /// `target` must be an object (or a non-registered symbol).
4998 ///
4999 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/register)
5000 #[wasm_bindgen(method)]
5001 pub fn register(this: &FinalizationRegistry, target: &JsValue, held_value: &JsValue);
5002
5003 /// Registers `target` with this `FinalizationRegistry`, with an
5004 /// `unregister_token` that can later be passed to
5005 /// [`FinalizationRegistry::unregister`] to remove the registration.
5006 ///
5007 /// `target` and `unregister_token` must be objects (or non-registered
5008 /// symbols), and the same value may be passed for both.
5009 ///
5010 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/register)
5011 #[wasm_bindgen(method, js_name = register)]
5012 pub fn register_with_token(
5013 this: &FinalizationRegistry,
5014 target: &JsValue,
5015 held_value: &JsValue,
5016 unregister_token: &JsValue,
5017 );
5018
5019 /// Unregisters all entries registered with this `FinalizationRegistry`
5020 /// using `unregister_token`. Returns `true` if any cells were removed.
5021 ///
5022 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/unregister)
5023 #[wasm_bindgen(method)]
5024 pub fn unregister(this: &FinalizationRegistry, unregister_token: &JsValue) -> bool;
5025}
5026
5027// Generator
5028#[wasm_bindgen]
5029extern "C" {
5030 #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
5031 #[derive(Clone, Debug, PartialEq, Eq)]
5032 pub type Generator<T = JsValue>;
5033
5034 /// The `next()` method returns an object with two properties done and value.
5035 /// You can also provide a parameter to the next method to send a value to the generator.
5036 ///
5037 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5038 #[cfg(not(js_sys_unstable_apis))]
5039 #[wasm_bindgen(method, catch)]
5040 pub fn next<T>(this: &Generator<T>, value: &T) -> Result<JsValue, JsValue>;
5041
5042 /// The `next()` method returns an object with two properties done and value.
5043 /// You can also provide a parameter to the next method to send a value to the generator.
5044 ///
5045 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5046 #[cfg(js_sys_unstable_apis)]
5047 #[wasm_bindgen(method, catch, js_name = next)]
5048 pub fn next<T: FromWasmAbi>(this: &Generator<T>, value: &T)
5049 -> Result<IteratorNext<T>, JsValue>;
5050
5051 // Next major: deprecate
5052 /// The `next()` method returns an object with two properties done and value.
5053 /// You can also provide a parameter to the next method to send a value to the generator.
5054 ///
5055 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5056 #[wasm_bindgen(method, catch)]
5057 pub fn next_iterator<T: FromWasmAbi>(
5058 this: &Generator<T>,
5059 value: &T,
5060 ) -> Result<IteratorNext<T>, JsValue>;
5061
5062 /// The `return()` method returns the given value and finishes the generator.
5063 ///
5064 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5065 #[cfg(not(js_sys_unstable_apis))]
5066 #[wasm_bindgen(method, js_name = "return")]
5067 pub fn return_<T>(this: &Generator<T>, value: &T) -> JsValue;
5068
5069 /// The `return()` method returns the given value and finishes the generator.
5070 ///
5071 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5072 #[cfg(js_sys_unstable_apis)]
5073 #[wasm_bindgen(method, catch, js_name = "return")]
5074 pub fn return_<T: FromWasmAbi>(
5075 this: &Generator<T>,
5076 value: &T,
5077 ) -> Result<IteratorNext<T>, JsValue>;
5078
5079 // Next major: deprecate
5080 /// The `return()` method returns the given value and finishes the generator.
5081 ///
5082 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5083 #[wasm_bindgen(method, catch, js_name = "return")]
5084 pub fn try_return<T: FromWasmAbi>(
5085 this: &Generator<T>,
5086 value: &T,
5087 ) -> Result<IteratorNext<T>, JsValue>;
5088
5089 /// The `throw()` method resumes the execution of a generator by throwing an error into it
5090 /// and returns an object with two properties done and value.
5091 ///
5092 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5093 #[cfg(not(js_sys_unstable_apis))]
5094 #[wasm_bindgen(method, catch)]
5095 pub fn throw<T>(this: &Generator<T>, error: &Error) -> Result<JsValue, JsValue>;
5096
5097 /// The `throw()` method resumes the execution of a generator by throwing an error into it
5098 /// and returns an object with two properties done and value.
5099 ///
5100 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5101 #[cfg(js_sys_unstable_apis)]
5102 #[wasm_bindgen(method, catch, js_name = throw)]
5103 pub fn throw<T: FromWasmAbi>(
5104 this: &Generator<T>,
5105 error: &JsValue,
5106 ) -> Result<IteratorNext<T>, JsValue>;
5107
5108 // Next major: deprecate
5109 /// The `throw()` method resumes the execution of a generator by throwing an error into it
5110 /// and returns an object with two properties done and value.
5111 ///
5112 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5113 #[wasm_bindgen(method, catch, js_name = throw)]
5114 pub fn throw_value<T: FromWasmAbi>(
5115 this: &Generator<T>,
5116 error: &JsValue,
5117 ) -> Result<IteratorNext<T>, JsValue>;
5118}
5119
5120impl<T: FromWasmAbi> Iterable for Generator<T> {
5121 type Item = T;
5122}
5123
5124// AsyncGenerator
5125#[wasm_bindgen]
5126extern "C" {
5127 #[wasm_bindgen(extends = Object, typescript_type = "AsyncGenerator<any, any, any>")]
5128 #[derive(Clone, Debug, PartialEq, Eq)]
5129 pub type AsyncGenerator<T = JsValue>;
5130
5131 /// The `next()` method returns an object with two properties done and value.
5132 /// You can also provide a parameter to the next method to send a value to the generator.
5133 ///
5134 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/next)
5135 #[wasm_bindgen(method, catch)]
5136 pub fn next<T>(
5137 this: &AsyncGenerator<T>,
5138 value: &T,
5139 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5140
5141 /// The `return()` method returns the given value and finishes the generator.
5142 ///
5143 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/return)
5144 #[wasm_bindgen(method, js_name = "return", catch)]
5145 pub fn return_<T>(
5146 this: &AsyncGenerator<T>,
5147 value: &T,
5148 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5149
5150 /// The `throw()` method resumes the execution of a generator by throwing an error into it
5151 /// and returns an object with two properties done and value.
5152 ///
5153 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/throw)
5154 #[wasm_bindgen(method, catch)]
5155 pub fn throw<T>(
5156 this: &AsyncGenerator<T>,
5157 error: &JsValue,
5158 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5159}
5160
5161impl<T: FromWasmAbi> AsyncIterable for AsyncGenerator<T> {
5162 type Item = T;
5163}
5164
5165// Map
5166#[wasm_bindgen]
5167extern "C" {
5168 #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
5169 #[derive(Clone, Debug, PartialEq, Eq)]
5170 pub type Map<K = JsValue, V = JsValue>;
5171
5172 /// The Map object holds key-value pairs. Any value (both objects and
5173 /// primitive values) maybe used as either a key or a value.
5174 ///
5175 /// **Note:** Consider using [`Map::new_typed`] for typing support.
5176 ///
5177 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5178 #[cfg(not(js_sys_unstable_apis))]
5179 #[wasm_bindgen(constructor)]
5180 pub fn new() -> Map;
5181
5182 /// The Map object holds key-value pairs. Any value (both objects and
5183 /// primitive values) maybe used as either a key or a value.
5184 ///
5185 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5186 #[cfg(js_sys_unstable_apis)]
5187 #[wasm_bindgen(constructor)]
5188 pub fn new<K, V>() -> Map<K, V>;
5189
5190 // Next major: deprecate
5191 /// The Map object holds key-value pairs. Any value (both objects and
5192 /// primitive values) maybe used as either a key or a value.
5193 ///
5194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5195 #[wasm_bindgen(constructor)]
5196 pub fn new_typed<K, V>() -> Map<K, V>;
5197
5198 /// The Map object holds key-value pairs. Any value (both objects and
5199 /// primitive values) maybe used as either a key or a value.
5200 ///
5201 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5202 #[wasm_bindgen(constructor, js_name = new)]
5203 pub fn new_from_entries<K, V, I: Iterable<Item = ArrayTuple<(K, V)>>>(entries: &I)
5204 -> Map<K, V>;
5205
5206 /// The `clear()` method removes all elements from a Map object.
5207 ///
5208 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
5209 #[wasm_bindgen(method)]
5210 pub fn clear<K, V>(this: &Map<K, V>);
5211
5212 /// The `delete()` method removes the specified element from a Map object.
5213 ///
5214 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
5215 #[wasm_bindgen(method)]
5216 pub fn delete<K, V>(this: &Map<K, V>, key: &K) -> bool;
5217
5218 /// The `forEach()` method executes a provided function once per each
5219 /// key/value pair in the Map object, in insertion order.
5220 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
5221 /// # Examples
5222 /// ```
5223 /// let js_map = Map::new();
5224 /// js_map.for_each(&mut |value, key| {
5225 /// // Do something here...
5226 /// })
5227 /// ```
5228 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
5229 #[wasm_bindgen(method, js_name = forEach)]
5230 pub fn for_each<K, V>(this: &Map<K, V>, callback: &mut dyn FnMut(V, K));
5231
5232 /// The `forEach()` method executes a provided function once per each
5233 /// key/value pair in the Map object, in insertion order. _(Fallible variation)_
5234 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
5235 /// # Examples
5236 /// ```
5237 /// let js_map = Map::new();
5238 /// js_map.for_each(&mut |value, key| {
5239 /// // Do something here...
5240 /// })
5241 /// ```
5242 ///
5243 /// **Note:** Consider using [`Map::try_for_each`] if the callback might throw an error.
5244 ///
5245 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
5246 #[wasm_bindgen(method, js_name = forEach, catch)]
5247 pub fn try_for_each<K, V>(
5248 this: &Map<K, V>,
5249 callback: &mut dyn FnMut(V, K) -> Result<(), JsError>,
5250 ) -> Result<(), JsValue>;
5251
5252 /// The `get()` method returns a specified element from a Map object.
5253 /// Returns `undefined` if the key is not found.
5254 ///
5255 /// **Note:** Consider using [`Map::get_checked`] to get an `Option<V>` instead.
5256 ///
5257 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5258 #[cfg(not(js_sys_unstable_apis))]
5259 #[wasm_bindgen(method)]
5260 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> V;
5261
5262 /// The `get()` method returns a specified element from a Map object.
5263 /// Returns `None` if the key is not found.
5264 ///
5265 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5266 #[cfg(js_sys_unstable_apis)]
5267 #[wasm_bindgen(method)]
5268 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
5269
5270 /// The `get()` method returns a specified element from a Map object.
5271 /// Returns `None` if the key is not found.
5272 ///
5273 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5274 #[wasm_bindgen(method, js_name = get)]
5275 pub fn get_checked<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
5276
5277 /// The `has()` method returns a boolean indicating whether an element with
5278 /// the specified key exists or not.
5279 ///
5280 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
5281 #[wasm_bindgen(method)]
5282 pub fn has<K, V>(this: &Map<K, V>, key: &K) -> bool;
5283
5284 /// The `set()` method adds or updates an element with a specified key
5285 /// and value to a Map object.
5286 ///
5287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
5288 #[wasm_bindgen(method)]
5289 pub fn set<K, V>(this: &Map<K, V>, key: &K, value: &V) -> Map<K, V>;
5290
5291 /// The value of size is an integer representing how many entries
5292 /// the Map object has. A set accessor function for size is undefined;
5293 /// you can not change this property.
5294 ///
5295 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
5296 #[wasm_bindgen(method, getter)]
5297 pub fn size<K, V>(this: &Map<K, V>) -> u32;
5298}
5299
5300impl Default for Map<JsValue, JsValue> {
5301 fn default() -> Self {
5302 Self::new()
5303 }
5304}
5305
5306// Map Iterator
5307#[wasm_bindgen]
5308extern "C" {
5309 /// The `entries()` method returns a new Iterator object that contains
5310 /// the [key, value] pairs for each element in the Map object in
5311 /// insertion order.
5312 ///
5313 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5314 #[cfg(not(js_sys_unstable_apis))]
5315 #[wasm_bindgen(method)]
5316 pub fn entries<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator;
5317
5318 /// The `entries()` method returns a new Iterator object that contains
5319 /// the [key, value] pairs for each element in the Map object in
5320 /// insertion order.
5321 ///
5322 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5323 #[cfg(js_sys_unstable_apis)]
5324 #[wasm_bindgen(method, js_name = entries)]
5325 pub fn entries<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5326 this: &Map<K, V>,
5327 ) -> Iterator<ArrayTuple<(K, V)>>;
5328
5329 // Next major: deprecate
5330 /// The `entries()` method returns a new Iterator object that contains
5331 /// the [key, value] pairs for each element in the Map object in
5332 /// insertion order.
5333 ///
5334 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5335 #[wasm_bindgen(method, js_name = entries)]
5336 pub fn entries_typed<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5337 this: &Map<K, V>,
5338 ) -> Iterator<ArrayTuple<(K, V)>>;
5339
5340 /// The `keys()` method returns a new Iterator object that contains the
5341 /// keys for each element in the Map object in insertion order.
5342 ///
5343 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
5344 #[wasm_bindgen(method)]
5345 pub fn keys<K: FromWasmAbi, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<K>;
5346
5347 /// The `values()` method returns a new Iterator object that contains the
5348 /// values for each element in the Map object in insertion order.
5349 ///
5350 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values)
5351 #[wasm_bindgen(method)]
5352 pub fn values<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<V>;
5353}
5354
5355impl<K, V> Iterable for Map<K, V> {
5356 type Item = ArrayTuple<(K, V)>;
5357}
5358
5359// Iterator
5360#[wasm_bindgen]
5361extern "C" {
5362 /// Any object that conforms to the JS iterator protocol. For example,
5363 /// something returned by `myArray[Symbol.iterator]()`.
5364 ///
5365 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5366 #[derive(Clone, Debug)]
5367 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
5368 pub type Iterator<T = JsValue>;
5369
5370 /// The `next()` method always has to return an object with appropriate
5371 /// properties including done and value. If a non-object value gets returned
5372 /// (such as false or undefined), a TypeError ("iterator.next() returned a
5373 /// non-object value") will be thrown.
5374 #[wasm_bindgen(catch, method)]
5375 pub fn next<T: FromWasmAbi>(this: &Iterator<T>) -> Result<IteratorNext<T>, JsValue>;
5376}
5377
5378impl<T> UpcastFrom<Iterator<T>> for Object {}
5379
5380impl Iterator {
5381 fn looks_like_iterator(it: &JsValue) -> bool {
5382 #[wasm_bindgen]
5383 extern "C" {
5384 #[derive(Clone, Debug)]
5385 type MaybeIterator;
5386
5387 #[wasm_bindgen(method, getter)]
5388 fn next(this: &MaybeIterator) -> JsValue;
5389 }
5390
5391 if !it.is_object() {
5392 return false;
5393 }
5394
5395 let it = it.unchecked_ref::<MaybeIterator>();
5396
5397 it.next().is_function()
5398 }
5399}
5400
5401// iterators in JS are themselves iterable
5402impl<T> Iterable for Iterator<T> {
5403 type Item = T;
5404}
5405
5406// Async Iterator
5407#[wasm_bindgen]
5408extern "C" {
5409 /// Any object that conforms to the JS async iterator protocol. For example,
5410 /// something returned by `myObject[Symbol.asyncIterator]()`.
5411 ///
5412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
5413 #[derive(Clone, Debug)]
5414 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>")]
5415 pub type AsyncIterator<T = JsValue>;
5416
5417 /// The `next()` method always has to return a Promise which resolves to an object
5418 /// with appropriate properties including done and value. If a non-object value
5419 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5420 /// returned a non-object value") will be thrown.
5421 #[cfg(not(js_sys_unstable_apis))]
5422 #[wasm_bindgen(catch, method)]
5423 pub fn next<T>(this: &AsyncIterator<T>) -> Result<Promise, JsValue>;
5424
5425 /// The `next()` method always has to return a Promise which resolves to an object
5426 /// with appropriate properties including done and value. If a non-object value
5427 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5428 /// returned a non-object value") will be thrown.
5429 #[cfg(js_sys_unstable_apis)]
5430 #[wasm_bindgen(catch, method, js_name = next)]
5431 pub fn next<T: FromWasmAbi>(
5432 this: &AsyncIterator<T>,
5433 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5434
5435 // Next major: deprecate
5436 /// The `next()` method always has to return a Promise which resolves to an object
5437 /// with appropriate properties including done and value. If a non-object value
5438 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5439 /// returned a non-object value") will be thrown.
5440 #[wasm_bindgen(catch, method, js_name = next)]
5441 pub fn next_iterator<T: FromWasmAbi>(
5442 this: &AsyncIterator<T>,
5443 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5444}
5445
5446impl<T> UpcastFrom<AsyncIterator<T>> for Object {}
5447
5448// iterators in JS are themselves iterable
5449impl<T> AsyncIterable for AsyncIterator<T> {
5450 type Item = T;
5451}
5452
5453/// An iterator over the JS `Symbol.iterator` iteration protocol.
5454///
5455/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
5456pub struct Iter<'a, T = JsValue> {
5457 js: &'a Iterator<T>,
5458 state: IterState,
5459}
5460
5461/// An iterator over the JS `Symbol.iterator` iteration protocol.
5462///
5463/// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
5464pub struct IntoIter<T = JsValue> {
5465 js: Iterator<T>,
5466 state: IterState,
5467}
5468
5469struct IterState {
5470 done: bool,
5471}
5472
5473impl<'a, T: FromWasmAbi + JsGeneric> IntoIterator for &'a Iterator<T> {
5474 type Item = Result<T, JsValue>;
5475 type IntoIter = Iter<'a, T>;
5476
5477 fn into_iter(self) -> Iter<'a, T> {
5478 Iter {
5479 js: self,
5480 state: IterState::new(),
5481 }
5482 }
5483}
5484
5485impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for Iter<'_, T> {
5486 type Item = Result<T, JsValue>;
5487
5488 fn next(&mut self) -> Option<Self::Item> {
5489 self.state.next(self.js)
5490 }
5491}
5492
5493impl<T: FromWasmAbi + JsGeneric> IntoIterator for Iterator<T> {
5494 type Item = Result<T, JsValue>;
5495 type IntoIter = IntoIter<T>;
5496
5497 fn into_iter(self) -> IntoIter<T> {
5498 IntoIter {
5499 js: self,
5500 state: IterState::new(),
5501 }
5502 }
5503}
5504
5505impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for IntoIter<T> {
5506 type Item = Result<T, JsValue>;
5507
5508 fn next(&mut self) -> Option<Self::Item> {
5509 self.state.next(&self.js)
5510 }
5511}
5512
5513impl IterState {
5514 fn new() -> IterState {
5515 IterState { done: false }
5516 }
5517
5518 fn next<T: FromWasmAbi + JsGeneric>(&mut self, js: &Iterator<T>) -> Option<Result<T, JsValue>> {
5519 if self.done {
5520 return None;
5521 }
5522 let next = match js.next() {
5523 Ok(val) => val,
5524 Err(e) => {
5525 self.done = true;
5526 return Some(Err(e));
5527 }
5528 };
5529 if next.done() {
5530 self.done = true;
5531 None
5532 } else {
5533 Some(Ok(next.value()))
5534 }
5535 }
5536}
5537
5538/// Create an iterator over `val` using the JS iteration protocol and
5539/// `Symbol.iterator`.
5540// #[cfg(not(js_sys_unstable_apis))]
5541pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter<JsValue>>, JsValue> {
5542 let iter_sym = Symbol::iterator();
5543
5544 let iter_fn = Reflect::get_symbol::<Object>(val.unchecked_ref(), iter_sym.as_ref())?;
5545 let iter_fn: Function = match iter_fn.dyn_into() {
5546 Ok(iter_fn) => iter_fn,
5547 Err(_) => return Ok(None),
5548 };
5549
5550 let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
5551 Ok(it) => it,
5552 Err(_) => return Ok(None),
5553 };
5554
5555 Ok(Some(it.into_iter()))
5556}
5557
5558/// Trait for JavaScript types that implement the iterable protocol via `Symbol.iterator`.
5559///
5560/// Types implementing this trait can be iterated over using JavaScript's iteration
5561/// protocol. The `Item` associated type specifies the type of values yielded.
5562///
5563/// ## Built-in Iterables
5564///
5565/// Many `js-sys` collection types implement `Iterable` out of the box:
5566///
5567/// ```ignore
5568/// use js_sys::{Array, Map, Set};
5569///
5570/// // Array<T> yields T
5571/// let arr: Array<Number> = get_numbers();
5572/// for value in arr.iter() {
5573/// let num: Number = value?;
5574/// }
5575///
5576/// // Map<K, V> yields Array (key-value pairs)
5577/// let map: Map<JsString, Number> = get_map();
5578/// for entry in map.iter() {
5579/// let pair: Array = entry?;
5580/// }
5581///
5582/// // Set<T> yields T
5583/// let set: Set<JsString> = get_set();
5584/// for value in set.iter() {
5585/// let s: JsString = value?;
5586/// }
5587/// ```
5588///
5589/// ## Typing Foreign Iterators
5590///
5591/// If you have a JavaScript value that implements the iterator protocol (has a `next()`
5592/// method) but isn't a built-in type, you can use [`JsCast`] to cast it to [`Iterator<T>`]:
5593///
5594/// ```ignore
5595/// use js_sys::Iterator;
5596/// use wasm_bindgen::JsCast;
5597///
5598/// // For a value you know implements the iterator protocol
5599/// fn process_iterator(js_iter: JsValue) {
5600/// // Checked cast - returns None if not an iterator
5601/// if let Some(iter) = js_iter.dyn_ref::<Iterator<Number>>() {
5602/// for value in iter.into_iter() {
5603/// let num: Number = value.unwrap();
5604/// // ...
5605/// }
5606/// }
5607/// }
5608///
5609/// // Or with unchecked cast when you're certain of the type
5610/// fn process_known_iterator(js_iter: JsValue) {
5611/// let iter: &Iterator<JsString> = js_iter.unchecked_ref();
5612/// for value in iter.into_iter() {
5613/// let s: JsString = value.unwrap();
5614/// // ...
5615/// }
5616/// }
5617/// ```
5618///
5619/// ## Using with `JsValue`
5620///
5621/// For dynamic or unknown iterables, use [`try_iter`] which returns an untyped iterator:
5622///
5623/// ```ignore
5624/// fn iterate_unknown(val: &JsValue) -> Result<(), JsValue> {
5625/// if let Some(iter) = js_sys::try_iter(val)? {
5626/// for item in iter {
5627/// let value: JsValue = item?;
5628/// // Handle dynamically...
5629/// }
5630/// }
5631/// Ok(())
5632/// }
5633/// ```
5634///
5635/// [`JsCast`]: wasm_bindgen::JsCast
5636/// [`Iterator<T>`]: Iterator
5637/// [`try_iter`]: crate::try_iter
5638pub trait Iterable {
5639 /// The type of values yielded by this iterable.
5640 type Item;
5641}
5642
5643impl<T: Iterable> Iterable for &T {
5644 type Item = T::Item;
5645}
5646
5647/// Trait for types known to implement the iterator protocol on Symbol.asyncIterator
5648pub trait AsyncIterable {
5649 type Item;
5650}
5651
5652impl<T: AsyncIterable> AsyncIterable for &T {
5653 type Item = T::Item;
5654}
5655
5656impl AsyncIterable for JsValue {
5657 type Item = JsValue;
5658}
5659
5660// IteratorNext
5661#[wasm_bindgen]
5662extern "C" {
5663 /// The result of calling `next()` on a JS iterator.
5664 ///
5665 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5666 #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
5667 #[derive(Clone, Debug, PartialEq, Eq)]
5668 pub type IteratorNext<T = JsValue>;
5669
5670 /// Has the value `true` if the iterator is past the end of the iterated
5671 /// sequence. In this case value optionally specifies the return value of
5672 /// the iterator.
5673 ///
5674 /// Has the value `false` if the iterator was able to produce the next value
5675 /// in the sequence. This is equivalent of not specifying the done property
5676 /// altogether.
5677 #[wasm_bindgen(method, getter)]
5678 pub fn done<T>(this: &IteratorNext<T>) -> bool;
5679
5680 /// Any JavaScript value returned by the iterator. Can be omitted when done
5681 /// is true.
5682 #[wasm_bindgen(method, getter)]
5683 pub fn value<T>(this: &IteratorNext<T>) -> T;
5684}
5685
5686#[allow(non_snake_case)]
5687pub mod Math {
5688 use super::*;
5689
5690 // Math
5691 #[wasm_bindgen]
5692 extern "C" {
5693 /// The `Math.abs()` function returns the absolute value of a number, that is
5694 /// Math.abs(x) = |x|
5695 ///
5696 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
5697 #[wasm_bindgen(js_namespace = Math)]
5698 pub fn abs(x: f64) -> f64;
5699
5700 /// The `Math.acos()` function returns the arccosine (in radians) of a
5701 /// number, that is ∀x∊[-1;1]
5702 /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
5703 ///
5704 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
5705 #[wasm_bindgen(js_namespace = Math)]
5706 pub fn acos(x: f64) -> f64;
5707
5708 /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
5709 /// number, that is ∀x ≥ 1
5710 /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
5711 ///
5712 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
5713 #[wasm_bindgen(js_namespace = Math)]
5714 pub fn acosh(x: f64) -> f64;
5715
5716 /// The `Math.asin()` function returns the arcsine (in radians) of a
5717 /// number, that is ∀x ∊ [-1;1]
5718 /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
5719 ///
5720 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
5721 #[wasm_bindgen(js_namespace = Math)]
5722 pub fn asin(x: f64) -> f64;
5723
5724 /// The `Math.asinh()` function returns the hyperbolic arcsine of a
5725 /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
5726 ///
5727 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
5728 #[wasm_bindgen(js_namespace = Math)]
5729 pub fn asinh(x: f64) -> f64;
5730
5731 /// The `Math.atan()` function returns the arctangent (in radians) of a
5732 /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
5733 /// tan(y) = x
5734 #[wasm_bindgen(js_namespace = Math)]
5735 pub fn atan(x: f64) -> f64;
5736
5737 /// The `Math.atan2()` function returns the arctangent of the quotient of
5738 /// its arguments.
5739 ///
5740 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
5741 #[wasm_bindgen(js_namespace = Math)]
5742 pub fn atan2(y: f64, x: f64) -> f64;
5743
5744 /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
5745 /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
5746 /// tanh(y) = x
5747 ///
5748 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
5749 #[wasm_bindgen(js_namespace = Math)]
5750 pub fn atanh(x: f64) -> f64;
5751
5752 /// The `Math.cbrt() `function returns the cube root of a number, that is
5753 /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
5754 ///
5755 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
5756 #[wasm_bindgen(js_namespace = Math)]
5757 pub fn cbrt(x: f64) -> f64;
5758
5759 /// The `Math.ceil()` function returns the smallest integer greater than
5760 /// or equal to a given number.
5761 ///
5762 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
5763 #[wasm_bindgen(js_namespace = Math)]
5764 pub fn ceil(x: f64) -> f64;
5765
5766 /// The `Math.clz32()` function returns the number of leading zero bits in
5767 /// the 32-bit binary representation of a number.
5768 ///
5769 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
5770 #[wasm_bindgen(js_namespace = Math)]
5771 pub fn clz32(x: i32) -> u32;
5772
5773 /// The `Math.cos()` static function returns the cosine of the specified angle,
5774 /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
5775 ///
5776 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
5777 #[wasm_bindgen(js_namespace = Math)]
5778 pub fn cos(x: f64) -> f64;
5779
5780 /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
5781 /// that can be expressed using the constant e.
5782 ///
5783 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
5784 #[wasm_bindgen(js_namespace = Math)]
5785 pub fn cosh(x: f64) -> f64;
5786
5787 /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
5788 /// (also known as Napier's constant), the base of the natural logarithms.
5789 ///
5790 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
5791 #[wasm_bindgen(js_namespace = Math)]
5792 pub fn exp(x: f64) -> f64;
5793
5794 /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
5795 /// natural logarithms.
5796 ///
5797 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
5798 #[wasm_bindgen(js_namespace = Math)]
5799 pub fn expm1(x: f64) -> f64;
5800
5801 /// The `Math.floor()` function returns the largest integer less than or
5802 /// equal to a given number.
5803 ///
5804 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
5805 #[wasm_bindgen(js_namespace = Math)]
5806 pub fn floor(x: f64) -> f64;
5807
5808 /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
5809 /// of a Number.
5810 ///
5811 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
5812 #[wasm_bindgen(js_namespace = Math)]
5813 pub fn fround(x: f64) -> f32;
5814
5815 /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
5816 ///
5817 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
5818 #[wasm_bindgen(js_namespace = Math)]
5819 pub fn hypot(x: f64, y: f64) -> f64;
5820
5821 /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
5822 /// two parameters.
5823 ///
5824 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
5825 #[wasm_bindgen(js_namespace = Math)]
5826 pub fn imul(x: i32, y: i32) -> i32;
5827
5828 /// The `Math.log()` function returns the natural logarithm (base e) of a number.
5829 /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
5830 ///
5831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
5832 #[wasm_bindgen(js_namespace = Math)]
5833 pub fn log(x: f64) -> f64;
5834
5835 /// The `Math.log10()` function returns the base 10 logarithm of a number.
5836 ///
5837 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
5838 #[wasm_bindgen(js_namespace = Math)]
5839 pub fn log10(x: f64) -> f64;
5840
5841 /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
5842 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
5843 #[wasm_bindgen(js_namespace = Math)]
5844 pub fn log1p(x: f64) -> f64;
5845
5846 /// The `Math.log2()` function returns the base 2 logarithm of a number.
5847 ///
5848 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
5849 #[wasm_bindgen(js_namespace = Math)]
5850 pub fn log2(x: f64) -> f64;
5851
5852 /// The `Math.max()` function returns the largest of two numbers.
5853 ///
5854 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
5855 #[wasm_bindgen(js_namespace = Math)]
5856 pub fn max(x: f64, y: f64) -> f64;
5857
5858 /// The static function `Math.min()` returns the lowest-valued number passed into it.
5859 ///
5860 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
5861 #[wasm_bindgen(js_namespace = Math)]
5862 pub fn min(x: f64, y: f64) -> f64;
5863
5864 /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
5865 ///
5866 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
5867 #[wasm_bindgen(js_namespace = Math)]
5868 pub fn pow(base: f64, exponent: f64) -> f64;
5869
5870 /// The `Math.random()` function returns a floating-point, pseudo-random number
5871 /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
5872 /// over that range — which you can then scale to your desired range.
5873 /// The implementation selects the initial seed to the random number generation algorithm;
5874 /// it cannot be chosen or reset by the user.
5875 ///
5876 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
5877 #[wasm_bindgen(js_namespace = Math)]
5878 pub fn random() -> f64;
5879
5880 /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
5881 ///
5882 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
5883 #[wasm_bindgen(js_namespace = Math)]
5884 pub fn round(x: f64) -> f64;
5885
5886 /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
5887 /// positive, negative or zero.
5888 ///
5889 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
5890 #[wasm_bindgen(js_namespace = Math)]
5891 pub fn sign(x: f64) -> f64;
5892
5893 /// The `Math.sin()` function returns the sine of a number.
5894 ///
5895 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
5896 #[wasm_bindgen(js_namespace = Math)]
5897 pub fn sin(x: f64) -> f64;
5898
5899 /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
5900 /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
5901 ///
5902 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
5903 #[wasm_bindgen(js_namespace = Math)]
5904 pub fn sinh(x: f64) -> f64;
5905
5906 /// The `Math.sqrt()` function returns the square root of a number, that is
5907 /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
5908 ///
5909 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
5910 #[wasm_bindgen(js_namespace = Math)]
5911 pub fn sqrt(x: f64) -> f64;
5912
5913 /// The `Math.tan()` function returns the tangent of a number.
5914 ///
5915 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
5916 #[wasm_bindgen(js_namespace = Math)]
5917 pub fn tan(x: f64) -> f64;
5918
5919 /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
5920 /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
5921 ///
5922 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
5923 #[wasm_bindgen(js_namespace = Math)]
5924 pub fn tanh(x: f64) -> f64;
5925
5926 /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
5927 /// digits.
5928 ///
5929 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
5930 #[wasm_bindgen(js_namespace = Math)]
5931 pub fn trunc(x: f64) -> f64;
5932
5933 /// The `Math.PI` property represents the ratio of the circumference of a circle to its diameter,
5934 /// approximately 3.14159.
5935 ///
5936 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI)
5937 #[wasm_bindgen(thread_local_v2, js_namespace = Math)]
5938 pub static PI: f64;
5939 }
5940}
5941
5942// Number.
5943#[wasm_bindgen]
5944extern "C" {
5945 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
5946 #[derive(Clone, PartialEq)]
5947 pub type Number;
5948
5949 /// The `Number.isFinite()` method determines whether the passed value is a finite number.
5950 ///
5951 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
5952 #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
5953 pub fn is_finite(value: &JsValue) -> bool;
5954
5955 /// The `Number.isInteger()` method determines whether the passed value is an integer.
5956 ///
5957 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
5958 #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
5959 pub fn is_integer(value: &JsValue) -> bool;
5960
5961 /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
5962 /// It is a more robust version of the original, global isNaN().
5963 ///
5964 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
5965 #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
5966 pub fn is_nan(value: &JsValue) -> bool;
5967
5968 /// The `Number.isSafeInteger()` method determines whether the provided value is a number
5969 /// that is a safe integer.
5970 ///
5971 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
5972 #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
5973 pub fn is_safe_integer(value: &JsValue) -> bool;
5974
5975 /// The `Number` JavaScript object is a wrapper object allowing
5976 /// you to work with numerical values. A `Number` object is
5977 /// created using the `Number()` constructor.
5978 ///
5979 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
5980 #[cfg(not(js_sys_unstable_apis))]
5981 #[wasm_bindgen(constructor)]
5982 #[deprecated(note = "recommended to use `Number::from` instead")]
5983 #[allow(deprecated)]
5984 pub fn new(value: &JsValue) -> Number;
5985
5986 #[wasm_bindgen(constructor)]
5987 fn new_from_str(value: &str) -> Number;
5988
5989 /// The `Number.parseInt()` method parses a string argument and returns an
5990 /// integer of the specified radix or base.
5991 ///
5992 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
5993 #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
5994 pub fn parse_int(text: &str, radix: u8) -> f64;
5995
5996 /// The `Number.parseFloat()` method parses a string argument and returns a
5997 /// floating point number.
5998 ///
5999 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
6000 #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
6001 pub fn parse_float(text: &str) -> f64;
6002
6003 /// The `toLocaleString()` method returns a string with a language sensitive
6004 /// representation of this number.
6005 ///
6006 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
6007 #[cfg(not(js_sys_unstable_apis))]
6008 #[wasm_bindgen(method, js_name = toLocaleString)]
6009 pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
6010
6011 /// The `toLocaleString()` method returns a string with a language sensitive
6012 /// representation of this number.
6013 ///
6014 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
6015 #[cfg(js_sys_unstable_apis)]
6016 #[wasm_bindgen(method, js_name = toLocaleString)]
6017 pub fn to_locale_string(
6018 this: &Number,
6019 locales: &[JsString],
6020 options: &Intl::NumberFormatOptions,
6021 ) -> JsString;
6022
6023 /// The `toPrecision()` method returns a string representing the Number
6024 /// object to the specified precision.
6025 ///
6026 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
6027 #[wasm_bindgen(catch, method, js_name = toPrecision)]
6028 pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
6029
6030 /// The `toFixed()` method returns a string representing the Number
6031 /// object using fixed-point notation.
6032 ///
6033 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
6034 #[wasm_bindgen(catch, method, js_name = toFixed)]
6035 pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
6036
6037 /// The `toExponential()` method returns a string representing the Number
6038 /// object in exponential notation.
6039 ///
6040 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
6041 #[wasm_bindgen(catch, method, js_name = toExponential)]
6042 pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
6043
6044 /// The `toString()` method returns a string representing the
6045 /// specified Number object.
6046 ///
6047 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
6048 #[cfg(not(js_sys_unstable_apis))]
6049 #[deprecated(note = "Use `Number::to_string_with_radix` instead.")]
6050 #[allow(deprecated)]
6051 #[wasm_bindgen(catch, method, js_name = toString)]
6052 pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
6053
6054 /// The `toString()` method returns a string representing the
6055 /// specified Number object.
6056 ///
6057 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
6058 #[wasm_bindgen(catch, method, js_name = toString)]
6059 pub fn to_string_with_radix(this: &Number, radix: u8) -> Result<JsString, JsValue>;
6060
6061 /// The `valueOf()` method returns the wrapped primitive value of
6062 /// a Number object.
6063 ///
6064 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
6065 #[wasm_bindgen(method, js_name = valueOf)]
6066 pub fn value_of(this: &Number) -> f64;
6067}
6068
6069impl Number {
6070 /// The smallest interval between two representable numbers.
6071 ///
6072 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
6073 pub const EPSILON: f64 = f64::EPSILON;
6074 /// The maximum safe integer in JavaScript (2^53 - 1).
6075 ///
6076 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
6077 pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
6078 /// The largest positive representable number.
6079 ///
6080 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
6081 pub const MAX_VALUE: f64 = f64::MAX;
6082 /// The minimum safe integer in JavaScript (-(2^53 - 1)).
6083 ///
6084 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
6085 pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
6086 /// The smallest positive representable number—that is, the positive number closest to zero
6087 /// (without actually being zero).
6088 ///
6089 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
6090 // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number.
6091 pub const MIN_VALUE: f64 = 5E-324;
6092 /// Special "Not a Number" value.
6093 ///
6094 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
6095 pub const NAN: f64 = f64::NAN;
6096 /// Special value representing negative infinity. Returned on overflow.
6097 ///
6098 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
6099 pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
6100 /// Special value representing infinity. Returned on overflow.
6101 ///
6102 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
6103 pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
6104
6105 /// Applies the binary `**` JS operator on the two `Number`s.
6106 ///
6107 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
6108 #[inline]
6109 pub fn pow(&self, rhs: &Self) -> Self {
6110 JsValue::as_ref(self)
6111 .pow(JsValue::as_ref(rhs))
6112 .unchecked_into()
6113 }
6114
6115 /// Applies the binary `>>>` JS operator on the two `Number`s.
6116 ///
6117 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
6118 #[inline]
6119 pub fn unsigned_shr(&self, rhs: &Self) -> Self {
6120 Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs)))
6121 }
6122}
6123
6124macro_rules! number_from {
6125 ($($x:ident)*) => ($(
6126 impl From<$x> for Number {
6127 #[inline]
6128 fn from(x: $x) -> Number {
6129 Number::unchecked_from_js(JsValue::from(x))
6130 }
6131 }
6132
6133 impl PartialEq<$x> for Number {
6134 #[inline]
6135 fn eq(&self, other: &$x) -> bool {
6136 self.value_of() == f64::from(*other)
6137 }
6138 }
6139
6140 impl UpcastFrom<$x> for Number {}
6141 )*)
6142}
6143number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
6144
6145// The only guarantee for a JS number
6146impl UpcastFrom<Number> for f64 {}
6147
6148/// The error type returned when a checked integral type conversion fails.
6149#[derive(Debug, Copy, Clone, PartialEq, Eq)]
6150pub struct TryFromIntError(());
6151
6152impl fmt::Display for TryFromIntError {
6153 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
6154 fmt.write_str("out of range integral type conversion attempted")
6155 }
6156}
6157
6158#[cfg(feature = "std")]
6159impl std::error::Error for TryFromIntError {}
6160
6161macro_rules! number_try_from {
6162 ($($x:ident)*) => ($(
6163 impl TryFrom<$x> for Number {
6164 type Error = TryFromIntError;
6165
6166 #[inline]
6167 fn try_from(x: $x) -> Result<Number, Self::Error> {
6168 let x_f64 = x as f64;
6169 if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) {
6170 Ok(Number::from(x_f64))
6171 } else {
6172 Err(TryFromIntError(()))
6173 }
6174 }
6175 }
6176 )*)
6177}
6178number_try_from!(i64 u64 i128 u128);
6179
6180impl From<&Number> for f64 {
6181 #[inline]
6182 fn from(n: &Number) -> f64 {
6183 n.value_of()
6184 }
6185}
6186
6187impl From<Number> for f64 {
6188 #[inline]
6189 fn from(n: Number) -> f64 {
6190 <f64 as From<&'_ Number>>::from(&n)
6191 }
6192}
6193
6194impl fmt::Debug for Number {
6195 #[inline]
6196 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6197 fmt::Debug::fmt(&self.value_of(), f)
6198 }
6199}
6200
6201impl fmt::Display for Number {
6202 #[inline]
6203 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6204 fmt::Display::fmt(&self.value_of(), f)
6205 }
6206}
6207
6208impl Default for Number {
6209 fn default() -> Self {
6210 Self::from(f64::default())
6211 }
6212}
6213
6214impl PartialEq<BigInt> for Number {
6215 #[inline]
6216 fn eq(&self, other: &BigInt) -> bool {
6217 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
6218 }
6219}
6220
6221impl Not for &Number {
6222 type Output = BigInt;
6223
6224 #[inline]
6225 fn not(self) -> Self::Output {
6226 JsValue::as_ref(self).bit_not().unchecked_into()
6227 }
6228}
6229
6230forward_deref_unop!(impl Not, not for Number);
6231forward_js_unop!(impl Neg, neg for Number);
6232forward_js_binop!(impl BitAnd, bitand for Number);
6233forward_js_binop!(impl BitOr, bitor for Number);
6234forward_js_binop!(impl BitXor, bitxor for Number);
6235forward_js_binop!(impl Shl, shl for Number);
6236forward_js_binop!(impl Shr, shr for Number);
6237forward_js_binop!(impl Add, add for Number);
6238forward_js_binop!(impl Sub, sub for Number);
6239forward_js_binop!(impl Div, div for Number);
6240forward_js_binop!(impl Mul, mul for Number);
6241forward_js_binop!(impl Rem, rem for Number);
6242
6243sum_product!(Number);
6244
6245impl PartialOrd for Number {
6246 #[inline]
6247 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
6248 if Number::is_nan(self) || Number::is_nan(other) {
6249 None
6250 } else if self == other {
6251 Some(Ordering::Equal)
6252 } else if self.lt(other) {
6253 Some(Ordering::Less)
6254 } else {
6255 Some(Ordering::Greater)
6256 }
6257 }
6258
6259 #[inline]
6260 fn lt(&self, other: &Self) -> bool {
6261 JsValue::as_ref(self).lt(JsValue::as_ref(other))
6262 }
6263
6264 #[inline]
6265 fn le(&self, other: &Self) -> bool {
6266 JsValue::as_ref(self).le(JsValue::as_ref(other))
6267 }
6268
6269 #[inline]
6270 fn ge(&self, other: &Self) -> bool {
6271 JsValue::as_ref(self).ge(JsValue::as_ref(other))
6272 }
6273
6274 #[inline]
6275 fn gt(&self, other: &Self) -> bool {
6276 JsValue::as_ref(self).gt(JsValue::as_ref(other))
6277 }
6278}
6279
6280#[cfg(not(js_sys_unstable_apis))]
6281impl FromStr for Number {
6282 type Err = Infallible;
6283
6284 #[allow(deprecated)]
6285 #[inline]
6286 fn from_str(s: &str) -> Result<Self, Self::Err> {
6287 Ok(Number::new_from_str(s))
6288 }
6289}
6290
6291// Date.
6292#[wasm_bindgen]
6293extern "C" {
6294 #[wasm_bindgen(extends = Object, typescript_type = "Date")]
6295 #[derive(Clone, Debug, PartialEq, Eq)]
6296 pub type Date;
6297
6298 /// The `getDate()` method returns the day of the month for the
6299 /// specified date according to local time.
6300 ///
6301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
6302 #[wasm_bindgen(method, js_name = getDate)]
6303 pub fn get_date(this: &Date) -> u32;
6304
6305 /// The `getDay()` method returns the day of the week for the specified date according to local time,
6306 /// where 0 represents Sunday. For the day of the month see getDate().
6307 ///
6308 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
6309 #[wasm_bindgen(method, js_name = getDay)]
6310 pub fn get_day(this: &Date) -> u32;
6311
6312 /// The `getFullYear()` method returns the year of the specified date according to local time.
6313 ///
6314 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
6315 #[wasm_bindgen(method, js_name = getFullYear)]
6316 pub fn get_full_year(this: &Date) -> u32;
6317
6318 /// The `getHours()` method returns the hour for the specified date, according to local time.
6319 ///
6320 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
6321 #[wasm_bindgen(method, js_name = getHours)]
6322 pub fn get_hours(this: &Date) -> u32;
6323
6324 /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
6325 ///
6326 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
6327 #[wasm_bindgen(method, js_name = getMilliseconds)]
6328 pub fn get_milliseconds(this: &Date) -> u32;
6329
6330 /// The `getMinutes()` method returns the minutes in the specified date according to local time.
6331 ///
6332 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
6333 #[wasm_bindgen(method, js_name = getMinutes)]
6334 pub fn get_minutes(this: &Date) -> u32;
6335
6336 /// The `getMonth()` method returns the month in the specified date according to local time,
6337 /// as a zero-based value (where zero indicates the first month of the year).
6338 ///
6339 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
6340 #[wasm_bindgen(method, js_name = getMonth)]
6341 pub fn get_month(this: &Date) -> u32;
6342
6343 /// The `getSeconds()` method returns the seconds in the specified date according to local time.
6344 ///
6345 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
6346 #[wasm_bindgen(method, js_name = getSeconds)]
6347 pub fn get_seconds(this: &Date) -> u32;
6348
6349 /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
6350 /// according to universal time.
6351 ///
6352 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
6353 #[wasm_bindgen(method, js_name = getTime)]
6354 pub fn get_time(this: &Date) -> f64;
6355
6356 /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
6357 /// from current locale (host system settings) to UTC.
6358 ///
6359 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
6360 #[wasm_bindgen(method, js_name = getTimezoneOffset)]
6361 pub fn get_timezone_offset(this: &Date) -> f64;
6362
6363 /// The `getUTCDate()` method returns the day (date) of the month in the specified date
6364 /// according to universal time.
6365 ///
6366 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
6367 #[wasm_bindgen(method, js_name = getUTCDate)]
6368 pub fn get_utc_date(this: &Date) -> u32;
6369
6370 /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
6371 /// where 0 represents Sunday.
6372 ///
6373 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
6374 #[wasm_bindgen(method, js_name = getUTCDay)]
6375 pub fn get_utc_day(this: &Date) -> u32;
6376
6377 /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
6378 ///
6379 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
6380 #[wasm_bindgen(method, js_name = getUTCFullYear)]
6381 pub fn get_utc_full_year(this: &Date) -> u32;
6382
6383 /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
6384 ///
6385 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
6386 #[wasm_bindgen(method, js_name = getUTCHours)]
6387 pub fn get_utc_hours(this: &Date) -> u32;
6388
6389 /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date
6390 /// according to universal time.
6391 ///
6392 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds)
6393 #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
6394 pub fn get_utc_milliseconds(this: &Date) -> u32;
6395
6396 /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
6397 ///
6398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
6399 #[wasm_bindgen(method, js_name = getUTCMinutes)]
6400 pub fn get_utc_minutes(this: &Date) -> u32;
6401
6402 /// The `getUTCMonth()` returns the month of the specified date according to universal time,
6403 /// as a zero-based value (where zero indicates the first month of the year).
6404 ///
6405 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
6406 #[wasm_bindgen(method, js_name = getUTCMonth)]
6407 pub fn get_utc_month(this: &Date) -> u32;
6408
6409 /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time.
6410 ///
6411 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds)
6412 #[wasm_bindgen(method, js_name = getUTCSeconds)]
6413 pub fn get_utc_seconds(this: &Date) -> u32;
6414
6415 /// Creates a JavaScript `Date` instance that represents
6416 /// a single moment in time. `Date` objects are based on a time value that is
6417 /// the number of milliseconds since 1 January 1970 UTC.
6418 ///
6419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6420 #[wasm_bindgen(constructor)]
6421 pub fn new(init: &JsValue) -> Date;
6422
6423 /// Creates a JavaScript `Date` instance that represents the current moment in
6424 /// time.
6425 ///
6426 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6427 #[wasm_bindgen(constructor)]
6428 pub fn new_0() -> Date;
6429
6430 /// Creates a JavaScript `Date` instance that represents
6431 /// a single moment in time. `Date` objects are based on a time value that is
6432 /// the number of milliseconds since 1 January 1970 UTC.
6433 ///
6434 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6435 #[wasm_bindgen(constructor)]
6436 pub fn new_with_year_month(year: u32, month: i32) -> Date;
6437
6438 /// Creates a JavaScript `Date` instance that represents
6439 /// a single moment in time. `Date` objects are based on a time value that is
6440 /// the number of milliseconds since 1 January 1970 UTC.
6441 ///
6442 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6443 #[wasm_bindgen(constructor)]
6444 pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
6445
6446 /// Creates a JavaScript `Date` instance that represents
6447 /// a single moment in time. `Date` objects are based on a time value that is
6448 /// the number of milliseconds since 1 January 1970 UTC.
6449 ///
6450 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6451 #[wasm_bindgen(constructor)]
6452 pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
6453
6454 /// Creates a JavaScript `Date` instance that represents
6455 /// a single moment in time. `Date` objects are based on a time value that is
6456 /// the number of milliseconds since 1 January 1970 UTC.
6457 ///
6458 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6459 #[wasm_bindgen(constructor)]
6460 pub fn new_with_year_month_day_hr_min(
6461 year: u32,
6462 month: i32,
6463 day: i32,
6464 hr: i32,
6465 min: i32,
6466 ) -> Date;
6467
6468 /// Creates a JavaScript `Date` instance that represents
6469 /// a single moment in time. `Date` objects are based on a time value that is
6470 /// the number of milliseconds since 1 January 1970 UTC.
6471 ///
6472 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6473 #[wasm_bindgen(constructor)]
6474 pub fn new_with_year_month_day_hr_min_sec(
6475 year: u32,
6476 month: i32,
6477 day: i32,
6478 hr: i32,
6479 min: i32,
6480 sec: i32,
6481 ) -> Date;
6482
6483 /// Creates a JavaScript `Date` instance that represents
6484 /// a single moment in time. `Date` objects are based on a time value that is
6485 /// the number of milliseconds since 1 January 1970 UTC.
6486 ///
6487 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6488 #[wasm_bindgen(constructor)]
6489 pub fn new_with_year_month_day_hr_min_sec_milli(
6490 year: u32,
6491 month: i32,
6492 day: i32,
6493 hr: i32,
6494 min: i32,
6495 sec: i32,
6496 milli: i32,
6497 ) -> Date;
6498
6499 /// The `Date.now()` method returns the number of milliseconds
6500 /// elapsed since January 1, 1970 00:00:00 UTC.
6501 ///
6502 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
6503 #[wasm_bindgen(static_method_of = Date)]
6504 pub fn now() -> f64;
6505
6506 /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
6507 /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
6508 /// contains illegal date values (e.g. 2015-02-31).
6509 ///
6510 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
6511 #[wasm_bindgen(static_method_of = Date)]
6512 pub fn parse(date: &str) -> f64;
6513
6514 /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
6515 ///
6516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
6517 #[wasm_bindgen(method, js_name = setDate)]
6518 pub fn set_date(this: &Date, day: u32) -> f64;
6519
6520 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6521 /// Returns new timestamp.
6522 ///
6523 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6524 #[wasm_bindgen(method, js_name = setFullYear)]
6525 pub fn set_full_year(this: &Date, year: u32) -> f64;
6526
6527 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6528 /// Returns new timestamp.
6529 ///
6530 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6531 #[wasm_bindgen(method, js_name = setFullYear)]
6532 pub fn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6533
6534 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6535 /// Returns new timestamp.
6536 ///
6537 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6538 #[wasm_bindgen(method, js_name = setFullYear)]
6539 pub fn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6540
6541 /// The `setHours()` method sets the hours for a specified date according to local time,
6542 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
6543 /// by the updated Date instance.
6544 ///
6545 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
6546 #[wasm_bindgen(method, js_name = setHours)]
6547 pub fn set_hours(this: &Date, hours: u32) -> f64;
6548
6549 /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
6550 ///
6551 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
6552 #[wasm_bindgen(method, js_name = setMilliseconds)]
6553 pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
6554
6555 /// The `setMinutes()` method sets the minutes for a specified date according to local time.
6556 ///
6557 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
6558 #[wasm_bindgen(method, js_name = setMinutes)]
6559 pub fn set_minutes(this: &Date, minutes: u32) -> f64;
6560
6561 /// The `setMonth()` method sets the month for a specified date according to the currently set year.
6562 ///
6563 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
6564 #[wasm_bindgen(method, js_name = setMonth)]
6565 pub fn set_month(this: &Date, month: u32) -> f64;
6566
6567 /// The `setSeconds()` method sets the seconds for a specified date according to local time.
6568 ///
6569 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
6570 #[wasm_bindgen(method, js_name = setSeconds)]
6571 pub fn set_seconds(this: &Date, seconds: u32) -> f64;
6572
6573 /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
6574 /// since January 1, 1970, 00:00:00 UTC.
6575 ///
6576 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
6577 #[wasm_bindgen(method, js_name = setTime)]
6578 pub fn set_time(this: &Date, time: f64) -> f64;
6579
6580 /// The `setUTCDate()` method sets the day of the month for a specified date
6581 /// according to universal time.
6582 ///
6583 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
6584 #[wasm_bindgen(method, js_name = setUTCDate)]
6585 pub fn set_utc_date(this: &Date, day: u32) -> f64;
6586
6587 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6588 ///
6589 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6590 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6591 pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
6592
6593 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6594 ///
6595 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6596 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6597 pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6598
6599 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6600 ///
6601 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6602 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6603 pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6604
6605 /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
6606 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time
6607 /// represented by the updated Date instance.
6608 ///
6609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
6610 #[wasm_bindgen(method, js_name = setUTCHours)]
6611 pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
6612
6613 /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
6614 /// according to universal time.
6615 ///
6616 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
6617 #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
6618 pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
6619
6620 /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
6621 ///
6622 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
6623 #[wasm_bindgen(method, js_name = setUTCMinutes)]
6624 pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
6625
6626 /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
6627 ///
6628 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
6629 #[wasm_bindgen(method, js_name = setUTCMonth)]
6630 pub fn set_utc_month(this: &Date, month: u32) -> f64;
6631
6632 /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
6633 ///
6634 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
6635 #[wasm_bindgen(method, js_name = setUTCSeconds)]
6636 pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
6637
6638 /// The `toDateString()` method returns the date portion of a Date object
6639 /// in human readable form in American English.
6640 ///
6641 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
6642 #[wasm_bindgen(method, js_name = toDateString)]
6643 pub fn to_date_string(this: &Date) -> JsString;
6644
6645 /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
6646 /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
6647 /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
6648 /// as denoted by the suffix "Z"
6649 ///
6650 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
6651 #[wasm_bindgen(method, js_name = toISOString)]
6652 pub fn to_iso_string(this: &Date) -> JsString;
6653
6654 /// The `toJSON()` method returns a string representation of the Date object.
6655 ///
6656 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
6657 #[wasm_bindgen(method, js_name = toJSON)]
6658 pub fn to_json(this: &Date) -> JsString;
6659
6660 /// The `toLocaleDateString()` method returns a string with a language sensitive
6661 /// representation of the date portion of this date. The new locales and options
6662 /// arguments let applications specify the language whose formatting conventions
6663 /// should be used and allow to customize the behavior of the function.
6664 /// In older implementations, which ignore the locales and options arguments,
6665 /// the locale used and the form of the string
6666 /// returned are entirely implementation dependent.
6667 ///
6668 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6669 #[cfg(not(js_sys_unstable_apis))]
6670 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6671 pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6672
6673 /// The `toLocaleDateString()` method returns a string with a language sensitive
6674 /// representation of the date portion of this date.
6675 ///
6676 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6677 #[cfg(js_sys_unstable_apis)]
6678 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6679 pub fn to_locale_date_string(
6680 this: &Date,
6681 locales: &[JsString],
6682 options: &Intl::DateTimeFormatOptions,
6683 ) -> JsString;
6684
6685 /// The `toLocaleString()` method returns a string with a language sensitive
6686 /// representation of this date. The new locales and options arguments
6687 /// let applications specify the language whose formatting conventions
6688 /// should be used and customize the behavior of the function.
6689 /// In older implementations, which ignore the locales
6690 /// and options arguments, the locale used and the form of the string
6691 /// returned are entirely implementation dependent.
6692 ///
6693 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6694 #[cfg(not(js_sys_unstable_apis))]
6695 #[wasm_bindgen(method, js_name = toLocaleString)]
6696 pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6697
6698 /// The `toLocaleString()` method returns a string with a language sensitive
6699 /// representation of this date.
6700 ///
6701 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6702 #[cfg(js_sys_unstable_apis)]
6703 #[wasm_bindgen(method, js_name = toLocaleString)]
6704 pub fn to_locale_string(
6705 this: &Date,
6706 locales: &[JsString],
6707 options: &Intl::DateTimeFormatOptions,
6708 ) -> JsString;
6709
6710 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6711 /// representation of the time portion of this date. The new locales and options
6712 /// arguments let applications specify the language whose formatting conventions should be
6713 /// used and customize the behavior of the function. In older implementations, which ignore
6714 /// the locales and options arguments, the locale used and the form of the string
6715 /// returned are entirely implementation dependent.
6716 ///
6717 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6718 #[cfg(not(js_sys_unstable_apis))]
6719 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6720 pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
6721
6722 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6723 /// representation of the time portion of this date.
6724 ///
6725 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6726 #[cfg(js_sys_unstable_apis)]
6727 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6728 pub fn to_locale_time_string(
6729 this: &Date,
6730 locales: &[JsString],
6731 options: &Intl::DateTimeFormatOptions,
6732 ) -> JsString;
6733
6734 #[cfg(not(js_sys_unstable_apis))]
6735 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6736 pub fn to_locale_time_string_with_options(
6737 this: &Date,
6738 locale: &str,
6739 options: &JsValue,
6740 ) -> JsString;
6741
6742 /// The `toString()` method returns a string representing
6743 /// the specified Date object.
6744 ///
6745 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
6746 #[cfg(not(js_sys_unstable_apis))]
6747 #[wasm_bindgen(method, js_name = toString)]
6748 pub fn to_string(this: &Date) -> JsString;
6749
6750 /// The `toTimeString()` method returns the time portion of a Date object in human
6751 /// readable form in American English.
6752 ///
6753 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
6754 #[wasm_bindgen(method, js_name = toTimeString)]
6755 pub fn to_time_string(this: &Date) -> JsString;
6756
6757 /// The `toUTCString()` method converts a date to a string,
6758 /// using the UTC time zone.
6759 ///
6760 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
6761 #[wasm_bindgen(method, js_name = toUTCString)]
6762 pub fn to_utc_string(this: &Date) -> JsString;
6763
6764 /// The `Date.UTC()` method accepts the same parameters as the
6765 /// longest form of the constructor, and returns the number of
6766 /// milliseconds in a `Date` object since January 1, 1970,
6767 /// 00:00:00, universal time.
6768 ///
6769 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
6770 #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
6771 pub fn utc(year: f64, month: f64) -> f64;
6772
6773 /// The `valueOf()` method returns the primitive value of
6774 /// a Date object.
6775 ///
6776 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
6777 #[wasm_bindgen(method, js_name = valueOf)]
6778 pub fn value_of(this: &Date) -> f64;
6779
6780 /// The `toTemporalInstant()` method converts a legacy `Date` object to a
6781 /// `Temporal.Instant` object representing the same moment in time.
6782 ///
6783 /// This method is added by the Temporal proposal to facilitate migration
6784 /// from legacy `Date` to the new Temporal API.
6785 ///
6786 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTemporalInstant)
6787 #[cfg(js_sys_unstable_apis)]
6788 #[wasm_bindgen(method, js_name = toTemporalInstant)]
6789 pub fn to_temporal_instant(this: &Date) -> Temporal::Instant;
6790}
6791
6792// Property Descriptor.
6793#[wasm_bindgen]
6794extern "C" {
6795 #[wasm_bindgen(extends = Object)]
6796 #[derive(Clone, Debug)]
6797 pub type PropertyDescriptor<T = JsValue>;
6798
6799 #[wasm_bindgen(method, getter = writable)]
6800 pub fn get_writable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6801
6802 #[wasm_bindgen(method, setter = writable)]
6803 pub fn set_writable<T>(this: &PropertyDescriptor<T>, writable: bool);
6804
6805 #[wasm_bindgen(method, getter = enumerable)]
6806 pub fn get_enumerable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6807
6808 #[wasm_bindgen(method, setter = enumerable)]
6809 pub fn set_enumerable<T>(this: &PropertyDescriptor<T>, enumerable: bool);
6810
6811 #[wasm_bindgen(method, getter = configurable)]
6812 pub fn get_configurable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6813
6814 #[wasm_bindgen(method, setter = configurable)]
6815 pub fn set_configurable<T>(this: &PropertyDescriptor<T>, configurable: bool);
6816
6817 #[wasm_bindgen(method, getter = get)]
6818 pub fn get_get<T: JsGeneric>(this: &PropertyDescriptor<T>) -> Option<Function<fn() -> T>>;
6819
6820 #[wasm_bindgen(method, setter = get)]
6821 pub fn set_get<T: JsGeneric>(this: &PropertyDescriptor<T>, get: Function<fn() -> T>);
6822
6823 #[wasm_bindgen(method, getter = set)]
6824 pub fn get_set<T: JsGeneric>(
6825 this: &PropertyDescriptor<T>,
6826 ) -> Option<Function<fn(T) -> JsValue>>;
6827
6828 #[wasm_bindgen(method, setter = set)]
6829 pub fn set_set<T: JsGeneric>(this: &PropertyDescriptor<T>, set: Function<fn(T) -> JsValue>);
6830
6831 #[wasm_bindgen(method, getter = value)]
6832 pub fn get_value<T>(this: &PropertyDescriptor<T>) -> Option<T>;
6833
6834 #[wasm_bindgen(method, setter = value)]
6835 pub fn set_value<T>(this: &PropertyDescriptor<T>, value: &T);
6836}
6837
6838impl PropertyDescriptor {
6839 #[cfg(not(js_sys_unstable_apis))]
6840 pub fn new<T>() -> PropertyDescriptor<T> {
6841 JsCast::unchecked_into(Object::new())
6842 }
6843
6844 #[cfg(js_sys_unstable_apis)]
6845 pub fn new<T>() -> PropertyDescriptor<T> {
6846 JsCast::unchecked_into(Object::<JsValue>::new())
6847 }
6848
6849 #[cfg(not(js_sys_unstable_apis))]
6850 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6851 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::new());
6852 desc.set_value(value);
6853 desc
6854 }
6855
6856 #[cfg(js_sys_unstable_apis)]
6857 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6858 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::<JsValue>::new());
6859 desc.set_value(value);
6860 desc
6861 }
6862}
6863
6864impl Default for PropertyDescriptor {
6865 fn default() -> Self {
6866 PropertyDescriptor::new()
6867 }
6868}
6869
6870// Object.
6871#[wasm_bindgen]
6872extern "C" {
6873 #[wasm_bindgen(typescript_type = "object")]
6874 #[derive(Clone, Debug)]
6875 pub type Object<T = JsValue>;
6876
6877 // Next major: deprecate
6878 /// The `Object.assign()` method is used to copy the values of all enumerable
6879 /// own properties from one or more source objects to a target object. It
6880 /// will return the target object.
6881 ///
6882 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6883 ///
6884 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6885 #[wasm_bindgen(static_method_of = Object)]
6886 pub fn assign<T>(target: &Object<T>, source: &Object<T>) -> Object<T>;
6887
6888 // Next major: deprecate
6889 /// The `Object.assign()` method is used to copy the values of all enumerable
6890 /// own properties from one or more source objects to a target object. It
6891 /// will return the target object.
6892 ///
6893 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6894 ///
6895 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6896 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch)]
6897 pub fn try_assign<T>(target: &Object<T>, source: &Object<T>) -> Result<Object<T>, JsValue>;
6898
6899 /// The `Object.assign()` method is used to copy the values of all enumerable
6900 /// own properties from one or more source objects to a target object. It
6901 /// will return the target object.
6902 ///
6903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6904 #[cfg(not(js_sys_unstable_apis))]
6905 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6906 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6907 #[allow(deprecated)]
6908 pub fn assign2<T>(target: &Object<T>, source1: &Object<T>, source2: &Object<T>) -> Object<T>;
6909
6910 /// The `Object.assign()` method is used to copy the values of all enumerable
6911 /// own properties from one or more source objects to a target object. It
6912 /// will return the target object.
6913 ///
6914 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6915 #[cfg(not(js_sys_unstable_apis))]
6916 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6917 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6918 #[allow(deprecated)]
6919 pub fn assign3<T>(
6920 target: &Object<T>,
6921 source1: &Object<T>,
6922 source2: &Object<T>,
6923 source3: &Object<T>,
6924 ) -> Object<T>;
6925
6926 /// The `Object.assign()` method is used to copy the values of all enumerable
6927 /// own properties from one or more source objects to a target object. It
6928 /// will return the target object.
6929 ///
6930 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6931 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch, variadic)]
6932 pub fn assign_many<T>(target: &Object<T>, sources: &[Object<T>]) -> Result<Object<T>, JsValue>;
6933
6934 /// The constructor property returns a reference to the `Object` constructor
6935 /// function that created the instance object.
6936 ///
6937 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
6938 #[wasm_bindgen(method, getter)]
6939 pub fn constructor<T>(this: &Object<T>) -> Function;
6940
6941 /// The `Object.create()` method creates a new object, using an existing
6942 /// object to provide the newly created object's prototype.
6943 ///
6944 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
6945 #[wasm_bindgen(static_method_of = Object)]
6946 pub fn create<T>(prototype: &Object<T>) -> Object<T>;
6947
6948 /// The static method `Object.defineProperty()` defines a new
6949 /// property directly on an object, or modifies an existing
6950 /// property on an object, and returns the object.
6951 ///
6952 /// **Note:** Consider using [`Object::define_property_str`] to support typing and error handling.
6953 ///
6954 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6955 #[cfg(not(js_sys_unstable_apis))]
6956 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
6957 pub fn define_property<T>(obj: &Object<T>, prop: &JsValue, descriptor: &Object) -> Object<T>;
6958
6959 // Stable `_key`-suffixed variants of the generic `K: PropertyKey` property
6960 // operations can be added if `PropertyKey` stabilizes first.
6961 /// The static method `Object.defineProperty()` defines a new
6962 /// property directly on an object, or modifies an existing
6963 /// property on an object, and returns the object.
6964 ///
6965 /// The property key may be any JavaScript property-key representation
6966 /// (string, number, or symbol).
6967 ///
6968 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6969 #[cfg(js_sys_unstable_apis)]
6970 #[wasm_bindgen(
6971 static_method_of = Object,
6972 js_name = defineProperty,
6973 catch,
6974 experimental_generic_mono
6975 )]
6976 pub fn define_property<T, K: PropertyKey>(
6977 obj: &Object<T>,
6978 prop: K,
6979 descriptor: &PropertyDescriptor<T>,
6980 ) -> Result<Object<T>, JsValue>;
6981
6982 // Next major: deprecate
6983 /// The static method `Object.defineProperty()` defines a new
6984 /// property directly on an object, or modifies an existing
6985 /// property on an object, and returns the object.
6986 ///
6987 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6988 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6989 pub fn define_property_str<T>(
6990 obj: &Object<T>,
6991 prop: &JsString,
6992 descriptor: &PropertyDescriptor<T>,
6993 ) -> Result<Object<T>, JsValue>;
6994
6995 /// The static method `Object.defineProperty()` defines a new
6996 /// property directly on an object, or modifies an existing
6997 /// property on an object, and returns the object.
6998 ///
6999 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
7000 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
7001 pub fn define_property_symbol<T>(
7002 obj: &Object<T>,
7003 prop: &Symbol,
7004 descriptor: &PropertyDescriptor<JsValue>,
7005 ) -> Result<Object<T>, JsValue>;
7006
7007 /// The `Object.defineProperties()` method defines new or modifies
7008 /// existing properties directly on an object, returning the
7009 /// object.
7010 ///
7011 /// **Note:** Consider using [`Object::try_define_properties`] to support typing and error handling.
7012 ///
7013 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
7014 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
7015 pub fn define_properties<T>(obj: &Object<T>, props: &Object) -> Object<T>;
7016
7017 /// The `Object.defineProperties()` method defines new or modifies
7018 /// existing properties directly on an object, returning the
7019 /// object.
7020 ///
7021 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
7022 #[cfg(js_sys_unstable_apis)]
7023 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties, catch)]
7024 pub fn try_define_properties<T>(
7025 obj: &Object<T>,
7026 props: &Object<PropertyDescriptor<T>>,
7027 ) -> Result<Object<T>, JsValue>;
7028
7029 /// The `Object.entries()` method returns an array of a given
7030 /// object's own enumerable property [key, value] pairs, in the
7031 /// same order as that provided by a for...in loop (the difference
7032 /// being that a for-in loop enumerates properties in the
7033 /// prototype chain as well).
7034 ///
7035 /// **Note:** Consider using [`Object::entries_typed`] to support typing and error handling.
7036 ///
7037 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7038 #[cfg(not(js_sys_unstable_apis))]
7039 #[wasm_bindgen(static_method_of = Object)]
7040 pub fn entries(object: &Object) -> Array;
7041
7042 /// The `Object.entries()` method returns an array of a given
7043 /// object's own enumerable property [key, value] pairs, in the
7044 /// same order as that provided by a for...in loop (the difference
7045 /// being that a for-in loop enumerates properties in the
7046 /// prototype chain as well).
7047 ///
7048 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7049 #[cfg(js_sys_unstable_apis)]
7050 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
7051 pub fn entries<T: JsGeneric>(
7052 object: &Object<T>,
7053 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
7054
7055 // Next major: deprecate
7056 /// The `Object.entries()` method returns an array of a given
7057 /// object's own enumerable property [key, value] pairs, in the
7058 /// same order as that provided by a for...in loop (the difference
7059 /// being that a for-in loop enumerates properties in the
7060 /// prototype chain as well).
7061 ///
7062 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7063 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
7064 pub fn entries_typed<T: JsGeneric>(
7065 object: &Object<T>,
7066 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
7067
7068 /// The `Object.freeze()` method freezes an object: that is, prevents new
7069 /// properties from being added to it; prevents existing properties from
7070 /// being removed; and prevents existing properties, or their enumerability,
7071 /// configurability, or writability, from being changed, it also prevents
7072 /// the prototype from being changed. The method returns the passed object.
7073 ///
7074 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
7075 #[wasm_bindgen(static_method_of = Object)]
7076 pub fn freeze<T>(value: &Object<T>) -> Object<T>;
7077
7078 /// The `Object.fromEntries()` method transforms a list of key-value pairs
7079 /// into an object.
7080 ///
7081 /// **Note:** Consider using [`Object::from_entries_typed`] to support typing and error handling.
7082 ///
7083 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7084 #[cfg(not(js_sys_unstable_apis))]
7085 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7086 pub fn from_entries(entries: &JsValue) -> Result<Object, JsValue>;
7087
7088 /// The `Object.fromEntries()` method transforms a list of key-value pairs
7089 /// into an object.
7090 ///
7091 /// Entry keys may use any JavaScript property-key representation
7092 /// (string, number, or symbol).
7093 ///
7094 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7095 #[cfg(js_sys_unstable_apis)]
7096 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7097 pub fn from_entries<K: PropertyKey, T: JsGeneric, I: Iterable<Item = ArrayTuple<(K, T)>>>(
7098 entries: &I,
7099 ) -> Result<Object<T>, JsValue>;
7100
7101 // Next major: deprecate
7102 /// The `Object.fromEntries()` method transforms a list of key-value pairs
7103 /// into an object.
7104 ///
7105 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7106 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7107 pub fn from_entries_typed<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
7108 entries: &I,
7109 ) -> Result<Object<T>, JsValue>;
7110
7111 /// The `Object.getOwnPropertyDescriptor()` method returns a
7112 /// property descriptor for an own property (that is, one directly
7113 /// present on an object and not in the object's prototype chain)
7114 /// of a given object.
7115 ///
7116 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7117 #[cfg(not(js_sys_unstable_apis))]
7118 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
7119 pub fn get_own_property_descriptor<T>(obj: &Object<T>, prop: &JsValue) -> JsValue;
7120
7121 /// The `Object.getOwnPropertyDescriptor()` method returns a
7122 /// property descriptor for an own property (that is, one directly
7123 /// present on an object and not in the object's prototype chain)
7124 /// of a given object.
7125 ///
7126 /// The property key may be any JavaScript property-key representation
7127 /// (string, number, or symbol).
7128 ///
7129 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7130 #[cfg(js_sys_unstable_apis)]
7131 #[wasm_bindgen(
7132 static_method_of = Object,
7133 js_name = getOwnPropertyDescriptor,
7134 catch,
7135 experimental_generic_mono
7136 )]
7137 pub fn get_own_property_descriptor<T, K: PropertyKey>(
7138 obj: &Object<T>,
7139 prop: K,
7140 ) -> Result<Option<PropertyDescriptor<T>>, JsValue>;
7141
7142 // Next major: deprecate
7143 /// The `Object.getOwnPropertyDescriptor()` method returns a
7144 /// property descriptor for an own property (that is, one directly
7145 /// present on an object and not in the object's prototype chain)
7146 /// of a given object.
7147 ///
7148 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7149 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
7150 pub fn get_own_property_descriptor_str<T>(
7151 obj: &Object<T>,
7152 prop: &JsString,
7153 ) -> Result<PropertyDescriptor<T>, JsValue>;
7154
7155 /// The `Object.getOwnPropertyDescriptor()` method returns a
7156 /// property descriptor for an own property (that is, one directly
7157 /// present on an object and not in the object's prototype chain)
7158 /// of a given object.
7159 ///
7160 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7161 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
7162 pub fn get_own_property_descriptor_symbol<T>(
7163 obj: &Object<T>,
7164 prop: &Symbol,
7165 ) -> Result<PropertyDescriptor<JsValue>, JsValue>;
7166
7167 /// The `Object.getOwnPropertyDescriptors()` method returns all own
7168 /// property descriptors of a given object.
7169 ///
7170 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
7171 #[cfg(not(js_sys_unstable_apis))]
7172 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
7173 pub fn get_own_property_descriptors<T>(obj: &Object<T>) -> JsValue;
7174
7175 /// The `Object.getOwnPropertyDescriptors()` method returns all own
7176 /// property descriptors of a given object.
7177 ///
7178 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
7179 #[cfg(js_sys_unstable_apis)]
7180 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors, catch)]
7181 pub fn get_own_property_descriptors<T>(
7182 obj: &Object<T>,
7183 ) -> Result<Object<PropertyDescriptor<T>>, JsValue>;
7184
7185 /// The `Object.getOwnPropertyNames()` method returns an array of
7186 /// all properties (including non-enumerable properties except for
7187 /// those which use Symbol) found directly upon a given object.
7188 ///
7189 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
7190 #[cfg(not(js_sys_unstable_apis))]
7191 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
7192 pub fn get_own_property_names<T>(obj: &Object<T>) -> Array;
7193
7194 /// The `Object.getOwnPropertyNames()` method returns an array of
7195 /// all properties (including non-enumerable properties except for
7196 /// those which use Symbol) found directly upon a given object.
7197 ///
7198 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
7199 #[cfg(js_sys_unstable_apis)]
7200 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames, catch)]
7201 pub fn get_own_property_names<T>(obj: &Object<T>) -> Result<Array<JsString>, JsValue>;
7202
7203 /// The `Object.getOwnPropertySymbols()` method returns an array of
7204 /// all symbol properties found directly upon a given object.
7205 ///
7206 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
7207 #[cfg(not(js_sys_unstable_apis))]
7208 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
7209 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Array;
7210
7211 /// The `Object.getOwnPropertySymbols()` method returns an array of
7212 /// all symbol properties found directly upon a given object.
7213 ///
7214 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
7215 #[cfg(js_sys_unstable_apis)]
7216 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols, catch)]
7217 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Result<Array<Symbol>, JsValue>;
7218
7219 /// The `Object.getPrototypeOf()` method returns the prototype
7220 /// (i.e. the value of the internal [[Prototype]] property) of the
7221 /// specified object.
7222 ///
7223 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
7224 #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
7225 pub fn get_prototype_of(obj: &JsValue) -> Object;
7226
7227 /// The `hasOwnProperty()` method returns a boolean indicating whether the
7228 /// object has the specified property as its own property (as opposed to
7229 /// inheriting it).
7230 ///
7231 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
7232 #[deprecated(note = "Use `Object::hasOwn` instead.")]
7233 #[allow(deprecated)]
7234 #[wasm_bindgen(method, js_name = hasOwnProperty)]
7235 pub fn has_own_property<T>(this: &Object<T>, property: &JsValue) -> bool;
7236
7237 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7238 /// object passed in has the specified property as its own property (as
7239 /// opposed to inheriting it).
7240 ///
7241 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7242 #[cfg(not(js_sys_unstable_apis))]
7243 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn)]
7244 pub fn has_own<T>(instance: &Object<T>, property: &JsValue) -> bool;
7245
7246 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7247 /// object passed in has the specified property as its own property (as
7248 /// opposed to inheriting it).
7249 ///
7250 /// The property key may be any JavaScript property-key representation
7251 /// (string, number, or symbol).
7252 ///
7253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7254 #[cfg(js_sys_unstable_apis)]
7255 #[wasm_bindgen(
7256 static_method_of = Object,
7257 js_name = hasOwn,
7258 catch,
7259 experimental_generic_mono
7260 )]
7261 pub fn has_own<T, K: PropertyKey>(instance: &Object<T>, property: K) -> Result<bool, JsValue>;
7262
7263 // Next major: deprecate
7264 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7265 /// object passed in has the specified property as its own property (as
7266 /// opposed to inheriting it).
7267 ///
7268 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7269 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7270 pub fn has_own_str<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
7271
7272 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7273 /// object passed in has the specified property as its own property (as
7274 /// opposed to inheriting it).
7275 ///
7276 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7277 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7278 pub fn has_own_symbol<T>(instance: &Object<T>, property: &Symbol) -> Result<bool, JsValue>;
7279
7280 /// The `Object.is()` method determines whether two values are the same value.
7281 ///
7282 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
7283 #[wasm_bindgen(static_method_of = Object)]
7284 pub fn is(value1: &JsValue, value_2: &JsValue) -> bool;
7285
7286 /// The `Object.isExtensible()` method determines if an object is extensible
7287 /// (whether it can have new properties added to it).
7288 ///
7289 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
7290 #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
7291 pub fn is_extensible<T>(object: &Object<T>) -> bool;
7292
7293 /// The `Object.isFrozen()` determines if an object is frozen.
7294 ///
7295 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
7296 #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
7297 pub fn is_frozen<T>(object: &Object<T>) -> bool;
7298
7299 /// The `Object.isSealed()` method determines if an object is sealed.
7300 ///
7301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
7302 #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
7303 pub fn is_sealed<T>(object: &Object<T>) -> bool;
7304
7305 /// The `isPrototypeOf()` method checks if an object exists in another
7306 /// object's prototype chain.
7307 ///
7308 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
7309 #[wasm_bindgen(method, js_name = isPrototypeOf)]
7310 pub fn is_prototype_of<T>(this: &Object<T>, value: &JsValue) -> bool;
7311
7312 /// The `Object.keys()` method returns an array of a given object's property
7313 /// names, in the same order as we get with a normal loop.
7314 ///
7315 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7316 #[cfg(not(js_sys_unstable_apis))]
7317 #[wasm_bindgen(static_method_of = Object)]
7318 pub fn keys<T>(object: &Object<T>) -> Array;
7319
7320 /// The `Object.keys()` method returns an array of a given object's property
7321 /// names, in the same order as we get with a normal loop.
7322 ///
7323 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7324 #[cfg(js_sys_unstable_apis)]
7325 #[wasm_bindgen(static_method_of = Object)]
7326 pub fn keys<T>(object: &Object<T>) -> Array<JsString>;
7327
7328 /// The [`Object`] constructor creates an object wrapper.
7329 ///
7330 /// **Note:** Consider using [`Object::new_typed`] for typed object records.
7331 ///
7332 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7333 #[wasm_bindgen(constructor)]
7334 pub fn new() -> Object;
7335
7336 // Next major: deprecate
7337 /// The [`Object`] constructor creates an object wrapper.
7338 ///
7339 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7340 #[wasm_bindgen(constructor)]
7341 pub fn new_typed<T>() -> Object<T>;
7342
7343 /// The `Object.preventExtensions()` method prevents new properties from
7344 /// ever being added to an object (i.e. prevents future extensions to the
7345 /// object).
7346 ///
7347 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
7348 #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
7349 pub fn prevent_extensions<T>(object: &Object<T>);
7350
7351 /// The `propertyIsEnumerable()` method returns a Boolean indicating
7352 /// whether the specified property is enumerable.
7353 ///
7354 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7355 #[cfg(not(js_sys_unstable_apis))]
7356 #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
7357 pub fn property_is_enumerable<T>(this: &Object<T>, property: &JsValue) -> bool;
7358
7359 /// The `propertyIsEnumerable()` method returns whether the specified
7360 /// property is both an own property and enumerable.
7361 ///
7362 /// The property key may be any JavaScript property-key representation
7363 /// (string, number, or symbol).
7364 ///
7365 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7366 #[cfg(js_sys_unstable_apis)]
7367 #[wasm_bindgen(
7368 method,
7369 js_name = propertyIsEnumerable,
7370 experimental_generic_mono
7371 )]
7372 pub fn property_is_enumerable<T, K: PropertyKey>(this: &Object<T>, property: K) -> bool;
7373
7374 /// The `Object.seal()` method seals an object, preventing new properties
7375 /// from being added to it and marking all existing properties as
7376 /// non-configurable. Values of present properties can still be changed as
7377 /// long as they are writable.
7378 ///
7379 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
7380 #[wasm_bindgen(static_method_of = Object)]
7381 pub fn seal<T>(value: &Object<T>) -> Object<T>;
7382
7383 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7384 /// internal `[[Prototype]]` property) of a specified object to another
7385 /// object or `null`.
7386 ///
7387 /// **Note:** Consider using [`Object::try_set_prototype_of`] to support errors.
7388 ///
7389 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7390 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
7391 pub fn set_prototype_of<T>(object: &Object<T>, prototype: &Object) -> Object<T>;
7392
7393 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7394 /// internal `[[Prototype]]` property) of a specified object to another
7395 /// object or `null`.
7396 ///
7397 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7398 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf, catch)]
7399 pub fn try_set_prototype_of<T>(
7400 object: &Object<T>,
7401 prototype: &Object,
7402 ) -> Result<Object<T>, JsValue>;
7403
7404 /// The `toLocaleString()` method returns a string representing the object.
7405 /// This method is meant to be overridden by derived objects for
7406 /// locale-specific purposes.
7407 ///
7408 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
7409 #[wasm_bindgen(method, js_name = toLocaleString)]
7410 pub fn to_locale_string<T>(this: &Object<T>) -> JsString;
7411
7412 // Next major: deprecate
7413 /// The `toString()` method returns a string representing the object.
7414 ///
7415 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7416 #[wasm_bindgen(method, js_name = toString)]
7417 pub fn to_string<T>(this: &Object<T>) -> JsString;
7418
7419 /// The `toString()` method returns a string representing the object.
7420 ///
7421 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7422 #[wasm_bindgen(method, js_name = toString)]
7423 pub fn to_js_string<T>(this: &Object<T>) -> JsString;
7424
7425 /// The `valueOf()` method returns the primitive value of the
7426 /// specified object.
7427 ///
7428 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
7429 #[wasm_bindgen(method, js_name = valueOf)]
7430 pub fn value_of<T>(this: &Object<T>) -> Object;
7431
7432 /// The `Object.values()` method returns an array of a given object's own
7433 /// enumerable property values, in the same order as that provided by a
7434 /// `for...in` loop (the difference being that a for-in loop enumerates
7435 /// properties in the prototype chain as well).
7436 ///
7437 /// **Note:** Consider using [`Object::try_values`] to support errors.
7438 ///
7439 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7440 #[cfg(not(js_sys_unstable_apis))]
7441 #[wasm_bindgen(static_method_of = Object)]
7442 pub fn values<T>(object: &Object<T>) -> Array<T>;
7443
7444 /// The `Object.values()` method returns an array of a given object's own
7445 /// enumerable property values, in the same order as that provided by a
7446 /// `for...in` loop (the difference being that a for-in loop enumerates
7447 /// properties in the prototype chain as well).
7448 ///
7449 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7450 #[cfg(js_sys_unstable_apis)]
7451 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7452 pub fn values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7453
7454 // Next major: deprecate
7455 /// The `Object.values()` method returns an array of a given object's own
7456 /// enumerable property values, in the same order as that provided by a
7457 /// `for...in` loop (the difference being that a for-in loop enumerates
7458 /// properties in the prototype chain as well).
7459 ///
7460 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7461 #[cfg(not(js_sys_unstable_apis))]
7462 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7463 pub fn try_values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7464}
7465
7466impl Object {
7467 /// Returns the `Object` value of this JS value if it's an instance of an
7468 /// object.
7469 ///
7470 /// If this JS value is not an instance of an object then this returns
7471 /// `None`.
7472 pub fn try_from(val: &JsValue) -> Option<&Object> {
7473 if val.is_object() {
7474 Some(val.unchecked_ref())
7475 } else {
7476 None
7477 }
7478 }
7479}
7480
7481// `Object.is`, not the derived `===`: subclasses like `Number` can hold
7482// `NaN`, for which `===` is not reflexive as `Eq` requires. Next major: add
7483// a reference-value base type excluding primitives, move `Number` onto
7484// `JsValue`, and derive.
7485impl<T> PartialEq for Object<T> {
7486 #[inline]
7487 fn eq(&self, other: &Object<T>) -> bool {
7488 Object::is(self.as_ref(), other.as_ref())
7489 }
7490}
7491
7492impl<T> Eq for Object<T> {}
7493
7494impl Default for Object<JsValue> {
7495 fn default() -> Self {
7496 Self::new()
7497 }
7498}
7499
7500// Proxy
7501#[wasm_bindgen]
7502extern "C" {
7503 #[wasm_bindgen(typescript_type = "ProxyConstructor")]
7504 #[derive(Clone, Debug)]
7505 pub type Proxy;
7506
7507 /// The [`Proxy`] object is used to define custom behavior for fundamental
7508 /// operations (e.g. property lookup, assignment, enumeration, function
7509 /// invocation, etc).
7510 ///
7511 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
7512 #[wasm_bindgen(constructor)]
7513 pub fn new(target: &JsValue, handler: &Object) -> Proxy;
7514
7515 /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
7516 /// object.
7517 ///
7518 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
7519 #[wasm_bindgen(static_method_of = Proxy)]
7520 pub fn revocable(target: &JsValue, handler: &Object) -> Object;
7521}
7522
7523// RangeError
7524#[wasm_bindgen]
7525extern "C" {
7526 /// The `RangeError` object indicates an error when a value is not in the set
7527 /// or range of allowed values.
7528 ///
7529 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7530 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
7531 #[derive(Clone, Debug, PartialEq, Eq)]
7532 pub type RangeError;
7533
7534 /// The `RangeError` object indicates an error when a value is not in the set
7535 /// or range of allowed values.
7536 ///
7537 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7538 #[wasm_bindgen(constructor)]
7539 pub fn new(message: &str) -> RangeError;
7540
7541 /// Creates a new `RangeError` with the given message and a typed
7542 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
7543 /// original cause of the error.
7544 ///
7545 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError/RangeError)
7546 #[wasm_bindgen(constructor)]
7547 pub fn new_with_options(message: &str, options: &ErrorOptions) -> RangeError;
7548}
7549
7550// ReferenceError
7551#[wasm_bindgen]
7552extern "C" {
7553 /// The `ReferenceError` object represents an error when a non-existent
7554 /// variable is referenced.
7555 ///
7556 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7557 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
7558 #[derive(Clone, Debug, PartialEq, Eq)]
7559 pub type ReferenceError;
7560
7561 /// The `ReferenceError` object represents an error when a non-existent
7562 /// variable is referenced.
7563 ///
7564 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7565 #[wasm_bindgen(constructor)]
7566 pub fn new(message: &str) -> ReferenceError;
7567
7568 /// Creates a new `ReferenceError` with the given message and a typed
7569 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
7570 /// original cause of the error.
7571 ///
7572 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError/ReferenceError)
7573 #[wasm_bindgen(constructor)]
7574 pub fn new_with_options(message: &str, options: &ErrorOptions) -> ReferenceError;
7575}
7576
7577#[allow(non_snake_case)]
7578pub mod Reflect {
7579 use super::*;
7580
7581 // Reflect
7582 #[wasm_bindgen]
7583 extern "C" {
7584 /// The static `Reflect.apply()` method calls a target function with
7585 /// arguments as specified.
7586 ///
7587 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
7588 #[wasm_bindgen(js_namespace = Reflect, catch)]
7589 pub fn apply<T: JsFunction = fn() -> JsValue>(
7590 target: &Function<T>,
7591 this_argument: &JsValue,
7592 arguments_list: &Array,
7593 ) -> Result<<T as JsFunction>::Ret, JsValue>;
7594
7595 /// The static `Reflect.construct()` method acts like the new operator, but
7596 /// as a function. It is equivalent to calling `new target(...args)`. It
7597 /// gives also the added option to specify a different prototype.
7598 ///
7599 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7600 #[cfg(not(js_sys_unstable_apis))]
7601 #[wasm_bindgen(js_namespace = Reflect, catch)]
7602 pub fn construct<T: JsFunction = fn() -> JsValue>(
7603 target: &Function<T>,
7604 arguments_list: &Array,
7605 ) -> Result<JsValue, JsValue>;
7606
7607 /// The static `Reflect.construct()` method acts like the new operator, but
7608 /// as a function. It is equivalent to calling `new target(...args)`. It
7609 /// gives also the added option to specify a different prototype.
7610 ///
7611 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7612 #[cfg(js_sys_unstable_apis)]
7613 #[wasm_bindgen(js_namespace = Reflect, catch)]
7614 pub fn construct<T: JsFunction = fn() -> JsValue>(
7615 target: &Function<T>,
7616 arguments_list: &ArrayTuple, // DOTO: <A1, A2, A3, A4, A5, A6, A7, A8>,
7617 ) -> Result<JsValue, JsValue>;
7618
7619 /// The static `Reflect.construct()` method acts like the new operator, but
7620 /// as a function. It is equivalent to calling `new target(...args)`. It
7621 /// gives also the added option to specify a different prototype.
7622 ///
7623 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7624 #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
7625 pub fn construct_with_new_target(
7626 target: &Function,
7627 arguments_list: &Array,
7628 new_target: &Function,
7629 ) -> Result<JsValue, JsValue>;
7630
7631 /// The static `Reflect.defineProperty()` method is like
7632 /// `Object.defineProperty()` but returns a `Boolean`.
7633 ///
7634 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7635 #[cfg(not(js_sys_unstable_apis))]
7636 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7637 pub fn define_property<T>(
7638 target: &Object<T>,
7639 property_key: &JsValue,
7640 attributes: &Object,
7641 ) -> Result<bool, JsValue>;
7642
7643 /// The static `Reflect.defineProperty()` method is like
7644 /// `Object.defineProperty()` but returns a `Boolean`.
7645 ///
7646 /// The property key may be any JavaScript property-key representation
7647 /// (string, number, or symbol).
7648 ///
7649 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7650 #[cfg(js_sys_unstable_apis)]
7651 #[wasm_bindgen(
7652 js_namespace = Reflect,
7653 js_name = defineProperty,
7654 catch,
7655 experimental_generic_mono
7656 )]
7657 pub fn define_property<T, K: PropertyKey>(
7658 target: &Object<T>,
7659 property_key: K,
7660 attributes: &PropertyDescriptor<T>,
7661 ) -> Result<bool, JsValue>;
7662
7663 /// The static `Reflect.defineProperty()` method is like
7664 /// `Object.defineProperty()` but returns a `Boolean`.
7665 ///
7666 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7667 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7668 pub fn define_property_str<T>(
7669 target: &Object<T>,
7670 property_key: &JsString,
7671 attributes: &PropertyDescriptor<T>,
7672 ) -> Result<bool, JsValue>;
7673
7674 /// The static `Reflect.deleteProperty()` method allows to delete
7675 /// properties. It is like the `delete` operator as a function.
7676 ///
7677 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7678 #[cfg(not(js_sys_unstable_apis))]
7679 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7680 pub fn delete_property<T>(target: &Object<T>, key: &JsValue) -> Result<bool, JsValue>;
7681
7682 /// The static `Reflect.deleteProperty()` method allows to delete
7683 /// properties. It is like the `delete` operator as a function.
7684 ///
7685 /// The property key may be any JavaScript property-key representation
7686 /// (string, number, or symbol).
7687 ///
7688 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7689 #[cfg(js_sys_unstable_apis)]
7690 #[wasm_bindgen(
7691 js_namespace = Reflect,
7692 js_name = deleteProperty,
7693 catch,
7694 experimental_generic_mono
7695 )]
7696 pub fn delete_property<T, K: PropertyKey>(
7697 target: &Object<T>,
7698 key: K,
7699 ) -> Result<bool, JsValue>;
7700
7701 /// The static `Reflect.deleteProperty()` method allows to delete
7702 /// properties. It is like the `delete` operator as a function.
7703 ///
7704 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7705 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7706 pub fn delete_property_str<T>(target: &Object<T>, key: &JsString) -> Result<bool, JsValue>;
7707
7708 /// The static `Reflect.get()` method works like getting a property from
7709 /// an object (`target[propertyKey]`) as a function.
7710 ///
7711 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7712 #[cfg(not(js_sys_unstable_apis))]
7713 #[wasm_bindgen(js_namespace = Reflect, catch)]
7714 pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
7715
7716 /// The static `Reflect.get()` method works like getting a property from
7717 /// an object (`target[propertyKey]`) as a function.
7718 ///
7719 /// The property key may be any JavaScript property-key representation
7720 /// (string, number, or symbol).
7721 ///
7722 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7723 #[cfg(js_sys_unstable_apis)]
7724 #[wasm_bindgen(js_namespace = Reflect, catch, experimental_generic_mono)]
7725 pub fn get<T, K: PropertyKey>(target: &Object<T>, key: K) -> Result<Option<T>, JsValue>;
7726
7727 /// The static `Reflect.get()` method works like getting a property from
7728 /// an object (`target[propertyKey]`) as a function.
7729 ///
7730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7731 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7732 pub fn get_str<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7733
7734 /// The static `Reflect.get()` method works like getting a property from
7735 /// an object (`target[propertyKey]`) as a function.
7736 ///
7737 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7738 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7739 pub fn get_symbol<T>(target: &Object<T>, key: &Symbol) -> Result<JsValue, JsValue>;
7740
7741 /// The same as [`get`](fn.get.html)
7742 /// except the key is an `f64`, which is slightly faster.
7743 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7744 pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
7745
7746 /// The same as [`get`](fn.get.html)
7747 /// except the key is a `u32`, which is slightly faster.
7748 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7749 pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
7750
7751 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7752 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7753 /// of the given property if it exists on the object, `undefined` otherwise.
7754 ///
7755 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7756 #[cfg(not(js_sys_unstable_apis))]
7757 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7758 pub fn get_own_property_descriptor<T>(
7759 target: &Object<T>,
7760 property_key: &JsValue,
7761 ) -> Result<JsValue, JsValue>;
7762
7763 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7764 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7765 /// of the given property if it exists on the object, `undefined` otherwise.
7766 ///
7767 /// The property key may be any JavaScript property-key representation
7768 /// (string, number, or symbol).
7769 ///
7770 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7771 #[cfg(js_sys_unstable_apis)]
7772 #[wasm_bindgen(
7773 js_namespace = Reflect,
7774 js_name = getOwnPropertyDescriptor,
7775 catch,
7776 experimental_generic_mono
7777 )]
7778 pub fn get_own_property_descriptor<T, K: PropertyKey>(
7779 target: &Object<T>,
7780 property_key: K,
7781 ) -> Result<Option<PropertyDescriptor<T>>, JsValue>;
7782
7783 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7784 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7785 /// of the given property if it exists on the object, `undefined` otherwise.
7786 ///
7787 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7788 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7789 pub fn get_own_property_descriptor_str<T>(
7790 target: &Object<T>,
7791 property_key: &JsString,
7792 ) -> Result<PropertyDescriptor<T>, JsValue>;
7793
7794 /// The static `Reflect.getPrototypeOf()` method is almost the same
7795 /// method as `Object.getPrototypeOf()`. It returns the prototype
7796 /// (i.e. the value of the internal `[[Prototype]]` property) of
7797 /// the specified object.
7798 ///
7799 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7800 #[cfg(not(js_sys_unstable_apis))]
7801 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7802 pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
7803
7804 /// The static `Reflect.getPrototypeOf()` method is almost the same
7805 /// method as `Object.getPrototypeOf()`. It returns the prototype
7806 /// (i.e. the value of the internal `[[Prototype]]` property) of
7807 /// the specified object.
7808 ///
7809 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7810 #[cfg(js_sys_unstable_apis)]
7811 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7812 pub fn get_prototype_of(target: &Object) -> Result<Object, JsValue>;
7813
7814 /// The static `Reflect.has()` method works like the in operator as a
7815 /// function.
7816 ///
7817 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7818 #[cfg(not(js_sys_unstable_apis))]
7819 #[wasm_bindgen(js_namespace = Reflect, catch)]
7820 pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
7821
7822 /// The static `Reflect.has()` method works like the in operator as a
7823 /// function.
7824 ///
7825 /// The property key may be any JavaScript property-key representation
7826 /// (string, number, or symbol).
7827 ///
7828 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7829 #[cfg(js_sys_unstable_apis)]
7830 #[wasm_bindgen(js_namespace = Reflect, catch, experimental_generic_mono)]
7831 pub fn has<T, K: PropertyKey>(target: &Object<T>, property_key: K)
7832 -> Result<bool, JsValue>;
7833
7834 // Next major: deprecate
7835 /// The static `Reflect.has()` method works like the in operator as a
7836 /// function.
7837 ///
7838 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7839 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7840 pub fn has_str<T>(target: &Object<T>, property_key: &JsString) -> Result<bool, JsValue>;
7841
7842 /// The static `Reflect.has()` method works like the in operator as a
7843 /// function.
7844 ///
7845 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7846 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7847 pub fn has_symbol<T>(target: &Object<T>, property_key: &Symbol) -> Result<bool, JsValue>;
7848
7849 /// The static `Reflect.isExtensible()` method determines if an object is
7850 /// extensible (whether it can have new properties added to it). It is
7851 /// similar to `Object.isExtensible()`, but with some differences.
7852 ///
7853 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
7854 #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
7855 pub fn is_extensible<T>(target: &Object<T>) -> Result<bool, JsValue>;
7856
7857 /// The static `Reflect.ownKeys()` method returns an array of the
7858 /// target object's own property keys.
7859 ///
7860 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
7861 #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
7862 pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
7863
7864 /// The static `Reflect.preventExtensions()` method prevents new
7865 /// properties from ever being added to an object (i.e. prevents
7866 /// future extensions to the object). It is similar to
7867 /// `Object.preventExtensions()`, but with some differences.
7868 ///
7869 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
7870 #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
7871 pub fn prevent_extensions<T>(target: &Object<T>) -> Result<bool, JsValue>;
7872
7873 /// The static `Reflect.set()` method works like setting a
7874 /// property on an object.
7875 ///
7876 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7877 #[cfg(not(js_sys_unstable_apis))]
7878 #[wasm_bindgen(js_namespace = Reflect, catch)]
7879 pub fn set(
7880 target: &JsValue,
7881 property_key: &JsValue,
7882 value: &JsValue,
7883 ) -> Result<bool, JsValue>;
7884
7885 /// The static `Reflect.set()` method works like setting a
7886 /// property on an object.
7887 ///
7888 /// The property key may be any JavaScript property-key representation
7889 /// (string, number, or symbol).
7890 ///
7891 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7892 #[cfg(js_sys_unstable_apis)]
7893 #[wasm_bindgen(js_namespace = Reflect, catch, experimental_generic_mono)]
7894 pub fn set<T, K: PropertyKey>(
7895 target: &Object<T>,
7896 property_key: K,
7897 value: &T,
7898 ) -> Result<bool, JsValue>;
7899
7900 /// The static `Reflect.set()` method works like setting a
7901 /// property on an object.
7902 ///
7903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7904 #[cfg(js_sys_unstable_apis)]
7905 #[wasm_bindgen(js_namespace = Reflect, catch)]
7906 pub fn set_symbol<T>(
7907 target: &Object<T>,
7908 property_key: &Symbol,
7909 value: &JsValue,
7910 ) -> Result<bool, JsValue>;
7911
7912 // Next major: deprecate
7913 /// The static `Reflect.set()` method works like setting a
7914 /// property on an object.
7915 ///
7916 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7917 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7918 pub fn set_str<T>(
7919 target: &Object<T>,
7920 property_key: &JsString,
7921 value: &T,
7922 ) -> Result<bool, JsValue>;
7923
7924 /// The same as [`set`](fn.set.html)
7925 /// except the key is an `f64`, which is slightly faster.
7926 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7927 pub fn set_f64(
7928 target: &JsValue,
7929 property_key: f64,
7930 value: &JsValue,
7931 ) -> Result<bool, JsValue>;
7932
7933 /// The same as [`set`](fn.set.html)
7934 /// except the key is a `u32`, which is slightly faster.
7935 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7936 pub fn set_u32(
7937 target: &JsValue,
7938 property_key: u32,
7939 value: &JsValue,
7940 ) -> Result<bool, JsValue>;
7941
7942 /// The static `Reflect.set()` method works like setting a
7943 /// property on an object.
7944 ///
7945 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7946 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7947 pub fn set_with_receiver(
7948 target: &JsValue,
7949 property_key: &JsValue,
7950 value: &JsValue,
7951 receiver: &JsValue,
7952 ) -> Result<bool, JsValue>;
7953
7954 /// The static `Reflect.setPrototypeOf()` method is the same
7955 /// method as `Object.setPrototypeOf()`. It sets the prototype
7956 /// (i.e., the internal `[[Prototype]]` property) of a specified
7957 /// object to another object or to null.
7958 ///
7959 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
7960 #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
7961 pub fn set_prototype_of<T>(
7962 target: &Object<T>,
7963 prototype: &JsValue,
7964 ) -> Result<bool, JsValue>;
7965 }
7966}
7967
7968// RegExp
7969#[wasm_bindgen]
7970extern "C" {
7971 #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
7972 #[derive(Clone, Debug, PartialEq, Eq)]
7973 pub type RegExp;
7974
7975 /// The `exec()` method executes a search for a match in a specified
7976 /// string. Returns a result array, or null.
7977 ///
7978 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7979 #[cfg(not(js_sys_unstable_apis))]
7980 #[wasm_bindgen(method)]
7981 pub fn exec(this: &RegExp, text: &str) -> Option<Array<JsString>>;
7982
7983 /// The `exec()` method executes a search for a match in a specified
7984 /// string. Returns a result array, or null.
7985 ///
7986 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7987 #[cfg(js_sys_unstable_apis)]
7988 #[wasm_bindgen(method)]
7989 pub fn exec(this: &RegExp, text: &str) -> Option<RegExpMatchArray>;
7990
7991 /// The flags property returns a string consisting of the flags of
7992 /// the current regular expression object.
7993 ///
7994 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
7995 #[wasm_bindgen(method, getter)]
7996 pub fn flags(this: &RegExp) -> JsString;
7997
7998 /// The global property indicates whether or not the "g" flag is
7999 /// used with the regular expression. global is a read-only
8000 /// property of an individual regular expression instance.
8001 ///
8002 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
8003 #[wasm_bindgen(method, getter)]
8004 pub fn global(this: &RegExp) -> bool;
8005
8006 /// The ignoreCase property indicates whether or not the "i" flag
8007 /// is used with the regular expression. ignoreCase is a read-only
8008 /// property of an individual regular expression instance.
8009 ///
8010 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
8011 #[wasm_bindgen(method, getter, js_name = ignoreCase)]
8012 pub fn ignore_case(this: &RegExp) -> bool;
8013
8014 /// The non-standard input property is a static property of
8015 /// regular expressions that contains the string against which a
8016 /// regular expression is matched. RegExp.$_ is an alias for this
8017 /// property.
8018 ///
8019 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
8020 #[wasm_bindgen(static_method_of = RegExp, getter)]
8021 pub fn input() -> JsString;
8022
8023 /// The lastIndex is a read/write integer property of regular expression
8024 /// instances that specifies the index at which to start the next match.
8025 ///
8026 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
8027 #[wasm_bindgen(structural, getter = lastIndex, method)]
8028 pub fn last_index(this: &RegExp) -> u32;
8029
8030 /// The lastIndex is a read/write integer property of regular expression
8031 /// instances that specifies the index at which to start the next match.
8032 ///
8033 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
8034 #[wasm_bindgen(structural, setter = lastIndex, method)]
8035 pub fn set_last_index(this: &RegExp, index: u32);
8036
8037 /// The non-standard lastMatch property is a static and read-only
8038 /// property of regular expressions that contains the last matched
8039 /// characters. `RegExp.$&` is an alias for this property.
8040 ///
8041 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
8042 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
8043 pub fn last_match() -> JsString;
8044
8045 /// The non-standard lastParen property is a static and read-only
8046 /// property of regular expressions that contains the last
8047 /// parenthesized substring match, if any. `RegExp.$+` is an alias
8048 /// for this property.
8049 ///
8050 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
8051 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
8052 pub fn last_paren() -> JsString;
8053
8054 /// The non-standard leftContext property is a static and
8055 /// read-only property of regular expressions that contains the
8056 /// substring preceding the most recent match. `RegExp.$`` is an
8057 /// alias for this property.
8058 ///
8059 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
8060 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
8061 pub fn left_context() -> JsString;
8062
8063 /// The multiline property indicates whether or not the "m" flag
8064 /// is used with the regular expression. multiline is a read-only
8065 /// property of an individual regular expression instance.
8066 ///
8067 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
8068 #[wasm_bindgen(method, getter)]
8069 pub fn multiline(this: &RegExp) -> bool;
8070
8071 /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
8072 /// are static and read-only properties of regular expressions
8073 /// that contain parenthesized substring matches.
8074 ///
8075 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
8076 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
8077 pub fn n1() -> JsString;
8078 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
8079 pub fn n2() -> JsString;
8080 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
8081 pub fn n3() -> JsString;
8082 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
8083 pub fn n4() -> JsString;
8084 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
8085 pub fn n5() -> JsString;
8086 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
8087 pub fn n6() -> JsString;
8088 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
8089 pub fn n7() -> JsString;
8090 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
8091 pub fn n8() -> JsString;
8092 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
8093 pub fn n9() -> JsString;
8094
8095 /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
8096 ///
8097 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
8098 #[wasm_bindgen(constructor)]
8099 pub fn new(pattern: &str, flags: &str) -> RegExp;
8100 #[wasm_bindgen(constructor)]
8101 pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
8102
8103 /// The non-standard rightContext property is a static and
8104 /// read-only property of regular expressions that contains the
8105 /// substring following the most recent match. `RegExp.$'` is an
8106 /// alias for this property.
8107 ///
8108 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
8109 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
8110 pub fn right_context() -> JsString;
8111
8112 /// The source property returns a String containing the source
8113 /// text of the regexp object, and it doesn't contain the two
8114 /// forward slashes on both sides and any flags.
8115 ///
8116 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
8117 #[wasm_bindgen(method, getter)]
8118 pub fn source(this: &RegExp) -> JsString;
8119
8120 /// The sticky property reflects whether or not the search is
8121 /// sticky (searches in strings only from the index indicated by
8122 /// the lastIndex property of this regular expression). sticky is
8123 /// a read-only property of an individual regular expression
8124 /// object.
8125 ///
8126 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
8127 #[wasm_bindgen(method, getter)]
8128 pub fn sticky(this: &RegExp) -> bool;
8129
8130 /// The `test()` method executes a search for a match between a
8131 /// regular expression and a specified string. Returns true or
8132 /// false.
8133 ///
8134 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
8135 #[wasm_bindgen(method)]
8136 pub fn test(this: &RegExp, text: &str) -> bool;
8137
8138 /// The `toString()` method returns a string representing the
8139 /// regular expression.
8140 ///
8141 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
8142 #[cfg(not(js_sys_unstable_apis))]
8143 #[wasm_bindgen(method, js_name = toString)]
8144 pub fn to_string(this: &RegExp) -> JsString;
8145
8146 /// The unicode property indicates whether or not the "u" flag is
8147 /// used with a regular expression. unicode is a read-only
8148 /// property of an individual regular expression instance.
8149 ///
8150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
8151 #[wasm_bindgen(method, getter)]
8152 pub fn unicode(this: &RegExp) -> bool;
8153}
8154
8155// RegExpMatchArray
8156#[wasm_bindgen]
8157extern "C" {
8158 /// The result array from `RegExp.exec()` or `String.matchAll()`.
8159 ///
8160 /// This is an array of strings with additional properties `index`, `input`, and `groups`.
8161 ///
8162 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#return_value)
8163 #[wasm_bindgen(extends = Object, extends = Array, typescript_type = "RegExpMatchArray")]
8164 #[derive(Clone, Debug, PartialEq, Eq)]
8165 pub type RegExpMatchArray;
8166
8167 /// The 0-based index of the match in the string.
8168 #[wasm_bindgen(method, getter)]
8169 pub fn index(this: &RegExpMatchArray) -> u32;
8170
8171 /// The original string that was matched against.
8172 #[wasm_bindgen(method, getter)]
8173 pub fn input(this: &RegExpMatchArray) -> JsString;
8174
8175 /// An object of named capturing groups whose keys are the names and valuestype Array
8176 /// are the capturing groups, or `undefined` if no named capturing groups were defined.
8177 #[wasm_bindgen(method, getter)]
8178 pub fn groups(this: &RegExpMatchArray) -> Option<Object>;
8179
8180 /// The number of elements in the match array (full match + capture groups).
8181 #[wasm_bindgen(method, getter)]
8182 pub fn length(this: &RegExpMatchArray) -> u32;
8183
8184 /// Gets the matched string or capture group at the given index.
8185 /// Index 0 is the full match, indices 1+ are capture groups.
8186 #[wasm_bindgen(method, indexing_getter)]
8187 pub fn get(this: &RegExpMatchArray, index: u32) -> Option<JsString>;
8188}
8189
8190// Set
8191#[wasm_bindgen]
8192extern "C" {
8193 #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
8194 #[derive(Clone, Debug, PartialEq, Eq)]
8195 pub type Set<T = JsValue>;
8196
8197 /// The [`Set`] object lets you store unique values of any type, whether
8198 /// primitive values or object references.
8199 ///
8200 /// **Note:** Consider using [`Set::new_typed`] to support typing.
8201 ///
8202 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8203 #[cfg(not(js_sys_unstable_apis))]
8204 #[wasm_bindgen(constructor)]
8205 pub fn new(init: &JsValue) -> Set;
8206
8207 /// The [`Set`] object lets you store unique values of any type, whether
8208 /// primitive values or object references.
8209 ///
8210 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8211 #[cfg(js_sys_unstable_apis)]
8212 #[wasm_bindgen(constructor)]
8213 pub fn new<T>() -> Set<T>;
8214
8215 // Next major: deprecate
8216 /// The [`Set`] object lets you store unique values of any type, whether
8217 /// primitive values or object references.
8218 ///
8219 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8220 #[wasm_bindgen(constructor)]
8221 pub fn new_typed<T>() -> Set<T>;
8222
8223 /// The [`Set`] object lets you store unique values of any type, whether
8224 /// primitive values or object references.
8225 ///
8226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8227 #[wasm_bindgen(constructor, js_name = new)]
8228 pub fn new_empty<T>() -> Set<T>;
8229
8230 /// The [`Set`] object lets you store unique values of any type, whether
8231 /// primitive values or object references.
8232 ///
8233 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8234 #[wasm_bindgen(constructor, js_name = new)]
8235 pub fn new_from_items<T>(items: &[T]) -> Set<T>;
8236
8237 /// The [`Set`] object lets you store unique values of any type, whether
8238 /// primitive values or object references.
8239 ///
8240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8241 #[wasm_bindgen(constructor, js_name = new, catch)]
8242 pub fn new_from_iterable<T, I: Iterable<Item = T>>(iterable: I) -> Result<Set<T>, JsValue>;
8243
8244 /// The `add()` method appends a new element with a specified value to the
8245 /// end of a [`Set`] object.
8246 ///
8247 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
8248 #[wasm_bindgen(method)]
8249 pub fn add<T>(this: &Set<T>, value: &T) -> Set<T>;
8250
8251 /// The `clear()` method removes all elements from a [`Set`] object.
8252 ///
8253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
8254 #[wasm_bindgen(method)]
8255 pub fn clear<T>(this: &Set<T>);
8256
8257 /// The `delete()` method removes the specified element from a [`Set`]
8258 /// object.
8259 ///
8260 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
8261 #[wasm_bindgen(method)]
8262 pub fn delete<T>(this: &Set<T>, value: &T) -> bool;
8263
8264 /// The `forEach()` method executes a provided function once for each value
8265 /// in the Set object, in insertion order.
8266 ///
8267 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8268 #[cfg(not(js_sys_unstable_apis))]
8269 #[wasm_bindgen(method, js_name = forEach)]
8270 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T, T, Set<T>));
8271
8272 /// The `forEach()` method executes a provided function once for each value
8273 /// in the Set object, in insertion order.
8274 ///
8275 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8276 #[cfg(js_sys_unstable_apis)]
8277 #[wasm_bindgen(method, js_name = forEach)]
8278 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T));
8279
8280 /// The `forEach()` method executes a provided function once for each value
8281 /// in the Set object, in insertion order.
8282 ///
8283 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8284 #[wasm_bindgen(method, js_name = forEach, catch)]
8285 pub fn try_for_each<T>(
8286 this: &Set<T>,
8287 callback: &mut dyn FnMut(T) -> Result<(), JsError>,
8288 ) -> Result<(), JsValue>;
8289
8290 /// The `has()` method returns a boolean indicating whether an element with
8291 /// the specified value exists in a [`Set`] object or not.
8292 ///
8293 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
8294 #[wasm_bindgen(method)]
8295 pub fn has<T>(this: &Set<T>, value: &T) -> bool;
8296
8297 /// The size accessor property returns the number of elements in a [`Set`]
8298 /// object.
8299 ///
8300 /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
8301 #[wasm_bindgen(method, getter)]
8302 pub fn size<T>(this: &Set<T>) -> u32;
8303
8304 /// The `union()` method returns a new set containing elements which are in
8305 /// either or both of this set and the given set.
8306 ///
8307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union)
8308 #[wasm_bindgen(method)]
8309 pub fn union<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8310
8311 /// The `intersection()` method returns a new set containing elements which are
8312 /// in both this set and the given set.
8313 ///
8314 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection)
8315 #[wasm_bindgen(method)]
8316 pub fn intersection<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8317
8318 /// The `difference()` method returns a new set containing elements which are
8319 /// in this set but not in the given set.
8320 ///
8321 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference)
8322 #[wasm_bindgen(method)]
8323 pub fn difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8324
8325 /// The `symmetricDifference()` method returns a new set containing elements
8326 /// which are in either this set or the given set, but not in both.
8327 ///
8328 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)
8329 #[wasm_bindgen(method, js_name = symmetricDifference)]
8330 pub fn symmetric_difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8331
8332 /// The `isSubsetOf()` method returns a boolean indicating whether all elements
8333 /// of this set are in the given set.
8334 ///
8335 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSubsetOf)
8336 #[wasm_bindgen(method, js_name = isSubsetOf)]
8337 pub fn is_subset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
8338
8339 /// The `isSupersetOf()` method returns a boolean indicating whether all elements
8340 /// of the given set are in this set.
8341 ///
8342 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSupersetOf)
8343 #[wasm_bindgen(method, js_name = isSupersetOf)]
8344 pub fn is_superset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
8345
8346 /// The `isDisjointFrom()` method returns a boolean indicating whether this set
8347 /// has no elements in common with the given set.
8348 ///
8349 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom)
8350 #[wasm_bindgen(method, js_name = isDisjointFrom)]
8351 pub fn is_disjoint_from<T>(this: &Set<T>, other: &Set<T>) -> bool;
8352}
8353
8354impl Default for Set<JsValue> {
8355 fn default() -> Self {
8356 Self::new_typed()
8357 }
8358}
8359
8360impl<T> Iterable for Set<T> {
8361 type Item = T;
8362}
8363
8364// SetIterator
8365#[wasm_bindgen]
8366extern "C" {
8367 /// The `entries()` method returns a new Iterator object that contains an
8368 /// array of [value, value] for each element in the Set object, in insertion
8369 /// order. For Set objects there is no key like in Map objects. However, to
8370 /// keep the API similar to the Map object, each entry has the same value
8371 /// for its key and value here, so that an array [value, value] is returned.
8372 ///
8373 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8374 #[cfg(not(js_sys_unstable_apis))]
8375 #[wasm_bindgen(method)]
8376 pub fn entries<T>(set: &Set<T>) -> Iterator;
8377
8378 /// The `entries()` method returns a new Iterator object that contains an
8379 /// array of [value, value] for each element in the Set object, in insertion
8380 /// order. For Set objects there is no key like in Map objects. However, to
8381 /// keep the API similar to the Map object, each entry has the same value
8382 /// for its key and value here, so that an array [value, value] is returned.
8383 ///
8384 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8385 #[cfg(js_sys_unstable_apis)]
8386 #[wasm_bindgen(method, js_name = entries)]
8387 pub fn entries<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
8388
8389 // Next major: deprecate
8390 /// The `entries()` method returns a new Iterator object that contains an
8391 /// array of [value, value] for each element in the Set object, in insertion
8392 /// order. For Set objects there is no key like in Map objects. However, to
8393 /// keep the API similar to the Map object, each entry has the same value
8394 /// for its key and value here, so that an array [value, value] is returned.
8395 ///
8396 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8397 #[wasm_bindgen(method, js_name = entries)]
8398 pub fn entries_typed<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
8399
8400 /// The `keys()` method is an alias for this method (for similarity with
8401 /// Map objects); it behaves exactly the same and returns values
8402 /// of Set elements.
8403 ///
8404 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
8405 #[wasm_bindgen(method)]
8406 pub fn keys<T>(set: &Set<T>) -> Iterator<T>;
8407
8408 /// The `values()` method returns a new Iterator object that contains the
8409 /// values for each element in the Set object in insertion order.
8410 ///
8411 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
8412 #[wasm_bindgen(method)]
8413 pub fn values<T>(set: &Set<T>) -> Iterator<T>;
8414}
8415
8416// SyntaxError
8417#[wasm_bindgen]
8418extern "C" {
8419 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8420 /// token order that does not conform to the syntax of the language when
8421 /// parsing code.
8422 ///
8423 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8424 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
8425 #[derive(Clone, Debug, PartialEq, Eq)]
8426 pub type SyntaxError;
8427
8428 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8429 /// token order that does not conform to the syntax of the language when
8430 /// parsing code.
8431 ///
8432 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8433 #[wasm_bindgen(constructor)]
8434 pub fn new(message: &str) -> SyntaxError;
8435
8436 /// Creates a new `SyntaxError` with the given message and a typed
8437 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8438 /// original cause of the error.
8439 ///
8440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError/SyntaxError)
8441 #[wasm_bindgen(constructor)]
8442 pub fn new_with_options(message: &str, options: &ErrorOptions) -> SyntaxError;
8443}
8444
8445// TypeError
8446#[wasm_bindgen]
8447extern "C" {
8448 /// The `TypeError` object represents an error when a value is not of the
8449 /// expected type.
8450 ///
8451 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8452 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
8453 #[derive(Clone, Debug, PartialEq, Eq)]
8454 pub type TypeError;
8455
8456 /// The `TypeError` object represents an error when a value is not of the
8457 /// expected type.
8458 ///
8459 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8460 #[wasm_bindgen(constructor)]
8461 pub fn new(message: &str) -> TypeError;
8462
8463 /// Creates a new `TypeError` with the given message and a typed
8464 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8465 /// original cause of the error.
8466 ///
8467 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError/TypeError)
8468 #[wasm_bindgen(constructor)]
8469 pub fn new_with_options(message: &str, options: &ErrorOptions) -> TypeError;
8470}
8471
8472// URIError
8473#[wasm_bindgen]
8474extern "C" {
8475 /// The `URIError` object represents an error when a global URI handling
8476 /// function was used in a wrong way.
8477 ///
8478 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8479 #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
8480 #[derive(Clone, Debug, PartialEq, Eq)]
8481 pub type UriError;
8482
8483 /// The `URIError` object represents an error when a global URI handling
8484 /// function was used in a wrong way.
8485 ///
8486 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8487 #[wasm_bindgen(constructor, js_class = "URIError")]
8488 pub fn new(message: &str) -> UriError;
8489
8490 /// Creates a new `URIError` with the given message and a typed
8491 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8492 /// original cause of the error.
8493 ///
8494 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError/URIError)
8495 #[wasm_bindgen(constructor, js_class = "URIError")]
8496 pub fn new_with_options(message: &str, options: &ErrorOptions) -> UriError;
8497}
8498
8499// WeakMap
8500#[wasm_bindgen]
8501extern "C" {
8502 #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
8503 #[derive(Clone, Debug, PartialEq, Eq)]
8504 pub type WeakMap<K = Object, V = JsValue>;
8505
8506 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8507 /// keys are weakly referenced. The keys must be objects and the values can
8508 /// be arbitrary values.
8509 ///
8510 /// **Note:** Consider using [`WeakMap::new_typed`] to support typing.
8511 ///
8512 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8513 #[cfg(not(js_sys_unstable_apis))]
8514 #[wasm_bindgen(constructor)]
8515 pub fn new() -> WeakMap;
8516
8517 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8518 /// keys are weakly referenced. The keys must be objects and the values can
8519 /// be arbitrary values.
8520 ///
8521 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8522 #[cfg(js_sys_unstable_apis)]
8523 #[wasm_bindgen(constructor)]
8524 pub fn new<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8525
8526 // Next major: deprecate
8527 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8528 /// keys are weakly referenced. The keys must be objects and the values can
8529 /// be arbitrary values.
8530 ///
8531 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8532 #[wasm_bindgen(constructor)]
8533 pub fn new_typed<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8534
8535 /// The `set()` method sets the value for the key in the [`WeakMap`] object.
8536 /// Returns the [`WeakMap`] object.
8537 ///
8538 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
8539 #[wasm_bindgen(method, js_class = "WeakMap")]
8540 pub fn set<K, V>(this: &WeakMap<K, V>, key: &K, value: &V) -> WeakMap<K, V>;
8541
8542 /// The `get()` method returns a specified by key element
8543 /// from a [`WeakMap`] object. Returns `undefined` if the key is not found.
8544 ///
8545 /// **Note:** Consider using [`WeakMap::get_checked`] to get an `Option<V>` instead.
8546 ///
8547 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8548 #[cfg(not(js_sys_unstable_apis))]
8549 #[wasm_bindgen(method)]
8550 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> V;
8551
8552 /// The `get()` method returns a specified by key element
8553 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8554 ///
8555 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8556 #[cfg(js_sys_unstable_apis)]
8557 #[wasm_bindgen(method)]
8558 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8559
8560 /// The `get()` method returns a specified by key element
8561 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8562 ///
8563 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8564 #[wasm_bindgen(method, js_name = get)]
8565 pub fn get_checked<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8566
8567 /// The `has()` method returns a boolean indicating whether an element with
8568 /// the specified key exists in the [`WeakMap`] object or not.
8569 ///
8570 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
8571 #[wasm_bindgen(method)]
8572 pub fn has<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8573
8574 /// The `delete()` method removes the specified element from a [`WeakMap`]
8575 /// object.
8576 ///
8577 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
8578 #[wasm_bindgen(method)]
8579 pub fn delete<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8580}
8581
8582impl Default for WeakMap {
8583 fn default() -> Self {
8584 Self::new()
8585 }
8586}
8587
8588// WeakSet
8589#[wasm_bindgen]
8590extern "C" {
8591 #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
8592 #[derive(Clone, Debug, PartialEq, Eq)]
8593 pub type WeakSet<T = Object>;
8594
8595 /// The `WeakSet` object lets you store weakly held objects in a collection.
8596 ///
8597 /// **Note:** Consider using [`WeakSet::new_typed`] for typed sets.
8598 ///
8599 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8600 #[cfg(not(js_sys_unstable_apis))]
8601 #[wasm_bindgen(constructor)]
8602 pub fn new() -> WeakSet;
8603
8604 /// The `WeakSet` object lets you store weakly held objects in a collection.
8605 ///
8606 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8607 #[cfg(js_sys_unstable_apis)]
8608 #[wasm_bindgen(constructor)]
8609 pub fn new<T = Object>() -> WeakSet<T>;
8610
8611 // Next major: deprecate
8612 /// The `WeakSet` object lets you store weakly held objects in a collection.
8613 ///
8614 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8615 #[wasm_bindgen(constructor)]
8616 pub fn new_typed<T = Object>() -> WeakSet<T>;
8617
8618 /// The `has()` method returns a boolean indicating whether an object exists
8619 /// in a WeakSet or not.
8620 ///
8621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
8622 #[wasm_bindgen(method)]
8623 pub fn has<T>(this: &WeakSet<T>, value: &T) -> bool;
8624
8625 /// The `add()` method appends a new object to the end of a WeakSet object.
8626 ///
8627 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
8628 #[wasm_bindgen(method)]
8629 pub fn add<T>(this: &WeakSet<T>, value: &T) -> WeakSet<T>;
8630
8631 /// The `delete()` method removes the specified element from a WeakSet
8632 /// object.
8633 ///
8634 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
8635 #[wasm_bindgen(method)]
8636 pub fn delete<T>(this: &WeakSet<T>, value: &T) -> bool;
8637}
8638
8639impl Default for WeakSet {
8640 fn default() -> Self {
8641 Self::new()
8642 }
8643}
8644
8645// WeakRef
8646#[wasm_bindgen]
8647extern "C" {
8648 #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
8649 #[derive(Clone, Debug, PartialEq, Eq)]
8650 pub type WeakRef<T = Object>;
8651
8652 /// The `WeakRef` object contains a weak reference to an object. A weak
8653 /// reference to an object is a reference that does not prevent the object
8654 /// from being reclaimed by the garbage collector.
8655 ///
8656 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
8657 #[wasm_bindgen(constructor)]
8658 pub fn new<T = Object>(target: &T) -> WeakRef<T>;
8659
8660 /// Returns the `Object` this `WeakRef` points to, or `None` if the
8661 /// object has been garbage collected.
8662 ///
8663 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
8664 #[wasm_bindgen(method)]
8665 pub fn deref<T>(this: &WeakRef<T>) -> Option<T>;
8666}
8667
8668#[cfg(js_sys_unstable_apis)]
8669#[allow(non_snake_case)]
8670pub mod Temporal;
8671
8672#[allow(non_snake_case)]
8673pub mod WebAssembly {
8674 use super::*;
8675
8676 // WebAssembly
8677 #[wasm_bindgen]
8678 extern "C" {
8679 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8680 /// from WebAssembly binary code. This function is useful if it is
8681 /// necessary to a compile a module before it can be instantiated
8682 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8683 ///
8684 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8685 #[cfg(not(js_sys_unstable_apis))]
8686 #[wasm_bindgen(js_namespace = WebAssembly)]
8687 pub fn compile(buffer_source: &JsValue) -> Promise<JsValue>;
8688
8689 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8690 /// from WebAssembly binary code. This function is useful if it is
8691 /// necessary to a compile a module before it can be instantiated
8692 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8693 ///
8694 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8695 #[cfg(js_sys_unstable_apis)]
8696 #[wasm_bindgen(js_namespace = WebAssembly)]
8697 pub fn compile(buffer_source: &JsValue) -> Promise<Module>;
8698
8699 /// The `WebAssembly.compileStreaming()` function compiles a
8700 /// `WebAssembly.Module` module directly from a streamed underlying
8701 /// source. This function is useful if it is necessary to a compile a
8702 /// module before it can be instantiated (otherwise, the
8703 /// `WebAssembly.instantiateStreaming()` function should be used).
8704 ///
8705 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8706 #[cfg(not(js_sys_unstable_apis))]
8707 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8708 pub fn compile_streaming(response: &Promise) -> Promise<JsValue>;
8709
8710 /// The `WebAssembly.compileStreaming()` function compiles a
8711 /// `WebAssembly.Module` module directly from a streamed underlying
8712 /// source. This function is useful if it is necessary to a compile a
8713 /// module before it can be instantiated (otherwise, the
8714 /// `WebAssembly.instantiateStreaming()` function should be used).
8715 ///
8716 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8717 #[cfg(js_sys_unstable_apis)]
8718 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8719 pub fn compile_streaming(response: &Promise) -> Promise<Module>;
8720
8721 /// The `WebAssembly.instantiate()` function allows you to compile and
8722 /// instantiate WebAssembly code.
8723 ///
8724 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8725 #[cfg(not(js_sys_unstable_apis))]
8726 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8727 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<JsValue>;
8728
8729 /// The `WebAssembly.instantiate()` function allows you to compile and
8730 /// instantiate WebAssembly code.
8731 ///
8732 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8733 #[cfg(js_sys_unstable_apis)]
8734 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8735 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<Instance>;
8736
8737 /// The `WebAssembly.instantiate()` function allows you to compile and
8738 /// instantiate WebAssembly code.
8739 ///
8740 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8741 #[cfg(not(js_sys_unstable_apis))]
8742 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8743 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<JsValue>;
8744
8745 /// The `WebAssembly.instantiate()` function allows you to compile and
8746 /// instantiate WebAssembly code.
8747 ///
8748 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8749 #[cfg(js_sys_unstable_apis)]
8750 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8751 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<Instance>;
8752
8753 /// The `WebAssembly.instantiateStreaming()` function compiles and
8754 /// instantiates a WebAssembly module directly from a streamed
8755 /// underlying source. This is the most efficient, optimized way to load
8756 /// Wasm code.
8757 ///
8758 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8759 #[cfg(not(js_sys_unstable_apis))]
8760 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8761 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<JsValue>;
8762
8763 /// The `WebAssembly.instantiateStreaming()` function compiles and
8764 /// instantiates a WebAssembly module directly from a streamed
8765 /// underlying source. This is the most efficient, optimized way to load
8766 /// Wasm code.
8767 ///
8768 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8769 #[cfg(js_sys_unstable_apis)]
8770 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8771 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<Instance>;
8772
8773 /// The `WebAssembly.validate()` function validates a given typed
8774 /// array of WebAssembly binary code, returning whether the bytes
8775 /// form a valid Wasm module (`true`) or not (`false`).
8776 ///
8777 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
8778 #[wasm_bindgen(js_namespace = WebAssembly, catch)]
8779 pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
8780 }
8781
8782 // WebAssembly.CompileError
8783 #[wasm_bindgen]
8784 extern "C" {
8785 /// The `WebAssembly.CompileError()` constructor creates a new
8786 /// WebAssembly `CompileError` object, which indicates an error during
8787 /// WebAssembly decoding or validation.
8788 ///
8789 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8790 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
8791 #[derive(Clone, Debug, PartialEq, Eq)]
8792 pub type CompileError;
8793
8794 /// The `WebAssembly.CompileError()` constructor creates a new
8795 /// WebAssembly `CompileError` object, which indicates an error during
8796 /// WebAssembly decoding or validation.
8797 ///
8798 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8799 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8800 pub fn new(message: &str) -> CompileError;
8801
8802 /// Creates a new `WebAssembly.CompileError` with the given message and
8803 /// a typed [`ErrorOptions`] dictionary whose `cause` property
8804 /// indicates the original cause of the error.
8805 ///
8806 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError/CompileError)
8807 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8808 pub fn new_with_options(message: &str, options: &ErrorOptions) -> CompileError;
8809 }
8810
8811 // WebAssembly.Instance
8812 #[wasm_bindgen]
8813 extern "C" {
8814 /// A `WebAssembly.Instance` object is a stateful, executable instance
8815 /// of a `WebAssembly.Module`. Instance objects contain all the exported
8816 /// WebAssembly functions that allow calling into WebAssembly code from
8817 /// JavaScript.
8818 ///
8819 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8820 #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
8821 #[derive(Clone, Debug, PartialEq, Eq)]
8822 pub type Instance;
8823
8824 /// The `WebAssembly.Instance()` constructor function can be called to
8825 /// synchronously instantiate a given `WebAssembly.Module`
8826 /// object. However, the primary way to get an `Instance` is through the
8827 /// asynchronous `WebAssembly.instantiateStreaming()` function.
8828 ///
8829 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8830 #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
8831 pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
8832
8833 /// The `exports` readonly property of the `WebAssembly.Instance` object
8834 /// prototype returns an object containing as its members all the
8835 /// functions exported from the WebAssembly module instance, to allow
8836 /// them to be accessed and used by JavaScript.
8837 ///
8838 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
8839 #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
8840 pub fn exports(this: &Instance) -> Object;
8841 }
8842
8843 // WebAssembly.LinkError
8844 #[wasm_bindgen]
8845 extern "C" {
8846 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8847 /// LinkError object, which indicates an error during module
8848 /// instantiation (besides traps from the start function).
8849 ///
8850 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8851 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
8852 #[derive(Clone, Debug, PartialEq, Eq)]
8853 pub type LinkError;
8854
8855 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8856 /// LinkError object, which indicates an error during module
8857 /// instantiation (besides traps from the start function).
8858 ///
8859 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8860 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8861 pub fn new(message: &str) -> LinkError;
8862
8863 /// Creates a new `WebAssembly.LinkError` with the given message and a
8864 /// typed [`ErrorOptions`] dictionary whose `cause` property indicates
8865 /// the original cause of the error.
8866 ///
8867 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError/LinkError)
8868 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8869 pub fn new_with_options(message: &str, options: &ErrorOptions) -> LinkError;
8870 }
8871
8872 // WebAssembly.RuntimeError
8873 #[wasm_bindgen]
8874 extern "C" {
8875 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8876 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8877 /// specifies a trap.
8878 ///
8879 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8880 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
8881 #[derive(Clone, Debug, PartialEq, Eq)]
8882 pub type RuntimeError;
8883
8884 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8885 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8886 /// specifies a trap.
8887 ///
8888 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8889 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8890 pub fn new(message: &str) -> RuntimeError;
8891
8892 /// Creates a new `WebAssembly.RuntimeError` with the given message
8893 /// and a typed [`ErrorOptions`] dictionary whose `cause` property
8894 /// indicates the original cause of the error.
8895 ///
8896 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError/RuntimeError)
8897 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8898 pub fn new_with_options(message: &str, options: &ErrorOptions) -> RuntimeError;
8899 }
8900
8901 // WebAssembly.Module
8902 #[wasm_bindgen]
8903 extern "C" {
8904 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8905 /// that has already been compiled by the browser and can be
8906 /// efficiently shared with Workers, and instantiated multiple times.
8907 ///
8908 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8909 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
8910 #[derive(Clone, Debug, PartialEq, Eq)]
8911 pub type Module;
8912
8913 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8914 /// that has already been compiled by the browser and can be
8915 /// efficiently shared with Workers, and instantiated multiple times.
8916 ///
8917 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8918 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8919 pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
8920
8921 /// The `WebAssembly.customSections()` function returns a copy of the
8922 /// contents of all custom sections in the given module with the given
8923 /// string name.
8924 ///
8925 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
8926 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
8927 pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
8928
8929 /// The `WebAssembly.exports()` function returns an array containing
8930 /// descriptions of all the declared exports of the given `Module`.
8931 ///
8932 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
8933 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8934 pub fn exports(module: &Module) -> Array;
8935
8936 /// The `WebAssembly.imports()` function returns an array containing
8937 /// descriptions of all the declared imports of the given `Module`.
8938 ///
8939 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
8940 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8941 pub fn imports(module: &Module) -> Array;
8942 }
8943
8944 // WebAssembly.Table
8945 #[wasm_bindgen]
8946 extern "C" {
8947 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8948 /// of the given size and element type.
8949 ///
8950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8951 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
8952 #[derive(Clone, Debug, PartialEq, Eq)]
8953 pub type Table;
8954
8955 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8956 /// of the given size and element type.
8957 ///
8958 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8959 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8960 pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
8961
8962 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8963 /// of the given size and element type.
8964 ///
8965 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8966 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8967 pub fn new_with_value(table_descriptor: &Object, value: JsValue) -> Result<Table, JsValue>;
8968
8969 /// The length prototype property of the `WebAssembly.Table` object
8970 /// returns the length of the table, i.e. the number of elements in the
8971 /// table.
8972 ///
8973 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
8974 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8975 pub fn length(this: &Table) -> u32;
8976
8977 /// The `get()` prototype method of the `WebAssembly.Table()` object
8978 /// retrieves a function reference stored at a given index.
8979 ///
8980 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8981 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8982 pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
8983
8984 /// The `get()` prototype method of the `WebAssembly.Table()` object
8985 /// retrieves a function reference stored at a given index.
8986 ///
8987 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8988 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = get)]
8989 pub fn get_raw(this: &Table, index: u32) -> Result<JsValue, JsValue>;
8990
8991 /// The `grow()` prototype method of the `WebAssembly.Table` object
8992 /// increases the size of the `Table` instance by a specified number of
8993 /// elements.
8994 ///
8995 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8996 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8997 pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
8998
8999 /// The `grow()` prototype method of the `WebAssembly.Table` object
9000 /// increases the size of the `Table` instance by a specified number of
9001 /// elements.
9002 ///
9003 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
9004 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = grow)]
9005 pub fn grow_with_value(
9006 this: &Table,
9007 additional_capacity: u32,
9008 value: JsValue,
9009 ) -> Result<u32, JsValue>;
9010
9011 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
9012 /// reference stored at a given index to a different value.
9013 ///
9014 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
9015 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
9016 pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
9017
9018 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
9019 /// reference stored at a given index to a different value.
9020 ///
9021 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
9022 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = set)]
9023 pub fn set_raw(this: &Table, index: u32, value: &JsValue) -> Result<(), JsValue>;
9024 }
9025
9026 // WebAssembly.Tag
9027 #[wasm_bindgen]
9028 extern "C" {
9029 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
9030 ///
9031 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
9032 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
9033 #[derive(Clone, Debug, PartialEq, Eq)]
9034 pub type Tag;
9035
9036 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
9037 ///
9038 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
9039 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9040 pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
9041 }
9042
9043 // WebAssembly.Exception
9044 #[wasm_bindgen]
9045 extern "C" {
9046 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
9047 ///
9048 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
9049 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
9050 #[derive(Clone, Debug, PartialEq, Eq)]
9051 pub type Exception;
9052
9053 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
9054 ///
9055 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
9056 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9057 pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
9058
9059 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
9060 ///
9061 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
9062 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9063 pub fn new_with_options(
9064 tag: &Tag,
9065 payload: &Array,
9066 options: &Object,
9067 ) -> Result<Exception, JsValue>;
9068
9069 /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
9070 /// test if the Exception matches a given tag.
9071 ///
9072 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
9073 #[wasm_bindgen(method, js_namespace = WebAssembly)]
9074 pub fn is(this: &Exception, tag: &Tag) -> bool;
9075
9076 /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
9077 /// to get the value of a specified item in the exception's data arguments
9078 ///
9079 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
9080 #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
9081 pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
9082 }
9083
9084 // WebAssembly.Global
9085 #[wasm_bindgen]
9086 extern "C" {
9087 /// The `WebAssembly.Global()` constructor creates a new `Global` object
9088 /// of the given type and value.
9089 ///
9090 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
9091 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
9092 #[derive(Clone, Debug, PartialEq, Eq)]
9093 pub type Global;
9094
9095 /// The `WebAssembly.Global()` constructor creates a new `Global` object
9096 /// of the given type and value.
9097 ///
9098 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
9099 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9100 pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
9101
9102 /// The value prototype property of the `WebAssembly.Global` object
9103 /// returns the value of the global.
9104 ///
9105 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
9106 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
9107 pub fn value(this: &Global) -> JsValue;
9108 #[wasm_bindgen(method, setter = value, js_namespace = WebAssembly)]
9109 pub fn set_value(this: &Global, value: &JsValue);
9110 }
9111
9112 // WebAssembly.Memory
9113 #[wasm_bindgen]
9114 extern "C" {
9115 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
9116 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
9117 #[derive(Clone, Debug, PartialEq, Eq)]
9118 pub type Memory;
9119
9120 /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
9121 /// which is a resizable `ArrayBuffer` that holds the raw bytes of
9122 /// memory accessed by a WebAssembly `Instance`.
9123 ///
9124 /// A memory created by JavaScript or in WebAssembly code will be
9125 /// accessible and mutable from both JavaScript and WebAssembly.
9126 ///
9127 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
9128 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9129 pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
9130
9131 /// An accessor property that returns the buffer contained in the
9132 /// memory.
9133 ///
9134 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
9135 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
9136 pub fn buffer(this: &Memory) -> JsValue;
9137
9138 /// The `grow()` prototype method of the `Memory` object increases the
9139 /// size of the memory instance by a specified number of WebAssembly
9140 /// pages.
9141 ///
9142 /// Takes the number of pages to grow (64KiB in size) and returns the
9143 /// previous size of memory, in pages.
9144 ///
9145 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
9146 #[wasm_bindgen(method, js_namespace = WebAssembly)]
9147 pub fn grow(this: &Memory, pages: u32) -> u32;
9148 }
9149
9150 // WebAssembly.Suspending / WebAssembly.promising (JSPI — JS Promise Integration)
9151 #[wasm_bindgen]
9152 extern "C" {
9153 /// A `WebAssembly.Suspending` object wraps a JavaScript async function
9154 /// so it can be used as a WebAssembly import under
9155 /// [JSPI (JS Promise Integration)][jspi].
9156 ///
9157 /// When WASM calls a `Suspending`-wrapped import that returns a
9158 /// `Promise`, the WASM fiber suspends until the promise settles; the
9159 /// resolved value is then returned to WASM as if the call had returned
9160 /// synchronously. The browser's event loop is **not** blocked.
9161 ///
9162 /// [jspi]: https://github.com/WebAssembly/js-promise-integration
9163 ///
9164 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Suspending)
9165 #[wasm_bindgen(
9166 js_namespace = WebAssembly,
9167 extends = Object,
9168 typescript_type = "WebAssembly.Suspending"
9169 )]
9170 #[derive(Clone, Debug, PartialEq, Eq)]
9171 pub type Suspending;
9172
9173 /// Wraps `func` (an async function) in a `WebAssembly.Suspending` object.
9174 ///
9175 /// Pass the returned object as a WASM import. Every call to that
9176 /// import from WASM will suspend the current fiber and resume it with
9177 /// the resolved value once `func`'s returned `Promise` settles.
9178 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9179 pub fn new(func: &Function) -> Suspending;
9180
9181 /// Wraps a WebAssembly exported `Function` so that calling it returns a
9182 /// `Promise` and enables JSPI suspension inside.
9183 ///
9184 /// Use `WebAssembly.promising` to obtain a "promising" wrapper around a
9185 /// raw WASM export; any JSPI suspensions that occur while the function
9186 /// executes will resolve the returned `Promise` when the fiber finishes.
9187 ///
9188 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/promising)
9189 #[wasm_bindgen(js_namespace = WebAssembly)]
9190 pub fn promising(func: &Function) -> Function;
9191 }
9192}
9193
9194/// The `JSON` object contains methods for parsing [JavaScript Object
9195/// Notation (JSON)](https://json.org/) and converting values to JSON. It
9196/// can't be called or constructed, and aside from its two method
9197/// properties, it has no interesting functionality of its own.
9198#[allow(non_snake_case)]
9199pub mod JSON {
9200 use super::*;
9201
9202 // JSON
9203 #[wasm_bindgen]
9204 extern "C" {
9205 /// The `JSON.parse()` method parses a JSON string, constructing the
9206 /// JavaScript value or object described by the string.
9207 ///
9208 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
9209 #[wasm_bindgen(catch, js_namespace = JSON)]
9210 pub fn parse(text: &str) -> Result<JsValue, JsValue>;
9211
9212 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9213 ///
9214 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9215 #[wasm_bindgen(catch, js_namespace = JSON)]
9216 pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
9217
9218 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9219 ///
9220 /// The `replacer` argument is a function that alters the behavior of the stringification
9221 /// process, or an array of String and Number objects that serve as a whitelist
9222 /// for selecting/filtering the properties of the value object to be included
9223 /// in the JSON string. If this value is null or not provided, all properties
9224 /// of the object are included in the resulting JSON string.
9225 ///
9226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9227 #[cfg(not(js_sys_unstable_apis))]
9228 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9229 pub fn stringify_with_replacer(
9230 obj: &JsValue,
9231 replacer: &JsValue,
9232 ) -> Result<JsString, JsValue>;
9233
9234 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9235 ///
9236 /// The `replacer` argument is a function that alters the behavior of the stringification
9237 /// process, or an array of String and Number objects that serve as a whitelist
9238 /// for selecting/filtering the properties of the value object to be included
9239 /// in the JSON string. If this value is null or not provided, all properties
9240 /// of the object are included in the resulting JSON string.
9241 ///
9242 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9243 #[cfg(js_sys_unstable_apis)]
9244 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9245 pub fn stringify_with_replacer<'a>(
9246 obj: &JsValue,
9247 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
9248 space: Option<u32>,
9249 ) -> Result<JsString, JsValue>;
9250
9251 // Next major: deprecate
9252 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9253 ///
9254 /// The `replacer` argument is a function that alters the behavior of the stringification
9255 /// process, or an array of String and Number objects that serve as a whitelist
9256 /// for selecting/filtering the properties of the value object to be included
9257 /// in the JSON string. If this value is null or not provided, all properties
9258 /// of the object are included in the resulting JSON string.
9259 ///
9260 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9261 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9262 pub fn stringify_with_replacer_func<'a>(
9263 obj: &JsValue,
9264 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
9265 space: Option<u32>,
9266 ) -> Result<JsString, JsValue>;
9267
9268 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9269 ///
9270 /// The `replacer` argument is a function that alters the behavior of the stringification
9271 /// process, or an array of String and Number objects that serve as a whitelist
9272 /// for selecting/filtering the properties of the value object to be included
9273 /// in the JSON string. If this value is null or not provided, all properties
9274 /// of the object are included in the resulting JSON string.
9275 ///
9276 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9277 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9278 pub fn stringify_with_replacer_list(
9279 obj: &JsValue,
9280 replacer: Vec<String>,
9281 space: Option<u32>,
9282 ) -> Result<JsString, JsValue>;
9283
9284 // Next major: deprecate
9285 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9286 ///
9287 /// The `replacer` argument is a function that alters the behavior of the stringification
9288 /// process, or an array of String and Number objects that serve as a whitelist
9289 /// for selecting/filtering the properties of the value object to be included
9290 /// in the JSON string. If this value is null or not provided, all properties
9291 /// of the object are included in the resulting JSON string.
9292 ///
9293 /// The `space` argument is a String or Number object that's used to insert white space into
9294 /// the output JSON string for readability purposes. If this is a Number, it
9295 /// indicates the number of space characters to use as white space; this number
9296 /// is capped at 10 (if it is greater, the value is just 10). Values less than
9297 /// 1 indicate that no space should be used. If this is a String, the string
9298 /// (or the first 10 characters of the string, if it's longer than that) is
9299 /// used as white space. If this parameter is not provided (or is null), no
9300 /// white space is used.
9301 ///
9302 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9303 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9304 pub fn stringify_with_replacer_and_space(
9305 obj: &JsValue,
9306 replacer: &JsValue,
9307 space: &JsValue,
9308 ) -> Result<JsString, JsValue>;
9309 }
9310}
9311// JsString
9312#[wasm_bindgen]
9313extern "C" {
9314 #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
9315 #[derive(Clone, PartialEq, Eq)]
9316 pub type JsString;
9317
9318 /// The length property of a String object indicates the length of a string,
9319 /// in UTF-16 code units.
9320 ///
9321 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
9322 #[wasm_bindgen(method, getter)]
9323 pub fn length(this: &JsString) -> u32;
9324
9325 /// The 'at()' method returns a new string consisting of the single UTF-16
9326 /// code unit located at the specified offset into the string, counting from
9327 /// the end if it's negative.
9328 ///
9329 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
9330 #[wasm_bindgen(method, js_class = "String")]
9331 pub fn at(this: &JsString, index: i32) -> Option<JsString>;
9332
9333 /// The String object's `charAt()` method returns a new string consisting of
9334 /// the single UTF-16 code unit located at the specified offset into the
9335 /// string.
9336 ///
9337 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
9338 #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
9339 pub fn char_at(this: &JsString, index: u32) -> JsString;
9340
9341 /// The `charCodeAt()` method returns an integer between 0 and 65535
9342 /// representing the UTF-16 code unit at the given index (the UTF-16 code
9343 /// unit matches the Unicode code point for code points representable in a
9344 /// single UTF-16 code unit, but might also be the first code unit of a
9345 /// surrogate pair for code points not representable in a single UTF-16 code
9346 /// unit, e.g. Unicode code points > 0x10000). If you want the entire code
9347 /// point value, use `codePointAt()`.
9348 ///
9349 /// Returns `NaN` if index is out of range.
9350 ///
9351 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
9352 #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
9353 pub fn char_code_at(this: &JsString, index: u32) -> f64;
9354
9355 /// The `codePointAt()` method returns a non-negative integer that is the
9356 /// Unicode code point value.
9357 ///
9358 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
9359 #[cfg(not(js_sys_unstable_apis))]
9360 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
9361 pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
9362
9363 /// The `codePointAt()` method returns a non-negative integer that is the
9364 /// Unicode code point value.
9365 ///
9366 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
9367 #[cfg(js_sys_unstable_apis)]
9368 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
9369 pub fn code_point_at(this: &JsString, pos: u32) -> Option<u32>;
9370
9371 // Next major: deprecate
9372 /// The `codePointAt()` method returns a non-negative integer that is the
9373 /// Unicode code point value.
9374 ///
9375 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
9376 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
9377 pub fn try_code_point_at(this: &JsString, pos: u32) -> Option<u16>;
9378
9379 /// The `concat()` method concatenates the string arguments to the calling
9380 /// string and returns a new string.
9381 ///
9382 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
9383 #[cfg(not(js_sys_unstable_apis))]
9384 #[wasm_bindgen(method, js_class = "String")]
9385 pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
9386
9387 /// The `concat()` method concatenates the string arguments to the calling
9388 /// string and returns a new string.
9389 ///
9390 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
9391 #[cfg(js_sys_unstable_apis)]
9392 #[wasm_bindgen(method, js_class = "String")]
9393 pub fn concat(this: &JsString, string: &JsString) -> JsString;
9394
9395 /// The `concat()` method concatenates the string arguments to the calling
9396 /// string and returns a new string.
9397 ///
9398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
9399 #[wasm_bindgen(method, js_class = "String")]
9400 pub fn concat_many(this: &JsString, strings: &[JsString]) -> JsString;
9401
9402 /// The `endsWith()` method determines whether a string ends with the characters of a
9403 /// specified string, returning true or false as appropriate.
9404 ///
9405 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
9406 #[cfg(not(js_sys_unstable_apis))]
9407 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
9408 pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
9409
9410 /// The `endsWith()` method determines whether a string ends with the characters of a
9411 /// specified string, returning true or false as appropriate.
9412 ///
9413 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
9414 #[cfg(js_sys_unstable_apis)]
9415 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
9416 pub fn ends_with(this: &JsString, search_string: &str) -> bool;
9417
9418 /// The static `String.fromCharCode()` method returns a string created from
9419 /// the specified sequence of UTF-16 code units.
9420 ///
9421 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9422 ///
9423 /// # Notes
9424 ///
9425 /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
9426 /// with different arities.
9427 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
9428 pub fn from_char_code(char_codes: &[u16]) -> JsString;
9429
9430 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9431 #[cfg(not(js_sys_unstable_apis))]
9432 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9433 pub fn from_char_code1(a: u32) -> JsString;
9434
9435 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9436 #[cfg(js_sys_unstable_apis)]
9437 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9438 pub fn from_char_code1(a: u16) -> JsString;
9439
9440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9441 #[cfg(not(js_sys_unstable_apis))]
9442 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9443 pub fn from_char_code2(a: u32, b: u32) -> JsString;
9444
9445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9446 #[cfg(js_sys_unstable_apis)]
9447 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9448 pub fn from_char_code2(a: u16, b: u16) -> JsString;
9449
9450 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9451 #[cfg(not(js_sys_unstable_apis))]
9452 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9453 pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
9454
9455 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9456 #[cfg(js_sys_unstable_apis)]
9457 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9458 pub fn from_char_code3(a: u16, b: u16, c: u16) -> JsString;
9459
9460 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9461 #[cfg(not(js_sys_unstable_apis))]
9462 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9463 pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
9464
9465 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9466 #[cfg(js_sys_unstable_apis)]
9467 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9468 pub fn from_char_code4(a: u16, b: u16, c: u16, d: u16) -> JsString;
9469
9470 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9471 #[cfg(not(js_sys_unstable_apis))]
9472 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9473 pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
9474
9475 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9476 #[cfg(js_sys_unstable_apis)]
9477 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9478 pub fn from_char_code5(a: u16, b: u16, c: u16, d: u16, e: u16) -> JsString;
9479
9480 /// The static `String.fromCodePoint()` method returns a string created by
9481 /// using the specified sequence of code points.
9482 ///
9483 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9484 ///
9485 /// # Exceptions
9486 ///
9487 /// A RangeError is thrown if an invalid Unicode code point is given
9488 ///
9489 /// # Notes
9490 ///
9491 /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
9492 /// with different arities.
9493 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
9494 pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
9495
9496 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9497 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9498 pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
9499
9500 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9501 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9502 pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
9503
9504 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9505 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9506 pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
9507
9508 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9509 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9510 pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
9511
9512 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9513 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9514 pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
9515
9516 /// The `includes()` method determines whether one string may be found
9517 /// within another string, returning true or false as appropriate.
9518 ///
9519 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
9520 #[wasm_bindgen(method, js_class = "String")]
9521 pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
9522
9523 /// The `indexOf()` method returns the index within the calling String
9524 /// object of the first occurrence of the specified value, starting the
9525 /// search at fromIndex. Returns -1 if the value is not found.
9526 ///
9527 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
9528 #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
9529 pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9530
9531 /// The `lastIndexOf()` method returns the index within the calling String
9532 /// object of the last occurrence of the specified value, searching
9533 /// backwards from fromIndex. Returns -1 if the value is not found.
9534 ///
9535 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
9536 #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
9537 pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9538
9539 /// The `localeCompare()` method returns a number indicating whether
9540 /// a reference string comes before or after or is the same as
9541 /// the given string in sort order.
9542 ///
9543 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9544 #[cfg(not(js_sys_unstable_apis))]
9545 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9546 pub fn locale_compare(
9547 this: &JsString,
9548 compare_string: &str,
9549 locales: &Array,
9550 options: &Object,
9551 ) -> i32;
9552
9553 /// The `localeCompare()` method returns a number indicating whether
9554 /// a reference string comes before or after or is the same as
9555 /// the given string in sort order.
9556 ///
9557 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9558 #[cfg(js_sys_unstable_apis)]
9559 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9560 pub fn locale_compare(
9561 this: &JsString,
9562 compare_string: &str,
9563 locales: &[JsString],
9564 options: &Intl::CollatorOptions,
9565 ) -> i32;
9566
9567 /// The `match()` method retrieves the matches when matching a string against a regular expression.
9568 ///
9569 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
9570 #[wasm_bindgen(method, js_class = "String", js_name = match)]
9571 pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
9572
9573 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9574 ///
9575 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9576 #[cfg(not(js_sys_unstable_apis))]
9577 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9578 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
9579
9580 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9581 ///
9582 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9583 #[cfg(js_sys_unstable_apis)]
9584 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9585 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator<RegExpMatchArray>;
9586
9587 /// The `normalize()` method returns the Unicode Normalization Form
9588 /// of a given string (if the value isn't a string, it will be converted to one first).
9589 ///
9590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
9591 #[wasm_bindgen(method, js_class = "String")]
9592 pub fn normalize(this: &JsString, form: &str) -> JsString;
9593
9594 /// The `padEnd()` method pads the current string with a given string
9595 /// (repeated, if needed) so that the resulting string reaches a given
9596 /// length. The padding is applied from the end (right) of the current
9597 /// string.
9598 ///
9599 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
9600 #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
9601 pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9602
9603 /// The `padStart()` method pads the current string with another string
9604 /// (repeated, if needed) so that the resulting string reaches the given
9605 /// length. The padding is applied from the start (left) of the current
9606 /// string.
9607 ///
9608 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
9609 #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
9610 pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9611
9612 /// The `repeat()` method constructs and returns a new string which contains the specified
9613 /// number of copies of the string on which it was called, concatenated together.
9614 ///
9615 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
9616 #[wasm_bindgen(method, js_class = "String")]
9617 pub fn repeat(this: &JsString, count: i32) -> JsString;
9618
9619 /// The `replace()` method returns a new string with some or all matches of a pattern
9620 /// replaced by a replacement. The pattern can be a string or a RegExp, and
9621 /// the replacement can be a string or a function to be called for each match.
9622 ///
9623 /// Note: The original string will remain unchanged.
9624 ///
9625 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9626 #[wasm_bindgen(method, js_class = "String")]
9627 pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9628
9629 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9630 #[cfg(not(js_sys_unstable_apis))]
9631 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9632 pub fn replace_with_function(
9633 this: &JsString,
9634 pattern: &str,
9635 replacement: &Function,
9636 ) -> JsString;
9637
9638 /// The replacer function signature is `(match, offset, string) -> replacement`
9639 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9640 /// when capture groups are present.
9641 ///
9642 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9643 #[cfg(js_sys_unstable_apis)]
9644 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9645 pub fn replace_with_function(
9646 this: &JsString,
9647 pattern: &str,
9648 replacement: &Function<fn(JsString) -> JsString>,
9649 ) -> JsString;
9650
9651 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9652 pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
9653
9654 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9655 #[cfg(not(js_sys_unstable_apis))]
9656 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9657 pub fn replace_by_pattern_with_function(
9658 this: &JsString,
9659 pattern: &RegExp,
9660 replacement: &Function,
9661 ) -> JsString;
9662
9663 /// The replacer function signature is `(match, offset, string) -> replacement`
9664 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9665 /// when capture groups are present.
9666 ///
9667 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9668 #[cfg(js_sys_unstable_apis)]
9669 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9670 pub fn replace_by_pattern_with_function(
9671 this: &JsString,
9672 pattern: &RegExp,
9673 replacement: &Function<fn(JsString) -> JsString>,
9674 ) -> JsString;
9675
9676 /// The `replace_all()` method returns a new string with all matches of a pattern
9677 /// replaced by a replacement. The pattern can be a string or a global RegExp, and
9678 /// the replacement can be a string or a function to be called for each match.
9679 ///
9680 /// Note: The original string will remain unchanged.
9681 ///
9682 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9683 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9684 pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9685
9686 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9687 #[cfg(not(js_sys_unstable_apis))]
9688 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9689 pub fn replace_all_with_function(
9690 this: &JsString,
9691 pattern: &str,
9692 replacement: &Function,
9693 ) -> JsString;
9694
9695 /// The replacer function signature is `(match, offset, string) -> replacement`
9696 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9697 /// when capture groups are present.
9698 ///
9699 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9700 #[cfg(js_sys_unstable_apis)]
9701 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9702 pub fn replace_all_with_function(
9703 this: &JsString,
9704 pattern: &str,
9705 replacement: &Function<fn(JsString) -> JsString>,
9706 ) -> JsString;
9707
9708 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9709 pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
9710 -> JsString;
9711
9712 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9713 #[cfg(not(js_sys_unstable_apis))]
9714 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9715 pub fn replace_all_by_pattern_with_function(
9716 this: &JsString,
9717 pattern: &RegExp,
9718 replacement: &Function,
9719 ) -> JsString;
9720
9721 /// The replacer function signature is `(match, offset, string) -> replacement`
9722 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9723 /// when capture groups are present.
9724 ///
9725 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9726 #[cfg(js_sys_unstable_apis)]
9727 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9728 pub fn replace_all_by_pattern_with_function(
9729 this: &JsString,
9730 pattern: &RegExp,
9731 replacement: &Function<fn(JsString) -> JsString>,
9732 ) -> JsString;
9733
9734 /// The `search()` method executes a search for a match between
9735 /// a regular expression and this String object.
9736 ///
9737 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
9738 #[wasm_bindgen(method, js_class = "String")]
9739 pub fn search(this: &JsString, pattern: &RegExp) -> i32;
9740
9741 /// The `slice()` method extracts a section of a string and returns it as a
9742 /// new string, without modifying the original string.
9743 ///
9744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
9745 #[wasm_bindgen(method, js_class = "String")]
9746 pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
9747
9748 /// The `split()` method splits a String object into an array of strings by separating the string
9749 /// into substrings, using a specified separator string to determine where to make each split.
9750 ///
9751 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9752 #[wasm_bindgen(method, js_class = "String")]
9753 pub fn split(this: &JsString, separator: &str) -> Array;
9754
9755 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9756 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9757 pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
9758
9759 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9760 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9761 pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
9762
9763 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9764 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9765 pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
9766
9767 /// The `startsWith()` method determines whether a string begins with the
9768 /// characters of a specified string, returning true or false as
9769 /// appropriate.
9770 ///
9771 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
9772 #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
9773 pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
9774
9775 /// The `substring()` method returns the part of the string between the
9776 /// start and end indexes, or to the end of the string.
9777 ///
9778 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
9779 #[wasm_bindgen(method, js_class = "String")]
9780 pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
9781
9782 /// The `substr()` method returns the part of a string between
9783 /// the start index and a number of characters after it.
9784 ///
9785 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
9786 #[wasm_bindgen(method, js_class = "String")]
9787 pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
9788
9789 /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
9790 /// according to any locale-specific case mappings.
9791 ///
9792 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
9793 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
9794 pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
9795
9796 /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
9797 /// according to any locale-specific case mappings.
9798 ///
9799 /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
9800 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
9801 pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
9802
9803 /// The `toLowerCase()` method returns the calling string value
9804 /// converted to lower case.
9805 ///
9806 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
9807 #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
9808 pub fn to_lower_case(this: &JsString) -> JsString;
9809
9810 /// The `toString()` method returns a string representing the specified
9811 /// object.
9812 ///
9813 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
9814 #[cfg(not(js_sys_unstable_apis))]
9815 #[wasm_bindgen(method, js_class = "String", js_name = toString)]
9816 pub fn to_string(this: &JsString) -> JsString;
9817
9818 /// The `toUpperCase()` method returns the calling string value converted to
9819 /// uppercase (the value will be converted to a string if it isn't one).
9820 ///
9821 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
9822 #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
9823 pub fn to_upper_case(this: &JsString) -> JsString;
9824
9825 /// The `trim()` method removes whitespace from both ends of a string.
9826 /// Whitespace in this context is all the whitespace characters (space, tab,
9827 /// no-break space, etc.) and all the line terminator characters (LF, CR,
9828 /// etc.).
9829 ///
9830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
9831 #[wasm_bindgen(method, js_class = "String")]
9832 pub fn trim(this: &JsString) -> JsString;
9833
9834 /// The `trimEnd()` method removes whitespace from the end of a string.
9835 /// `trimRight()` is an alias of this method.
9836 ///
9837 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9838 #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
9839 pub fn trim_end(this: &JsString) -> JsString;
9840
9841 /// The `trimEnd()` method removes whitespace from the end of a string.
9842 /// `trimRight()` is an alias of this method.
9843 ///
9844 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9845 #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
9846 pub fn trim_right(this: &JsString) -> JsString;
9847
9848 /// The `trimStart()` method removes whitespace from the beginning of a
9849 /// string. `trimLeft()` is an alias of this method.
9850 ///
9851 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9852 #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
9853 pub fn trim_start(this: &JsString) -> JsString;
9854
9855 /// The `trimStart()` method removes whitespace from the beginning of a
9856 /// string. `trimLeft()` is an alias of this method.
9857 ///
9858 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9859 #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
9860 pub fn trim_left(this: &JsString) -> JsString;
9861
9862 /// The `valueOf()` method returns the primitive value of a `String` object.
9863 ///
9864 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
9865 #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
9866 pub fn value_of(this: &JsString) -> JsString;
9867
9868 /// The static `raw()` method is a tag function of template literals,
9869 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9870 ///
9871 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9872 #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
9873 pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
9874
9875 /// The static `raw()` method is a tag function of template literals,
9876 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9877 ///
9878 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9879 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9880 pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
9881
9882 /// The static `raw()` method is a tag function of template literals,
9883 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9884 ///
9885 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9886 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9887 pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
9888
9889 /// The static `raw()` method is a tag function of template literals,
9890 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9891 ///
9892 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9893 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9894 pub fn raw_2(
9895 call_site: &Object,
9896 substitutions1: &str,
9897 substitutions2: &str,
9898 ) -> Result<JsString, JsValue>;
9899
9900 /// The static `raw()` method is a tag function of template literals,
9901 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9902 ///
9903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9904 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9905 pub fn raw_3(
9906 call_site: &Object,
9907 substitutions1: &str,
9908 substitutions2: &str,
9909 substitutions3: &str,
9910 ) -> Result<JsString, JsValue>;
9911
9912 /// The static `raw()` method is a tag function of template literals,
9913 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9914 ///
9915 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9916 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9917 pub fn raw_4(
9918 call_site: &Object,
9919 substitutions1: &str,
9920 substitutions2: &str,
9921 substitutions3: &str,
9922 substitutions4: &str,
9923 ) -> Result<JsString, JsValue>;
9924
9925 /// The static `raw()` method is a tag function of template literals,
9926 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9927 ///
9928 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9929 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9930 pub fn raw_5(
9931 call_site: &Object,
9932 substitutions1: &str,
9933 substitutions2: &str,
9934 substitutions3: &str,
9935 substitutions4: &str,
9936 substitutions5: &str,
9937 ) -> Result<JsString, JsValue>;
9938
9939 /// The static `raw()` method is a tag function of template literals,
9940 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9941 ///
9942 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9943 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9944 pub fn raw_6(
9945 call_site: &Object,
9946 substitutions1: &str,
9947 substitutions2: &str,
9948 substitutions3: &str,
9949 substitutions4: &str,
9950 substitutions5: &str,
9951 substitutions6: &str,
9952 ) -> Result<JsString, JsValue>;
9953
9954 /// The static `raw()` method is a tag function of template literals,
9955 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9956 ///
9957 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9958 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9959 pub fn raw_7(
9960 call_site: &Object,
9961 substitutions1: &str,
9962 substitutions2: &str,
9963 substitutions3: &str,
9964 substitutions4: &str,
9965 substitutions5: &str,
9966 substitutions6: &str,
9967 substitutions7: &str,
9968 ) -> Result<JsString, JsValue>;
9969}
9970
9971// These upcasts are non-castable due to the constraints on the function
9972// but the UpcastFrom covariance must still extend through closure types.
9973// (impl UpcastFrom really just means CovariantGeneric relation)
9974impl UpcastFrom<String> for JsString {}
9975impl UpcastFrom<JsString> for String {}
9976
9977impl UpcastFrom<&str> for JsString {}
9978impl UpcastFrom<JsString> for &str {}
9979
9980impl UpcastFrom<char> for JsString {}
9981impl UpcastFrom<JsString> for char {}
9982
9983impl wasm_bindgen::__rt::marker::JsStringLikeSealed for JsString {}
9984impl wasm_bindgen::__rt::marker::JsStringLikeSealed for &JsString {}
9985impl wasm_bindgen::JsStringLike for JsString {}
9986impl wasm_bindgen::JsStringLike for &JsString {}
9987
9988impl JsString {
9989 /// Returns the `JsString` value of this JS value if it's an instance of a
9990 /// string.
9991 ///
9992 /// If this JS value is not an instance of a string then this returns
9993 /// `None`.
9994 #[cfg(not(js_sys_unstable_apis))]
9995 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
9996 pub fn try_from(val: &JsValue) -> Option<&JsString> {
9997 val.dyn_ref()
9998 }
9999
10000 /// Returns whether this string is a valid UTF-16 string.
10001 ///
10002 /// This is useful for learning whether `String::from(..)` will return a
10003 /// lossless representation of the JS string. If this string contains
10004 /// unpaired surrogates then `String::from` will succeed but it will be a
10005 /// lossy representation of the JS string because unpaired surrogates will
10006 /// become replacement characters.
10007 ///
10008 /// If this function returns `false` then to get a lossless representation
10009 /// of the string you'll need to manually use the `iter` method (or the
10010 /// `char_code_at` accessor) to view the raw character codes.
10011 ///
10012 /// For more information, see the documentation on [JS strings vs Rust
10013 /// strings][docs]
10014 ///
10015 /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
10016 pub fn is_valid_utf16(&self) -> bool {
10017 core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
10018 }
10019
10020 /// Returns an iterator over the `u16` character codes that make up this JS
10021 /// string.
10022 ///
10023 /// This method will call `char_code_at` for each code in this JS string,
10024 /// returning an iterator of the codes in sequence.
10025 pub fn iter(
10026 &self,
10027 ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
10028 (0..self.length()).map(move |i| self.char_code_at(i) as u16)
10029 }
10030
10031 /// If this string consists of a single Unicode code point, then this method
10032 /// converts it into a Rust `char` without doing any allocations.
10033 ///
10034 /// If this JS value is not a valid UTF-8 or consists of more than a single
10035 /// codepoint, then this returns `None`.
10036 ///
10037 /// Note that a single Unicode code point might be represented as more than
10038 /// one code unit on the JavaScript side. For example, a JavaScript string
10039 /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
10040 /// corresponds to a character '𐐷'.
10041 pub fn as_char(&self) -> Option<char> {
10042 let len = self.length();
10043
10044 if len == 0 || len > 2 {
10045 return None;
10046 }
10047
10048 #[cfg(not(js_sys_unstable_apis))]
10049 let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
10050 #[cfg(js_sys_unstable_apis)]
10051 let cp = self.code_point_at(0)?;
10052
10053 let c = core::char::from_u32(cp)?;
10054
10055 if c.len_utf16() as u32 == len {
10056 Some(c)
10057 } else {
10058 None
10059 }
10060 }
10061}
10062
10063impl PartialEq<str> for JsString {
10064 #[allow(clippy::cmp_owned)] // prevent infinite recursion
10065 fn eq(&self, other: &str) -> bool {
10066 String::from(self) == other
10067 }
10068}
10069
10070impl<'a> PartialEq<&'a str> for JsString {
10071 fn eq(&self, other: &&'a str) -> bool {
10072 <JsString as PartialEq<str>>::eq(self, other)
10073 }
10074}
10075
10076impl PartialEq<String> for JsString {
10077 fn eq(&self, other: &String) -> bool {
10078 <JsString as PartialEq<str>>::eq(self, other)
10079 }
10080}
10081
10082impl<'a> PartialEq<&'a String> for JsString {
10083 fn eq(&self, other: &&'a String) -> bool {
10084 <JsString as PartialEq<str>>::eq(self, other)
10085 }
10086}
10087
10088impl Default for JsString {
10089 fn default() -> Self {
10090 Self::from("")
10091 }
10092}
10093
10094impl<'a> From<&'a str> for JsString {
10095 fn from(s: &'a str) -> Self {
10096 JsString::unchecked_from_js(JsValue::from_str(s))
10097 }
10098}
10099
10100impl From<String> for JsString {
10101 fn from(s: String) -> Self {
10102 From::from(&*s)
10103 }
10104}
10105
10106impl From<char> for JsString {
10107 #[inline]
10108 fn from(c: char) -> Self {
10109 JsString::from_code_point1(c as u32).unwrap_throw()
10110 }
10111}
10112
10113impl<'a> From<&'a JsString> for String {
10114 fn from(s: &'a JsString) -> Self {
10115 s.obj.as_string().unwrap_throw()
10116 }
10117}
10118
10119impl From<JsString> for String {
10120 fn from(s: JsString) -> Self {
10121 From::from(&s)
10122 }
10123}
10124
10125impl fmt::Debug for JsString {
10126 #[inline]
10127 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10128 fmt::Debug::fmt(&String::from(self), f)
10129 }
10130}
10131
10132impl fmt::Display for JsString {
10133 #[inline]
10134 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10135 fmt::Display::fmt(&String::from(self), f)
10136 }
10137}
10138
10139impl str::FromStr for JsString {
10140 type Err = convert::Infallible;
10141 fn from_str(s: &str) -> Result<Self, Self::Err> {
10142 Ok(JsString::from(s))
10143 }
10144}
10145
10146// Symbol
10147#[wasm_bindgen]
10148extern "C" {
10149 #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
10150 #[derive(Clone, Debug)]
10151 pub type Symbol;
10152
10153 /// The `Symbol.hasInstance` well-known symbol is used to determine
10154 /// if a constructor object recognizes an object as its instance.
10155 /// The `instanceof` operator's behavior can be customized by this symbol.
10156 ///
10157 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
10158 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = hasInstance)]
10159 pub fn has_instance() -> Symbol;
10160
10161 /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
10162 /// if an object should be flattened to its array elements when using the
10163 /// `Array.prototype.concat()` method.
10164 ///
10165 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
10166 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = isConcatSpreadable)]
10167 pub fn is_concat_spreadable() -> Symbol;
10168
10169 /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
10170 /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
10171 ///
10172 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
10173 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncIterator)]
10174 pub fn async_iterator() -> Symbol;
10175
10176 /// The `Symbol.iterator` well-known symbol specifies the default iterator
10177 /// for an object. Used by `for...of`.
10178 ///
10179 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
10180 #[wasm_bindgen(static_method_of = Symbol, getter)]
10181 pub fn iterator() -> Symbol;
10182
10183 /// The `Symbol.match` well-known symbol specifies the matching of a regular
10184 /// expression against a string. This function is called by the
10185 /// `String.prototype.match()` method.
10186 ///
10187 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
10188 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = match)]
10189 pub fn match_() -> Symbol;
10190
10191 /// The `Symbol.replace` well-known symbol specifies the method that
10192 /// replaces matched substrings of a string. This function is called by the
10193 /// `String.prototype.replace()` method.
10194 ///
10195 /// For more information, see `RegExp.prototype[@@replace]()` and
10196 /// `String.prototype.replace()`.
10197 ///
10198 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
10199 #[wasm_bindgen(static_method_of = Symbol, getter)]
10200 pub fn replace() -> Symbol;
10201
10202 /// The `Symbol.search` well-known symbol specifies the method that returns
10203 /// the index within a string that matches the regular expression. This
10204 /// function is called by the `String.prototype.search()` method.
10205 ///
10206 /// For more information, see `RegExp.prototype[@@search]()` and
10207 /// `String.prototype.search()`.
10208 ///
10209 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
10210 #[wasm_bindgen(static_method_of = Symbol, getter)]
10211 pub fn search() -> Symbol;
10212
10213 /// The well-known symbol `Symbol.species` specifies a function-valued
10214 /// property that the constructor function uses to create derived objects.
10215 ///
10216 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
10217 #[wasm_bindgen(static_method_of = Symbol, getter)]
10218 pub fn species() -> Symbol;
10219
10220 /// The `Symbol.split` well-known symbol specifies the method that splits a
10221 /// string at the indices that match a regular expression. This function is
10222 /// called by the `String.prototype.split()` method.
10223 ///
10224 /// For more information, see `RegExp.prototype[@@split]()` and
10225 /// `String.prototype.split()`.
10226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
10227 #[wasm_bindgen(static_method_of = Symbol, getter)]
10228 pub fn split() -> Symbol;
10229
10230 /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
10231 /// property that is called to convert an object to a corresponding
10232 /// primitive value.
10233 ///
10234 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
10235 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toPrimitive)]
10236 pub fn to_primitive() -> Symbol;
10237
10238 /// The `Symbol.toStringTag` well-known symbol is a string valued property
10239 /// that is used in the creation of the default string description of an
10240 /// object. It is accessed internally by the `Object.prototype.toString()`
10241 /// method.
10242 ///
10243 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10244 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toStringTag)]
10245 pub fn to_string_tag() -> Symbol;
10246
10247 /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
10248 /// the given key and returns it if found.
10249 /// Otherwise a new symbol gets created in the global symbol registry with this key.
10250 ///
10251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
10252 #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
10253 pub fn for_(key: &str) -> Symbol;
10254
10255 /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
10256 ///
10257 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
10258 #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
10259 pub fn key_for(sym: &Symbol) -> JsValue;
10260
10261 // Next major: deprecate
10262 /// The `toString()` method returns a string representing the specified Symbol object.
10263 ///
10264 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10265 #[wasm_bindgen(method, js_name = toString)]
10266 pub fn to_string(this: &Symbol) -> JsString;
10267
10268 /// The `toString()` method returns a string representing the specified Symbol object.
10269 ///
10270 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10271 #[wasm_bindgen(method, js_name = toString)]
10272 pub fn to_js_string(this: &Symbol) -> JsString;
10273
10274 /// The `Symbol.unscopables` well-known symbol is used to specify an object
10275 /// value of whose own and inherited property names are excluded from the
10276 /// with environment bindings of the associated object.
10277 ///
10278 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
10279 #[wasm_bindgen(static_method_of = Symbol, getter)]
10280 pub fn unscopables() -> Symbol;
10281
10282 /// The `valueOf()` method returns the primitive value of a Symbol object.
10283 ///
10284 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
10285 #[wasm_bindgen(method, js_name = valueOf)]
10286 pub fn value_of(this: &Symbol) -> Symbol;
10287}
10288
10289mod primitive_union_sealed {
10290 /// Seal for the TypeScript primitive-union marker traits.
10291 pub trait Sealed {}
10292}
10293
10294macro_rules! impl_primitive_union_category {
10295 ($trait:path, bigint) => {
10296 impl $trait for i64 {}
10297 impl $trait for u64 {}
10298 impl $trait for i128 {}
10299 impl $trait for u128 {}
10300 impl $trait for BigInt {}
10301 impl $trait for &BigInt {}
10302 };
10303 ($trait:path, boolean) => {
10304 impl $trait for bool {}
10305 impl $trait for Boolean {}
10306 impl $trait for &Boolean {}
10307 };
10308 ($trait:path, number) => {
10309 impl $trait for i8 {}
10310 impl $trait for u8 {}
10311 impl $trait for i16 {}
10312 impl $trait for u16 {}
10313 impl $trait for i32 {}
10314 impl $trait for u32 {}
10315 impl $trait for isize {}
10316 impl $trait for usize {}
10317 impl $trait for f32 {}
10318 impl $trait for f64 {}
10319 impl $trait for Number {}
10320 impl $trait for &Number {}
10321 };
10322 // Mirrors the sealed `wasm_bindgen::JsStringLike` implementations. A
10323 // blanket `impl<T: JsStringLike>` would overlap with the concrete impls
10324 // below, since coherence cannot rule out a foreign trait being implemented
10325 // for `i32` and friends.
10326 ($trait:path, string) => {
10327 impl $trait for String {}
10328 impl $trait for &str {}
10329 impl $trait for &String {}
10330 impl $trait for &alloc::boxed::Box<str> {}
10331 impl $trait for &alloc::borrow::Cow<'_, str> {}
10332 impl $trait for JsString {}
10333 impl $trait for &JsString {}
10334 };
10335 ($trait:path, symbol) => {
10336 impl $trait for Symbol {}
10337 impl $trait for &Symbol {}
10338 };
10339}
10340
10341impl_primitive_union_category!(primitive_union_sealed::Sealed, bigint);
10342impl_primitive_union_category!(primitive_union_sealed::Sealed, boolean);
10343impl_primitive_union_category!(primitive_union_sealed::Sealed, number);
10344impl_primitive_union_category!(primitive_union_sealed::Sealed, string);
10345impl_primitive_union_category!(primitive_union_sealed::Sealed, symbol);
10346
10347macro_rules! primitive_union_category_doc {
10348 (bigint) => {
10349 "- `bigint`: `i64`, `u64`, `i128`, `u128`, [`BigInt`], and `&BigInt`\n"
10350 };
10351 (boolean) => {
10352 "- `boolean`: `bool`, [`Boolean`], and `&Boolean`\n"
10353 };
10354 (number) => {
10355 "- `number`: `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `isize`, `usize`, `f32`, `f64`, [`Number`], and `&Number`\n"
10356 };
10357 (string) => {
10358 "- `string`: `String`, `&str`, `&String`, `&Box<str>`, `&Cow<str>`, \
10359 [`JsString`], and `&JsString` (the \
10360 [`JsStringLike`](wasm_bindgen::JsStringLike) types)\n"
10361 };
10362 (symbol) => {
10363 "- `symbol`: [`Symbol`] and `&Symbol`\n"
10364 };
10365}
10366
10367macro_rules! define_primitive_union_traits {
10368 ($(($(#[$attr:meta])* $name:ident, $typescript:literal, [$($supertrait:ident),*], [$($category:ident),+])),* $(,)?) => {
10369 $(
10370 $(#[$attr])*
10371 #[doc = concat!(
10372 "Marker for Rust parameter types represented by the TypeScript union `",
10373 $typescript,
10374 "`.\n\n",
10375 "Use this trait as a bound on an `experimental_generic_mono` ",
10376 "JavaScript import. Each monomorphisation retains its concrete ",
10377 "ABI representation; this marker only restricts which Rust types ",
10378 "may instantiate the parameter.\n\n",
10379 "The union's primitive categories use these Rust representations:\n\n",
10380 $(primitive_union_category_doc!($category),)+
10381 "\nThis trait is experimental and may change or be removed as ",
10382 "`experimental_generic_mono` evolves."
10383 )]
10384 pub trait $name: IntoWasmAbi + primitive_union_sealed::Sealed $(+ $supertrait)* {}
10385
10386 $(impl_primitive_union_category!($name, $category);)+
10387 )*
10388 };
10389}
10390
10391// The catalog covers every union of two or more of the primitive categories
10392// with a Rust-native ABI representation (`bigint`, `boolean`, `number`, and
10393// `string`). `symbol` crosses the boundary as an ordinary JS handle, so unions
10394// containing it are better expressed with a `&Symbol` overload; the one
10395// exception is `PropertyKey`, where `symbol` carries semantic identity.
10396define_primitive_union_traits! {
10397 (
10398 JsBigIntOrBooleanOrNumberOrStringLike,
10399 "bigint | boolean | number | string",
10400 [],
10401 [bigint, boolean, number, string]
10402 ),
10403 (
10404 JsBigIntOrBooleanOrNumberLike,
10405 "bigint | boolean | number",
10406 [JsBigIntOrBooleanOrNumberOrStringLike],
10407 [bigint, boolean, number]
10408 ),
10409 (
10410 JsBigIntOrBooleanOrStringLike,
10411 "bigint | boolean | string",
10412 [JsBigIntOrBooleanOrNumberOrStringLike],
10413 [bigint, boolean, string]
10414 ),
10415 (
10416 JsBigIntOrNumberOrStringLike,
10417 "bigint | number | string",
10418 [JsBigIntOrBooleanOrNumberOrStringLike],
10419 [bigint, number, string]
10420 ),
10421 (
10422 JsBooleanOrNumberOrStringLike,
10423 "boolean | number | string",
10424 [JsBigIntOrBooleanOrNumberOrStringLike],
10425 [boolean, number, string]
10426 ),
10427 (
10428 JsBigIntOrBooleanLike,
10429 "bigint | boolean",
10430 [JsBigIntOrBooleanOrNumberLike, JsBigIntOrBooleanOrStringLike],
10431 [bigint, boolean]
10432 ),
10433 (
10434 JsBigIntOrNumberLike,
10435 "bigint | number",
10436 [JsBigIntOrBooleanOrNumberLike, JsBigIntOrNumberOrStringLike],
10437 [bigint, number]
10438 ),
10439 (
10440 JsBigIntOrStringLike,
10441 "bigint | string",
10442 [JsBigIntOrBooleanOrStringLike, JsBigIntOrNumberOrStringLike],
10443 [bigint, string]
10444 ),
10445 (
10446 JsBooleanOrNumberLike,
10447 "boolean | number",
10448 [JsBigIntOrBooleanOrNumberLike, JsBooleanOrNumberOrStringLike],
10449 [boolean, number]
10450 ),
10451 (
10452 JsBooleanOrStringLike,
10453 "boolean | string",
10454 [JsBigIntOrBooleanOrStringLike, JsBooleanOrNumberOrStringLike],
10455 [boolean, string]
10456 ),
10457 (
10458 JsNumberOrStringLike,
10459 "number | string",
10460 [
10461 JsBigIntOrNumberOrStringLike,
10462 JsBooleanOrNumberOrStringLike,
10463 PropertyKey
10464 ],
10465 [number, string]
10466 ),
10467 (
10468 /// TypeScript's `PropertyKey`: the key types accepted by JavaScript
10469 /// property operations and by TypeScript's `Record`.
10470 ///
10471 PropertyKey,
10472 "number | string | symbol",
10473 [],
10474 [number, string, symbol]
10475 ),
10476}
10477
10478#[allow(non_snake_case)]
10479pub mod Intl {
10480 use super::*;
10481
10482 // Intl
10483 #[wasm_bindgen]
10484 extern "C" {
10485 /// The `Intl.getCanonicalLocales()` method returns an array containing
10486 /// the canonical locale names. Duplicates will be omitted and elements
10487 /// will be validated as structurally valid language tags.
10488 ///
10489 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
10490 #[cfg(not(js_sys_unstable_apis))]
10491 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
10492 pub fn get_canonical_locales(s: &JsValue) -> Array;
10493
10494 /// The `Intl.getCanonicalLocales()` method returns an array containing
10495 /// the canonical locale names. Duplicates will be omitted and elements
10496 /// will be validated as structurally valid language tags.
10497 ///
10498 /// Throws a `RangeError` if any of the strings are not valid locale identifiers.
10499 ///
10500 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
10501 #[cfg(js_sys_unstable_apis)]
10502 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl, catch)]
10503 pub fn get_canonical_locales(s: &[JsString]) -> Result<Array<JsString>, JsValue>;
10504
10505 /// The `Intl.supportedValuesOf()` method returns an array containing the
10506 /// supported calendar, collation, currency, numbering system, or unit values
10507 /// supported by the implementation.
10508 ///
10509 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
10510 #[wasm_bindgen(js_name = supportedValuesOf, js_namespace = Intl)]
10511 pub fn supported_values_of(key: SupportedValuesKey) -> Array<JsString>;
10512 }
10513
10514 // Intl string enums
10515
10516 /// Key for `Intl.supportedValuesOf()`.
10517 #[wasm_bindgen]
10518 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10519 pub enum SupportedValuesKey {
10520 Calendar = "calendar",
10521 Collation = "collation",
10522 Currency = "currency",
10523 NumberingSystem = "numberingSystem",
10524 TimeZone = "timeZone",
10525 Unit = "unit",
10526 }
10527
10528 /// Locale matching algorithm for Intl constructors.
10529 #[wasm_bindgen]
10530 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10531 pub enum LocaleMatcher {
10532 Lookup = "lookup",
10533 BestFit = "best fit",
10534 }
10535
10536 /// Usage for `Intl.Collator`.
10537 #[wasm_bindgen]
10538 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10539 pub enum CollatorUsage {
10540 Sort = "sort",
10541 Search = "search",
10542 }
10543
10544 /// Sensitivity for `Intl.Collator`.
10545 #[wasm_bindgen]
10546 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10547 pub enum CollatorSensitivity {
10548 Base = "base",
10549 Accent = "accent",
10550 Case = "case",
10551 Variant = "variant",
10552 }
10553
10554 /// Case first option for `Intl.Collator`.
10555 #[wasm_bindgen]
10556 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10557 pub enum CollatorCaseFirst {
10558 Upper = "upper",
10559 Lower = "lower",
10560 False = "false",
10561 }
10562
10563 /// Style for `Intl.NumberFormat`.
10564 #[wasm_bindgen]
10565 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10566 pub enum NumberFormatStyle {
10567 Decimal = "decimal",
10568 Currency = "currency",
10569 Percent = "percent",
10570 Unit = "unit",
10571 }
10572
10573 /// Currency display for `Intl.NumberFormat`.
10574 #[wasm_bindgen]
10575 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10576 pub enum CurrencyDisplay {
10577 Code = "code",
10578 Symbol = "symbol",
10579 NarrowSymbol = "narrowSymbol",
10580 Name = "name",
10581 }
10582
10583 /// Currency sign for `Intl.NumberFormat`.
10584 #[wasm_bindgen]
10585 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10586 pub enum CurrencySign {
10587 Standard = "standard",
10588 Accounting = "accounting",
10589 }
10590
10591 /// Unit display for `Intl.NumberFormat`.
10592 #[wasm_bindgen]
10593 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10594 pub enum UnitDisplay {
10595 Short = "short",
10596 Narrow = "narrow",
10597 Long = "long",
10598 }
10599
10600 /// Notation for `Intl.NumberFormat`.
10601 #[wasm_bindgen]
10602 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10603 pub enum NumberFormatNotation {
10604 Standard = "standard",
10605 Scientific = "scientific",
10606 Engineering = "engineering",
10607 Compact = "compact",
10608 }
10609
10610 /// Compact display for `Intl.NumberFormat`.
10611 #[wasm_bindgen]
10612 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10613 pub enum CompactDisplay {
10614 Short = "short",
10615 Long = "long",
10616 }
10617
10618 /// Sign display for `Intl.NumberFormat`.
10619 #[wasm_bindgen]
10620 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10621 pub enum SignDisplay {
10622 Auto = "auto",
10623 Never = "never",
10624 Always = "always",
10625 ExceptZero = "exceptZero",
10626 }
10627
10628 /// Rounding mode for `Intl.NumberFormat`.
10629 #[wasm_bindgen]
10630 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10631 pub enum RoundingMode {
10632 Ceil = "ceil",
10633 Floor = "floor",
10634 Expand = "expand",
10635 Trunc = "trunc",
10636 HalfCeil = "halfCeil",
10637 HalfFloor = "halfFloor",
10638 HalfExpand = "halfExpand",
10639 HalfTrunc = "halfTrunc",
10640 HalfEven = "halfEven",
10641 }
10642
10643 /// Rounding priority for `Intl.NumberFormat`.
10644 #[wasm_bindgen]
10645 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10646 pub enum RoundingPriority {
10647 Auto = "auto",
10648 MorePrecision = "morePrecision",
10649 LessPrecision = "lessPrecision",
10650 }
10651
10652 /// Trailing zero display for `Intl.NumberFormat`.
10653 #[wasm_bindgen]
10654 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10655 pub enum TrailingZeroDisplay {
10656 Auto = "auto",
10657 StripIfInteger = "stripIfInteger",
10658 }
10659
10660 /// Use grouping option for `Intl.NumberFormat`.
10661 ///
10662 /// Determines whether to use grouping separators, such as thousands
10663 /// separators or thousand/lakh/crore separators.
10664 ///
10665 /// The default is `Min2` if notation is "compact", and `Auto` otherwise.
10666 ///
10667 /// Note: The string values `"true"` and `"false"` are accepted by JavaScript
10668 /// but are always converted to the default value. Use `True` and `False`
10669 /// variants for the boolean behavior.
10670 ///
10671 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#usegrouping)
10672 #[wasm_bindgen]
10673 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10674 pub enum UseGrouping {
10675 /// Display grouping separators even if the locale prefers otherwise.
10676 Always = "always",
10677 /// Display grouping separators based on the locale preference,
10678 /// which may also be dependent on the currency.
10679 Auto = "auto",
10680 /// Display grouping separators when there are at least 2 digits in a group.
10681 Min2 = "min2",
10682 /// Same as `Always`. Display grouping separators even if the locale prefers otherwise.
10683 True = "true",
10684 /// Display no grouping separators.
10685 False = "false",
10686 }
10687
10688 /// Date/time style for `Intl.DateTimeFormat`.
10689 #[wasm_bindgen]
10690 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10691 pub enum DateTimeStyle {
10692 Full = "full",
10693 Long = "long",
10694 Medium = "medium",
10695 Short = "short",
10696 }
10697
10698 /// Hour cycle for `Intl.DateTimeFormat`.
10699 #[wasm_bindgen]
10700 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10701 pub enum HourCycle {
10702 H11 = "h11",
10703 H12 = "h12",
10704 H23 = "h23",
10705 H24 = "h24",
10706 }
10707
10708 /// Weekday format for `Intl.DateTimeFormat`.
10709 #[wasm_bindgen]
10710 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10711 pub enum WeekdayFormat {
10712 Narrow = "narrow",
10713 Short = "short",
10714 Long = "long",
10715 }
10716
10717 /// Era format for `Intl.DateTimeFormat`.
10718 #[wasm_bindgen]
10719 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10720 pub enum EraFormat {
10721 Narrow = "narrow",
10722 Short = "short",
10723 Long = "long",
10724 }
10725
10726 /// Year format for `Intl.DateTimeFormat`.
10727 #[wasm_bindgen]
10728 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10729 pub enum YearFormat {
10730 Numeric = "numeric",
10731 TwoDigit = "2-digit",
10732 }
10733
10734 /// Month format for `Intl.DateTimeFormat`.
10735 #[wasm_bindgen]
10736 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10737 pub enum MonthFormat {
10738 #[wasm_bindgen]
10739 Numeric = "numeric",
10740 #[wasm_bindgen]
10741 TwoDigit = "2-digit",
10742 #[wasm_bindgen]
10743 Narrow = "narrow",
10744 #[wasm_bindgen]
10745 Short = "short",
10746 #[wasm_bindgen]
10747 Long = "long",
10748 }
10749
10750 /// Day format for `Intl.DateTimeFormat`.
10751 #[wasm_bindgen]
10752 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10753 pub enum DayFormat {
10754 #[wasm_bindgen]
10755 Numeric = "numeric",
10756 #[wasm_bindgen]
10757 TwoDigit = "2-digit",
10758 }
10759
10760 /// Hour/minute/second format for `Intl.DateTimeFormat`.
10761 #[wasm_bindgen]
10762 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10763 pub enum NumericFormat {
10764 #[wasm_bindgen]
10765 Numeric = "numeric",
10766 #[wasm_bindgen]
10767 TwoDigit = "2-digit",
10768 }
10769
10770 /// Time zone name format for `Intl.DateTimeFormat`.
10771 #[wasm_bindgen]
10772 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10773 pub enum TimeZoneNameFormat {
10774 Short = "short",
10775 Long = "long",
10776 ShortOffset = "shortOffset",
10777 LongOffset = "longOffset",
10778 ShortGeneric = "shortGeneric",
10779 LongGeneric = "longGeneric",
10780 }
10781
10782 /// Day period format for `Intl.DateTimeFormat`.
10783 #[wasm_bindgen]
10784 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10785 pub enum DayPeriodFormat {
10786 Narrow = "narrow",
10787 Short = "short",
10788 Long = "long",
10789 }
10790
10791 /// Part type for `DateTimeFormat.formatToParts()`.
10792 #[wasm_bindgen]
10793 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10794 pub enum DateTimeFormatPartType {
10795 Day = "day",
10796 DayPeriod = "dayPeriod",
10797 Era = "era",
10798 FractionalSecond = "fractionalSecond",
10799 Hour = "hour",
10800 Literal = "literal",
10801 Minute = "minute",
10802 Month = "month",
10803 RelatedYear = "relatedYear",
10804 Second = "second",
10805 TimeZoneName = "timeZoneName",
10806 Weekday = "weekday",
10807 Year = "year",
10808 YearName = "yearName",
10809 }
10810
10811 /// Part type for `NumberFormat.formatToParts()`.
10812 #[wasm_bindgen]
10813 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10814 pub enum NumberFormatPartType {
10815 Compact = "compact",
10816 Currency = "currency",
10817 Decimal = "decimal",
10818 ExponentInteger = "exponentInteger",
10819 ExponentMinusSign = "exponentMinusSign",
10820 ExponentSeparator = "exponentSeparator",
10821 Fraction = "fraction",
10822 Group = "group",
10823 Infinity = "infinity",
10824 Integer = "integer",
10825 Literal = "literal",
10826 MinusSign = "minusSign",
10827 Nan = "nan",
10828 PercentSign = "percentSign",
10829 PlusSign = "plusSign",
10830 Unit = "unit",
10831 Unknown = "unknown",
10832 }
10833
10834 /// Type for `Intl.PluralRules` (cardinal or ordinal).
10835 #[wasm_bindgen]
10836 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10837 pub enum PluralRulesType {
10838 Cardinal = "cardinal",
10839 Ordinal = "ordinal",
10840 }
10841
10842 /// Plural category returned by `PluralRules.select()`.
10843 #[wasm_bindgen]
10844 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10845 pub enum PluralCategory {
10846 Zero = "zero",
10847 One = "one",
10848 Two = "two",
10849 Few = "few",
10850 Many = "many",
10851 Other = "other",
10852 }
10853
10854 /// Numeric option for `Intl.RelativeTimeFormat`.
10855 #[wasm_bindgen]
10856 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10857 pub enum RelativeTimeFormatNumeric {
10858 Always = "always",
10859 Auto = "auto",
10860 }
10861
10862 /// Style for `Intl.RelativeTimeFormat`.
10863 #[wasm_bindgen]
10864 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10865 pub enum RelativeTimeFormatStyle {
10866 Long = "long",
10867 Short = "short",
10868 Narrow = "narrow",
10869 }
10870
10871 /// Unit for `RelativeTimeFormat.format()`.
10872 #[wasm_bindgen]
10873 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10874 pub enum RelativeTimeFormatUnit {
10875 Year = "year",
10876 Years = "years",
10877 Quarter = "quarter",
10878 Quarters = "quarters",
10879 Month = "month",
10880 Months = "months",
10881 Week = "week",
10882 Weeks = "weeks",
10883 Day = "day",
10884 Days = "days",
10885 Hour = "hour",
10886 Hours = "hours",
10887 Minute = "minute",
10888 Minutes = "minutes",
10889 Second = "second",
10890 Seconds = "seconds",
10891 }
10892
10893 /// Part type for `RelativeTimeFormat.formatToParts()`.
10894 #[wasm_bindgen]
10895 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10896 pub enum RelativeTimeFormatPartType {
10897 Literal = "literal",
10898 Integer = "integer",
10899 Decimal = "decimal",
10900 Fraction = "fraction",
10901 }
10902
10903 /// Source indicator for range format parts.
10904 ///
10905 /// Indicates which part of the range (start, end, or shared) a formatted
10906 /// part belongs to when using `formatRangeToParts()`.
10907 ///
10908 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts#description)
10909 #[wasm_bindgen]
10910 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10911 pub enum RangeSource {
10912 /// The part is from the start of the range.
10913 StartRange = "startRange",
10914 /// The part is from the end of the range.
10915 EndRange = "endRange",
10916 /// The part is shared between start and end (e.g., a separator or common element).
10917 Shared = "shared",
10918 }
10919
10920 /// Type for `Intl.ListFormat`.
10921 #[wasm_bindgen]
10922 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10923 pub enum ListFormatType {
10924 /// For lists of standalone items (default).
10925 Conjunction = "conjunction",
10926 /// For lists representing alternatives.
10927 Disjunction = "disjunction",
10928 /// For lists of values with units.
10929 Unit = "unit",
10930 }
10931
10932 /// Style for `Intl.ListFormat`.
10933 #[wasm_bindgen]
10934 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10935 pub enum ListFormatStyle {
10936 /// "A, B, and C" (default).
10937 Long = "long",
10938 /// "A, B, C".
10939 Short = "short",
10940 /// "A B C".
10941 Narrow = "narrow",
10942 }
10943
10944 /// Part type for `Intl.ListFormat.formatToParts()`.
10945 #[wasm_bindgen]
10946 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10947 pub enum ListFormatPartType {
10948 /// A value from the list.
10949 Element = "element",
10950 /// A linguistic construct (e.g., ", ", " and ").
10951 Literal = "literal",
10952 }
10953
10954 /// Type for `Intl.Segmenter`.
10955 #[wasm_bindgen]
10956 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10957 pub enum SegmenterGranularity {
10958 /// Segment by grapheme clusters (user-perceived characters).
10959 Grapheme = "grapheme",
10960 /// Segment by words.
10961 Word = "word",
10962 /// Segment by sentences.
10963 Sentence = "sentence",
10964 }
10965
10966 /// Type for `Intl.DisplayNames`.
10967 #[wasm_bindgen]
10968 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10969 pub enum DisplayNamesType {
10970 /// Language display names.
10971 Language = "language",
10972 /// Region display names.
10973 Region = "region",
10974 /// Script display names.
10975 Script = "script",
10976 /// Currency display names.
10977 Currency = "currency",
10978 /// Calendar display names.
10979 Calendar = "calendar",
10980 /// Date/time field display names.
10981 DateTimeField = "dateTimeField",
10982 }
10983
10984 /// Style for `Intl.DisplayNames`.
10985 #[wasm_bindgen]
10986 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10987 pub enum DisplayNamesStyle {
10988 /// Full display name (default).
10989 Long = "long",
10990 /// Abbreviated display name.
10991 Short = "short",
10992 /// Minimal display name.
10993 Narrow = "narrow",
10994 }
10995
10996 /// Fallback for `Intl.DisplayNames`.
10997 #[wasm_bindgen]
10998 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10999 pub enum DisplayNamesFallback {
11000 /// Return the input code if no display name is available (default).
11001 Code = "code",
11002 /// Return undefined if no display name is available.
11003 None = "none",
11004 }
11005
11006 /// Language display for `Intl.DisplayNames`.
11007 #[wasm_bindgen]
11008 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11009 pub enum DisplayNamesLanguageDisplay {
11010 /// Use dialect names (e.g., "British English").
11011 Dialect = "dialect",
11012 /// Use standard names (e.g., "English (United Kingdom)").
11013 Standard = "standard",
11014 }
11015
11016 // Intl.RelativeTimeFormatOptions
11017 #[wasm_bindgen]
11018 extern "C" {
11019 /// Options for `Intl.RelativeTimeFormat` constructor.
11020 ///
11021 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#options)
11022 #[wasm_bindgen(extends = Object)]
11023 #[derive(Clone, Debug)]
11024 pub type RelativeTimeFormatOptions;
11025
11026 #[wasm_bindgen(method, getter = localeMatcher)]
11027 pub fn get_locale_matcher(this: &RelativeTimeFormatOptions) -> Option<LocaleMatcher>;
11028 #[wasm_bindgen(method, setter = localeMatcher)]
11029 pub fn set_locale_matcher(this: &RelativeTimeFormatOptions, value: LocaleMatcher);
11030
11031 #[wasm_bindgen(method, getter = numeric)]
11032 pub fn get_numeric(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatNumeric>;
11033 #[wasm_bindgen(method, setter = numeric)]
11034 pub fn set_numeric(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatNumeric);
11035
11036 #[wasm_bindgen(method, getter = style)]
11037 pub fn get_style(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatStyle>;
11038 #[wasm_bindgen(method, setter = style)]
11039 pub fn set_style(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatStyle);
11040 }
11041
11042 impl RelativeTimeFormatOptions {
11043 pub fn new() -> RelativeTimeFormatOptions {
11044 JsCast::unchecked_into(Object::new())
11045 }
11046 }
11047
11048 impl Default for RelativeTimeFormatOptions {
11049 fn default() -> Self {
11050 RelativeTimeFormatOptions::new()
11051 }
11052 }
11053
11054 // Intl.ResolvedRelativeTimeFormatOptions
11055 #[wasm_bindgen]
11056 extern "C" {
11057 /// Resolved options returned by `Intl.RelativeTimeFormat.prototype.resolvedOptions()`.
11058 ///
11059 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11060 #[wasm_bindgen(extends = RelativeTimeFormatOptions)]
11061 #[derive(Clone, Debug)]
11062 pub type ResolvedRelativeTimeFormatOptions;
11063
11064 /// The resolved locale string.
11065 #[wasm_bindgen(method, getter = locale)]
11066 pub fn get_locale(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
11067
11068 /// The numbering system used.
11069 #[wasm_bindgen(method, getter = numberingSystem)]
11070 pub fn get_numbering_system(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
11071 }
11072
11073 // Intl.RelativeTimeFormatPart
11074 #[wasm_bindgen]
11075 extern "C" {
11076 /// A part of the formatted relative time returned by `formatToParts()`.
11077 ///
11078 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11079 #[wasm_bindgen(extends = Object)]
11080 #[derive(Clone, Debug)]
11081 pub type RelativeTimeFormatPart;
11082
11083 /// The type of this part.
11084 #[wasm_bindgen(method, getter = type)]
11085 pub fn type_(this: &RelativeTimeFormatPart) -> RelativeTimeFormatPartType;
11086
11087 /// The string value of this part.
11088 #[wasm_bindgen(method, getter = value)]
11089 pub fn value(this: &RelativeTimeFormatPart) -> JsString;
11090
11091 /// The unit used in this part (only for integer parts).
11092 #[wasm_bindgen(method, getter = unit)]
11093 pub fn unit(this: &RelativeTimeFormatPart) -> Option<JsString>;
11094 }
11095
11096 // Intl.LocaleMatcherOptions
11097 #[wasm_bindgen]
11098 extern "C" {
11099 /// Options for `supportedLocalesOf` methods.
11100 #[wasm_bindgen(extends = Object)]
11101 #[derive(Clone, Debug)]
11102 pub type LocaleMatcherOptions;
11103
11104 #[wasm_bindgen(method, getter = localeMatcher)]
11105 pub fn get_locale_matcher(this: &LocaleMatcherOptions) -> Option<LocaleMatcher>;
11106
11107 #[wasm_bindgen(method, setter = localeMatcher)]
11108 pub fn set_locale_matcher(this: &LocaleMatcherOptions, value: LocaleMatcher);
11109 }
11110
11111 impl LocaleMatcherOptions {
11112 pub fn new() -> LocaleMatcherOptions {
11113 JsCast::unchecked_into(Object::new())
11114 }
11115 }
11116
11117 impl Default for LocaleMatcherOptions {
11118 fn default() -> Self {
11119 LocaleMatcherOptions::new()
11120 }
11121 }
11122
11123 // Intl.Collator Options
11124 #[wasm_bindgen]
11125 extern "C" {
11126 /// Options for `Intl.Collator` and `String.prototype.localeCompare`.
11127 ///
11128 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options)
11129 #[wasm_bindgen(extends = Object)]
11130 #[derive(Clone, Debug)]
11131 pub type CollatorOptions;
11132
11133 #[wasm_bindgen(method, getter = localeMatcher)]
11134 pub fn get_locale_matcher(this: &CollatorOptions) -> Option<LocaleMatcher>;
11135 #[wasm_bindgen(method, setter = localeMatcher)]
11136 pub fn set_locale_matcher(this: &CollatorOptions, value: LocaleMatcher);
11137
11138 #[wasm_bindgen(method, getter = usage)]
11139 pub fn get_usage(this: &CollatorOptions) -> Option<CollatorUsage>;
11140 #[wasm_bindgen(method, setter = usage)]
11141 pub fn set_usage(this: &CollatorOptions, value: CollatorUsage);
11142
11143 #[wasm_bindgen(method, getter = sensitivity)]
11144 pub fn get_sensitivity(this: &CollatorOptions) -> Option<CollatorSensitivity>;
11145 #[wasm_bindgen(method, setter = sensitivity)]
11146 pub fn set_sensitivity(this: &CollatorOptions, value: CollatorSensitivity);
11147
11148 #[wasm_bindgen(method, getter = ignorePunctuation)]
11149 pub fn get_ignore_punctuation(this: &CollatorOptions) -> Option<bool>;
11150 #[wasm_bindgen(method, setter = ignorePunctuation)]
11151 pub fn set_ignore_punctuation(this: &CollatorOptions, value: bool);
11152
11153 #[wasm_bindgen(method, getter = numeric)]
11154 pub fn get_numeric(this: &CollatorOptions) -> Option<bool>;
11155 #[wasm_bindgen(method, setter = numeric)]
11156 pub fn set_numeric(this: &CollatorOptions, value: bool);
11157
11158 #[wasm_bindgen(method, getter = caseFirst)]
11159 pub fn get_case_first(this: &CollatorOptions) -> Option<CollatorCaseFirst>;
11160 #[wasm_bindgen(method, setter = caseFirst)]
11161 pub fn set_case_first(this: &CollatorOptions, value: CollatorCaseFirst);
11162 }
11163 impl CollatorOptions {
11164 pub fn new() -> CollatorOptions {
11165 JsCast::unchecked_into(Object::new())
11166 }
11167 }
11168 impl Default for CollatorOptions {
11169 fn default() -> Self {
11170 CollatorOptions::new()
11171 }
11172 }
11173
11174 // Intl.Collator ResolvedCollatorOptions
11175 #[wasm_bindgen]
11176 extern "C" {
11177 #[wasm_bindgen(extends = CollatorOptions)]
11178 #[derive(Clone, Debug)]
11179 pub type ResolvedCollatorOptions;
11180
11181 #[wasm_bindgen(method, getter = locale)]
11182 pub fn get_locale(this: &ResolvedCollatorOptions) -> JsString; // not Option, always present
11183 #[wasm_bindgen(method, getter = collation)]
11184 pub fn get_collation(this: &ResolvedCollatorOptions) -> JsString;
11185 }
11186
11187 // Intl.Collator
11188 #[wasm_bindgen]
11189 extern "C" {
11190 /// The `Intl.Collator` object is a constructor for collators, objects
11191 /// that enable language sensitive string comparison.
11192 ///
11193 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
11194 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
11195 #[derive(Clone, Debug)]
11196 pub type Collator;
11197
11198 /// The `Intl.Collator` object is a constructor for collators, objects
11199 /// that enable language sensitive string comparison.
11200 ///
11201 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
11202 #[cfg(not(js_sys_unstable_apis))]
11203 #[wasm_bindgen(constructor, js_namespace = Intl)]
11204 pub fn new(locales: &Array, options: &Object) -> Collator;
11205
11206 /// The `Intl.Collator` object is a constructor for collators, objects
11207 /// that enable language sensitive string comparison.
11208 ///
11209 /// Throws a `RangeError` if locales contain invalid values.
11210 ///
11211 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
11212 #[cfg(js_sys_unstable_apis)]
11213 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11214 pub fn new(locales: &[JsString], options: &CollatorOptions) -> Result<Collator, JsValue>;
11215
11216 /// The Intl.Collator.prototype.compare property returns a function that
11217 /// compares two strings according to the sort order of this Collator
11218 /// object.
11219 ///
11220 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
11221 #[cfg(not(js_sys_unstable_apis))]
11222 #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
11223 pub fn compare(this: &Collator) -> Function;
11224
11225 /// Compares two strings according to the sort order of this Collator.
11226 ///
11227 /// Returns a negative value if `a` comes before `b`, positive if `a` comes
11228 /// after `b`, and zero if they are equal.
11229 ///
11230 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare)
11231 #[cfg(js_sys_unstable_apis)]
11232 #[wasm_bindgen(method, js_class = "Intl.Collator")]
11233 pub fn compare(this: &Collator, a: &str, b: &str) -> i32;
11234
11235 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
11236 /// object with properties reflecting the locale and collation options
11237 /// computed during initialization of this Collator object.
11238 ///
11239 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
11240 #[cfg(not(js_sys_unstable_apis))]
11241 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11242 pub fn resolved_options(this: &Collator) -> Object;
11243
11244 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
11245 /// object with properties reflecting the locale and collation options
11246 /// computed during initialization of this Collator object.
11247 ///
11248 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
11249 #[cfg(js_sys_unstable_apis)]
11250 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11251 pub fn resolved_options(this: &Collator) -> ResolvedCollatorOptions;
11252
11253 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
11254 /// containing those of the provided locales that are supported in
11255 /// collation without having to fall back to the runtime's default
11256 /// locale.
11257 ///
11258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
11259 #[cfg(not(js_sys_unstable_apis))]
11260 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
11261 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11262
11263 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
11264 /// containing those of the provided locales that are supported in
11265 /// collation without having to fall back to the runtime's default
11266 /// locale.
11267 ///
11268 /// Throws a `RangeError` if locales contain invalid values.
11269 ///
11270 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
11271 #[cfg(js_sys_unstable_apis)]
11272 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11273 pub fn supported_locales_of(
11274 locales: &[JsString],
11275 options: &LocaleMatcherOptions,
11276 ) -> Result<Array<JsString>, JsValue>;
11277 }
11278
11279 #[cfg(not(js_sys_unstable_apis))]
11280 impl Default for Collator {
11281 fn default() -> Self {
11282 Self::new(
11283 &JsValue::UNDEFINED.unchecked_into(),
11284 &JsValue::UNDEFINED.unchecked_into(),
11285 )
11286 }
11287 }
11288
11289 #[cfg(js_sys_unstable_apis)]
11290 impl Default for Collator {
11291 fn default() -> Self {
11292 Self::new(&[], &Default::default()).unwrap()
11293 }
11294 }
11295
11296 // Intl.DateTimeFormatOptions
11297 #[wasm_bindgen]
11298 extern "C" {
11299 /// Options for `Intl.DateTimeFormat` constructor.
11300 ///
11301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)
11302 #[wasm_bindgen(extends = Object)]
11303 #[derive(Clone, Debug)]
11304 pub type DateTimeFormatOptions;
11305
11306 // Locale matching
11307 #[wasm_bindgen(method, getter = localeMatcher)]
11308 pub fn get_locale_matcher(this: &DateTimeFormatOptions) -> Option<LocaleMatcher>;
11309 #[wasm_bindgen(method, setter = localeMatcher)]
11310 pub fn set_locale_matcher(this: &DateTimeFormatOptions, value: LocaleMatcher);
11311
11312 // Calendar/numbering (free-form strings, no enum)
11313 #[wasm_bindgen(method, getter = calendar)]
11314 pub fn get_calendar(this: &DateTimeFormatOptions) -> Option<JsString>;
11315 #[wasm_bindgen(method, setter = calendar)]
11316 pub fn set_calendar(this: &DateTimeFormatOptions, value: &str);
11317
11318 #[wasm_bindgen(method, getter = numberingSystem)]
11319 pub fn get_numbering_system(this: &DateTimeFormatOptions) -> Option<JsString>;
11320 #[wasm_bindgen(method, setter = numberingSystem)]
11321 pub fn set_numbering_system(this: &DateTimeFormatOptions, value: &str);
11322
11323 // Timezone (free-form string)
11324 #[wasm_bindgen(method, getter = timeZone)]
11325 pub fn get_time_zone(this: &DateTimeFormatOptions) -> Option<JsString>;
11326 #[wasm_bindgen(method, setter = timeZone)]
11327 pub fn set_time_zone(this: &DateTimeFormatOptions, value: &str);
11328
11329 // Hour cycle
11330 #[wasm_bindgen(method, getter = hour12)]
11331 pub fn get_hour12(this: &DateTimeFormatOptions) -> Option<bool>;
11332 #[wasm_bindgen(method, setter = hour12)]
11333 pub fn set_hour12(this: &DateTimeFormatOptions, value: bool);
11334
11335 #[wasm_bindgen(method, getter = hourCycle)]
11336 pub fn get_hour_cycle(this: &DateTimeFormatOptions) -> Option<HourCycle>;
11337 #[wasm_bindgen(method, setter = hourCycle)]
11338 pub fn set_hour_cycle(this: &DateTimeFormatOptions, value: HourCycle);
11339
11340 // Style shortcuts
11341 #[wasm_bindgen(method, getter = dateStyle)]
11342 pub fn get_date_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
11343 #[wasm_bindgen(method, setter = dateStyle)]
11344 pub fn set_date_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
11345
11346 #[wasm_bindgen(method, getter = timeStyle)]
11347 pub fn get_time_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
11348 #[wasm_bindgen(method, setter = timeStyle)]
11349 pub fn set_time_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
11350
11351 // Component options
11352 #[wasm_bindgen(method, getter = weekday)]
11353 pub fn get_weekday(this: &DateTimeFormatOptions) -> Option<WeekdayFormat>;
11354 #[wasm_bindgen(method, setter = weekday)]
11355 pub fn set_weekday(this: &DateTimeFormatOptions, value: WeekdayFormat);
11356
11357 #[wasm_bindgen(method, getter = era)]
11358 pub fn get_era(this: &DateTimeFormatOptions) -> Option<EraFormat>;
11359 #[wasm_bindgen(method, setter = era)]
11360 pub fn set_era(this: &DateTimeFormatOptions, value: EraFormat);
11361
11362 #[wasm_bindgen(method, getter = year)]
11363 pub fn get_year(this: &DateTimeFormatOptions) -> Option<YearFormat>;
11364 #[wasm_bindgen(method, setter = year)]
11365 pub fn set_year(this: &DateTimeFormatOptions, value: YearFormat);
11366
11367 #[wasm_bindgen(method, getter = month)]
11368 pub fn get_month(this: &DateTimeFormatOptions) -> Option<MonthFormat>;
11369 #[wasm_bindgen(method, setter = month)]
11370 pub fn set_month(this: &DateTimeFormatOptions, value: MonthFormat);
11371
11372 #[wasm_bindgen(method, getter = day)]
11373 pub fn get_day(this: &DateTimeFormatOptions) -> Option<DayFormat>;
11374 #[wasm_bindgen(method, setter = day)]
11375 pub fn set_day(this: &DateTimeFormatOptions, value: DayFormat);
11376
11377 #[wasm_bindgen(method, getter = hour)]
11378 pub fn get_hour(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
11379 #[wasm_bindgen(method, setter = hour)]
11380 pub fn set_hour(this: &DateTimeFormatOptions, value: NumericFormat);
11381
11382 #[wasm_bindgen(method, getter = minute)]
11383 pub fn get_minute(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
11384 #[wasm_bindgen(method, setter = minute)]
11385 pub fn set_minute(this: &DateTimeFormatOptions, value: NumericFormat);
11386
11387 #[wasm_bindgen(method, getter = second)]
11388 pub fn get_second(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
11389 #[wasm_bindgen(method, setter = second)]
11390 pub fn set_second(this: &DateTimeFormatOptions, value: NumericFormat);
11391
11392 #[wasm_bindgen(method, getter = fractionalSecondDigits)]
11393 pub fn get_fractional_second_digits(this: &DateTimeFormatOptions) -> Option<u8>;
11394 #[wasm_bindgen(method, setter = fractionalSecondDigits)]
11395 pub fn set_fractional_second_digits(this: &DateTimeFormatOptions, value: u8);
11396
11397 #[wasm_bindgen(method, getter = timeZoneName)]
11398 pub fn get_time_zone_name(this: &DateTimeFormatOptions) -> Option<TimeZoneNameFormat>;
11399 #[wasm_bindgen(method, setter = timeZoneName)]
11400 pub fn set_time_zone_name(this: &DateTimeFormatOptions, value: TimeZoneNameFormat);
11401
11402 #[wasm_bindgen(method, getter = dayPeriod)]
11403 pub fn get_day_period(this: &DateTimeFormatOptions) -> Option<DayPeriodFormat>;
11404 #[wasm_bindgen(method, setter = dayPeriod)]
11405 pub fn set_day_period(this: &DateTimeFormatOptions, value: DayPeriodFormat);
11406 }
11407
11408 impl DateTimeFormatOptions {
11409 pub fn new() -> DateTimeFormatOptions {
11410 JsCast::unchecked_into(Object::new())
11411 }
11412 }
11413
11414 impl Default for DateTimeFormatOptions {
11415 fn default() -> Self {
11416 DateTimeFormatOptions::new()
11417 }
11418 }
11419
11420 // Intl.ResolvedDateTimeFormatOptions
11421 #[wasm_bindgen]
11422 extern "C" {
11423 /// Resolved options returned by `Intl.DateTimeFormat.prototype.resolvedOptions()`.
11424 ///
11425 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions)
11426 #[wasm_bindgen(extends = DateTimeFormatOptions)]
11427 #[derive(Clone, Debug)]
11428 pub type ResolvedDateTimeFormatOptions;
11429
11430 /// The resolved locale string.
11431 #[wasm_bindgen(method, getter = locale)]
11432 pub fn get_locale(this: &ResolvedDateTimeFormatOptions) -> JsString;
11433 }
11434
11435 // Intl.DateTimeFormatPart
11436 #[wasm_bindgen]
11437 extern "C" {
11438 /// A part of the formatted date returned by `formatToParts()`.
11439 ///
11440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
11441 #[wasm_bindgen(extends = Object)]
11442 #[derive(Clone, Debug)]
11443 pub type DateTimeFormatPart;
11444
11445 /// The type of the part (e.g., "day", "month", "year", "literal", etc.)
11446 #[wasm_bindgen(method, getter = type)]
11447 pub fn type_(this: &DateTimeFormatPart) -> DateTimeFormatPartType;
11448
11449 /// The value of the part.
11450 #[wasm_bindgen(method, getter)]
11451 pub fn value(this: &DateTimeFormatPart) -> JsString;
11452 }
11453
11454 // Intl.DateTimeRangeFormatPart
11455 #[wasm_bindgen]
11456 extern "C" {
11457 /// A part of the formatted date range returned by `formatRangeToParts()`.
11458 ///
11459 /// Extends `DateTimeFormatPart` with a `source` property indicating whether
11460 /// the part is from the start date, end date, or shared between them.
11461 ///
11462 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
11463 #[wasm_bindgen(extends = DateTimeFormatPart)]
11464 #[derive(Clone, Debug)]
11465 pub type DateTimeRangeFormatPart;
11466
11467 /// The source of the part: "startRange", "endRange", or "shared".
11468 #[wasm_bindgen(method, getter)]
11469 pub fn source(this: &DateTimeRangeFormatPart) -> RangeSource;
11470 }
11471
11472 // Intl.DateTimeFormat
11473 #[wasm_bindgen]
11474 extern "C" {
11475 /// The `Intl.DateTimeFormat` object is a constructor for objects
11476 /// that enable language-sensitive date and time formatting.
11477 ///
11478 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
11479 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
11480 #[derive(Clone, Debug)]
11481 pub type DateTimeFormat;
11482
11483 /// The `Intl.DateTimeFormat` object is a constructor for objects
11484 /// that enable language-sensitive date and time formatting.
11485 ///
11486 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
11487 #[cfg(not(js_sys_unstable_apis))]
11488 #[wasm_bindgen(constructor, js_namespace = Intl)]
11489 pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
11490
11491 /// The `Intl.DateTimeFormat` object is a constructor for objects
11492 /// that enable language-sensitive date and time formatting.
11493 ///
11494 /// Throws a `RangeError` if locales contain invalid values.
11495 ///
11496 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
11497 #[cfg(js_sys_unstable_apis)]
11498 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11499 pub fn new(
11500 locales: &[JsString],
11501 options: &DateTimeFormatOptions,
11502 ) -> Result<DateTimeFormat, JsValue>;
11503
11504 /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
11505 /// formats a date according to the locale and formatting options of this
11506 /// Intl.DateTimeFormat object.
11507 ///
11508 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
11509 #[cfg(not(js_sys_unstable_apis))]
11510 #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
11511 pub fn format(this: &DateTimeFormat) -> Function;
11512
11513 /// Formats a date according to the locale and formatting options of this
11514 /// `Intl.DateTimeFormat` object.
11515 ///
11516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format)
11517 #[cfg(js_sys_unstable_apis)]
11518 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat")]
11519 pub fn format(this: &DateTimeFormat, date: &Date) -> JsString;
11520
11521 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
11522 /// formatting of strings produced by DateTimeFormat formatters.
11523 ///
11524 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
11525 #[cfg(not(js_sys_unstable_apis))]
11526 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
11527 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
11528
11529 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
11530 /// formatting of strings produced by DateTimeFormat formatters.
11531 ///
11532 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
11533 #[cfg(js_sys_unstable_apis)]
11534 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
11535 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array<DateTimeFormatPart>;
11536
11537 /// The `Intl.DateTimeFormat.prototype.formatRange()` method formats a date range
11538 /// in the most concise way based on the locales and options provided when
11539 /// instantiating this `Intl.DateTimeFormat` object.
11540 ///
11541 /// Throws a `TypeError` if the dates are invalid.
11542 ///
11543 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange)
11544 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRange, catch)]
11545 pub fn format_range(
11546 this: &DateTimeFormat,
11547 start_date: &Date,
11548 end_date: &Date,
11549 ) -> Result<JsString, JsValue>;
11550
11551 /// The `Intl.DateTimeFormat.prototype.formatRangeToParts()` method returns an array
11552 /// of locale-specific tokens representing each part of the formatted date range
11553 /// produced by `Intl.DateTimeFormat` formatters.
11554 ///
11555 /// Throws a `TypeError` if the dates are invalid.
11556 ///
11557 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
11558 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRangeToParts, catch)]
11559 pub fn format_range_to_parts(
11560 this: &DateTimeFormat,
11561 start_date: &Date,
11562 end_date: &Date,
11563 ) -> Result<Array<DateTimeRangeFormatPart>, JsValue>;
11564
11565 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
11566 /// object with properties reflecting the locale and date and time formatting
11567 /// options computed during initialization of this DateTimeFormat object.
11568 ///
11569 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
11570 #[cfg(not(js_sys_unstable_apis))]
11571 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11572 pub fn resolved_options(this: &DateTimeFormat) -> Object;
11573
11574 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
11575 /// object with properties reflecting the locale and date and time formatting
11576 /// options computed during initialization of this DateTimeFormat object.
11577 ///
11578 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
11579 #[cfg(js_sys_unstable_apis)]
11580 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11581 pub fn resolved_options(this: &DateTimeFormat) -> ResolvedDateTimeFormatOptions;
11582
11583 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
11584 /// containing those of the provided locales that are supported in date
11585 /// and time formatting without having to fall back to the runtime's default
11586 /// locale.
11587 ///
11588 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
11589 #[cfg(not(js_sys_unstable_apis))]
11590 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11591 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11592
11593 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
11594 /// containing those of the provided locales that are supported in date
11595 /// and time formatting without having to fall back to the runtime's default
11596 /// locale.
11597 ///
11598 /// Throws a `RangeError` if locales contain invalid values.
11599 ///
11600 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
11601 #[cfg(js_sys_unstable_apis)]
11602 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11603 pub fn supported_locales_of(
11604 locales: &[JsString],
11605 options: &LocaleMatcherOptions,
11606 ) -> Result<Array<JsString>, JsValue>;
11607 }
11608
11609 #[cfg(not(js_sys_unstable_apis))]
11610 impl Default for DateTimeFormat {
11611 fn default() -> Self {
11612 Self::new(
11613 &JsValue::UNDEFINED.unchecked_into(),
11614 &JsValue::UNDEFINED.unchecked_into(),
11615 )
11616 }
11617 }
11618
11619 #[cfg(js_sys_unstable_apis)]
11620 impl Default for DateTimeFormat {
11621 fn default() -> Self {
11622 Self::new(&[], &Default::default()).unwrap()
11623 }
11624 }
11625
11626 // Intl.NumberFormatOptions
11627 #[wasm_bindgen]
11628 extern "C" {
11629 /// Options for `Intl.NumberFormat` constructor.
11630 ///
11631 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options)
11632 #[wasm_bindgen(extends = Object)]
11633 #[derive(Clone, Debug)]
11634 pub type NumberFormatOptions;
11635
11636 // Locale matching
11637 #[wasm_bindgen(method, getter = localeMatcher)]
11638 pub fn get_locale_matcher(this: &NumberFormatOptions) -> Option<LocaleMatcher>;
11639 #[wasm_bindgen(method, setter = localeMatcher)]
11640 pub fn set_locale_matcher(this: &NumberFormatOptions, value: LocaleMatcher);
11641
11642 // Numbering system (free-form string)
11643 #[wasm_bindgen(method, getter = numberingSystem)]
11644 pub fn get_numbering_system(this: &NumberFormatOptions) -> Option<JsString>;
11645 #[wasm_bindgen(method, setter = numberingSystem)]
11646 pub fn set_numbering_system(this: &NumberFormatOptions, value: &str);
11647
11648 // Style
11649 #[wasm_bindgen(method, getter = style)]
11650 pub fn get_style(this: &NumberFormatOptions) -> Option<NumberFormatStyle>;
11651 #[wasm_bindgen(method, setter = style)]
11652 pub fn set_style(this: &NumberFormatOptions, value: NumberFormatStyle);
11653
11654 // Currency options (currency code is free-form ISO 4217 string)
11655 #[wasm_bindgen(method, getter = currency)]
11656 pub fn get_currency(this: &NumberFormatOptions) -> Option<JsString>;
11657 #[wasm_bindgen(method, setter = currency)]
11658 pub fn set_currency(this: &NumberFormatOptions, value: &str);
11659
11660 #[wasm_bindgen(method, getter = currencyDisplay)]
11661 pub fn get_currency_display(this: &NumberFormatOptions) -> Option<CurrencyDisplay>;
11662 #[wasm_bindgen(method, setter = currencyDisplay)]
11663 pub fn set_currency_display(this: &NumberFormatOptions, value: CurrencyDisplay);
11664
11665 #[wasm_bindgen(method, getter = currencySign)]
11666 pub fn get_currency_sign(this: &NumberFormatOptions) -> Option<CurrencySign>;
11667 #[wasm_bindgen(method, setter = currencySign)]
11668 pub fn set_currency_sign(this: &NumberFormatOptions, value: CurrencySign);
11669
11670 // Unit options (unit name is free-form string)
11671 #[wasm_bindgen(method, getter = unit)]
11672 pub fn get_unit(this: &NumberFormatOptions) -> Option<JsString>;
11673 #[wasm_bindgen(method, setter = unit)]
11674 pub fn set_unit(this: &NumberFormatOptions, value: &str);
11675
11676 #[wasm_bindgen(method, getter = unitDisplay)]
11677 pub fn get_unit_display(this: &NumberFormatOptions) -> Option<UnitDisplay>;
11678 #[wasm_bindgen(method, setter = unitDisplay)]
11679 pub fn set_unit_display(this: &NumberFormatOptions, value: UnitDisplay);
11680
11681 // Notation
11682 #[wasm_bindgen(method, getter = notation)]
11683 pub fn get_notation(this: &NumberFormatOptions) -> Option<NumberFormatNotation>;
11684 #[wasm_bindgen(method, setter = notation)]
11685 pub fn set_notation(this: &NumberFormatOptions, value: NumberFormatNotation);
11686
11687 #[wasm_bindgen(method, getter = compactDisplay)]
11688 pub fn get_compact_display(this: &NumberFormatOptions) -> Option<CompactDisplay>;
11689 #[wasm_bindgen(method, setter = compactDisplay)]
11690 pub fn set_compact_display(this: &NumberFormatOptions, value: CompactDisplay);
11691
11692 // Sign display
11693 #[wasm_bindgen(method, getter = signDisplay)]
11694 pub fn get_sign_display(this: &NumberFormatOptions) -> Option<SignDisplay>;
11695 #[wasm_bindgen(method, setter = signDisplay)]
11696 pub fn set_sign_display(this: &NumberFormatOptions, value: SignDisplay);
11697
11698 // Digit options
11699 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11700 pub fn get_minimum_integer_digits(this: &NumberFormatOptions) -> Option<u8>;
11701 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11702 pub fn set_minimum_integer_digits(this: &NumberFormatOptions, value: u8);
11703
11704 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11705 pub fn get_minimum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11706 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11707 pub fn set_minimum_fraction_digits(this: &NumberFormatOptions, value: u8);
11708
11709 #[wasm_bindgen(method, getter = maximumFractionDigits)]
11710 pub fn get_maximum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11711 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11712 pub fn set_maximum_fraction_digits(this: &NumberFormatOptions, value: u8);
11713
11714 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11715 pub fn get_minimum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11716 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11717 pub fn set_minimum_significant_digits(this: &NumberFormatOptions, value: u8);
11718
11719 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11720 pub fn get_maximum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11721 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11722 pub fn set_maximum_significant_digits(this: &NumberFormatOptions, value: u8);
11723
11724 // Grouping
11725 #[wasm_bindgen(method, getter = useGrouping)]
11726 pub fn get_use_grouping(this: &NumberFormatOptions) -> Option<UseGrouping>;
11727 #[wasm_bindgen(method, setter = useGrouping)]
11728 pub fn set_use_grouping(this: &NumberFormatOptions, value: UseGrouping);
11729
11730 // Rounding
11731 #[wasm_bindgen(method, getter = roundingMode)]
11732 pub fn get_rounding_mode(this: &NumberFormatOptions) -> Option<RoundingMode>;
11733 #[wasm_bindgen(method, setter = roundingMode)]
11734 pub fn set_rounding_mode(this: &NumberFormatOptions, value: RoundingMode);
11735
11736 #[wasm_bindgen(method, getter = roundingPriority)]
11737 pub fn get_rounding_priority(this: &NumberFormatOptions) -> Option<RoundingPriority>;
11738 #[wasm_bindgen(method, setter = roundingPriority)]
11739 pub fn set_rounding_priority(this: &NumberFormatOptions, value: RoundingPriority);
11740
11741 #[wasm_bindgen(method, getter = roundingIncrement)]
11742 pub fn get_rounding_increment(this: &NumberFormatOptions) -> Option<u32>;
11743 #[wasm_bindgen(method, setter = roundingIncrement)]
11744 pub fn set_rounding_increment(this: &NumberFormatOptions, value: u32);
11745
11746 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11747 pub fn get_trailing_zero_display(this: &NumberFormatOptions)
11748 -> Option<TrailingZeroDisplay>;
11749 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11750 pub fn set_trailing_zero_display(this: &NumberFormatOptions, value: TrailingZeroDisplay);
11751 }
11752
11753 impl NumberFormatOptions {
11754 pub fn new() -> NumberFormatOptions {
11755 JsCast::unchecked_into(Object::new())
11756 }
11757 }
11758
11759 impl Default for NumberFormatOptions {
11760 fn default() -> Self {
11761 NumberFormatOptions::new()
11762 }
11763 }
11764
11765 // Intl.ResolvedNumberFormatOptions
11766 #[wasm_bindgen]
11767 extern "C" {
11768 /// Resolved options returned by `Intl.NumberFormat.prototype.resolvedOptions()`.
11769 ///
11770 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions)
11771 #[wasm_bindgen(extends = NumberFormatOptions)]
11772 #[derive(Clone, Debug)]
11773 pub type ResolvedNumberFormatOptions;
11774
11775 /// The resolved locale string.
11776 #[wasm_bindgen(method, getter = locale)]
11777 pub fn get_locale(this: &ResolvedNumberFormatOptions) -> JsString;
11778 }
11779
11780 // Intl.NumberFormatPart
11781 #[wasm_bindgen]
11782 extern "C" {
11783 /// A part of the formatted number returned by `formatToParts()`.
11784 ///
11785 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11786 #[wasm_bindgen(extends = Object)]
11787 #[derive(Clone, Debug)]
11788 pub type NumberFormatPart;
11789
11790 /// The type of the part (e.g., "integer", "decimal", "fraction", "currency", etc.)
11791 #[wasm_bindgen(method, getter = type)]
11792 pub fn type_(this: &NumberFormatPart) -> NumberFormatPartType;
11793
11794 /// The value of the part.
11795 #[wasm_bindgen(method, getter)]
11796 pub fn value(this: &NumberFormatPart) -> JsString;
11797 }
11798
11799 // Intl.NumberRangeFormatPart
11800 #[wasm_bindgen]
11801 extern "C" {
11802 /// A part of the formatted number range returned by `formatRangeToParts()`.
11803 ///
11804 /// Extends `NumberFormatPart` with a `source` property indicating whether
11805 /// the part is from the start number, end number, or shared between them.
11806 ///
11807 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11808 #[wasm_bindgen(extends = NumberFormatPart)]
11809 #[derive(Clone, Debug)]
11810 pub type NumberRangeFormatPart;
11811
11812 /// The source of the part: "startRange", "endRange", or "shared".
11813 #[wasm_bindgen(method, getter)]
11814 pub fn source(this: &NumberRangeFormatPart) -> RangeSource;
11815 }
11816
11817 // Intl.NumberFormat
11818 #[wasm_bindgen]
11819 extern "C" {
11820 /// The `Intl.NumberFormat` object is a constructor for objects
11821 /// that enable language sensitive number formatting.
11822 ///
11823 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11824 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
11825 #[derive(Clone, Debug)]
11826 pub type NumberFormat;
11827
11828 /// The `Intl.NumberFormat` object is a constructor for objects
11829 /// that enable language sensitive number formatting.
11830 ///
11831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11832 #[cfg(not(js_sys_unstable_apis))]
11833 #[wasm_bindgen(constructor, js_namespace = Intl)]
11834 pub fn new(locales: &Array, options: &Object) -> NumberFormat;
11835
11836 /// The `Intl.NumberFormat` object is a constructor for objects
11837 /// that enable language sensitive number formatting.
11838 ///
11839 /// Throws a `RangeError` if locales contain invalid values.
11840 ///
11841 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11842 #[cfg(js_sys_unstable_apis)]
11843 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11844 pub fn new(
11845 locales: &[JsString],
11846 options: &NumberFormatOptions,
11847 ) -> Result<NumberFormat, JsValue>;
11848
11849 /// The Intl.NumberFormat.prototype.format property returns a getter function that
11850 /// formats a number according to the locale and formatting options of this
11851 /// NumberFormat object.
11852 ///
11853 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
11854 #[cfg(not(js_sys_unstable_apis))]
11855 #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
11856 pub fn format(this: &NumberFormat) -> Function;
11857
11858 /// Formats a number according to the locale and formatting options of this
11859 /// `Intl.NumberFormat` object.
11860 ///
11861 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11862 /// or use E notation: `"1000000E-6"` → `"1"`).
11863 ///
11864 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format)
11865 #[cfg(js_sys_unstable_apis)]
11866 #[wasm_bindgen(method, js_class = "Intl.NumberFormat")]
11867 pub fn format(this: &NumberFormat, value: &JsString) -> JsString;
11868
11869 /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
11870 /// formatting of strings produced by NumberTimeFormat formatters.
11871 ///
11872 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
11873 #[cfg(not(js_sys_unstable_apis))]
11874 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11875 pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
11876
11877 /// The `Intl.NumberFormat.prototype.formatToParts()` method allows locale-aware
11878 /// formatting of strings produced by `Intl.NumberFormat` formatters.
11879 ///
11880 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11881 /// or use E notation: `"1000000E-6"` → `"1"`).
11882 ///
11883 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11884 #[cfg(js_sys_unstable_apis)]
11885 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11886 pub fn format_to_parts(this: &NumberFormat, value: &JsString) -> Array<NumberFormatPart>;
11887
11888 /// Formats a range of numbers according to the locale and formatting options
11889 /// of this `Intl.NumberFormat` object.
11890 ///
11891 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11892 /// or use E notation: `"1000000E-6"` → `"1"`).
11893 ///
11894 /// Throws a `TypeError` if the values are invalid.
11895 ///
11896 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange)
11897 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRange, catch)]
11898 pub fn format_range(
11899 this: &NumberFormat,
11900 start: &JsString,
11901 end: &JsString,
11902 ) -> Result<JsString, JsValue>;
11903
11904 /// Returns an array of locale-specific tokens representing each part of
11905 /// the formatted number range.
11906 ///
11907 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11908 /// or use E notation: `"1000000E-6"` → `"1"`).
11909 ///
11910 /// Throws a `TypeError` if the values are invalid.
11911 ///
11912 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11913 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRangeToParts, catch)]
11914 pub fn format_range_to_parts(
11915 this: &NumberFormat,
11916 start: &JsString,
11917 end: &JsString,
11918 ) -> Result<Array<NumberRangeFormatPart>, JsValue>;
11919
11920 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11921 /// object with properties reflecting the locale and number formatting
11922 /// options computed during initialization of this NumberFormat object.
11923 ///
11924 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11925 #[cfg(not(js_sys_unstable_apis))]
11926 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11927 pub fn resolved_options(this: &NumberFormat) -> Object;
11928
11929 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11930 /// object with properties reflecting the locale and number formatting
11931 /// options computed during initialization of this NumberFormat object.
11932 ///
11933 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11934 #[cfg(js_sys_unstable_apis)]
11935 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11936 pub fn resolved_options(this: &NumberFormat) -> ResolvedNumberFormatOptions;
11937
11938 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11939 /// containing those of the provided locales that are supported in number
11940 /// formatting without having to fall back to the runtime's default locale.
11941 ///
11942 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11943 #[cfg(not(js_sys_unstable_apis))]
11944 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11945 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11946
11947 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11948 /// containing those of the provided locales that are supported in number
11949 /// formatting without having to fall back to the runtime's default locale.
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/NumberFormat/supportedLocalesOf)
11954 #[cfg(js_sys_unstable_apis)]
11955 #[wasm_bindgen(static_method_of = NumberFormat, 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 NumberFormat {
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 NumberFormat {
11974 fn default() -> Self {
11975 Self::new(&[], &Default::default()).unwrap()
11976 }
11977 }
11978
11979 // Intl.PluralRulesOptions
11980 #[wasm_bindgen]
11981 extern "C" {
11982 /// Options for `Intl.PluralRules` constructor.
11983 ///
11984 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#options)
11985 #[wasm_bindgen(extends = Object)]
11986 #[derive(Clone, Debug)]
11987 pub type PluralRulesOptions;
11988
11989 #[wasm_bindgen(method, getter = localeMatcher)]
11990 pub fn get_locale_matcher(this: &PluralRulesOptions) -> Option<LocaleMatcher>;
11991 #[wasm_bindgen(method, setter = localeMatcher)]
11992 pub fn set_locale_matcher(this: &PluralRulesOptions, value: LocaleMatcher);
11993
11994 #[wasm_bindgen(method, getter = type)]
11995 pub fn get_type(this: &PluralRulesOptions) -> Option<PluralRulesType>;
11996 #[wasm_bindgen(method, setter = type)]
11997 pub fn set_type(this: &PluralRulesOptions, value: PluralRulesType);
11998
11999 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
12000 pub fn get_minimum_integer_digits(this: &PluralRulesOptions) -> Option<u8>;
12001 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
12002 pub fn set_minimum_integer_digits(this: &PluralRulesOptions, value: u8);
12003
12004 #[wasm_bindgen(method, getter = minimumFractionDigits)]
12005 pub fn get_minimum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
12006 #[wasm_bindgen(method, setter = minimumFractionDigits)]
12007 pub fn set_minimum_fraction_digits(this: &PluralRulesOptions, value: u8);
12008
12009 #[wasm_bindgen(method, getter = maximumFractionDigits)]
12010 pub fn get_maximum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
12011 #[wasm_bindgen(method, setter = maximumFractionDigits)]
12012 pub fn set_maximum_fraction_digits(this: &PluralRulesOptions, value: u8);
12013
12014 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
12015 pub fn get_minimum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
12016 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
12017 pub fn set_minimum_significant_digits(this: &PluralRulesOptions, value: u8);
12018
12019 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
12020 pub fn get_maximum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
12021 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
12022 pub fn set_maximum_significant_digits(this: &PluralRulesOptions, value: u8);
12023
12024 #[wasm_bindgen(method, getter = roundingPriority)]
12025 pub fn get_rounding_priority(this: &PluralRulesOptions) -> Option<RoundingPriority>;
12026 #[wasm_bindgen(method, setter = roundingPriority)]
12027 pub fn set_rounding_priority(this: &PluralRulesOptions, value: RoundingPriority);
12028
12029 #[wasm_bindgen(method, getter = roundingIncrement)]
12030 pub fn get_rounding_increment(this: &PluralRulesOptions) -> Option<u32>;
12031 #[wasm_bindgen(method, setter = roundingIncrement)]
12032 pub fn set_rounding_increment(this: &PluralRulesOptions, value: u32);
12033
12034 #[wasm_bindgen(method, getter = roundingMode)]
12035 pub fn get_rounding_mode(this: &PluralRulesOptions) -> Option<RoundingMode>;
12036 #[wasm_bindgen(method, setter = roundingMode)]
12037 pub fn set_rounding_mode(this: &PluralRulesOptions, value: RoundingMode);
12038
12039 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
12040 pub fn get_trailing_zero_display(this: &PluralRulesOptions) -> Option<TrailingZeroDisplay>;
12041 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
12042 pub fn set_trailing_zero_display(this: &PluralRulesOptions, value: TrailingZeroDisplay);
12043 }
12044
12045 impl PluralRulesOptions {
12046 pub fn new() -> PluralRulesOptions {
12047 JsCast::unchecked_into(Object::new())
12048 }
12049 }
12050
12051 impl Default for PluralRulesOptions {
12052 fn default() -> Self {
12053 PluralRulesOptions::new()
12054 }
12055 }
12056
12057 // Intl.ResolvedPluralRulesOptions
12058 #[wasm_bindgen]
12059 extern "C" {
12060 /// Resolved options returned by `Intl.PluralRules.prototype.resolvedOptions()`.
12061 ///
12062 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/resolvedOptions)
12063 #[wasm_bindgen(extends = PluralRulesOptions)]
12064 #[derive(Clone, Debug)]
12065 pub type ResolvedPluralRulesOptions;
12066
12067 /// The resolved locale string.
12068 #[wasm_bindgen(method, getter = locale)]
12069 pub fn get_locale(this: &ResolvedPluralRulesOptions) -> JsString;
12070
12071 /// The plural categories used by the locale.
12072 #[wasm_bindgen(method, getter = pluralCategories)]
12073 pub fn get_plural_categories(this: &ResolvedPluralRulesOptions) -> Array<JsString>;
12074 }
12075
12076 // Intl.PluralRules
12077 #[wasm_bindgen]
12078 extern "C" {
12079 /// The `Intl.PluralRules` object is a constructor for objects
12080 /// that enable plural sensitive formatting and plural language rules.
12081 ///
12082 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
12083 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
12084 #[derive(Clone, Debug)]
12085 pub type PluralRules;
12086
12087 /// The `Intl.PluralRules` object is a constructor for objects
12088 /// that enable plural sensitive formatting and plural language rules.
12089 ///
12090 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
12091 #[cfg(not(js_sys_unstable_apis))]
12092 #[wasm_bindgen(constructor, js_namespace = Intl)]
12093 pub fn new(locales: &Array, options: &Object) -> PluralRules;
12094
12095 /// The `Intl.PluralRules` object is a constructor for objects
12096 /// that enable plural sensitive formatting and plural language rules.
12097 ///
12098 /// Throws a `RangeError` if locales contain invalid values.
12099 ///
12100 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
12101 #[cfg(js_sys_unstable_apis)]
12102 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12103 pub fn new(
12104 locales: &[JsString],
12105 options: &PluralRulesOptions,
12106 ) -> Result<PluralRules, JsValue>;
12107
12108 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
12109 /// object with properties reflecting the locale and plural formatting
12110 /// options computed during initialization of this PluralRules object.
12111 ///
12112 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
12113 #[cfg(not(js_sys_unstable_apis))]
12114 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12115 pub fn resolved_options(this: &PluralRules) -> Object;
12116
12117 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
12118 /// object with properties reflecting the locale and plural formatting
12119 /// options computed during initialization of this PluralRules object.
12120 ///
12121 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
12122 #[cfg(js_sys_unstable_apis)]
12123 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12124 pub fn resolved_options(this: &PluralRules) -> ResolvedPluralRulesOptions;
12125
12126 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
12127 /// which plural rule to use for locale-aware formatting.
12128 ///
12129 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
12130 #[cfg(not(js_sys_unstable_apis))]
12131 #[wasm_bindgen(method, js_namespace = Intl)]
12132 pub fn select(this: &PluralRules, number: f64) -> JsString;
12133
12134 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
12135 /// which plural rule to use for locale-aware formatting.
12136 ///
12137 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
12138 #[cfg(js_sys_unstable_apis)]
12139 #[wasm_bindgen(method, js_namespace = Intl)]
12140 pub fn select(this: &PluralRules, number: f64) -> PluralCategory;
12141
12142 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
12143 /// which plural rule to use for locale-aware formatting of a range of numbers.
12144 ///
12145 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
12146 #[cfg(not(js_sys_unstable_apis))]
12147 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
12148 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> JsString;
12149
12150 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
12151 /// which plural rule to use for locale-aware formatting of a range of numbers.
12152 ///
12153 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
12154 #[cfg(js_sys_unstable_apis)]
12155 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
12156 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> PluralCategory;
12157
12158 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
12159 /// containing those of the provided locales that are supported in plural
12160 /// formatting without having to fall back to the runtime's default locale.
12161 ///
12162 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
12163 #[cfg(not(js_sys_unstable_apis))]
12164 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
12165 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12166
12167 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
12168 /// containing those of the provided locales that are supported in plural
12169 /// formatting without having to fall back to the runtime's default locale.
12170 ///
12171 /// Throws a `RangeError` if locales contain invalid values.
12172 ///
12173 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
12174 #[cfg(js_sys_unstable_apis)]
12175 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12176 pub fn supported_locales_of(
12177 locales: &[JsString],
12178 options: &LocaleMatcherOptions,
12179 ) -> Result<Array<JsString>, JsValue>;
12180 }
12181
12182 #[cfg(not(js_sys_unstable_apis))]
12183 impl Default for PluralRules {
12184 fn default() -> Self {
12185 Self::new(
12186 &JsValue::UNDEFINED.unchecked_into(),
12187 &JsValue::UNDEFINED.unchecked_into(),
12188 )
12189 }
12190 }
12191
12192 #[cfg(js_sys_unstable_apis)]
12193 impl Default for PluralRules {
12194 fn default() -> Self {
12195 Self::new(&[], &Default::default()).unwrap()
12196 }
12197 }
12198
12199 // Intl.RelativeTimeFormat
12200 #[wasm_bindgen]
12201 extern "C" {
12202 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
12203 /// that enable language-sensitive relative time formatting.
12204 ///
12205 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
12206 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
12207 #[derive(Clone, Debug)]
12208 pub type RelativeTimeFormat;
12209
12210 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
12211 /// that enable language-sensitive relative time formatting.
12212 ///
12213 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
12214 #[cfg(not(js_sys_unstable_apis))]
12215 #[wasm_bindgen(constructor, js_namespace = Intl)]
12216 pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
12217
12218 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
12219 /// that enable language-sensitive relative time formatting.
12220 ///
12221 /// Throws a `RangeError` if locales contain invalid values.
12222 ///
12223 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
12224 #[cfg(js_sys_unstable_apis)]
12225 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12226 pub fn new(locales: &[JsString]) -> Result<RelativeTimeFormat, JsValue>;
12227
12228 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
12229 /// that enable language-sensitive relative time formatting.
12230 ///
12231 /// Throws a `RangeError` if locales or options contain invalid values.
12232 ///
12233 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
12234 #[cfg(js_sys_unstable_apis)]
12235 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12236 pub fn new_with_options(
12237 locales: &[JsString],
12238 options: &RelativeTimeFormatOptions,
12239 ) -> Result<RelativeTimeFormat, JsValue>;
12240
12241 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
12242 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
12243 ///
12244 /// Throws a `RangeError` if unit is invalid.
12245 ///
12246 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
12247 #[cfg(not(js_sys_unstable_apis))]
12248 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
12249 pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
12250
12251 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
12252 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
12253 ///
12254 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
12255 #[cfg(js_sys_unstable_apis)]
12256 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
12257 pub fn format(
12258 this: &RelativeTimeFormat,
12259 value: f64,
12260 unit: RelativeTimeFormatUnit,
12261 ) -> JsString;
12262
12263 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
12264 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
12265 ///
12266 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
12267 #[cfg(not(js_sys_unstable_apis))]
12268 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
12269 pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
12270
12271 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
12272 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
12273 ///
12274 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
12275 #[cfg(js_sys_unstable_apis)]
12276 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
12277 pub fn format_to_parts(
12278 this: &RelativeTimeFormat,
12279 value: f64,
12280 unit: RelativeTimeFormatUnit,
12281 ) -> Array<RelativeTimeFormatPart>;
12282
12283 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
12284 /// object with properties reflecting the locale and relative time formatting
12285 /// options computed during initialization of this RelativeTimeFormat object.
12286 ///
12287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
12288 #[cfg(not(js_sys_unstable_apis))]
12289 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12290 pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
12291
12292 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
12293 /// object with properties reflecting the locale and relative time formatting
12294 /// options computed during initialization of this RelativeTimeFormat object.
12295 ///
12296 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
12297 #[cfg(js_sys_unstable_apis)]
12298 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12299 pub fn resolved_options(this: &RelativeTimeFormat) -> ResolvedRelativeTimeFormatOptions;
12300
12301 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
12302 /// containing those of the provided locales that are supported in date and time
12303 /// formatting without having to fall back to the runtime's default locale.
12304 ///
12305 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
12306 #[cfg(not(js_sys_unstable_apis))]
12307 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
12308 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12309
12310 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
12311 /// containing those of the provided locales that are supported in date and time
12312 /// formatting without having to fall back to the runtime's default locale.
12313 ///
12314 /// Throws a `RangeError` if locales contain invalid values.
12315 ///
12316 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
12317 #[cfg(js_sys_unstable_apis)]
12318 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12319 pub fn supported_locales_of(
12320 locales: &[JsString],
12321 options: &LocaleMatcherOptions,
12322 ) -> Result<Array<JsString>, JsValue>;
12323 }
12324
12325 #[cfg(not(js_sys_unstable_apis))]
12326 impl Default for RelativeTimeFormat {
12327 fn default() -> Self {
12328 Self::new(
12329 &JsValue::UNDEFINED.unchecked_into(),
12330 &JsValue::UNDEFINED.unchecked_into(),
12331 )
12332 }
12333 }
12334
12335 #[cfg(js_sys_unstable_apis)]
12336 impl Default for RelativeTimeFormat {
12337 fn default() -> Self {
12338 Self::new(&[]).unwrap()
12339 }
12340 }
12341
12342 // Intl.ListFormatOptions
12343 #[wasm_bindgen]
12344 extern "C" {
12345 /// Options for `Intl.ListFormat` constructor.
12346 ///
12347 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#options)
12348 #[wasm_bindgen(extends = Object)]
12349 #[derive(Clone, Debug)]
12350 pub type ListFormatOptions;
12351
12352 #[wasm_bindgen(method, getter = localeMatcher)]
12353 pub fn get_locale_matcher(this: &ListFormatOptions) -> Option<LocaleMatcher>;
12354 #[wasm_bindgen(method, setter = localeMatcher)]
12355 pub fn set_locale_matcher(this: &ListFormatOptions, value: LocaleMatcher);
12356
12357 #[wasm_bindgen(method, getter = type)]
12358 pub fn get_type(this: &ListFormatOptions) -> Option<ListFormatType>;
12359 #[wasm_bindgen(method, setter = type)]
12360 pub fn set_type(this: &ListFormatOptions, value: ListFormatType);
12361
12362 #[wasm_bindgen(method, getter = style)]
12363 pub fn get_style(this: &ListFormatOptions) -> Option<ListFormatStyle>;
12364 #[wasm_bindgen(method, setter = style)]
12365 pub fn set_style(this: &ListFormatOptions, value: ListFormatStyle);
12366 }
12367
12368 impl ListFormatOptions {
12369 pub fn new() -> ListFormatOptions {
12370 JsCast::unchecked_into(Object::new())
12371 }
12372 }
12373
12374 impl Default for ListFormatOptions {
12375 fn default() -> Self {
12376 ListFormatOptions::new()
12377 }
12378 }
12379
12380 // Intl.ResolvedListFormatOptions
12381 #[wasm_bindgen]
12382 extern "C" {
12383 /// Resolved options returned by `Intl.ListFormat.prototype.resolvedOptions()`.
12384 ///
12385 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
12386 #[wasm_bindgen(extends = ListFormatOptions)]
12387 #[derive(Clone, Debug)]
12388 pub type ResolvedListFormatOptions;
12389
12390 /// The resolved locale string.
12391 #[wasm_bindgen(method, getter = locale)]
12392 pub fn get_locale(this: &ResolvedListFormatOptions) -> JsString;
12393 }
12394
12395 // Intl.ListFormatPart
12396 #[wasm_bindgen]
12397 extern "C" {
12398 /// A part of the formatted list returned by `formatToParts()`.
12399 ///
12400 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
12401 #[wasm_bindgen(extends = Object)]
12402 #[derive(Clone, Debug)]
12403 pub type ListFormatPart;
12404
12405 /// The type of the part ("element" or "literal").
12406 #[wasm_bindgen(method, getter = type)]
12407 pub fn type_(this: &ListFormatPart) -> ListFormatPartType;
12408
12409 /// The value of the part.
12410 #[wasm_bindgen(method, getter)]
12411 pub fn value(this: &ListFormatPart) -> JsString;
12412 }
12413
12414 // Intl.ListFormat
12415 #[wasm_bindgen]
12416 extern "C" {
12417 /// The `Intl.ListFormat` object enables language-sensitive list formatting.
12418 ///
12419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat)
12420 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.ListFormat")]
12421 #[derive(Clone, Debug)]
12422 pub type ListFormat;
12423
12424 /// Creates a new `Intl.ListFormat` object.
12425 ///
12426 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
12427 #[cfg(not(js_sys_unstable_apis))]
12428 #[wasm_bindgen(constructor, js_namespace = Intl)]
12429 pub fn new(locales: &Array, options: &Object) -> ListFormat;
12430
12431 /// Creates a new `Intl.ListFormat` object.
12432 ///
12433 /// Throws a `RangeError` if locales or options contain invalid values.
12434 ///
12435 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
12436 #[cfg(js_sys_unstable_apis)]
12437 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12438 pub fn new(
12439 locales: &[JsString],
12440 options: &ListFormatOptions,
12441 ) -> Result<ListFormat, JsValue>;
12442
12443 /// Formats a list of strings according to the locale and options.
12444 ///
12445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
12446 #[cfg(not(js_sys_unstable_apis))]
12447 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
12448 pub fn format(this: &ListFormat, list: &Array) -> JsString;
12449
12450 /// Formats a list of strings according to the locale and options.
12451 ///
12452 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
12453 #[cfg(js_sys_unstable_apis)]
12454 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
12455 pub fn format(this: &ListFormat, list: &[JsString]) -> JsString;
12456
12457 /// Returns an array of objects representing the list in parts.
12458 ///
12459 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
12460 #[cfg(not(js_sys_unstable_apis))]
12461 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
12462 pub fn format_to_parts(this: &ListFormat, list: &Array) -> Array;
12463
12464 /// Returns an array of objects representing the list in parts.
12465 ///
12466 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
12467 #[cfg(js_sys_unstable_apis)]
12468 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
12469 pub fn format_to_parts(this: &ListFormat, list: &[JsString]) -> Array<ListFormatPart>;
12470
12471 /// Returns an object with properties reflecting the options used.
12472 ///
12473 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
12474 #[cfg(not(js_sys_unstable_apis))]
12475 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12476 pub fn resolved_options(this: &ListFormat) -> Object;
12477
12478 /// Returns an object with properties reflecting the options used.
12479 ///
12480 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
12481 #[cfg(js_sys_unstable_apis)]
12482 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12483 pub fn resolved_options(this: &ListFormat) -> ResolvedListFormatOptions;
12484
12485 /// Returns an array of supported locales.
12486 ///
12487 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
12488 #[cfg(not(js_sys_unstable_apis))]
12489 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
12490 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12491
12492 /// Returns an array of supported locales.
12493 ///
12494 /// Throws a `RangeError` if locales contain invalid values.
12495 ///
12496 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
12497 #[cfg(js_sys_unstable_apis)]
12498 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12499 pub fn supported_locales_of(
12500 locales: &[JsString],
12501 options: &LocaleMatcherOptions,
12502 ) -> Result<Array<JsString>, JsValue>;
12503 }
12504
12505 #[cfg(not(js_sys_unstable_apis))]
12506 impl Default for ListFormat {
12507 fn default() -> Self {
12508 Self::new(
12509 &JsValue::UNDEFINED.unchecked_into(),
12510 &JsValue::UNDEFINED.unchecked_into(),
12511 )
12512 }
12513 }
12514
12515 #[cfg(js_sys_unstable_apis)]
12516 impl Default for ListFormat {
12517 fn default() -> Self {
12518 Self::new(&[], &Default::default()).unwrap()
12519 }
12520 }
12521
12522 // Intl.SegmenterOptions
12523 #[wasm_bindgen]
12524 extern "C" {
12525 /// Options for `Intl.Segmenter` constructor.
12526 ///
12527 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#options)
12528 #[wasm_bindgen(extends = Object)]
12529 #[derive(Clone, Debug)]
12530 pub type SegmenterOptions;
12531
12532 #[wasm_bindgen(method, getter = localeMatcher)]
12533 pub fn get_locale_matcher(this: &SegmenterOptions) -> Option<LocaleMatcher>;
12534 #[wasm_bindgen(method, setter = localeMatcher)]
12535 pub fn set_locale_matcher(this: &SegmenterOptions, value: LocaleMatcher);
12536
12537 #[wasm_bindgen(method, getter = granularity)]
12538 pub fn get_granularity(this: &SegmenterOptions) -> Option<SegmenterGranularity>;
12539 #[wasm_bindgen(method, setter = granularity)]
12540 pub fn set_granularity(this: &SegmenterOptions, value: SegmenterGranularity);
12541 }
12542
12543 impl SegmenterOptions {
12544 pub fn new() -> SegmenterOptions {
12545 JsCast::unchecked_into(Object::new())
12546 }
12547 }
12548
12549 impl Default for SegmenterOptions {
12550 fn default() -> Self {
12551 SegmenterOptions::new()
12552 }
12553 }
12554
12555 // Intl.ResolvedSegmenterOptions
12556 #[wasm_bindgen]
12557 extern "C" {
12558 /// Resolved options returned by `Intl.Segmenter.prototype.resolvedOptions()`.
12559 ///
12560 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12561 #[wasm_bindgen(extends = SegmenterOptions)]
12562 #[derive(Clone, Debug)]
12563 pub type ResolvedSegmenterOptions;
12564
12565 /// The resolved locale string.
12566 #[wasm_bindgen(method, getter = locale)]
12567 pub fn get_locale(this: &ResolvedSegmenterOptions) -> JsString;
12568 }
12569
12570 // Intl.SegmentData
12571 #[wasm_bindgen]
12572 extern "C" {
12573 /// Data about a segment returned by the Segments iterator.
12574 ///
12575 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments#segment_data)
12576 #[wasm_bindgen(extends = Object)]
12577 #[derive(Clone, Debug)]
12578 pub type SegmentData;
12579
12580 /// The segment string.
12581 #[wasm_bindgen(method, getter)]
12582 pub fn segment(this: &SegmentData) -> JsString;
12583
12584 /// The index of the segment in the original string.
12585 #[wasm_bindgen(method, getter)]
12586 pub fn index(this: &SegmentData) -> u32;
12587
12588 /// The original input string.
12589 #[wasm_bindgen(method, getter)]
12590 pub fn input(this: &SegmentData) -> JsString;
12591
12592 /// Whether the segment is word-like (only for word granularity).
12593 #[wasm_bindgen(method, getter = isWordLike)]
12594 pub fn is_word_like(this: &SegmentData) -> Option<bool>;
12595 }
12596
12597 // Intl.Segments
12598 #[wasm_bindgen]
12599 extern "C" {
12600 /// The Segments object is an iterable collection of segments of a string.
12601 ///
12602 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments)
12603 #[wasm_bindgen(extends = Object)]
12604 #[derive(Clone, Debug)]
12605 pub type Segments;
12606
12607 /// Returns segment data for the segment containing the character at the given index.
12608 ///
12609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments/containing)
12610 #[wasm_bindgen(method)]
12611 pub fn containing(this: &Segments, index: u32) -> Option<SegmentData>;
12612 }
12613
12614 // Intl.Segmenter
12615 #[wasm_bindgen]
12616 extern "C" {
12617 /// The `Intl.Segmenter` object enables locale-sensitive text segmentation.
12618 ///
12619 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter)
12620 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Segmenter")]
12621 #[derive(Clone, Debug)]
12622 pub type Segmenter;
12623
12624 /// Creates a new `Intl.Segmenter` object.
12625 ///
12626 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
12627 #[cfg(not(js_sys_unstable_apis))]
12628 #[wasm_bindgen(constructor, js_namespace = Intl)]
12629 pub fn new(locales: &Array, options: &Object) -> Segmenter;
12630
12631 /// Creates a new `Intl.Segmenter` object.
12632 ///
12633 /// Throws a `RangeError` if locales or options contain invalid values.
12634 ///
12635 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
12636 #[cfg(js_sys_unstable_apis)]
12637 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12638 pub fn new(locales: &[JsString], options: &SegmenterOptions) -> Result<Segmenter, JsValue>;
12639
12640 /// Returns a Segments object containing the segments of the input string.
12641 ///
12642 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment)
12643 #[wasm_bindgen(method, js_class = "Intl.Segmenter")]
12644 pub fn segment(this: &Segmenter, input: &str) -> Segments;
12645
12646 /// Returns an object with properties reflecting the options used.
12647 ///
12648 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12649 #[cfg(not(js_sys_unstable_apis))]
12650 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12651 pub fn resolved_options(this: &Segmenter) -> Object;
12652
12653 /// Returns an object with properties reflecting the options used.
12654 ///
12655 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12656 #[cfg(js_sys_unstable_apis)]
12657 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12658 pub fn resolved_options(this: &Segmenter) -> ResolvedSegmenterOptions;
12659
12660 /// Returns an array of supported locales.
12661 ///
12662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
12663 #[cfg(not(js_sys_unstable_apis))]
12664 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf)]
12665 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
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/Segmenter/supportedLocalesOf)
12672 #[cfg(js_sys_unstable_apis)]
12673 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12674 pub fn supported_locales_of(
12675 locales: &[JsString],
12676 options: &LocaleMatcherOptions,
12677 ) -> Result<Array<JsString>, JsValue>;
12678 }
12679
12680 #[cfg(not(js_sys_unstable_apis))]
12681 impl Default for Segmenter {
12682 fn default() -> Self {
12683 Self::new(
12684 &JsValue::UNDEFINED.unchecked_into(),
12685 &JsValue::UNDEFINED.unchecked_into(),
12686 )
12687 }
12688 }
12689
12690 #[cfg(js_sys_unstable_apis)]
12691 impl Default for Segmenter {
12692 fn default() -> Self {
12693 Self::new(&[], &Default::default()).unwrap()
12694 }
12695 }
12696
12697 // Intl.DisplayNamesOptions
12698 #[wasm_bindgen]
12699 extern "C" {
12700 /// Options for `Intl.DisplayNames` constructor.
12701 ///
12702 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options)
12703 #[wasm_bindgen(extends = Object)]
12704 #[derive(Clone, Debug)]
12705 pub type DisplayNamesOptions;
12706
12707 #[wasm_bindgen(method, getter = localeMatcher)]
12708 pub fn get_locale_matcher(this: &DisplayNamesOptions) -> Option<LocaleMatcher>;
12709 #[wasm_bindgen(method, setter = localeMatcher)]
12710 pub fn set_locale_matcher(this: &DisplayNamesOptions, value: LocaleMatcher);
12711
12712 #[wasm_bindgen(method, getter = type)]
12713 pub fn get_type(this: &DisplayNamesOptions) -> Option<DisplayNamesType>;
12714 #[wasm_bindgen(method, setter = type)]
12715 pub fn set_type(this: &DisplayNamesOptions, value: DisplayNamesType);
12716
12717 #[wasm_bindgen(method, getter = style)]
12718 pub fn get_style(this: &DisplayNamesOptions) -> Option<DisplayNamesStyle>;
12719 #[wasm_bindgen(method, setter = style)]
12720 pub fn set_style(this: &DisplayNamesOptions, value: DisplayNamesStyle);
12721
12722 #[wasm_bindgen(method, getter = fallback)]
12723 pub fn get_fallback(this: &DisplayNamesOptions) -> Option<DisplayNamesFallback>;
12724 #[wasm_bindgen(method, setter = fallback)]
12725 pub fn set_fallback(this: &DisplayNamesOptions, value: DisplayNamesFallback);
12726
12727 #[wasm_bindgen(method, getter = languageDisplay)]
12728 pub fn get_language_display(
12729 this: &DisplayNamesOptions,
12730 ) -> Option<DisplayNamesLanguageDisplay>;
12731 #[wasm_bindgen(method, setter = languageDisplay)]
12732 pub fn set_language_display(this: &DisplayNamesOptions, value: DisplayNamesLanguageDisplay);
12733 }
12734
12735 impl DisplayNamesOptions {
12736 pub fn new() -> DisplayNamesOptions {
12737 JsCast::unchecked_into(Object::new())
12738 }
12739 }
12740
12741 impl Default for DisplayNamesOptions {
12742 fn default() -> Self {
12743 DisplayNamesOptions::new()
12744 }
12745 }
12746
12747 // Intl.ResolvedDisplayNamesOptions
12748 #[wasm_bindgen]
12749 extern "C" {
12750 /// Resolved options returned by `Intl.DisplayNames.prototype.resolvedOptions()`.
12751 ///
12752 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12753 #[wasm_bindgen(extends = DisplayNamesOptions)]
12754 #[derive(Clone, Debug)]
12755 pub type ResolvedDisplayNamesOptions;
12756
12757 /// The resolved locale string.
12758 #[wasm_bindgen(method, getter = locale)]
12759 pub fn get_locale(this: &ResolvedDisplayNamesOptions) -> JsString;
12760 }
12761
12762 // Intl.DisplayNames
12763 #[wasm_bindgen]
12764 extern "C" {
12765 /// The `Intl.DisplayNames` object enables the consistent translation of
12766 /// language, region, and script display names.
12767 ///
12768 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
12769 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DisplayNames")]
12770 #[derive(Clone, Debug)]
12771 pub type DisplayNames;
12772
12773 /// Creates a new `Intl.DisplayNames` object.
12774 ///
12775 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12776 #[cfg(not(js_sys_unstable_apis))]
12777 #[wasm_bindgen(constructor, js_namespace = Intl)]
12778 pub fn new(locales: &Array, options: &Object) -> DisplayNames;
12779
12780 /// Creates a new `Intl.DisplayNames` object.
12781 ///
12782 /// Throws a `RangeError` if locales or options contain invalid values.
12783 ///
12784 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12785 #[cfg(js_sys_unstable_apis)]
12786 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12787 pub fn new(
12788 locales: &[JsString],
12789 options: &DisplayNamesOptions,
12790 ) -> Result<DisplayNames, JsValue>;
12791
12792 /// Returns the display name for the given code.
12793 ///
12794 /// Returns `undefined` if fallback is "none" and no name is available.
12795 ///
12796 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of)
12797 #[wasm_bindgen(method, js_class = "Intl.DisplayNames")]
12798 pub fn of(this: &DisplayNames, code: &str) -> Option<JsString>;
12799
12800 /// Returns an object with properties reflecting the options used.
12801 ///
12802 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12803 #[cfg(not(js_sys_unstable_apis))]
12804 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12805 pub fn resolved_options(this: &DisplayNames) -> Object;
12806
12807 /// Returns an object with properties reflecting the options used.
12808 ///
12809 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12810 #[cfg(js_sys_unstable_apis)]
12811 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12812 pub fn resolved_options(this: &DisplayNames) -> ResolvedDisplayNamesOptions;
12813
12814 /// Returns an array of supported locales.
12815 ///
12816 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12817 #[cfg(not(js_sys_unstable_apis))]
12818 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf)]
12819 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12820
12821 /// Returns an array of supported locales.
12822 ///
12823 /// Throws a `RangeError` if locales contain invalid values.
12824 ///
12825 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12826 #[cfg(js_sys_unstable_apis)]
12827 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12828 pub fn supported_locales_of(
12829 locales: &[JsString],
12830 options: &LocaleMatcherOptions,
12831 ) -> Result<Array<JsString>, JsValue>;
12832 }
12833
12834 // Intl.Locale
12835 #[wasm_bindgen]
12836 extern "C" {
12837 /// The `Intl.Locale` object is a standard built-in property of the Intl object
12838 /// that represents a Unicode locale identifier.
12839 ///
12840 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
12841 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Locale")]
12842 #[derive(Clone, Debug)]
12843 pub type Locale;
12844
12845 /// Creates a new `Intl.Locale` object.
12846 ///
12847 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12848 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12849 pub fn new(tag: &str) -> Result<Locale, JsValue>;
12850
12851 /// Creates a new `Intl.Locale` object with options.
12852 ///
12853 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12854 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12855 pub fn new_with_options(tag: &str, options: &Object) -> Result<Locale, JsValue>;
12856
12857 /// The base name of the locale (language + region + script).
12858 ///
12859 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName)
12860 #[wasm_bindgen(method, getter = baseName)]
12861 pub fn base_name(this: &Locale) -> JsString;
12862
12863 /// The calendar type for the locale.
12864 ///
12865 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar)
12866 #[wasm_bindgen(method, getter)]
12867 pub fn calendar(this: &Locale) -> Option<JsString>;
12868
12869 /// The case first sorting option.
12870 ///
12871 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst)
12872 #[wasm_bindgen(method, getter = caseFirst)]
12873 pub fn case_first(this: &Locale) -> Option<JsString>;
12874
12875 /// The collation type for the locale.
12876 ///
12877 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation)
12878 #[wasm_bindgen(method, getter)]
12879 pub fn collation(this: &Locale) -> Option<JsString>;
12880
12881 /// The hour cycle for the locale.
12882 ///
12883 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle)
12884 #[wasm_bindgen(method, getter = hourCycle)]
12885 pub fn hour_cycle(this: &Locale) -> Option<JsString>;
12886
12887 /// The language code for the locale.
12888 ///
12889 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language)
12890 #[wasm_bindgen(method, getter)]
12891 pub fn language(this: &Locale) -> JsString;
12892
12893 /// The numbering system for the locale.
12894 ///
12895 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem)
12896 #[wasm_bindgen(method, getter = numberingSystem)]
12897 pub fn numbering_system(this: &Locale) -> Option<JsString>;
12898
12899 /// Whether the locale uses numeric collation.
12900 ///
12901 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric)
12902 #[wasm_bindgen(method, getter)]
12903 pub fn numeric(this: &Locale) -> bool;
12904
12905 /// The region code for the locale.
12906 ///
12907 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/region)
12908 #[wasm_bindgen(method, getter)]
12909 pub fn region(this: &Locale) -> Option<JsString>;
12910
12911 /// The script code for the locale.
12912 ///
12913 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/script)
12914 #[wasm_bindgen(method, getter)]
12915 pub fn script(this: &Locale) -> Option<JsString>;
12916
12917 /// Returns an array of available calendars for the locale.
12918 ///
12919 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars)
12920 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCalendars)]
12921 pub fn get_calendars(this: &Locale) -> Array<JsString>;
12922
12923 /// Returns an array of available collations for the locale.
12924 ///
12925 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations)
12926 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCollations)]
12927 pub fn get_collations(this: &Locale) -> Array<JsString>;
12928
12929 /// Returns an array of available hour cycles for the locale.
12930 ///
12931 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles)
12932 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getHourCycles)]
12933 pub fn get_hour_cycles(this: &Locale) -> Array<JsString>;
12934
12935 /// Returns an array of available numbering systems for the locale.
12936 ///
12937 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems)
12938 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getNumberingSystems)]
12939 pub fn get_numbering_systems(this: &Locale) -> Array<JsString>;
12940
12941 /// Returns an array of available time zones for the locale's region.
12942 ///
12943 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones)
12944 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTimeZones)]
12945 pub fn get_time_zones(this: &Locale) -> Option<Array<JsString>>;
12946
12947 /// Returns week information for the locale.
12948 ///
12949 /// May not be available in all environments.
12950 ///
12951 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12952 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getWeekInfo, catch)]
12953 pub fn get_week_info(this: &Locale) -> Result<WeekInfo, JsValue>;
12954
12955 /// Returns text layout information for the locale.
12956 ///
12957 /// May not be available in all environments.
12958 ///
12959 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12960 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTextInfo, catch)]
12961 pub fn get_text_info(this: &Locale) -> Result<TextInfo, JsValue>;
12962
12963 /// Returns a new Locale with the specified calendar.
12964 ///
12965 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize)
12966 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12967 pub fn maximize(this: &Locale) -> Locale;
12968
12969 /// Returns a new Locale with the minimal subtags.
12970 ///
12971 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize)
12972 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12973 pub fn minimize(this: &Locale) -> Locale;
12974 }
12975
12976 // Intl.Locale WeekInfo
12977 #[wasm_bindgen]
12978 extern "C" {
12979 /// Week information for a locale.
12980 ///
12981 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12982 #[wasm_bindgen(extends = Object)]
12983 #[derive(Clone, Debug)]
12984 pub type WeekInfo;
12985
12986 /// The first day of the week (1 = Monday, 7 = Sunday).
12987 #[wasm_bindgen(method, getter = firstDay)]
12988 pub fn first_day(this: &WeekInfo) -> u8;
12989
12990 /// Array of weekend days.
12991 #[wasm_bindgen(method, getter)]
12992 pub fn weekend(this: &WeekInfo) -> Array<Number>;
12993
12994 /// Minimal days in the first week of the year.
12995 #[wasm_bindgen(method, getter = minimalDays)]
12996 pub fn minimal_days(this: &WeekInfo) -> u8;
12997 }
12998
12999 // Intl.Locale TextInfo
13000 #[wasm_bindgen]
13001 extern "C" {
13002 /// Text layout information for a locale.
13003 ///
13004 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
13005 #[wasm_bindgen(extends = Object)]
13006 #[derive(Clone, Debug)]
13007 pub type TextInfo;
13008
13009 /// The text direction ("ltr" or "rtl").
13010 #[wasm_bindgen(method, getter)]
13011 pub fn direction(this: &TextInfo) -> JsString;
13012 }
13013
13014 // Intl.DurationFormat enums
13015
13016 /// The style for duration formatting.
13017 ///
13018 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style)
13019 #[wasm_bindgen]
13020 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13021 pub enum DurationFormatStyle {
13022 Long = "long",
13023 Short = "short",
13024 Narrow = "narrow",
13025 Digital = "digital",
13026 }
13027
13028 /// The display style for individual duration units.
13029 ///
13030 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#years)
13031 #[wasm_bindgen]
13032 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13033 pub enum DurationUnitStyle {
13034 Long = "long",
13035 Short = "short",
13036 Narrow = "narrow",
13037 }
13038
13039 /// The display style for time duration units (hours, minutes, seconds).
13040 ///
13041 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#hours)
13042 #[wasm_bindgen]
13043 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13044 pub enum DurationTimeUnitStyle {
13045 Long = "long",
13046 Short = "short",
13047 Narrow = "narrow",
13048 Numeric = "numeric",
13049 #[wasm_bindgen(js_name = "2-digit")]
13050 TwoDigit = "2-digit",
13051 }
13052
13053 /// The display option for duration units.
13054 ///
13055 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#yearsdisplay)
13056 #[wasm_bindgen]
13057 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13058 pub enum DurationUnitDisplay {
13059 Auto = "auto",
13060 Always = "always",
13061 }
13062
13063 /// The type of a duration format part.
13064 ///
13065 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts#type)
13066 #[wasm_bindgen]
13067 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13068 pub enum DurationFormatPartType {
13069 Years = "years",
13070 Months = "months",
13071 Weeks = "weeks",
13072 Days = "days",
13073 Hours = "hours",
13074 Minutes = "minutes",
13075 Seconds = "seconds",
13076 Milliseconds = "milliseconds",
13077 Microseconds = "microseconds",
13078 Nanoseconds = "nanoseconds",
13079 Literal = "literal",
13080 Integer = "integer",
13081 Decimal = "decimal",
13082 Fraction = "fraction",
13083 }
13084
13085 // Intl.DurationFormatOptions
13086 #[wasm_bindgen]
13087 extern "C" {
13088 /// Options for `Intl.DurationFormat` constructor.
13089 ///
13090 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#options)
13091 #[wasm_bindgen(extends = Object)]
13092 #[derive(Clone, Debug)]
13093 pub type DurationFormatOptions;
13094
13095 #[wasm_bindgen(method, getter = localeMatcher)]
13096 pub fn get_locale_matcher(this: &DurationFormatOptions) -> Option<LocaleMatcher>;
13097 #[wasm_bindgen(method, setter = localeMatcher)]
13098 pub fn set_locale_matcher(this: &DurationFormatOptions, value: LocaleMatcher);
13099
13100 #[wasm_bindgen(method, getter = style)]
13101 pub fn get_style(this: &DurationFormatOptions) -> Option<DurationFormatStyle>;
13102 #[wasm_bindgen(method, setter = style)]
13103 pub fn set_style(this: &DurationFormatOptions, value: DurationFormatStyle);
13104
13105 #[wasm_bindgen(method, getter = years)]
13106 pub fn get_years(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13107 #[wasm_bindgen(method, setter = years)]
13108 pub fn set_years(this: &DurationFormatOptions, value: DurationUnitStyle);
13109
13110 #[wasm_bindgen(method, getter = yearsDisplay)]
13111 pub fn get_years_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13112 #[wasm_bindgen(method, setter = yearsDisplay)]
13113 pub fn set_years_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13114
13115 #[wasm_bindgen(method, getter = months)]
13116 pub fn get_months(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13117 #[wasm_bindgen(method, setter = months)]
13118 pub fn set_months(this: &DurationFormatOptions, value: DurationUnitStyle);
13119
13120 #[wasm_bindgen(method, getter = monthsDisplay)]
13121 pub fn get_months_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13122 #[wasm_bindgen(method, setter = monthsDisplay)]
13123 pub fn set_months_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13124
13125 #[wasm_bindgen(method, getter = weeks)]
13126 pub fn get_weeks(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13127 #[wasm_bindgen(method, setter = weeks)]
13128 pub fn set_weeks(this: &DurationFormatOptions, value: DurationUnitStyle);
13129
13130 #[wasm_bindgen(method, getter = weeksDisplay)]
13131 pub fn get_weeks_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13132 #[wasm_bindgen(method, setter = weeksDisplay)]
13133 pub fn set_weeks_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13134
13135 #[wasm_bindgen(method, getter = days)]
13136 pub fn get_days(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13137 #[wasm_bindgen(method, setter = days)]
13138 pub fn set_days(this: &DurationFormatOptions, value: DurationUnitStyle);
13139
13140 #[wasm_bindgen(method, getter = daysDisplay)]
13141 pub fn get_days_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13142 #[wasm_bindgen(method, setter = daysDisplay)]
13143 pub fn set_days_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13144
13145 #[wasm_bindgen(method, getter = hours)]
13146 pub fn get_hours(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
13147 #[wasm_bindgen(method, setter = hours)]
13148 pub fn set_hours(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
13149
13150 #[wasm_bindgen(method, getter = hoursDisplay)]
13151 pub fn get_hours_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13152 #[wasm_bindgen(method, setter = hoursDisplay)]
13153 pub fn set_hours_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13154
13155 #[wasm_bindgen(method, getter = minutes)]
13156 pub fn get_minutes(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
13157 #[wasm_bindgen(method, setter = minutes)]
13158 pub fn set_minutes(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
13159
13160 #[wasm_bindgen(method, getter = minutesDisplay)]
13161 pub fn get_minutes_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13162 #[wasm_bindgen(method, setter = minutesDisplay)]
13163 pub fn set_minutes_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13164
13165 #[wasm_bindgen(method, getter = seconds)]
13166 pub fn get_seconds(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
13167 #[wasm_bindgen(method, setter = seconds)]
13168 pub fn set_seconds(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
13169
13170 #[wasm_bindgen(method, getter = secondsDisplay)]
13171 pub fn get_seconds_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13172 #[wasm_bindgen(method, setter = secondsDisplay)]
13173 pub fn set_seconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13174
13175 #[wasm_bindgen(method, getter = milliseconds)]
13176 pub fn get_milliseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13177 #[wasm_bindgen(method, setter = milliseconds)]
13178 pub fn set_milliseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
13179
13180 #[wasm_bindgen(method, getter = millisecondsDisplay)]
13181 pub fn get_milliseconds_display(
13182 this: &DurationFormatOptions,
13183 ) -> Option<DurationUnitDisplay>;
13184 #[wasm_bindgen(method, setter = millisecondsDisplay)]
13185 pub fn set_milliseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13186
13187 #[wasm_bindgen(method, getter = microseconds)]
13188 pub fn get_microseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13189 #[wasm_bindgen(method, setter = microseconds)]
13190 pub fn set_microseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
13191
13192 #[wasm_bindgen(method, getter = microsecondsDisplay)]
13193 pub fn get_microseconds_display(
13194 this: &DurationFormatOptions,
13195 ) -> Option<DurationUnitDisplay>;
13196 #[wasm_bindgen(method, setter = microsecondsDisplay)]
13197 pub fn set_microseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13198
13199 #[wasm_bindgen(method, getter = nanoseconds)]
13200 pub fn get_nanoseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13201 #[wasm_bindgen(method, setter = nanoseconds)]
13202 pub fn set_nanoseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
13203
13204 #[wasm_bindgen(method, getter = nanosecondsDisplay)]
13205 pub fn get_nanoseconds_display(this: &DurationFormatOptions)
13206 -> Option<DurationUnitDisplay>;
13207 #[wasm_bindgen(method, setter = nanosecondsDisplay)]
13208 pub fn set_nanoseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13209
13210 #[wasm_bindgen(method, getter = fractionalDigits)]
13211 pub fn get_fractional_digits(this: &DurationFormatOptions) -> Option<u8>;
13212 #[wasm_bindgen(method, setter = fractionalDigits)]
13213 pub fn set_fractional_digits(this: &DurationFormatOptions, value: u8);
13214 }
13215
13216 impl DurationFormatOptions {
13217 pub fn new() -> DurationFormatOptions {
13218 JsCast::unchecked_into(Object::new())
13219 }
13220 }
13221
13222 impl Default for DurationFormatOptions {
13223 fn default() -> Self {
13224 DurationFormatOptions::new()
13225 }
13226 }
13227
13228 // Intl.ResolvedDurationFormatOptions
13229 #[wasm_bindgen]
13230 extern "C" {
13231 /// Resolved options returned by `Intl.DurationFormat.prototype.resolvedOptions()`.
13232 ///
13233 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
13234 #[wasm_bindgen(extends = DurationFormatOptions)]
13235 #[derive(Clone, Debug)]
13236 pub type ResolvedDurationFormatOptions;
13237
13238 /// The resolved locale string.
13239 #[wasm_bindgen(method, getter = locale)]
13240 pub fn get_locale(this: &ResolvedDurationFormatOptions) -> JsString;
13241
13242 /// The resolved numbering system.
13243 #[wasm_bindgen(method, getter = numberingSystem)]
13244 pub fn get_numbering_system(this: &ResolvedDurationFormatOptions) -> JsString;
13245 }
13246
13247 // Intl.Duration (input object for DurationFormat)
13248 #[wasm_bindgen]
13249 extern "C" {
13250 /// A duration object used as input to `Intl.DurationFormat.format()`.
13251 ///
13252 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration)
13253 #[wasm_bindgen(extends = Object)]
13254 #[derive(Clone, Debug)]
13255 pub type Duration;
13256
13257 #[wasm_bindgen(method, getter)]
13258 pub fn years(this: &Duration) -> Option<f64>;
13259 #[wasm_bindgen(method, setter)]
13260 pub fn set_years(this: &Duration, value: f64);
13261
13262 #[wasm_bindgen(method, getter)]
13263 pub fn months(this: &Duration) -> Option<f64>;
13264 #[wasm_bindgen(method, setter)]
13265 pub fn set_months(this: &Duration, value: f64);
13266
13267 #[wasm_bindgen(method, getter)]
13268 pub fn weeks(this: &Duration) -> Option<f64>;
13269 #[wasm_bindgen(method, setter)]
13270 pub fn set_weeks(this: &Duration, value: f64);
13271
13272 #[wasm_bindgen(method, getter)]
13273 pub fn days(this: &Duration) -> Option<f64>;
13274 #[wasm_bindgen(method, setter)]
13275 pub fn set_days(this: &Duration, value: f64);
13276
13277 #[wasm_bindgen(method, getter)]
13278 pub fn hours(this: &Duration) -> Option<f64>;
13279 #[wasm_bindgen(method, setter)]
13280 pub fn set_hours(this: &Duration, value: f64);
13281
13282 #[wasm_bindgen(method, getter)]
13283 pub fn minutes(this: &Duration) -> Option<f64>;
13284 #[wasm_bindgen(method, setter)]
13285 pub fn set_minutes(this: &Duration, value: f64);
13286
13287 #[wasm_bindgen(method, getter)]
13288 pub fn seconds(this: &Duration) -> Option<f64>;
13289 #[wasm_bindgen(method, setter)]
13290 pub fn set_seconds(this: &Duration, value: f64);
13291
13292 #[wasm_bindgen(method, getter)]
13293 pub fn milliseconds(this: &Duration) -> Option<f64>;
13294 #[wasm_bindgen(method, setter)]
13295 pub fn set_milliseconds(this: &Duration, value: f64);
13296
13297 #[wasm_bindgen(method, getter)]
13298 pub fn microseconds(this: &Duration) -> Option<f64>;
13299 #[wasm_bindgen(method, setter)]
13300 pub fn set_microseconds(this: &Duration, value: f64);
13301
13302 #[wasm_bindgen(method, getter)]
13303 pub fn nanoseconds(this: &Duration) -> Option<f64>;
13304 #[wasm_bindgen(method, setter)]
13305 pub fn set_nanoseconds(this: &Duration, value: f64);
13306 }
13307
13308 impl Duration {
13309 pub fn new() -> Duration {
13310 JsCast::unchecked_into(Object::new())
13311 }
13312 }
13313
13314 impl Default for Duration {
13315 fn default() -> Self {
13316 Duration::new()
13317 }
13318 }
13319
13320 // Intl.DurationFormatPart
13321 #[wasm_bindgen]
13322 extern "C" {
13323 /// A part of the formatted duration returned by `formatToParts()`.
13324 ///
13325 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
13326 #[wasm_bindgen(extends = Object)]
13327 #[derive(Clone, Debug)]
13328 pub type DurationFormatPart;
13329
13330 /// The type of the part.
13331 #[wasm_bindgen(method, getter = type)]
13332 pub fn type_(this: &DurationFormatPart) -> DurationFormatPartType;
13333
13334 /// The value of the part.
13335 #[wasm_bindgen(method, getter)]
13336 pub fn value(this: &DurationFormatPart) -> JsString;
13337
13338 /// The unit this part represents (if applicable).
13339 #[wasm_bindgen(method, getter)]
13340 pub fn unit(this: &DurationFormatPart) -> Option<JsString>;
13341 }
13342
13343 // Intl.DurationFormat
13344 #[wasm_bindgen]
13345 extern "C" {
13346 /// The `Intl.DurationFormat` object enables language-sensitive duration formatting.
13347 ///
13348 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat)
13349 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DurationFormat")]
13350 #[derive(Clone, Debug)]
13351 pub type DurationFormat;
13352
13353 /// Creates a new `Intl.DurationFormat` object.
13354 ///
13355 /// Throws a `RangeError` if locales or options contain invalid values.
13356 ///
13357 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat)
13358 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13359 pub fn new(
13360 locales: &[JsString],
13361 options: &DurationFormatOptions,
13362 ) -> Result<DurationFormat, JsValue>;
13363
13364 /// Formats a duration according to the locale and formatting options.
13365 ///
13366 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format)
13367 #[wasm_bindgen(method, js_class = "Intl.DurationFormat")]
13368 pub fn format(this: &DurationFormat, duration: &Duration) -> JsString;
13369
13370 /// Returns an array of objects representing the formatted duration in parts.
13371 ///
13372 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
13373 #[wasm_bindgen(method, js_class = "Intl.DurationFormat", js_name = formatToParts)]
13374 pub fn format_to_parts(
13375 this: &DurationFormat,
13376 duration: &Duration,
13377 ) -> Array<DurationFormatPart>;
13378
13379 /// Returns an object with properties reflecting the options used.
13380 ///
13381 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
13382 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13383 pub fn resolved_options(this: &DurationFormat) -> ResolvedDurationFormatOptions;
13384
13385 /// Returns an array of supported locales.
13386 ///
13387 /// Throws a `RangeError` if locales contain invalid values.
13388 ///
13389 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf)
13390 #[wasm_bindgen(static_method_of = DurationFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13391 pub fn supported_locales_of(
13392 locales: &[JsString],
13393 options: &LocaleMatcherOptions,
13394 ) -> Result<Array<JsString>, JsValue>;
13395 }
13396
13397 impl Default for DurationFormat {
13398 fn default() -> Self {
13399 Self::new(&[], &Default::default()).unwrap()
13400 }
13401 }
13402}
13403
13404#[wasm_bindgen]
13405extern "C" {
13406 /// The `PromiseState` object represents the the status of the promise,
13407 /// as used in `allSettled`.
13408 ///
13409 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13410 #[must_use]
13411 #[wasm_bindgen(extends = Object, typescript_type = "any")]
13412 #[derive(Clone, Debug)]
13413 pub type PromiseState<T = JsValue>;
13414
13415 /// A string, either "fulfilled" or "rejected", indicating the eventual state of the promise.
13416 #[wasm_bindgen(method, getter = status)]
13417 pub fn get_status<T>(this: &PromiseState<T>) -> String;
13418
13419 /// Only present if status is "fulfilled". The value that the promise was fulfilled with.
13420 #[wasm_bindgen(method, getter = value)]
13421 pub fn get_value<T>(this: &PromiseState<T>) -> Option<T>;
13422
13423 /// Only present if status is "rejected". The reason that the promise was rejected with.
13424 #[wasm_bindgen(method, getter = reason)]
13425 pub fn get_reason<T>(this: &PromiseState<T>) -> Option<JsValue>;
13426}
13427
13428impl<T> PromiseState<T> {
13429 pub fn is_fulfilled(&self) -> bool {
13430 self.get_status() == "fulfilled"
13431 }
13432
13433 pub fn is_rejected(&self) -> bool {
13434 self.get_status() == "rejected"
13435 }
13436}
13437
13438/// Converts a `PromiseState<T>` into a `Result<T, JsValue>`, matching the
13439/// spec invariant that exactly one of the fulfilled value or the rejection
13440/// reason is populated per slot.
13441impl<T: JsGeneric + FromWasmAbi> From<PromiseState<T>> for Result<T, JsValue> {
13442 fn from(state: PromiseState<T>) -> Result<T, JsValue> {
13443 if state.is_fulfilled() {
13444 Ok(state.get_value().unwrap())
13445 } else {
13446 Err(state.get_reason().unwrap())
13447 }
13448 }
13449}
13450
13451// Promise
13452#[wasm_bindgen]
13453extern "C" {
13454 /// The `Promise` object represents the eventual completion (or failure) of
13455 /// an asynchronous operation, and its resulting value.
13456 ///
13457 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13458 #[must_use]
13459 #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>", no_promising)]
13460 #[derive(Clone, Debug)]
13461 pub type Promise<T = JsValue>;
13462
13463 /// Creates a new `Promise` with the provided executor `cb`
13464 ///
13465 /// The `cb` is a function that is passed with the arguments `resolve` and
13466 /// `reject`. The `cb` function is executed immediately by the `Promise`
13467 /// implementation, passing `resolve` and `reject` functions (the executor
13468 /// is called before the `Promise` constructor even returns the created
13469 /// object). The `resolve` and `reject` functions, when called, resolve or
13470 /// reject the promise, respectively. The executor normally initiates
13471 /// some asynchronous work, and then, once that completes, either calls
13472 /// the `resolve` function to resolve the promise or else rejects it if an
13473 /// error occurred.
13474 ///
13475 /// If an error is thrown in the executor function, the promise is rejected.
13476 /// The return value of the executor is ignored.
13477 ///
13478 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13479 #[cfg(not(js_sys_unstable_apis))]
13480 #[wasm_bindgen(constructor)]
13481 pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
13482
13483 /// Creates a new `Promise` with the provided executor `cb`
13484 ///
13485 /// The `cb` is a function that is passed with the arguments `resolve` and
13486 /// `reject`. The `cb` function is executed immediately by the `Promise`
13487 /// implementation, passing `resolve` and `reject` functions (the executor
13488 /// is called before the `Promise` constructor even returns the created
13489 /// object). The `resolve` and `reject` functions, when called, resolve or
13490 /// reject the promise, respectively. The executor normally initiates
13491 /// some asynchronous work, and then, once that completes, either calls
13492 /// the `resolve` function to resolve the promise or else rejects it if an
13493 /// error occurred.
13494 ///
13495 /// If an error is thrown in the executor function, the promise is rejected.
13496 /// The return value of the executor is ignored.
13497 ///
13498 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13499 #[cfg(js_sys_unstable_apis)]
13500 #[wasm_bindgen(constructor)]
13501 pub fn new<T: JsGeneric>(
13502 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
13503 ) -> Promise<T>;
13504
13505 // Next major: deprecate
13506 /// Creates a new `Promise` with the provided executor `cb`
13507 ///
13508 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13509 #[wasm_bindgen(constructor)]
13510 pub fn new_typed<T: Promising + JsGeneric>(
13511 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
13512 ) -> Promise<<T as Promising>::Resolution>;
13513
13514 /// The `Promise.all(iterable)` method returns a single `Promise` that
13515 /// resolves when all of the promises in the iterable argument have resolved
13516 /// or when the iterable argument contains no promises. It rejects with the
13517 /// reason of the first promise that rejects.
13518 ///
13519 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
13520 #[cfg(not(js_sys_unstable_apis))]
13521 #[wasm_bindgen(static_method_of = Promise)]
13522 pub fn all(obj: &JsValue) -> Promise;
13523
13524 /// The `Promise.all(iterable)` method returns a single `Promise` that
13525 /// resolves when all of the promises in the iterable argument have resolved
13526 /// or when the iterable argument contains no promises. It rejects with the
13527 /// reason of the first promise that rejects.
13528 ///
13529 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
13530 #[cfg(js_sys_unstable_apis)]
13531 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
13532 pub fn all<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
13533 where
13534 I::Item: Promising;
13535
13536 // Next major: deprecate
13537 /// The `Promise.all(iterable)` method returns a single `Promise` that
13538 /// resolves when all of the promises in the iterable argument have resolved
13539 /// or when the iterable argument contains no promises. It rejects with the
13540 /// reason of the first promise that rejects.
13541 ///
13542 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
13543 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
13544 pub fn all_iterable<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
13545 where
13546 I::Item: Promising;
13547
13548 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
13549 /// resolves when all of the promises in the iterable argument have either
13550 /// fulfilled or rejected or when the iterable argument contains no promises.
13551 ///
13552 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13553 #[cfg(not(js_sys_unstable_apis))]
13554 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
13555 pub fn all_settled(obj: &JsValue) -> Promise;
13556
13557 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
13558 /// resolves when all of the promises in the iterable argument have either
13559 /// fulfilled or rejected or when the iterable argument contains no promises.
13560 ///
13561 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13562 #[cfg(js_sys_unstable_apis)]
13563 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
13564 pub fn all_settled<I: Iterable>(
13565 obj: &I,
13566 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
13567 where
13568 I::Item: Promising;
13569
13570 // Next major: deprecate
13571 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
13572 /// resolves when all of the promises in the iterable argument have either
13573 /// fulfilled or rejected or when the iterable argument contains no promises.
13574 ///
13575 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13576 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
13577 pub fn all_settled_iterable<I: Iterable>(
13578 obj: &I,
13579 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
13580 where
13581 I::Item: Promising;
13582
13583 /// The `Promise.any(iterable)` method returns a single `Promise` that
13584 /// resolves when any of the promises in the iterable argument have resolved
13585 /// or when the iterable argument contains no promises. It rejects with an
13586 /// `AggregateError` if all promises in the iterable rejected.
13587 ///
13588 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
13589 #[cfg(not(js_sys_unstable_apis))]
13590 #[wasm_bindgen(static_method_of = Promise)]
13591 pub fn any(obj: &JsValue) -> Promise;
13592
13593 /// The `Promise.any(iterable)` method returns a single `Promise` that
13594 /// resolves when any of the promises in the iterable argument have resolved
13595 /// or when the iterable argument contains no promises. It rejects with an
13596 /// `AggregateError` if all promises in the iterable rejected.
13597 ///
13598 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
13599 #[cfg(js_sys_unstable_apis)]
13600 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
13601 pub fn any<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13602 where
13603 I::Item: Promising;
13604
13605 // Next major: deprecate
13606 /// The `Promise.any(iterable)` method returns a single `Promise` that
13607 /// resolves when any of the promises in the iterable argument have resolved
13608 /// or when the iterable argument contains no promises. It rejects with an
13609 /// `AggregateError` if all promises in the iterable rejected.
13610 ///
13611 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
13612 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
13613 pub fn any_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13614 where
13615 I::Item: Promising;
13616
13617 /// The `Promise.race(iterable)` method returns a promise that resolves or
13618 /// rejects as soon as one of the promises in the iterable resolves or
13619 /// rejects, with the value or reason from that promise.
13620 ///
13621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
13622 #[cfg(not(js_sys_unstable_apis))]
13623 #[wasm_bindgen(static_method_of = Promise)]
13624 pub fn race(obj: &JsValue) -> Promise;
13625
13626 /// The `Promise.race(iterable)` method returns a promise that resolves or
13627 /// rejects as soon as one of the promises in the iterable resolves or
13628 /// rejects, with the value or reason from that promise.
13629 ///
13630 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
13631 #[cfg(js_sys_unstable_apis)]
13632 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
13633 pub fn race<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13634 where
13635 I::Item: Promising;
13636
13637 // Next major: deprecate
13638 /// The `Promise.race(iterable)` method returns a promise that resolves or
13639 /// rejects as soon as one of the promises in the iterable resolves or
13640 /// rejects, with the value or reason from that promise.
13641 ///
13642 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
13643 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
13644 pub fn race_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13645 where
13646 I::Item: Promising;
13647
13648 /// The `Promise.reject(reason)` method returns a `Promise` object that is
13649 /// rejected with the given reason.
13650 ///
13651 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
13652 #[cfg(not(js_sys_unstable_apis))]
13653 #[wasm_bindgen(static_method_of = Promise)]
13654 pub fn reject(obj: &JsValue) -> Promise;
13655
13656 /// The `Promise.reject(reason)` method returns a `Promise` object that is
13657 /// rejected with the given reason.
13658 ///
13659 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
13660 #[cfg(js_sys_unstable_apis)]
13661 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
13662 pub fn reject<T>(obj: &JsValue) -> Promise<T>;
13663
13664 // Next major: deprecate
13665 /// The `Promise.reject(reason)` method returns a `Promise` object that is
13666 /// rejected with the given reason.
13667 ///
13668 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
13669 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
13670 pub fn reject_typed<T>(obj: &JsValue) -> Promise<T>;
13671
13672 /// The `Promise.resolve(value)` method returns a `Promise` object that is
13673 /// resolved with the given value. If the value is a promise, that promise
13674 /// is returned; if the value is a thenable (i.e. has a "then" method), the
13675 /// returned promise will "follow" that thenable, adopting its eventual
13676 /// state; otherwise the returned promise will be fulfilled with the value.
13677 ///
13678 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
13679 #[wasm_bindgen(static_method_of = Promise, js_name = resolve)]
13680 pub fn resolve<U: Promising>(obj: &U) -> Promise<U::Resolution>;
13681
13682 /// The `catch()` method returns a `Promise` and deals with rejected cases
13683 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
13684 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
13685 /// `obj.then(undefined, onRejected)`).
13686 ///
13687 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
13688 #[cfg(not(js_sys_unstable_apis))]
13689 #[wasm_bindgen(method)]
13690 pub fn catch<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut(JsValue)>) -> Promise<JsValue>;
13691
13692 /// The `catch()` method returns a `Promise` and deals with rejected cases
13693 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
13694 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
13695 /// `obj.then(undefined, onRejected)`).
13696 ///
13697 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
13698 #[cfg(js_sys_unstable_apis)]
13699 #[wasm_bindgen(method, js_name = catch)]
13700 pub fn catch<'a, T, R: Promising>(
13701 this: &Promise<T>,
13702 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13703 ) -> Promise<R::Resolution>;
13704
13705 // Next major: deprecate
13706 /// Same as `catch`, but returning a result to become the new Promise value.
13707 #[wasm_bindgen(method, js_name = catch)]
13708 pub fn catch_map<'a, T, R: Promising>(
13709 this: &Promise<T>,
13710 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13711 ) -> Promise<R::Resolution>;
13712
13713 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13714 /// callback functions for the success and failure cases of the `Promise`.
13715 ///
13716 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13717 #[cfg(not(js_sys_unstable_apis))]
13718 #[wasm_bindgen(method)]
13719 pub fn then<'a, T>(this: &Promise<T>, cb: &ScopedClosure<'a, dyn FnMut(T)>)
13720 -> Promise<JsValue>;
13721
13722 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13723 /// callback functions for the success and failure cases of the `Promise`.
13724 ///
13725 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13726 #[cfg(js_sys_unstable_apis)]
13727 #[wasm_bindgen(method, js_name = then)]
13728 pub fn then<'a, T, R: Promising>(
13729 this: &Promise<T>,
13730 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13731 ) -> Promise<R::Resolution>;
13732
13733 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13734 /// callback functions for the success and failure cases of the `Promise`.
13735 ///
13736 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13737 #[wasm_bindgen(method, js_name = then)]
13738 pub fn then_with_reject<'a, T, R: Promising>(
13739 this: &Promise<T>,
13740 resolve: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13741 reject: &ScopedClosure<'a, dyn FnMut(JsValue) -> Result<R, JsError>>,
13742 ) -> Promise<R::Resolution>;
13743
13744 // Next major: deprecate
13745 /// Alias for `then()` with a return value.
13746 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13747 /// callback functions for the success and failure cases of the `Promise`.
13748 ///
13749 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13750 #[wasm_bindgen(method, js_name = then)]
13751 pub fn then_map<'a, T, R: Promising>(
13752 this: &Promise<T>,
13753 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13754 ) -> Promise<R::Resolution>;
13755
13756 /// Same as `then`, only with both arguments provided.
13757 ///
13758 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13759 #[wasm_bindgen(method, js_name = then)]
13760 pub fn then2(
13761 this: &Promise,
13762 resolve: &ScopedClosure<dyn FnMut(JsValue)>,
13763 reject: &ScopedClosure<dyn FnMut(JsValue)>,
13764 ) -> Promise;
13765
13766 /// The `finally()` method returns a `Promise`. When the promise is settled,
13767 /// whether fulfilled or rejected, the specified callback function is
13768 /// executed. This provides a way for code that must be executed once the
13769 /// `Promise` has been dealt with to be run whether the promise was
13770 /// fulfilled successfully or rejected.
13771 ///
13772 /// This lets you avoid duplicating code in both the promise's `then()` and
13773 /// `catch()` handlers.
13774 ///
13775 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
13776 #[wasm_bindgen(method)]
13777 pub fn finally<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut()>) -> Promise<JsValue>;
13778}
13779
13780impl<T: JsGeneric> Promising for Promise<T> {
13781 type Resolution = T;
13782}
13783
13784/// Internal: maps a tuple of `Promise<T_i>` to the result shapes of
13785/// [`Promise::all_tuple`] and [`Promise::all_settled_tuple`].
13786///
13787/// Implemented for every tuple arity 1..=8 of `Promise<T: JsGeneric>`. The
13788/// associated `Joined` / `Settled` types pin down the [`ArrayTuple`] shape
13789/// of the result so the one [`JsCast::unchecked_into`] needed to reinterpret
13790/// the [`Array<JsValue>`] returned by `Promise.all` / `Promise.allSettled`
13791/// is encapsulated inside each impl — the caller sees a fully-typed
13792/// `Promise<ArrayTuple<...>>`.
13793///
13794/// The soundness of the `unchecked_into`s here rests on `Promise.all` and
13795/// `Promise.allSettled` preserving input order and arity, which they do by
13796/// spec.
13797///
13798/// You normally call [`Promise::all_tuple`] / [`Promise::all_settled_tuple`]
13799/// rather than using this trait directly.
13800#[doc(hidden)]
13801pub trait PromiseTuple {
13802 /// The typed `ArrayTuple` shape the joined promise resolves to.
13803 ///
13804 /// For a tuple `(Promise<T1>, Promise<T2>, ...)` this is
13805 /// `ArrayTuple<(T1, T2, ...)>`.
13806 type Joined: JsGeneric;
13807
13808 /// The typed `ArrayTuple` shape the all-settled promise resolves to.
13809 ///
13810 /// For a tuple `(Promise<T1>, Promise<T2>, ...)` this is
13811 /// `ArrayTuple<(PromiseState<T1>, PromiseState<T2>, ...)>`.
13812 type Settled: JsGeneric;
13813
13814 /// Join via `Promise.all`, returning a typed `Promise`.
13815 fn all(self) -> Promise<Self::Joined>;
13816
13817 /// Settle via `Promise.allSettled`, returning a typed `Promise`.
13818 fn all_settled(self) -> Promise<Self::Settled>;
13819}
13820
13821macro_rules! impl_promise_tuple {
13822 ([$($T:ident)+] [$($idx:tt)+]) => {
13823 // Rust tuple of `Promise<T_i>`. Builds the heterogeneous
13824 // `ArrayTuple` of promises via the existing `From<(...)>` impl
13825 // (each element upcasts through `JsGeneric`), then delegates to
13826 // the `ArrayTuple` impl below.
13827 impl<$($T: JsGeneric),+> PromiseTuple for ($(Promise<$T>,)+) {
13828 type Joined = ArrayTuple<($($T,)+)>;
13829 type Settled = ArrayTuple<($(PromiseState<$T>,)+)>;
13830
13831 fn all(self) -> Promise<Self::Joined> {
13832 let tuple: ArrayTuple<($(Promise<$T>,)+)> = ($(self.$idx,)+).into();
13833 tuple.all()
13834 }
13835
13836 fn all_settled(self) -> Promise<Self::Settled> {
13837 let tuple: ArrayTuple<($(Promise<$T>,)+)> = ($(self.$idx,)+).into();
13838 tuple.all_settled()
13839 }
13840 }
13841
13842 // `ArrayTuple<(Promise<T_1>, ..., Promise<T_n>)>` — callers who
13843 // already have an `ArrayTuple` (e.g. from a binding that returns
13844 // one, or built via `.into()` earlier in a pipeline) can pass it
13845 // directly without unpacking into a Rust tuple.
13846 //
13847 // Hands the `ArrayTuple` straight to `Promise.all_iterable` /
13848 // `Promise.allSettled_iterable` and reinterprets the result
13849 // `Array<JsValue>` as the intended typed `ArrayTuple`. Safe because
13850 // `Promise.all` / `Promise.allSettled` preserve input order and
13851 // arity by spec.
13852 impl<$($T: JsGeneric),+> PromiseTuple for ArrayTuple<($(Promise<$T>,)+)> {
13853 type Joined = ArrayTuple<($($T,)+)>;
13854 type Settled = ArrayTuple<($(PromiseState<$T>,)+)>;
13855
13856 fn all(self) -> Promise<Self::Joined> {
13857 use wasm_bindgen::JsCast;
13858 Promise::all_iterable(&self).unchecked_into()
13859 }
13860
13861 fn all_settled(self) -> Promise<Self::Settled> {
13862 use wasm_bindgen::JsCast;
13863 Promise::all_settled_iterable(&self).unchecked_into()
13864 }
13865 }
13866 };
13867}
13868
13869impl_promise_tuple!([T1][0]);
13870impl_promise_tuple!([T1 T2] [0 1]);
13871impl_promise_tuple!([T1 T2 T3] [0 1 2]);
13872impl_promise_tuple!([T1 T2 T3 T4] [0 1 2 3]);
13873impl_promise_tuple!([T1 T2 T3 T4 T5] [0 1 2 3 4]);
13874impl_promise_tuple!([T1 T2 T3 T4 T5 T6] [0 1 2 3 4 5]);
13875impl_promise_tuple!([T1 T2 T3 T4 T5 T6 T7] [0 1 2 3 4 5 6]);
13876impl_promise_tuple!([T1 T2 T3 T4 T5 T6 T7 T8] [0 1 2 3 4 5 6 7]);
13877
13878impl Promise {
13879 /// Heterogeneous counterpart to [`Promise::all_iterable`]: accepts a Rust
13880 /// tuple of `Promise<T_i>` and returns a single [`Promise`] resolving to a
13881 /// typed [`ArrayTuple<(T_1, T_2, ..., T_n)>`].
13882 ///
13883 /// Destructure the awaited result via [`ArrayTuple::into_tuple`] to get
13884 /// the individual values back as a native Rust tuple. Implemented for
13885 /// arity 1..=8.
13886 ///
13887 /// Rejects with the first rejection, matching `Promise.all` semantics.
13888 ///
13889 /// # Example
13890 ///
13891 /// ```ignore
13892 /// use js_sys::Promise;
13893 ///
13894 /// let (response, buffer) = Promise::all_tuple((fetch_promise, buffer_promise))
13895 /// .await?
13896 /// .into_tuple();
13897 /// ```
13898 #[inline]
13899 pub fn all_tuple<T: PromiseTuple>(promises: T) -> Promise<T::Joined> {
13900 promises.all()
13901 }
13902
13903 /// Heterogeneous counterpart to [`Promise::all_settled_iterable`]: accepts
13904 /// a Rust tuple of `Promise<T_i>` and returns a single [`Promise`]
13905 /// resolving to a typed
13906 /// `ArrayTuple<(PromiseState<T_1>, ..., PromiseState<T_n>)>`.
13907 ///
13908 /// Unlike [`Promise::all_tuple`], this never rejects early: every input
13909 /// settles (fulfills or rejects) and is reflected by its [`PromiseState`]
13910 /// slot in the result tuple. Implemented for arity 1..=8.
13911 ///
13912 /// # Example
13913 ///
13914 /// ```ignore
13915 /// use js_sys::Promise;
13916 ///
13917 /// let results = Promise::all_settled_tuple((fetch_promise, buffer_promise)).await?;
13918 /// let (response_state, buffer_state) = results.into_tuple();
13919 /// ```
13920 #[inline]
13921 pub fn all_settled_tuple<T: PromiseTuple>(promises: T) -> Promise<T::Settled> {
13922 promises.all_settled()
13923 }
13924}
13925
13926/// Returns a handle to the global scope object.
13927///
13928/// This allows access to the global properties and global names by accessing
13929/// the `Object` returned.
13930pub fn global() -> Object {
13931 use wasm_bindgen::__rt::LazyCell;
13932
13933 #[cfg_attr(target_feature = "atomics", thread_local)]
13934 static GLOBAL: LazyCell<Object> = LazyCell::new(get_global_object);
13935
13936 return GLOBAL.clone();
13937
13938 fn get_global_object() -> Object {
13939 // Accessing the global object is not an easy thing to do, and what we
13940 // basically want is `globalThis` but we can't rely on that existing
13941 // everywhere. In the meantime we've got the fallbacks mentioned in:
13942 //
13943 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
13944 //
13945 // Note that this is pretty heavy code-size wise but it at least gets
13946 // the job largely done for now and avoids the `Function` constructor at
13947 // the end which triggers CSP errors.
13948 #[wasm_bindgen]
13949 extern "C" {
13950 #[derive(Clone, Debug)]
13951 type Global;
13952
13953 #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
13954 static GLOBAL_THIS: Option<Object>;
13955
13956 #[wasm_bindgen(thread_local_v2, js_name = self)]
13957 static SELF: Option<Object>;
13958
13959 #[wasm_bindgen(thread_local_v2, js_name = window)]
13960 static WINDOW: Option<Object>;
13961
13962 #[wasm_bindgen(thread_local_v2, js_name = global)]
13963 static GLOBAL: Option<Object>;
13964 }
13965
13966 // The order is important: in Firefox Extension Content Scripts `globalThis`
13967 // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
13968 let static_object = SELF
13969 .with(Option::clone)
13970 .or_else(|| WINDOW.with(Option::clone))
13971 .or_else(|| GLOBAL_THIS.with(Option::clone))
13972 .or_else(|| GLOBAL.with(Option::clone));
13973 if let Some(obj) = static_object {
13974 if !obj.is_undefined() {
13975 return obj;
13976 }
13977 }
13978
13979 // Global object not found
13980 JsValue::undefined().unchecked_into()
13981 }
13982}
13983
13984// Float16Array
13985//
13986// Rust does not yet have a stable builtin `f16`, so the raw JS bindings live
13987// here and any Rust-side helper APIs use explicit `u16` / `f32` naming. The
13988// unsuffixed float APIs are reserved for a future native `f16` binding.
13989#[wasm_bindgen]
13990extern "C" {
13991 #[wasm_bindgen(extends = Object, typescript_type = "Float16Array")]
13992 #[derive(Clone, Debug)]
13993 pub type Float16Array;
13994
13995 /// The `Float16Array()` constructor creates a new array.
13996 ///
13997 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13998 #[wasm_bindgen(constructor)]
13999 pub fn new(constructor_arg: &JsValue) -> Float16Array;
14000
14001 /// The `Float16Array()` constructor creates an array with an internal
14002 /// buffer large enough for `length` elements.
14003 ///
14004 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
14005 #[wasm_bindgen(constructor)]
14006 pub fn new_with_length(length: u32) -> Float16Array;
14007
14008 /// The `Float16Array()` constructor creates an array with the given
14009 /// buffer but is a view starting at `byte_offset`.
14010 ///
14011 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
14012 #[wasm_bindgen(constructor)]
14013 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> Float16Array;
14014
14015 /// The `Float16Array()` constructor creates an array with the given
14016 /// buffer but is a view starting at `byte_offset` for `length` elements.
14017 ///
14018 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
14019 #[wasm_bindgen(constructor)]
14020 pub fn new_with_byte_offset_and_length(
14021 buffer: &JsValue,
14022 byte_offset: u32,
14023 length: u32,
14024 ) -> Float16Array;
14025
14026 /// The `fill()` method fills all elements from a start index to an end
14027 /// index with a static `f32` value.
14028 ///
14029 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
14030 #[wasm_bindgen(method, js_name = fill)]
14031 pub fn fill_with_f32(this: &Float16Array, value: f32, start: u32, end: u32) -> Float16Array;
14032
14033 /// The buffer accessor property represents the `ArrayBuffer` referenced
14034 /// by a `TypedArray` at construction time.
14035 #[wasm_bindgen(getter, method)]
14036 pub fn buffer(this: &Float16Array) -> ArrayBuffer;
14037
14038 /// The `subarray()` method returns a new `TypedArray` on the same
14039 /// `ArrayBuffer` store and with the same element types as this array.
14040 #[wasm_bindgen(method)]
14041 pub fn subarray(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
14042
14043 /// The `slice()` method returns a shallow copy of a portion of a typed
14044 /// array into a new typed array object.
14045 #[wasm_bindgen(method)]
14046 pub fn slice(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
14047
14048 /// The `forEach()` method executes a provided function once per array
14049 /// element, passing values as `f32`.
14050 #[wasm_bindgen(method, js_name = forEach)]
14051 pub fn for_each_as_f32(this: &Float16Array, callback: &mut dyn FnMut(f32, u32, Float16Array));
14052
14053 /// The `forEach()` method executes a provided function once per array
14054 /// element, passing values as `f32`.
14055 #[wasm_bindgen(method, js_name = forEach, catch)]
14056 pub fn try_for_each_as_f32(
14057 this: &Float16Array,
14058 callback: &mut dyn FnMut(f32, u32, Float16Array) -> Result<(), JsError>,
14059 ) -> Result<(), JsValue>;
14060
14061 /// The length accessor property represents the length (in elements) of a
14062 /// typed array.
14063 #[wasm_bindgen(method, getter)]
14064 pub fn length(this: &Float16Array) -> u32;
14065
14066 /// The byteLength accessor property represents the length (in bytes) of a
14067 /// typed array.
14068 #[wasm_bindgen(method, getter, js_name = byteLength)]
14069 pub fn byte_length(this: &Float16Array) -> u32;
14070
14071 /// The byteOffset accessor property represents the offset (in bytes) of a
14072 /// typed array from the start of its `ArrayBuffer`.
14073 #[wasm_bindgen(method, getter, js_name = byteOffset)]
14074 pub fn byte_offset(this: &Float16Array) -> u32;
14075
14076 /// The `set()` method stores multiple values in the typed array, reading
14077 /// input values from a specified array.
14078 #[wasm_bindgen(method)]
14079 pub fn set(this: &Float16Array, src: &JsValue, offset: u32);
14080
14081 /// Gets the value at `idx` as an `f32`, counting from the end if negative.
14082 #[wasm_bindgen(method, js_name = at)]
14083 pub fn at_as_f32(this: &Float16Array, idx: i32) -> Option<f32>;
14084
14085 /// The `copyWithin()` method shallow copies part of a typed array to another
14086 /// location in the same typed array and returns it, without modifying its size.
14087 ///
14088 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
14089 #[wasm_bindgen(method, js_name = copyWithin)]
14090 pub fn copy_within(this: &Float16Array, target: i32, start: i32, end: i32) -> Float16Array;
14091
14092 /// Gets the value at `idx` as an `f32`, equivalent to JavaScript
14093 /// `arr[idx]`.
14094 #[wasm_bindgen(method, indexing_getter)]
14095 pub fn get_index_as_f32(this: &Float16Array, idx: u32) -> f32;
14096
14097 /// Sets the value at `idx` from an `f32`, equivalent to JavaScript
14098 /// `arr[idx] = value`.
14099 #[wasm_bindgen(method, indexing_setter)]
14100 pub fn set_index_from_f32(this: &Float16Array, idx: u32, value: f32);
14101}
14102
14103impl Default for Float16Array {
14104 fn default() -> Self {
14105 Self::new(&JsValue::UNDEFINED.unchecked_into())
14106 }
14107}
14108
14109impl TypedArray for Float16Array {}
14110
14111impl Float16Array {
14112 fn as_uint16_view(&self) -> Uint16Array {
14113 let buffer = self.buffer();
14114 Uint16Array::new_with_byte_offset_and_length(
14115 buffer.as_ref(),
14116 self.byte_offset(),
14117 self.length(),
14118 )
14119 }
14120
14121 /// Creates an array from raw IEEE 754 binary16 bit patterns.
14122 ///
14123 /// This pairs naturally with the optional `half` crate:
14124 ///
14125 /// ```rust
14126 /// use half::f16;
14127 /// use js_sys::Float16Array;
14128 ///
14129 /// let values = [f16::from_f32(1.0), f16::from_f32(-2.0)];
14130 /// let bits = values.map(f16::to_bits);
14131 /// let array = Float16Array::new_from_u16_slice(&bits);
14132 /// ```
14133 pub fn new_from_u16_slice(slice: &[u16]) -> Float16Array {
14134 let array = Float16Array::new_with_length(slice.len() as u32);
14135 array.copy_from_u16_slice(slice);
14136 array
14137 }
14138
14139 /// Copy the raw IEEE 754 binary16 bit patterns from this JS typed array
14140 /// into the destination Rust slice.
14141 ///
14142 /// # Panics
14143 ///
14144 /// This function will panic if this typed array's length is different than
14145 /// the length of the provided `dst` array.
14146 ///
14147 /// Values copied into `dst` can be converted back into `half::f16` with
14148 /// `half::f16::from_bits`.
14149 pub fn copy_to_u16_slice(&self, dst: &mut [u16]) {
14150 self.as_uint16_view().copy_to(dst);
14151 }
14152
14153 /// Copy raw IEEE 754 binary16 bit patterns from the source Rust slice into
14154 /// this JS typed array.
14155 ///
14156 /// # Panics
14157 ///
14158 /// This function will panic if this typed array's length is different than
14159 /// the length of the provided `src` array.
14160 ///
14161 /// When using the optional `half` crate, populate `src` with
14162 /// `half::f16::to_bits()`.
14163 pub fn copy_from_u16_slice(&self, src: &[u16]) {
14164 self.as_uint16_view().copy_from(src);
14165 }
14166
14167 /// Efficiently copies the contents of this JS typed array into a new Vec of
14168 /// raw IEEE 754 binary16 bit patterns.
14169 ///
14170 /// This makes it easy to round-trip through the optional `half` crate:
14171 ///
14172 /// ```rust
14173 /// use half::f16;
14174 ///
14175 /// let bits = array.to_u16_vec();
14176 /// let values: Vec<f16> = bits.into_iter().map(f16::from_bits).collect();
14177 /// ```
14178 pub fn to_u16_vec(&self) -> Vec<u16> {
14179 self.as_uint16_view().to_vec()
14180 }
14181}
14182
14183macro_rules! arrays {
14184 ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
14185 #[wasm_bindgen]
14186 extern "C" {
14187 #[wasm_bindgen(extends = Object, typescript_type = $name)]
14188 #[derive(Clone, Debug)]
14189 pub type $name;
14190
14191 /// The
14192 #[doc = $ctor]
14193 /// constructor creates a new array.
14194 ///
14195 /// [MDN documentation](
14196 #[doc = $mdn]
14197 /// )
14198 #[wasm_bindgen(constructor)]
14199 pub fn new(constructor_arg: &JsValue) -> $name;
14200
14201 /// An
14202 #[doc = $ctor]
14203 /// which creates an array with an internal buffer large
14204 /// enough for `length` elements.
14205 ///
14206 /// [MDN documentation](
14207 #[doc = $mdn]
14208 /// )
14209 #[wasm_bindgen(constructor)]
14210 pub fn new_with_length(length: u32) -> $name;
14211
14212 /// An
14213 #[doc = $ctor]
14214 /// which creates an array from a Rust slice.
14215 ///
14216 /// [MDN documentation](
14217 #[doc = $mdn]
14218 /// )
14219 #[wasm_bindgen(constructor)]
14220 pub fn new_from_slice(slice: &[$ty]) -> $name;
14221
14222 /// An
14223 #[doc = $ctor]
14224 /// which creates an array with the given buffer but is a
14225 /// view starting at `byte_offset`.
14226 ///
14227 /// [MDN documentation](
14228 #[doc = $mdn]
14229 /// )
14230 #[wasm_bindgen(constructor)]
14231 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
14232
14233 /// An
14234 #[doc = $ctor]
14235 /// which creates an array with the given buffer but is a
14236 /// view starting at `byte_offset` for `length` elements.
14237 ///
14238 /// [MDN documentation](
14239 #[doc = $mdn]
14240 /// )
14241 #[wasm_bindgen(constructor)]
14242 pub fn new_with_byte_offset_and_length(
14243 buffer: &JsValue,
14244 byte_offset: u32,
14245 length: u32,
14246 ) -> $name;
14247
14248 /// The `fill()` method fills all the elements of an array from a start index
14249 /// to an end index with a static value. The end index is not included.
14250 ///
14251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
14252 #[wasm_bindgen(method)]
14253 pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
14254
14255 /// The buffer accessor property represents the `ArrayBuffer` referenced
14256 /// by a `TypedArray` at construction time.
14257 #[wasm_bindgen(getter, method)]
14258 pub fn buffer(this: &$name) -> ArrayBuffer;
14259
14260 /// The `subarray()` method returns a new `TypedArray` on the same
14261 /// `ArrayBuffer` store and with the same element types as for this
14262 /// `TypedArray` object.
14263 #[wasm_bindgen(method)]
14264 pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
14265
14266 /// The `slice()` method returns a shallow copy of a portion of a typed
14267 /// array into a new typed array object. This method has the same algorithm
14268 /// as `Array.prototype.slice()`.
14269 #[wasm_bindgen(method)]
14270 pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
14271
14272 /// The `forEach()` method executes a provided function once per array
14273 /// element. This method has the same algorithm as
14274 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
14275 /// types here.
14276 #[wasm_bindgen(method, js_name = forEach)]
14277 pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
14278
14279 /// The `forEach()` method executes a provided function once per array
14280 /// element. This method has the same algorithm as
14281 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
14282 /// types here.
14283 #[wasm_bindgen(method, js_name = forEach, catch)]
14284 pub fn try_for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name) -> Result<(), JsError>) -> Result<(), JsValue>;
14285
14286 /// The length accessor property represents the length (in elements) of a
14287 /// typed array.
14288 #[wasm_bindgen(method, getter)]
14289 pub fn length(this: &$name) -> u32;
14290
14291 /// The byteLength accessor property represents the length (in bytes) of a
14292 /// typed array.
14293 #[wasm_bindgen(method, getter, js_name = byteLength)]
14294 pub fn byte_length(this: &$name) -> u32;
14295
14296 /// The byteOffset accessor property represents the offset (in bytes) of a
14297 /// typed array from the start of its `ArrayBuffer`.
14298 #[wasm_bindgen(method, getter, js_name = byteOffset)]
14299 pub fn byte_offset(this: &$name) -> u32;
14300
14301 /// The `set()` method stores multiple values in the typed array, reading
14302 /// input values from a specified array.
14303 #[wasm_bindgen(method)]
14304 pub fn set(this: &$name, src: &JsValue, offset: u32);
14305
14306 /// Gets the value at `idx`, counting from the end if negative.
14307 #[wasm_bindgen(method)]
14308 pub fn at(this: &$name, idx: i32) -> Option<$ty>;
14309
14310 /// The `copyWithin()` method shallow copies part of a typed array to another
14311 /// location in the same typed array and returns it, without modifying its size.
14312 ///
14313 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
14314 #[wasm_bindgen(method, js_name = copyWithin)]
14315 pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
14316
14317 /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
14318 #[wasm_bindgen(method, indexing_getter)]
14319 pub fn get_index(this: &$name, idx: u32) -> $ty;
14320
14321 /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
14322 #[wasm_bindgen(method, indexing_setter)]
14323 pub fn set_index(this: &$name, idx: u32, value: $ty);
14324
14325 /// Copies the Rust slice's data to self.
14326 ///
14327 /// This method is not expected to be public. It requires the length of the
14328 /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
14329 #[wasm_bindgen(method, js_name = set)]
14330 fn copy_from_slice(this: &$name, slice: &[$ty]);
14331
14332 /// Copies this TypedArray's data to Rust slice;
14333 ///
14334 /// This method is not expected to be public. It requires the length of the
14335 /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
14336 ///
14337 /// # Workaround
14338 ///
14339 /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
14340 /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
14341 /// us to specify the `this` value inside the function.
14342 ///
14343 /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
14344 /// `slice.set(typed_array)`.
14345 #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
14346 fn copy_to_slice(slice: &mut [$ty], this: &$name);
14347 }
14348
14349 impl $name {
14350 /// Creates a JS typed array which is a view into wasm's linear
14351 /// memory at the slice specified.
14352 ///
14353 /// This function returns a new typed array which is a view into
14354 /// wasm's memory. This view does not copy the underlying data.
14355 ///
14356 /// # Safety
14357 ///
14358 /// Views into WebAssembly memory are only valid so long as the
14359 /// backing buffer isn't resized in JS. Once this function is called
14360 /// any future calls to `Box::new` (or malloc of any form) may cause
14361 /// the returned value here to be invalidated. Use with caution!
14362 ///
14363 /// Additionally the returned object can be safely mutated but the
14364 /// input slice isn't guaranteed to be mutable.
14365 ///
14366 /// Finally, the returned object is disconnected from the input
14367 /// slice's lifetime, so there's no guarantee that the data is read
14368 /// at the right time.
14369 pub unsafe fn view(rust: &[$ty]) -> $name {
14370 wasm_bindgen::__rt::wbg_cast(rust)
14371 }
14372
14373 /// Creates a JS typed array which is a view into wasm's linear
14374 /// memory at the specified pointer with specified length.
14375 ///
14376 /// This function returns a new typed array which is a view into
14377 /// wasm's memory. This view does not copy the underlying data.
14378 ///
14379 /// # Safety
14380 ///
14381 /// Views into WebAssembly memory are only valid so long as the
14382 /// backing buffer isn't resized in JS. Once this function is called
14383 /// any future calls to `Box::new` (or malloc of any form) may cause
14384 /// the returned value here to be invalidated. Use with caution!
14385 ///
14386 /// Additionally the returned object can be safely mutated,
14387 /// the changes are guaranteed to be reflected in the input array.
14388 pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
14389 let slice = core::slice::from_raw_parts_mut(ptr, length);
14390 Self::view(slice)
14391 }
14392
14393 /// Copy the contents of this JS typed array into the destination
14394 /// Rust pointer.
14395 ///
14396 /// This function will efficiently copy the memory from a typed
14397 /// array into this Wasm module's own linear memory, initializing
14398 /// the memory destination provided.
14399 ///
14400 /// # Safety
14401 ///
14402 /// This function requires `dst` to point to a buffer
14403 /// large enough to fit this array's contents.
14404 pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
14405 let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
14406 self.copy_to(slice);
14407 }
14408
14409 /// Copy the contents of this JS typed array into the destination
14410 /// Rust slice.
14411 ///
14412 /// This function will efficiently copy the memory from a typed
14413 /// array into this Wasm module's own linear memory, initializing
14414 /// the memory destination provided.
14415 ///
14416 /// # Panics
14417 ///
14418 /// This function will panic if this typed array's length is
14419 /// different than the length of the provided `dst` array.
14420 pub fn copy_to(&self, dst: &mut [$ty]) {
14421 core::assert_eq!(self.length() as usize, dst.len());
14422 $name::copy_to_slice(dst, self);
14423 }
14424
14425 /// Copy the contents of this JS typed array into the destination
14426 /// Rust slice.
14427 ///
14428 /// This function will efficiently copy the memory from a typed
14429 /// array into this Wasm module's own linear memory, initializing
14430 /// the memory destination provided.
14431 ///
14432 /// # Panics
14433 ///
14434 /// This function will panic if this typed array's length is
14435 /// different than the length of the provided `dst` array.
14436 pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
14437 core::assert_eq!(self.length() as usize, dst.len());
14438 let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
14439 self.copy_to(dst);
14440 dst
14441 }
14442
14443 /// Copy the contents of the source Rust slice into this
14444 /// JS typed array.
14445 ///
14446 /// This function will efficiently copy the memory from within
14447 /// the Wasm module's own linear memory to this typed array.
14448 ///
14449 /// # Panics
14450 ///
14451 /// This function will panic if this typed array's length is
14452 /// different than the length of the provided `src` array.
14453 pub fn copy_from(&self, src: &[$ty]) {
14454 core::assert_eq!(self.length() as usize, src.len());
14455 self.copy_from_slice(src);
14456 }
14457
14458 /// Efficiently copies the contents of this JS typed array into a new Vec.
14459 pub fn to_vec(&self) -> Vec<$ty> {
14460 let len = self.length() as usize;
14461 let mut output = Vec::with_capacity(len);
14462 // Safety: the capacity has been set
14463 unsafe {
14464 self.raw_copy_to_ptr(output.as_mut_ptr());
14465 output.set_len(len);
14466 }
14467 output
14468 }
14469 }
14470
14471 impl<'a> From<&'a [$ty]> for $name {
14472 #[inline]
14473 fn from(slice: &'a [$ty]) -> $name {
14474 // This is safe because the `new` function makes a copy if its argument is a TypedArray
14475 $name::new_from_slice(slice)
14476 }
14477 }
14478
14479 impl Default for $name {
14480 fn default() -> Self {
14481 Self::new(&JsValue::UNDEFINED.unchecked_into())
14482 }
14483 }
14484
14485 impl TypedArray for $name {}
14486
14487
14488 )*);
14489}
14490
14491arrays! {
14492 /// `Int8Array()`
14493 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
14494 Int8Array: i8,
14495
14496 /// `Int16Array()`
14497 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
14498 Int16Array: i16,
14499
14500 /// `Int32Array()`
14501 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
14502 Int32Array: i32,
14503
14504 /// `Uint8Array()`
14505 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
14506 Uint8Array: u8,
14507
14508 /// `Uint8ClampedArray()`
14509 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
14510 Uint8ClampedArray: u8,
14511
14512 /// `Uint16Array()`
14513 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
14514 Uint16Array: u16,
14515
14516 /// `Uint32Array()`
14517 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
14518 Uint32Array: u32,
14519
14520 /// `Float32Array()`
14521 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
14522 Float32Array: f32,
14523
14524 /// `Float64Array()`
14525 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
14526 Float64Array: f64,
14527
14528 /// `BigInt64Array()`
14529 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
14530 BigInt64Array: i64,
14531
14532 /// `BigUint64Array()`
14533 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
14534 BigUint64Array: u64,
14535}
14536
14537/// Bridging between JavaScript `Promise`s and Rust `Future`s.
14538///
14539/// Enables `promise.await` directly on any [`Promise`].
14540/// This module is also re-exported by `wasm-bindgen-futures` for backwards compatibility.
14541pub mod futures;